Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 1 | From 815c97ba0de02da9dace3fcfcbdf9b20e029f0d7 Mon Sep 17 00:00:00 2001 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 2 | From: Martin Jansa <martin.jansa@lge.com> |
| 3 | Date: Fri, 1 Jun 2018 08:41:07 +0000 |
| 4 | Subject: [PATCH] Fix webkitgtk builds |
| 5 | |
| 6 | This is a partial revert of "linux-user: fix mmap/munmap/mprotect/mremap/shmat". |
| 7 | |
| 8 | This patch fixes qemu-i386 hangs during gobject-introspection in webkitgtk build |
| 9 | when musl is used on qemux86. This is the same issue that |
| 10 | 0008-linux-user-Fix-webkitgtk-hangs-on-32-bit-x86-target.patch was |
| 11 | fixing in the 2.11 release. |
| 12 | |
| 13 | This patch also fixes a build failure when building webkitgtk for |
| 14 | qemumips. A QEMU assert is seen while building webkitgtk: |
| 15 | page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed. |
| 16 | |
| 17 | This reverts commit ebf9a3630c911d0cfc9c20f7cafe9ba4f88cf583. |
| 18 | |
| 19 | Upstream-Status: Pending |
| 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 21 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 22 | [update patch context] |
| 23 | Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com> |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 24 | --- |
| 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 31 | Index: 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 Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 44 | +#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \ |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 45 | + (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 46 | #else |
| 47 | |
| 48 | #include "exec/hwaddr.h" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 49 | Index: 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 Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 54 | #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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 65 | Index: 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 Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 70 | 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 78 | @@ -467,8 +467,8 @@ abi_long target_mmap(abi_ulong start, ab |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 79 | * 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 82 | - if (end < start || !guest_range_valid(start, len)) { |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 83 | - errno = ENOMEM; |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 84 | + if (end < start || ((unsigned long)start + len - 1 > (abi_ulong) -1)) { |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 85 | + errno = EINVAL; |
| 86 | goto fail; |
| 87 | } |
| 88 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 89 | @@ -604,10 +604,8 @@ int target_munmap(abi_ulong start, abi_u |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 90 | 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 101 | @@ -662,13 +660,6 @@ abi_long target_mremap(abi_ulong old_add |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 102 | 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 115 | Index: 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 Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 120 | 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 Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 129 | @@ -7376,7 +7373,7 @@ static int open_self_maps(void *cpu_env, |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 130 | 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 Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 136 | if (page_check_range(h2g(min), max - min, flags) == -1) { |
| 137 | continue; |