blob: f2a44986b7234995738e66d92c66afce0ef77c0d [file] [log] [blame]
Andrew Geisslerd25ed322020-06-27 00:28:28 -05001From 815c97ba0de02da9dace3fcfcbdf9b20e029f0d7 Mon Sep 17 00:00:00 2001
Brad Bishopc68388fc2019-08-26 01:33:31 -04002From: Martin Jansa <martin.jansa@lge.com>
3Date: Fri, 1 Jun 2018 08:41:07 +0000
4Subject: [PATCH] Fix webkitgtk builds
5
6This is a partial revert of "linux-user: fix mmap/munmap/mprotect/mremap/shmat".
7
8This patch fixes qemu-i386 hangs during gobject-introspection in webkitgtk build
9when musl is used on qemux86. This is the same issue that
100008-linux-user-Fix-webkitgtk-hangs-on-32-bit-x86-target.patch was
11fixing in the 2.11 release.
12
13This patch also fixes a build failure when building webkitgtk for
14qemumips. A QEMU assert is seen while building webkitgtk:
15page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed.
16
17This reverts commit ebf9a3630c911d0cfc9c20f7cafe9ba4f88cf583.
18
19Upstream-Status: Pending
20Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Andrew Geissler82c905d2020-04-13 13:39:40 -050021
Andrew Geisslerd25ed322020-06-27 00:28:28 -050022[update patch context]
23Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
Brad Bishopc68388fc2019-08-26 01:33:31 -040024---
25 include/exec/cpu-all.h | 6 +-----
26 include/exec/cpu_ldst.h | 5 ++++-
27 linux-user/mmap.c | 17 ++++-------------
28 linux-user/syscall.c | 5 +----
29 4 files changed, 10 insertions(+), 23 deletions(-)
30
Andrew Geissler635e0e42020-08-21 15:58:33 -050031Index: qemu-5.1.0/include/exec/cpu-all.h
32===================================================================
33--- qemu-5.1.0.orig/include/exec/cpu-all.h
34+++ qemu-5.1.0/include/exec/cpu-all.h
35@@ -176,11 +176,8 @@ extern unsigned long reserved_va;
36 * avoid setting bits at the top of guest addresses that might need
37 * to be used for tags.
38 */
39-#define GUEST_ADDR_MAX_ \
40- ((MIN_CONST(TARGET_VIRT_ADDR_SPACE_BITS, TARGET_ABI_BITS) <= 32) ? \
41- UINT32_MAX : ~0ul)
42-#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : GUEST_ADDR_MAX_)
43-
Brad Bishopc68388fc2019-08-26 01:33:31 -040044+#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \
Andrew Geissler635e0e42020-08-21 15:58:33 -050045+ (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
Brad Bishopc68388fc2019-08-26 01:33:31 -040046 #else
47
48 #include "exec/hwaddr.h"
Andrew Geissler635e0e42020-08-21 15:58:33 -050049Index: qemu-5.1.0/include/exec/cpu_ldst.h
50===================================================================
51--- qemu-5.1.0.orig/include/exec/cpu_ldst.h
52+++ qemu-5.1.0/include/exec/cpu_ldst.h
53@@ -75,7 +75,10 @@ typedef uint64_t abi_ptr;
Brad Bishopc68388fc2019-08-26 01:33:31 -040054 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
55 #define guest_addr_valid(x) (1)
56 #else
57-#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
58+#define guest_addr_valid(x) ({ \
59+ ((x) < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
60+ (!reserved_va || ((x) < reserved_va)); \
61+})
62 #endif
63 #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
64
Andrew Geissler635e0e42020-08-21 15:58:33 -050065Index: qemu-5.1.0/linux-user/mmap.c
66===================================================================
67--- qemu-5.1.0.orig/linux-user/mmap.c
68+++ qemu-5.1.0/linux-user/mmap.c
69@@ -71,7 +71,7 @@ int target_mprotect(abi_ulong start, abi
Brad Bishopc68388fc2019-08-26 01:33:31 -040070 return -TARGET_EINVAL;
71 len = TARGET_PAGE_ALIGN(len);
72 end = start + len;
73- if (!guest_range_valid(start, len)) {
74+ if (end < start) {
75 return -TARGET_ENOMEM;
76 }
77 prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
Andrew Geissler635e0e42020-08-21 15:58:33 -050078@@ -467,8 +467,8 @@ abi_long target_mmap(abi_ulong start, ab
Brad Bishopc68388fc2019-08-26 01:33:31 -040079 * It can fail only on 64-bit host with 32-bit target.
80 * On any other target/host host mmap() handles this error correctly.
81 */
Andrew Geissler635e0e42020-08-21 15:58:33 -050082- if (end < start || !guest_range_valid(start, len)) {
Brad Bishopc68388fc2019-08-26 01:33:31 -040083- errno = ENOMEM;
Andrew Geissler635e0e42020-08-21 15:58:33 -050084+ if (end < start || ((unsigned long)start + len - 1 > (abi_ulong) -1)) {
Brad Bishopc68388fc2019-08-26 01:33:31 -040085+ errno = EINVAL;
86 goto fail;
87 }
88
Andrew Geissler635e0e42020-08-21 15:58:33 -050089@@ -604,10 +604,8 @@ int target_munmap(abi_ulong start, abi_u
Brad Bishopc68388fc2019-08-26 01:33:31 -040090 if (start & ~TARGET_PAGE_MASK)
91 return -TARGET_EINVAL;
92 len = TARGET_PAGE_ALIGN(len);
93- if (len == 0 || !guest_range_valid(start, len)) {
94+ if (len == 0)
95 return -TARGET_EINVAL;
96- }
97-
98 mmap_lock();
99 end = start + len;
100 real_start = start & qemu_host_page_mask;
Andrew Geissler635e0e42020-08-21 15:58:33 -0500101@@ -662,13 +660,6 @@ abi_long target_mremap(abi_ulong old_add
Brad Bishopc68388fc2019-08-26 01:33:31 -0400102 int prot;
103 void *host_addr;
104
105- if (!guest_range_valid(old_addr, old_size) ||
106- ((flags & MREMAP_FIXED) &&
107- !guest_range_valid(new_addr, new_size))) {
108- errno = ENOMEM;
109- return -1;
110- }
111-
112 mmap_lock();
113
114 if (flags & MREMAP_FIXED) {
Andrew Geissler635e0e42020-08-21 15:58:33 -0500115Index: qemu-5.1.0/linux-user/syscall.c
116===================================================================
117--- qemu-5.1.0.orig/linux-user/syscall.c
118+++ qemu-5.1.0/linux-user/syscall.c
119@@ -4336,9 +4336,6 @@ static inline abi_ulong do_shmat(CPUArch
Brad Bishopc68388fc2019-08-26 01:33:31 -0400120 return -TARGET_EINVAL;
121 }
122 }
123- if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) {
124- return -TARGET_EINVAL;
125- }
126
127 mmap_lock();
128
Andrew Geissler635e0e42020-08-21 15:58:33 -0500129@@ -7376,7 +7373,7 @@ static int open_self_maps(void *cpu_env,
Andrew Geisslerd25ed322020-06-27 00:28:28 -0500130 const char *path;
131
132 max = h2g_valid(max - 1) ?
133- max : (uintptr_t) g2h(GUEST_ADDR_MAX) + 1;
134+ max : (uintptr_t) g2h(GUEST_ADDR_MAX);
135
Brad Bishopc68388fc2019-08-26 01:33:31 -0400136 if (page_check_range(h2g(min), max - min, flags) == -1) {
137 continue;