Skip to contentSkip to conversation

x86: Find correct 64 bit ramdisk address for microcode early update

PATCH Superseded Yinghai Lu 2 participants 8 messages Jun 11, 2014 – Jul 1, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86: Find correct 64 bit ramdisk address for microcode early update

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

---
 arch/x86/include/asm/setup.h                |    3 +++
 arch/x86/kernel/cpu/microcode/amd_early.c   |   10 +++++-----
 arch/x86/kernel/cpu/microcode/intel_early.c |    8 ++++----
 arch/x86/kernel/setup.c                     |   28 ++++++++++++++--------------
 4 files changed, 26 insertions(+), 23 deletions(-)
arch/x86/include/asm/setup.h +3 -0
Index: linux-2.6/arch/x86/include/asm/setup.h
===================================================================
@@ -105,6 +105,9 @@ void *extend_brk(size_t size, size_t ali
 	RESERVE_BRK(name, sizeof(type) * entries)
 
 extern void probe_roms(void);
+u64 get_ramdisk_image(struct boot_params *bp);
+u64 get_ramdisk_size(struct boot_params *bp);
+
 #ifdef __i386__
 
 asmlinkage void __init i386_start_kernel(void);
arch/x86/kernel/cpu/microcode/amd_early.c +5 -5
Index: linux-2.6/arch/x86/kernel/cpu/microcode/amd_early.c
===================================================================
@@ -51,12 +51,12 @@ static struct cpio_data __init find_ucod
 	 */
 	p       = (struct boot_params *)__pa_nodebug(&boot_params);
 	path    = (char *)__pa_nodebug(ucode_path);
-	start   = (void *)p->hdr.ramdisk_image;
-	size    = p->hdr.ramdisk_size;
+	start   = (void *)(unsigned long)get_ramdisk_image(p);
+	size    = get_ramdisk_size(p);
 #else
 	path    = ucode_path;
-	start   = (void *)(boot_params.hdr.ramdisk_image + PAGE_OFFSET);
-	size    = boot_params.hdr.ramdisk_size;
+	start   = (void *)(get_ramdisk_image(&boot_params) + PAGE_OFFSET);
+	size    = get_ramdisk_size(&boot_params);
 #endif
 
 	return find_cpio_data(path, start, size, &offset);
@@ -371,7 +371,7 @@ int __init save_microcode_in_initrd_amd(
 	 */
 	if (relocated_ramdisk)
 		container = (u8 *)(__va(relocated_ramdisk) +
-			     (cont - boot_params.hdr.ramdisk_image));
+			     (cont - get_ramdisk_size(&boot_params)));
 
 	if (ucode_new_rev)
 		pr_info("microcode: updated early to new patch_level=0x%08x\n",
arch/x86/kernel/cpu/microcode/intel_early.c +4 -4
Index: linux-2.6/arch/x86/kernel/cpu/microcode/intel_early.c
===================================================================
@@ -733,8 +733,8 @@ load_ucode_intel_bsp(void)
 	struct boot_params *boot_params_p;
 
 	boot_params_p = (struct boot_params *)__pa_nodebug(&boot_params);
-	ramdisk_image = boot_params_p->hdr.ramdisk_image;
-	ramdisk_size  = boot_params_p->hdr.ramdisk_size;
+	ramdisk_image = get_ramdisk_image(boot_params_p);
+	ramdisk_size  = get_ramdisk_size(boot_params_p);
 	initrd_start_early = ramdisk_image;
 	initrd_end_early = initrd_start_early + ramdisk_size;
 
@@ -743,8 +743,8 @@ load_ucode_intel_bsp(void)
 		(unsigned long *)__pa_nodebug(&mc_saved_in_initrd),
 		initrd_start_early, initrd_end_early, &uci);
 #else
-	ramdisk_image = boot_params.hdr.ramdisk_image;
-	ramdisk_size  = boot_params.hdr.ramdisk_size;
+	ramdisk_image = get_ramdisk_image(&boot_params);
+	ramdisk_size  = get_ramdisk_size(&boot_params);
 	initrd_start_early = ramdisk_image + PAGE_OFFSET;
 	initrd_end_early = initrd_start_early + ramdisk_size;
 
arch/x86/kernel/setup.c +14 -14
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -299,19 +299,19 @@ u64 relocated_ramdisk;
 
 #ifdef CONFIG_BLK_DEV_INITRD
 
-static u64 __init get_ramdisk_image(void)
+u64 __init get_ramdisk_image(struct boot_params *bp)
 {
-	u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+	u64 ramdisk_image = bp->hdr.ramdisk_image;
 
-	ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
+	ramdisk_image |= (u64)bp->ext_ramdisk_image << 32;
 
 	return ramdisk_image;
 }
-static u64 __init get_ramdisk_size(void)
+u64 __init get_ramdisk_size(struct boot_params *bp)
 {
-	u64 ramdisk_size = boot_params.hdr.ramdisk_size;
+	u64 ramdisk_size = bp->hdr.ramdisk_size;
 
-	ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
+	ramdisk_size |= (u64)bp->ext_ramdisk_size << 32;
 
 	return ramdisk_size;
 }
@@ -320,8 +320,8 @@ static u64 __init get_ramdisk_size(void)
 static void __init relocate_initrd(void)
 {
 	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
+	u64 ramdisk_image = get_ramdisk_image(&boot_params);
+	u64 ramdisk_size  = get_ramdisk_size(&boot_params);
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 	unsigned long slop, clen, mapaddr;
 	char *p, *q;
@@ -359,8 +359,8 @@ static void __init relocate_initrd(void)
 		ramdisk_size  -= clen;
 	}
 
-	ramdisk_image = get_ramdisk_image();
-	ramdisk_size  = get_ramdisk_size();
+	ramdisk_image = get_ramdisk_image(&boot_params);
+	ramdisk_size  = get_ramdisk_size(&boot_params);
 	printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
 		" [mem %#010llx-%#010llx]\n",
 		ramdisk_image, ramdisk_image + ramdisk_size - 1,
@@ -370,8 +370,8 @@ static void __init relocate_initrd(void)
 static void __init early_reserve_initrd(void)
 {
 	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
+	u64 ramdisk_image = get_ramdisk_image(&boot_params);
+	u64 ramdisk_size  = get_ramdisk_size(&boot_params);
 	u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
 
 	if (!boot_params.hdr.type_of_loader ||
@@ -383,8 +383,8 @@ static void __init early_reserve_initrd(
 static void __init reserve_initrd(void)
 {
 	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
+	u64 ramdisk_image = get_ramdisk_image(&boot_params);
+	u64 ramdisk_size  = get_ramdisk_size(&boot_params);
 	u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
 	u64 mapped_size;
 
#1 lore raw
Quoted 9 lines · Yinghai Lu

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

Have you tested this with early microcode loading on a 32-bit kernel?

-hpa

author
#2 lore raw
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Yinghai Lu

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Quoted 9 lines
Quoted 6 lines

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

Have you tested this with early microcode loading on a 32-bit kernel?

No, I did not test that on a 32bit kernel. We did not enabled ramdisk loading high
above 4G, right?

Do you want to me to drop changes for 32 bit path (under those MARCO)? like:
+++ linux-2.6/arch/x86/kernel/cpu/
microcode/amd_early.c
@@ -51,12 +51,12 @@ static struct cpio_data __init find_ucod

         */
        p       = (struct boot_params *)__pa_nodebug(&boot_params);
        path    = (char *)__pa_nodebug(ucode_path);
-       start   = (void *)p->hdr.ramdisk_image;
-       size    = p->hdr.ramdisk_size;
+       start   = (void *)(unsigned long)get_ramdisk_image(p);
+       size    = get_ramdisk_size(p);

+++ linux-2.6/arch/x86/kernel/cpu/microcode/intel_early.c

        boot_params_p = (struct boot_params *)__pa_nodebug(&boot_params);
-       ramdisk_image = boot_params_p->hdr.ramdisk_
image;
-       ramdisk_size  = boot_params_p->hdr.ramdisk_size;
+       ramdisk_image = get_ramdisk_image(boot_params_p);
+       ramdisk_size  = get_ramdisk_size(boot_params_p);
        initrd_start_early = ramdisk_image;
        initrd_end_early = initrd_start_early + ramdisk_size;

BTW, Is there any 32bit bootloader that could load ramdisk above 4G?

Thanks

Yinghai

#3 lore raw
Quoted 43 lines · Yinghai Lu
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Yinghai Lu

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Quoted 9 lines
Quoted 6 lines

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

Have you tested this with early microcode loading on a 32-bit kernel?

No, I did not test that on a 32bit kernel. We did not enabled ramdisk loading high
above 4G, right?

Do you want to me to drop changes for 32 bit path (under those MARCO)? like:
+++ linux-2.6/arch/x86/kernel/cpu/
microcode/amd_early.c

(quoted diff) +5 -4
@@ -51,12 +51,12 @@ static struct cpio_data __init find_ucod
         */
        p       = (struct boot_params *)__pa_nodebug(&boot_params);
        path    = (char *)__pa_nodebug(ucode_path);
-       start   = (void *)p->hdr.ramdisk_image;
-       size    = p->hdr.ramdisk_size;
+       start   = (void *)(unsigned long)get_ramdisk_image(p);
+       size    = get_ramdisk_size(p);
 
+++ linux-2.6/arch/x86/kernel/cpu/microcode/intel_early.c
 
        boot_params_p = (struct boot_params *)__pa_nodebug(&boot_params);
-       ramdisk_image = boot_params_p->hdr.ramdisk_
 image;
-       ramdisk_size  = boot_params_p->hdr.ramdisk_size;
+       ramdisk_image = get_ramdisk_image(boot_params_p);
+       ramdisk_size  = get_ramdisk_size(boot_params_p);
        initrd_start_early = ramdisk_image;
        initrd_end_early = initrd_start_early + ramdisk_size;
Quoted 2 lines

BTW, Is there any 32bit bootloader that could load ramdisk above 4G?

It is not about loading over 4G, it is that some kinds of code (in particular accessing global variables) from the early microcode loading code doesn't work on 32 bits, so it needs to be tested.

-hpa

author
#4 lore raw
Quoted 4 lines · H. Peter Anvin

It is not about loading over 4G, it is that some kinds of code (in particular accessing global variables) from the early microcode loading code doesn't work on 32 bits, so it needs to be tested.

Ok, will test 32bit path.

Thanks

Yinghai

author
#5 lore raw
Quoted 7 lines · Yinghai Lu
Quoted 4 lines · H. Peter Anvin

It is not about loading over 4G, it is that some kinds of code (in particular accessing global variables) from the early microcode loading code doesn't work on 32 bits, so it needs to be tested.

Ok, will test 32bit path.

Hi Peter,

Just checked, 32bit path works with the patch.
To be exactly Intel 32bit path works.

Thanks

Yinghai

#6 lore raw
In reply to Yinghai Lu
Quoted 7 lines · Yinghai Lu

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

Please update your patch description to explain what "different usage" you have in mind here.

-hpa

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

When using kexec with 64bit kernel, bzImage and ramdisk could be loaded above 4G. We need this to get correct ramdisk adress.

Make get_ramdisk_image() global and use it for early microcode updating. Also make it to take boot_params pointer for different usage.

Please update your patch description to explain what "different usage" you have in mind here.

oh, no. I should drop that line. That is left over for parsing acpi/srat patchset.

Thanks

Yinghai