From patchwork Mon Jan 14 01:11:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 155401 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3121011jaa; Sun, 13 Jan 2019 17:24:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN4EKsdLtFvQG1j+3f4PtRzLgTuvnrHyvR2I9E4wjctyFNcnpmKUFOKkvDFbViCuvi9ccxcp X-Received: by 2002:a05:6000:1251:: with SMTP id j17mr21542596wrx.315.1547429084673; Sun, 13 Jan 2019 17:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547429084; cv=none; d=google.com; s=arc-20160816; b=fa3jXW8749e4RHzhZIi6DF3CnYPcKxBu1w3cvHspoIFb6gSbncdZa18E6nHRlDYwec KWHTt1Tx+PTlZdZ+UXzqAeJfXPK3uKzulVFuSdlfPguP8wbNYAo+KHZ+baAVYY+0rpUR +gm+Owno4x8iy6Io3bWBKOO6k391O/moQDAOzMV7/gfcm2SaHgjR+pjbnHhYAWu7mr1/ JE0HouJgRMHBfcHkILkZ4VX+WCbDMeqRovokQrUl6o5McylVk3JALhwu4gkCrsdbPf77 Eqm4JvQliYXSCFAGqj8+Q5eDwvZxqSwQYeS/3YERUYReKHywCydvoKlGdeYeN0VVE1nw Bfzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=QEnnJ0lnXGNqeUVPB5fOxxV2hOiG+cnB1X7vEWDXqS0=; b=QGhZ4q/8VQlg1RprYJepA4RlGm75M+9u9zc43P65cKLtB050AfO1TBpZHlEC9u2eIk proePr4NFugOSzw4MycaGc+CzI9cbed0hw2adwChUpg20uqcylUGvKhsq8SrDxDT54XV RC77uN9phXPeDqkO8//JvSw4muy7VO0L0vcG709VbD0zeRpIA+OjbHlMz+0VxBgWfQ2A JGtY+ot58WqRM4M8/o9O8QnHVaAHeePGhXmuCoQcDM01jqVp+c1Xbdc4RXraiCMMRWSj 6Q70YvmPG1y+iWs2X7MpEFoV/JuX8X69RaPhJElckVI46ahrPKMg7PFLUZaXc6SEKVJl OiTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DwWoYC8H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o204si18531499wme.148.2019.01.13.17.24.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 13 Jan 2019 17:24:44 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DwWoYC8H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:57274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giqzb-00065y-F6 for patch@linaro.org; Sun, 13 Jan 2019 20:24:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giqni-000653-38 for qemu-devel@nongnu.org; Sun, 13 Jan 2019 20:12:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1giqnZ-00016v-1M for qemu-devel@nongnu.org; Sun, 13 Jan 2019 20:12:21 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:37008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1giqnY-00016a-Rb for qemu-devel@nongnu.org; Sun, 13 Jan 2019 20:12:16 -0500 Received: by mail-pg1-x543.google.com with SMTP id c25so8739326pgb.4 for ; Sun, 13 Jan 2019 17:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QEnnJ0lnXGNqeUVPB5fOxxV2hOiG+cnB1X7vEWDXqS0=; b=DwWoYC8HbRPzOlRLwQsLFonSKFOPmWhpB51Y7KnksUeC/e7ZlwkyHiZo+qyZDNtKdq 4FL7XWzI8hQfYWMPgBaDFaaGMudBZyJEUdzbEZfUceONUkRyi3MrMhNVOi+fpY4g/NzB iAsL4wU1+haZCDKwNjEZZXn3rMzgmKtMvpTEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QEnnJ0lnXGNqeUVPB5fOxxV2hOiG+cnB1X7vEWDXqS0=; b=GslDnE3Tmpxxfm/uHkAwPs7vZDr+p67ghaz42tMOUfbYCr46wrIvAXje95LWQZEn93 ruzUUVFnvycQtJ4Znzi/FdLkbOpwwIy+GKCzK5nuOsD8f+yh22Oc/1JfoO1FrMy6RJA6 X4M1BBjtJ2BJ99oJpD9O5kOqco7xEcD3+S3D6yR/pmydznoOpJjyY4M0hfFm9WMddOdS DAStOYg1qxgn1e6JJE8N1lkJ/kJ8u3lHBDi4jDPzCF3KsfPZiJQT78Tp/o0EjTOWxcLi Q52NPyfkP+eMbZYH726SyTc87BoYHBfsttNKWNH79b0cwy0h7n4hpgDpRrQozR6g96cY OLjw== X-Gm-Message-State: AJcUukc6e7ouH7ph/G2akX3dBf3TL7kakVT+q1UmrgnmiQT9OfO5seaH brgvV6NN1gSbzB+L/C0UANqC7xN7XqB+xQ== X-Received: by 2002:a63:ed42:: with SMTP id m2mr21204447pgk.147.1547428335527; Sun, 13 Jan 2019 17:12:15 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:1064:7600:4085:6ae6:1bde:1c45]) by smtp.gmail.com with ESMTPSA id 5sm159602229pfz.149.2019.01.13.17.12.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Jan 2019 17:12:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 12:11:19 +1100 Message-Id: <20190114011122.5995-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190114011122.5995-1-richard.henderson@linaro.org> References: <20190114011122.5995-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH 14/17] tcg: Introduce target-specific page data for user-only X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At the same time, remember MAP_SHARED as PAGE_SHARED. When mapping new pages, make sure that old target-specific page data is removed. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 10 ++++++++-- accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 10 ++++++++-- linux-user/syscall.c | 4 ++-- 4 files changed, 46 insertions(+), 6 deletions(-) -- 2.17.2 diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 117d2fbbca..92ec47dc79 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -244,10 +244,14 @@ extern intptr_t qemu_host_page_mask; #define PAGE_WRITE_ORG 0x0010 /* Invalidate the TLB entry immediately, helpful for s390x * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() */ -#define PAGE_WRITE_INV 0x0040 +#define PAGE_WRITE_INV 0x0020 +/* Page is mapped shared. */ +#define PAGE_SHARED 0x0040 +/* For use with page_set_flags: page is being replaced; target_data cleared. */ +#define PAGE_RESET 0x0080 #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) /* FIXME: Code that sets/uses this is broken and needs to go away. */ -#define PAGE_RESERVED 0x0020 +#define PAGE_RESERVED 0x0100 #endif #if defined(CONFIG_USER_ONLY) @@ -260,6 +264,8 @@ int walk_memory_regions(void *, walk_memory_regions_fn); int page_get_flags(target_ulong address); void page_set_flags(target_ulong start, target_ulong end, int flags); int page_check_range(target_ulong start, target_ulong len, int flags); +void *page_get_target_data(target_ulong address); +void *page_alloc_target_data(target_ulong address, size_t size); #endif CPUArchState *cpu_copy(CPUArchState *env); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 639f0b2728..047cd2f50d 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -111,6 +111,7 @@ typedef struct PageDesc { unsigned int code_write_count; #else unsigned long flags; + void *target_data; #endif #ifndef CONFIG_USER_ONLY QemuSpin lock; @@ -2477,6 +2478,7 @@ int page_get_flags(target_ulong address) void page_set_flags(target_ulong start, target_ulong end, int flags) { target_ulong addr, len; + bool reset_target_data; /* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates @@ -2493,6 +2495,8 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) if (flags & PAGE_WRITE) { flags |= PAGE_WRITE_ORG; } + reset_target_data = !(flags & PAGE_VALID) || (flags & PAGE_RESET); + flags &= ~PAGE_RESET; for (addr = start, len = end - start; len != 0; @@ -2506,10 +2510,34 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) p->first_tb) { tb_invalidate_phys_page(addr, 0); } + if (reset_target_data && p->target_data) { + g_free(p->target_data); + p->target_data = NULL; + } p->flags = flags; } } +void *page_get_target_data(target_ulong address) +{ + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); + return p ? p->target_data : NULL; +} + +void *page_alloc_target_data(target_ulong address, size_t size) +{ + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); + void *ret = NULL; + + if (p) { + ret = p->target_data; + if (!ret && (p->flags & PAGE_VALID)) { + p->target_data = ret = g_malloc0(size); + } + } + return ret; +} + int page_check_range(target_ulong start, target_ulong len, int flags) { PageDesc *p; diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 41e0983ce8..f83874b8c1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -562,7 +562,11 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + if ((flags & MAP_TYPE) == MAP_SHARED) { + prot |= PAGE_SHARED; + } + prot |= PAGE_RESET | PAGE_VALID; + page_set_flags(start, start + len, prot); the_end: #ifdef DEBUG_MMAP printf("ret=0x" TARGET_ABI_FMT_lx "\n", start); @@ -754,9 +758,11 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, new_addr = -1; } else { new_addr = h2g(host_addr); + /* FIXME: Move page flags (and target_data?) for each page. */ prot = page_get_flags(old_addr); page_set_flags(old_addr, old_addr + old_size, 0); - page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); + page_set_flags(new_addr, new_addr + new_size, + prot | PAGE_VALID | PAGE_RESET); } tb_invalidate_phys_range(new_addr, new_addr + new_size); mmap_unlock(); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 280137da8c..715101816d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3845,8 +3845,8 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, raddr=h2g((unsigned long)host_raddr); page_set_flags(raddr, raddr + shm_info.shm_segsz, - PAGE_VALID | PAGE_READ | - ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); + PAGE_VALID | PAGE_SHARED | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); for (i = 0; i < N_SHM_REGIONS; i++) { if (!shm_regions[i].in_use) {