Skip to contentSkip to conversation

x86/cpu: Fix SPECULATIVE_MITIGATION=n kernels

PATCH Applied Sean Christopherson 8 participants 19 messages Apr 9, 2024 – Apr 19, 2024

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")
---
 kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
index 8f6affd051f7..07ad53b7f119 100644
@@ -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
#2 lore raw

[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.

Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")
Cc Linus Torvalds <[email protected]>
---
 kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
index 8f6affd..07ad53b 100644
@@ -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)
 {
#3 lore raw

Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n

In reply to Sean Christopherson

Hi 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_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.

Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")
---
 kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
index 8f6affd051f7..07ad53b7f119 100644
@@ -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
#4 lore raw

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_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.

Fixes f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")
---
 kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cpu.c +2 -1
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -0
 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?

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

#5 lore raw

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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {

I think a minimal workaround/fix would be:

drivers/base/Kconfig +4 -0
index 2b8fd6bb7da0..290be2f9e909 100644
@@ -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

#6 lore raw

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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {  

I think a minimal workaround/fix would be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..290be2f9e909 100644

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
#7 lore raw

Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n

In reply to Michael Ellerman

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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {

I think a minimal workaround/fix would be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..290be2f9e909 100644

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
#8 lore raw

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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {

I think a minimal workaround/fix would be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..290be2f9e909 100644

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

Quoted 1 line

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
index 2b8fd6bb7da0..5930cb56ee29 100644
@@ -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
#9 lore raw

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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {

I think a minimal workaround/fix would be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..290be2f9e909 100644

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

Quoted 1 line

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 +0 -0
index 2b8fd6bb7da0..5930cb56ee29 100644

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

#10 lore raw

Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n

In reply to Sean Christopherson
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
index 8f6affd051f7..07ad53b7f119 100644
@@ -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 -1
 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)
 {

I think a minimal workaround/fix would be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..290be2f9e909 100644

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

Quoted 1 line

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 +0 -0
index 2b8fd6bb7da0..5930cb56ee29 100644

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

#11 lore raw

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 generic Kconfig, though can't that it more simply be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..5930cb56ee29 100644
@@ -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 GLOB

I 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.

https://lore.kernel.org/all/[email protected]

#12 lore raw

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 generic Kconfig, though can't that it more simply be:

drivers/base/Kconfig +0 -0
index 2b8fd6bb7da0..5930cb56ee29 100644
@@ -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 GLOB

I 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.

https://lore.kernel.org/all/[email protected]

Ah, thanks. I'll go Ack that...

Will

#13 lore raw

Re: [PATCH 1/3] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n

In reply to Sean Christopherson

Hi Sean,

Quoted 8 lines · Sean Christopherson

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.
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")

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
#14 lore raw

PATCH 2/3 x86/cpu: Disable BHI mitigation by default when SPECULATION_MITIGATIONS=n

In reply to Sean Christopherson

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.

Fixes ec9404e40e8f ("x86/bhi: Add BHI mitigation knob")
Cc Pawan Gupta <[email protected]>
Cc Daniel Sneddon <[email protected]>
---
 arch/x86/kernel/cpu/bugs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +3 -3
index 295463707e68..e1775debeafe 100644
@@ -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
#15 lore raw

[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
index 27f5004..7e4a706 100644
@@ -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)
 {
#16 lore raw

PATCH 3/3 x86/cpu: Ignore "mitigations" kernel parameter if SPECULATION_MITIGATIONS=n

In reply to Sean Christopherson

Explicitly 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
index 70046a019d42..7d623df11a1a 100644
@@ -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
index 10a6251f58f3..f4e4dd360636 100644
@@ -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
index 07ad53b7f119..d445763d8047 100644
@@ -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
#17 lore raw

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 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
index 70046a019d42..7d623df11a1a 100644
@@ -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
index 10a6251f58f3..f4e4dd360636 100644
@@ -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 +0 -0
index 07ad53b7f119..d445763d8047 100644

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

Reviewed-by on the v1 series
#18 lore raw
In reply to Sean Christopherson
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