Skip to contentSkip to conversation

Avoid page_set_flags() assert in qemu-user host page protection code

PATCH Applied Juergen Lock 3 participants 5 messages Mar 31, 2010 – Apr 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Avoid page_set_flags() assert in qemu-user host page protection code

V2 that uses endaddr = end-of-guest-address-space if !h2g_valid(endaddr) after I found out that indeed works; and also disables the FreeBSD 6.x /compat/linux/proc/self/maps fallback because it can return partial lines if (at least I think that's the reason) the mappings change between subsequent read() calls.

exec.c +7 -6
@@ -306,13 +306,14 @@ static void page_init(void)
 
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                     } else {
 #if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
 #endif
                     }
+                    page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
             }
             free(freep);
@@ -323,11 +324,7 @@ static void page_init(void)
 
         last_brk = (unsigned long)sbrk(0);
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-        f = fopen("/compat/linux/proc/self/maps", "r");
-#else
         f = fopen("/proc/self/maps", "r");
-#endif
         if (f) {
             mmap_lock();
 
@@ -343,7 +340,11 @@ static void page_init(void)
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
                     } else {
+#if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
+#endif
                     }
                     page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Juergen Lock

V2 that uses endaddr = end-of-guest-address-space if !h2g_valid(endaddr) after I found out that indeed works; and also disables the FreeBSD 6.x /compat/linux/proc/self/maps fallback because it can return partial lines if (at least I think that's the reason) the mappings change between subsequent read() calls.

Quoted 46 lines
exec.c +7 -6
@@ -306,13 +306,14 @@ static void page_init(void)
 
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                     } else {
 #if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
 #endif
                     }
+                    page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
             }
             free(freep);
@@ -323,11 +324,7 @@ static void page_init(void)
 
         last_brk = (unsigned long)sbrk(0);
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-        f = fopen("/compat/linux/proc/self/maps", "r");
-#else
         f = fopen("/proc/self/maps", "r");
-#endif
         if (f) {
             mmap_lock();
 
@@ -343,7 +340,11 @@ static void page_init(void)
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
                     } else {
+#if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
+#endif
                     }
                     page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
#2 lore raw
In reply to Juergen Lock
Quoted 7 lines · Juergen Lock

V2 that uses endaddr = end-of-guest-address-space if !h2g_valid(endaddr) after I found out that indeed works; and also disables the FreeBSD 6.x /compat/linux/proc/self/maps fallback because it can return partial lines if (at least I think that's the reason) the mappings change between subsequent read() calls.

Thanks, applied.

Quoted 46 lines
exec.c +7 -6
@@ -306,13 +306,14 @@ static void page_init(void)
 
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                     } else {
 #if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
-                        page_set_flags(startaddr, endaddr, PAGE_RESERVED);
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
 #endif
                     }
+                    page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
             }
             free(freep);
@@ -323,11 +324,7 @@ static void page_init(void)
 
         last_brk = (unsigned long)sbrk(0);
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-        f = fopen("/compat/linux/proc/self/maps", "r");
-#else
         f = fopen("/proc/self/maps", "r");
-#endif
         if (f) {
             mmap_lock();
 
@@ -343,7 +340,11 @@ static void page_init(void)
                     if (h2g_valid(endaddr)) {
                         endaddr = h2g(endaddr);
                     } else {
+#if TARGET_ABI_BITS <= L1_MAP_ADDR_SPACE_BITS
                         endaddr = ~0ul;
+#else
+                        endaddr = ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS) - 1;
+#endif
                     }
                     page_set_flags(startaddr, endaddr, PAGE_RESERVED);
                 }
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw
Quoted 11 lines · Aurelien Jarno
Quoted 7 lines · Juergen Lock

V2 that uses endaddr = end-of-guest-address-space if !h2g_valid(endaddr) after I found out that indeed works; and also disables the FreeBSD 6.x /compat/linux/proc/self/maps fallback because it can return partial lines if (at least I think that's the reason) the mappings change between subsequent read() calls.

Thanks, applied.

This patch actually breaks the build on 32-bit hosts. I have reverted it.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#4 lore raw
Quoted 8 lines · Aurelien Jarno
Quoted 7 lines · Aurelien Jarno
Quoted 6 lines · Juergen Lock

V2 that uses endaddr = end-of-guest-address-space if !h2g_valid(endaddr) after I found out that indeed works; and also disables the FreeBSD 6.x /compat/linux/proc/self/maps fallback because it can return partial lines if (at least I think that's the reason) the mappings change between subsequent read() calls.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks, applied.

This patch actually breaks the build on 32-bit hosts. I have reverted it.

Oh dear, sorry about that. :( Should I make a new version thats conditional on the host being 64-bit? Or do you think 32-bit hosts also need something fixed there?

Sorry again...
Juergen