x86/cpu: Fix SPECULATIVE_MITIGATION=n kernels
Subsystems (7)
cover x86/cpu: Fix SPECULATIVE_MITIGATION=n kernels
Fix the handling of SPECULATION_MITIGATIONS=n so that it actually does what it says it does: disable any and all mitigations.
And because I don't see a way to provide sane behavior for overriding SPECULATION_MITIGATIONS=n at runtime, explicitly disallow doing so via the "mitigations" kernel parameter, e.g. so that the user at least knows that their system is still likely vulnerable to a variety of issues.
Sean Christopherson (3):
x86/cpu: Actually turn off mitigations by default for
SPECULATION_MITIGATIONS=n
x86/cpu: Disable BHI mitigation by default when
SPECULATION_MITIGATIONS=n
x86/cpu: Ignore "mitigations" kernel parameter if
SPECULATION_MITIGATIONS=n
Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/Kconfig | 10 +++++++--- arch/x86/kernel/cpu/bugs.c | 6 +++--- kernel/cpu.c | 5 ++++- 4 files changed, 17 insertions(+), 7 deletions(-)
base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702
Signature · 1 line
2.44.0.478.gd926399ef9-goog
PATCH 1/3 x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Initialize cpu_mitigations to CPU_MITIGATIONS_OFF if the kernel is built with CONFIG_SPECULATION_MITIGATIONS=n, as the help text quite clearly states that disabling SPECULATION_MITIGATIONS is supposed to turn off all mitigations by default.
│ If you say N, all mitigations will be disabled. You really │ should know what you are doing to say so.
As is, the kernel still defaults to CPU_MITIGATIONS_AUTO, which results in some mitigations being enabled in spite of SPECULATION_MITIGATIONS=n.
--- kernel/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
[tip: x86/urgent] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f337a6a21e2fd67eadea471e93d05dd37baaa9be Gitweb: https://git.kernel.org/tip/f337a6a21e2fd67eadea471e93d05dd37baaa9be Author: Sean Christopherson <[email protected]> AuthorDate: Tue, 09 Apr 2024 10:51:05 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 10 Apr 2024 16:22:47 +02:00
x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Initialize cpu_mitigations to CPU_MITIGATIONS_OFF if the kernel is built with CONFIG_SPECULATION_MITIGATIONS=n, as the help text quite clearly states that disabling SPECULATION_MITIGATIONS is supposed to turn off all mitigations by default.
│ If you say N, all mitigations will be disabled. You really │ should know what you are doing to say so.
As is, the kernel still defaults to CPU_MITIGATIONS_AUTO, which results in some mitigations being enabled in spite of SPECULATION_MITIGATIONS=n.
--- kernel/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
In reply to Sean ChristophersonHi Sean,
I noticed this commit in linux-next.
Quoted 36 lines · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
Initialize
cpu_mitigationstoCPU_MITIGATIONS_OFFif the kernel is built withCONFIG_SPECULATION_MITIGATIONS=n, as the help text quite clearly states that disablingSPECULATION_MITIGATIONSis supposed to turn off all mitigations by default.│ If you say N, all mitigations will be disabled. You really │ should know what you are doing to say so.As is, the kernel still defaults to
CPU_MITIGATIONS_AUTO, which results in some mitigations being enabled in spite of SPECULATION_MITIGATIONS=n.Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")Signed-off-by Sean Christopherson <[email protected]>--- kernel/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/cpu.c +2
-1@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {Signature · 1 line
2.44.0.478.gd926399ef9-goog
I noticed because it turned off all mitigations for my PowerPC qemu boot tests - probably because CONFIG_SPECULATION_MITIGATIONS only exists in arch/x86/Kconfig ... thus for other architectures that have cpu mitigations, this will always default them to off, right?
Signature · 2 lines
Cheers, Stephen Rothwell
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 36 lines · Stephen Rothwell
Hi Sean,
I noticed this commit in linux-next.
Quoted 31 lines · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
Initialize
cpu_mitigationstoCPU_MITIGATIONS_OFFif the kernel is built withCONFIG_SPECULATION_MITIGATIONS=n, as the help text quite clearly states that disablingSPECULATION_MITIGATIONSis supposed to turn off all mitigations by default.│ If you say N, all mitigations will be disabled. You really │ should know what you are doing to say so.As is, the kernel still defaults to
CPU_MITIGATIONS_AUTO, which results in some mitigations being enabled in spite of SPECULATION_MITIGATIONS=n.Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")Signed-off-by Sean Christopherson <[email protected]>--- kernel/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/cpu.c +2
-1@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;
Quoted 10 lines
Quoted 5 lines
kernel/cpu.c +0
-0static int __init mitigations_parse_cmdline (char *arg) {Signature · 1 line
2.44.0.478.gd926399ef9-googI noticed because it turned off all mitigations for my PowerPC qemu boot tests - probably because
CONFIG_SPECULATION_MITIGATIONSonly exists inarch/x86/Kconfig... thus for other architectures that have cpu mitigations, this will always default them to off, right?
Yep.
The patch has the effect of changing the default for non-x86 arches from auto to off.
I see at least powerpc, arm64 and s390 use cpu_mitigations_off() and will be affected.
cheers
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {
I think a minimal workaround/fix would be:
drivers/base/Kconfig +4 -0
@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOB
cheers
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Hi all,
Quoted 28 lines · On Sat, 13 Apr 2024 19:38:47 +1000 Michael Ellerman <[email protected]> wrote:
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {I think a minimal workaround/fix would be:
drivers/base/Kconfig +0
-0
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 200
Quoted 10 lines
drivers/base/Kconfig +4
-0@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOB
The original commit is now in Linus' tree.
Signature · 2 lines
Cheers, Stephen Rothwell
Geert Uytterhoeven
Tested-byRe: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
In reply to Michael EllermanHi Michael,
Quoted 27 lines · Michael Ellerman
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {I think a minimal workaround/fix would be:
drivers/base/Kconfig +0
-0
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 200
Quoted 10 lines
drivers/base/Kconfig +4
-0@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOB
Thanks, that works for me (on arm64), so
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 42 lines · Geert Uytterhoeven
Hi Michael,
Quoted 27 lines · Michael Ellerman
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {I think a minimal workaround/fix would be:
drivers/base/Kconfig +0
-0drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 200
Quoted 10 lines
drivers/base/Kconfig +4
-0@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOBThanks, that works for me (on arm64), so
Quoted 1 line
Tested-by Geert Uytterhoeven <[email protected]>
Oof. I completely missed that "cpu_mitigations" wasn't x86-only. I can't think of better solution than an on-by-default generic Kconfig, though can't that it more simply be:
drivers/base/Kconfig +3 -0
@@ -191,6 +191,9 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool !X86 + config SOC_BUS bool select GLOB
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 52 lines · Sean Christopherson
Quoted 40 lines · Geert Uytterhoeven
Quoted 27 lines · Michael Ellerman
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {I think a minimal workaround/fix would be:
drivers/base/Kconfig +0
-0drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 200
Quoted 10 lines
drivers/base/Kconfig +4
-0@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOBThanks, that works for me (on arm64), so
Quoted 1 line
Tested-by Geert Uytterhoeven <[email protected]>Oof. I completely missed that "
cpu_mitigations" wasn't x86-only. I can't think of better solution than an on-by-default genericKconfig, though can't that it more simply be:drivers/base/Kconfig +0
-0
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 196
Quoted 6 lines
drivers/base/Kconfig +3
-0@@ -191,6 +191,9 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool !X86 +
Yeah that works too.
cheers
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
In reply to Sean ChristophersonQuoted 52 lines · Sean Christopherson
Quoted 40 lines · Geert Uytterhoeven
Quoted 27 lines · Michael Ellerman
Quoted 1 line · Michael Ellerman
Stephen Rothwell <[email protected]> writes:
...
Quoted 1 line
Quoted 1 line · On Tue, 9 Apr 2024 10:51:05 -0700 Sean Christopherson <[email protected]>…
...
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
kernel/cpu.c +0
-0@@ -3207,7 +3207,8 @@ enum cpu_mitigations { };Quoted 7 lines
Quoted 7 lines
kernel/cpu.c enum cpu_mitigations { · line 3214
Quoted 7 lines
kernel/cpu.c +2
-1static enum cpu_mitigations cpu_mitigations__ro_after_init = -CPU_MITIGATIONS_AUTO ; +IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS ) ?CPU_MITIGATIONS_AUTO : +CPU_MITIGATIONS_OFF ;static int __init mitigations_parse_cmdline (char *arg) {I think a minimal workaround/fix would be:
drivers/base/Kconfig +0
-0drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 200
Quoted 10 lines
drivers/base/Kconfig +4
-0@@ -191,6 +191,10 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool y + depends on !X86 + config SOC_BUS bool select GLOBThanks, that works for me (on arm64), so
Quoted 1 line
Tested-by Geert Uytterhoeven <[email protected]>Oof. I completely missed that "
cpu_mitigations" wasn't x86-only. I can't think of better solution than an on-by-default genericKconfig, though can't that it more simply be:drivers/base/Kconfig +0
-0
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 199
Quoted 9 lines
drivers/base/Kconfig +3
-0@@ -191,6 +191,9 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool +config SPECULATION_MITIGATIONS + def_bool !X86 + config SOC_BUS bool select GLOB
I can't see this in -next yet. Do you plan to post it as a proper patch to collect acks etc?
Cheers,
Will
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 14 lines · Will Deacon
Quoted 13 lines · Sean Christopherson
On Mon, Apr 15, 2024, Geert Uytterhoeven wrote:
Oof. I completely missed that "cpu_mitigations" wasn't x86-only. I can't think of better solution than an on-by-default genericKconfig, though can't that it more simply be:drivers/base/Kconfig +0
-0@@ -191,6 +191,9 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES bool
Quoted 9 lines
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 199
Quoted 6 lines
drivers/base/Kconfig +3
-0+config SPECULATION_MITIGATIONS + def_bool !X86 + config SOC_BUS bool select GLOBI can't see this in -next yet. Do you plan to post it as a proper patch to collect acks etc?
Sorry, I neglected to Cc everyone.
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
Quoted 25 lines · Sean Christopherson
Quoted 14 lines · Will Deacon
Quoted 13 lines · Sean Christopherson
On Mon, Apr 15, 2024, Geert Uytterhoeven wrote:
Oof. I completely missed that "cpu_mitigations" wasn't x86-only. I can't think of better solution than an on-by-default genericKconfig, though can't that it more simply be:drivers/base/Kconfig +0
-0@@ -191,6 +191,9 @@ config GENERIC_CPU_AUTOPROBE config GENERIC_CPU_VULNERABILITIES boolQuoted 9 lines
drivers/base/Kconfig config GENERIC_CPU_AUTOPROBE · line 199
Quoted 6 lines
drivers/base/Kconfig +3
-0+config SPECULATION_MITIGATIONS + def_bool !X86 + config SOC_BUS bool select GLOBI can't see this in -next yet. Do you plan to post it as a proper patch to collect acks etc?
Quoted 3 lines
Sorry, I neglected to Cc everyone.
Ah, thanks. I'll go Ack that...
Will
Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n
In reply to Sean ChristophersonHi Sean,
Quoted 8 lines · Sean Christopherson
Initialize
cpu_mitigationstoCPU_MITIGATIONS_OFFif the kernel is built withCONFIG_SPECULATION_MITIGATIONS=n, as the help text quite clearly states that disablingSPECULATION_MITIGATIONSis supposed to turn off all mitigations by default.│ If you say N, all mitigations will be disabled. You really │ should know what you are doing to say so.
Quoted 6 lines
As is, the kernel still defaults to
CPU_MITIGATIONS_AUTO, which results in some mitigations being enabled in spite of SPECULATION_MITIGATIONS=n.Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")Signed-off-by Sean Christopherson <[email protected]>
Thanks for your patch, which is now commit f337a6a21e2fd67e ("x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n") in v6.9-rc4.
This causes the following suspicious messages on R-Car H3:
CPU features: kernel page table isolation forced OFF by mitigations=off spectre-v4 mitigation disabled by command-line option spectre-v2 mitigation disabled by command line option spectre-v2 mitigation disabled by command line option
and R-Car V4H:
CPU features: kernel page table isolation forced OFF by mitigations=off spectre-v4 mitigation disabled by command-line option spectre-bhb mitigation disabled by command line option spectre-bhb mitigation disabled by command line option
Interestingly, no mitigations are disabled on the command-line.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
PATCH 2/3 x86/cpu: Disable BHI mitigation by default when SPECULATION_MITIGATIONS=n
In reply to Sean ChristophersonRework the initialization of bhi_mitigation to use positive CONFIG tests for the ON/AUTO cases so that lack of *any* CONFIG_SPECTRE_BHI_* #define, i.e. when the kernel is built with CONFIG_SPECULATION_MITIGATIONS=n, results in the mitigation being OFF by default, not AUTO.
Per the help text for SPECULATION_MITIGATIONS, the intent is that 'N' disables all mitigations.
--- arch/x86/kernel/cpu/bugs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
@@ -1630,9 +1630,9 @@ enum bhi_mitigations { };static enum bhi_mitigations bhi_mitigation__ro_after_init = -IS_ENABLED (CONFIG_SPECTRE_BHI_ON ) ?BHI_MITIGATION_ON : -IS_ENABLED (CONFIG_SPECTRE_BHI_OFF ) ?BHI_MITIGATION_OFF : -BHI_MITIGATION_AUTO ; +IS_ENABLED (CONFIG_SPECTRE_BHI_ON ) ?BHI_MITIGATION_ON : +IS_ENABLED (CONFIG_SPECTRE_BHI_AUTO ) ?BHI_MITIGATION_AUTO : +BHI_MITIGATION_OFF ;static int __init spectre_bhi_parse_cmdline (char *str) {
Signature · 1 line
2.44.0.478.gd926399ef9-goog
[tip: x86/urgent] x86/cpu: Disable BHI mitigation by default when SPECULATION_MITIGATIONS=n
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: e8f2ec1cc10e86adfc2089fb93a1158e69989bbd Gitweb: https://git.kernel.org/tip/e8f2ec1cc10e86adfc2089fb93a1158e69989bbd Author: Sean Christopherson <[email protected]> AuthorDate: Tue, 09 Apr 2024 10:51:06 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 10 Apr 2024 16:22:56 +02:00
x86/cpu: Disable BHI mitigation by default when SPECULATION_MITIGATIONS=n
Rework the initialization of bhi_mitigation to use positive CONFIG tests for the ON/AUTO cases so that lack of *any* CONFIG_SPECTRE_BHI_* #define, i.e. when the kernel is built with CONFIG_SPECULATION_MITIGATIONS=n, results in the mitigation being OFF by default, not AUTO.
Per the help text for SPECULATION_MITIGATIONS, the intent is that 'N' disables all mitigations.
--- arch/x86/kernel/cpu/bugs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
@@ -1630,9 +1630,9 @@ enum bhi_mitigations { };static enum bhi_mitigations bhi_mitigation__ro_after_init = -IS_ENABLED (CONFIG_SPECTRE_BHI_ON ) ?BHI_MITIGATION_ON : -IS_ENABLED (CONFIG_SPECTRE_BHI_OFF ) ?BHI_MITIGATION_OFF : -BHI_MITIGATION_AUTO ; +IS_ENABLED (CONFIG_SPECTRE_BHI_ON ) ?BHI_MITIGATION_ON : +IS_ENABLED (CONFIG_SPECTRE_BHI_AUTO ) ?BHI_MITIGATION_AUTO : +BHI_MITIGATION_OFF ;static int __init spectre_bhi_parse_cmdline (char *str) {
PATCH 3/3 x86/cpu: Ignore "mitigations" kernel parameter if SPECULATION_MITIGATIONS=n
In reply to Sean ChristophersonExplicitly disallow enabling mitigations at runtime for kernels that were built with CONFIG_SPECULATION_MITIGATIONS=n. Because more Kconfigs are buried behind SPECULATION_MITIGATIONS, trying to provide sane behavior for retroactively enabling mitigations is extremely difficult, bordering on impossible. E.g. page table isolation and call depth tracking requrie build-time support, BHI mitigations will still be off without additional kernel parameters, etc.
--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/Kconfig | 10 +++++++--- kernel/cpu.c | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -3423,6 +3423,9 @@ arch-independent options, each of which is an aggregation of existing arch-specific options. + Note, "mitigations" is supported on x86 if and only if + the kernel was built with SPECULATION_MITIGATIONS=y. + off Disable all optional CPU mitigations. This improves system performance, but it may also
arch/x86/Kconfig +7 -3
@@ -2493,10 +2493,14 @@ menuconfig SPECULATION_MITIGATIONS default y help Say Y here to enable options which enable mitigations for - speculative execution hardware vulnerabilities. + speculative execution hardware vulnerabilities. Mitigations can + be disabled or restricted to SMT systems at runtime via the + "mitigations" kernel parameter. - If you say N, all mitigations will be disabled. You really - should know what you are doing to say so. + If you say N, all mitigations will be disabled. This CANNOT be + overridden at runtime. + + Say 'Y', unless you really know what you are doing. if SPECULATION_MITIGATIONS
kernel/cpu.c +2 -0
@@ -3214,6 +3214,8 @@ static int __init mitigations_parse_cmdline(char *arg) {if (!strcmp (arg,"off" )) cpu_mitigations =CPU_MITIGATIONS_OFF ; +else if (!IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS )) +pr_crit ("Kernel compiled without mitigations, system may still be vulnerable\n" );else if (!strcmp (arg,"auto" )) cpu_mitigations =CPU_MITIGATIONS_AUTO ;else if (!strcmp (arg,"auto,nosmt" ))
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Re: [PATCH 3/3] x86/cpu: Ignore "mitigations" kernel parameter if SPECULATION_MITIGATIONS=n
Quoted 56 lines · Sean Christopherson
Explicitly disallow enabling mitigations at runtime for kernels that were built with
CONFIG_SPECULATION_MITIGATIONS=n. Because more Kconfigs are buried behindSPECULATION_MITIGATIONS, trying to provide sane behavior for retroactively enabling mitigations is extremely difficult, bordering on impossible. E.g. page table isolation and call depth tracking requrie build-time support, BHI mitigations will still be off without additional kernel parameters, etc.Signed-off-by Sean Christopherson <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/Kconfig | 10 +++++++--- kernel/cpu.c | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-)Documentation/admin-guide/kernel-parameters.txt +3
-0@@ -3423,6 +3423,9 @@ arch-independent options, each of which is an aggregation of existing arch-specific options. + Note, "mitigations" is supported on x86 if and only if + the kernel was built with SPECULATION_MITIGATIONS=y. + off Disable all optional CPU mitigations. This improves system performance, but it may alsoarch/x86/Kconfig +7
-3@@ -2493,10 +2493,14 @@ menuconfig SPECULATION_MITIGATIONS default y help Say Y here to enable options which enable mitigations for - speculative execution hardware vulnerabilities. + speculative execution hardware vulnerabilities. Mitigations can + be disabled or restricted to SMT systems at runtime via the + "mitigations" kernel parameter. - If you say N, all mitigations will be disabled. You really - should know what you are doing to say so. + If you say N, all mitigations will be disabled. This CANNOT be + overridden at runtime. + + Say 'Y', unless you really know what you are doing. if SPECULATION_MITIGATIONSkernel/cpu.c +0
-0
kernel/cpu.c static int __init mitigations_parse_cmdline(char *arg) · line 3218
Quoted 5 lines
kernel/cpu.c +2
-0@@ -3214,6 +3214,8 @@ static int __init mitigations_parse_cmdline(char *arg) {if (!strcmp (arg,"off" )) cpu_mitigations =CPU_MITIGATIONS_OFF ; +else if (!IS_ENABLED (CONFIG_SPECULATION_MITIGATIONS )) +pr_crit ("Kernel compiled without mitigations, system may still be vulnerable\n" );
This doesn't really make it clear that the kernel is actively ignoring the mitigations= command line. I think something like this would be more clear:
kernel/cpu.c static int __init mitigations_parse_cmdline(char *arg) · line 3219
Quoted 1 line
kernel/cpu.c +1
-0+pr_crit ("Kernel compiled without mitigations, ignoring mitigations= boot option. System may still be vulnerable\n" );
Thanks,
Ingo
Quoted 16 lines · Sean Christopherson
Fix the handling of SPECULATION_MITIGATIONS=n so that it actually does what it says it does: disable any and all mitigations.
And because I don't see a way to provide sane behavior for overriding SPECULATION_MITIGATIONS=n at runtime, explicitly disallow doing so via the "mitigations" kernel parameter, e.g. so that the user at least knows that their system is still likely vulnerable to a variety of issues.
Sean Christopherson (3):
x86/cpu: Actually turn off mitigations by default for
SPECULATION_MITIGATIONS=n
x86/cpu: Disable BHI mitigation by default when
SPECULATION_MITIGATIONS=n
x86/cpu: Ignore "mitigations" kernel parameter if
SPECULATION_MITIGATIONS=n
Quoted 8 lines
Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/Kconfig | 10 +++++++--- arch/x86/kernel/cpu/bugs.c | 6 +++--- kernel/cpu.c | 5 ++++- 4 files changed, 17 insertions(+), 7 deletions(-)base-commit:
2c71fdf02a95b3dd425b42f28fd47fb2b1d22702