Skip to content

Commit 6893a95

Browse files
committed
x86/speculation: Prepare arch_smt_update() for PRCTL mode
The upcoming fine grained per task STIBP control needs to be updated on CPU hotplug as well. Split out the code which controls the strict mode so the prctl control code can be added later. Mark the SMP function call argument __unused while at it. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Tim Chen <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Casey Schaufler <[email protected]> Cc: Asit Mallick <[email protected]> Cc: Arjan van de Ven <[email protected]> Cc: Jon Masters <[email protected]> Cc: Waiman Long <[email protected]> Cc: Greg KH <[email protected]> Cc: Dave Stewart <[email protected]> Cc: Kees Cook <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 6d991ba commit 6893a95

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -530,40 +530,44 @@ static void __init spectre_v2_select_mitigation(void)
530530
arch_smt_update();
531531
}
532532

533-
static bool stibp_needed(void)
533+
static void update_stibp_msr(void * __unused)
534534
{
535-
/* Enhanced IBRS makes using STIBP unnecessary. */
536-
if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
537-
return false;
538-
539-
/* Check for strict user mitigation mode */
540-
return spectre_v2_user == SPECTRE_V2_USER_STRICT;
535+
wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
541536
}
542537

543-
static void update_stibp_msr(void *info)
538+
/* Update x86_spec_ctrl_base in case SMT state changed. */
539+
static void update_stibp_strict(void)
544540
{
545-
wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
541+
u64 mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
542+
543+
if (sched_smt_active())
544+
mask |= SPEC_CTRL_STIBP;
545+
546+
if (mask == x86_spec_ctrl_base)
547+
return;
548+
549+
pr_info("Update user space SMT mitigation: STIBP %s\n",
550+
mask & SPEC_CTRL_STIBP ? "always-on" : "off");
551+
x86_spec_ctrl_base = mask;
552+
on_each_cpu(update_stibp_msr, NULL, 1);
546553
}
547554

548555
void arch_smt_update(void)
549556
{
550-
u64 mask;
551-
552-
if (!stibp_needed())
557+
/* Enhanced IBRS implies STIBP. No update required. */
558+
if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
553559
return;
554560

555561
mutex_lock(&spec_ctrl_mutex);
556562

557-
mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
558-
if (sched_smt_active())
559-
mask |= SPEC_CTRL_STIBP;
560-
561-
if (mask != x86_spec_ctrl_base) {
562-
pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
563-
mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling");
564-
x86_spec_ctrl_base = mask;
565-
on_each_cpu(update_stibp_msr, NULL, 1);
563+
switch (spectre_v2_user) {
564+
case SPECTRE_V2_USER_NONE:
565+
break;
566+
case SPECTRE_V2_USER_STRICT:
567+
update_stibp_strict();
568+
break;
566569
}
570+
567571
mutex_unlock(&spec_ctrl_mutex);
568572
}
569573

0 commit comments

Comments
 (0)