x86/microcode: vsnprintf() might be unavailable
Subsystems (2)
PATCH 1/1 x86/microcode: vsnprintf() might be unavailable
On Intel CPUs with x32 kernels we call load_builtin_intel_microcode() from head_32.S on quite earlier stage. At that point sprintf() might be out of scope to be called. As a result the 32-bit kernel does not boot on Intel CPUs. It has been tested on Braswell and Merrifield.
The patch changes sprintf() call to plain code which does the same in this particular case.
--- arch/x86/kernel/cpu/microcode/intel_early.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/microcode/intel_early.c +9 -4
@@ -523,9 +523,9 @@ EXPORT_SYMBOL_GPL(save_mc_for_early);static bool __init load_builtin_intel_microcode (struct cpio_data *cp) { -u32 eax =0x00000001 , ebx, ecx =0 , edx; -int family, model, stepping; -char name[30 ]; +unsigned int eax =0x00000001 , ebx, ecx =0 , edx; +unsigned int family, model, stepping; +char name[30 ] ="intel-ucode" , *p = name +11 ;native_cpuid (&eax, &ebx, &ecx, &edx);
@@ -533,7 +533,12 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp) model =x86_model (eax); stepping = eax &0xf ; -sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping); + *p++ ='/' ; + p =hex_byte_pack (p, family); + *p++ ='-' ; + p =hex_byte_pack (p, model); + *p++ ='-' ; + p =hex_byte_pack (p, stepping);return get_builtin_firmware (cp, name); }
Signature · 1 line
2.1.4
Quoted 3 lines · Andy Shevchenko
On Intel CPUs with x32 kernels we call
load_builtin_intel_microcode()fromhead_32.Son quite earlier stage. At that pointsprintf()might be out of scope to be called.
Hrrm, I don't get that. How can sprintf() be out of scope?
Testing on 32-bit was successful here. How is x32 different?
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Andy Shevchenko
On Intel CPUs with x32 kernels we call
load_builtin_intel_microcode()fromhead_32.Son quite earlier stage. At that pointsprintf()might be out of scope to be called.Hrrm, I don't get that. How can
sprintf()be out of scope?
Initial paging setup is involved? I just sent a small update to previous patch. Please, look at it.
Quoted 2 lines
Testing on 32-bit was successful here. How is x32 different?
Hmm… which Intel CPUs you run on?
Ah, one more thing we run our kernel from kexec (I hope it's not a case, but who knows).
Quoted 3 lines
Thanks.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 1 line · Andy Shevchenko
Initial paging setup is involved?
Yes, load_ucode_bsp happens before paging is enabled on 32-bit. And that should remain that way - we want microcode application as early as possible.
Quoted 1 line
Hmm… which Intel CPUs you run on?
processor : 0vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
stepping : 9
microcode : 0x1b
and an SNB one too.
Quoted 2 lines
Ah, one more thing we run our kernel from kexec (I hope it's not a case, but who knows).
Does it work when you boot a normal 32-bit kernel with builtin microcode on it?
In order to load built-in microcode, you'll have to enable the boot options in the commit message to
760d765b2bb6 ("x86/microcode: Parse built-in microcode early")
Let me know if something's not clear.
Quoted 15 lines · Andy Shevchenko
arch/x86/kernel/cpu/microcode/intel_early.c static bool __init load_builtin_intel_microcode(struct cpio_data *cp) · line 542
Quoted 12 lines
arch/x86/kernel/cpu/microcode/intel_early.c +6
-1@@ -533,7 +533,12 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp) model =x86_model (eax); stepping = eax &0xf ; -sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping); + *p++ ='/' ; + p =hex_byte_pack (p, family); + *p++ ='-' ; + p =hex_byte_pack (p, model); + *p++ ='-' ; + p =hex_byte_pack (p, stepping);Forgot to add *p = '\0'; here, but it doesn't really mater for the idea.
Quoted 2 lines
What I would like to tell that if I move 'call
load_ucode_bsp' after paging is done, it seemssprintf()starts working nicely.
Hmm, ok, so something's not able to stomach pre-paging. Can you dump something from the failure, RIP, stack, whatever?
Can I reproduce it?
Quoted 1 line
So, I don't know which fix is better (or neither),
See above.
Quoted 1 line
and wondering if we need to fix AMD part.
No need, AFAICT. It did work in my testing.
Quoted 2 lines
P.S. It would be really nice to get an expert / detailed explanation what is going on there.
Yeah, that's why I'm asking.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 17 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko
Initial paging setup is involved?
Yes,
load_ucode_bsphappens before paging is enabled on 32-bit. And that should remain that way - we want microcode application as early as possible.Quoted 1 line
Hmm… which Intel CPUs you run on?
processor : 0
vendor_id: GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
stepping : 9
microcode :0x1b
Quoted 1 line
and an SNB one too.
Now at home already.
Will check tomorrow what we have.
Quoted 6 lines
Quoted 3 lines
Ah, one more thing we run our kernel from kexec (I hope it's not a case, but who knows).
Does it work when you boot a normal 32-bit kernel with builtin microcode on it?
Ditto.
Quoted 7 lines
In order to load built-in microcode, you'll have to enable the boot options in the commit message to
760d765b2bb6("x86/microcode: Parse built-in microcode early")Let me know if something's not clear.
We are using slightly different (to upstream) i386_defconfig with some devices enabled like serial console. As environment the Buildroot is used with uclibc and busybox. No extra microcode is enabled.
By default as far as I remember the FIRMWARE* is set to y for all options.
Quoted 16 lines · Andy Shevchenko
Quoted 15 lines
arch/x86/kernel/cpu/microcode/intel_early.c static bool __init load_builtin_intel_microcode(struct cpio_data *cp) · line 542
Quoted 12 lines
arch/x86/kernel/cpu/microcode/intel_early.c +6
-1@@ -533,7 +533,12 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp) model =x86_model (eax); stepping = eax &0xf ; -sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping); + *p++ ='/' ; + p =hex_byte_pack (p, family); + *p++ ='-' ; + p =hex_byte_pack (p, model); + *p++ ='-' ; + p =hex_byte_pack (p, stepping);Forgot to add *p = '\0'; here, but it doesn't really mater for the idea.
Quoted 5 lines
Quoted 2 lines
What I would like to tell that if I move 'call
load_ucode_bsp' after paging is done, it seemssprintf()starts working nicely.Hmm, ok, so something's not able to stomach pre-paging. Can you dump something from the failure, RIP, stack, whatever?
I have a totally empty screen (serial console). So, if you teach me how to gather that I could do it later on.
Quoted 2 lines
Can I reproduce it?
I can send our defconfig and kexec command line for sure.
[]
Quoted 3 lines
Quoted 1 line
and wondering if we need to fix AMD part.
No need, AFAICT. It did work in my testing.
Ok. We have no AMD here :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 1 line · Andy Shevchenko
Ditto.
"Ditto" means it doesn't work booting a normal 32-bit kernel too?
Quoted 2 lines
I have a totally empty screen (serial console). So, if you teach me how to gather that I could do it later on.
That'll be hard - you'd probably need a hardware debugger or something special to get a RIP or other data that early... Or hack up some very early console printing with BIOS methods and so on. hpa had something like that somewhere AFAIR...
Quoted 1 line
I can send our defconfig and kexec command line for sure.
Yes please.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 4 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko
Ditto.
"Ditto" means it doesn't work booting a normal 32-bit kernel too?
Ditto, meant to test when I will be at work again :-)
But, unfortunately it doesn't. I did two images of next-20150602 with and without this patch and 100% success and failure respectively (do each test twice).
I have tested with 32-bit kernel run as EFI 32 binary from EFI Shell on ASuS T100TA (Intel BayTrail-T):
processor : 0vendor_id : GenuineIntel
cpu family : 6
model : 55
model name : Intel(R) Atom(TM) CPU Z3740 @ 1.33GHz
stepping : 3
microcode : 0x31e
cpu MHz : 1330.000
Quoted 7 lines
Quoted 2 lines
I have a totally empty screen (serial console). So, if you teach me how to gather that I could do it later on.
That'll be hard - you'd probably need a hardware debugger or something special to get a RIP or other data that early... Or hack up some very early console printing with BIOS methods and so on. hpa had something like that somewhere AFAIR...
I could try kvm / qemu as well, though there might be not the same conditions.
Quoted 3 lines
Quoted 1 line
I can send our defconfig and kexec command line for sure.
Yes please.
Here is the difference to the i386_defconfig as in next-20150602:
(quoted diff) +0 -0
b/arch/x86/configs/i386_defconfig
index aaa1118..7579120 100644
arch/x86/configs/i386_defconfig +57 -4
82 lines not on this page · raw message
kexec command:
kexec -l $bootdir/vmlinuz --initrd $bootdir/initrd --command-line="$cmdline"
cmdline (in case of kexec the acpi_rdsp=0xdeadbeaf is added, 0xdeadbeaf not an actual address):
console=tty1 console=ttyS0,115200n8 ignore_loglevel spidev.bufsiz=8192
P.S. I could test any configuration you suppose if it's needed.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines
Quoted 2 lines
I have a totally empty screen (serial console). So, if you teach me how to gather that I could do it later on.
That'll be hard - you'd probably need a hardware debugger or something special to get a RIP or other data that early... Or hack up some very early console printing with BIOS methods and so on. hpa had something like that somewhere AFAIR...
I could try kvm / qemu as well, though there might be not the same conditions.
Yeah, qemu runs fine.
Signature · 13 lines
Andy Shevchenko <[email protected]> Intel Finland Oy --------------------------------------------------------------------- Intel Finland Oy Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 - 4 Domiciled in Helsinki This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 9 lines · Andriy
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines
Quoted 2 lines
I have a totally empty screen (serial console). So, if you teach me how to gather that I could do it later on.
That'll be hard - you'd probably need a hardware debugger or something special to get a RIP or other data that early... Or hack up some very early console printing with BIOS methods and so on. hpa had something like that somewhere AFAIR...
Quoted 4 lines
Quoted 2 lines
I could try kvm / qemu as well, though there might be not the same conditions.
Yeah, qemu runs fine.
So, I did some more experiments and even if we build the string properly, we choke later in get_builtin_firmware(). Actually, we don't choke but we don't find firwmare because we're running with physical addresses and those __start/__stop_builtin_fw things are virtual addresses. Yuck!
So I'm gravitating towards disabling builtin microcode loading on 32-bit. For now, as the merge window is going to be open soon, until we/I have fixed it properly. And I don't have a clear solution now - all I can think of is ugly ifdeffery which I'd like to avoid.
Grrr.
---
arch/x86/kernel/cpu/microcode/amd_early.c +4 -0
@@ -230,6 +230,7 @@ static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)static bool __init load_builtin_amd_microcode (struct cpio_data *cp,int family) { +#ifdef CONFIG_X86_64 char fw_name[36 ] ="amd-ucode/microcode_amd.bin" ;if (family >=0x15 )
@@ -237,6 +238,9 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp, int family) "amd-ucode/microcode_amd_fam%.2xh.bin", family);return get_builtin_firmware (cp, fw_name); +#else +return false; +#endif }void __init load_ucode_amd_bsp (int family)
arch/x86/kernel/cpu/microcode/intel_early.c +4 -0
@@ -523,6 +523,7 @@ EXPORT_SYMBOL_GPL(save_mc_for_early);static bool __init load_builtin_intel_microcode (struct cpio_data *cp) { +#ifdef CONFIG_X86_64 u32 eax =0x00000001 , ebx, ecx =0 , edx;int family, model, stepping;char name[30 ];
@@ -536,6 +537,9 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp)sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping);return get_builtin_firmware (cp, name); +#else +return false; +#endif }static __initdata char ucode_name[] ="kernel/x86/microcode/GenuineIntel.bin" ;
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--PATCH 1/1 x86/microcode: Disable builtin microcode loading on 32-bit for now
Ok, here's an actual patch. I'm very sorry for the confusion and big thanks guys for catching it on time, before it hits the merge window!
Much appreciated. :-D
---
From: Borislav Petkov <[email protected]>
Date: Thu, 4 Jun 2015 09:52:37 +0200
Subject: [PATCH] x86/microcode: Disable builtin microcode loading on 32-bit for now
Andy Shevchenko reported machine freezes when booting latest tip on x32 setups. Problem is, the builtin microcode handling cannot really work that early, when we haven't even enabled paging. A proper fix would involve handling that case specially as every other early 32-bit boot case in the microcode loader and would require much more involved changes for which it is too late now, more than a week before the upcoming merge window.
So, disable the builtin microcode loading only on 32-bit for now.
Signed-off-by:
--- arch/x86/kernel/cpu/microcode/amd_early.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel_early.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/x86/kernel/cpu/microcode/amd_early.c +4 -0
@@ -230,6 +230,7 @@ static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)static bool __init load_builtin_amd_microcode (struct cpio_data *cp,int family) { +#ifdef CONFIG_X86_64 char fw_name[36 ] ="amd-ucode/microcode_amd.bin" ;if (family >=0x15 )
@@ -237,6 +238,9 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp, int family) "amd-ucode/microcode_amd_fam%.2xh.bin", family);return get_builtin_firmware (cp, fw_name); +#else +return false; +#endif }void __init load_ucode_amd_bsp (int family)
arch/x86/kernel/cpu/microcode/intel_early.c +4 -0
@@ -523,6 +523,7 @@ EXPORT_SYMBOL_GPL(save_mc_for_early);static bool __init load_builtin_intel_microcode (struct cpio_data *cp) { +#ifdef CONFIG_X86_64 u32 eax =0x00000001 , ebx, ecx =0 , edx;int family, model, stepping;char name[30 ];
@@ -536,6 +537,9 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp)sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping);return get_builtin_firmware (cp, name); +#else +return false; +#endif }static __initdata char ucode_name[] ="kernel/x86/microcode/GenuineIntel.bin" ;
Signature · 9 lines
2.3.5
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH] x86/microcode: Disable builtin microcode loading on 32-bit for now
Quoted 4 lines · Borislav Petkov
Ok, here's an actual patch. I'm very sorry for the confusion and big thanks guys for catching it on time, before it hits the merge window!
Much appreciated. :-D
Thanks!
Quoted 73 lines
---
From: Borislav Petkov <[email protected]>
Date: Thu, 4 Jun 2015 09:52:37 +0200
Subject: [PATCH] x86/microcode: Disable builtin microcode loading on 32-bit for nowAndy Shevchenko reported machine freezes when booting latest tip on x32 setups. Problem is, the builtin microcode handling cannot really work that early, when we haven't even enabled paging. A proper fix would involve handling that case specially as every other early 32-bit boot case in the microcode loader and would require much more involved changes for which it is too late now, more than a week before the upcoming merge window.
So, disable the builtin microcode loading only on 32-bit for now.
Reported-by Andy Shevchenko <[email protected]>Cc Mika Westerberg <[email protected]>Cc <[email protected]>Signed-off-by:
--- arch/x86/kernel/cpu/microcode/amd_early.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel_early.c | 4 ++++ 2 files changed, 8 insertions(+)arch/x86/kernel/cpu/microcode/amd_early.c +4
-0@@ -230,6 +230,7 @@ static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)static bool __init load_builtin_amd_microcode (struct cpio_data *cp,int family) { +#ifdef CONFIG_X86_64 char fw_name[36 ] ="amd-ucode/microcode_amd.bin" ;if (family >=0x15 )@@ -237,6 +238,9 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp, int family) "amd-ucode/microcode_amd_fam%.2xh.bin", family);return get_builtin_firmware (cp, fw_name); +#else +return false; +#endif }void __init load_ucode_amd_bsp (int family)arch/x86/kernel/cpu/microcode/intel_early.c +4
-0@@ -523,6 +523,7 @@ EXPORT_SYMBOL_GPL(save_mc_for_early);static bool __init load_builtin_intel_microcode (struct cpio_data *cp) { +#ifdef CONFIG_X86_64 u32 eax =0x00000001 , ebx, ecx =0 , edx;int family, model, stepping;char name[30 ];@@ -536,6 +537,9 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp)sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping);return get_builtin_firmware (cp, name); +#else +return false; +#endif }static __initdata char ucode_name[] ="kernel/x86/microcode/GenuineIntel.bin" ;Signature · 1 line
2.3.5
Signature · 13 lines
Andy Shevchenko <[email protected]> Intel Finland Oy --------------------------------------------------------------------- Intel Finland Oy Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 - 4 Domiciled in Helsinki This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
[+ Mika, who also somehow involved in the investigation]
Quoted 5 lines · Andy Shevchenko
On Intel CPUs with x32 kernels we call
load_builtin_intel_microcode()fromhead_32.Son quite earlier stage. At that pointsprintf()might be out of scope to be called. As a result the 32-bit kernel does not boot on Intel CPUs. It has been tested on Braswell and Merrifield.
Small update below.
Quoted 13 lines
The patch changes
sprintf()call to plain code which does the same in this particular case.Signed-off-by Andy Shevchenko <[email protected]>--- arch/x86/kernel/cpu/microcode/intel_early.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)arch/x86/kernel/cpu/microcode/intel_early.c +0
-0
arch/x86/kernel/cpu/microcode/intel_early.c EXPORT_SYMBOL_GPL(save_mc_for_early); · line 527
Quoted 8 lines
arch/x86/kernel/cpu/microcode/intel_early.c +2
-3@@ -523,9 +523,9 @@ EXPORT_SYMBOL_GPL(save_mc_for_early);static bool __init load_builtin_intel_microcode (struct cpio_data *cp) { -u32 eax =0x00000001 , ebx, ecx =0 , edx; -int family, model, stepping; -char name[30 ]; +unsigned int eax =0x00000001 , ebx, ecx =0 , edx; +unsigned int family, model, stepping;
Change types to be in align with function prototypes.
Quoted 6 lines
arch/x86/kernel/cpu/microcode/intel_early.c +1
-0+char name[30 ] ="intel-ucode" , *p = name +11 ;native_cpuid (&eax, &ebx, &ecx, &edx);@@ -533,7 +533,12 @@ static bool __init load_builtin_intel_microcode(struct cpio_data *cp) model =x86_model (eax);
arch/x86/kernel/cpu/microcode/intel_early.c static bool __init load_builtin_intel_microcode(struct cpio_data *cp) · line 542
Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel_early.c +6
-1stepping = eax &0xf ; -sprintf (name,"intel-ucode/%02x-%02x-%02x" , family, model, stepping); + *p++ ='/' ; + p =hex_byte_pack (p, family); + *p++ ='-' ; + p =hex_byte_pack (p, model); + *p++ ='-' ; + p =hex_byte_pack (p, stepping);
Forgot to add *p = '\0'; here, but it doesn't really mater for the idea.
What I would like to tell that if I move 'call load_ucode_bsp' after paging is done, it seems sprintf() starts working nicely. So, I don't know which fix is better (or neither), and wondering if we need to fix AMD part.
Please, share your opinions, suggestions.
P.S. It would be really nice to get an expert / detailed explanation what is going on there.
Quoted 2 lines
arch/x86/kernel/cpu/microcode/intel_early.c +0
-0return get_builtin_firmware (cp, name); }
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy