RE: [PATCH v4 11/36] x86/bugs: Restructure spectre_v2_user mitigation
From: Kaplan, David
Date: Mon Apr 14 2025 - 15:20:34 EST
[AMD Official Use Only - AMD Internal Distribution Only]
> -----Original Message-----
> From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Sent: Thursday, April 10, 2025 11:26 AM
> To: Kaplan, David <David.Kaplan@xxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>; Borislav Petkov <bp@xxxxxxxxx>;
> Peter Zijlstra <peterz@xxxxxxxxxxxxx>; Pawan Gupta
> <pawan.kumar.gupta@xxxxxxxxxxxxxxx>; Ingo Molnar <mingo@xxxxxxxxxx>; Dave
> Hansen <dave.hansen@xxxxxxxxxxxxxxx>; x86@xxxxxxxxxx; H . Peter Anvin
> <hpa@xxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx; Brendan Jackman
> <jackmanb@xxxxxxxxxx>; Derek Manwaring <derekmn@xxxxxxxxxx>
> Subject: Re: [PATCH v4 11/36] x86/bugs: Restructure spectre_v2_user mitigation
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Mon, Mar 10, 2025 at 11:39:58AM -0500, David Kaplan wrote:
> > static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation
> > mode) @@ -1446,10 +1436,10 @@ static inline bool
> spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
> > return spectre_v2_in_eibrs_mode(mode) || mode ==
> > SPECTRE_V2_IBRS; }
> >
> > +
>
> Extra newline here.
Ack
>
> > case SPECTRE_V2_USER_CMD_SECCOMP:
> > - case SPECTRE_V2_USER_CMD_SECCOMP_IBPB:
> > if (IS_ENABLED(CONFIG_SECCOMP))
> > - mode = SPECTRE_V2_USER_SECCOMP;
> > + spectre_v2_user_ibpb = SPECTRE_V2_USER_SECCOMP;
> > else
> > - mode = SPECTRE_V2_USER_PRCTL;
> > + spectre_v2_user_ibpb = SPECTRE_V2_USER_PRCTL;
> > + spectre_v2_user_stibp = spectre_v2_user_ibpb;
> > + break;
> > + case SPECTRE_V2_USER_CMD_SECCOMP_IBPB:
> > + spectre_v2_user_ibpb = SPECTRE_V2_USER_STRICT;
> > + spectre_v2_user_stibp = SPECTRE_V2_USER_PRCTL;
> > break;
> > }
>
> For SPECTRE_V2_USER_CMD_SECCOMP_IBPB, shouldn't
> spectre_v2_user_stibp be SPECTRE_V2_USER_SECCOMP if
> CONFIG_SECCOMP?
Yes, you're right.
>
> Also I think spectre_v2_user_ibpb needs to be cleared here if
> X86_FEATURE_IBPB isn't set. And similar for spectre_v2_user_stibp and
> X86_FEATURE_STIBP.
Ack.
>
> > - /* Initialize Indirect Branch Prediction Barrier */
> > - if (boot_cpu_has(X86_FEATURE_IBPB)) {
> > - static_branch_enable(&switch_vcpu_ibpb);
> > + /*
> > + * At this point, an STIBP mode other than "off" has been set.
> > + * If STIBP support is not being forced, check if STIBP always-on
> > + * is preferred.
> > + */
> > + if (spectre_v2_user_stibp != SPECTRE_V2_USER_STRICT &&
> > + boot_cpu_has(X86_FEATURE_AMD_STIBP_ALWAYS_ON))
> > + spectre_v2_user_stibp =
> > + SPECTRE_V2_USER_STRICT_PREFERRED;
>
> Instead of checking for !SPECTRE_V2_USER_STRICT it would probably be
> better to check for SPECTRE_V2_USER_PRCTL or
> SPECTRE_V2_USER_SECCOMP directly.
>
> Then the returns added to the SPECTRE_V2_USER_CMD_AUTO case in
> "x86/bugs: Add attack vector controls for spectre_v2_user" can be converted to
> breaks, which simplifies the control flow and also allows the above-suggested
> X86_FEATURE_IBPB/X86_FEATURE_STIBP checks to keep working.
>
Got it, yeah will do that.
Thanks --David Kaplan