Skip to content

SSB updates V17 0

Thomas Gleixner historical-speck 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest15 patches 24 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15SSB updates V17 1arch/x86/kvm/svm.c+12 -120 replies
2/15SSB updates V17 2arch/x86/include/asm/cpufeatures.h arch/x86/kernel/cpu/common.c arch/x86/kvm/cpuid.c +2 more+26 -231 reply
3/15SSB updates V17 3arch/x86/include/asm/cpufeatures.h arch/x86/kernel/cpu/bugs.c arch/x86/kernel/cpu/common.c +1 more+20 -91 reply
4/15SSB updates V17 4arch/x86/include/asm/cpufeatures.h arch/x86/kernel/cpu/amd.c arch/x86/kernel/cpu/bugs.c +3 more+14 -161 reply
5/15SSB updates V17 5arch/x86/include/asm/cpufeatures.h arch/x86/kernel/cpu/amd.c+2 -01 reply
6/15SSB updates V17 6arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/process.c arch/x86/kernel/smpboot.c+130 -61 reply
7/15SSB updates V17 7arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/cpu/bugs.c arch/x86/kvm/svm.c +1 more+35 -91 reply
8/15SSB updates V17 8arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/msr-index.h arch/x86/kernel/cpu/bugs.c +1 more+18 -27 replies
9/15SSB updates V17 9arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/cpu/bugs.c arch/x86/kernel/process.c+9 -41 reply
10/15SSB updates V17 10arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/cpu/bugs.c+44 -491 reply
11/15SSB updates V17 11arch/x86/include/asm/nospec-branch.h arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/cpu/bugs.c+6 -241 reply
12/15SSB updates V17 12arch/x86/include/asm/nospec-branch.h arch/x86/kernel/cpu/bugs.c+2 -130 replies
13/15SSB updates V17 13arch/x86/kernel/cpu/bugs.c+20 -82 replies
14/15SSB updates V17 14arch/x86/include/asm/spec-ctrl.h arch/x86/kernel/cpu/bugs.c+36 -02 replies
15/15SSB updates V17 15arch/x86/kernel/cpu/common.c arch/x86/kvm/cpuid.c arch/x86/kvm/svm.c+28 -33 replies

Reviews trailers per patch

13 of 15 patches have a Reviewed-by or Acked-by.

PatchBorislav PetkovKonrad Rzeszutek WilkPaolo BonziniJörg Otte
1/15R-b R-b A-b
2/15R-b T-b
3/15R-b R-b
4/15R-b R-b
5/15R-b R-b
6/15R-b R-b
7/15R-b R-b R-b
8/15R-b
9/15R-b R-b
10/15R-b
11/15R-b R-b
12/15R-b R-b
13/15R-b
14/15
15/15

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v1 thread

Cover letter [patch 00/15] SSB updates V17 0

This is an update to the previous 'SSB updates V16' series which addresses various review comments.

Delta patch below. Git bundle comes in follow up mail.

Thanks,

tglx

8<-----------------

arch/x86/kernel/cpu/bugs.c +21 -15
index ae42e30e7b41..e15c27f5540c 100644
@@ -140,8 +140,8 @@ static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
 void
 x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
 {
-	u64 hostssbd = ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
-	u64 msr, guest, host = x86_spec_ctrl_base;
+	u64 msrval, guestval, hostval = x86_spec_ctrl_base;
+	struct thread_info *ti = current_thread_info();
 
 	/* Is MSR_SPEC_CTRL implemented ? */
 	if (static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) {
@@ -150,39 +150,45 @@ x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
 		 * modifiable bits in the host base value and or the
 		 * modifiable bits from the guest value.
 		 */
-		guest = host & ~x86_spec_ctrl_mask;
-		guest |= guest_spec_ctrl & x86_spec_ctrl_mask;
+		guestval = hostval & ~x86_spec_ctrl_mask;
+		guestval |= guest_spec_ctrl & x86_spec_ctrl_mask;
 
 		/* SSBD controlled in MSR_SPEC_CTRL */
 		if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))
-			host |= hostssbd;
+			hostval |= ssbd_tif_to_spec_ctrl(ti->flags);
 
-		if (host != guest) {
-			msr = setguest ? guest : host;
-			wrmsrl(MSR_IA32_SPEC_CTRL, msr);
+		if (hostval != guest_spec_ctrl) {
+			msrval = setguest ? guest_spec_ctrl : hostval;
+			wrmsrl(MSR_IA32_SPEC_CTRL, msrval);
 		}
 	}
 
 	/*
-	 * If SSBD is not handled in MSR_SPEC_CTRL on AMD update
+	 * If SSBD is not handled in MSR_SPEC_CTRL on AMD, update
 	 * MSR_AMD64_L2_CFG or MSR_VIRT_SPEC_CTRL if supported.
 	 */
 	if (!static_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
 	    !static_cpu_has(X86_FEATURE_VIRT_SSBD))
 		return;
 
-	/* If host has SSBD disabled via command line, force it */
+	/*
+	 * If the host has SSBD mitigation enabled, force it in the host's
+	 * virtual MSR value. If its not permanently enabled, evaluate
+	 * current's TIF_SSBD thread flag.
+	 */
 	if (static_cpu_has(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE))
-		hostssbd |= SPEC_CTRL_SSBD;
+		hostsval = SPEC_CTRL_SSBD;
+	else
+		hostval = ssbd_tif_to_spec_ctrl(ti->flags);
 
 	/* Sanitize the guest value */
-	guest = guest_virt_spec_ctrl & SPEC_CTRL_SSBD;
+	guestval = guest_virt_spec_ctrl & SPEC_CTRL_SSBD;
 
-	if (hostssbd != guest) {
+	if (hostval != guestval) {
 		unsigned long tif;
 
-		tif = setguest ? ssbd_spec_ctrl_to_tif(guest) :
-				 ssbd_spec_ctrl_to_tif(hostssbd);
+		tif = setguest ? ssbd_spec_ctrl_to_tif(guestval) :
+				 ssbd_spec_ctrl_to_tif(hostval);
 
 		speculative_store_bypass_update(tif);
 	}
arch/x86/kernel/cpu/intel.c +1 -0
index dd37244c587a..577e7f7ae273 100644
@@ -191,6 +191,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
 		setup_clear_cpu_cap(X86_FEATURE_MSR_SPEC_CTRL);
 		setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
 		setup_clear_cpu_cap(X86_FEATURE_SSBD);
+		setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL_SSBD);
 	}
 
 	/*
arch/x86/kernel/process.c +21 -4
index 80ef41a2097f..30ca2d1a9231 100644
@@ -299,12 +299,20 @@ void speculative_store_bypass_ht_init(void)
 	unsigned int cpu;
 
 	st->local_state = 0;
+
+	/*
+	 * Shared state setup happens once on the first bringup
+	 * of the CPU. It's not destroyed on CPU hotunplug.
+	 */
 	if (st->shared_state)
 		return;
 
 	raw_spin_lock_init(&st->lock);
 
-	/* Go over HT siblings: */
+	/*
+	 * Go over HT siblings and check whether one of them has set up the
+	 * shared state pointer already.
+	 */
 	for_each_cpu(cpu, topology_sibling_cpumask(this_cpu)) {
 		if (cpu == this_cpu)
 			continue;
@@ -316,13 +324,22 @@ void speculative_store_bypass_ht_init(void)
 		st->shared_state = per_cpu(ssb_state, cpu).shared_state;
 		return;
 	}
-	/* Link shared state of the first HT sibling to itself. */
+
+	/*
+	 * First HT sibling to come up on the core.  Link shared state of
+	 * the first HT sibling to itself. The siblings on the same core
+	 * which come up later will see the shared state pointer and link
+	 * themself to the state of this CPU.
+	 */
 	st->shared_state = st;
 }
 
 /*
- * Logic is: first HT sibling enables SSBD for both siblings in the core and
- * last sibling to disable it, disables it for the whole core.
+ * Logic is: First HT sibling enables SSBD for both siblings in the core
+ * and last sibling to disable it, disables it for the whole core. This how
+ * MSR_SPEC_CTRL works in "hardware":
+ *
+ *  CORE_SPEC_CTRL = THREAD0_SPEC_CTRL | THREAD1_SPEC_CTRL
  */
 static __always_inline void amd_set_core_ssb_state(unsigned long tifn)
 {
arch/x86/kvm/svm.c +3 -3
index c23d2bb0a8bf..47b1c94e035b 100644
@@ -214,9 +214,9 @@ struct vcpu_svm {
 
 	u64 spec_ctrl;
 	/*
-	 * Contains guest-controlled bits of VIRT_SPEC_CTRL, which
-	 * will be translated into the appropriate bits to perform
-	 * speculative control.
+	 * Contains guest-controlled bits of VIRT_SPEC_CTRL, which will be
+	 * translated into the appropriate L2_CFG bits on the host to
+	 * perform speculative control.
 	 */
 	u64 virt_spec_ctrl;