From: Jan Beulich Date: Tue, 7 Feb 2017 13:32:05 +0000 (+0100) Subject: page_alloc: clear nr_bootmem_regions in end_boot_allocator() X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~2841 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5fcf1c2516d253011b7c1001fe6a82e6c293f708;p=xen.git page_alloc: clear nr_bootmem_regions in end_boot_allocator() ... to make alloc_boot_pages() fail for late callers. Don't rely on reaching the BOOT_BUG_ON(1) near the end of that function though, but instead make this situation easier to distinguish from actual allocation failures by adding an explicit check. While there, make the iteration variable unsigned and guard against underflow. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index ae2476d10c..915e1f7654 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -329,13 +329,16 @@ unsigned long __init alloc_boot_pages( unsigned long nr_pfns, unsigned long pfn_align) { unsigned long pg, _e; - int i; + unsigned int i = nr_bootmem_regions; - for ( i = nr_bootmem_regions - 1; i >= 0; i-- ) + BOOT_BUG_ON(!nr_bootmem_regions); + + while ( i-- ) { struct bootmem_region *r = &bootmem_region_list[i]; + pg = (r->e - nr_pfns) & ~(pfn_align - 1); - if ( pg < r->s ) + if ( pg >= r->e || pg < r->s ) continue; #if defined(CONFIG_X86) && !defined(NDEBUG) @@ -1352,6 +1355,7 @@ void __init end_boot_allocator(void) if ( r->s < r->e ) init_heap_pages(mfn_to_page(r->s), r->e - r->s); } + nr_bootmem_regions = 0; init_heap_pages(virt_to_page(bootmem_region_list), 1); if ( !dma_bitsize && (num_online_nodes() > 1) )