x86-64: improve e820_search_gap()
PATCH 1/1 x86-64: improve e820_search_gap()
Blindly putting the gap close after max_pfn might be fine for native (though even there I'm uncertain regarding memory hotplug), but will certainly present a problem on Xen. And properly searching for a gap above 4Gb shouldn't hurt native.
Also, make the function static to ensure there are no other users that could depend on the previous behavior regarding the way start_addr gets specified.
--- arch/x86/include/asm/e820.h | 2 -- arch/x86/kernel/e820.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/include/asm/e820.h +0 -2
@@ -79,8 +79,6 @@ extern u64 e820_remove_range(u64 start, int checktype);extern void update_e820 (void );extern void e820_setup_gap (void ); -extern int e820_search_gap (unsigned long *gapstart,unsigned long *gapsize, -unsigned long start_addr,unsigned long long end_addr);struct setup_data ;extern void parse_e820_ext (struct setup_data *data,unsigned long pa_data);
arch/x86/kernel/e820.c +9 -2
@@ -533,13 +533,19 @@ static void __init update_e820_saved(voi/* * Search for a gap in the e820 memory space from start_addr to end_addr. */ -__init int e820_search_gap (unsigned long *gapstart,unsigned long *gapsize, +static int __init +e820_search_gap (unsigned long *gapstart,unsigned long *gapsize,unsigned long start_addr,unsigned long long end_addr) {unsigned long long last;int i = e820.nr_map;int found =0 ; +#ifdef CONFIG_X86_64 +if (start_addr >=MAX_GAP_END ) + last = end_addr ?: (1UL << boot_cpu_data.x86_phys_bits); + else +#endif last = (end_addr && end_addr <MAX_GAP_END ) ? end_addr :MAX_GAP_END ;while (--i >=0 ) {
@@ -585,11 +591,12 @@ __init void e820_setup_gap(void)#ifdef CONFIG_X86_64 if (!found) { - gapstart = (max_pfn <<PAGE_SHIFT ) +1024 *1024 ;printk (KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit " "address range\n" KERN_ERR "PCI: Unassigned devices with 32bit resource " "registers may break!\n" ); + found =e820_search_gap (&gapstart, &gapsize,MAX_GAP_END ,0 ); +BUG_ON (!found); }#endif
Quoted 39 lines · Jan Beulich
Blindly putting the gap close after
max_pfnmight be fine for native (though even there I'm uncertain regarding memory hotplug), but will certainly present a problem on Xen. And properly searching for a gap above 4Gb shouldn't hurt native.Also, make the function static to ensure there are no other users that could depend on the previous behavior regarding the way
start_addrgets specified.Signed-off-by Jan Beulich <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>--- arch/x86/include/asm/e820.h | 2 -- arch/x86/kernel/e820.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-)arch/x86/include/asm/e820.h +0
-2@@ -79,8 +79,6 @@ extern u64 e820_remove_range(u64 start, int checktype);extern void update_e820 (void );extern void e820_setup_gap (void ); -extern int e820_search_gap (unsigned long *gapstart,unsigned long *gapsize, -unsigned long start_addr,unsigned long long end_addr);struct setup_data ;extern void parse_e820_ext (struct setup_data *data,unsigned long pa_data);arch/x86/kernel/e820.c +2
-1@@ -533,13 +533,19 @@ static void __init update_e820_saved(voi/* * Search for a gap in the e820 memory space from start_addr to end_addr. */ -__init int e820_search_gap (unsigned long *gapstart,unsigned long *gapsize, +static int __init +e820_search_gap (unsigned long *gapstart,unsigned long *gapsize,unsigned long start_addr,unsigned long long end_addr) {
arch/x86/kernel/e820.c static void __init update_e820_saved(voi · line 549
Quoted 10 lines
arch/x86/kernel/e820.c +5
-0unsigned long long last;int i = e820.nr_map;int found =0 ; +#ifdef CONFIG_X86_64 +if (start_addr >=MAX_GAP_END ) + last = end_addr ?: (1UL << boot_cpu_data.x86_phys_bits); + else +#endif last = (end_addr && end_addr <MAX_GAP_END ) ? end_addr :MAX_GAP_END ;
hm, this #ifdef block looks quite ugly and should be cleaned up. x86_phys_bits could be filled in on 32-bit too - and on 32-bit start_addr cannot be larger than 4GB anyway.
arch/x86/kernel/e820.c __init void e820_setup_gap(void) · line 599
Quoted 12 lines
arch/x86/kernel/e820.c +2
-1while (--i >=0 ) {@@ -585,11 +591,12 @@ __init void e820_setup_gap(void)#ifdef CONFIG_X86_64 if (!found) { - gapstart = (max_pfn <<PAGE_SHIFT ) +1024 *1024 ;printk (KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit " "address range\n" KERN_ERR "PCI: Unassigned devices with 32bit resource " "registers may break!\n" ); + found =e820_search_gap (&gapstart, &gapsize,MAX_GAP_END ,0 ); +BUG_ON (!found);
that BUG_ON() will be hard to debug - please use a WARN_ON instead.
Ingo
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Ingo Molnar <[email protected]> 12.03.09 12:02 >>>
arch/x86/kernel/e820.c +5
-0+#ifdef CONFIG_X86_64 +if (start_addr >=MAX_GAP_END ) + last = end_addr ?: (1UL << boot_cpu_data.x86_phys_bits); + else +#endif last = (end_addr && end_addr <MAX_GAP_END ) ? end_addr :MAX_GAP_END ;hm, this #ifdef block looks quite ugly and should be cleaned up.
x86_phys_bitscould be filled in on 32-bit too - and on 32-bit
I'm about to submit a patch to that effect. But I'm trying to keep patches independent as much as possible.
Quoted 1 line
start_addrcannot be larger than 4GB anyway.
Correct, but I think the code would be less self-documenting if it relied on that fact rather than making clear from the first glance that the conditional is only being evaluated (and hence can only be true) on 64-bits.
Quoted 14 lines
arch/x86/kernel/e820.c __init void e820_setup_gap(void) · line 599
Quoted 11 lines
arch/x86/kernel/e820.c +2
-1@@ -585,11 +591,12 @@ __init void e820_setup_gap(void)#ifdef CONFIG_X86_64 if (!found) { - gapstart = (max_pfn <<PAGE_SHIFT ) +1024 *1024 ;printk (KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit " "address range\n" KERN_ERR "PCI: Unassigned devices with 32bit resource " "registers may break!\n" ); + found =e820_search_gap (&gapstart, &gapsize,MAX_GAP_END ,0 ); +BUG_ON (!found);that
BUG_ON()will be hard to debug - please use aWARN_ONinstead.
Will do, but please clarify the above point before I re-submit.
Jan
Quoted 5 lines · Jan Beulich
Blindly putting the gap close after
max_pfnmight be fine for native (though even there I'm uncertain regarding memory hotplug), but will certainly present a problem on Xen. And properly searching for a gap above 4Gb shouldn't hurt native.
What Xen-related issue are you thinking of?
When booting dom0 I reashape the guest memory to match the host E820 map, and for domU my plan is to leave a hole at 3-4GB for pci passthrough resources.
J