Re: [PATCH 05/22] x86/srso: Fix SBPB enablement for mitigations=off

From: Josh Poimboeuf
Date: Wed Aug 23 2023 - 16:56:05 EST


On Wed, Aug 23, 2023 at 07:57:20AM +0200, Borislav Petkov wrote:
> On Sun, Aug 20, 2023 at 06:19:02PM -0700, Josh Poimboeuf wrote:
> > If the user has requested no mitigations with mitigations=off, use the
> > lighter-weight SBPB instead of IBPB for other mitigations.
> >
> > Note that even with mitigations=off, IBPB/SBPB may still be used for
> > Spectre v2 user <-> user protection. Whether that makes sense is a
> > question for another day.
>
> Well, with my user hat on, off means off.
>
> IINM, spectre_v2_parse_cmdline() will give SPECTRE_V2_CMD_NONE to
> spectre_v2_select_mitigation() when mitigations=off.
>
> spectre_v2_user_select_mitigation() will use the
> spectre_v2_select_mitigation()'s result, which turn into
> SPECTRE_V2_USER_CMD_NONE and then not enable *BPB either.

Ah, right. I missed how spectre_v2_parse_user_cmdline() checks
spectre_v2_cmd. That is quite the maze.

> So even if we set x86_pred_cmd to SBPB here, it won't do anything
> because X86_FEATURE_USE_IBPB won't be set and
> indirect_branch_prediction_barrier() will be a NOP.

Right.

> IOW, I think we should separate the check:
>
> if (cpu_mitigations_off())
> return;
>
> at the beginning of srso_select_mitigation() so that it is crystal
> clear. Maybe even slap a comment over it.

Yeah, that's fine. I can drop this patch and add a new patch to do
that.

--
Josh