Skip to contentSkip to conversation

x86: seperate reserve_early and reserve_early_overlap_check

PATCH In review Yinghai Lu 2 participants 4 messages Nov 25, 2009 – Dec 3, 2009

Subsystems (3)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86: seperate reserve_early and reserve_early_overlap_check

when the area is from find_e820_area(), it could be overlapped with others.

so just add it directly. the new reserve_early()

and rename old reserve_early() to reserve_early_overlap_check()

---
 arch/x86/include/asm/e820.h  |    3 ++-
 arch/x86/kernel/e820.c       |   26 +++++++++++++++++++++++++-
 arch/x86/kernel/efi.c        |    4 ++--
 arch/x86/kernel/head32.c     |    6 ++++--
 arch/x86/kernel/head64.c     |    6 ++++--
 arch/x86/kernel/mpparse.c    |    6 ++++--
 arch/x86/kernel/setup.c      |    6 ++++--
 arch/x86/kernel/trampoline.c |    7 ++++---
 arch/x86/xen/mmu.c           |    4 ++--
 arch/x86/xen/setup.c         |    2 +-
 10 files changed, 52 insertions(+), 18 deletions(-)
arch/x86/include/asm/e820.h +2 -1
Index: linux-2.6/arch/x86/include/asm/e820.h
===================================================================
@@ -111,7 +111,8 @@ extern unsigned long end_user_pfn;
 
 extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
 extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
-extern void reserve_early(u64 start, u64 end, char *name);
+void reserve_early(u64 start, u64 end, char *name);
+void reserve_early_overlap_check(u64 start, u64 end, char *name);
 extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
 extern void free_early(u64 start, u64 end);
 extern void early_res_to_bootmem(u64 start, u64 end);
arch/x86/kernel/e820.c +25 -1
Index: linux-2.6/arch/x86/kernel/e820.c
===================================================================
@@ -835,6 +835,30 @@ static void __init drop_overlaps_that_ar
 	}
 }
 
+void __init reserve_early(u64 start, u64 end, char *name)
+{
+	int i;
+	struct early_res *r;
+
+	if (start >= end)
+		return;
+
+	for (i = 0; i < MAX_EARLY_RES; i++) {
+		r = &early_res[i];
+		if (!r->end) {
+			r->start = start;
+			r->end = end;
+			if (name)
+				strncpy(r->name, name, sizeof(r->name) - 1);
+			r->overlap_ok = 0;
+
+			return;
+		}
+	}
+
+	panic("Too many early reservations");
+}
+
 static void __init __reserve_early(u64 start, u64 end, char *name,
 						int overlap_ok)
 {
@@ -891,7 +915,7 @@ void __init reserve_early_overlap_ok(u64
  * range without risk of panic'ing on an overlapping overlap_ok
  * early reservation.
  */
-void __init reserve_early(u64 start, u64 end, char *name)
+void __init reserve_early_overlap_check(u64 start, u64 end, char *name)
 {
 	if (start >= end)
 		return;
arch/x86/kernel/efi.c +2 -2
Index: linux-2.6/arch/x86/kernel/efi.c
===================================================================
@@ -290,8 +290,8 @@ void __init efi_reserve_early(void)
 		boot_params.efi_info.efi_memdesc_size;
 	memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
 	memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
-	reserve_early(pmap, pmap + memmap.nr_map * memmap.desc_size,
-		      "EFI memmap");
+	reserve_early_overlap_check(pmap,
+			 pmap + memmap.nr_map * memmap.desc_size, "EFI memmap");
 }
 
 #if EFI_DEBUG
arch/x86/kernel/head32.c +4 -2
Index: linux-2.6/arch/x86/kernel/head32.c
===================================================================
@@ -31,7 +31,8 @@ void __init i386_start_kernel(void)
 {
 	reserve_trampoline_memory();
 
-	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
+	reserve_early_overlap_check(__pa_symbol(&_text),
+				 __pa_symbol(&__bss_stop), "TEXT DATA BSS");
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	/* Reserve INITRD */
@@ -39,7 +40,8 @@ void __init i386_start_kernel(void)
 		u64 ramdisk_image = boot_params.hdr.ramdisk_image;
 		u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
 		u64 ramdisk_end   = ramdisk_image + ramdisk_size;
-		reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
+		reserve_early_overlap_check(ramdisk_image, ramdisk_end,
+						 "RAMDISK");
 	}
 #endif
 
arch/x86/kernel/head64.c +4 -2
Index: linux-2.6/arch/x86/kernel/head64.c
===================================================================
@@ -100,7 +100,8 @@ void __init x86_64_start_reservations(ch
 
 	reserve_trampoline_memory();
 
-	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
+	reserve_early_overlap_check(__pa_symbol(&_text),
+				 __pa_symbol(&__bss_stop), "TEXT DATA BSS");
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	/* Reserve INITRD */
@@ -108,7 +109,8 @@ void __init x86_64_start_reservations(ch
 		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
 		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
 		unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
-		reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
+		reserve_early_overlap_check(ramdisk_image, ramdisk_end,
+						 "RAMDISK");
 	}
 #endif
 
arch/x86/kernel/mpparse.c +4 -2
Index: linux-2.6/arch/x86/kernel/mpparse.c
===================================================================
@@ -671,7 +671,8 @@ static void __init smp_reserve_memory(st
 {
 	unsigned long size = get_mpc_size(mpf->physptr);
 
-	reserve_early(mpf->physptr, mpf->physptr+size, "MP-table mpc");
+	reserve_early_overlap_check(mpf->physptr, mpf->physptr+size,
+					 "MP-table mpc");
 }
 
 static int __init smp_scan_config(unsigned long base, unsigned long length)
@@ -700,7 +701,8 @@ static int __init smp_scan_config(unsign
 			       mpf, (u64)virt_to_phys(mpf));
 
 			mem = virt_to_phys(mpf);
-			reserve_early(mem, mem + sizeof(*mpf), "MP-table mpf");
+			reserve_early_overlap_check(mem, mem + sizeof(*mpf),
+							 "MP-table mpf");
 			if (mpf->physptr)
 				smp_reserve_memory(mpf);
 
arch/x86/kernel/setup.c +4 -2
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -299,7 +299,8 @@ static inline void init_gbpages(void)
 static void __init reserve_brk(void)
 {
 	if (_brk_end > _brk_start)
-		reserve_early(__pa(_brk_start), __pa(_brk_end), "BRK");
+		reserve_early_overlap_check(__pa(_brk_start), __pa(_brk_end),
+						 "BRK");
 
 	/* Mark brk area as locked down and no longer taking any
 	   new allocations */
@@ -476,7 +477,8 @@ static void __init reserve_early_setup_d
 	while (pa_data) {
 		data = early_memremap(pa_data, sizeof(*data));
 		sprintf(buf, "setup data %x", data->type);
-		reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
+		reserve_early_overlap_check(pa_data,
+					 pa_data+sizeof(*data)+data->len, buf);
 		pa_data = data->next;
 		early_iounmap(data, sizeof(*data));
 	}
arch/x86/kernel/trampoline.c +4 -3
Index: linux-2.6/arch/x86/kernel/trampoline.c
===================================================================
@@ -22,11 +22,12 @@ void __init reserve_trampoline_memory(vo
 	 * FIXME: Don't need the extra page at 4K, but need to fix
 	 * trampoline before removing it. (see the GDT stuff)
 	 */
-	reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
+	reserve_early_overlap_check(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
+					 "EX TRAMPOLINE");
 #endif
 	/* Has to be in very low memory so we can execute real-mode AP code. */
-	reserve_early(TRAMPOLINE_BASE, TRAMPOLINE_BASE + TRAMPOLINE_SIZE,
-			"TRAMPOLINE");
+	reserve_early_overlap_check(TRAMPOLINE_BASE,
+			 TRAMPOLINE_BASE + TRAMPOLINE_SIZE, "TRAMPOLINE");
 }
 
 /*
arch/x86/xen/mmu.c +2 -2
Index: linux-2.6/arch/x86/xen/mmu.c
===================================================================
@@ -1751,7 +1751,7 @@ __init pgd_t *xen_setup_kernel_pagetable
 	__xen_write_cr3(true, __pa(pgd));
 	xen_mc_issue(PARAVIRT_LAZY_CPU);
 
-	reserve_early(__pa(xen_start_info->pt_base),
+	reserve_early_overlap_check(__pa(xen_start_info->pt_base),
 		      __pa(xen_start_info->pt_base +
 			   xen_start_info->nr_pt_frames * PAGE_SIZE),
 		      "XEN PAGETABLES");
@@ -1789,7 +1789,7 @@ __init pgd_t *xen_setup_kernel_pagetable
 
 	pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(swapper_pg_dir)));
 
-	reserve_early(__pa(xen_start_info->pt_base),
+	reserve_early_overlap_check(__pa(xen_start_info->pt_base),
 		      __pa(xen_start_info->pt_base +
 			   xen_start_info->nr_pt_frames * PAGE_SIZE),
 		      "XEN PAGETABLES");
arch/x86/xen/setup.c +1 -1
Index: linux-2.6/arch/x86/xen/setup.c
===================================================================
@@ -61,7 +61,7 @@ char * __init xen_memory_setup(void)
 	 *  - xen_start_info
 	 * See comment above "struct start_info" in <xen/interface/xen.h>
 	 */
-	reserve_early(__pa(xen_start_info->mfn_list),
+	reserve_early_overlap_check(__pa(xen_start_info->mfn_list),
 		      __pa(xen_start_info->pt_base),
 			"XEN START INFO");
 
#1 lore raw
Quoted 8 lines · Yinghai Lu

when the area is from find_e820_area(), it could be overlapped with others.

so just add it directly. the new reserve_early()

and rename old reserve_early() to reserve_early_overlap_check()

Hi Yinghai,

I had this patch in my queue but it looks like I had overlooked it as it arrived during the U.S. holiday; I apologize profusely!

I'm concerned about several things with this patch, which doesn't mean it isn't fulfilling a genuine need:

1. Renaming reserve_early() to reserve_early_overlap_check() is most likely going to get overlooked, and people will use the "new" reserve_early() thinking that they got the old one.

2. This creates overlapping ranges in the reservation array itself.

What it looks to me is what we need is actually a reserve_early_clobber() which does what the current reserve_early() does except that it ignores the overlap_ok flag on existing reservations.

I have attached an untested patch to do that. Note that I don't have any callers for reserve_early_clobber(), since one effect of changing the semantics of an existing function in the way you did is that the patch contains the call sites that *didn't* need modification rather than the one that *did* need modification. The call sites that want the new semantics need to be modified. As such, it's possible that the comment I added is completely wrong, I really need some further information on this.

[Note: the function __reserve_early() hasn't actually changed; I just moved it ahead of drop_overlaps().]

Sorry again for the delay.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
arch/x86/include/asm/e820.h +1 -0
index 761249e..b45bf41 100644
@@ -113,6 +113,7 @@ extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
 extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
 extern void reserve_early(u64 start, u64 end, char *name);
 extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
+extern void reserve_early_clobber(u64 start, u64 end, char *name);
 extern void free_early(u64 start, u64 end);
 extern void early_res_to_bootmem(u64 start, u64 end);
 extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
arch/x86/kernel/e820.c +48 -29

131 lines not on this page · raw message

author
#2 lore raw
Quoted 14 lines · H. Peter Anvin
Quoted 7 lines · Yinghai Lu

when the area is from find_e820_area(), it could be overlapped with others.

so just add it directly. the new reserve_early()

and rename old reserve_early() to reserve_early_overlap_check()

Hi Yinghai,

I had this patch in my queue but it looks like I had overlooked it as it arrived during the U.S. holiday; I apologize profusely!

Quoted 6 lines

I'm concerned about several things with this patch, which doesn't mean it isn't fulfilling a genuine need:

1. Renaming reserve_early() to reserve_early_overlap_check() is most likely going to get overlooked, and people will use the "new" reserve_early() thinking that they got the old one.

kill reserve_early()
and use
reserve_early_overlap_check()
reserve_early_overlap_not_check()
?

Quoted 2 lines

2. This creates overlapping ranges in the reservation array itself.

why?

if the range is retrieved from find_e820_area(). that range should be safe. we could add the early_res directly.

Quoted 14 lines

What it looks to me is what we need is actually a reserve_early_clobber() which does what the current reserve_early() does except that it ignores the overlap_ok flag on existing reservations.

I have attached an untested patch to do that. Note that I don't have any callers for reserve_early_clobber(), since one effect of changing the semantics of an existing function in the way you did is that the patch contains the call sites that *didn't* need modification rather than the one that *did* need modification. The call sites that want the new semantics need to be modified. As such, it's possible that the comment I added is completely wrong, I really need some further information on this.

Quoted 3 lines

[Note: the function __reserve_early() hasn't actually changed; I just moved it ahead of drop_overlaps().]

your patch seems to solve the multiple overlap ok problem.

these overlap check stuff is added by SGI guys to bandit their bios problem. maybe we can kill them at some point.

YH

#3 lore raw
Quoted 7 lines · Yinghai Lu
Quoted 3 lines

1. Renaming reserve_early() to reserve_early_overlap_check() is most likely going to get overlooked, and people will use the "new" reserve_early() thinking that they got the old one.

kill reserve_early()
and use
reserve_early_overlap_check()
reserve_early_overlap_not_check()

I would think that we should just leave the current reserve_early() in place... it is what we want most of the time.

I guess I'd like to know specifically when one does *not* want an overlap check, which is really the issue here.

Quoted 6 lines
Quoted 1 line

2. This creates overlapping ranges in the reservation array itself.

why?

if the range is retrieved from find_e820_area(). that range should be safe. we could add the early_res directly.

If there is no overlap, the current reserve_early() will work just fine.
If there is overlap, then your code would create overlapping
reservations in the array, since it doesn't seem to check.

Either the new interface is unnecessary, or it is bad... I don't see any other alternatives. Unless the only point is to try to shave off a few microseconds, but if so, it seems rather pointless to seek to the end of the array first...

Quoted 5 lines

your patch seems to solve the multiple overlap ok problem.

these overlap check stuff is added by SGI guys to bandit their bios problem. maybe we can kill them at some point.

It's probably a good idea to have them... errors happen.

One thing I would like to see is to change the underlying data structure to instead of having (start, end, attributes) for each reservation, have (start, attributes) for all address space. Such a list would by definition always be sorted, and overlaps would be trivial to detect.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.