[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [PATCH v2 20/26] tcg: Introduce target-specific page data for
From: |
Richard Henderson |
Subject: |
[Qemu-arm] [PATCH v2 20/26] tcg: Introduce target-specific page data for user-only |
Date: |
Sun, 10 Feb 2019 17:08:23 -0800 |
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 <address@hidden>
---
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(-)
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) {
--
2.17.2
- [Qemu-arm] [PATCH v2 06/26] target/arm: Add MTE system registers, (continued)
- [Qemu-arm] [PATCH v2 06/26] target/arm: Add MTE system registers, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 07/26] target/arm: Assert no manual change to CACHED_PSTATE_BITS, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 22/26] target/arm: Create tagged ram when MTE is enabled, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 11/26] target/arm: Implement ADDG, SUBG instructions, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 13/26] target/arm: Implement the SUBP instruction, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 25/26] target/arm: Enable MTE, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 23/26] target/arm: Add allocation tag storage for user mode, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 26/26] tests/tcg/aarch64: Add mte smoke tests, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 12/26] target/arm: Implement the GMI instruction, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 24/26] target/arm: Add allocation tag storage for system mode, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 20/26] tcg: Introduce target-specific page data for user-only,
Richard Henderson <=
- [Qemu-arm] [PATCH v2 14/26] target/arm: Define arm_cpu_do_unaligned_access for CONFIG_USER_ONLY, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 17/26] target/arm: Implement the access tag cache flushes, Richard Henderson, 2019/02/10
- [Qemu-arm] [PATCH v2 09/26] target/arm: Suppress tag check for sp+offset, Richard Henderson, 2019/02/10