Skip to contentSkip to conversation

linux-user: don't adjust base of found hole

PATCH In review Alex Bennée 2 participants 2 messages Jan 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user: don't adjust base of found hole

The pgb_find_hole function goes to the trouble of taking account of both mmap_min_addr and any offset we've applied to decide the starting address of a potential hole. This is especially important for emulating 32bit ARM in a 32bit build as we have applied the offset to ensure there will be space to map the ARM_COMMPAGE bellow the main guest map (using wrapped arithmetic).

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/690

---
v2
- also make same adjustment to fallback

---
 linux-user/elfload.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
linux-user/elfload.c +2 -3
index 238979b8b6..fa9dae5f3f 100644
@@ -2293,8 +2293,7 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_size,
     brk = (uintptr_t)sbrk(0);
 
     if (!maps) {
-        ret = pgd_find_hole_fallback(guest_size, brk, align, offset);
-        return ret == -1 ? -1 : ret - guest_loaddr;
+        return pgd_find_hole_fallback(guest_size, brk, align, offset);
     }
 
     /* The first hole is before the first map entry. */
@@ -2334,7 +2333,7 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_size,
 
         /* Record the lowest successful match. */
         if (ret < 0) {
-            ret = align_start - guest_loaddr;
+            ret = align_start;
         }
         /* If this hole contains the identity map, select it. */
         if (align_start <= guest_loaddr &&
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Alex Bennée

The pgb_find_hole function goes to the trouble of taking account of both mmap_min_addr and any offset we've applied to decide the starting address of a potential hole. This is especially important for emulating 32bit ARM in a 32bit build as we have applied the offset to ensure there will be space to map the ARM_COMMPAGE bellow the main guest map (using wrapped arithmetic).

Quoted 8 lines

Resolves:https://gitlab.com/qemu-project/qemu/-/issues/690

---
v2
- also make same adjustment to fallback

---
  linux-user/elfload.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

r~