x86/microcode/AMD: Load late on both threads too
Subsystems (3)
Borislav Petkov
maintainerPATCH 1/2 x86/microcode/AMD: Load late on both threads too
From: "Borislav Petkov (AMD)" <[email protected]>
Do the same as early loading - load on both threads.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -700,7 +700,7 @@ static enum ucode_state apply_microcode_amd(int cpu)rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy);/* need to apply patch? */ -if (rev >= mc_amd->hdr.patch_id) { +if (rev > mc_amd->hdr.patch_id) { ret =UCODE_OK ; goto out; }
Signature · 1 line
2.35.1
Borislav Petkov
maintainerPATCH 2/2 x86/microcode: Add a "microcode=" command line option
From: "Borislav Petkov (AMD)" <[email protected]>
It will be used to control microcode loader behavior. Add the first chicken bit: to control whether the AMD side should load microcode late on all logical SMT threads.
--- .../admin-guide/kernel-parameters.txt | 7 +++ arch/x86/kernel/cpu/microcode/amd.c | 5 ++- arch/x86/kernel/cpu/microcode/core.c | 44 +++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 16 +++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/microcode/internal.h
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -3228,6 +3228,13 @@ mga= [HW,DRM] + microcode= [X86] Control the behavior of the microcode + loader. Available options: + + no_late_all - do not load on all SMT threads on + AMD. Loading on all logical threads is enabled by + default. + min_addr=nn[KMG] [KNL,BOOT,IA-64] All physical memory below this physical address is ignored.
arch/x86/kernel/cpu/microcode/amd.c +4 -1
@@ -36,6 +36,8 @@#include <asm/cpu.h> #include <asm/msr.h> +#include "internal.h" + static struct equiv_cpu_table { unsigned int num_entries; struct equiv_cpu_entry *entry;
@@ -700,7 +702,8 @@ static enum ucode_state apply_microcode_amd(int cpu)rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy);/* need to apply patch? */ -if (rev > mc_amd->hdr.patch_id) { +if ((rev > mc_amd->hdr.patch_id) || + (rev == mc_amd->hdr.patch_id && !(control &LATE_ALL_THREADS ))) { ret =UCODE_OK ; goto out; }
arch/x86/kernel/cpu/microcode/core.c +44 -0
72 lines not on this page · raw message
arch/x86/kernel/cpu/microcode/internal.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __X86_MICROCODE_INTERNAL_H__ +#define __X86_MICROCODE_INTERNAL_H__ + +extern unsigned long control; + +/* Loader control flags. */ +enum control_flags { + __LATE_ALL_THREADS =0 , + __CONTROL_FLAGS_NUM, +}; + +#define LATE_ALL_THREADS BIT_ULL(__LATE_ALL_THREADS) +#define CONTROL_FLAGS_MASK ~(BIT_ULL(__CONTROL_FLAGS_NUM) - 1) + +#endif /* __X86_MICROCODE_INTERNAL_H__ */
Signature · 1 line
2.35.1
Re: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Hi
Quoted 20 lines · Borislav Petkov
From: "Borislav Petkov (AMD)" <[email protected]>
It will be used to control microcode loader behavior. Add the first chicken bit: to control whether the AMD side should load microcode late on all logical SMT threads.
Signed-off-by Borislav Petkov (AMD) <[email protected]>--- .../admin-guide/kernel-parameters.txt | 7 +++ arch/x86/kernel/cpu/microcode/amd.c | 5 ++- arch/x86/kernel/cpu/microcode/core.c | 44 +++++++++++++++++++ arch/x86/kernel/cpu/microcode/internal.h | 16 +++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/microcode/internal.hDocumentation/admin-guide/kernel-parameters.txt +0
-0
Documentation/admin-guide/kernel-parameters.txt line 3237
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +7
-0@@ -3228,6 +3228,13 @@ mga= [HW,DRM] + microcode= [X86] Control the behavior of the microcode + loader. Available options: + + no_late_all - do not load on all SMT threads on + AMD. Loading on all logical threads is enabled by + default. +
The default behavior is that the reload happens on all threads for both early and late.
The chicken bit in cmdline and the sysfs/control is to opt-out just in case they want to change the default behavior?
When end user changes the behavior, isn't it against the design specification? And if so, should that result in kernel being tainted after a reload?
Is this reload on all threads required by all models, or only certain models? I was wondering if the forced reload could be limited to only affected CPUs instead of doing it on all unconditionally.
Quoted 80 lines
Documentation/admin-guide/kernel-parameters.txt +0
-0min_addr=nn[KMG] [KNL,BOOT,IA-64] All physical memory below this physical address is ignored.arch/x86/kernel/cpu/microcode/amd.c +4
-1@@ -36,6 +36,8 @@#include <asm/cpu.h> #include <asm/msr.h> +#include "internal.h" + static struct equiv_cpu_table { unsigned int num_entries; struct equiv_cpu_entry *entry;@@ -700,7 +702,8 @@ static enum ucode_state apply_microcode_amd(int cpu)rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy);/* need to apply patch? */ -if (rev > mc_amd->hdr.patch_id) { +if ((rev > mc_amd->hdr.patch_id) || + (rev == mc_amd->hdr.patch_id && !(control &LATE_ALL_THREADS ))) { ret =UCODE_OK ; goto out; }arch/x86/kernel/cpu/microcode/core.c +28
-0@@ -40,11 +40,15 @@#include <asm/cmdline.h> #include <asm/setup.h> +#include "internal.h" +#define DRIVER_VERSION "2.2"static struct microcode_ops *microcode_ops;static bool dis_ucode_ldr = true; +unsigned long control =LATE_ALL_THREADS ; +bool initrd_gone;LIST_HEAD (microcode_cache);@@ -522,8 +526,32 @@ static ssize_t processor_flags_show(struct device *dev,return sprintf (buf,"0x%x\n" , uci->cpu_sig.pf); } +static ssize_t control_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"0x%lx\n" , control); +} + +static ssize_t control_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +unsigned long val; + +if (kstrtoul (buf,0 , &val) <0 ) +return -ERANGE ; + +if (val &CONTROL_FLAGS_MASK ) +return -EINVAL ; + + control = val; + +return count; +} +static DEVICE_ATTR_RO (version);static DEVICE_ATTR_RO (processor_flags); +static DEVICE_ATTR_ADMIN_RW (control);static struct attribute *mc_default_attrs[] = { &dev_attr_version.attr,
arch/x86/kernel/cpu/microcode/core.c static struct attribute *cpu_root_microcode_attrs[] = { · line 653
Quoted 4 lines
arch/x86/kernel/cpu/microcode/core.c +1
-0@@ -622,6 +650,7 @@ static struct attribute *cpu_root_microcode_attrs[] = {#ifdef CONFIG_MICROCODE_LATE_LOADING &dev_attr_reload.attr, #endif + &dev_attr_control.attr,
Shouldn't the "control" be under LATE_LOADING? Since this only controls late-loading behavior?
Borislav Petkov
maintainerRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Quoted 3 lines · Ashok Raj
When end user changes the behavior, isn't it against the design specification? And if so, should that result in kernel being tainted after a reload?
That's a chicken bit and should not be used usually. I'm adding it just in case.
Quoted 3 lines
Is this reload on all threads required by all models, or only certain models? I was wondering if the forced reload could be limited to only affected CPUs instead of doing it on all unconditionally.
Unconditionally.
Quoted 2 lines
Shouldn't the "control" be under
LATE_LOADING? Since this only controls late-loading behavior?
No, that's a bitfield and is going to be used for other flags, if needed and which are not necessarily late-loading related.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Ashok Raj
When end user changes the behavior, isn't it against the design specification? And if so, should that result in kernel being tainted after a reload?
That's a chicken bit and should not be used usually. I'm adding it just in case.
How about a debugfs opt-out instead? Say something like
/sys/kernel/debug/microcode/debug_control?
Since the code doesn't use this in the early loading, it appears we can drop the cmdline entirely?
Quoted 6 lines
Quoted 4 lines
Is this reload on all threads required by all models, or only certain models? I was wondering if the forced reload could be limited to only affected CPUs instead of doing it on all unconditionally.
Unconditionally.
Thanks, this simplifies.
Since this is quite different from what the "typical" HT behavior w.r.t , microcode, maybe good to document this behavior in microcode.rst.
If the user switches the expected flow, should the code "taint" if its opted out?
Quoted 6 lines
Quoted 3 lines
Shouldn't the "control" be under
LATE_LOADING? Since this only controls late-loading behavior?No, that's a bitfield and is going to be used for other flags, if needed and which are not necessarily late-loading related.
My .000002c. Maybe add such sysfs control only when we really need one, but should not include debug use.
Borislav Petkov
maintainerRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Quoted 2 lines · Ashok Raj
Since the code doesn't use this in the early loading, it appears we can drop the cmdline entirely?
The driver needs a control mechanism and this is it. It needs to be always there so no, no debugfs.
Quoted 2 lines
If the user switches the expected flow, should the code "taint" if its opted out?
When it turns out that this needs to happen, it'll get added then.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette[tip: x86/microcode] x86/microcode: Add a "microcode=" command line option
In reply to Borislav PetkovThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 4a7349239418d78193e8d328f5eebd14a3f77bcd Gitweb: https://git.kernel.org/tip/4a7349239418d78193e8d328f5eebd14a3f77bcd Author: Borislav Petkov (AMD) <[email protected]> AuthorDate: Thu, 18 May 2023 03:02:29 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 12 Jun 2023 11:02:52 +02:00
x86/microcode: Add a "microcode=" command line option
It will be used to control microcode loader behavior. Add the first chicken bit: to control whether the AMD side should load microcode late on all logical SMT threads.
--- Documentation/admin-guide/kernel-parameters.txt | 7 +++- arch/x86/kernel/cpu/microcode/amd.c | 5 +- arch/x86/kernel/cpu/microcode/core.c | 44 ++++++++++++++++- arch/x86/kernel/cpu/microcode/internal.h | 16 ++++++- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/microcode/internal.h
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -3228,6 +3228,13 @@ mga= [HW,DRM] + microcode= [X86] Control the behavior of the microcode + loader. Available options: + + no_late_all - do not load on all SMT threads on + AMD. Loading on all logical threads is enabled by + default. + min_addr=nn[KMG] [KNL,BOOT,IA-64] All physical memory below this physical address is ignored.
arch/x86/kernel/cpu/microcode/amd.c +4 -1
@@ -36,6 +36,8 @@#include <asm/cpu.h> #include <asm/msr.h> +#include "internal.h" + static struct equiv_cpu_table { unsigned int num_entries; struct equiv_cpu_entry *entry;
@@ -700,7 +702,8 @@ static enum ucode_state apply_microcode_amd(int cpu)rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy);/* need to apply patch? */ -if (rev > mc_amd->hdr.patch_id) { +if ((rev > mc_amd->hdr.patch_id) || + (rev == mc_amd->hdr.patch_id && !(control &LATE_ALL_THREADS ))) { ret =UCODE_OK ; goto out; }
arch/x86/kernel/cpu/microcode/core.c +44 -0
72 lines not on this page · raw message
arch/x86/kernel/cpu/microcode/internal.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __X86_MICROCODE_INTERNAL_H__ +#define __X86_MICROCODE_INTERNAL_H__ + +extern unsigned long control; + +/* Loader control flags. */ +enum control_flags { + __LATE_ALL_THREADS =0 , + __CONTROL_FLAGS_NUM, +}; + +#define LATE_ALL_THREADS BIT_ULL(__LATE_ALL_THREADS) +#define CONTROL_FLAGS_MASK ~(BIT_ULL(__CONTROL_FLAGS_NUM) - 1) + +#endif /* __X86_MICROCODE_INTERNAL_H__ */
Re: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
In reply to Borislav PetkovQuoted 5 lines · Borislav Petkov
From: "Borislav Petkov (AMD)" <[email protected]>
It will be used to control microcode loader behavior. Add the first chicken bit: to control whether the AMD side should load microcode late on all logical SMT threads.
This has a distinct void of information here.
Why is it suddenly required to prevent late loading on SMT threads?
That's the exact opposite of what e7ad18d1169c ("x86/microcode/AMD:
Apply the patch early on every logical thread") is doing.
I'm seriously confused.
Documentation/admin-guide/kernel-parameters.txt line 3236
Quoted 7 lines
Documentation/admin-guide/kernel-parameters.txt +6
-0+ microcode= [X86] Control the behavior of the microcode + loader. Available options: + + no_late_all - do not load on all SMT threads on + AMD. Loading on all logical threads is enabled by + default.
no_late_all is a horrible option name.
Also the explanation is not mentioning that this is only relevant for late loading.
Aside of that why is this a kernel side chicken bit and not communicated by the microcode header?
How should an administrator know which microcode versions need this treatment and which do not? How is that supposed to work on a fleet?
Quoted 4 lines
arch/x86/kernel/cpu/microcode/core.c +0
-0@@ -40,11 +40,15 @@#include <asm/cmdline.h>
arch/x86/kernel/cpu/microcode/core.c line 50
Quoted 10 lines
arch/x86/kernel/cpu/microcode/core.c +3
-0#include <asm/setup.h> +#include "internal.h" +#define DRIVER_VERSION "2.2"static struct microcode_ops *microcode_ops;static bool dis_ucode_ldr = true; +unsigned long control =LATE_ALL_THREADS ;
global variable name without a proper prefix. Moo.
Quoted 12 lines
arch/x86/kernel/cpu/microcode/core.c +12
-0+static ssize_t control_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"0x%lx\n" , control); +} + +static ssize_t control_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +unsigned long val; +
arch/x86/kernel/cpu/microcode/core.c static ssize_t processor_flags_show(struct device *dev, · line 550
Quoted 10 lines
arch/x86/kernel/cpu/microcode/core.c +10
-0+if (kstrtoul (buf,0 , &val) <0 ) +return -ERANGE ; + +if (val &CONTROL_FLAGS_MASK ) +return -EINVAL ; + + control = val; + +return count; +}
Where is the documentation which tells me what I'm supposed to write into this file? Also this is a generic file, right? So what's the meaning for non AMD? I can write this bit into it successfully and nothing happens, right?
Quoted 6 lines
+++
b/arch/x86/kernel/cpu/microcode/internal.harch/x86/kernel/cpu/microcode/core.c +4
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __X86_MICROCODE_INTERNAL_H__ +#define __X86_MICROCODE_INTERNAL_H__ +
arch/x86/kernel/cpu/microcode/core.c line 14
Quoted 10 lines
arch/x86/kernel/cpu/microcode/core.c +10
-0+extern unsigned long control; + +/* Loader control flags. */ +enum control_flags { + __LATE_ALL_THREADS =0 , + __CONTROL_FLAGS_NUM, +}; + +#define LATE_ALL_THREADS BIT_ULL(__LATE_ALL_THREADS) +#define CONTROL_FLAGS_MASK ~(BIT_ULL(__CONTROL_FLAGS_NUM) - 1)
Why ULL bits for a unsigned long variable?
Thanks,
tglx
Borislav Petkov
maintainerRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Quoted 1 line · Thomas Gleixner
Why is it suddenly required to prevent late loading on SMT threads?
The intent is, like a chicken bit, to revert to the *old* behavior which would not load on both threads. In *case* some old configuration of CPU and microcode cannot handle loading on both threads. Which is from Bulldozer onwards but I don't think anyone uses Bulldozer anymore.
Quoted 2 lines
That's the exact opposite of what
e7ad18d1169c("x86/microcode/AMD:
Apply the patch early on every logical thread") is doing.
No, see patch 1 - it does exactly the same what this commit does but for late loading.
Bottomline: on AMD, we should load on both threads by default.
Quoted 1 line
no_late_allis a horrible option name.
Yeah, at the time dis_ucode_ldr was horrible too. I tried harder this time.
What do you suggest?
Quoted 2 lines
Also the explanation is not mentioning that this is only relevant for late loading.
Huh, it has "late" in the name. :-)
Quoted 2 lines
Aside of that why is this a kernel side chicken bit and not communicated by the microcode header?
See above. This chicken bit is there, just in case, to help in the case where the user cannot do anything else. It should not be used, judging by all the combinations I've tested here.
Quoted 2 lines
How should an administrator know which microcode versions need this treatment and which do not? How is that supposed to work on a fleet?
None of them should need it. Thus, a chicken bit as a last option in production.
Quoted 1 line
global variable name without a proper prefix. Moo.
Lemme fix.
Quoted 2 lines
Where is the documentation which tells me what I'm supposed to write into this file? Also this is a generic file, right?
Lemme write some docs about it.
Quoted 2 lines
So what's the meaning for non AMD? I can write this bit into it successfully and nothing happens, right?
Yes, this bit is AMD-only.
Quoted 1 line
Why ULL bits for a unsigned long variable?
There's no BIT_UL() macro.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Diff ontop with the proposed changes so that they're easily reviewable:
---
Documentation/arch/x86/microcode.rst +10 -0
@@ -238,3 +238,13 @@ the final kernel image. The early loader finds them and applies them. Needless to say, this method is not the most flexible one because it requires rebuilding the kernel each time updated microcode from the CPU vendor is available. + +Loader control +============== + +/sys/devices/system/cpu/microcode/control controls different aspects of +the microcode loader's behavior and can be used to modify it by toggling +bits in that file. Currently defined controls are: + +bit 0: Do not load on all SMT threads on AMD. Loading on all logical + threads is enabled by default.
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -703,7 +703,7 @@ static enum ucode_state apply_microcode_amd(int cpu)/* need to apply patch? */ if ((rev > mc_amd->hdr.patch_id) || - (rev == mc_amd->hdr.patch_id && !(control &LATE_ALL_THREADS ))) { + (rev == mc_amd->hdr.patch_id && !(microcode_control &LATE_ALL_THREADS ))) { ret =UCODE_OK ; goto out; }
arch/x86/kernel/cpu/microcode/core.c +4 -4
@@ -47,7 +47,7 @@static struct microcode_ops *microcode_ops;static bool dis_ucode_ldr = true; -unsigned long control =LATE_ALL_THREADS ; +unsigned long microcode_control =LATE_ALL_THREADS ;bool initrd_gone;
@@ -529,7 +529,7 @@ static ssize_t processor_flags_show(struct device *dev,static ssize_t control_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"0x%lx\n" , control); +return sprintf (buf,"0x%lx\n" , microcode_control); } static ssize_t control_store(struct device *dev,
@@ -544,7 +544,7 @@ static ssize_t control_store(struct device *dev,if (val &CONTROL_FLAGS_MASK )return -EINVAL ; - control = val; + microcode_control = val;return count; }
@@ -722,7 +722,7 @@ static int __init parse_cmdline_param(char *str) str++;if (!strcmp (str,"no_late_all" )) - control &= ~LATE_ALL_THREADS ; + microcode_control &= ~LATE_ALL_THREADS ;return 1 ; }
arch/x86/kernel/cpu/microcode/internal.h +1 -1
@@ -2,7 +2,7 @@#ifndef __X86_MICROCODE_INTERNAL_H__#define __X86_MICROCODE_INTERNAL_H__ -extern unsigned long control; +extern unsigned long microcode_control;/* Loader control flags. */ enum control_flags {
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
In reply to Borislav PetkovQuoted 7 lines · Borislav Petkov
Quoted 1 line · Thomas Gleixner
Why is it suddenly required to prevent late loading on SMT threads?
The intent is, like a chicken bit, to revert to the *old* behavior which would not load on both threads. In *case* some old configuration of CPU and microcode cannot handle loading on both threads. Which is from Bulldozer onwards but I don't think anyone uses Bulldozer anymore.
So why not making the late loading thing depend on >= bulldozer?
Also I'm failing to see how this is different from the early loader:
Quoted 2 lines
Quoted 2 lines
That's the exact opposite of what
e7ad18d1169c("x86/microcode/AMD:
Apply the patch early on every logical thread") is doing.
That changelogs says:
"Btw, change only the early paths. On the late loading paths, there's
no point in doing per-thread modification because if is it some case like in the bugzilla below - removing a CPUID flag - the kernel cannot go and un-use features it has detected are there early. For that, one should use early loading anyway."
which makes sense to some extent, but obviously there is a use case for late loading on both threads. So what are you worried about breaking here?
If the late load does a behavioural change, then it does not matter whether you make sure both threads are hosed in the same way or not. If the late load is harmless and just addressing some correctness issue then loading on the secondary thread should be a noop, right?
Quoted 2 lines
No, see patch 1 - it does exactly the same what this commit does but for late loading.
Sorry no. Patch 1 brings the late loading decision in line with the early loading decision, i.e. ensure that microcode is loaded on both threads. That condition
/* need to apply patch? */
- if (rev >= mc_amd->hdr.patch_id) {
+ if (rev > mc_amd->hdr.patch_id) {
really could do with a proper comment which explains why loading the same revision makes sense.
Quoted 1 line
Bottomline: on AMD, we should load on both threads by default.
Fine. Then what is this about? If it survives early loading on both threads then why do we need a chickenbit for late loading?
So if someone turns that on needlessly then in the worst case the primary thread behaves differently than the secondary thread, right?
Quoted 6 lines
Quoted 2 lines
Aside of that why is this a kernel side chicken bit and not communicated by the microcode header?
See above. This chicken bit is there, just in case, to help in the case where the user cannot do anything else. It should not be used, judging by all the combinations I've tested here.
If it should not be used, then where is the big fat warning emitted when it is actually enabled?
The more I read this the less I'm convinced that this makes any sense at all:
1) You did not add a chicken bit when you made this change for the early loader. Why needs late loading suddenly one?
2) Late loading is "use at your own peril" up to the point where the minimum revision field is in place. So why do we need a bandaid chickenbit for something which is considered unsafe anyway?
3) The microcode people @AMD should be able to figure out whether unconditionally (late) loading on the secondary thread is safe or not.
I told Intel to make microcode loading something sane. It's not any different for AMD. This hastily cobbled together chickenbit thing without a fundamental technical justification definitely does not quality for sane.
Quoted 3 lines
Quoted 1 line
Why ULL bits for a unsigned long variable?
There's no
BIT_UL()macro.
git grep '#define BIT(' include/
Thanks,
tglx
Borislav Petkov
maintainerRe: [PATCH 2/2] x86/microcode: Add a "microcode=" command line option
Just to sum up what we talked about on IRC:
Early loading already does per-thread loading unconditionally and it doesn't have a chicken bit. I will do the chicken bit for both loading methods but keep it out-of-tree if it turns out we need it.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 1 line · Borislav Petkov
Do the same as early loading - load on both threads.
Hey Boris,
What's the benefit of doing the loading on both threads? I would have naively thought it was just wasted work.
I think I even have a back-burnered Intel patch around somewhere that ensures that we *never* load on both threads.
Borislav Petkov
maintainerQuoted 2 lines · Dave Hansen
What's the benefit of doing the loading on both threads? I would have naively thought it was just wasted work.
I have the perfect example for this, see:
e7ad18d1169c ("x86/microcode/AMD: Apply the patch early on every logical thread")
so it is for reasons like that.
Quoted 2 lines
I think I even have a back-burnered Intel patch around somewhere that ensures that we *never* load on both threads.
Interesting - I guess there are considerable differences in microcode architecture between the two. :-)
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 8 lines · Borislav Petkov
Quoted 2 lines · Dave Hansen
What's the benefit of doing the loading on both threads? I would have naively thought it was just wasted work.
I have the perfect example for this, see:
e7ad18d1169c("x86/microcode/AMD: Apply the patch early on every logical thread")so it is for reasons like that.
Yikes, so the second CMT thread reports a bumped version but not all the _effects_ of that version? That's, uh ... fun???
Quoted 4 lines
Quoted 2 lines
I think I even have a back-burnered Intel patch around somewhere that ensures that we *never* load on both threads.
Interesting - I guess there are considerable differences in microcode architecture between the two. 😄
Yeah, sure seems that way.
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Borislav Petkov
Quoted 2 lines · Dave Hansen
What's the benefit of doing the loading on both threads? I would have naively thought it was just wasted work.
Quoted 8 lines
Quoted 5 lines
I have the perfect example for this, see:
e7ad18d1169c("x86/microcode/AMD: Apply the patch early on every logical thread")so it is for reasons like that.
Yikes, so the second CMT thread reports a bumped version but not all the _effects_ of that version? That's, uh ... fun???
That does seem like fun. :)
Borislav,
Is there any way to tell that a microcode patch has been loaded on only one thread? And what does this mean for SEV-SNP attestation?
Borislav Petkov
maintainerQuoted 2 lines · Jim Mattson
Is there any way to tell that a microcode patch has been loaded on only one thread?
Only the example you see in the bugzilla link above.
Quoted 1 line
And what does this mean for SEV-SNP attestation?
More specifically? The CPUID page or microcode revision?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 10 lines · Borislav Petkov
Quoted 2 lines · Jim Mattson
Is there any way to tell that a microcode patch has been loaded on only one thread?
Only the example you see in the bugzilla link above.
Quoted 1 line
And what does this mean for SEV-SNP attestation?
More specifically? The CPUID page or microcode revision?
Specifically, "Security Version Numbers (SVNs) of the currently executing platform firmware and microcode."
Quoted 5 lines
--
Regards/Gruss,
Boris.
Borislav Petkov
maintainerQuoted 2 lines · Jim Mattson
Specifically, "Security Version Numbers (SVNs) of the currently executing platform firmware and microcode."
Yes, I know the microcode revision is part of the attestation.
What exactly are you asking?
If you don't state your question, how do you expect me to answer?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 10 lines · Borislav Petkov
Quoted 2 lines · Jim Mattson
Specifically, "Security Version Numbers (SVNs) of the currently executing platform firmware and microcode."
Yes, I know the microcode revision is part of the attestation.
What exactly are you asking?
If you don't state your question, how do you expect me to answer?
Doesn't this render that attestation misleading, since the microcode patch may not have been loaded on all logical processors?
--
Quoted 4 lines
Regards/Gruss,
Boris.
Borislav Petkov
maintainerQuoted 2 lines · Jim Mattson
Doesn't this render that attestation misleading, since the microcode patch may not have been loaded on all logical processors?
For that it doesn't matter because the microcode engine is shared between the two threads. The updated microcode revision is shown on any of the two threads so you can load on one only. And we did this for years.
Only recently we started loading on both and we will be doing that from now on.
What could be problematic is if it simply fails loading on some cores
- regardless of SMT - but that would be problematic not only to SEV-SNP attestation but to the general system health. tglx has some patches which verify what has been successfully loaded where so hopefully we'll be verifying more in that area.
HTH.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 5 lines · Borislav Petkov
Quoted 2 lines · Jim Mattson
Doesn't this render that attestation misleading, since the microcode patch may not have been loaded on all logical processors?
Quoted 7 lines
For that it doesn't matter because the microcode engine is shared between the two threads. The updated microcode revision is shown on any of the two threads so you can load on one only. And we did this for years.
Only recently we started loading on both and we will be doing that from now on.
SEV-SNP is supposed to protect the guest from a malicious host. A malicious host may not load the microcode update on both threads. As a result, it gives me some concern when I see something like this
(https://lore.kernel.org/lkml/[email protected]/):
+NOTE: For Genoa (Family=0x19 Model=0x11) and Bergamo (Family=0x19 Model=0xa0), +either AGESA version >= 1.0.0.8 OR a kernel with the following commit is +required:
+a32b0f0db3f3 ("x86/microcode/AMD: Load late on both threads too")
It seems problematic if the guest can't tell from the attestation whether or not the identified microcode revision has been correctly applied.
Quoted 5 lines
What could be problematic is if it simply fails loading on some cores
- regardless of SMT - but that would be problematic not only to SEV-SNP attestation but to the general system health. tglx has some patches which verify what has been successfully loaded where so hopefully we'll be verifying more in that area.
I had assumed that the SEV-SNP microcode revision attestation was for all logical processors on the host. Are you saying that it is not?
Borislav Petkov
maintainerQuoted 4 lines · Jim Mattson
SEV-SNP is supposed to protect the guest from a malicious host. A malicious host may not load the microcode update on both threads. As a result, it gives me some concern when I see something like this
(https://lore.kernel.org/lkml/[email protected]/):
All I can say is that if this is needed for a SEV/SNP-relevant fix, the attestation flow will be adjusted to handle this properly.
Quoted 2 lines
I had assumed that the SEV-SNP microcode revision attestation was for all logical processors on the host. Are you saying that it is not?
The attestation flow is fine as it takes into account the lowest microcode revision across all cores in the system. So it doesn't matter for SNP which core has been applied successfully or which one hasn't.
HTH.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 2 lines
tglx has some patches which verify what has been successfully loaded where so hopefully we'll be verifying more in that area.
Are those ready for some early testing?
Borislav Petkov
maintainerQuoted 4 lines · Peter Shier
Quoted 2 lines
tglx has some patches which verify what has been successfully loaded where so hopefully we'll be verifying more in that area.
Are those ready for some early testing?
Yap, I'm sure tglx will be happy if people test and report bugs.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: a32b0f0db3f396f1c9be2fe621e77c09ec3d8e7d Gitweb: https://git.kernel.org/tip/a32b0f0db3f396f1c9be2fe621e77c09ec3d8e7d Author: Borislav Petkov (AMD) <[email protected]> AuthorDate: Tue, 02 May 2023 19:53:50 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 12 Jun 2023 11:02:17 +02:00
x86/microcode/AMD: Load late on both threads too
Do the same as early loading - load on both threads.
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -700,7 +700,7 @@ static enum ucode_state apply_microcode_amd(int cpu)rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy);/* need to apply patch? */ -if (rev >= mc_amd->hdr.patch_id) { +if (rev > mc_amd->hdr.patch_id) { ret =UCODE_OK ; goto out; }