Skip to contentSkip to conversation

x86/bugs: Qualify RETBLEED_INTEL_MSG

PATCH Applied David Kaplan 6 participants 28 messages Oct 3, 2025 – Nov 2, 2025

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

PATCH 1/1 x86/bugs: Qualify RETBLEED_INTEL_MSG

When retbleed mitigation is disabled, the kernel already prints an info message that the system is vulnerable. Recent code restructuring also inadvertently led to RETBLEED_INTEL_MSG being printed as an error, which is unnecessary as retbleed mitigation was already explicitly disabled (by config option, cmdline, etc.).

Qualify this print statement so the warning is not printed unless an actual retbleed mitigation was selected and is being disabled due to incompatibility with spectre_v2.

---
 arch/x86/kernel/cpu/bugs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +3 -1
index 6a526ae1fe99..e08de5b0d20b 100644
@@ -1463,7 +1463,9 @@ static void __init retbleed_update_mitigation(void)
 			break;
 		default:
 			if (retbleed_mitigation != RETBLEED_MITIGATION_STUFF) {
-				pr_err(RETBLEED_INTEL_MSG);
+				if (retbleed_mitigation != RETBLEED_MITIGATION_NONE)
+					pr_err(RETBLEED_INTEL_MSG);
+
 				retbleed_mitigation = RETBLEED_MITIGATION_NONE;
 			}
 		}

base-commit: d501f68c45ee1505c4a94c68051387ffa32c9a21

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 21 lines · David Kaplan

When retbleed mitigation is disabled, the kernel already prints an info message that the system is vulnerable. Recent code restructuring also inadvertently led to RETBLEED_INTEL_MSG being printed as an error, which is unnecessary as retbleed mitigation was already explicitly disabled (by config option, cmdline, etc.).

Qualify this print statement so the warning is not printed unless an actual retbleed mitigation was selected and is being disabled due to incompatibility with spectre_v2.

---
 arch/x86/kernel/cpu/bugs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +0 -0
index 6a526ae1fe99..e08de5b0d20b 100644

arch/x86/kernel/cpu/bugs.c static void __init retbleed_update_mitigation(void) · line 1471

Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +3 -1
@@ -1463,7 +1463,9 @@ static void __init retbleed_update_mitigation(void)
 			break;
 		default:
 			if (retbleed_mitigation != RETBLEED_MITIGATION_STUFF) {
-				pr_err(RETBLEED_INTEL_MSG);
+				if (retbleed_mitigation != RETBLEED_MITIGATION_NONE)
+					pr_err(RETBLEED_INTEL_MSG);
+
 				retbleed_mitigation = RETBLEED_MITIGATION_NONE;
 			}
 		}

I guess we can do that for now...

But even with it, my random guest says:

[    0.420377] mitigations: Enabled attack vectors: SMT mitigations: off
[    0.421355] Speculative Store Bypass: Vulnerable
[    0.422234] Spectre V2 : Vulnerable
[    0.422845] Speculative Return Stack Overflow: Vulnerable
[    0.423759] Spectre V1 : Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers

during boot with

# CONFIG_CPU_MITIGATIONS is not set

in its config.

The "Enabled attack vectors" doesn't mean a whole lot if we've disabled mitigations. It probably is even a bit misleading.

The others are perhaps *technically* correct but then we're reporting only a subset of the mitigations and not all for which the machine is affected.

But it ain't the right fix long term, AFAICT.

Because we probably should do this instead:

arch/x86/kernel/cpu/Makefile +1 -1
index 2f8a58ef690e..c789286a480b 100644
@@ -22,7 +22,7 @@ obj-y                 += topology_common.o topology_ext.o topology_amd.o
 obj-y                  += common.o
 obj-y                  += rdrand.o
 obj-y                  += match.o
-obj-y                  += bugs.o
+obj-$(CONFIG_CPU_MITIGATIONS)          += bugs.o
 obj-y                  += aperfmperf.o
 obj-y                  += cpuid-deps.o cpuid_0x2_table.o
 obj-y                  += umwait.o

because off means off and there should be nothing in the boot log about any mitigations and no code should be built in. Which is done now - just the code is inactive which is not what we do with disabled code in the kernel.

But that then causes at least this:

ERROR: modpost: "cpu_buf_vm_clear" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "switch_vcpu_ibpb" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "gds_ucode_mitigated" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "l1tf_vmx_mitigation" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "x86_ibpb_exit_to_user" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "itlb_multihit_kvm_mitigation" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "x86_spec_ctrl_current" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "x86_virt_spec_ctrl" [arch/x86/kvm/kvm-amd.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [/mnt/k/kernel/r/11/linux/Makefile:1960: modpost] Error 2

which means untangling from kvm... which means ugly ifdeffery...

Sounds like a longer project...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 58 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Monday, October 6, 2025 8:11 AM
To: Kaplan, David <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Josh Poimboeuf <[email protected]>; Pawan Gupta <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; Klaus Kusche <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] x86/bugs: Qualify RETBLEED_INTEL_MSG

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 21 lines · David Kaplan

When retbleed mitigation is disabled, the kernel already prints an info message that the system is vulnerable. Recent code restructuring also inadvertently led to RETBLEED_INTEL_MSG being printed as an error, which is unnecessary as retbleed mitigation was already explicitly disabled (by config option, cmdline, etc.).

Qualify this print statement so the warning is not printed unless an actual retbleed mitigation was selected and is being disabled due to incompatibility with spectre_v2.

---
 arch/x86/kernel/cpu/bugs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +0 -0
index 6a526ae1fe99..e08de5b0d20b 100644

arch/x86/kernel/cpu/bugs.c static void __init retbleed_update_mitigation(void) · line 1471

Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +3 -1
@@ -1463,7 +1463,9 @@ static void __init retbleed_update_mitigation(void)
                      break;
              default:
                      if (retbleed_mitigation != RETBLEED_MITIGATION_STUFF) {
-                             pr_err(RETBLEED_INTEL_MSG);
+                             if (retbleed_mitigation != RETBLEED_MITIGATION_NONE)
+                                     pr_err(RETBLEED_INTEL_MSG);
+
                              retbleed_mitigation = RETBLEED_MITIGATION_NONE;
                      }
              }

I guess we can do that for now...

But even with it, my random guest says:

[    0.420377] mitigations: Enabled attack vectors: SMT mitigations: off
[    0.421355] Speculative Store Bypass: Vulnerable
[    0.422234] Spectre V2 : Vulnerable
[    0.422845] Speculative Return Stack Overflow: Vulnerable
[    0.423759] Spectre V1 : Vulnerable: __user pointer sanitization and usercopy
Quoted 7 lines

barriers only; no swapgs barriers

during boot with

# CONFIG_CPU_MITIGATIONS is not set

in its config.

All of the above messages are printed as pr_info() though, while the RETBLEED_INTEL_MSG was printed as pr_err(). Which I think is an important distinction.

Quoted 3 lines

The "Enabled attack vectors" doesn't mean a whole lot if we've disabled mitigations. It probably is even a bit misleading.

We could fix that to print None or something like that if none are selected I suppose.

Quoted 40 lines

The others are perhaps *technically* correct but then we're reporting only a subset of the mitigations and not all for which the machine is affected.

But it ain't the right fix long term, AFAICT.

Because we probably should do this instead:

arch/x86/kernel/cpu/Makefile +0 -0
index 2f8a58ef690e..c789286a480b 100644
@@ -22,7 +22,7 @@ obj-y                 += topology_common.o topology_ext.o

topology_amd.o

 obj-y                  += common.o
 obj-y                  += rdrand.o
 obj-y                  += match.o
arch/x86/kernel/cpu/Makefile +1 -1
-obj-y                  += bugs.o
+obj-$(CONFIG_CPU_MITIGATIONS)          += bugs.o
 obj-y                  += aperfmperf.o
 obj-y                  += cpuid-deps.o cpuid_0x2_table.o
 obj-y                  += umwait.o

because off means off and there should be nothing in the boot log about any mitigations and no code should be built in. Which is done now - just the code is inactive which is not what we do with disabled code in the kernel.

But that then causes at least this:

ERROR: modpost: "cpu_buf_vm_clear" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "switch_vcpu_ibpb" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "gds_ucode_mitigated" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "l1tf_vmx_mitigation" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "x86_ibpb_exit_to_user" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "itlb_multihit_kvm_mitigation" [arch/x86/kvm/kvm.ko] undefined!
ERROR: modpost: "x86_spec_ctrl_current" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "x86_virt_spec_ctrl" [arch/x86/kvm/kvm-amd.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [/mnt/k/kernel/r/11/linux/Makefile:1960: modpost] Error 2

Quoted 4 lines

which means untangling from kvm... which means ugly ifdeffery...

Sounds like a longer project...

Sounds rather yucky. What about just not calling cpu_select_mitigations() if CONFIG_CPU_MITIGATIONS=n? Then you won't get any print messages either I'd think.

--David Kaplan

maintainer
#3 lore raw
Quoted 1 line · David

Sounds rather yucky.

I'll give it a try at some point and see how ugly it becomes...

Quoted 3 lines

What about just not calling cpu_select_mitigations() if CONFIG_CPU_MITIGATIONS=n? Then you won't get any print messages either I'd think.

I want to not compile in that code at all if CPU_MITIGATIONS=off, actually.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#4 lore raw
Quoted 10 lines · Borislav Petkov
Quoted 1 line · David

Sounds rather yucky.

I'll give it a try at some point and see how ugly it becomes...

Quoted 3 lines

What about just not calling cpu_select_mitigations() if CONFIG_CPU_MITIGATIONS=n? Then you won't get any print messages either I'd think.

I want to not compile in that code at all if CPU_MITIGATIONS=off, actually.

Even when CPU mitigations are disabled there is still some handling required for mitigations like GDS that requires a write to MSR to ensure correct behavior. So not all of bugs.c can be compiled out easily.

IMO, rather than targeting the mitigation enabling code it might make more sense to compile out the actual mitigations scattered accross the kernel. This may also improve performance by reducing the code footprint, and can also help getting a cleaner disassembly.

maintainer
#5 lore raw
Quoted 3 lines · Pawan Gupta

Even when CPU mitigations are disabled there is still some handling required for mitigations like GDS that requires a write to MSR to ensure correct behavior.

When mitigations are compiled out there are no mitigations by definition. So whatever you're talking about must be something else which should happen in vendor code.

Quoted 4 lines

IMO, rather than targeting the mitigation enabling code it might make more sense to compile out the actual mitigations scattered accross the kernel. This may also improve performance by reducing the code footprint, and can also help getting a cleaner disassembly.

Probably... however, it needs to be done smartly because sprinkling ifdeffery and turning what is an already unreadable mess into a bigger abomination, won't fly. Perhaps split out the mitigations glue into separate compilation units and build-disable them... we'll see.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#6 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Pawan Gupta

Even when CPU mitigations are disabled there is still some handling required for mitigations like GDS that requires a write to MSR to ensure correct behavior.

When mitigations are compiled out there are no mitigations by definition.

GDS microcode mitigation is enabled by default, for disabling the mitigation an MSR write is required.

Quoted 2 lines

So whatever you're talking about must be something else which should happen in vendor code.

Perhaps yes when bugs.c is compiled out.

Quoted 9 lines
Quoted 4 lines

IMO, rather than targeting the mitigation enabling code it might make more sense to compile out the actual mitigations scattered accross the kernel. This may also improve performance by reducing the code footprint, and can also help getting a cleaner disassembly.

Probably... however, it needs to be done smartly because sprinkling ifdeffery and turning what is an already unreadable mess into a bigger abomination, won't fly. Perhaps split out the mitigations glue into separate compilation units and build-disable them... we'll see.

Ya, that would be better.

maintainer
#7 lore raw
Quoted 6 lines · Pawan Gupta
Quoted 5 lines · Borislav Petkov
Quoted 4 lines · Pawan Gupta

IMO, rather than targeting the mitigation enabling code it might make more sense to compile out the actual mitigations scattered accross the kernel. This may also improve performance by reducing the code footprint, and can also help getting a cleaner disassembly.

Isn't that what CONFIG_CPU_MITIGATIONS=n already does today?

Quoted 6 lines
Quoted 4 lines

Probably... however, it needs to be done smartly because sprinkling ifdeffery and turning what is an already unreadable mess into a bigger abomination, won't fly. Perhaps split out the mitigations glue into separate compilation units and build-disable them... we'll see.

Ya, that would be better.

On a sort of related note, it's confusing that there are two completely different classes of MITIGATION options which get conflated:

1) compile the kernel with support for certain mitigations:

MITIGATION_RETPOLINE
MITIGATION_RETHUNK
MITIGATION_PAGE_TABLE_ISOLATION
MITIGATION_UNRET_ENTRY
MITIGATION_CALL_DEPTH_TRACKING
MITIGATION_IBPB_ENTRY
MITIGATION_IBRS_ENTRY
MITIGATION_SRSO
MITIGATION_SLS

2) enable bug-specific runtime defaults:

MITIGATION_GDS
MITIGATION_RFDS
MITIGATION_SPECTRE_BHI
MITIGATION_MDS
MITIGATION_TAA
MITIGATION_MMIO_STALE_DATA
MITIGATION_L1TF
MITIGATION_RETBLEED
MITIGATION_SPECTRE_V1
MITIGATION_SPECTRE_V2
MITIGATION_SRBDS
MITIGATION_SSB
MITIGATION_ITS
MITIGATION_TSA
MITIGATION_VMSCAPE

In general, #1 uglify the kernel. And some #2 depend on #1.

IMO, we should rename the #1 options. For example:

MITIGATION_RETPOLINE -> X86_UGLY_INDIRECT_THUNKS
MITIGATION_RETHUNK -> X86_UGLY_RETURN_THUNKS

etc...

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

Signature · 1 line
Josh
maintainer
#8 lore raw
Quoted 1 line · Josh Poimboeuf

Isn't that what CONFIG_CPU_MITIGATIONS=n already does today?

I'd like =n to mean, code is not compiled in.

We do have some savings:

text data bss dec hex filename
136442490 9737118 36764336 182943944 ae780c8 vmlinux # CONFIG_CPU_MITIGATIONS is not set
138493310 10692818 37741668 186927796 b244ab4 vmlinux # CONFIG_CPU_MITIGATIONS=y

but look at bugs.o:

# CONFIG_CPU_MITIGATIONS is not set 599K arch/x86/kernel/cpu/bugs.o
# CONFIG_CPU_MITIGATIONS=y 625K arch/x86/kernel/cpu/bugs.o

and those unused 600K still go into vmlinux:

$ readelf -W -s vmlinux | grep cpu_show_
 38058: ffffffff81869d20    27 FUNC    LOCAL  DEFAULT    1 cpu_show_not_affected
 91642: ffffffff81284980    70 FUNC    GLOBAL DEFAULT    1 cpu_show_vmscape
 92944: ffffffff812840f0    68 FUNC    GLOBAL DEFAULT    1 cpu_show_spectre_v1
 93449: ffffffff812847e0    70 FUNC    GLOBAL DEFAULT    1 cpu_show_gds
 96967: ffffffff81869d20    27 FUNC    WEAK   DEFAULT    1 cpu_show_ghostwrite
 99329: ffffffff812843b0    70 FUNC    GLOBAL DEFAULT    1 cpu_show_spec_store_bypass
102119: ffffffff81284830    70 FUNC    GLOBAL DEFAULT    1 cpu_show_reg_file_data_sampling
102618: ffffffff812845b0    56 FUNC    GLOBAL DEFAULT    1 cpu_show_itlb_multihit
102660: ffffffff81284880    85 FUNC    GLOBAL DEFAULT    1 cpu_show_old_microcode
103154: ffffffff812848e0    70 FUNC    GLOBAL DEFAULT    1 cpu_show_indirect_target_selection
103474: ffffffff81284460   164 FUNC    GLOBAL DEFAULT    1 cpu_show_mds
103673: ffffffff81284510   153 FUNC    GLOBAL DEFAULT    1 cpu_show_tsx_async_abort
106613: ffffffff81284930    70 FUNC    GLOBAL DEFAULT    1 cpu_show_tsa
109692: ffffffff81284400    92 FUNC    GLOBAL DEFAULT    1 cpu_show_l1tf
111021: ffffffff81284640   150 FUNC    GLOBAL DEFAULT    1 cpu_show_mmio_stale_data
111165: ffffffff812845f0    70 FUNC    GLOBAL DEFAULT    1 cpu_show_srbds
112332: ffffffff81284090    83 FUNC    GLOBAL DEFAULT    1 cpu_show_meltdown
114213: ffffffff812846e0   174 FUNC    GLOBAL DEFAULT    1 cpu_show_retbleed
114312: ffffffff81284790    70 FUNC    GLOBAL DEFAULT    1 cpu_show_spec_rstack_overflow
118586: ffffffff81284140   619 FUNC    GLOBAL DEFAULT    1 cpu_show_spectre_v2
$ readelf -W -s vmlinux | grep _parse_cmdline
  2575: ffffffff897a0050    27 FUNC    LOCAL  DEFAULT   18 nospectre_v2_parse_cmdline
  2578: ffffffff897a0070    27 FUNC    LOCAL  DEFAULT   18 nossb_parse_cmdline
  2587: ffffffff897a0110    37 FUNC    LOCAL  DEFAULT   18 its_parse_cmdline
  2591: ffffffff897a01d0   138 FUNC    LOCAL  DEFAULT   18 tsx_async_abort_parse_cmdline
  2594: ffffffff897a0260   138 FUNC    LOCAL  DEFAULT   18 mmio_stale_data_parse_cmdline
  2597: ffffffff897a02f0    97 FUNC    LOCAL  DEFAULT   18 rfds_parse_cmdline
  2599: ffffffff897a0360    56 FUNC    LOCAL  DEFAULT   18 srbds_parse_cmdline
  2601: ffffffff897a03a0    38 FUNC    LOCAL  DEFAULT   18 l1d_flush_parse_cmdline
  2603: ffffffff897a03d0    96 FUNC    LOCAL  DEFAULT   18 gds_parse_cmdline
  2604: ffffffff897a0430   166 FUNC    LOCAL  DEFAULT   18 tsa_parse_cmdline
  2606: ffffffff897a04e0   268 FUNC    LOCAL  DEFAULT   18 spectre_v2_user_parse_cmdline
  2608: ffffffff897a05f0   487 FUNC    LOCAL  DEFAULT   18 spectre_v2_parse_cmdline
  2609: ffffffff897a07e0   131 FUNC    LOCAL  DEFAULT   18 spectre_bhi_parse_cmdline
  2611: ffffffff897a0870   206 FUNC    LOCAL  DEFAULT   18 ssb_parse_cmdline
  2613: ffffffff897a0a30   200 FUNC    LOCAL  DEFAULT   18 srso_parse_cmdline
  2615: ffffffff897a0b00   178 FUNC    LOCAL  DEFAULT   18 vmscape_parse_cmdline
  2617: ffffffff897a0bc0   344 FUNC    LOCAL  DEFAULT   18 retbleed_parse_cmdline

and so on...

So I'd like to try to see whether completely axing it off in the =n case without incurring a lot of ugly ifdeffery, would work.

Quoted 2 lines

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

Not sure about UGLY but if you can come up with a name that says "has impact on the resulting code and when you have them enabled, you have weird asm constructs all over the place", sure, why not.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#9 lore raw
Quoted 7 lines · Borislav Petkov
Quoted 1 line · Josh Poimboeuf

Isn't that what CONFIG_CPU_MITIGATIONS=n already does today?

I'd like =n to mean, code is not compiled in.

We do have some savings:

Quoted 8 lines

text data bss dec hex filename
136442490 9737118 36764336 182943944 ae780c8 vmlinux # CONFIG_CPU_MITIGATIONS is not set
138493310 10692818 37741668 186927796 b244ab4 vmlinux # CONFIG_CPU_MITIGATIONS=y

but look at bugs.o:

# CONFIG_CPU_MITIGATIONS is not set 599K arch/x86/kernel/cpu/bugs.o
# CONFIG_CPU_MITIGATIONS=y 625K arch/x86/kernel/cpu/bugs.o

The good news is that CONFIG_CPU_MITIGATIONS=n already seems to remove all the "ugly", but yeah, stripping out bugs.o would be a nice bonus.

Quoted 6 lines
Quoted 2 lines

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

Not sure about UGLY but if you can come up with a name that says "has impact on the resulting code and when you have them enabled, you have weird asm constructs all over the place", sure, why not.

I think almost anything which removes the "MITIGATION" from the name would be an improvement. The build enablements really are a different kind of thing compared to the runtime defaults and it's confusing to intermingle them together.

The "UGLY" was tongue in cheek, but it does have a nice ring to it.

Maybe CONFIG_BUILD_INDIRECT_THUNKS or so.

Signature · 1 line
Josh
maintainer
#10 lore raw
Quoted 8 lines · Josh Poimboeuf

I think almost anything which removes the "MITIGATION" from the name would be an improvement. The build enablements really are a different kind of thing compared to the runtime defaults and it's confusing to intermingle them together.

The "UGLY" was tongue in cheek, but it does have a nice ring to it.

Maybe CONFIG_BUILD_INDIRECT_THUNKS or so.

Right, makes sense.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#11 lore raw
In reply to Borislav Petkov
Quoted 10 lines · Borislav Petkov
Quoted 1 line · Josh Poimboeuf

Isn't that what CONFIG_CPU_MITIGATIONS=n already does today?

I'd like =n to mean, code is not compiled in.

We do have some savings:

text data bss dec hex filename
136442490 9737118 36764336 182943944 ae780c8 vmlinux # CONFIG_CPU_MITIGATIONS is not set
138493310 10692818 37741668 186927796 b244ab4 vmlinux # CONFIG_CPU_MITIGATIONS=y

I guess bulk of these savings are comming from CALL_THUNKS that force 16 byte function alignment.

Quoted 6 lines

but look at bugs.o:

# CONFIG_CPU_MITIGATIONS is not set 599K arch/x86/kernel/cpu/bugs.o
# CONFIG_CPU_MITIGATIONS=y 625K arch/x86/kernel/cpu/bugs.o

and those unused 600K still go into vmlinux:

Thats a lot. OTOH, most of the bugs.c is __init code, do you think it is still problematic?

maintainer
#12 lore raw
Quoted 2 lines · Pawan Gupta

Thats a lot. OTOH, most of the bugs.c is __init code, do you think it is still problematic?

What is wrong with aiming to not have dead code in the kernel if it can be removed cleanly?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#13 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 2 lines · Pawan Gupta

Thats a lot. OTOH, most of the bugs.c is __init code, do you think it is still problematic?

What is wrong with aiming to not have dead code in the kernel if it can be removed cleanly?

Nothing wrong with that. There are certain things (like I mentioned earlier) that needs to be moved out of bugs.c.

#14 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 18 lines

-----Original Message-----
From: Pawan Gupta <[email protected]>
Sent: Thursday, October 9, 2025 12:14 PM
To: Borislav Petkov <[email protected]>
Cc: Josh Poimboeuf <[email protected]>; Kaplan, David <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; Klaus Kusche <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] x86/bugs: Qualify RETBLEED_INTEL_MSG

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 1 line · Borislav Petkov

On Wed, Oct 08, 2025 at 11:04:32PM -0700, Pawan Gupta wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Thats a lot. OTOH, most of the bugs.c is __init code, do you think it is still problematic?

What is wrong with aiming to not have dead code in the kernel if it can be removed cleanly?

Nothing wrong with that. There are certain things (like I mentioned earlier) that needs to be moved out of bugs.c.

If we really want to optimize a CONFIG_CPU_MITIGATIONS=n kernel, why not also look at alternatives that will never be enabled?

All the extra NOPs I think can affect performance in various ways and if there was a way at compile time to know that the alternative would never be enabled (because the feature is completely dependent on a cpu mitigation) you could eliminate the NOPs...

--David Kaplan

maintainer
#15 lore raw
Quoted 7 lines · David

If we really want to optimize a CONFIG_CPU_MITIGATIONS=n kernel, why not also look at alternatives that will never be enabled?

All the extra NOPs I think can affect performance in various ways and if there was a way at compile time to know that the alternative would never be enabled (because the feature is completely dependent on a cpu mitigation) you could eliminate the NOPs...

I don't see why not. That mitigations gunk should be just like any other CONFIG_-controllable item and not simply "leak" into the build because, oh well, we've done it this way from the very beginning and no one should touch it.

So yeah, eventually we should try this. I've been experimenting with untangling bugs.c today, will check how much it actually saves us when I finish beating the stinking pile into submission.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#16 lore raw
Quoted 9 lines · On Fri, 10 Oct 2025 01:14:37 +0200 Borislav Petkov <[email protected]> wrote:
Quoted 7 lines · David

If we really want to optimize a CONFIG_CPU_MITIGATIONS=n kernel, why not also look at alternatives that will never be enabled?

All the extra NOPs I think can affect performance in various ways and if there was a way at compile time to know that the alternative would never be enabled (because the feature is completely dependent on a cpu mitigation) you could eliminate the NOPs...

Quoted 9 lines

I don't see why not. That mitigations gunk should be just like any other CONFIG_-controllable item and not simply "leak" into the build because, oh well, we've done it this way from the very beginning and no one should touch it.

So yeah, eventually we should try this. I've been experimenting with untangling bugs.c today, will check how much it actually saves us when I finish beating the stinking pile into submission.

There are systems (probably with a busybox/buildroot userspace) where, even if everything doesn't run as root, any access that manages to add any code will likely give you root access.
So all the mitigations are just pointless.
Similarly if you disable 'page table separation' (which 'trivially' allows programs to read kernel memory) there is no point compiling in anything else at all.

I'd even suspect that Linus disables them all on his kernel build system.

In both cases you may also want to compile out clac/stac because of their performance impact on most cpu.

David

maintainer
#17 lore raw
In reply to Borislav Petkov
Quoted 9 lines · Borislav Petkov
Quoted 7 lines · David

If we really want to optimize a CONFIG_CPU_MITIGATIONS=n kernel, why not also look at alternatives that will never be enabled?

All the extra NOPs I think can affect performance in various ways and if there was a way at compile time to know that the alternative would never be enabled (because the feature is completely dependent on a cpu mitigation) you could eliminate the NOPs...

Quoted 8 lines

I don't see why not. That mitigations gunk should be just like any other CONFIG_-controllable item and not simply "leak" into the build because, oh well, we've done it this way from the very beginning and no one should touch it.

So yeah, eventually we should try this. I've been experimenting with untangling bugs.c today, will check how much it actually saves us when I finish beating the stinking pile into submission.

So I can't say that it is insignificant:

text data bss dec hex filename

30787172        11613226        7863812 50264210        2fef892 vmlinux.with
30210273        11598338        6061260 47869871        2da6faf vmlinux.without

that's ~500K code on my tailored config, meaning I haven't even enabled all mitigations. So I'm thinking we should do this, but slowly, piecemeal, until we have settled on the layout.

I'll send some patches soon to gather opinions...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer
#18 lore raw
In reply to Josh Poimboeuf
Quoted 9 lines · Josh Poimboeuf
Quoted 6 lines · Pawan Gupta
Quoted 5 lines · Borislav Petkov
Quoted 4 lines · Pawan Gupta

IMO, rather than targeting the mitigation enabling code it might make more sense to compile out the actual mitigations scattered accross the kernel. This may also improve performance by reducing the code footprint, and can also help getting a cleaner disassembly.

Isn't that what CONFIG_CPU_MITIGATIONS=n already does today?

Not entirely, looking at entry_64.o for example, I see 243 NOPs with CONFIG_CPU_MITIGATIONS=n. I suspect a lot of them are due to ALTERNATIVEs for mitigations. In the same file, clear_bhb_loop() is not compliled out and adds ~160 bytes.

Another example is process.c which still contains below functions:

0000000000000000 <speculation_ctrl_update_tif>:
00000000000008b0 <speculative_store_bypass_ht_init>:
0000000000000980 <speculation_ctrl_update>:
0000000000000c30 <speculation_ctrl_update_current>:

Quoted 44 lines
Quoted 6 lines
Quoted 4 lines

Probably... however, it needs to be done smartly because sprinkling ifdeffery and turning what is an already unreadable mess into a bigger abomination, won't fly. Perhaps split out the mitigations glue into separate compilation units and build-disable them... we'll see.

Ya, that would be better.

On a sort of related note, it's confusing that there are two completely different classes of MITIGATION options which get conflated:

1) compile the kernel with support for certain mitigations:

MITIGATION_RETPOLINE
MITIGATION_RETHUNK
MITIGATION_PAGE_TABLE_ISOLATION
MITIGATION_UNRET_ENTRY
MITIGATION_CALL_DEPTH_TRACKING
MITIGATION_IBPB_ENTRY
MITIGATION_IBRS_ENTRY
MITIGATION_SRSO
MITIGATION_SLS

2) enable bug-specific runtime defaults:

MITIGATION_GDS
MITIGATION_RFDS
MITIGATION_SPECTRE_BHI
MITIGATION_MDS
MITIGATION_TAA
MITIGATION_MMIO_STALE_DATA
MITIGATION_L1TF
MITIGATION_RETBLEED
MITIGATION_SPECTRE_V1
MITIGATION_SPECTRE_V2
MITIGATION_SRBDS
MITIGATION_SSB
MITIGATION_ITS
MITIGATION_TSA
MITIGATION_VMSCAPE

In general, #1 uglify the kernel. And some #2 depend on #1.

IMO, we should rename the #1 options. For example:

Quoted 7 lines

MITIGATION_RETPOLINE -> X86_UGLY_INDIRECT_THUNKS
MITIGATION_RETHUNK -> X86_UGLY_RETURN_THUNKS

etc...

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

:-) Agree, this is ugly. One way to handle this could be two levels of Kconfig options like below:

* CONFIG_MITIGATION_FOO - Compiles out the mitigation
* CONFIG_MITIGATION_FOO_DEFAULT - Sets the bootup default
select X86_UGLY_INDIRECT_THUNKS

Then supporting mitigation like INDIRECT_THUNKS would only be enabled if there is a dependent mitigation enabled.

maintainer
#19 lore raw
Quoted 7 lines · Pawan Gupta
Quoted 6 lines · Josh Poimboeuf

On Tue, Oct 07, 2025 at 04:08:21PM -0700, Pawan Gupta wrote:
MITIGATION_RETPOLINE -> X86_UGLY_INDIRECT_THUNKS
MITIGATION_RETHUNK -> X86_UGLY_RETURN_THUNKS

etc...

Quoted 7 lines
Quoted 2 lines

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

:-) Agree, this is ugly. One way to handle this could be two levels of Kconfig options like below:

* CONFIG_MITIGATION_FOO - Compiles out the mitigation

Maybe, though compiling out individual features would be complicated by the fact that we have dependencies between several of the mitigations, as evidenced by *_update_mitigation().

Quoted 1 line

* CONFIG_MITIGATION_FOO_DEFAULT - Sets the bootup default

I'm wondering if we can just get rid of the compiled-in defaults. Do people really need that anymore, now that we have the attack vector controls? We could instead have

CONFIG_CPU_MITIGATIONS_OFF
CONFIG_CPU_MITIGATIONS_AUTO
CONFIG_CPU_MITIGATIONS_AUTO_NOSMT

CONFIG_CPU_MITIGATIONS_USER_USER
CONFIG_CPU_MITIGATIONS_USER_KERNEL
CONFIG_CPU_MITIGATIONS_GUEST_HOST
CONFIG_CPU_MITIGATIONS_GUEST_GUEST

... which should cover the main cases. And of course there's always CONFIG_CMDLINE for more customization.

Quoted 1 line

select X86_UGLY_INDIRECT_THUNKS

Unfortunately it's not always straightforward enough to say "mitigation FOO always needs X ugly feature".

For example, newer CPUs mitigate Spectre v2 with enhanced IBRS, so they don't necessarily need all the retpoline and legacy IBRS stuff. So CONFIG_MITIGATION_SPECTRE_V2 shouldn't enable those unconditionally.

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which then allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

Signature · 1 line
Josh
reviewer
#20 lore raw
Quoted 11 lines · Josh Poimboeuf
Quoted 10 lines · Pawan Gupta
Quoted 8 lines · Josh Poimboeuf

On Tue, Oct 07, 2025 at 04:08:21PM -0700, Pawan Gupta wrote:
MITIGATION_RETPOLINE -> X86_UGLY_INDIRECT_THUNKS
MITIGATION_RETHUNK -> X86_UGLY_RETURN_THUNKS

etc...

Then one only needs to grep their .config file for UGLY to understand why their disassembly is so inscrutable ;-)

Quoted 8 lines
Quoted 4 lines

:-) Agree, this is ugly. One way to handle this could be two levels of Kconfig options like below:

* CONFIG_MITIGATION_FOO - Compiles out the mitigation

Maybe, though compiling out individual features would be complicated by the fact that we have dependencies between several of the mitigations, as evidenced by *_update_mitigation().

My thought was separate them out as:

- Generic mitigation like,
CONFIG_MITIGATION_CLEAR_CPU_BUFFERS
...
which are not directly user selectable.

- Vulnerability based mitigation like,
CONFIG_MITIGATION_MDS
CONFIG_MITIGATION_TAA
CONFIG_MITIGATION_MMIO
CONFIG_MITIGATION_TSA
...
which are user selectable, and does:

select CONFIG_MITIGATION_CLEAR_CPU_BUFFERS

When none from this category is selected, CONFIG_MITIGATION_CLEAR_CPU_BUFFERS stays unset. All of VERW sites can then use CONFIG_MITIGATION_CLEAR_CPU_BUFFERS to not generate NOPs/JMPs as well.

Quoted 10 lines
Quoted 1 line

* CONFIG_MITIGATION_FOO_DEFAULT - Sets the bootup default

I'm wondering if we can just get rid of the compiled-in defaults. Do people really need that anymore, now that we have the attack vector controls? We could instead have

CONFIG_CPU_MITIGATIONS_OFF
CONFIG_CPU_MITIGATIONS_AUTO
CONFIG_CPU_MITIGATIONS_AUTO_NOSMT

Quoted 7 lines

CONFIG_CPU_MITIGATIONS_USER_USER
CONFIG_CPU_MITIGATIONS_USER_KERNEL
CONFIG_CPU_MITIGATIONS_GUEST_HOST
CONFIG_CPU_MITIGATIONS_GUEST_GUEST

... which should cover the main cases. And of course there's always CONFIG_CMDLINE for more customization.

That works too.

Quoted 8 lines
Quoted 1 line

select X86_UGLY_INDIRECT_THUNKS

Unfortunately it's not always straightforward enough to say "mitigation FOO always needs X ugly feature".

For example, newer CPUs mitigate Spectre v2 with enhanced IBRS, so they don't necessarily need all the retpoline and legacy IBRS stuff. So CONFIG_MITIGATION_SPECTRE_V2 shouldn't enable those unconditionally.

A more conservative approach can work here that selects a supporting mitigation even though not all CPUs need it.

Quoted 11 lines

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which then allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

maintainer
#21 lore raw
Quoted 6 lines · Pawan Gupta
Quoted 6 lines

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which then allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

Quoted 8 lines
Quoted 5 lines

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

Why not? A distro can just enable everything:

CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE=y
CONFIG_MITIGATION_SPECTRE_V2_IBRS=y

and then if/when some older HW ages out of being supported by the distro, they can start disabling things.

Signature · 1 line
Josh
reviewer
#22 lore raw
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Pawan Gupta
Quoted 11 lines

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which then allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

Quoted 4 lines
Quoted 2 lines

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

Why not? A distro can just enable everything:

Ahh, right.

Quoted 6 lines

CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE=y
CONFIG_MITIGATION_SPECTRE_V2_IBRS=y

and then if/when some older HW ages out of being supported by the distro, they can start disabling things.

Yup, that makes sense.

#23 lore raw
In reply to Josh Poimboeuf

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 32 lines

-----Original Message-----
From: Josh Poimboeuf <[email protected]>
Sent: Friday, October 10, 2025 2:19 PM
To: Pawan Gupta <[email protected]>
Cc: Borislav Petkov <[email protected]>; Kaplan, David <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; Klaus Kusche <[email protected]>; [email protected]
Subject: Re: [PATCH] x86/bugs: Qualify RETBLEED_INTEL_MSG

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 1 line · Pawan Gupta
Quoted 1 line

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which

then

Quoted 5 lines
Quoted 5 lines

allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

Quoted 8 lines
Quoted 5 lines

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

Quoted 9 lines

Why not? A distro can just enable everything:

CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE=y
CONFIG_MITIGATION_SPECTRE_V2_IBRS=y

and then if/when some older HW ages out of being supported by the distro, they can start disabling things.

Is this really improving things?

There's already a lot of CONFIG options related to mitigations that make testing a pain, and this seems to just make it worse by now having even more options that may or may not make sense together.

I get the value in building a kernel with all mitigations disabled, although frankly I think that only makes sense if it's substantially better than just 'mitigations=off'. But is the cost of only building support for IBRS and not retpoline really buying much?

--David Kaplan

maintainer
#24 lore raw
Quoted 29 lines · David
Quoted 17 lines · Pawan Gupta
Quoted 1 line
Quoted 1 line

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu which

then

Quoted 5 lines
Quoted 5 lines

allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

Quoted 8 lines
Quoted 5 lines

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

Quoted 9 lines

Why not? A distro can just enable everything:

CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE=y
CONFIG_MITIGATION_SPECTRE_V2_IBRS=y

and then if/when some older HW ages out of being supported by the distro, they can start disabling things.

Is this really improving things?

Quoted 8 lines

There's already a lot of CONFIG options related to mitigations that make testing a pain, and this seems to just make it worse by now having even more options that may or may not make sense together.

I get the value in building a kernel with all mitigations disabled, although frankly I think that only makes sense if it's substantially better than just 'mitigations=off'. But is the cost of only building support for IBRS and not retpoline really buying much?

I think this would add several improvements.

It makes it clearer *why* retpolines are enabled: to mitigate Spectre v2 for older hardware. (Though, frustratingly, retpolines have made a comeback thanks to ITS.)

If I know I won't be running my kernel on old HW, this would make it easy to phase out old mitigations that are no longer needed, that otherwise uglify the code and might affect performance even when they're disabled at runtime.

That would be useful for me personally (I don't want that crap in my kernel if I don't need it), but also for distros which phase out support for older CPUs.

Yes, it does add some config options, but we can counterbalance that by removing all the ones which set the defaults, and instead only allow changing defaults at the granularity of attack vectors.

And these MITIGATION config options wouldn't need to be referenced by actual code. Their purpose would be to select CONFIG_BUILD_INDIRECT_THUNKS and friends, as needed, which are in a separate namespace (naming bikeshedding welcome). So overall I think there would be a lot less confusion about the purpose of each config option.

(Yes, CONFIG_MITIGATION_* could also be used to compile out individual mitigations, but I'm not quite convinced that would be worth all the ifdeffery)

That's kind of a lot, I can work up some patches to clarify what it all would look like.

Signature · 1 line
Josh
#25 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 56 lines

-----Original Message-----
From: Josh Poimboeuf <[email protected]>
Sent: Friday, October 10, 2025 3:48 PM
To: Kaplan, David <[email protected]>
Cc: Pawan Gupta <[email protected]>; Borislav Petkov <[email protected]>; Thomas Gleixner <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Dave Hansen <[email protected]>; [email protected]; H . Peter Anvin <[email protected]>; Klaus Kusche <[email protected]>; linux- [email protected]
Subject: Re: [PATCH] x86/bugs: Qualify RETBLEED_INTEL_MSG

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 2 lines · David
Quoted 2 lines · Pawan Gupta
Quoted 1 line
Quoted 1 line

Instead, CONFIG_MITIGATION_SPECTRE_V2 could enable a submenu

which

Quoted 27 lines
Quoted 15 lines

then

Quoted 5 lines
Quoted 5 lines

allows the user to enable retpoline, IBRS on entry, etc, with each having help text describing what generations of CPUs it would be the default for, to help guide the user to choose sane defaults depending on their CPU:

Quoted 8 lines
Quoted 5 lines

* CONFIG_MITIGATION_SPECTRE_V2
* CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE
select CONFIG_BUILD_INDIRECT_THUNKS
* CONFIG_MITIGATION_SPECTRE_V2_IBRS
select CONFIG_BUILD_IBRS_ENTRY

That would be good if a kernel is built for certain specific CPU(s). This may not be ideal for distro kernels.

Quoted 9 lines

Why not? A distro can just enable everything:

CONFIG_MITIGATION_SPECTRE_V2=y
CONFIG_MITIGATION_SPECTRE_V2_RETPOLINE=y
CONFIG_MITIGATION_SPECTRE_V2_IBRS=y

and then if/when some older HW ages out of being supported by the distro, they can start disabling things.

Is this really improving things?

Quoted 8 lines

There's already a lot of CONFIG options related to mitigations that make testing a pain, and this seems to just make it worse by now having even more options that may or may not make sense together.

I get the value in building a kernel with all mitigations disabled, although frankly I think that only makes sense if it's substantially better than just 'mitigations=off'. But is the cost of only building support for IBRS and not retpoline really buying much?

Quoted 5 lines

I think this would add several improvements.

It makes it clearer *why* retpolines are enabled: to mitigate Spectre v2 for older hardware. (Though, frustratingly, retpolines have made a comeback thanks to ITS.)

I don't think you mean 'enabled' here, you mean why they're being built into the kernel? If retpolines are being enabled at runtime, that is reported via sysfs.

Quoted 5 lines

If I know I won't be running my kernel on old HW, this would make it easy to phase out old mitigations that are no longer needed, that otherwise uglify the code and might affect performance even when they're disabled at runtime.

To check if I'm understanding right, is the idea that if you have an ALTERNATIVE that is based on some feature flag (like X86_FEATURE_CLEAR_CPU_BUF) but your kernel is built without any support for those mitigations that need that then that macro would essentially get deleted at compile time so you don't have the extra NOPs? That seems useful.

And if you don't need any retpoline support then you remove retpolines from your compile options?

Quoted 8 lines

That would be useful for me personally (I don't want that crap in my kernel if I don't need it), but also for distros which phase out support for older CPUs.

Yes, it does add some config options, but we can counterbalance that by removing all the ones which set the defaults, and instead only allow changing defaults at the granularity of attack vectors.

I agree that would simplify things

Quoted 8 lines

And these MITIGATION config options wouldn't need to be referenced by actual code. Their purpose would be to select CONFIG_BUILD_INDIRECT_THUNKS and friends, as needed, which are in a separate namespace (naming bikeshedding welcome). So overall I think there would be a lot less confusion about the purpose of each config option.

Quoted 7 lines

(Yes, CONFIG_MITIGATION_* could also be used to compile out individual mitigations, but I'm not quite convinced that would be worth all the ifdeffery)

That's kind of a lot, I can work up some patches to clarify what it all would look like.

Yeah sounds interesting.

Thanks
--David Kaplan

maintainer
#26 lore raw
Quoted 7 lines · David
Quoted 3 lines

It makes it clearer *why* retpolines are enabled: to mitigate Spectre v2 for older hardware. (Though, frustratingly, retpolines have made a comeback thanks to ITS.)

I don't think you mean 'enabled' here, you mean why they're being built into the kernel? If retpolines are being enabled at runtime, that is reported via sysfs.

Right, I meant compiled in.

Quoted 11 lines
Quoted 4 lines

If I know I won't be running my kernel on old HW, this would make it easy to phase out old mitigations that are no longer needed, that otherwise uglify the code and might affect performance even when they're disabled at runtime.

To check if I'm understanding right, is the idea that if you have an ALTERNATIVE that is based on some feature flag (like X86_FEATURE_CLEAR_CPU_BUF) but your kernel is built without any support for those mitigations that need that then that macro would essentially get deleted at compile time so you don't have the extra NOPs? That seems useful.

If we decide we care enough about removing those NOPs, then yes, that would be a use case. We could wrap the CLEAR_CPU_BUFFERS definition with #ifdef CONFIG_UGLY_CLEAR_CPU_BUFFERS or whatever.

Quoted 2 lines

And if you don't need any retpoline support then you remove retpolines from your compile options?

Right.

Signature · 1 line
Josh
merge bot Applied
#27 lore raw
In reply to David Kaplan
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:     204ced4108f5d38f6804968fd9543cc69c3f8da6
Gitweb:        https://git.kernel.org/tip/204ced4108f5d38f6804968fd9543cc69c3f8da6
Author:        David Kaplan <[email protected]>
AuthorDate:    Fri, 03 Oct 2025 12:19:36 -05:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 21 Oct 2025 12:32:28 +02:00

x86/bugs: Qualify RETBLEED_INTEL_MSG

When retbleed mitigation is disabled, the kernel already prints an info message that the system is vulnerable. Recent code restructuring also inadvertently led to RETBLEED_INTEL_MSG being printed as an error, which is unnecessary as retbleed mitigation was already explicitly disabled (by config option, cmdline, etc.).

Qualify this print statement so the warning is not printed unless an actual retbleed mitigation was selected and is being disabled due to incompatibility with spectre_v2.

---
 arch/x86/kernel/cpu/bugs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +3 -1
index 6a526ae..e08de5b 100644
@@ -1463,7 +1463,9 @@ static void __init retbleed_update_mitigation(void)
 			break;
 		default:
 			if (retbleed_mitigation != RETBLEED_MITIGATION_STUFF) {
-				pr_err(RETBLEED_INTEL_MSG);
+				if (retbleed_mitigation != RETBLEED_MITIGATION_NONE)
+					pr_err(RETBLEED_INTEL_MSG);
+
 				retbleed_mitigation = RETBLEED_MITIGATION_NONE;
 			}
 		}