x86/MCE: Get microcode revision from cpu_info instead of boot_cpu_data
Subsystems (4)
PATCH 1/1 x86/MCE: Get microcode revision from cpu_info instead of boot_cpu_data
Commit fa94d0c6e0f3 ("x86/MCE: Save microcode revision in machine check records") extended MCE entries to report the microcode revision taken from boot_cpu_data. Unfortunately, boot_cpu_data isn't updated on late microcode loading, thus making MCE entries slightly incorrect. Use cpu_info instead, which is updated on late microcode loading.
--- arch/x86/kernel/cpu/mcheck/mce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
@@ -134,7 +134,7 @@ void mce_setup(struct mce *m)if (this_cpu_has (X86_FEATURE_INTEL_PPIN ))rdmsrl (MSR_PPIN , m->ppin); - m->microcode = boot_cpu_data.microcode; + m->microcode =cpu_data (m->extcpu).microcode; } DEFINE_PER_CPU(struct mce, injectm);
Borislav Petkov
maintainerQuoted 4 lines · Filippo Sironi
Commit
fa94d0c6e0f3("x86/MCE: Save microcode revision in machine check records") extended MCE entries to report the microcode revision taken fromboot_cpu_data. Unfortunately,boot_cpu_dataisn't updated on late microcode loading,
Actually, I'd prefer if we fixed *that* instead by adding:
/* Update boot_cpu_data's revision too, if we're on the BSP: */ if (c->cpu_index == boot_cpu_data.cpu_index) boot_cpu_data.microcode = <new rev>;
to the end of ->apply_microcode() functions so that boot_cpu_data has the correct revision too, in case something else queries it.
Thx.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Filippo Sironi
Commit
fa94d0c6e0f3("x86/MCE: Save microcode revision in machine check records") extended MCE entries to report the microcode revision taken fromboot_cpu_data. Unfortunately,boot_cpu_dataisn't updated on late microcode loading,Actually, I'd prefer if we fixed *that* instead by adding:
Quoted 15 lines
/* Update boot_cpu_data's revision too, if we're on the BSP: */ if (c->cpu_index == boot_cpu_data.cpu_index) boot_cpu_data.microcode = <new rev>;to the end of ->apply_microcode() functions so that
boot_cpu_datahas the correct revision too, in case something else queries it.Thx.
Signature · 5 lines
Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --
I've that patch in my tree already, I can post it.
I'm still curious on why you'd prefer to use boot_cpu_data for all CPUs instead of using cpu_data(m->extcpu) though.
Regards,
Filippo
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Borislav Petkov
maintainerQuoted 3 lines · Filippo
I've that patch in my tree already, I can post it.
I'm still curious on why you'd prefer to useboot_cpu_datafor all CPUs instead of usingcpu_data(m->extcpu)though.
Well, for starters, boot_cpu_data having stale revision is a bug in itself already. So fixing that is already the Right Thing(tm) to do.
Then, one fine day when the whole cpu_data mess is cleaned up, boot_cpu_data will morph into the global descriptor representing CPU features and keeping it uptodate now will facilitate the replacement without introducing bugs.
PATCH 1/1 arch/x86: Fix boot_cpu_data.microcode version output
In reply to Borislav PetkovOn systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/x86/kernel/cpu/microcode/amd.c +4 -0
@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
arch/x86/kernel/cpu/microcode/intel.c +4 -0
@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
Re: [PATCH] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 22 lines · Prarit Bhargava
On systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
Fixes fa94d0c6e0f3 ("x86/MCE: Save microcode revision in machine check records")Suggested-by Borislav Petkov <[email protected]>Signed-off-by Prarit Bhargava <[email protected]>--- arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)arch/x86/kernel/cpu/microcode/amd.c +0
-0
arch/x86/kernel/cpu/microcode/amd.c static enum ucode_state apply_microcode_amd(int cpu) · line 543
Quoted 7 lines
arch/x86/kernel/cpu/microcode/amd.c +4
-0@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +
Borislav, hold off on this. I want to double check something with AMD.
I think this has to be
boot_cpu_data.microcode = mc_amd->hdr.patch_id;
I'm going to grab some old/new microcode and test. I do know that the Intel update below works.
P.
Quoted 9 lines
arch/x86/kernel/cpu/microcode/amd.c +0
-0return UCODE_UPDATED ; }arch/x86/kernel/cpu/microcode/intel.c +0
-0
arch/x86/kernel/cpu/microcode/intel.c static enum ucode_state apply_microcode_intel(int cpu) · line 860
Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +4
-0@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Borislav Petkov
maintainerRe: [PATCH] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 3 lines · Prarit Bhargava
I think this has to be
boot_cpu_data.microcode = mc_amd->hdr.patch_id;
Yes, it does.
PATCH v2 1/1 arch/x86: Fix boot_cpu_data.microcode version output
In reply to Borislav PetkovI tested this on AMD Ryzen & Intel Broadwell system and dumped the boot_cpu_data before and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.
P.
---8<---
On systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
---
Changes in v2: Use mc_amd->hdr.patch_id on AMD
arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/x86/kernel/cpu/microcode/amd.c +4 -0
@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; +return UCODE_UPDATED ; }
arch/x86/kernel/cpu/microcode/intel.c +4 -0
@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 50 lines · Prarit Bhargava
I tested this on AMD Ryzen & Intel Broadwell system and dumped the
boot_cpu_databefore and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.P.
---8<---
On systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
Fixes fa94d0c6e0f3 ("x86/MCE: Save microcode revision in machine check records")Suggested-by Borislav Petkov <[email protected]>Signed-off-by Prarit Bhargava <[email protected]>---
Changes in v2: Usemc_amd->hdr.patch_idon AMD
arch/x86/kernel/cpu/microcode/amd.c| 4 ++++arch/x86/kernel/cpu/microcode/intel.c| 4 ++++2 files changed, 8 insertions(+)arch/x86/kernel/cpu/microcode/amd.c +4
-0@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; +return UCODE_UPDATED ; }arch/x86/kernel/cpu/microcode/intel.c +0
-0
arch/x86/kernel/cpu/microcode/intel.c static enum ucode_state apply_microcode_intel(int cpu) · line 859
Quoted 9 lines
arch/x86/kernel/cpu/microcode/intel.c +4
-0@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
There may be a chance of skipping this code, I think.
If the microcode is loaded on the hyperthread sibling of the boot cpu before being loaded on the boot cpu, the boot cpu will exit earlier from apply_microcode_intel() - in if (rev >= mc->hdr.rev) { ... }.
(This seems to be possible in apply_microcode_amd() as well.)
In my tree with the aforementioned change - Intel only - I also had the following patch:
which prevents the issue.
Quoted 4 lines
Signature · 1 line
2.17.0
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
arch/x86/kernel/cpu/microcode/intel.c +6 -4
@@ -797,6 +797,7 @@ static enum ucode_state apply_microcode_intel(int cpu)struct microcode_intel *mc;static int prev_rev;u32 rev; +enum ucode_state ret;/* We should bind the task to the CPU */ if (WARN_ON (raw_smp_processor_id () != cpu))
@@ -817,9 +818,8 @@ static enum ucode_state apply_microcode_intel(int cpu)*/ rev =intel_get_microcode_revision ();if (rev >= mc->hdr.rev) { - uci->cpu_sig.rev = rev; - c->microcode = rev; -return UCODE_OK ; + ret =UCODE_OK ; + goto out; }/*
@@ -848,10 +848,12 @@ static enum ucode_state apply_microcode_intel(int cpu) prev_rev = rev; } + ret =UCODE_UPDATED ; +out: uci->cpu_sig.rev = rev; c->microcode = rev; -return UCODE_UPDATED ; +return ret; } static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
Borislav Petkov
maintainerRe: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 10 lines · Filippo
There may be a chance of skipping this code, I think.
If the microcode is loaded on the hyperthread sibling of the boot cpu before being loaded on the boot cpu, the boot cpu will exit earlier from
apply_microcode_intel()- in if (rev >=mc->hdr.rev) { ... }.(This seems to be possible in
apply_microcode_amd()as well.)In my tree with the aforementioned change - Intel only - I also had the following patch:
Yap, good catch.
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 9 lines · Borislav Petkov
Quoted 6 lines · Filippo
There may be a chance of skipping this code, I think.
If the microcode is loaded on the hyperthread sibling of the boot cpu before being loaded on the boot cpu, the boot cpu will exit earlier from
apply_microcode_intel()- in if (rev >=mc->hdr.rev) { ... }.
Quoted 14 lines
Quoted 4 lines
(This seems to be possible in
apply_microcode_amd()as well.)In my tree with the aforementioned change - Intel only - I also had the following patch:
Yap, good catch.
Signature · 5 lines
Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --
Boris, Prarit,
I've sent the patch the I had in my tree and extended it to cover apply_microcode_amd(). I don't have an AMD host available for testing, can one of you give that a spin?
Thanks,
Filippo
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
In reply to Prarit BhargavaHi.
Quoted 61 lines
I tested this on AMD Ryzen & Intel Broadwell system and dumped the
boot_cpu_databefore and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.P.
---8<---
On systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
Fixes fa94d0c6e0f3 ("x86/MCE: Save microcode revision in machine check records")Suggested-by Borislav Petkov <[email protected]>Signed-off-by Prarit Bhargava <[email protected]>---
Changes in v2: Usemc_amd->hdr.patch_idon AMDarch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)arch/x86/kernel/cpu/microcode/amd.c +4
-0@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; +return UCODE_UPDATED ; }arch/x86/kernel/cpu/microcode/intel.c +4
-1@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; } --
Quoted 1 line
2.17.0
After this patch, do we preserve an original microcode version somewhere? If no, why? Sometimes it is useful while debugging another crash because of faulty microcode.
Thanks.
Signature · 1 line
Oleksandr Natalenko (post-factum)
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 62 lines · Oleksandr Natalenko
Hi.
Quoted 60 lines
I tested this on AMD Ryzen & Intel Broadwell system and dumped the
boot_cpu_databefore and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.P.
---8<---
On systems where a runtime microcode update has occurred the microcode version output in a MCE log record is wrong because boot_cpu_data.microcode is not updated during runtime.
Update boot_cpu_data.microcode when the BSP's microcode is updated.
Fixes fa94d0c6e0f3 ("x86/MCE: Save microcode revision in machine check records")Suggested-by Borislav Petkov <[email protected]>Signed-off-by Prarit Bhargava <[email protected]>---
Changes in v2: Usemc_amd->hdr.patch_idon AMDarch/x86/kernel/cpu/microcode/amd.c | 4 ++++
arch/x86/kernel/cpu/microcode/intel.c | 4 ++++2 files changed, 8 insertions(+)arch/x86/kernel/cpu/microcode/amd.c +4
-0@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; + /* Update boot_cpu_data's revision too, if we're on the BSP: */ + if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; + return UCODE_UPDATED; }arch/x86/kernel/cpu/microcode/intel.c +4
-0@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; + /* Update boot_cpu_data's revision too, if we're on the BSP: */ + if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; + return UCODE_UPDATED; }
Quoted 7 lines
Quoted 2 lines
Signature · 1 line
2.17.0After this patch, do we preserve an original microcode version somewhere? If no, why? Sometimes it is useful while debugging another crash because of faulty microcode.
Interesting, and thanks for bringing this up. Oleksandr, under what circumstances would you want to know what the old version was. AFAICS it is no longer running and should not have an impact on the system?
P.
Quoted 2 lines
Thanks.
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Hi.
Quoted 7 lines · Prarit Bhargava
Quoted 4 lines
After this patch, do we preserve an original microcode version somewhere? If no, why? Sometimes it is useful while debugging another crash because of faulty microcode.
Interesting, and thanks for bringing this up. Oleksandr, under what circumstances would you want to know what the old version was. AFAICS it is no longer running and should not have an impact on the system?
Once the kernel log does not contain a printout regarding updated microcode anymore (because the log buffer is limited in size and can be overwritten) and once you have a vmcore, it is handy to use boot_cpu_data to compare the microcode version with the per-CPU value to find out that is was updated at all. Or, maybe, that can be inspected in another way now?
Signature · 1 line
Oleksandr Natalenko (post-factum)
Borislav Petkov
maintainerRe: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
(drop stable@ from CC)
Quoted 2 lines · Oleksandr Natalenko
Once the kernel log does not contain a printout regarding updated microcode anymore (because the log buffer is limited in size and can be overwritten)
There's no reliable way to get the old microcode revision which was overwritten during the upgrade. If dmesg gets overwritten you lose, like in all the other gazillion cases where you lose information due to that. Sorry.
This becomes an even bigger problem if you have a long-running system which upgrades microcode a couple of times before being rebooted again. In that case, your only log which contains the microcode revisions being upgraded is dmesg.
Quoted 3 lines
once you have a vmcore, it is handy to use
boot_cpu_datato compare the microcode version with the per-CPU value to find out that is was updated at all.
boot_cpu_data.microcode was never meant to contain the *previous* microcode revision AFAICT - it just didn't get updated, which we're fixing now.
Quoted 1 line
Or, maybe, that can be inspected in another way now?
Dunno, does kdump collect /proc/cpuinfo? If so:
$ grep microcode /proc/cpuinfo
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Luck, Tony
maintainerRE: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 3 lines
There's no reliable way to get the old microcode revision which was overwritten during the upgrade. If dmesg gets overwritten you lose, like in all the other gazillion cases where you lose information due to that.
The primary requirement here is that we report the version of the microcode in use at the time of a crash. Keeping history of all updates seems to me to beyond the scope of the kernel's responsibilities.
It's not like these updates appear out of the ether. You have to go out and grab a new package and install it. User land can keep track of this much more easily than the kernel.
-Tony
Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Hi.
Quoted 11 lines · Tony
Quoted 3 lines
There's no reliable way to get the old microcode revision which was overwritten during the upgrade. If dmesg gets overwritten you lose, like in all the other gazillion cases where you lose information due to that.
The primary requirement here is that we report the version of the microcode in use at the time of a crash. Keeping history of all updates seems to me to beyond the scope of the kernel's responsibilities.
It's not like these updates appear out of the ether. You have to go out and grab a new package and install it. User land can keep track of this much more easily than the kernel.
I don't mind doing the right thing at all. It is just to inform you that it was found to be useful.
Also, [1].
Thanks ☺.
Signature · 1 line
Oleksandr Natalenko (post-factum)
Boris Petkov
maintainerRe: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
Quoted 3 lines · Oleksandr Natalenko
I don't mind doing the right thing at all. It is just to inform you that
it was found to be useful.
I don't think it would've worked if you did a second microcode upgrade on the system.
Signature · 1 line
Sent from a small device: formatting sux and brevity is inevitable.
Borislav Petkov
maintainerRe: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
In reply to Prarit Bhargava(dropping stable@)
Quoted 4 lines · Prarit Bhargava
I tested this on AMD Ryzen & Intel Broadwell system and dumped the
boot_cpu_databefore and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.
Ok, sending the two patches I've massaged into submission as a reply to this message - please run them on your boxes. You can also inject MCEs on the AMD box to verify - simply enable CONFIG_X86_MCE_INJECT, go to debugfs and do, for example:
cd /sys/kernel/debug/mce-inject/
echo 10 > /sys/devices/system/machinecheck/machinecheck0/check_interval
echo 0x9c7d410092080813 > status; echo 0x000000006d3d483b > addr; echo 2 > cpu; echo 4 > bank; echo hw > flags echo 0xbc00200000010015 > status; echo 0x00000000942e4d98 > addr; echo 6 > cpu; echo 2 > bank; echo hw > flags echo 0xfe000010000b0c0f > status; echo 0xe1101add1e550012 > addr; echo 0xcafebeef > misc; echo 2 > cpu; echo hw > flags; echo 4 > bank
Thanks!
Borislav Petkov
maintainerPATCH 1/2 x86/microcode: Make sure boot_cpu_data.microcode is up-to-date
From: Prarit Bhargava <[email protected]>
The MCE code uses boot_cpu_data.microcode to prepare the MCE record. However, on systems where late microcode update has occurred, the microcode revision output in a MCE log record is wrong because boot_cpu_data.microcode is not updated when the microcode gets updated.
However, the microcode revision saved in boot_cpu_data's microcode member should be kept up-to-date, regardless, for consistency.
Make it so.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/x86/kernel/cpu/microcode/amd.c +4 -0
@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; +return UCODE_UPDATED ; }
arch/x86/kernel/cpu/microcode/intel.c +4 -0
@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }
Signature · 9 lines
2.18.0.321.gffc6fa0e3962
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Borislav Petkov
maintainerPATCH 2/2 x86/microcode: Update the new microcode revision unconditionally
In reply to Borislav PetkovFrom: Filippo Sironi <[email protected]>
Handle the case where microcode gets loaded on the BSP's hyperthread sibling first and the boot_cpu_data's microcode revision doesn't get updated because of early exit due to the siblings sharing a microcode engine.
For that, simply write the updated revision on all CPUs unconditionally.
--- arch/x86/kernel/cpu/microcode/amd.c | 22 +++++++++++++--------- arch/x86/kernel/cpu/microcode/intel.c | 13 ++++++++----- 2 files changed, 21 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +13 -9
@@ -504,6 +504,7 @@ static enum ucode_state apply_microcode_amd(int cpu)struct microcode_amd *mc_amd;struct ucode_cpu_info *uci;struct ucode_patch *p; +enum ucode_state ret;u32 rev, dummy;BUG_ON (raw_smp_processor_id () != cpu);
@@ -521,9 +522,8 @@ static enum ucode_state apply_microcode_amd(int cpu)/* need to apply patch? */ if (rev >= mc_amd->hdr.patch_id) { - c->microcode = rev; - uci->cpu_sig.rev = rev; -return UCODE_OK ; + ret =UCODE_OK ; + goto out; }if (__apply_microcode_amd (mc_amd)) {
@@ -531,17 +531,21 @@ static enum ucode_state apply_microcode_amd(int cpu) cpu, mc_amd->hdr.patch_id);return UCODE_ERROR ; } -pr_info ("CPU%d: new patch_level=0x%08x\n" , cpu, - mc_amd->hdr.patch_id); - uci->cpu_sig.rev = mc_amd->hdr.patch_id; - c->microcode = mc_amd->hdr.patch_id; + rev = mc_amd->hdr.patch_id; + ret =UCODE_UPDATED ; + +pr_info ("CPU%d: new patch_level=0x%08x\n" , cpu, rev); + +out: + uci->cpu_sig.rev = rev; + c->microcode = rev;/* Update boot_cpu_data's revision too, if we're on the BSP: */ if (c->cpu_index == boot_cpu_data.cpu_index) - boot_cpu_data.microcode = mc_amd->hdr.patch_id; + boot_cpu_data.microcode = rev; -return UCODE_UPDATED ; +return ret; }static int install_equiv_cpu_table (const u8 *buf)
arch/x86/kernel/cpu/microcode/intel.c +8 -5
@@ -795,6 +795,7 @@ static enum ucode_state apply_microcode_intel(int cpu)struct ucode_cpu_info *uci = ucode_cpu_info + cpu;struct cpuinfo_x86 *c = &cpu_data (cpu);struct microcode_intel *mc; +enum ucode_state ret;static int prev_rev;u32 rev;
@@ -817,9 +818,8 @@ static enum ucode_state apply_microcode_intel(int cpu)*/ rev =intel_get_microcode_revision ();if (rev >= mc->hdr.rev) { - uci->cpu_sig.rev = rev; - c->microcode = rev; -return UCODE_OK ; + ret =UCODE_OK ; + goto out; }/*
@@ -848,14 +848,17 @@ static enum ucode_state apply_microcode_intel(int cpu) prev_rev = rev; } + ret =UCODE_UPDATED ; + +out: uci->cpu_sig.rev = rev; - c->microcode = rev; + c->microcode = rev;/* Update boot_cpu_data's revision too, if we're on the BSP: */ if (c->cpu_index == boot_cpu_data.cpu_index) boot_cpu_data.microcode = rev; -return UCODE_UPDATED ; +return ret; } static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
Signature · 9 lines
2.18.0.321.gffc6fa0e3962
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH v2] arch/x86: Fix boot_cpu_data.microcode version output
In reply to Borislav PetkovQuoted 13 lines · Borislav Petkov
(dropping stable@)
Quoted 4 lines · Prarit Bhargava
I tested this on AMD Ryzen & Intel Broadwell system and dumped the
boot_cpu_databefore and after a microcode update. On the Intel system I also did a fatal MCE using mce-inject to confirm the output from the mce handling code.Ok, sending the two patches I've massaged into submission as a reply to this message - please run them on your boxes. You can also inject MCEs on the AMD box to verify - simply enable
CONFIG_X86_MCE_INJECT, go to debugfs and do, for example:
Quoted 6 lines
cd
/sys/kernel/debug/mce-inject/
echo 10 >/sys/devices/system/machinecheck/machinecheck0/check_interval
echo0x9c7d410092080813> status; echo0x000000006d3d483b> addr; echo 2 > cpu; echo 4 > bank; echo hw > flags echo0xbc00200000010015> status; echo0x00000000942e4d98> addr; echo 6 > cpu; echo 2 > bank; echo hw > flags echo0xfe000010000b0c0f> status; echo0xe1101add1e550012> addr; echo0xcafebeef> misc; echo 2 > cpu; echo hw > flags; echo 4 > bank
Borislav, I'm not sure if you saw his comments but Oleksandr, cc'd, has an objection to overwriting the stored microcode version in boot_cpu_data. He has found that information useful in debugging microcode issues.
P.
Quoted 2 lines
Thanks!
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
tip-bot for Prarit Bhargava
merge bot[tip:x86/urgent] x86/microcode: Make sure boot_cpu_data.microcode is up-to-date
In reply to Prarit Bhargavax86/microcode: Make sure boot_cpu_data.microcode is up-to-date
Commit-ID: 370a132bb2227ff76278f98370e0e701d86ff752 Gitweb: https://git.kernel.org/tip/370a132bb2227ff76278f98370e0e701d86ff752 Author: Prarit Bhargava <[email protected]> AuthorDate: Tue, 31 Jul 2018 07:27:39 -0400 Committer: Thomas Gleixner <[email protected]> CommitDate: Sun, 2 Sep 2018 14:10:54 +0200
x86/microcode: Make sure boot_cpu_data.microcode is up-to-date
When preparing an MCE record for logging, boot_cpu_data.microcode is used to read out the microcode revision on the box.
However, on systems where late microcode update has happened, the microcode revision output in a MCE log record is wrong because boot_cpu_data.microcode is not updated when the microcode gets updated.
But, the microcode revision saved in boot_cpu_data's microcode member should be kept up-to-date, regardless, for consistency.
Make it so.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 ++++ arch/x86/kernel/cpu/microcode/intel.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/x86/kernel/cpu/microcode/amd.c +4 -0
@@ -537,6 +537,10 @@ static enum ucode_state apply_microcode_amd(int cpu) uci->cpu_sig.rev = mc_amd->hdr.patch_id; c->microcode = mc_amd->hdr.patch_id; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = mc_amd->hdr.patch_id; +return UCODE_UPDATED ; }
arch/x86/kernel/cpu/microcode/intel.c +4 -0
@@ -851,6 +851,10 @@ static enum ucode_state apply_microcode_intel(int cpu) uci->cpu_sig.rev = rev; c->microcode = rev; +/* Update boot_cpu_data's revision too, if we're on the BSP: */ +if (c->cpu_index == boot_cpu_data.cpu_index) + boot_cpu_data.microcode = rev; +return UCODE_UPDATED ; }