Skip to contentSkip to conversation

SSBD via LS_CFG

PATCH In review Brian Woods 2 participants 7 messages Aug 27, 2018 – Aug 31, 2018

lore
Share & tools
lore
#0 lore raw

v3 cover SSBD via LS_CFG

This series of patches is for enabling SSBD via the LS_CFG MSR for family 15h-17h. The first patch make it so that the information is correctly displayed on boot. The last patch is for further enablement for Xen switching SSBD on or off internally, or for further control of SSBD for guests via the VIRT_SPEC_CTRL.

Note: Patch 1 is standalone and just improves reporting of SSBD in the init print statements. Patch 2 is intended for a later date when there's a C ALTERNATIVE (which I've talked to Andy about some) and will most likely get rolled into series of patches for giving HVM guests control of SSBD when it's only available via LS_CFG.

v1 -> v2:
- changed some variable types
- updated ssbd_amd_ls_cfg_set_nonsmt function
- changed sbd_amd_ls_cfg_init to a presmp_initcall
- deleted ssbd_amd_ls_cfg_set_init due to ^ and it happening later in the boot
- various smaller cleanups
v2 -> v3:
- moved the SSBD_AMD_LS_CFG synthetic feature from patch 1 to 2 and added ssbd_amd_ls_cfg_av for it's use in patch 1
- in patch 2, only set SSBD_AMD_LS_CFG once everything is known to be ready/good
- since it's later in the boot process due to a v1 change, use nr_sockets
- various smaller changes/cleanups from Jan's feedback

Brian Woods (2):
x86/spec-ctrl: add AMD SSBD LS_CFG in init print x86/spec-ctrl: add support for modifying SSBD via LS_CFG MSR

 xen/arch/x86/cpu/amd.c            |  15 ++--
 xen/arch/x86/smpboot.c            |   3 +
 xen/arch/x86/spec_ctrl.c          | 180 +++++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/cpufeatures.h |   1 +
 xen/include/asm-x86/spec_ctrl.h   |   5 ++
 5 files changed, 195 insertions(+), 9 deletions(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v3 1/2 x86/spec-ctrl: add AMD SSBD LS_CFG in init print

Edit the initialization code for AMD's SSBD via the LS_CFG MSR and enable it to pass the status to the initial spec-ctrl print_details at boot.

---
 xen/arch/x86/cpu/amd.c          | 12 +++++++++---
 xen/arch/x86/spec_ctrl.c        | 10 ++++++++--
 xen/include/asm-x86/spec_ctrl.h |  3 +++
 3 files changed, 20 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/amd.c +9 -3
index a7afa2fa7a..6e65ae7427 100644
@@ -604,7 +604,7 @@ static void init_amd(struct cpuinfo_x86 *c)
 	 * If the user has explicitly chosen to disable Memory Disambiguation
 	 * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
 	 */
-	if (opt_ssbd) {
+	if (!ssbd_amd_ls_cfg_mask) {
 		int bit = -1;
 
 		switch (c->x86) {
@@ -613,8 +613,14 @@ static void init_amd(struct cpuinfo_x86 *c)
 		case 0x17: bit = 10; break;
 		}
 
-		if (bit >= 0 && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
-			value |= 1ull << bit;
+		if (bit >= 0)
+			ssbd_amd_ls_cfg_mask = 1ull << bit;
+	}
+
+	if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
+		ssbd_amd_ls_cfg_av = true;
+		if (opt_ssbd) {
+			value |= ssbd_amd_ls_cfg_mask;
 			wrmsr_safe(MSR_AMD64_LS_CFG, value);
 		}
 	}
xen/arch/x86/spec_ctrl.c +8 -2
index c430b25b84..b32c12c6c0 100644
@@ -58,6 +58,9 @@ paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr;
 static bool __initdata cpu_has_bug_l1tf;
 static unsigned int __initdata l1d_maxphysaddr;
 
+bool ssbd_amd_ls_cfg_av;
+uint64_t __read_mostly ssbd_amd_ls_cfg_mask;
+
 static int __init parse_bti(const char *s)
 {
     const char *ss;
@@ -281,11 +284,12 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)
     printk("Speculative mitigation facilities:\n");
 
     /* Hardware features which pertain to speculative mitigations. */
-    printk("  Hardware features:%s%s%s%s%s%s%s%s%s%s\n",
+    printk("  Hardware features:%s%s%s%s%s%s%s%s%s%s%s\n",
            (_7d0 & cpufeat_mask(X86_FEATURE_IBRSB)) ? " IBRS/IBPB" : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_STIBP)) ? " STIBP"     : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_L1D_FLUSH)) ? " L1D_FLUSH" : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_SSBD))  ? " SSBD"      : "",
+           ssbd_amd_ls_cfg_av                       ? " LS_CFG_SSBD" : "",
            (e8b  & cpufeat_mask(X86_FEATURE_IBPB))  ? " IBPB"      : "",
            (caps & ARCH_CAPABILITIES_IBRS_ALL)      ? " IBRS_ALL"  : "",
            (caps & ARCH_CAPABILITIES_RDCL_NO)       ? " RDCL_NO"   : "",
@@ -305,7 +309,7 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)
                "\n");
 
     /* Settings for Xen's protection, irrespective of guests. */
-    printk("  Xen settings: BTI-Thunk %s, SPEC_CTRL: %s%s, Other:%s%s\n",
+    printk("  Xen settings: BTI-Thunk %s, SPEC_CTRL: %s%s%s, Other:%s%s\n",
            thunk == THUNK_NONE      ? "N/A" :
            thunk == THUNK_RETPOLINE ? "RETPOLINE" :
            thunk == THUNK_LFENCE    ? "LFENCE" :
@@ -314,6 +318,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)
            (default_xen_spec_ctrl & SPEC_CTRL_IBRS)  ? "IBRS+" :  "IBRS-",
            !boot_cpu_has(X86_FEATURE_SSBD)           ? "" :
            (default_xen_spec_ctrl & SPEC_CTRL_SSBD)  ? " SSBD+" : " SSBD-",
+           !ssbd_amd_ls_cfg_av                       ? "" :
+           opt_ssbd                                  ? " LS_CFG_SSBD+" : " LS_CFG_SSBD-",
            opt_ibpb                                  ? " IBPB"  : "",
            opt_l1d_flush                             ? " L1D_FLUSH" : "");
 
xen/include/asm-x86/spec_ctrl.h +3 -0
index 8f8aad40bb..1b9101a988 100644
@@ -50,6 +50,9 @@ extern int8_t opt_pv_l1tf;
  */
 extern paddr_t l1tf_addr_mask, l1tf_safe_maddr;
 
+extern bool ssbd_amd_ls_cfg_av;
+extern uint64_t ssbd_amd_ls_cfg_mask;
+
 static inline void init_shadow_spec_ctrl_state(void)
 {
     struct cpu_info *info = get_cpu_info();
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [PATCH v3 1/2] x86/spec-ctrl: add AMD SSBD LS_CFG in init print

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 27.08.18 at 18:54, <[email protected]> wrote:

Edit the initialization code for AMD's SSBD via the LS_CFG MSR and enable it to pass the status to the initial spec-ctrl print_details at boot.

---

I think I had indicated so before: A brief revision log is expected here, in particular to aid people having looked at prior versions of a patch. Whether you also put such a log in the cover letter is up to you, but there it's not normally going to be patch specific.

Quoted 13 lines
xen/arch/x86/cpu/amd.c +1 -1
@@ -604,7 +604,7 @@ static void init_amd(struct cpuinfo_x86 *c)
 	 * If the user has explicitly chosen to disable Memory Disambiguation
 	 * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
 	 */
-	if (opt_ssbd) {
+	if (!ssbd_amd_ls_cfg_mask) {
 		int bit = -1;
 
 		switch (c->x86) {
@@ -613,8 +613,14 @@ static void init_amd(struct cpuinfo_x86 *c)
 		case 0x17: bit = 10; break;

xen/arch/x86/cpu/amd.c static void init_amd(struct cpuinfo_x86 *c) · line 621

Quoted 10 lines
xen/arch/x86/cpu/amd.c +6 -2
 		}
 
-		if (bit >= 0 && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
-			value |= 1ull << bit;
+		if (bit >= 0)
+			ssbd_amd_ls_cfg_mask = 1ull << bit;
+	}
+
+	if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
+		ssbd_amd_ls_cfg_av = true;

"av" is standing for "avail" I guess? If so, I'd prefer if you spelled it out.

Also two of the three comments given on v2 still apply here. Please address _all_ comments either verbally or by code changes before sending a new version.

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 61

Quoted 7 lines
xen/arch/x86/spec_ctrl.c +1 -0
@@ -58,6 +58,9 @@ paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr;
 static bool __initdata cpu_has_bug_l1tf;
 static unsigned int __initdata l1d_maxphysaddr;
 
+bool ssbd_amd_ls_cfg_av;

__read_mostly (afaict)

Also the variable seems pointless - this ...

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 62

Quoted 1 line
xen/arch/x86/spec_ctrl.c +1 -0
+uint64_t __read_mostly ssbd_amd_ls_cfg_mask;

... variable being (non-)zero should suffice as indication. Otherwise the definition of this variable in this file looks wrong, as there's no reference to it in here.

Quoted 52 lines
xen/arch/x86/spec_ctrl.c +2 -1
@@ -281,11 +284,12 @@ static void __init print_details(enum ind_thunk thunk, 
 uint64_t caps)
     printk("Speculative mitigation facilities:\n");
 
     /* Hardware features which pertain to speculative mitigations. */
-    printk("  Hardware features:%s%s%s%s%s%s%s%s%s%s\n",
+    printk("  Hardware features:%s%s%s%s%s%s%s%s%s%s%s\n",
            (_7d0 & cpufeat_mask(X86_FEATURE_IBRSB)) ? " IBRS/IBPB" : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_STIBP)) ? " STIBP"     : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_L1D_FLUSH)) ? " L1D_FLUSH" : "",
            (_7d0 & cpufeat_mask(X86_FEATURE_SSBD))  ? " SSBD"      : "",
+           ssbd_amd_ls_cfg_av                       ? " LS_CFG_SSBD" : "",
            (e8b  & cpufeat_mask(X86_FEATURE_IBPB))  ? " IBPB"      : "",
            (caps & ARCH_CAPABILITIES_IBRS_ALL)      ? " IBRS_ALL"  : "",

(caps & ARCH_CAPABILITIES_RDCL_NO) ? " RDCL_NO" : "",

xen/arch/x86/spec_ctrl.c +1 -1
@@ -305,7 +309,7 @@ static void __init print_details(enum ind_thunk thunk, 
 uint64_t caps)
                "\n");
 
     /* Settings for Xen's protection, irrespective of guests. */
-    printk("  Xen settings: BTI-Thunk %s, SPEC_CTRL: %s%s, Other:%s%s\n",
+    printk("  Xen settings: BTI-Thunk %s, SPEC_CTRL: %s%s%s, Other:%s%s\n",
            thunk == THUNK_NONE      ? "N/A" :
            thunk == THUNK_RETPOLINE ? "RETPOLINE" :
            thunk == THUNK_LFENCE    ? "LFENCE" :
xen/arch/x86/spec_ctrl.c +2 -0
@@ -314,6 +318,8 @@ static void __init print_details(enum ind_thunk thunk, 
 uint64_t caps)
            (default_xen_spec_ctrl & SPEC_CTRL_IBRS)  ? "IBRS+" :  "IBRS-",
            !boot_cpu_has(X86_FEATURE_SSBD)           ? "" :
            (default_xen_spec_ctrl & SPEC_CTRL_SSBD)  ? " SSBD+" : " SSBD-",
+           !ssbd_amd_ls_cfg_av                       ? "" :
+           opt_ssbd                                  ? " LS_CFG_SSBD+" : " 
 LS_CFG_SSBD-",
            opt_ibpb                                  ? " IBPB"  : "",
            opt_l1d_flush                             ? " L1D_FLUSH" : "");
xen/include/asm-x86/spec_ctrl.h +3 -0
index 8f8aad40bb..1b9101a988 100644
@@ -50,6 +50,9 @@ extern int8_t opt_pv_l1tf;
  */
 extern paddr_t l1tf_addr_mask, l1tf_safe_maddr;
 
+extern bool ssbd_amd_ls_cfg_av;
+extern uint64_t ssbd_amd_ls_cfg_mask;
+
 static inline void init_shadow_spec_ctrl_state(void)
 {
     struct cpu_info *info = get_cpu_info();
Signature · 1 line
2.11.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

PATCH v3 2/2 x86/spec-ctrl: add support for modifying SSBD via LS_CFG MSR

In reply to Brian Woods

Adds support for modifying the LS_CFG MSR to enable SSBD on supporting AMD CPUs. There needs to be locking logic for family 17h with SMT enabled since both threads share the same MSR. Otherwise, a core just needs to write to the LS_CFG MSR. For more information see:
https://developer.amd.com/wp-content/resources/124441_AMD64_SpeculativeStoreBypassDisable_Whitepaper_final.pdf

---
 xen/arch/x86/cpu/amd.c            |  13 +--
 xen/arch/x86/smpboot.c            |   3 +
 xen/arch/x86/spec_ctrl.c          | 172 +++++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/cpufeatures.h |   1 +
 xen/include/asm-x86/spec_ctrl.h   |   2 +
 5 files changed, 181 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/amd.c +4 -9
index 6e65ae7427..e96f14268e 100644
@@ -601,8 +601,8 @@ static void init_amd(struct cpuinfo_x86 *c)
 	}
 
 	/*
-	 * If the user has explicitly chosen to disable Memory Disambiguation
-	 * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
+	 * Poke the LS_CFG MSR to see if the mitigation for Speculative
+	 * Store Bypass is available.
 	 */
 	if (!ssbd_amd_ls_cfg_mask) {
 		int bit = -1;
@@ -615,14 +615,9 @@ static void init_amd(struct cpuinfo_x86 *c)
 
 		if (bit >= 0)
 			ssbd_amd_ls_cfg_mask = 1ull << bit;
-	}
 
-	if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
-		ssbd_amd_ls_cfg_av = true;
-		if (opt_ssbd) {
-			value |= ssbd_amd_ls_cfg_mask;
-			wrmsr_safe(MSR_AMD64_LS_CFG, value);
-		}
+		if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value))
+			ssbd_amd_ls_cfg_av = true;
 	}
 
 	/* MFENCE stops RDTSC speculation */
xen/arch/x86/smpboot.c +3 -0
index 7e76cc3d68..b103b46dee 100644
@@ -376,6 +376,9 @@ void start_secondary(void *unused)
     if ( boot_cpu_has(X86_FEATURE_IBRSB) )
         wrmsrl(MSR_SPEC_CTRL, default_xen_spec_ctrl);
 
+    if ( default_xen_ssbd_amd_ls_cfg_en )
+        ssbd_amd_ls_cfg_set(true);
+
     if ( xen_guest )
         hypervisor_ap_setup();
 
xen/arch/x86/spec_ctrl.c +171 -1

204 lines not on this page · raw message

xen/include/asm-x86/cpufeatures.h +1 -0
index 249fa6e531..8927704ef3 100644
@@ -33,3 +33,4 @@ XEN_CPUFEATURE(SC_RSB_HVM,      (FSCAPINTS+0)*32+19) /* RSB overwrite needed for
 XEN_CPUFEATURE(NO_XPTI,         (FSCAPINTS+0)*32+20) /* XPTI mitigation not in use */
 XEN_CPUFEATURE(SC_MSR_IDLE,     (FSCAPINTS+0)*32+21) /* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */
 XEN_CPUFEATURE(XEN_LBR,         (FSCAPINTS+0)*32+22) /* Xen uses MSR_DEBUGCTL.LBR */
+XEN_CPUFEATURE(SSBD_AMD_LS_CFG, (FSCAPINTS+0)*32+23) /* if SSBD support is enabled via LS    _CGF MSR on AMD hardware */
xen/include/asm-x86/spec_ctrl.h +2 -0
index 1b9101a988..b142cf09d7 100644
@@ -52,6 +52,8 @@ extern paddr_t l1tf_addr_mask, l1tf_safe_maddr;
 
 extern bool ssbd_amd_ls_cfg_av;
 extern uint64_t ssbd_amd_ls_cfg_mask;
+extern bool default_xen_ssbd_amd_ls_cfg_en;
+extern void ssbd_amd_ls_cfg_set(bool enable_ssbd);
 
 static inline void init_shadow_spec_ctrl_state(void)
 {
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [PATCH v3 2/2] x86/spec-ctrl: add support for modifying SSBD via LS_CFG MSR

Quoted 77 lines
Quoted 1 line
Quoted 1 line · On 27.08.18 at 18:55, <[email protected]> wrote:

Adds support for modifying the LS_CFG MSR to enable SSBD on supporting AMD CPUs. There needs to be locking logic for family 17h with SMT enabled since both threads share the same MSR. Otherwise, a core just needs to write to the LS_CFG MSR. For more information see:
https://developer.amd.com/wp-content/resources/124441_AMD64_SpeculativeStoreB
ypassDisable_Whitepaper_final.pdf

---
 xen/arch/x86/cpu/amd.c            |  13 +--
 xen/arch/x86/smpboot.c            |   3 +
 xen/arch/x86/spec_ctrl.c          | 172 
+++++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/cpufeatures.h |   1 +
 xen/include/asm-x86/spec_ctrl.h   |   2 +
 5 files changed, 181 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/amd.c +4 -9
index 6e65ae7427..e96f14268e 100644
@@ -601,8 +601,8 @@ static void init_amd(struct cpuinfo_x86 *c)
 	}
 
 	/*
-	 * If the user has explicitly chosen to disable Memory Disambiguation
-	 * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
+	 * Poke the LS_CFG MSR to see if the mitigation for Speculative
+	 * Store Bypass is available.
 	 */
 	if (!ssbd_amd_ls_cfg_mask) {
 		int bit = -1;
@@ -615,14 +615,9 @@ static void init_amd(struct cpuinfo_x86 *c)
 
 		if (bit >= 0)
 			ssbd_amd_ls_cfg_mask = 1ull << bit;
-	}
 
-	if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
-		ssbd_amd_ls_cfg_av = true;
-		if (opt_ssbd) {
-			value |= ssbd_amd_ls_cfg_mask;
-			wrmsr_safe(MSR_AMD64_LS_CFG, value);
-		}
+		if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value))
+			ssbd_amd_ls_cfg_av = true;
 	}
 
 	/* MFENCE stops RDTSC speculation */
xen/arch/x86/smpboot.c +3 -0
index 7e76cc3d68..b103b46dee 100644
@@ -376,6 +376,9 @@ void start_secondary(void *unused)
     if ( boot_cpu_has(X86_FEATURE_IBRSB) )
         wrmsrl(MSR_SPEC_CTRL, default_xen_spec_ctrl);
 
+    if ( default_xen_ssbd_amd_ls_cfg_en )
+        ssbd_amd_ls_cfg_set(true);
+
     if ( xen_guest )
         hypervisor_ap_setup();
 
xen/arch/x86/spec_ctrl.c +1 -0
index b32c12c6c0..89cc444f56 100644
@@ -20,6 +20,7 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/warning.h>
+#include <xen/spinlock.h>
 
 #include <asm/microcode.h>
 #include <asm/msr.h>

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 63

Quoted 5 lines
xen/arch/x86/spec_ctrl.c +2 -0
@@ -58,8 +59,17 @@ paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr;
 static bool __initdata cpu_has_bug_l1tf;
 static unsigned int __initdata l1d_maxphysaddr;
 
+/* for SSBD support for AMD via LS_CFG */
+#define SSBD_AMD_MAX_SOCKET 4

Oh, went up from 2 to 4? But still not a dynamic upper bound?

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 67

Quoted 4 lines
xen/arch/x86/spec_ctrl.c +4 -0
+struct ssbd_amd_ls_cfg_smt_status {
+    spinlock_t lock;
+    uint32_t mask;
+} __attribute__ ((aligned (64)));

Ehem. See the respective comment on patch 1. To put it bluntly, I'm not willing to look at patches where prior comments were not addressed, the more that you had verbally agreed to use SMP_CACHE_BYTES here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH v3 2/2] x86/spec-ctrl: add support for modifying SSBD via LS_CFG MSR

Quoted 80 lines · Jan Beulich
Quoted 80 lines
Quoted 1 line
Quoted 1 line · On 27.08.18 at 18:55, <[email protected]> wrote:

Adds support for modifying the LS_CFG MSR to enable SSBD on supporting AMD CPUs. There needs to be locking logic for family 17h with SMT enabled since both threads share the same MSR. Otherwise, a core just needs to write to the LS_CFG MSR. For more information see:
https://developer.amd.com/wp-content/resources/124441_AMD64_SpeculativeStoreB
ypassDisable_Whitepaper_final.pdf

---
 xen/arch/x86/cpu/amd.c            |  13 +--
 xen/arch/x86/smpboot.c            |   3 +
 xen/arch/x86/spec_ctrl.c          | 172 
+++++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/cpufeatures.h |   1 +
 xen/include/asm-x86/spec_ctrl.h   |   2 +
 5 files changed, 181 insertions(+), 10 deletions(-)
xen/arch/x86/cpu/amd.c +4 -9
index 6e65ae7427..e96f14268e 100644
@@ -601,8 +601,8 @@ static void init_amd(struct cpuinfo_x86 *c)
 	}
 
 	/*
-	 * If the user has explicitly chosen to disable Memory Disambiguation
-	 * to mitigiate Speculative Store Bypass, poke the appropriate MSR.
+	 * Poke the LS_CFG MSR to see if the mitigation for Speculative
+	 * Store Bypass is available.
 	 */
 	if (!ssbd_amd_ls_cfg_mask) {
 		int bit = -1;
@@ -615,14 +615,9 @@ static void init_amd(struct cpuinfo_x86 *c)
 
 		if (bit >= 0)
 			ssbd_amd_ls_cfg_mask = 1ull << bit;
-	}
 
-	if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value)) {
-		ssbd_amd_ls_cfg_av = true;
-		if (opt_ssbd) {
-			value |= ssbd_amd_ls_cfg_mask;
-			wrmsr_safe(MSR_AMD64_LS_CFG, value);
-		}
+		if (ssbd_amd_ls_cfg_mask && !rdmsr_safe(MSR_AMD64_LS_CFG, value))
+			ssbd_amd_ls_cfg_av = true;
 	}
 
 	/* MFENCE stops RDTSC speculation */
xen/arch/x86/smpboot.c +3 -0
index 7e76cc3d68..b103b46dee 100644
@@ -376,6 +376,9 @@ void start_secondary(void *unused)
     if ( boot_cpu_has(X86_FEATURE_IBRSB) )
         wrmsrl(MSR_SPEC_CTRL, default_xen_spec_ctrl);
 
+    if ( default_xen_ssbd_amd_ls_cfg_en )
+        ssbd_amd_ls_cfg_set(true);
+
     if ( xen_guest )
         hypervisor_ap_setup();
 
xen/arch/x86/spec_ctrl.c +1 -0
index b32c12c6c0..89cc444f56 100644
@@ -20,6 +20,7 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/warning.h>
+#include <xen/spinlock.h>
 
 #include <asm/microcode.h>
 #include <asm/msr.h>
@@ -58,8 +59,17 @@ paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr;
 static bool __initdata cpu_has_bug_l1tf;
 static unsigned int __initdata l1d_maxphysaddr;
 
Quoted 5 lines

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 63

Quoted 2 lines
xen/arch/x86/spec_ctrl.c +2 -0
+/* for SSBD support for AMD via LS_CFG */
+#define SSBD_AMD_MAX_SOCKET 4

Oh, went up from 2 to 4? But still not a dynamic upper bound?

Well, 4 was just to be safe. 2 is more than reasonable IMO. Having it dynamic seems like a lot of work to save 8 bytes (or after the bump to 4, 24 bytes) when it doesn't get used.

Quoted 10 lines

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 67

Quoted 4 lines
xen/arch/x86/spec_ctrl.c +4 -0
+struct ssbd_amd_ls_cfg_smt_status {
+    spinlock_t lock;
+    uint32_t mask;
+} __attribute__ ((aligned (64)));

Ehem. See the respective comment on patch 1. To put it bluntly, I'm not willing to look at patches where prior comments were not addressed, the more that you had verbally agreed to use SMP_CACHE_BYTES here.

Quoted 2 lines

Jan

Well, a rebasing failed and I had to regenerate the patches from a diff of the v3 patches combined, and I missed fixing that one part. I'm terrible sorry I missed that one fix.

Signature · 6 lines
Brian Woods

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH v3 2/2] x86/spec-ctrl: add support for modifying SSBD via LS_CFG MSR

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 20:09, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 27.08.18 at 18:55, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +1 -0
@@ -20,6 +20,7 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/warning.h>
+#include <xen/spinlock.h>
 
 #include <asm/microcode.h>
 #include <asm/msr.h>
@@ -58,8 +59,17 @@ paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr;
 static bool __initdata cpu_has_bug_l1tf;
 static unsigned int __initdata l1d_maxphysaddr;
 
Quoted 5 lines

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 63

Quoted 2 lines
xen/arch/x86/spec_ctrl.c +2 -0
+/* for SSBD support for AMD via LS_CFG */
+#define SSBD_AMD_MAX_SOCKET 4

Oh, went up from 2 to 4? But still not a dynamic upper bound?

Quoted 3 lines

Well, 4 was just to be safe. 2 is more than reasonable IMO. Having it dynamic seems like a lot of work to save 8 bytes (or after the bump to 4, 24 bytes) when it doesn't get used.

Well, am I misremembering that I saw you say somewhere that you'd switch to using nr_sockets?

Quoted 10 lines
Quoted 9 lines

xen/arch/x86/spec_ctrl.c paddr_t __read_mostly l1tf_addr_mask, __read_mostly l1tf_safe_maddr; · line 67

Quoted 4 lines
xen/arch/x86/spec_ctrl.c +4 -0
+struct ssbd_amd_ls_cfg_smt_status {
+    spinlock_t lock;
+    uint32_t mask;
+} __attribute__ ((aligned (64)));

Ehem. See the respective comment on patch 1. To put it bluntly, I'm not willing to look at patches where prior comments were not addressed, the more that you had verbally agreed to use SMP_CACHE_BYTES here.

Quoted 3 lines

Well, a rebasing failed and I had to regenerate the patches from a diff of the v3 patches combined, and I missed fixing that one part. I'm terrible sorry I missed that one fix.

If it was just that one fix, I wouldn't have stopped review at that point. But together with patch 1 it makes at least three missed fixes, and that made me then consider it too much.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel