Re: [PATCH v3 2/6] x86/bugs: Use SBPB in __write_ibpb() if applicable

From: Tom Lendacky
Date: Wed Apr 02 2025 - 16:41:41 EST


On 4/2/25 13:19, Josh Poimboeuf wrote:
> __write_ibpb() does IBPB, which (among other things) flushes branch type
> predictions on AMD. If the CPU has SRSO_NO, or if the SRSO mitigation
> has been disabled, branch type flushing isn't needed, in which case the
> lighter-weight SBPB can be used.

Maybe add something here that indicates the x86_pred_cmd variable tracks
this optimization so switch to using that variable vs the hardcoded IBPB?

Thanks,
Tom

>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> ---
> arch/x86/entry/entry.S | 2 +-
> arch/x86/kernel/cpu/bugs.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S
> index 3a53319988b9..a5b421ec19c0 100644
> --- a/arch/x86/entry/entry.S
> +++ b/arch/x86/entry/entry.S
> @@ -21,7 +21,7 @@
> SYM_FUNC_START(__write_ibpb)
> ANNOTATE_NOENDBR
> movl $MSR_IA32_PRED_CMD, %ecx
> - movl $PRED_CMD_IBPB, %eax
> + movl _ASM_RIP(x86_pred_cmd), %eax
> xorl %edx, %edx
> wrmsr
>
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 310cb3f7139c..c8b8dc829046 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(x86_spec_ctrl_base);
> DEFINE_PER_CPU(u64, x86_spec_ctrl_current);
> EXPORT_PER_CPU_SYMBOL_GPL(x86_spec_ctrl_current);
>
> -u64 x86_pred_cmd __ro_after_init = PRED_CMD_IBPB;
> +u32 x86_pred_cmd __ro_after_init = PRED_CMD_IBPB;
> EXPORT_SYMBOL_GPL(x86_pred_cmd);
>
> static u64 __ro_after_init x86_arch_cap_msr;