Skip to content

Commit a5ce9f2

Browse files
committed
x86/speculation: Merge one test in spectre_v2_user_select_mitigation()
Merge the test whether the CPU supports STIBP into the test which determines whether STIBP is required. Thus try to simplify what is already an insane logic. Remove a superfluous newline in a comment, while at it. Signed-off-by: Borislav Petkov <[email protected]> Cc: Anthony Steinhauser <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b3a9e3b commit a5ce9f2

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,12 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
763763
}
764764

765765
/*
766-
* If enhanced IBRS is enabled or SMT impossible, STIBP is not
766+
* If no STIBP, enhanced IBRS is enabled or SMT impossible, STIBP is not
767767
* required.
768768
*/
769-
if (!smt_possible || spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
769+
if (!boot_cpu_has(X86_FEATURE_STIBP) ||
770+
!smt_possible ||
771+
spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
770772
return;
771773

772774
/*
@@ -778,12 +780,6 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
778780
boot_cpu_has(X86_FEATURE_AMD_STIBP_ALWAYS_ON))
779781
mode = SPECTRE_V2_USER_STRICT_PREFERRED;
780782

781-
/*
782-
* If STIBP is not available, clear the STIBP mode.
783-
*/
784-
if (!boot_cpu_has(X86_FEATURE_STIBP))
785-
mode = SPECTRE_V2_USER_NONE;
786-
787783
spectre_v2_user_stibp = mode;
788784

789785
set_mode:
@@ -1270,7 +1266,6 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
12701266
* Indirect branch speculation is always disabled in strict
12711267
* mode. It can neither be enabled if it was force-disabled
12721268
* by a previous prctl call.
1273-
12741269
*/
12751270
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
12761271
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||

0 commit comments

Comments
 (0)