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

From: Borislav Petkov
Date: Wed Aug 23 2023 - 01:57:21 EST


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.

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.

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.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette