Re: [PATCH] x86/bugs: Default retbleed to =stuff when retpoline is auto enabled

From: Pawan Gupta
Date: Fri Feb 09 2024 - 15:34:02 EST


Hi Josh / Borislav,

On Fri, Feb 09, 2024 at 10:56:25AM -0800, Josh Poimboeuf wrote:
> On Thu, Feb 08, 2024 at 05:12:15PM -0800, Pawan Gupta wrote:
> > @@ -1025,10 +1041,17 @@ static void __init retbleed_select_mitigation(void)
> > retbleed_mitigation = RETBLEED_MITIGATION_UNRET;
> > else if (IS_ENABLED(CONFIG_CPU_IBPB_ENTRY) && boot_cpu_has(X86_FEATURE_IBPB))
> > retbleed_mitigation = RETBLEED_MITIGATION_IBPB;
> > + } else if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
> > + spectre_v2_parse_cmdline() == SPECTRE_V2_CMD_AUTO &&
>
> spectre_v2_parse_cmdline() has side effects (printks) and shouldn't be
> called twice.
>
> And what's the point of checking spectre_v2= anyway? Shouldn't retbleed
> be mitigated by default, independently of whatever the user may have
> specified for Spectre v2?

@Borislav, what do you think about this approach?

> > + spectre_v2_enabled == SPECTRE_V2_RETPOLINE) {
> > + if (IS_ENABLED(CONFIG_CALL_DEPTH_TRACKING))
> > + retbleed_mitigation = RETBLEED_MITIGATION_STUFF;
> > + else
> > + pr_err("WARNING: Retpoline enabled, but kernel not compiled with CALL_DEPTH_TRACKING.\n");
>
> If retbleed is vulnerable then the sysfs file should show that.

It does shows vulnerable, retbleed_mitigation is not set to
RETBLEED_MITIGATION_STUFF for CONFIG_CALL_DEPTH_TRACKING=n.

> Also, I think this pr_err() is redundant with RETBLEED_INTEL_MSG and can
> be removed.

IMO, they both serve a different purpose, RETBLEED_INTEL_MSG is a
generic warning, and the message with !CONFIG_CALL_DEPTH_TRACKING hints
a corrective action.

If you look at "case RETBLEED_CMD_STUFF" it also prints a separate warning for
!CONFIG_CALL_DEPTH_TRACKING:

case RETBLEED_CMD_STUFF:
if (IS_ENABLED(CONFIG_CALL_DEPTH_TRACKING) &&
spectre_v2_enabled == SPECTRE_V2_RETPOLINE) {
retbleed_mitigation = RETBLEED_MITIGATION_STUFF;

} else {
if (IS_ENABLED(CONFIG_CALL_DEPTH_TRACKING))
pr_err("WARNING: retbleed=stuff depends on spectre_v2=retpoline\n");
else
pr_err("WARNING: kernel not compiled with CALL_DEPTH_TRACKING.\n");