[PATCH] x86: extend e820 ealy_res support 32bit - fix v2

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Yinghai Lu
Date: Thursday, May 22, 2008 - 3:20 pm

[PATCH] x86: extend e820 ealy_res support 32bit - fix v2

use find_e820_area to find addess for new RAMDISK, instead of using ram blindly

also print out low ram and bootmap info

v2: remove extra -1 in reaseve_early calling
    panic if can not find space for new RAMDISK

Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>

Index: linux-2.6/arch/x86/kernel/setup_32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup_32.c
+++ linux-2.6/arch/x86/kernel/setup_32.c
@@ -466,11 +466,11 @@ static bool do_relocate_initrd = false;
 
 static void __init reserve_initrd(void)
 {
-	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;
-	unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
-	unsigned long ramdisk_here;
+	u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+	u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
+	u64 ramdisk_end   = ramdisk_image + ramdisk_size;
+	u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
+	u64 ramdisk_here;
 
 	if (!boot_params.hdr.type_of_loader ||
 	    !ramdisk_image || !ramdisk_size)
@@ -478,14 +478,8 @@ static void __init reserve_initrd(void)
 
 	initrd_start = 0;
 
-	if (ramdisk_end < ramdisk_image) {
-		free_bootmem(ramdisk_image, ramdisk_size);
-		printk(KERN_ERR "initrd wraps around end of memory, "
-		       "disabling initrd\n");
-		return;
-	}
 	if (ramdisk_size >= end_of_lowmem/2) {
-		free_bootmem(ramdisk_image, ramdisk_size);
+		free_early(ramdisk_image, ramdisk_end);
 		printk(KERN_ERR "initrd too large to handle, "
 		       "disabling initrd\n");
 		return;
@@ -495,8 +489,7 @@ static void __init reserve_initrd(void)
 		/* All in lowmem, easy case */
 		/*
 		 * don't need to reserve again, already reserved early
-		 * in i386_start_kernel, and early_res_to_bootmem
-		 * convert that to reserved in bootmem
+		 * in i386_start_kernel
 		 */
 		initrd_start = ramdisk_image + PAGE_OFFSET;
 		initrd_end = initrd_start+ramdisk_size;
@@ -504,11 +497,18 @@ static void __init reserve_initrd(void)
 	}
 
 	/* We need to move the initrd down into lowmem */
-	ramdisk_here = (end_of_lowmem - ramdisk_size) & PAGE_MASK;
+	ramdisk_here = find_e820_area(min_low_pfn<<PAGE_SHIFT,
+				 end_of_lowmem, ramdisk_size,
+				 PAGE_SIZE);
+
+	if (ramdisk_here == -1ULL)
+		panic("Cannot find placce for new RAMDISK of size %lld\n",
+			 ramdisk_size);
 
 	/* Note: this includes all the lowmem currently occupied by
 	   the initrd, we rely on that fact to keep the data intact. */
-	reserve_bootmem(ramdisk_here, ramdisk_size, BOOTMEM_DEFAULT);
+	reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
+			 "NEW RAMDISK");
 	initrd_start = ramdisk_here + PAGE_OFFSET;
 	initrd_end   = initrd_start + ramdisk_size;
 
@@ -519,10 +519,10 @@ static void __init reserve_initrd(void)
 
 static void __init relocate_initrd(void)
 {
-	unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
-	unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
-	unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
-	unsigned long ramdisk_here;
+	u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+	u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
+	u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
+	u64 ramdisk_here;
 	unsigned long slop, clen, mapaddr;
 	char *p, *q;
 
@@ -540,6 +540,8 @@ static void __init relocate_initrd(void)
 		memcpy(q, p, clen);
 		q += clen;
 		/* need to free these low pages...*/
+		printk(KERN_INFO "Freeing old partial RAMDISK %08llx-%08llx\n",
+			 ramdisk_image, ramdisk_image + clen - 1);
 		free_bootmem(ramdisk_image, clen);
 		ramdisk_image += clen;
 		ramdisk_size  -= clen;
@@ -560,6 +562,11 @@ static void __init relocate_initrd(void)
 		ramdisk_size  -= clen;
 	}
 	/* high pages is not converted by early_res_to_bootmem */
+	ramdisk_image = boot_params.hdr.ramdisk_image;
+	ramdisk_size  = boot_params.hdr.ramdisk_size;
+	printk(KERN_INFO "Copied RAMDISK from %016llx - %016llx to %08llx - %08llx\n",
+		ramdisk_image, ramdisk_image + ramdisk_size - 1,
+		ramdisk_here, ramdisk_here + ramdisk_size - 1);
 }
 
 #endif /* CONFIG_BLK_DEV_INITRD */
@@ -576,10 +583,17 @@ void __init setup_bootmem_allocator(void
 				 PAGE_SIZE);
 	if (bootmap == -1L)
 		panic("Cannot find bootmem map of size %ld\n", bootmap_size);
+	reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
+#ifdef CONFIG_BLK_DEV_INITRD
+	reserve_initrd();
+#endif
 	bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
+	printk(KERN_INFO "  low ram: %08lx - %08lx\n",
+		 min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
+	printk(KERN_INFO "  bootmap %08lx - %08lx\n",
+		 bootmap, bootmap + bootmap_size);
 	register_bootmem_low_pages(max_low_pfn);
 	early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
-	reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
 
 #ifdef CONFIG_ACPI_SLEEP
 	/*
@@ -593,9 +607,6 @@ void __init setup_bootmem_allocator(void
 	 */
 	find_smp_config();
 #endif
-#ifdef CONFIG_BLK_DEV_INITRD
-	reserve_initrd();
-#endif
 	numa_kva_reserve();
 	reserve_crashkernel();
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] x86: make e820.c to have common functions, Yinghai Lu, (Sun May 11, 12:30 am)
Re: [PATCH] x86: make e820.c to have common functions, Ingo Molnar, (Tue May 13, 6:05 am)
Re: [PATCH] x86: make e820.c to have common functions, Yinghai Lu, (Tue May 13, 10:35 am)
[PATCH] x86: extend e820 ealy_res support 32bit, Yinghai Lu, (Sun May 18, 1:18 am)
[PATCH] x86: move e820_mark_nosave_regions to e820.c, Yinghai Lu, (Tue May 20, 8:10 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix, Jeremy Fitzhardinge, (Thu May 22, 3:12 am)
[PATCH] x86: extend e820 ealy_res support 32bit - fix v2, Yinghai Lu, (Thu May 22, 3:20 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix v2, Jeremy Fitzhardinge, (Fri May 23, 4:32 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix v2, Jeremy Fitzhardinge, (Fri May 23, 4:38 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix v2, Jeremy Fitzhardinge, (Sat May 24, 1:54 am)
[PATCH] xen: boot via i386_start_kernel to get early reser ..., Jeremy Fitzhardinge, (Sat May 24, 2:49 am)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Thomas Gleixner, (Tue May 27, 8:44 am)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Tue May 27, 1:37 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Thomas Gleixner, (Tue May 27, 1:58 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Tue May 27, 2:06 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Tue May 27, 2:22 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Tue May 27, 2:47 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Wed May 28, 3:01 am)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Wed May 28, 2:24 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Thu May 29, 6:37 am)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, H. Peter Anvin, (Thu May 29, 11:58 am)
[PATCH] x86: 32bit numa srat fix early_ioremap leak, Yinghai Lu, (Thu May 29, 4:25 pm)
Re: [PATCH] x86: extend e820 ealy_res support 32bit - fix #2, Jeremy Fitzhardinge, (Fri May 30, 8:50 am)
[PATCH] x86: 32bit numa increase max_elements to 1024, Yinghai Lu, (Sat May 31, 10:51 pm)
[PATCH] x86: set node_remap_size[0] in fallback path, Yinghai Lu, (Sat May 31, 10:53 pm)
[PATCH] x86: numa_32 print out debug info all kva, Yinghai Lu, (Sat May 31, 10:56 pm)
[PATCH] x86: cleanup max_pfn_mapped usage - 32bit, Yinghai Lu, (Sun Jun 1, 11:53 pm)
[PATCH] x86: cleanup max_pfn_mapped usage - 64bit, Yinghai Lu, (Sun Jun 1, 11:55 pm)