RE: [PATCH v3 13/35] x86/bugs: Restructure spectre_v2_user mitigation

Kaplan, David
2025-02-12T15:59:40Z

[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Josh Poimboeuf <jpoimboe@kernel.org>
> Sent: Monday, February 10, 2025 6:54 PM
> To: Kaplan, David <David.Kaplan@amd.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>; Borislav Petkov <bp@alien8.de>; Peter
> Zijlstra <peterz@infradead.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 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