RE: [PATCH v3 13/35] x86/bugs: Restructure spectre_v2_user mitigation
From: Kaplan, David
Date: Wed Feb 12 2025 - 10:59:50 EST
[AMD Official Use Only - AMD Internal Distribution Only]
> -----Original Message-----
> From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Sent: Monday, February 10, 2025 6:54 PM
> 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
> Subject: Re: [PATCH v3 13/35] 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 Wed, Jan 08, 2025 at 02:24:53PM -0600, David Kaplan wrote:
> > - if (retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
> > - retbleed_mitigation == RETBLEED_MITIGATION_IBPB) {
> > - if (mode != SPECTRE_V2_USER_STRICT &&
> > - mode != SPECTRE_V2_USER_STRICT_PREFERRED)
> > + if (spectre_v2_user_stibp != SPECTRE_V2_USER_NONE &&
> > + (retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
> > + retbleed_mitigation == RETBLEED_MITIGATION_IBPB)) {
>
> This adds a hidden dependency on retbleed_update_mitigation()?
Yeah I guess it does. I'm not sure of a way to cleanly avoid this if the logic is kept as-is, do you think it's ok just to document this dependency explicitly?
The only case I think where this matters is if 'stuff' is selected for retbleed, and then retbleed_update_mitigation decides you can't do that and it has to re-select and may end up with unret or ibpb. That case doesn't even make much sense since 'retbleed=stuff' isn't a mitigation for AMD.
One idea, which would involve changing the logic vs upstream, is that 'retbleed=stuff' should only be allowed on Intel and it should be converted to AUTO on AMD. If that's the case, then there isn't really a hidden dependency anymore since the retbleed mitigation will never change to unret/ibpb during retbleed_update_mitigation(). Thoughts?
>
> Also, that last line should be aligned one more space to the right:
>
> if (spectre_v2_user_stibp != SPECTRE_V2_USER_NONE &&
> (retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
> retbleed_mitigation == RETBLEED_MITIGATION_IBPB)) {
Ack
>
> > +static void __init spectre_v2_user_apply_mitigation(void)
> > +{
> > + /* Initialize Indirect Branch Prediction Barrier */
> > + if (boot_cpu_has(X86_FEATURE_IBPB) &&
> > + spectre_v2_user_ibpb != SPECTRE_V2_USER_NONE) {
> > + setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
> >
> > -set_mode:
> > - pr_info("%s\n", spectre_v2_user_strings[mode]);
> > + switch (spectre_v2_user_ibpb) {
> > + case SPECTRE_V2_USER_NONE:
> > + break;
>
> This case can't happen, spectre_v2_user_ibpb was already checked for
> !SPECTRE_V2_USER_NONE above.
Ack
Thanks --David Kaplan