blob: 066ea7865a740b715a18ceda4caa2de6a733f9af [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 496231774f8bc17ecfaf543a6603e3cad3f3f74e Mon Sep 17 00:00:00 2001
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002From: Martin Jansa <martin.jansa@lge.com>
3Date: Fri, 1 Jun 2018 08:41:07 +0000
4Subject: [PATCH] Revert "linux-user: fix mmap/munmap/mprotect/mremap/shmat"
5
6Causes qemu-i386 to hang during gobject-introspection in webkitgtk build
7when musl is used on qemux86 - the same issue as
80010-linux-user-Fix-webkitgtk-hangs-on-32-bit-x86-target.patch
9was fixing in 2.11.0 release, but with this patch the fix no longer worked
10as discussed here:
11http://lists.openembedded.org/pipermail/openembedded-core/2018-May/150302.html
12http://lists.openembedded.org/pipermail/openembedded-core/2018-June/151382.html
13
14This reverts commit ebf9a3630c911d0cfc9c20f7cafe9ba4f88cf583.
15
16Upstream-Status: Pending
Brad Bishop19323692019-04-05 15:28:33 -040017
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018---
19 include/exec/cpu-all.h | 6 +-----
20 include/exec/cpu_ldst.h | 16 +++++++++-------
21 linux-user/mmap.c | 17 ++++-------------
22 linux-user/syscall.c | 5 +----
23 4 files changed, 15 insertions(+), 29 deletions(-)
24
25diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
Brad Bishop19323692019-04-05 15:28:33 -040026index 117d2fbb..90558c14 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027--- a/include/exec/cpu-all.h
28+++ b/include/exec/cpu-all.h
Brad Bishop19323692019-04-05 15:28:33 -040029@@ -163,12 +163,8 @@ extern unsigned long guest_base;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 extern int have_guest_base;
31 extern unsigned long reserved_va;
32
33-#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
34-#define GUEST_ADDR_MAX (~0ul)
35-#else
36-#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \
37+#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \
38 (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
39-#endif
40 #else
41
42 #include "exec/hwaddr.h"
43diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
Brad Bishop19323692019-04-05 15:28:33 -040044index 95906849..ed17b3f6 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080045--- a/include/exec/cpu_ldst.h
46+++ b/include/exec/cpu_ldst.h
Brad Bishop19323692019-04-05 15:28:33 -040047@@ -62,13 +62,15 @@ typedef uint64_t abi_ptr;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080048 /* All direct uses of g2h and h2g need to go away for usermode softmmu. */
Brad Bishop19323692019-04-05 15:28:33 -040049 #define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050
51-#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
52-#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
53-
54-static inline int guest_range_valid(unsigned long start, unsigned long len)
55-{
56- return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
57-}
58+#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
59+#define h2g_valid(x) 1
60+#else
61+#define h2g_valid(x) ({ \
62+ unsigned long __guest = (unsigned long)(x) - guest_base; \
63+ (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
64+ (!reserved_va || (__guest < reserved_va)); \
65+})
66+#endif
67
68 #define h2g_nocheck(x) ({ \
69 unsigned long __ret = (unsigned long)(x) - guest_base; \
70diff --git a/linux-user/mmap.c b/linux-user/mmap.c
Brad Bishop19323692019-04-05 15:28:33 -040071index 41e0983c..d0ee1c53 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072--- a/linux-user/mmap.c
73+++ b/linux-user/mmap.c
Brad Bishop19323692019-04-05 15:28:33 -040074@@ -79,7 +79,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080075 return -TARGET_EINVAL;
76 len = TARGET_PAGE_ALIGN(len);
77 end = start + len;
78- if (!guest_range_valid(start, len)) {
79+ if (end < start) {
80 return -TARGET_ENOMEM;
81 }
82 prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
Brad Bishop19323692019-04-05 15:28:33 -040083@@ -490,8 +490,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084 * It can fail only on 64-bit host with 32-bit target.
85 * On any other target/host host mmap() handles this error correctly.
86 */
87- if (!guest_range_valid(start, len)) {
88- errno = ENOMEM;
89+ if ((unsigned long)start + len - 1 > (abi_ulong) -1) {
90+ errno = EINVAL;
91 goto fail;
92 }
93
Brad Bishop19323692019-04-05 15:28:33 -040094@@ -631,10 +631,8 @@ int target_munmap(abi_ulong start, abi_ulong len)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080095 if (start & ~TARGET_PAGE_MASK)
96 return -TARGET_EINVAL;
97 len = TARGET_PAGE_ALIGN(len);
98- if (len == 0 || !guest_range_valid(start, len)) {
99+ if (len == 0)
100 return -TARGET_EINVAL;
101- }
102-
103 mmap_lock();
104 end = start + len;
105 real_start = start & qemu_host_page_mask;
Brad Bishop19323692019-04-05 15:28:33 -0400106@@ -689,13 +687,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800107 int prot;
108 void *host_addr;
109
110- if (!guest_range_valid(old_addr, old_size) ||
111- ((flags & MREMAP_FIXED) &&
112- !guest_range_valid(new_addr, new_size))) {
113- errno = ENOMEM;
114- return -1;
115- }
116-
117 mmap_lock();
118
119 if (flags & MREMAP_FIXED) {
120diff --git a/linux-user/syscall.c b/linux-user/syscall.c
Brad Bishop19323692019-04-05 15:28:33 -0400121index 280137da..efdd0006 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800122--- a/linux-user/syscall.c
123+++ b/linux-user/syscall.c
Brad Bishop19323692019-04-05 15:28:33 -0400124@@ -3818,9 +3818,6 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800125 return -TARGET_EINVAL;
126 }
127 }
128- if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) {
129- return -TARGET_EINVAL;
130- }
131
132 mmap_lock();
133
Brad Bishop19323692019-04-05 15:28:33 -0400134@@ -6582,7 +6579,7 @@ static int open_self_maps(void *cpu_env, int fd)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800135 }
136 if (h2g_valid(min)) {
137 int flags = page_get_flags(h2g(min));
138- max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX) + 1;
139+ max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX);
140 if (page_check_range(h2g(min), max - min, flags) == -1) {
141 continue;
142 }