From patchwork Mon Feb 11 01:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 157955 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2064594jaa; Sun, 10 Feb 2019 17:24:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IaGJRIV/p7IBEpkxcmqJgqsrzfiGIWtswENyttIStX+rPL3penheKf/sg9XU8SHmwqD1N3i X-Received: by 2002:a7b:c399:: with SMTP id s25mr7579708wmj.90.1549848248628; Sun, 10 Feb 2019 17:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549848248; cv=none; d=google.com; s=arc-20160816; b=IecrM/XAhKrQLgpwK3g/CwFM+4Geb7RkNA9aA6GUJuZTGK9kplyIOsw7SxRF4T2/KK Hqd93zyzX7ybUoZuX+rfOFxRpwlahP7o9wRZakNX+u6YBIqyvYzp3T9BV/TH8WZcCxEa Wa1L0D6t3PGbEfRsKLdkk6jL/To9Dgzmn/95Pj9ngdt/KEbGg7tmWBXxjvQvbX1a+IGT InfGZB5yYiadLPHA+kBip90Rp1hln0l8iLNRy5+4ZXtZOr68ur80DwxDVa4FuI9mOWeC +M92j1OWduEmX8ezAj+uVnRIyaNYddpv6ntPOFutKFWFWORqbDwABWwNb8eOcq3kkVL/ OEXA== 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=IYfDmawl379GZgWCUsgON1GHK8BY9wa/LpINsjn/HBc=; b=ilsuOkWChXJ1ckGwe0t73KIPvDeNG7i6HtaqCewSZPyY1FrLbpqn4sVOx6+hBAtC8h vcQEAqPuau5tLRsUYffomu2PmqoZqXXkdd0rCxMtlmZq/j56rsx6RXYjSoJiZhQnF4h3 A8W9IAwbkOwnw03kB1JU3UN1PXK/C2ISZo+tyoqE9Iw2AEG+aBKs2wK7aVvAiITramGi 1bYuoc1gYooCS1IZw2y1qbb1WfyMXq8C246LZhFWX6XD3FqHBFM/F5v6qdzPEVOhKn6L wRqffeGiZr2ZDwevTZia3f7L901DvEkZdiFN4LVi8FHWOdqs7S/ncwf+w8EIQwNzQStt jInw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=X+1o0xIl; 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 t7si6173677wrw.410.2019.02.10.17.24.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 10 Feb 2019 17:24:08 -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=X+1o0xIl; 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]:42301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt0KN-0000Wa-Gc for patch@linaro.org; Sun, 10 Feb 2019 20:24:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt05v-0005wL-16 for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gt05s-00007X-3f for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:10 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44214) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gt05r-0008O9-Mp for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:07 -0500 Received: by mail-pg1-x542.google.com with SMTP id y1so4188581pgk.11 for ; Sun, 10 Feb 2019 17:08:59 -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=IYfDmawl379GZgWCUsgON1GHK8BY9wa/LpINsjn/HBc=; b=X+1o0xIlcU4rnnY4YsMSmvoeIktLuTh+vW6ZUxzd5U2pbMbbcbHtdfA/su8IZSsMLT obyPCceQM6zT/G6epiYKvtQguU392xKcwKz6D7lODC/PQLXB8D0mWmzncB1A+Ghu5QqO HTY2FPeAnEKPfQkDvOGRK7pQmcXHAjw7QghbpLjpbFeXBS0RAkCADh1IzIrtCiYG2nrc FQKnXoja/uuqnUnrR5Vubxphdc4qBc6qeWm9SeDHvsJmH/4jZmeR3MSbPT/YCdcUEUHP Vxn/GmGGJzJuY28MQiQhOEDZs5490xMwPymKCThO0S4P+Dae2lklZL3wBHY0j+6mrDi0 o++g== 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=IYfDmawl379GZgWCUsgON1GHK8BY9wa/LpINsjn/HBc=; b=pUiPofkUPXnW7Bm9+xn9dtke4O+u7HWUhWXDgsWN+fC5BoaqAzsnjaCfZf4OZ24Cmj LvALoBP8Sn7mzzI/j140g4Q0EIDtS1jQR4kDp3N+BBpBAFZkFIveYzXlsqjHFkaxz5Re HglbNaASyoTL4382FmRxl1y2OOFjOeFav6dqNdPAjfpQqcbFmx7UQ8+EQakmrv+zFqcr 51I8bEvvtIjZyTY48KPUbDM6ZRfGVnS8BMWNwNA13yklq1UXieYK6JpbC0FptFLn8Iun KLx5JhpQPJB/yYks8JXu7fPeOtJsUVEztRb/ytd7kTbYEsdFx9+jDpemtdPh7+9MXF7u fVLg== X-Gm-Message-State: AHQUAuY4OLUoi7CgzfQVZRgmD7KfCOVbLRYqxc+DcEOZmzjINYf0DoE6 Sw3LFAMUL3V8kKOqFp7SzrtREE82ryI= X-Received: by 2002:a62:9917:: with SMTP id d23mr16055952pfe.88.1549847337734; Sun, 10 Feb 2019 17:08:57 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id g14sm17177630pfg.27.2019.02.10.17.08.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Feb 2019 17:08:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 10 Feb 2019 17:08:23 -0800 Message-Id: <20190211010829.29869-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211010829.29869-1-richard.henderson@linaro.org> References: <20190211010829.29869-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::542 Subject: [Qemu-devel] [PATCH v2 20/26] 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 b16c9ec513..e88ecad0b3 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 8f593b926f..6cc266428d 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -107,6 +107,7 @@ typedef struct PageDesc { unsigned int code_write_count; #else unsigned long flags; + void *target_data; #endif #ifndef CONFIG_USER_ONLY QemuSpin lock; @@ -2476,6 +2477,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 @@ -2492,6 +2494,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; @@ -2505,10 +2509,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 e0249efe4f..0b786b87a2 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 5bbb72f3d5..9d89b40321 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3884,8 +3884,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) {