Skip to contentSkip to conversation

xen: Check if the range is valid in init_domheap_pages

PATCH In review Julien Grall 3 participants 4 messages Nov 13, 2013 – Nov 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xen: Check if the range is valid in init_domheap_pages

On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions will call init_domheap_pages with the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

---
Changes in v3:
- Invert the check

Changes in v2:
- Change commit title
- Move the check in init_domheap_pages

---
 xen/common/page_alloc.c | 3 +++
 1 file changed, 3 insertions(+)
xen/common/page_alloc.c +3 -0
index 4c17fbd..0701333 100644
@@ -1429,6 +1429,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe)
     smfn = round_pgup(ps) >> PAGE_SHIFT;
     emfn = round_pgdown(pe) >> PAGE_SHIFT;
 
+    if ( emfn <= smfn )
+        return;
+
     init_heap_pages(mfn_to_page(smfn), emfn - smfn);
 }
 
Signature · 1 line
1.8.3.1
Acked-by on v3 1/1
#1 lore raw
Quoted 11 lines · Julien Grall

On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in
the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions will call init_domheap_pages with the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

I understand Jan's reservations, but I think just being more liberal here is fine really.

#2 lore raw
In reply to Julien Grall
Quoted 10 lines · Julien Grall

On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions will call init_domheap_pages with the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

Ping ? Without this commit, the user is unable to pass initrd to dom0 on ARM.

Signature · 1 line
Julien Grall
Acked-by
#3 lore raw
Quoted 9 lines · Julien Grall
Quoted 8 lines · Julien Grall

On ARM, when an initrd is given to xen by U-boot, it will reserve the memory in
the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions will call init_domheap_pages with the start and the end of range equals. But the latter assumes that (start > end), if not Xen will hang because the number of pages is equals to (unsigned)-1.

Quoted 6 lines
Quoted 3 lines
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

Ping ? Without this commit, the user is unable to pass initrd to dom0 on ARM.

It was fine with me.