RE: [PATCH v5 16/16] x86/bugs: Restructure SRSO mitigation

Kaplan, David
2025-04-29T17:18:30Z

[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Borislav Petkov <bp@alien8.de>
> Sent: Tuesday, April 29, 2025 11:51 AM
> To: Kaplan, David <David.Kaplan@amd.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>; Peter Zijlstra <peterz@infradead.org>;
> Josh Poimboeuf <jpoimboe@kernel.org>; Pawan Gupta
> <pawan.kumar.gupta@linux.intel.com>; Ingo Molnar <mingo@redhat.com>; Dave
> Hansen <dave.hansen@linux.intel.com>; x86@kernel.org; H . Peter Anvin
> <hpa@zytor.com>; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v5 16/16] x86/bugs: Restructure SRSO mitigation
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Fri, Apr 18, 2025 at 11:17:21AM -0500, David Kaplan wrote:
> > @@ -2738,130 +2730,80 @@ static void __init
> > srso_select_mitigation(void) {
> > bool has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE);
>
> I'll push that init after the return so that it doesn't happen unnecessarily.
>
> > - if (!boot_cpu_has_bug(X86_BUG_SRSO) ||
> > - cpu_mitigations_off() ||
> > - srso_cmd == SRSO_CMD_OFF) {
> > - if (boot_cpu_has(X86_FEATURE_SBPB))
> > - x86_pred_cmd = PRED_CMD_SBPB;
> > - goto out;
> > - }
> > + if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
> > + srso_mitigation = SRSO_MITIGATION_NONE;
> > +
> > + if (srso_mitigation == SRSO_MITIGATION_NONE)
> > + return;
> > +
> > + if (srso_mitigation == SRSO_MITIGATION_AUTO)
> > + srso_mitigation = SRSO_MITIGATION_SAFE_RET;
> >
> > if (has_microcode) {
> > /*
> > * Zen1/2 with SMT off aren't vulnerable after the right
> > * IBPB microcode has been applied.
> > - *
> > - * Zen1/2 don't have SBPB, no need to try to enable it here.
>
> Why?
>

The comment doesn't make any sense in the new structure. In the old code, SBPB gets enabled at the start of the function, before we check if you're on a Zen1/2 with SMT off. The comment arguably made some sense in the old code because you're disabling SRSO mitigations but after you had done the SBPB check...but the comment is pointing out this is ok because these CPUs never support SBPB anyway. Normally, if SRSO is off, you try to use SBPB.

In the new flow, the SBPB work is done in srso_apply_mitigation(), and for all parts. So the whole concern about how the code determines SRSO mitigation isn't needed after already handling SBPB doesn't exist anymore.

I'd say this is another reason why the new structure is easier to understand, it has fewer subtleties like this.

--David Kaplan