Skip to contentSkip to conversation

MDS basics 0

PATCH In review Thomas Gleixner 11 participants 59 messages Mar 1, 2019 – Mar 8, 2019

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v6 cover MDS basics 0

Changes vs. V5:

- Fix tools/ build (Josh)

- Dropped the AIRMONT_MID change as it needs confirmation from Intel

- Made the consolidated whitelist more readable and correct

- Added the MSBDS only quirk for XEON PHI, made the idle flush depend on it and updated the sysfs output accordingly.

- Fixed the protection matrix in the admin documentation and clarified the SMT situation vs. MSBDS only.

- Updated the KVM/VMX changelog.

Delta patch against V5 below.

Available from git:

cvs.ou.linutronix.de:linux/speck/linux WIP.mds

The linux-4.20.y, linux-4.19.y and linux-4.14.y branches are updated as well and contain the untested backports of the pile for reference.

I'll send git bundles of the pile as well.

Thanks,

tglx

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

Documentation/admin-guide/hw-vuln/mds.rst +35 -14
index 73cdc390aece..1de29d28903d 100644
@@ -23,6 +23,10 @@ vulnerability is not present on:
 Whether a processor is affected or not can be read out from the MDS
 vulnerability file in sysfs. See :ref:`mds_sys_info`.
 
+Not all processors are affected by all variants of MDS, but the mitigation
+is identical for all of them so the kernel treats them as a single
+vulnerability.
+
 Related CVEs
 ------------
 
@@ -112,6 +116,7 @@ to the above information:
 
     ========================  ============================================
     'SMT vulnerable'          SMT is enabled
+    'SMT mitigated'           SMT is enabled and mitigated
     'SMT disabled'            SMT is disabled
     'SMT Host state unknown'  Kernel runs in a VM, Host SMT state unknown
     ========================  ============================================
@@ -153,8 +158,12 @@ CPU buffer clearing
   The mitigation for MDS clears the affected CPU buffers on return to user
   space and when entering a guest.
 
-  If SMT is enabled it also clears the buffers on idle entry, but that's not
-  a sufficient SMT protection for all MDS variants; it covers solely MSBDS.
+  If SMT is enabled it also clears the buffers on idle entry when the CPU
+  is only affected by MSBDS and not any other MDS variant, because the
+  other variants cannot be protected against cross Hyper-Thread attacks.
+
+  For CPUs which are only affected by MSBDS the user space, guest and idle
+  transition mitigations are sufficient and SMT is not affected.
 
 .. _virt_mechanism:
 
@@ -168,8 +177,10 @@ Virtualization mitigation
 
     If the L1D flush mitigation is enabled and up to date microcode is
     available, the L1D flush mitigation is automatically protecting the
-    guest transition. If the L1D flush mitigation is disabled the MDS
-    mitigation is disabled as well.
+    guest transition.
+
+    If the L1D flush mitigation is disabled then the MDS mitigation is
+    invoked explicit when the host MDS mitigation is enabled.
 
     For details on L1TF and virtualization see:
     :ref:`Documentation/admin-guide/hw-vuln//l1tf.rst <mitigation_control_kvm>`.
@@ -177,16 +188,18 @@ Virtualization mitigation
   - CPU is not affected by L1TF:
 
     CPU buffers are flushed before entering the guest when the host MDS
-    protection is enabled.
+    mitigation is enabled.
 
   The resulting MDS protection matrix for the host to guest transition:
 
   ============ ===== ============= ============ =================
-   L1TF         MDS   VMX-L1FLUSH   Host MDS     State
+   L1TF         MDS   VMX-L1FLUSH   Host MDS     MDS-State
 
    Don't care   No    Don't care    N/A          Not affected
 
-   Yes          Yes   Disabled      Don't care   Vulnerable
+   Yes          Yes   Disabled      Off          Vulnerable
+
+   Yes          Yes   Disabled      Full         Mitigated
 
    Yes          Yes   Enabled       Don't care   Mitigated
 
@@ -196,7 +209,7 @@ Virtualization mitigation
   ============ ===== ============= ============ =================
 
   This only covers the host to guest transition, i.e. prevents leakage from
-  host to guest, but does not protect the guest internally. Guest need to
+  host to guest, but does not protect the guest internally. Guests need to
   have their own protections.
 
 .. _xeon_phi:
@@ -210,14 +223,22 @@ XEON PHI specific considerations
   for malicious user space. The exposure can be disabled on the kernel
   command line with the 'ring3mwait=disable' command line option.
 
+  XEON PHI is not affected by the other MDS variants and MSBDS is mitigated
+  before the CPU enters a idle state. As XEON PHI is not affected by L1TF
+  either disabling SMT is not required for full protection.
+
 .. _mds_smt_control:
 
 SMT control
 ^^^^^^^^^^^
 
-  To prevent the SMT issues of MDS it might be necessary to disable SMT
-  completely. Disabling SMT can have a significant performance impact, but
-  the impact depends on the type of workloads.
+  All MDS variants except MSBDS can be attacked cross Hyper-Threads. That
+  means on CPUs which are affected by MFBDS or MLPDS it is necessary to
+  disable SMT for full protection. These are most of the affected CPUs; the
+  exception is XEON PHI, see :ref:`xeon_phi`.
+
+  Disabling SMT can have a significant performance impact, but the impact
+  depends on the type of workloads.
 
   See the relevant chapter in the L1TF mitigation documentation for details:
   :ref:`Documentation/admin-guide/hw-vuln/l1tf.rst <smt_control>`.
@@ -260,9 +281,7 @@ Mitigation selection guide
 2. Virtualization with trusted guests
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-   The same considerations as above versus trusted user space apply. See
-   also: :ref:`Documentation/admin-guide/hw-vuln//l1tf.rst <mitigation_selection>`.
-
+   The same considerations as above versus trusted user space apply.
 
 3. Virtualization with untrusted guests
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -270,6 +289,8 @@ Mitigation selection guide
    The protection depends on the state of the L1TF mitigations.
    See :ref:`virt_mechanism`.
 
+   If the MDS mitigation is enabled and SMT is disabled, guest to host and
+   guest to guest attacks are prevented.
 
 .. _mds_default_mitigations:
 
Documentation/x86/mds.rst +18 -11
index b050623c869c..3d6f943f1afb 100644
@@ -107,19 +107,19 @@ user space or VM guests.
 Kernel internal mitigation modes
 --------------------------------
 
- ======= ===========================================================
- off     Mitigation is disabled. Either the CPU is not affected or
-         mds=off is supplied on the kernel command line
+ ======= ============================================================
+ off      Mitigation is disabled. Either the CPU is not affected or
+          mds=off is supplied on the kernel command line
 
- full    Mitigation is eanbled. CPU is affected and MD_CLEAR is
-         advertised in CPUID.
+ full     Mitigation is eanbled. CPU is affected and MD_CLEAR is
+          advertised in CPUID.
 
- vmwerv	 Mitigation is enabled. CPU is affected and MD_CLEAR is not
-	 advertised in CPUID. That is mainly for virtualization
-	 scenarios where the host has the updated microcode but the
-	 hypervisor does not expose MD_CLEAR in CPUID. It's a best
-	 effort approach without guarantee.
- ======= ===========================================================
+ vmwerv	  Mitigation is enabled. CPU is affected and MD_CLEAR is not
+	  advertised in CPUID. That is mainly for virtualization
+	  scenarios where the host has the updated microcode but the
+	  hypervisor does not expose MD_CLEAR in CPUID. It's a best
+	  effort approach without guarantee.
+ ======= ============================================================
 
 If the CPU is affected and mds=off is not supplied on the kernel command
 line then the kernel selects the appropriate mitigation mode depending on
@@ -189,6 +189,13 @@ Mitigation points
    When SMT is inactive, i.e. either the CPU does not support it or all
    sibling threads are offline CPU buffer clearing is not required.
 
+   The idle clearing is enabled on CPUs which are only affected by MSBDS
+   and not by any other MDS variant. The other MDS variants cannot be
+   protected against cross Hyper-Thread attacks because the Fill Buffer and
+   the Load Ports are shared. So on CPUs affected by other variants, the
+   idle clearing would be a window dressing exercise and is therefore not
+   activated.
+
    The invocation is controlled by the static key mds_idle_clear which is
    switched depending on the chosen mitigation mode and the SMT state of
    the system.
arch/x86/include/asm/cpufeatures.h +1 -0
index ae3f987b24f1..bdcea163850a 100644
@@ -383,5 +383,6 @@
 #define X86_BUG_SPEC_STORE_BYPASS	X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 #define X86_BUG_L1TF			X86_BUG(18) /* CPU is affected by L1 Terminal Fault */
 #define X86_BUG_MDS			X86_BUG(19) /* CPU is affected by Microarchitectural data sampling */
+#define X86_BUG_MSBDS_ONLY		X86_BUG(20) /* CPU is only affected by the  MSDBS variant of BUG_MDS */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/bugs.c +14 -0
index aea871e69d64..e11654f93e71 100644
@@ -667,6 +667,15 @@ static void update_indir_branch_cond(void)
 /* Update the static key controlling the MDS CPU buffer clear in idle */
 static void update_mds_branch_idle(void)
 {
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled, so clearing the buffers on
+	 * idle would be a window dressing exercise.
+	 */
+	if (!boot_cpu_has(X86_BUG_MSBDS_ONLY))
+		return;
+
 	if (sched_smt_active())
 		static_branch_enable(&mds_idle_clear);
 	else
@@ -1174,6 +1183,11 @@ static ssize_t mds_show_state(char *buf)
 			       mds_strings[mds_mitigation]);
 	}
 
+	if (boot_cpu_has(X86_BUG_MSBDS_ONLY)) {
+		return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
+			       sched_smt_active() ? "mitigated" : "disabled");
+	}
+
 	return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
 		       sched_smt_active() ? "vulnerable" : "disabled");
 }
arch/x86/kernel/cpu/common.c +53 -31

99 lines not on this page · raw message

tools/power/x86/turbostat/Makefile +1 -1
index 1598b4fa0b11..045f5f7d68ab 100644
@@ -9,7 +9,7 @@ ifeq ("$(origin O)", "command line")
 endif
 
 turbostat : turbostat.c
-override CFLAGS +=	-Wall
+override CFLAGS +=	-Wall -I../../../include
 override CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
 override CFLAGS +=	-DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"'
 
tools/power/x86/x86_energy_perf_policy/Makefile +1 -1
index ae7a0e09b722..1fdeef864e7c 100644
@@ -9,7 +9,7 @@ ifeq ("$(origin O)", "command line")
 endif
 
 x86_energy_perf_policy : x86_energy_perf_policy.c
-override CFLAGS +=	-Wall
+override CFLAGS +=	-Wall -I../../../include
 override CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
 
 %: %.c
#1 lore raw

PATCH v6 1/14 MDS basics 1

Subject: [patch V6 01/14] x86/msr-index: Cleanup bit defines
From: Thomas Gleixner <[email protected]>

Greg pointed out that speculation related bit defines are using (1 << N) format instead of BIT(N). Aside of that (1 << N) is wrong as it should use 1UL at least.

Clean it up.

[ Josh Poimboeuf: Fix tools build ]

---
V5 -> V6: Fix tools build (Josh)

---
 arch/x86/include/asm/msr-index.h                |   34 ++++++++++++------------
 tools/power/x86/turbostat/Makefile              |    2 -
 tools/power/x86/x86_energy_perf_policy/Makefile |    2 -
 3 files changed, 20 insertions(+), 18 deletions(-)
arch/x86/include/asm/msr-index.h +18 -16
@@ -2,6 +2,8 @@
 #ifndef _ASM_X86_MSR_INDEX_H
 #define _ASM_X86_MSR_INDEX_H
 
+#include <linux/bits.h>
+
 /*
  * CPU model specific register (MSR) numbers.
  *
@@ -40,14 +42,14 @@
 /* Intel MSRs. Some also available on other CPUs */
 
 #define MSR_IA32_SPEC_CTRL		0x00000048 /* Speculation Control */
-#define SPEC_CTRL_IBRS			(1 << 0)   /* Indirect Branch Restricted Speculation */
+#define SPEC_CTRL_IBRS			BIT(0)	   /* Indirect Branch Restricted Speculation */
 #define SPEC_CTRL_STIBP_SHIFT		1	   /* Single Thread Indirect Branch Predictor (STIBP) bit */
-#define SPEC_CTRL_STIBP			(1 << SPEC_CTRL_STIBP_SHIFT)	/* STIBP mask */
+#define SPEC_CTRL_STIBP			BIT(SPEC_CTRL_STIBP_SHIFT)	/* STIBP mask */
 #define SPEC_CTRL_SSBD_SHIFT		2	   /* Speculative Store Bypass Disable bit */
-#define SPEC_CTRL_SSBD			(1 << SPEC_CTRL_SSBD_SHIFT)	/* Speculative Store Bypass Disable */
+#define SPEC_CTRL_SSBD			BIT(SPEC_CTRL_SSBD_SHIFT)	/* Speculative Store Bypass Disable */
 
 #define MSR_IA32_PRED_CMD		0x00000049 /* Prediction Command */
-#define PRED_CMD_IBPB			(1 << 0)   /* Indirect Branch Prediction Barrier */
+#define PRED_CMD_IBPB			BIT(0)	   /* Indirect Branch Prediction Barrier */
 
 #define MSR_PPIN_CTL			0x0000004e
 #define MSR_PPIN			0x0000004f
@@ -69,20 +71,20 @@
 #define MSR_MTRRcap			0x000000fe
 
 #define MSR_IA32_ARCH_CAPABILITIES	0x0000010a
-#define ARCH_CAP_RDCL_NO		(1 << 0)   /* Not susceptible to Meltdown */
-#define ARCH_CAP_IBRS_ALL		(1 << 1)   /* Enhanced IBRS support */
-#define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH	(1 << 3)   /* Skip L1D flush on vmentry */
-#define ARCH_CAP_SSB_NO			(1 << 4)   /*
-						    * Not susceptible to Speculative Store Bypass
-						    * attack, so no Speculative Store Bypass
-						    * control required.
-						    */
+#define ARCH_CAP_RDCL_NO		BIT(0)	/* Not susceptible to Meltdown */
+#define ARCH_CAP_IBRS_ALL		BIT(1)	/* Enhanced IBRS support */
+#define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH	BIT(3)	/* Skip L1D flush on vmentry */
+#define ARCH_CAP_SSB_NO			BIT(4)	/*
+						 * Not susceptible to Speculative Store Bypass
+						 * attack, so no Speculative Store Bypass
+						 * control required.
+						 */
 
 #define MSR_IA32_FLUSH_CMD		0x0000010b
-#define L1D_FLUSH			(1 << 0)   /*
-						    * Writeback and invalidate the
-						    * L1 data cache.
-						    */
+#define L1D_FLUSH			BIT(0)	/*
+						 * Writeback and invalidate the
+						 * L1 data cache.
+						 */
 
 #define MSR_IA32_BBL_CR_CTL		0x00000119
 #define MSR_IA32_BBL_CR_CTL3		0x0000011e
tools/power/x86/turbostat/Makefile +1 -1
@@ -9,7 +9,7 @@ ifeq ("$(origin O)", "command line")
 endif
 
 turbostat : turbostat.c
-override CFLAGS +=	-Wall
+override CFLAGS +=	-Wall -I../../../include
 override CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
 override CFLAGS +=	-DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"'
 
tools/power/x86/x86_energy_perf_policy/Makefile +1 -1
@@ -9,7 +9,7 @@ ifeq ("$(origin O)", "command line")
 endif
 
 x86_energy_perf_policy : x86_energy_perf_policy.c
-override CFLAGS +=	-Wall
+override CFLAGS +=	-Wall -I../../../include
 override CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
 
 %: %.c
Reviewed-by on v6 1/14
#2 lore raw

[MODERATED] Re: [patch V6 01/14] MDS basics 1

Quoted 9 lines · speck for Thomas Gleixner

Subject: [patch V6 01/14] x86/msr-index: Cleanup bit defines
From: Thomas Gleixner <[email protected]>

Greg pointed out that speculation related bit defines are using (1 << N) format instead of BIT(N). Aside of that (1 << N) is wrong as it should use 1UL at least.

Clean it up.

Quoted 8 lines

[ Josh Poimboeuf: Fix tools build ]

---
V5 -> V6: Fix tools build (Josh)

#3 lore raw

PATCH v6 2/14 MDS basics 2

In reply to Thomas Gleixner

Subject: [patch V6 02/14] x86/speculation: Consolidate CPU whitelists
From: Thomas Gleixner <[email protected]>

The CPU vulnerability whitelists have some overlap and there are more whitelists coming along.

Use the driver_data field in the x86_cpu_id struct to denote the whitelisted vulnerabilities and combine all whitelists into one.

---

V5 --> V6: Use a helper macro to make it more readable

           Fix the AMD family 0xf-0x12 vs. ANY ordering
---
 arch/x86/kernel/cpu/common.c |  110 +++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 50 deletions(-)
arch/x86/kernel/cpu/common.c +60 -50
@@ -948,61 +948,72 @@ static void identify_cpu_without_cpuid(s
 #endif
 }
 
-static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
-	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_SALTWELL,	X86_FEATURE_ANY },
-	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_SALTWELL_TABLET,	X86_FEATURE_ANY },
-	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_BONNELL_MID,	X86_FEATURE_ANY },
-	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_SALTWELL_MID,	X86_FEATURE_ANY },
-	{ X86_VENDOR_INTEL,	6, INTEL_FAM6_ATOM_BONNELL,	X86_FEATURE_ANY },
-	{ X86_VENDOR_CENTAUR,	5 },
-	{ X86_VENDOR_INTEL,	5 },
-	{ X86_VENDOR_NSC,	5 },
-	{ X86_VENDOR_ANY,	4 },
+#define NO_SPECULATION	BIT(0)
+#define NO_MELTDOWN	BIT(1)
+#define NO_SSB		BIT(2)
+#define NO_L1TF		BIT(3)
+
+#define VULNWL(_vendor, _family, _model, _whitelist)	\
+	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
+
+#define VULNWL_INTEL(model, whitelist)		\
+	VULNWL(INTEL, 6, INTEL_FAM6_##model, whitelist)
+
+#define VULNWL_AMD(family, whitelist)		\
+	VULNWL(AMD, family, X86_MODEL_ANY, whitelist)
+
+#define VULNWL_HYGON(family, whitelist)		\
+	VULNWL(HYGON, family, X86_MODEL_ANY, whitelist)
+
+static const __initconst struct x86_cpu_id cpu_vuln_whitelist[] = {
+	VULNWL(ANY,	4, X86_MODEL_ANY,	NO_SPECULATION),
+	VULNWL(CENTAUR,	5, X86_MODEL_ANY,	NO_SPECULATION),
+	VULNWL(INTEL,	5, X86_MODEL_ANY,	NO_SPECULATION),
+	VULNWL(NSC,	5, X86_MODEL_ANY,	NO_SPECULATION),
+
+	VULNWL_INTEL(ATOM_SALTWELL,		NO_SPECULATION),
+	VULNWL_INTEL(ATOM_SALTWELL_TABLET,	NO_SPECULATION),
+	VULNWL_INTEL(ATOM_SALTWELL_MID,		NO_SPECULATION),
+	VULNWL_INTEL(ATOM_BONNELL,		NO_SPECULATION),
+	VULNWL_INTEL(ATOM_BONNELL_MID,		NO_SPECULATION),
+
+	VULNWL_INTEL(ATOM_SILVERMONT,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(ATOM_SILVERMONT_X,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(ATOM_SILVERMONT_MID,	NO_SSB | NO_L1TF),
+	VULNWL_INTEL(ATOM_AIRMONT,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF),
+
+	VULNWL_INTEL(CORE_YONAH,		NO_SSB),
+
+	VULNWL_INTEL(ATOM_AIRMONT_MID,		NO_L1TF),
+	VULNWL_INTEL(ATOM_GOLDMONT,		NO_L1TF),
+	VULNWL_INTEL(ATOM_GOLDMONT_X,		NO_L1TF),
+	VULNWL_INTEL(ATOM_GOLDMONT_PLUS,	NO_L1TF),
+
+	VULNWL_AMD(0x0f,		NO_MELTDOWN | NO_SSB | NO_L1TF),
+	VULNWL_AMD(0x10,		NO_MELTDOWN | NO_SSB | NO_L1TF),
+	VULNWL_AMD(0x11,		NO_MELTDOWN | NO_SSB | NO_L1TF),
+	VULNWL_AMD(0x12,		NO_MELTDOWN | NO_SSB | NO_L1TF),
+
+	/* FAMILY_ANY must be last, otherwise 0x0f - 0x12 matches won't work */
+	VULNWL_AMD(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF),
+	VULNWL_HYGON(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF),
 	{}
 };
 
-static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
-	{ X86_VENDOR_AMD },
-	{ X86_VENDOR_HYGON },
-	{}
-};
-
-/* Only list CPUs which speculate but are non susceptible to SSB */
-static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_AIRMONT		},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT_X	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT_MID	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_CORE_YONAH		},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_XEON_PHI_KNL		},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_XEON_PHI_KNM		},
-	{ X86_VENDOR_AMD,	0x12,					},
-	{ X86_VENDOR_AMD,	0x11,					},
-	{ X86_VENDOR_AMD,	0x10,					},
-	{ X86_VENDOR_AMD,	0xf,					},
-	{}
-};
+static bool __init cpu_matches(unsigned long which)
+{
+	const struct x86_cpu_id *m = x86_match_cpu(cpu_vuln_whitelist);
 
-static const __initconst struct x86_cpu_id cpu_no_l1tf[] = {
-	/* in addition to cpu_no_speculation */
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT_X	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_AIRMONT		},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_SILVERMONT_MID	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_AIRMONT_MID	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_GOLDMONT	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_GOLDMONT_X	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_ATOM_GOLDMONT_PLUS	},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_XEON_PHI_KNL		},
-	{ X86_VENDOR_INTEL,	6,	INTEL_FAM6_XEON_PHI_KNM		},
-	{}
-};
+	return m && !!(m->driver_data & which);
+}
 
 static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
 {
 	u64 ia32_cap = 0;
 
-	if (x86_match_cpu(cpu_no_speculation))
+	if (cpu_matches(NO_SPECULATION))
 		return;
 
 	setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
@@ -1011,15 +1022,14 @@ static void __init cpu_set_bug_bits(stru
 	if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
 		rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
 
-	if (!x86_match_cpu(cpu_no_spec_store_bypass) &&
-	   !(ia32_cap & ARCH_CAP_SSB_NO) &&
+	if (!cpu_matches(NO_SSB) && !(ia32_cap & ARCH_CAP_SSB_NO) &&
 	   !cpu_has(c, X86_FEATURE_AMD_SSB_NO))
 		setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS);
 
 	if (ia32_cap & ARCH_CAP_IBRS_ALL)
 		setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);
 
-	if (x86_match_cpu(cpu_no_meltdown))
+	if (cpu_matches(NO_MELTDOWN))
 		return;
 
 	/* Rogue Data Cache Load? No! */
@@ -1028,7 +1038,7 @@ static void __init cpu_set_bug_bits(stru
 
 	setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
 
-	if (x86_match_cpu(cpu_no_l1tf))
+	if (cpu_matches(NO_L1TF))
 		return;
 
 	setup_force_cpu_bug(X86_BUG_L1TF);
Reviewed-by on v6 2/14
#4 lore raw

[MODERATED] Re: [patch V6 02/14] MDS basics 2

Quoted 10 lines · speck for Thomas Gleixner

static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) {

arch/x86/kernel/cpu/common.c +1 -1
 	u64 ia32_cap = 0;
 
-	if (x86_match_cpu(cpu_no_speculation))
+	if (cpu_matches(NO_SPECULATION))
 		return;
 
 	setup_force_cpu_bug(X86_BUG_SPECTRE_V1);

arch/x86/kernel/cpu/common.c static void __init cpu_set_bug_bits(stru · line 1025

Quoted 6 lines
arch/x86/kernel/cpu/common.c +1 -2
@@ -1011,15 +1022,14 @@ static void __init cpu_set_bug_bits(stru
 	if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
 		rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
 
-	if (!x86_match_cpu(cpu_no_spec_store_bypass) &&
-	   !(ia32_cap & ARCH_CAP_SSB_NO) &&
+	if (!cpu_matches(NO_SSB) && !(ia32_cap & ARCH_CAP_SSB_NO) &&

Much clearer and well unified.

maintainer Reviewed-by on v6 2/14
#5 lore raw

[MODERATED] Re: [patch V6 02/14] MDS basics 2

In reply to Thomas Gleixner
Quoted 11 lines · speck for Thomas Gleixner

Subject: [patch V6 02/14] x86/speculation: Consolidate CPU whitelists
From: Thomas Gleixner <[email protected]>

The CPU vulnerability whitelists have some overlap and there are more whitelists coming along.

Use the driver_data field in the x86_cpu_id struct to denote the whitelisted vulnerabilities and combine all whitelists into one.

Reviewed-by on v6 2/14
#6 lore raw

[MODERATED] Re: [patch V6 02/14] MDS basics 2

In reply to Thomas Gleixner
Quoted 11 lines · speck for Thomas Gleixner

Subject: [patch V6 02/14] x86/speculation: Consolidate CPU whitelists
From: Thomas Gleixner <[email protected]>

The CPU vulnerability whitelists have some overlap and there are more whitelists coming along.

Use the driver_data field in the x86_cpu_id struct to denote the whitelisted vulnerabilities and combine all whitelists into one.

Quoted 7 lines

---

V5 --> V6: Use a helper macro to make it more readable

           Fix the AMD family 0xf-0x12 vs. ANY ordering
---
 arch/x86/kernel/cpu/common.c |  110 +++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 50 deletions(-)

Yap, nice and clean.

Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#7 lore raw

PATCH v6 3/14 MDS basics 3

In reply to Thomas Gleixner

Subject: [patch V6 03/14] x86/speculation/mds: Add basic bug infrastructure for MDS
From: Andi Kleen <[email protected]>

Microarchitectural Data Sampling (MDS), is a class of side channel attacks on internal buffers in Intel CPUs. The variants are:

- Microarchitectural Store Buffer Data Sampling (MSBDS) (CVE-2018-12126)
- Microarchitectural Fill Buffer Data Sampling (MFBDS) (CVE-2018-12130)
- Microarchitectural Load Port Data Sampling (MLPDS) (CVE-2018-12127)

MSBDS leaks Store Buffer Entries which can be speculatively forwarded to a dependent load (store-to-load forwarding) as an optimization. The forward can also happen to a faulting or assisting load operation for a different memory address, which can be exploited under certain conditions. Store buffers are partitioned between Hyper-Threads so cross thread forwarding is not possible. But if a thread enters or exits a sleep state the store buffer is repartitioned which can expose data from one thread to the other.

MFBDS leaks Fill Buffer Entries. Fill buffers are used internally to manage L1 miss situations and to hold data which is returned or sent in response to a memory or I/O operation. Fill buffers can forward data to a load operation and also write data to the cache. When the fill buffer is deallocated it can retain the stale data of the preceding operations which can then be forwarded to a faulting or assisting load operation, which can be exploited under certain conditions. Fill buffers are shared between Hyper-Threads so cross thread leakage is possible.

MLDPS leaks Load Port Data. Load ports are used to perform load operations from memory or I/O. The received data is then forwarded to the register file or a subsequent operation. In some implementations the Load Port can contain stale data from a previous operation which can be forwarded to faulting or assisting loads under certain conditions, which again can be exploited eventually. Load ports are shared between Hyper-Threads so cross thread leakage is possible.

All variants have the same mitigation for single CPU thread case (SMT off), so the kernel can treat them as one MDS issue.

Add the basic infrastructure to detect if the current CPU is affected by MDS.

[ tglx: Rewrote changelog ]

---
V5: Adopt to the consolidated quirk table
V3: Addressed Borislav's review comments

---
 arch/x86/include/asm/cpufeatures.h |    2 ++
 arch/x86/include/asm/msr-index.h   |    5 +++++
 arch/x86/kernel/cpu/common.c       |   27 +++++++++++++++++----------
 3 files changed, 24 insertions(+), 10 deletions(-)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -344,6 +344,7 @@
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
 #define X86_FEATURE_AVX512_4VNNIW	(18*32+ 2) /* AVX-512 Neural Network Instructions */
 #define X86_FEATURE_AVX512_4FMAPS	(18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
+#define X86_FEATURE_MD_CLEAR		(18*32+10) /* VERW clears CPU buffers */
 #define X86_FEATURE_PCONFIG		(18*32+18) /* Intel PCONFIG */
 #define X86_FEATURE_SPEC_CTRL		(18*32+26) /* "" Speculation Control (IBRS + IBPB) */
 #define X86_FEATURE_INTEL_STIBP		(18*32+27) /* "" Single Thread Indirect Branch Predictors */
@@ -381,5 +382,6 @@
 #define X86_BUG_SPECTRE_V2		X86_BUG(16) /* CPU is affected by Spectre variant 2 attack with indirect branches */
 #define X86_BUG_SPEC_STORE_BYPASS	X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 #define X86_BUG_L1TF			X86_BUG(18) /* CPU is affected by L1 Terminal Fault */
+#define X86_BUG_MDS			X86_BUG(19) /* CPU is affected by Microarchitectural data sampling */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/include/asm/msr-index.h +5 -0
@@ -79,6 +79,11 @@
 						 * attack, so no Speculative Store Bypass
 						 * control required.
 						 */
+#define ARCH_CAP_MDS_NO			BIT(5)   /*
+						  * Not susceptible to
+						  * Microarchitectural Data
+						  * Sampling (MDS) vulnerabilities.
+						  */
 
 #define MSR_IA32_FLUSH_CMD		0x0000010b
 #define L1D_FLUSH			BIT(0)	/*
arch/x86/kernel/cpu/common.c +17 -10
@@ -952,6 +952,7 @@ static void identify_cpu_without_cpuid(s
 #define NO_MELTDOWN	BIT(1)
 #define NO_SSB		BIT(2)
 #define NO_L1TF		BIT(3)
+#define NO_MDS		BIT(4)
 
 #define VULNWL(_vendor, _family, _model, _whitelist)	\
 	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
@@ -971,6 +972,7 @@ static const __initconst struct x86_cpu_
 	VULNWL(INTEL,	5, X86_MODEL_ANY,	NO_SPECULATION),
 	VULNWL(NSC,	5, X86_MODEL_ANY,	NO_SPECULATION),
 
+	/* Intel Family 6 */
 	VULNWL_INTEL(ATOM_SALTWELL,		NO_SPECULATION),
 	VULNWL_INTEL(ATOM_SALTWELL_TABLET,	NO_SPECULATION),
 	VULNWL_INTEL(ATOM_SALTWELL_MID,		NO_SPECULATION),
@@ -987,18 +989,20 @@ static const __initconst struct x86_cpu_
 	VULNWL_INTEL(CORE_YONAH,		NO_SSB),
 
 	VULNWL_INTEL(ATOM_AIRMONT_MID,		NO_L1TF),
-	VULNWL_INTEL(ATOM_GOLDMONT,		NO_L1TF),
-	VULNWL_INTEL(ATOM_GOLDMONT_X,		NO_L1TF),
-	VULNWL_INTEL(ATOM_GOLDMONT_PLUS,	NO_L1TF),
-
-	VULNWL_AMD(0x0f,		NO_MELTDOWN | NO_SSB | NO_L1TF),
-	VULNWL_AMD(0x10,		NO_MELTDOWN | NO_SSB | NO_L1TF),
-	VULNWL_AMD(0x11,		NO_MELTDOWN | NO_SSB | NO_L1TF),
-	VULNWL_AMD(0x12,		NO_MELTDOWN | NO_SSB | NO_L1TF),
+
+	VULNWL_INTEL(ATOM_GOLDMONT,		NO_MDS | NO_L1TF),
+	VULNWL_INTEL(ATOM_GOLDMONT_X,		NO_MDS | NO_L1TF),
+	VULNWL_INTEL(ATOM_GOLDMONT_PLUS,	NO_MDS | NO_L1TF),
+
+	/* AMD Family 0xf - 0x12 */
+	VULNWL_AMD(0x0f,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x10,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x11,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x12,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
 
 	/* FAMILY_ANY must be last, otherwise 0x0f - 0x12 matches won't work */
-	VULNWL_AMD(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF),
-	VULNWL_HYGON(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF),
+	VULNWL_AMD(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF | NO_MDS),
+	VULNWL_HYGON(X86_FAMILY_ANY,	NO_MELTDOWN | NO_L1TF | NO_MDS),
 	{}
 };
 
@@ -1029,6 +1033,9 @@ static void __init cpu_set_bug_bits(stru
 	if (ia32_cap & ARCH_CAP_IBRS_ALL)
 		setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);
 
+	if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO))
+		setup_force_cpu_bug(X86_BUG_MDS);
+
 	if (cpu_matches(NO_MELTDOWN))
 		return;
 
Reviewed-by on v6 3/14
#8 lore raw

[MODERATED] Re: [patch V6 03/14] MDS basics 3

arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_ · line 1001

Quoted 6 lines · speck for Thomas Gleixner

Subject: [patch V6 03/14] x86/speculation/mds: Add basic bug infrastructure for MDS

arch/x86/kernel/cpu/common.c +5 -0
+	/* AMD Family 0xf - 0x12 */
+	VULNWL_AMD(0x0f,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x10,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x11,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),
+	VULNWL_AMD(0x12,	NO_MELTDOWN | NO_SSB | NO_L1TF | NO_MDS),

Lucky guys :-)

#9 lore raw

PATCH v6 4/14 MDS basics 4

In reply to Thomas Gleixner

Subject: [patch V6 04/14] x86/speculation/mds: Add BUG_MSBDS_ONLY
From: Thomas Gleixner <[email protected]>

This bug bit is set on CPUs which are only affected by Microarchitectural Store Buffer Data Sampling (MSBDS) and not by any other MDS variant.

This is important because the Store Buffers are partitioned between Hyper-Threads so cross thread forwarding is not possible. But if a thread enters or exits a sleep state the store buffer is repartitioned which can expose data from one thread to the other. This transition can be mitigated.

That means that for CPUs which are only affected by MSBDS SMT can be enabled, if the CPU is not affected by other SMT sensitive vulnerabilities, e.g. L1TF. The XEON PHI variants fall into that category.

---
 arch/x86/include/asm/cpufeatures.h |    1 +
 arch/x86/kernel/cpu/common.c       |   10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -383,5 +383,6 @@
 #define X86_BUG_SPEC_STORE_BYPASS	X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 #define X86_BUG_L1TF			X86_BUG(18) /* CPU is affected by L1 Terminal Fault */
 #define X86_BUG_MDS			X86_BUG(19) /* CPU is affected by Microarchitectural data sampling */
+#define X86_BUG_MSBDS_ONLY		X86_BUG(20) /* CPU is only affected by the  MSDBS variant of BUG_MDS */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/common.c +7 -3
@@ -953,6 +953,7 @@ static void identify_cpu_without_cpuid(s
 #define NO_SSB		BIT(2)
 #define NO_L1TF		BIT(3)
 #define NO_MDS		BIT(4)
+#define MSBDS_ONLY	BIT(5)
 
 #define VULNWL(_vendor, _family, _model, _whitelist)	\
 	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
@@ -983,8 +984,8 @@ static const __initconst struct x86_cpu_
 	VULNWL_INTEL(ATOM_SILVERMONT_X,		NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_SILVERMONT_MID,	NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_AIRMONT,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF | MSBDS_ONLY),
+	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF | MSBDS_ONLY),
 
 	VULNWL_INTEL(CORE_YONAH,		NO_SSB),
 
@@ -1033,8 +1034,11 @@ static void __init cpu_set_bug_bits(stru
 	if (ia32_cap & ARCH_CAP_IBRS_ALL)
 		setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);
 
-	if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO))
+	if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO)) {
 		setup_force_cpu_bug(X86_BUG_MDS);
+		if (cpu_matches(MSBDS_ONLY))
+			setup_force_cpu_bug(X86_BUG_MSBDS_ONLY);
+	}
 
 	if (cpu_matches(NO_MELTDOWN))
 		return;
Reviewed-by on v6 4/14
#10 lore raw

[MODERATED] Re: [patch V6 04/14] MDS basics 4

Quoted 55 lines · speck for Thomas Gleixner

Subject: [patch V6 04/14] x86/speculation/mds: Add BUG_MSBDS_ONLY
From: Thomas Gleixner <[email protected]>

This bug bit is set on CPUs which are only affected by Microarchitectural Store Buffer Data Sampling (MSBDS) and not by any other MDS variant.

This is important because the Store Buffers are partitioned between Hyper-Threads so cross thread forwarding is not possible. But if a thread enters or exits a sleep state the store buffer is repartitioned which can expose data from one thread to the other. This transition can be mitigated.

That means that for CPUs which are only affected by MSBDS SMT can be enabled, if the CPU is not affected by other SMT sensitive vulnerabilities, e.g. L1TF. The XEON PHI variants fall into that category.

---
 arch/x86/include/asm/cpufeatures.h |    1 +
 arch/x86/kernel/cpu/common.c       |   10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -383,5 +383,6 @@
 #define X86_BUG_SPEC_STORE_BYPASS	X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 #define X86_BUG_L1TF			X86_BUG(18) /* CPU is affected by L1 Terminal Fault */
 #define X86_BUG_MDS			X86_BUG(19) /* CPU is affected by Microarchitectural data sampling */
+#define X86_BUG_MSBDS_ONLY		X86_BUG(20) /* CPU is only affected by the  MSDBS variant of BUG_MDS */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/common.c +3 -2
@@ -953,6 +953,7 @@ static void identify_cpu_without_cpuid(s
 #define NO_SSB		BIT(2)
 #define NO_L1TF		BIT(3)
 #define NO_MDS		BIT(4)
+#define MSBDS_ONLY	BIT(5)
 
 #define VULNWL(_vendor, _family, _model, _whitelist)	\
 	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
@@ -983,8 +984,8 @@ static const __initconst struct x86_cpu_
 	VULNWL_INTEL(ATOM_SILVERMONT_X,		NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_SILVERMONT_MID,	NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_AIRMONT,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF | MSBDS_ONLY),
+	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF | MSBDS_ONLY),
 
 	VULNWL_INTEL(CORE_YONAH,		NO_SSB),
 
@@ -1033,8 +1034,11 @@ static void __init cpu_set_bug_bits(stru
 	if (ia32_cap & ARCH_CAP_IBRS_ALL)
 		setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED);

arch/x86/kernel/cpu/common.c static void __init cpu_set_bug_bits(stru · line 1044

Quoted 10 lines
arch/x86/kernel/cpu/common.c +4 -1
 
-	if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO))
+	if (!cpu_matches(NO_MDS) && !(ia32_cap & ARCH_CAP_MDS_NO)) {
 		setup_force_cpu_bug(X86_BUG_MDS);
+		if (cpu_matches(MSBDS_ONLY))
+			setup_force_cpu_bug(X86_BUG_MSBDS_ONLY);
+	}
 
 	if (cpu_matches(NO_MELTDOWN))
 		return;

It looks weird to have it as a separate bug flag and not as a subset of full MDS such as:

    #define NO_IDLE_SHARED_MDS BIT(4)
    #define NO_SHARED_MDS      BIT(5)
    #define NO_MDS             (NO_IDLE_SHARED_MDS | NO_SHARED_MDS)

Now that would probably make sense only if the mitigation of full MDS required to also imply a VERW before entering idle (that's the mitigation of MSBDS_ONLY, right?). Turning off SMT removes the need to do that so the layout seem to make sense as is.

#11 lore raw

Re: [patch V6 04/14] MDS basics 4

Quoted 8 lines · speck for Frederic Weisbecker

arch/x86/kernel/cpu/common.c static void __init cpu_set_bug_bits(stru · line 1044

Quoted 3 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/common.c +0 -0
 	if (cpu_matches(NO_MELTDOWN))
 		return;

It looks weird to have it as a separate bug flag and not as a subset of full MDS such as:

Quoted 7 lines
    #define NO_IDLE_SHARED_MDS BIT(4)
    #define NO_SHARED_MDS      BIT(5)
    #define NO_MDS             (NO_IDLE_SHARED_MDS | NO_SHARED_MDS)

Now that would probably make sense only if the mitigation of full MDS required to also imply a VERW before entering idle (that's the mitigation of MSBDS_ONLY, right?). Turning off SMT removes the need to do that so the layout seem to make sense as is.

Yeah, I had several variants of the theme, but all of them sucked in one way or the other.

Thanks,

tglx

#12 lore raw

[MODERATED] Re: [patch V6 04/14] MDS basics 4

In reply to Thomas Gleixner
Quoted 41 lines · speck for Thomas Gleixner

Subject: [patch V6 04/14] x86/speculation/mds: Add BUG_MSBDS_ONLY
From: Thomas Gleixner <[email protected]>

This bug bit is set on CPUs which are only affected by Microarchitectural Store Buffer Data Sampling (MSBDS) and not by any other MDS variant.

This is important because the Store Buffers are partitioned between Hyper-Threads so cross thread forwarding is not possible. But if a thread enters or exits a sleep state the store buffer is repartitioned which can expose data from one thread to the other. This transition can be mitigated.

That means that for CPUs which are only affected by MSBDS SMT can be enabled, if the CPU is not affected by other SMT sensitive vulnerabilities, e.g. L1TF. The XEON PHI variants fall into that category.

---
 arch/x86/include/asm/cpufeatures.h |    1 +
 arch/x86/kernel/cpu/common.c       |   10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -383,5 +383,6 @@
 #define X86_BUG_SPEC_STORE_BYPASS	X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 #define X86_BUG_L1TF			X86_BUG(18) /* CPU is affected by L1 Terminal Fault */
 #define X86_BUG_MDS			X86_BUG(19) /* CPU is affected by Microarchitectural data sampling */
+#define X86_BUG_MSBDS_ONLY		X86_BUG(20) /* CPU is only affected by the  MSDBS variant of BUG_MDS */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/common.c +1 -0
@@ -953,6 +953,7 @@ static void identify_cpu_without_cpuid(s
 #define NO_SSB		BIT(2)
 #define NO_L1TF		BIT(3)
 #define NO_MDS		BIT(4)
+#define MSBDS_ONLY	BIT(5)
 
 #define VULNWL(_vendor, _family, _model, _whitelist)	\
 	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }

arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_ · line 988

Quoted 7 lines
arch/x86/kernel/cpu/common.c +2 -2
@@ -983,8 +984,8 @@ static const __initconst struct x86_cpu_
 	VULNWL_INTEL(ATOM_SILVERMONT_X,		NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_SILVERMONT_MID,	NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_AIRMONT,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF | MSBDS_ONLY),
+	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF | MSBDS_ONLY),

Looking at the table in the magic PDF, Silvermont/Airmont are MDBDS_ONLY as well.

The model numbers listed in the Silvermont/Airmont category are 37, 4a, 4c, 4d, 5a, 5d, 6e, 65, 75.

The first 5 of those models match up with Linux's Silvermont/Airmont names, while the last 4 are unknown.  I can't locate them anywhere and have requested clarification.

~Andrew

#13 lore raw

Re: [patch V6 04/14] MDS basics 4

Quoted 15 lines · speck for Andrew Cooper

arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_ · line 988

Quoted 10 lines · speck for Thomas Gleixner

#define VULNWL(_vendor, _family, _model, _whitelist) \

arch/x86/kernel/cpu/common.c +2 -2
 	{ X86_VENDOR_##_vendor, _family, _model, X86_FEATURE_ANY, _whitelist }
@@ -983,8 +984,8 @@ static const __initconst struct x86_cpu_
 	VULNWL_INTEL(ATOM_SILVERMONT_X,		NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_SILVERMONT_MID,	NO_SSB | NO_L1TF),
 	VULNWL_INTEL(ATOM_AIRMONT,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF),
-	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF),
+	VULNWL_INTEL(XEON_PHI_KNL,		NO_SSB | NO_L1TF | MSBDS_ONLY),
+	VULNWL_INTEL(XEON_PHI_KNM,		NO_SSB | NO_L1TF | MSBDS_ONLY),

Looking at the table in the magic PDF, Silvermont/Airmont are MDBDS_ONLY as well.

Quoted 6 lines

The model numbers listed in the Silvermont/Airmont category are 37, 4a, 4c, 4d, 5a, 5d, 6e, 65, 75.

The first 5 of those models match up with Linux's Silvermont/Airmont names, while the last 4 are unknown.  I can't locate them anywhere and have requested clarification.

Yeah, forgot about the Silvermonts. Though the SMT problem does not exist there as these beasts do not have HT AFAICT.

Thanks,

tglx

#14 lore raw

[MODERATED] Re: [patch V6 04/14] MDS basics 4

In reply to Thomas Gleixner
Quoted 5 lines · speck for Thomas Gleixner

Subject: [patch V6 04/14] x86/speculation/mds: Add BUG_MSBDS_ONLY
From: Thomas Gleixner <[email protected]>

This bug bit is set on CPUs which are only affected by Microarchitectural Store Buffer Data Sampling (MSBDS) and not by any other MDS variant.

This patch is pointless. It won't have VERW support and we don't have mitigation for Xeon Phi because Linus rejected software sequences.

Xeon Phi will simply not be mitigated. However Xeon PHIs are not widely used, and those that are deployed can be handled in different ways.

-Andi

#15 lore raw

[MODERATED] Re: [patch V6 04/14] MDS basics 4

Quoted 3 lines · speck for Andi Kleen

Xeon Phi will simply not be mitigated. However Xeon PHIs are not widely used,

Heh. Understatement of the year.

Quoted 1 line

and those that are deployed can be handled in different ways.

I don't think anybody uses them in situations that would care.

The main target was HPC, I think.

So I think the "handled in different ways" ends up being "ignored", I suspect.

Linus

#16 lore raw

PATCH v6 5/14 MDS basics 5

In reply to Thomas Gleixner

From: Andi Kleen <[email protected]>
Subject: [patch V6 05/14] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests

X86_FEATURE_MD_CLEAR is a new CPUID bit which is set when microcode provides the mechanism to invoke a flush of various exploitable CPU buffers by invoking the VERW instruction.

Hand it through to guests so they can adjust their mitigations.

This also requires corresponding qemu changes, which are available separately.

[ tglx: Massaged changelog ]

---
 arch/x86/kvm/cpuid.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +2 -1
@@ -410,7 +410,8 @@ static inline int __do_cpuid_ent(struct
 	/* cpuid 7.0.edx*/
 	const u32 kvm_cpuid_7_0_edx_x86_features =
 		F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
-		F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES) | F(INTEL_STIBP);
+		F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES) | F(INTEL_STIBP) |
+		F(MD_CLEAR);
 
 	/* all calls to cpuid_count() should be made on the same cpu */
 	get_cpu();
Reviewed-by on v6 5/14
#17 lore raw

[MODERATED] Re: [patch V6 05/14] MDS basics 5

Quoted 12 lines · speck for Thomas Gleixner

From: Andi Kleen <[email protected]>
Subject: [patch V6 05/14] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests

X86_FEATURE_MD_CLEAR is a new CPUID bit which is set when microcode provides the mechanism to invoke a flush of various exploitable CPU buffers by invoking the VERW instruction.

Hand it through to guests so they can adjust their mitigations.

This also requires corresponding qemu changes, which are available separately.

Quoted 6 lines

[ tglx: Massaged changelog ]

#18 lore raw

[MODERATED] Re: [patch V6 05/14] MDS basics 5

In reply to Thomas Gleixner
Quoted 11 lines · speck for Thomas Gleixner

From: Andi Kleen <[email protected]>
Subject: [patch V6 05/14] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests

X86_FEATURE_MD_CLEAR is a new CPUID bit which is set when microcode provides the mechanism to invoke a flush of various exploitable CPU buffers by invoking the VERW instruction.

Hand it through to guests so they can adjust their mitigations.

This also requires corresponding qemu changes, which are available separately.

This patch is not complete. You also need some variant of

x86/speculation/mds: Handle VMENTRY clear for CPUs without l1tf

in my patch kit.

-Andi

#19 lore raw

Re: [patch V6 05/14] MDS basics 5

Quoted 8 lines · speck for Andi Kleen
Quoted 7 lines · speck for Thomas Gleixner

From: Andi Kleen <[email protected]>
Subject: [patch V6 05/14] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests

X86_FEATURE_MD_CLEAR is a new CPUID bit which is set when microcode provides the mechanism to invoke a flush of various exploitable CPU buffers by invoking the VERW instruction.

Quoted 8 lines
Quoted 4 lines

Hand it through to guests so they can adjust their mitigations.

This also requires corresponding qemu changes, which are available separately.

This patch is not complete. You also need some variant of

x86/speculation/mds: Handle VMENTRY clear for CPUs without l1tf

650b68a0622f ("x86/kvm/vmx: Add MDS protection when L1D Flush is not active")

Thanks,

tglx

#20 lore raw

PATCH v6 6/14 MDS basics 6

In reply to Thomas Gleixner

Subject: [patch V6 06/14] x86/speculation/mds: Add mds_clear_cpu_buffers()
From: Thomas Gleixner <[email protected]>

The Microarchitectural Data Sampling (MDS) vulernabilities are mitigated by clearing the affected CPU buffers. The mechanism for clearing the buffers uses the unused and obsolete VERW instruction in combination with a microcode update which triggers a CPU buffer clear when VERW is executed.

Provide a inline function with the assembly magic. The argument of the VERW instruction must be a memory operand as documented:

"MD_CLEAR enumerates that the memory-operand variant of VERW (for
example, VERW m16) has been extended to also overwrite buffers affected by MDS. This buffer overwriting functionality is not guaranteed for the register operand variant of VERW."

Documentation also recommends to use a writable data segment selector:

"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."

Add x86 specific documentation about MDS and the internal workings of the mitigation.

---
v4 --> V5: Fix typos and remove the conditional mode reference.

V3 --> V4: Document the segment selecor choice as well.

V2 --> V3: Add VERW documentation and fix typos/grammar..., dropped 'i(0)'
Add more details fo the documentation file

V1 --> V2: Add "cc" clobber and documentation

---
 Documentation/index.rst              |    1 
 Documentation/x86/conf.py            |   10 +++
 Documentation/x86/index.rst          |    8 ++
 Documentation/x86/mds.rst            |   99 +++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/nospec-branch.h |   25 ++++++++
 5 files changed, 143 insertions(+)
Documentation/index.rst +1 -0
@@ -101,6 +101,7 @@ implementation.
    :maxdepth: 2
 
    sh/index
+   x86/index
 
 Filesystem Documentation
 ------------------------
Documentation/x86/conf.py new file +10 -0
@@ -0,0 +1,10 @@
+# -*- coding: utf-8; mode: python -*-
+
+project = "X86 architecture specific documentation"
+
+tags.add("subproject")
+
+latex_documents = [
+    ('index', 'x86.tex', project,
+     'The kernel development community', 'manual'),
+]
Documentation/x86/index.rst new file +8 -0
@@ -0,0 +1,8 @@
+==========================
+x86 architecture specifics
+==========================
+
+.. toctree::
+   :maxdepth: 1
+
+   mds
Documentation/x86/mds.rst new file +99 -0

99 lines not on this page · raw message

arch/x86/include/asm/nospec-branch.h +25 -0
@@ -318,6 +318,31 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_
 DECLARE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
 DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
+#include <asm/segment.h>
+
+/**
+ * mds_clear_cpu_buffers - Mitigation for MDS vulnerability
+ *
+ * This uses the otherwise unused and obsolete VERW instruction in
+ * combination with microcode which triggers a CPU buffer flush when the
+ * instruction is executed.
+ */
+static inline void mds_clear_cpu_buffers(void)
+{
+	static const u16 ds = __KERNEL_DS;
+
+	/*
+	 * Has to be the memory-operand variant because only that
+	 * guarantees the CPU buffer flush functionality according to
+	 * documentation. The register-operand variant does not.
+	 * Works with any segment selector, but a valid writable
+	 * data segment is the fastest variant.
+	 *
+	 * "cc" clobber is required because VERW modifies ZF.
+	 */
+	asm volatile("verw %[ds]" : : [ds] "m" (ds) : "cc");
+}
+
 #endif /* __ASSEMBLY__ */
 
 /*
#21 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: [patch V6 06/14] MDS basics 6

Quoted 8 lines · speck for Thomas Gleixner

Provide a inline function with the assembly magic. The argument of the VERW instruction must be a memory operand as documented:

"MD_CLEAR enumerates that the memory-operand variant of VERW (for
example, VERW m16) has been extended to also overwrite buffers affected by MDS. This buffer overwriting functionality is not guaranteed for the register operand variant of VERW."

Quoted 7 lines

Documentation also recommends to use a writable data segment selector:

"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."

Note that we raised this again with Intel last week amid Andrew's results and they are going to get back to us if this guidance changes as a result of further measurements on their end. It's a few cycles difference in the Coffeelake case, but it could always be higher.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#22 lore raw

Re: Encrypted Message

Quoted 8 lines · speck for Jon Masters
Quoted 7 lines

Documentation also recommends to use a writable data segment selector:

"The buffer overwriting occurs regardless of the result of the VERW
permission check, as well as when the selector is null or causes a descriptor load segment violation. However, for lowest latency we recommend using a selector that indicates a valid writable data segment."

Quoted 4 lines

Note that we raised this again with Intel last week amid Andrew's results and they are going to get back to us if this guidance changes as a result of further measurements on their end. It's a few cycles difference in the Coffeelake case, but it could always be higher.

Ok. We can fix that up on top once we have final answers.

Thanks,

tglx

#23 lore raw

PATCH v6 7/14 MDS basics 7

In reply to Thomas Gleixner

Subject: [patch V6 07/14] x86/speculation/mds: Clear CPU buffers on exit to user
From: Thomas Gleixner <[email protected]>

Add a static key which controls the invocation of the CPU buffer clear mechanism on exit to user space and add the call into prepare_exit_to_usermode() and do_nmi() right before actually returning.

Add documentation which kernel to user space transition this covers and explain why some corner cases are not mitigated.

---
V4 --> v5: Use an inline helper instead of open coding it.
Rework the documentation paragraph about exceptions.

V3 --> V4: Add #DS mitigation and document that the #MC corner case
is really not interesting.

V3: Add NMI conditional on user regs and update documentation accordingly.
Use the static branch scheme suggested by Peter. Fix typos ...

---
 Documentation/x86/mds.rst            |   52 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/common.c              |    3 ++
 arch/x86/include/asm/nospec-branch.h |   13 ++++++++
 arch/x86/kernel/cpu/bugs.c           |    3 ++
 arch/x86/kernel/nmi.c                |    4 ++
 arch/x86/kernel/traps.c              |    7 ++++
 6 files changed, 82 insertions(+)
Documentation/x86/mds.rst +52 -0
@@ -97,3 +97,55 @@ According to current knowledge additiona
 itself are not required because the necessary gadgets to expose the leaked
 data cannot be controlled in a way which allows exploitation from malicious
 user space or VM guests.
+
+Mitigation points
+-----------------
+
+1. Return to user space
+^^^^^^^^^^^^^^^^^^^^^^^
+
+   When transitioning from kernel to user space the CPU buffers are flushed
+   on affected CPUs when the mitigation is not disabled on the kernel
+   command line. The migitation is enabled through the static key
+   mds_user_clear.
+
+   The mitigation is invoked in prepare_exit_to_usermode() which covers
+   most of the kernel to user space transitions. There are a few exceptions
+   which are not invoking prepare_exit_to_usermode() on return to user
+   space. These exceptions use the paranoid exit code.
+
+   - Non Maskable Interrupt (NMI):
+
+     Access to sensible data like keys, credentials in the NMI context is
+     mostly theoretical: The CPU can do prefetching or execute a
+     misspeculated code path and thereby fetching data which might end up
+     leaking through a buffer.
+
+     But for mounting other attacks the kernel stack address of the task is
+     already valuable information. So in full mitigation mode, the NMI is
+     mitigated on the return from do_nmi() to provide almost complete
+     coverage.
+
+   - Double fault (#DF):
+
+     A double fault is usually fatal, but the ESPFIX workaround, which can
+     be triggered from user space through modify_ldt(2) is a recoverable
+     double fault. #DF uses the paranoid exit path, so explicit mitigation
+     in the double fault handler is required.
+
+   - Machine Check Exception (#MC):
+
+     Another corner case is a #MC which hits between the CPU buffer clear
+     invocation and the actual return to user. As this still is in kernel
+     space it takes the paranoid exit path which does not clear the CPU
+     buffers. So the #MC handler repopulates the buffers to some
+     extent. Machine checks are not reliably controllable and the window is
+     extremly small so mitigation would just tick a checkbox that this
+     theoretical corner case is covered. To keep the amount of special
+     cases small, ignore #MC.
+
+   - Debug Exception (#DB):
+
+     This takes the paranoid exit path only when the INT1 breakpoint is in
+     kernel space. #DB on a user space address takes the regular exit path,
+     so no extra mitigation required.
arch/x86/entry/common.c +3 -0
@@ -31,6 +31,7 @@
 #include <asm/vdso.h>
 #include <linux/uaccess.h>
 #include <asm/cpufeature.h>
+#include <asm/nospec-branch.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/syscalls.h>
@@ -212,6 +213,8 @@ static void exit_to_usermode_loop(struct
 #endif
 
 	user_enter_irqoff();
+
+	mds_user_clear_cpu_buffers();
 }
 
 #define SYSCALL_EXIT_WORK_FLAGS				\
arch/x86/include/asm/nospec-branch.h +13 -0
@@ -318,6 +318,8 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_
 DECLARE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
 DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
+DECLARE_STATIC_KEY_FALSE(mds_user_clear);
+
 #include <asm/segment.h>
 
 /**
@@ -343,6 +345,17 @@ static inline void mds_clear_cpu_buffers
 	asm volatile("verw %[ds]" : : [ds] "m" (ds) : "cc");
 }
 
+/**
+ * mds_user_clear_cpu_buffers - Mitigation for MDS vulnerability
+ *
+ * Clear CPU buffers if the corresponding static key is enabled
+ */
+static inline void mds_user_clear_cpu_buffers(void)
+{
+	if (static_branch_likely(&mds_user_clear))
+		mds_clear_cpu_buffers();
+}
+
 #endif /* __ASSEMBLY__ */
 
 /*
arch/x86/kernel/cpu/bugs.c +3 -0
@@ -63,6 +63,9 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_i
 /* Control unconditional IBPB in switch_mm() */
 DEFINE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
+/* Control MDS CPU buffer clear before returning to user space */
+DEFINE_STATIC_KEY_FALSE(mds_user_clear);
+
 void __init check_bugs(void)
 {
 	identify_boot_cpu();
arch/x86/kernel/nmi.c +4 -0
@@ -34,6 +34,7 @@
 #include <asm/x86_init.h>
 #include <asm/reboot.h>
 #include <asm/cache.h>
+#include <asm/nospec-branch.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/nmi.h>
@@ -533,6 +534,9 @@ do_nmi(struct pt_regs *regs, long error_
 		write_cr2(this_cpu_read(nmi_cr2));
 	if (this_cpu_dec_return(nmi_state))
 		goto nmi_restart;
+
+	if (user_mode(regs))
+		mds_user_clear_cpu_buffers();
 }
 NOKPROBE_SYMBOL(do_nmi);
 
arch/x86/kernel/traps.c +7 -0
@@ -366,6 +366,13 @@ dotraplinkage void do_double_fault(struc
 		regs->ip = (unsigned long)general_protection;
 		regs->sp = (unsigned long)&gpregs->orig_ax;
 
+		/*
+		 * This situation can be triggered by userspace via
+		 * modify_ldt(2) and the return does not take the regular
+		 * user space exit, so a CPU buffer clear is required when
+		 * MDS mitigation is enabled.
+		 */
+		mds_user_clear_cpu_buffers();
 		return;
 	}
 #endif
#24 lore raw

[MODERATED] Re: [patch V6 07/14] MDS basics 7

Documentation/x86/mds.rst According to current knowledge additiona · line 151

Quoted 6 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst +6 -0
+
+   - Debug Exception (#DB):
+
+     This takes the paranoid exit path only when the INT1 breakpoint is in
+     kernel space. #DB on a user space address takes the regular exit path,
+     so no extra mitigation required.

I can't find that part in this patch, maybe it's further in the series?

Quoted 11 lines
arch/x86/kernel/nmi.c +1 -0
@@ -34,6 +34,7 @@
 #include <asm/x86_init.h>
 #include <asm/reboot.h>
 #include <asm/cache.h>
+#include <asm/nospec-branch.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/nmi.h>

arch/x86/kernel/nmi.c do_nmi(struct pt_regs *regs, long error_ · line 539

Quoted 6 lines
arch/x86/kernel/nmi.c +3 -0
@@ -533,6 +534,9 @@ do_nmi(struct pt_regs *regs, long error_
 		write_cr2(this_cpu_read(nmi_cr2));
 	if (this_cpu_dec_return(nmi_state))
 		goto nmi_restart;
+
+	if (user_mode(regs))
+		mds_user_clear_cpu_buffers();

What if the NMI fires after a call to prepare_exit_to_usermode() but before the actual return to usermode, would that be a problem?

Thanks.

#25 lore raw

Re: [patch V6 07/14] MDS basics 7

Quoted 9 lines · speck for Frederic Weisbecker

Documentation/x86/mds.rst According to current knowledge additiona · line 151

Quoted 6 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst +6 -0
+
+   - Debug Exception (#DB):
+
+     This takes the paranoid exit path only when the INT1 breakpoint is in
+     kernel space. #DB on a user space address takes the regular exit path,
+     so no extra mitigation required.

I can't find that part in this patch, maybe it's further in the series?

There is no patch. #DB is not interesting as explained above.

Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/nmi.c +1 -0
@@ -34,6 +34,7 @@
 #include <asm/x86_init.h>
 #include <asm/reboot.h>
 #include <asm/cache.h>
+#include <asm/nospec-branch.h>
 
Quoted 12 lines

arch/x86/kernel/nmi.c do_nmi(struct pt_regs *regs, long error_ · line 539

Quoted 9 lines
arch/x86/kernel/nmi.c +3 -0
 #define CREATE_TRACE_POINTS
 #include <trace/events/nmi.h>
@@ -533,6 +534,9 @@ do_nmi(struct pt_regs *regs, long error_
 		write_cr2(this_cpu_read(nmi_cr2));
 	if (this_cpu_dec_return(nmi_state))
 		goto nmi_restart;
+
+	if (user_mode(regs))
+		mds_user_clear_cpu_buffers();

What if the NMI fires after a call to prepare_exit_to_usermode() but before the actual return to usermode, would that be a problem?

Yes, it's a hole in the protection, but you would need to be able to orchestrate that as user which I doubt you can. So the thought was that we rather avoid the penalty for perf when it hits kernel space, which requires root ....

Thanks,

tglx

#26 lore raw

[MODERATED] Re: [patch V6 07/14] MDS basics 7

Quoted 12 lines · speck for Thomas Gleixner
Quoted 9 lines · speck for Frederic Weisbecker

Documentation/x86/mds.rst According to current knowledge additiona · line 151

Quoted 6 lines · speck for Thomas Gleixner
Documentation/x86/mds.rst +6 -0
+
+   - Debug Exception (#DB):
+
+     This takes the paranoid exit path only when the INT1 breakpoint is in
+     kernel space. #DB on a user space address takes the regular exit path,
+     so no extra mitigation required.

I can't find that part in this patch, maybe it's further in the series?

Quoted 1 line

There is no patch. #DB is not interesting as explained above.

Oh right, my brainfart...

Quoted 22 lines
Quoted 9 lines
Quoted 9 lines
arch/x86/kernel/nmi.c +1 -0
@@ -34,6 +34,7 @@
 #include <asm/x86_init.h>
 #include <asm/reboot.h>
 #include <asm/cache.h>
+#include <asm/nospec-branch.h>
 
Quoted 12 lines

arch/x86/kernel/nmi.c do_nmi(struct pt_regs *regs, long error_ · line 539

Quoted 9 lines
arch/x86/kernel/nmi.c +3 -0
 #define CREATE_TRACE_POINTS
 #include <trace/events/nmi.h>
@@ -533,6 +534,9 @@ do_nmi(struct pt_regs *regs, long error_
 		write_cr2(this_cpu_read(nmi_cr2));
 	if (this_cpu_dec_return(nmi_state))
 		goto nmi_restart;
+
+	if (user_mode(regs))
+		mds_user_clear_cpu_buffers();

What if the NMI fires after a call to prepare_exit_to_usermode() but before the actual return to usermode, would that be a problem?

Quoted 4 lines

Yes, it's a hole in the protection, but you would need to be able to orchestrate that as user which I doubt you can. So the thought was that we rather avoid the penalty for perf when it hits kernel space, which requires root ....

Fair enough.

Reviewed-by on v6 7/14
#27 lore raw

[MODERATED] Re: [patch V6 07/14] MDS basics 7

In reply to Thomas Gleixner
Quoted 30 lines · speck for Thomas Gleixner

Subject: [patch V6 07/14] x86/speculation/mds: Clear CPU buffers on exit to user
From: Thomas Gleixner <[email protected]>

Add a static key which controls the invocation of the CPU buffer clear mechanism on exit to user space and add the call into prepare_exit_to_usermode() and do_nmi() right before actually returning.

Add documentation which kernel to user space transition this covers and explain why some corner cases are not mitigated.

---
V4 --> v5: Use an inline helper instead of open coding it.
Rework the documentation paragraph about exceptions.

V3 --> V4: Add #DS mitigation and document that the #MC corner case
is really not interesting.

V3: Add NMI conditional on user regs and update documentation accordingly.
Use the static branch scheme suggested by Peter. Fix typos ...

---
 Documentation/x86/mds.rst            |   52 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/common.c              |    3 ++
 arch/x86/include/asm/nospec-branch.h |   13 ++++++++
 arch/x86/kernel/cpu/bugs.c           |    3 ++
 arch/x86/kernel/nmi.c                |    4 ++
 arch/x86/kernel/traps.c              |    7 ++++
 6 files changed, 82 insertions(+)

...

Quoted 6 lines
arch/x86/kernel/traps.c +0 -0
@@ -366,6 +366,13 @@ dotraplinkage void do_double_fault(struc
 		regs->ip = (unsigned long)general_protection;
 		regs->sp = (unsigned long)&gpregs->orig_ax;
 

arch/x86/kernel/traps.c dotraplinkage void do_double_fault(struc · line 378

Quoted 10 lines
arch/x86/kernel/traps.c +7 -0
+		/*
+		 * This situation can be triggered by userspace via
+		 * modify_ldt(2) and the return does not take the regular
+		 * user space exit, so a CPU buffer clear is required when
+		 * MDS mitigation is enabled.
+		 */
+		mds_user_clear_cpu_buffers();
 		return;
 	}
 #endif

Looks like the traps.c change is missing a hunk, see below. Otherwise:

arch/x86/kernel/traps.c: In function ‘do_double_fault’:
arch/x86/kernel/traps.c:375:3: error: implicit declaration of function ‘mds_user_clear_cpu_buffers’ [-Werror=implicit-function-declaration]
mds_user_clear_cpu_buffers();
^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:276: arch/x86/kernel/traps.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [scripts/Makefile.build:492: arch/x86/kernel] Error 2
make: *** [Makefile:1043: arch/x86] Error 2
make: *** Waiting for unfinished jobs....

---

arch/x86/kernel/traps.c +1 -0
index 5942060dba9a..ce33f7f672d6 100644
@@ -61,6 +61,7 @@
 #include <asm/mpx.h>
 #include <asm/vm86.h>
 #include <asm/umip.h>
+#include <asm/nospec-branch.h>
 
 #ifdef CONFIG_X86_64
 #include <asm/x86_init.h>

---

with that

Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#28 lore raw

PATCH v6 8/14 MDS basics 8

In reply to Thomas Gleixner

CPUs which are affected by L1TF and MDS mitigate MDS with the L1D Flush on VMENTER when updated microcode is installed.

If a CPU is not affected by L1TF or if the L1D Flush is not in use, then MDS mitigation needs to be invoked explicit.

For these cases, follow the host mitigation state and invoke the MDS mitigation before VMENTER.

---
V4 --> V5: Fix changelog

---
 arch/x86/kernel/cpu/bugs.c |    1 +
 arch/x86/kvm/vmx/vmx.c     |    2 ++
 2 files changed, 3 insertions(+)
arch/x86/kernel/cpu/bugs.c +1 -0
@@ -65,6 +65,7 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always
 
 /* Control MDS CPU buffer clear before returning to user space */
 DEFINE_STATIC_KEY_FALSE(mds_user_clear);
+EXPORT_SYMBOL_GPL(mds_user_clear);
 
 void __init check_bugs(void)
 {
arch/x86/kvm/vmx/vmx.c +2 -0
@@ -6371,6 +6371,8 @@ static void __vmx_vcpu_run(struct kvm_vc
 
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
 		vmx_l1d_flush(vcpu);
+	else if (static_branch_unlikely(&mds_user_clear))
+		mds_clear_cpu_buffers();
 
 	asm(
 		/* Store host registers */
Reviewed-by on v6 8/14
#29 lore raw

[MODERATED] Re: [patch V6 08/14] MDS basics 8

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc

Quoted 31 lines · speck for Thomas Gleixner

CPUs which are affected by L1TF and MDS mitigate MDS with the L1D Flush on VMENTER when updated microcode is installed.

If a CPU is not affected by L1TF or if the L1D Flush is not in use, then MDS mitigation needs to be invoked explicit.

For these cases, follow the host mitigation state and invoke the MDS mitigation before VMENTER.

---
V4 --> V5: Fix changelog

---
 arch/x86/kernel/cpu/bugs.c |    1 +
 arch/x86/kvm/vmx/vmx.c     |    2 ++
 2 files changed, 3 insertions(+)
arch/x86/kernel/cpu/bugs.c +1 -0
@@ -65,6 +65,7 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always
 
 /* Control MDS CPU buffer clear before returning to user space */
 DEFINE_STATIC_KEY_FALSE(mds_user_clear);
+EXPORT_SYMBOL_GPL(mds_user_clear);
 
 void __init check_bugs(void)
 {
arch/x86/kvm/vmx/vmx.c +0 -0
@@ -6371,6 +6371,8 @@ static void __vmx_vcpu_run(struct kvm_vc

We may want to add a comment below to summarize what's explained in the changelog. git blame tends to lose prime history after any future most unsignificant variable rename. Something like:

+ /* l1tf mitigation, if present, spares us mds mitigation */

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc · line 6375

Quoted 4 lines
arch/x86/kvm/vmx/vmx.c +2 -0
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
 		vmx_l1d_flush(vcpu);
+	else if (static_branch_unlikely(&mds_user_clear))
+		mds_clear_cpu_buffers();

Thanks.

#30 lore raw

[MODERATED] Encrypted Message

In reply to Thomas Gleixner

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: [patch V6 08/14] MDS basics 8

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc · line 6375

Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kvm/vmx/vmx.c +2 -0
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
 		vmx_l1d_flush(vcpu);
+	else if (static_branch_unlikely(&mds_user_clear))
+		mds_clear_cpu_buffers();

Does this cover the case where we have older ucode installed that does L1D flush but NOT the MD_CLEAR? I'm about to go check to see if there's logic handling this but wanted to call it out.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#31 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Jon Masters <[email protected]>
Subject: Re: [patch V6 08/14] MDS basics 8

Quoted 9 lines · speck for Jon Masters

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc · line 6375

Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kvm/vmx/vmx.c +2 -0
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
 		vmx_l1d_flush(vcpu);
+	else if (static_branch_unlikely(&mds_user_clear))
+		mds_clear_cpu_buffers();

Does this cover the case where we have older ucode installed that does L1D flush but NOT the MD_CLEAR? I'm about to go check to see if there's logic handling this but wanted to call it out.

Aside from the above question, I've reviewed all of the patches extensively at this point. Feel free to add a Reviewed-by or Tested-by according to your preference. I've a bunch of further tests running, including on AMD platforms just so to check nothing broke with those platforms that are not susceptible to MDS.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#32 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Jon Masters <[email protected]>
Subject: Re: [patch V6 08/14] MDS basics 8

Quoted 11 lines · speck for Jon Masters
Quoted 9 lines · speck for Jon Masters

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc · line 6375

Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kvm/vmx/vmx.c +2 -0
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
 		vmx_l1d_flush(vcpu);
+	else if (static_branch_unlikely(&mds_user_clear))
+		mds_clear_cpu_buffers();

Does this cover the case where we have older ucode installed that does L1D flush but NOT the MD_CLEAR? I'm about to go check to see if there's logic handling this but wanted to call it out.

Quoted 5 lines

Aside from the above question, I've reviewed all of the patches extensively at this point. Feel free to add a Reviewed-by or Tested-by according to your preference. I've a bunch of further tests running, including on AMD platforms just so to check nothing broke with those platforms that are not susceptible to MDS.

Running fine on AMD platform here and reports correctly:

$ cat /sys/devices/system/cpu/vulnerabilities/mds
Not affected

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#33 lore raw

Re: Encrypted Message

In reply to Jon Masters
Quoted 9 lines · speck for Jon Masters

arch/x86/kvm/vmx/vmx.c static void __vmx_vcpu_run(struct kvm_vc · line 6375

Quoted 4 lines · speck for Thomas Gleixner
      if (static_branch_unlikely(&vmx_l1d_should_flush))
              vmx_l1d_flush(vcpu);
arch/x86/kvm/vmx/vmx.c +2 -0
+     else if (static_branch_unlikely(&mds_user_clear))
+             mds_clear_cpu_buffers();

Does this cover the case where we have older ucode installed that does L1D flush but NOT the MD_CLEAR? I'm about to go check to see if there's logic handling this but wanted to call it out.

If no updated microcode is available then it's pretty irrelevant which code path you take. None of them will mitigate MDS.

Thanks,

tglx

#34 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: Encrypted Message

Quoted 8 lines · speck for Thomas Gleixner
Quoted 6 lines · speck for Jon Masters
Quoted 4 lines · speck for Thomas Gleixner
      if (static_branch_unlikely(&vmx_l1d_should_flush))
              vmx_l1d_flush(vcpu);
arch/x86/kvm/vmx/vmx.c +2 -0
+     else if (static_branch_unlikely(&mds_user_clear))
+             mds_clear_cpu_buffers();
Quoted 6 lines
Quoted 3 lines

Does this cover the case where we have older ucode installed that does L1D flush but NOT the MD_CLEAR? I'm about to go check to see if there's logic handling this but wanted to call it out.

If no updated microcode is available then it's pretty irrelevant which code path you take. None of them will mitigate MDS.

You're right. My fear was we'd have some microcode that mitigated L1D without implied MD clear but also did MDS. I was incorrect - all ucode that will be publicly released will have both properties.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
Reviewed-by on v6 8/14
#35 lore raw

[MODERATED] Re: [patch V6 08/14] MDS basics 8

In reply to Thomas Gleixner
Quoted 5 lines · speck for Thomas Gleixner

CPUs which are affected by L1TF and MDS mitigate MDS with the L1D Flush on VMENTER when updated microcode is installed.

If a CPU is not affected by L1TF or if the L1D Flush is not in use, then MDS mitigation needs to be invoked explicit.

explicitly.

Quoted 4 lines

For these cases, follow the host mitigation state and invoke the MDS mitigation before VMENTER.

Quoted 8 lines

---
V4 --> V5: Fix changelog

---
 arch/x86/kernel/cpu/bugs.c |    1 +
 arch/x86/kvm/vmx/vmx.c     |    2 ++
 2 files changed, 3 insertions(+)

With that:

Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#36 lore raw

PATCH v6 9/14 MDS basics 9

In reply to Thomas Gleixner

Subject: [patch V6 09/14] x86/speculation/mds: Conditionally clear CPU buffers on idle entry
From: Thomas Gleixner <[email protected]>

Add a static key which controls the invocation of the CPU buffer clear mechanism on idle entry. This is independent of other MDS mitigations because the idle entry invocation to mitigate the potential leakage due to store buffer repartitioning is only necessary on SMT systems.

Add the actual invocations to the different halt/mwait variants which covers all usage sites. mwaitx is not patched as it's not available on Intel CPUs.

The buffer clear is only invoked before entering the C-State to prevent that stale data from the idling CPU is spilled to the Hyper-Thread sibling after the Store buffer got repartitioned and all entries are available to the non idle sibling.

When coming out of idle the store buffer is partitioned again so each sibling has half of it available. Now CPU which returned from idle could be speculatively exposed to contents of the sibling, but the buffers are flushed either on exit to user space or on VMENTER.

When later on conditional buffer clearing is implemented on top of this, then there is no action required either because before returning to user space the context switch will set the condition flag which causes a flush on the return to user path.

Note, that the buffer clearing on idle is only sensible on CPUs which are solely affected by MSBDS and not any other variant of MDS because the other MDS variants cannot be mitigated when SMT is enabled, so the buffer clearing on idle would be a window dressing exercise.

This intentionally does not handle the case in the acpi/processor_idle driver which uses the legacy IO port interface for C-State transitions for two reasons:

- The acpi/processor_idle driver was replaced by the intel_idle driver almost a decade ago. Anything Nehalem upwards supports it and defaults to that new driver.

- The legacy IO port interface is likely to be used on older and therefore unaffected CPUs or on systems which do not receive microcode updates anymore, so there is no point in adding that.

---
V4: Export mds_idle_clear
V3: Adjust document wording

---
 Documentation/x86/mds.rst            |   42 +++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/irqflags.h      |    4 +++
 arch/x86/include/asm/mwait.h         |    7 +++++
 arch/x86/include/asm/nospec-branch.h |   12 ++++++++++
 arch/x86/kernel/cpu/bugs.c           |    3 ++
 5 files changed, 68 insertions(+)
Documentation/x86/mds.rst +42 -0
@@ -149,3 +149,45 @@ Mitigation points
      This takes the paranoid exit path only when the INT1 breakpoint is in
      kernel space. #DB on a user space address takes the regular exit path,
      so no extra mitigation required.
+
+
+2. C-State transition
+^^^^^^^^^^^^^^^^^^^^^
+
+   When a CPU goes idle and enters a C-State the CPU buffers need to be
+   cleared on affected CPUs when SMT is active. This addresses the
+   repartitioning of the store buffer when one of the Hyper-Threads enters
+   a C-State.
+
+   When SMT is inactive, i.e. either the CPU does not support it or all
+   sibling threads are offline CPU buffer clearing is not required.
+
+   The idle clearing is enabled on CPUs which are only affected by MSBDS
+   and not by any other MDS variant. The other MDS variants cannot be
+   protected against cross Hyper-Thread attacks because the Fill Buffer and
+   the Load Ports are shared. So on CPUs affected by other variants, the
+   idle clearing would be a window dressing exercise and is therefore not
+   activated.
+
+   The invocation is controlled by the static key mds_idle_clear which is
+   switched depending on the chosen mitigation mode and the SMT state of
+   the system.
+
+   The buffer clear is only invoked before entering the C-State to prevent
+   that stale data from the idling CPU from spilling to the Hyper-Thread
+   sibling after the store buffer got repartitioned and all entries are
+   available to the non idle sibling.
+
+   When coming out of idle the store buffer is partitioned again so each
+   sibling has half of it available. The back from idle CPU could be then
+   speculatively exposed to contents of the sibling. The buffers are
+   flushed either on exit to user space or on VMENTER so malicious code
+   in user space or the guest cannot speculatively access them.
+
+   The mitigation is hooked into all variants of halt()/mwait(), but does
+   not cover the legacy ACPI IO-Port mechanism because the ACPI idle driver
+   has been superseded by the intel_idle driver around 2010 and is
+   preferred on all affected CPUs which are expected to gain the MD_CLEAR
+   functionality in microcode. Aside of that the IO-Port mechanism is a
+   legacy interface which is only used on older systems which are either
+   not affected or do not receive microcode updates anymore.
arch/x86/include/asm/irqflags.h +4 -0
@@ -6,6 +6,8 @@
 
 #ifndef __ASSEMBLY__
 
+#include <asm/nospec-branch.h>
+
 /* Provide __cpuidle; we can't safely include <linux/cpu.h> */
 #define __cpuidle __attribute__((__section__(".cpuidle.text")))
 
@@ -54,11 +56,13 @@ static inline void native_irq_enable(voi
 
 static inline __cpuidle void native_safe_halt(void)
 {
+	mds_idle_clear_cpu_buffers();
 	asm volatile("sti; hlt": : :"memory");
 }
 
 static inline __cpuidle void native_halt(void)
 {
+	mds_idle_clear_cpu_buffers();
 	asm volatile("hlt": : :"memory");
 }
 
arch/x86/include/asm/mwait.h +7 -0
@@ -6,6 +6,7 @@
 #include <linux/sched/idle.h>
 
 #include <asm/cpufeature.h>
+#include <asm/nospec-branch.h>
 
 #define MWAIT_SUBSTATE_MASK		0xf
 #define MWAIT_CSTATE_MASK		0xf
@@ -40,6 +41,8 @@ static inline void __monitorx(const void
 
 static inline void __mwait(unsigned long eax, unsigned long ecx)
 {
+	mds_idle_clear_cpu_buffers();
+
 	/* "mwait %eax, %ecx;" */
 	asm volatile(".byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));
@@ -74,6 +77,8 @@ static inline void __mwait(unsigned long
 static inline void __mwaitx(unsigned long eax, unsigned long ebx,
 			    unsigned long ecx)
 {
+	/* No MDS buffer clear as this is AMD/HYGON only */
+
 	/* "mwaitx %eax, %ebx, %ecx;" */
 	asm volatile(".byte 0x0f, 0x01, 0xfb;"
 		     :: "a" (eax), "b" (ebx), "c" (ecx));
@@ -81,6 +86,8 @@ static inline void __mwaitx(unsigned lon
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
+	mds_idle_clear_cpu_buffers();
+
 	trace_hardirqs_on();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
arch/x86/include/asm/nospec-branch.h +12 -0
@@ -319,6 +319,7 @@ DECLARE_STATIC_KEY_FALSE(switch_mm_cond_
 DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
 DECLARE_STATIC_KEY_FALSE(mds_user_clear);
+DECLARE_STATIC_KEY_FALSE(mds_idle_clear);
 
 #include <asm/segment.h>
 
@@ -356,6 +357,17 @@ static inline void mds_user_clear_cpu_bu
 		mds_clear_cpu_buffers();
 }
 
+/**
+ * mds_idle_clear_cpu_buffers - Mitigation for MDS vulnerability
+ *
+ * Clear CPU buffers if the corresponding static key is enabled
+ */
+static inline void mds_idle_clear_cpu_buffers(void)
+{
+	if (static_branch_likely(&mds_idle_clear))
+		mds_clear_cpu_buffers();
+}
+
 #endif /* __ASSEMBLY__ */
 
 /*
arch/x86/kernel/cpu/bugs.c +3 -0
@@ -66,6 +66,9 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always
 /* Control MDS CPU buffer clear before returning to user space */
 DEFINE_STATIC_KEY_FALSE(mds_user_clear);
 EXPORT_SYMBOL_GPL(mds_user_clear);
+/* Control MDS CPU buffer clear before idling (halt, mwait) */
+DEFINE_STATIC_KEY_FALSE(mds_idle_clear);
+EXPORT_SYMBOL_GPL(mds_idle_clear);
 
 void __init check_bugs(void)
 {
Reviewed-by on v6 9/14
#37 lore raw

[MODERATED] Re: [patch V6 09/14] MDS basics 9

Quoted 40 lines · speck for Thomas Gleixner

Subject: [patch V6 09/14] x86/speculation/mds: Conditionally clear CPU buffers on idle entry
From: Thomas Gleixner <[email protected]>

Add a static key which controls the invocation of the CPU buffer clear mechanism on idle entry. This is independent of other MDS mitigations because the idle entry invocation to mitigate the potential leakage due to store buffer repartitioning is only necessary on SMT systems.

Add the actual invocations to the different halt/mwait variants which covers all usage sites. mwaitx is not patched as it's not available on Intel CPUs.

The buffer clear is only invoked before entering the C-State to prevent that stale data from the idling CPU is spilled to the Hyper-Thread sibling after the Store buffer got repartitioned and all entries are available to the non idle sibling.

When coming out of idle the store buffer is partitioned again so each sibling has half of it available. Now CPU which returned from idle could be speculatively exposed to contents of the sibling, but the buffers are flushed either on exit to user space or on VMENTER.

When later on conditional buffer clearing is implemented on top of this, then there is no action required either because before returning to user space the context switch will set the condition flag which causes a flush on the return to user path.

Note, that the buffer clearing on idle is only sensible on CPUs which are solely affected by MSBDS and not any other variant of MDS because the other MDS variants cannot be mitigated when SMT is enabled, so the buffer clearing on idle would be a window dressing exercise.

This intentionally does not handle the case in the acpi/processor_idle driver which uses the legacy IO port interface for C-State transitions for two reasons:

- The acpi/processor_idle driver was replaced by the intel_idle driver almost a decade ago. Anything Nehalem upwards supports it and defaults to that new driver.

Quoted 7 lines

- The legacy IO port interface is likely to be used on older and therefore unaffected CPUs or on systems which do not receive microcode updates anymore, so there is no point in adding that.

#38 lore raw

PATCH v6 10/14 MDS basics 10

In reply to Thomas Gleixner

Subject: [patch V6 10/14] x86/speculation/mds: Add mitigation control for MDS
From: Thomas Gleixner <[email protected]>

Now that the mitigations are in place, add a command line parameter to control the mitigation, a mitigation selector function and a SMT update mechanism.

This is the minimal straight forward initial implementation which just provides an always on/off mode. The command line parameter is:

mds=[full|off]

This is consistent with the existing mitigations for other speculative hardware vulnerabilities.

The idle invocation is dynamically updated according to the SMT state of the system similar to the dynamic update of the STIBP mitigation. The idle mitigation is limited to CPUs which are only affected by MSBDS and not any other variant, because the other variants cannot be mitigated on SMT enabled systems.

---
V5 --> V6: Make idle clearing depend on BUG_MSBDS_ONLY V4 --> V5: Remove 'auto'

---
 Documentation/admin-guide/kernel-parameters.txt |   22 +++++++
 arch/x86/include/asm/processor.h                |    5 +
 arch/x86/kernel/cpu/bugs.c                      |   68 ++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +22 -0
@@ -2356,6 +2356,28 @@
 			Format: <first>,<last>
 			Specifies range of consoles to be captured by the MDA.
 
+	mds=		[X86,INTEL]
+			Control mitigation for the Micro-architectural Data
+			Sampling (MDS) vulnerability.
+
+			Certain CPUs are vulnerable to an exploit against CPU
+			internal buffers which can forward information to a
+			disclosure gadget under certain conditions.
+
+			In vulnerable processors, the speculatively
+			forwarded data can be used in a cache side channel
+			attack, to access data to which the attacker does
+			not have direct access.
+
+			This parameter controls the MDS mitigation. The
+			options are:
+
+			full    - Enable MDS mitigation on vulnerable CPUs
+			off     - Unconditionally disable MDS mitigation
+
+			Not specifying this option is equivalent to
+			mds=full.
+
 	mem=nn[KMG]	[KNL,BOOT] Force usage of a specific amount of memory
 			Amount of memory to be used when the kernel is not able
 			to see the whole system memory or for test.
arch/x86/include/asm/processor.h +5 -0
@@ -992,4 +992,9 @@ enum l1tf_mitigations {
 
 extern enum l1tf_mitigations l1tf_mitigation;
 
+enum mds_mitigations {
+	MDS_MITIGATION_OFF,
+	MDS_MITIGATION_FULL,
+};
+
 #endif /* _ASM_X86_PROCESSOR_H */
arch/x86/kernel/cpu/bugs.c +68 -0

98 lines not on this page · raw message

#39 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: [patch V6 10/14] MDS basics 10

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 672

Quoted 3 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/bugs.c +3 -0
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
           ^^^^^
           MSBDS
Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#40 lore raw

[MODERATED] Re: [patch V6 10/14] MDS basics 10

In reply to Thomas Gleixner

Hi Thomas,

Quoted 4 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/bugs.c +4 -0
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+	/*

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 680

Quoted 10 lines
arch/x86/kernel/cpu/bugs.c +10 -0
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled, so clearing the buffers on
+	 * idle would be a window dressing exercise.
+	 */
+	if (!boot_cpu_has(X86_BUG_MSBDS_ONLY))
+		return;
+
+	if (sched_smt_active())
+		static_branch_enable(&mds_idle_clear);

Do you think it's worth also clearing MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT by setting ring3mwait_disabled when sched_smt_active() is true above?

I don't expect anybody will pass manually ring3mwait=disable to the kernel on XEON_PHI_KNL/XEON_PHI_KNM. I'm not aware of any app using the user mwait, which also makes this not a big deal.. but it goes both ways, it's also not a big deal for userland to turn it off when we report SMT is enabled and safe in sysfs.

Thanks,
Andrea

#41 lore raw

Re: [patch V6 10/14] MDS basics 10

Andrea,

Quoted 13 lines · speck for Andrea Arcangeli

Hi Thomas,

Quoted 10 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/bugs.c +10 -0
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled, so clearing the buffers on
+	 * idle would be a window dressing exercise.
+	 */
+	if (!boot_cpu_has(X86_BUG_MSBDS_ONLY))
Quoted 8 lines

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 680

Quoted 4 lines
arch/x86/kernel/cpu/bugs.c +4 -0
+		return;
+
+	if (sched_smt_active())
+		static_branch_enable(&mds_idle_clear);

Do you think it's worth also clearing MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT by setting ring3mwait_disabled when sched_smt_active() is true above?

Not sure.

Quoted 5 lines

I don't expect anybody will pass manually ring3mwait=disable to the kernel on XEON_PHI_KNL/XEON_PHI_KNM. I'm not aware of any app using the user mwait, which also makes this not a big deal.. but it goes both ways, it's also not a big deal for userland to turn it off when we report SMT is enabled and safe in sysfs.

True and as usual we don't really know what people are doing and wreckaging existing applications which rely on that would be not nice.

Thanks,

tglx

#42 lore raw

[MODERATED] Re: [patch V6 10/14] MDS basics 10

In reply to Thomas Gleixner
Quoted 26 lines · speck for Thomas Gleixner

Subject: [patch V6 10/14] x86/speculation/mds: Add mitigation control for MDS
From: Thomas Gleixner <[email protected]>

Now that the mitigations are in place, add a command line parameter to control the mitigation, a mitigation selector function and a SMT update mechanism.

This is the minimal straight forward initial implementation which just provides an always on/off mode. The command line parameter is:

mds=[full|off]

This is consistent with the existing mitigations for other speculative hardware vulnerabilities.

The idle invocation is dynamically updated according to the SMT state of the system similar to the dynamic update of the STIBP mitigation. The idle mitigation is limited to CPUs which are only affected by MSBDS and not any other variant, because the other variants cannot be mitigated on SMT enabled systems.

---
V5 --> V6: Make idle clearing depend on BUG_MSBDS_ONLY V4 --> V5: Remove 'auto'
---

...

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 673

Quoted 11 lines
arch/x86/kernel/cpu/bugs.c +7 -0
@@ -617,6 +664,24 @@ static void update_indir_branch_cond(voi
 		static_branch_disable(&switch_to_cond_stibp);
 }
 
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled,

... but we're not enabling the key when SMT on those is disabled, AFAICT. Or is that coming later?

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 676

Quoted 4 lines

so clearing the buffers on

arch/x86/kernel/cpu/bugs.c +3 -0
+	 * idle would be a window dressing exercise.
+	 */
+	if (!boot_cpu_has(X86_BUG_MSBDS_ONLY))

if (!boot_cpu_has_bug

Quoted 22 lines
arch/x86/kernel/cpu/bugs.c +11 -0
+		return;
+
+	if (sched_smt_active())
+		static_branch_enable(&mds_idle_clear);
+	else
+		static_branch_disable(&mds_idle_clear);
+}
+
 void arch_smt_update(void)
 {
 	/* Enhanced IBRS implies STIBP. No update required. */
@@ -638,6 +703,9 @@ void arch_smt_update(void)
 		break;
 	}
 
+	if (mds_mitigation == MDS_MITIGATION_FULL)
+		update_mds_branch_idle();
+
 	mutex_unlock(&spec_ctrl_mutex);
 }
 
Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#43 lore raw

Re: [patch V6 10/14] MDS basics 10

Quoted 11 lines · speck for Borislav Petkov

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi

Quoted 7 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/bugs.c +7 -0
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled,

... but we're not enabling the key when SMT on those is disabled, AFAICT. Or is that coming later?

Five lines down ....

Quoted 6 lines

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 676

Quoted 4 lines

so clearing the buffers on

arch/x86/kernel/cpu/bugs.c +3 -0
+	 * idle would be a window dressing exercise.
+	 */
+	if (!boot_cpu_has(X86_BUG_MSBDS_ONLY))

if (!boot_cpu_has_bug

Fixed.

Quoted 3 lines

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 679

Quoted 3 lines
arch/x86/kernel/cpu/bugs.c +3 -0
+		return;
+
+	if (sched_smt_active())

... here is the decision whether to enable or disable.

Quoted 4 lines

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi · line 683

Quoted 4 lines
arch/x86/kernel/cpu/bugs.c +4 -0
+		static_branch_enable(&mds_idle_clear);
+	else
+		static_branch_disable(&mds_idle_clear);
+}

Thanks,

tglx

#44 lore raw

Re: [patch V6 10/14] MDS basics 10

Quoted 13 lines · speck for Thomas Gleixner
Quoted 11 lines · speck for Borislav Petkov

arch/x86/kernel/cpu/bugs.c static void update_indir_branch_cond(voi

Quoted 7 lines · speck for Thomas Gleixner
arch/x86/kernel/cpu/bugs.c +7 -0
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+	/*
+	 * Enable the idle clearing on CPUs which are affected only by
+	 * MDBDS and not any other MDS variant. The other variants cannot
+	 * be mitigated when SMT is enabled,

... but we're not enabling the key when SMT on those is disabled, AFAICT. Or is that coming later?

Quoted 1 line

Five lines down ....

Following up on our conversation on IRC, I've reworded the comment:

/*
* Enable the idle clearing if SMT is active on CPUs which are
* affected only by MSBDS and not any other MDS variant. *
* The other variants cannot be mitigated when SMT is enabled, so
* clearing the buffers on idle just to prevent the Store Buffer
* repartitioning leak would be a window dressing exercise. */
if (!boot_cpu_has_bug(X86_BUG_MSBDS_ONLY))
return;

Thanks,

tglx

Reviewed-by
#45 lore raw

[MODERATED] Re: Re: [patch V6 10/14] MDS basics 10

Review

Quoted 12 lines · speck for Thomas Gleixner

Following up on our conversation on IRC, I've reworded the comment:

/*
* Enable the idle clearing if SMT is active on CPUs which are
* affected only by MSBDS and not any other MDS variant. *
* The other variants cannot be mitigated when SMT is enabled, so
* clearing the buffers on idle just to prevent the Store Buffer
* repartitioning leak would be a window dressing exercise.

(quoted diff) +0 -0
 	 */
 	if (!boot_cpu_has_bug(X86_BUG_MSBDS_ONLY))
 		return;

Yap, looks good.

With that addressed:

Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#46 lore raw

PATCH v6 11/14 MDS basics 11

In reply to Thomas Gleixner

Subject: [patch V6 11/14] x86/speculation/mds: Add sysfs reporting for MDS
From: Thomas Gleixner <[email protected]>

Add the sysfs reporting file for MDS. It exposes the vulnerability and mitigation state similar to the existing files for the other speculative hardware vulnerabilities.

---
V3: Copy & Paste done right :(

---
 Documentation/ABI/testing/sysfs-devices-system-cpu |    1 
 arch/x86/kernel/cpu/bugs.c                         |   25 +++++++++++++++++++++
 drivers/base/cpu.c                                 |    8 ++++++
 include/linux/cpu.h                                |    2 +
 4 files changed, 36 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +1 -0
@@ -484,6 +484,7 @@ What:		/sys/devices/system/cpu/vulnerabi
 		/sys/devices/system/cpu/vulnerabilities/spectre_v2
 		/sys/devices/system/cpu/vulnerabilities/spec_store_bypass
 		/sys/devices/system/cpu/vulnerabilities/l1tf
+		/sys/devices/system/cpu/vulnerabilities/mds
 Date:		January 2018
 Contact:	Linux kernel mailing list <[email protected]>
 Description:	Information about CPU vulnerabilities
arch/x86/kernel/cpu/bugs.c +25 -0
@@ -1170,6 +1170,22 @@ static ssize_t l1tf_show_state(char *buf
 }
 #endif
 
+static ssize_t mds_show_state(char *buf)
+{
+	if (!hypervisor_is_type(X86_HYPER_NATIVE)) {
+		return sprintf(buf, "%s; SMT Host state unknown\n",
+			       mds_strings[mds_mitigation]);
+	}
+
+	if (boot_cpu_has(X86_BUG_MSBDS_ONLY)) {
+		return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
+			       sched_smt_active() ? "mitigated" : "disabled");
+	}
+
+	return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
+		       sched_smt_active() ? "vulnerable" : "disabled");
+}
+
 static char *stibp_state(void)
 {
 	if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
@@ -1236,6 +1252,10 @@ static ssize_t cpu_show_common(struct de
 		if (boot_cpu_has(X86_FEATURE_L1TF_PTEINV))
 			return l1tf_show_state(buf);
 		break;
+
+	case X86_BUG_MDS:
+		return mds_show_state(buf);
+
 	default:
 		break;
 	}
@@ -1267,4 +1287,9 @@ ssize_t cpu_show_l1tf(struct device *dev
 {
 	return cpu_show_common(dev, attr, buf, X86_BUG_L1TF);
 }
+
+ssize_t cpu_show_mds(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return cpu_show_common(dev, attr, buf, X86_BUG_MDS);
+}
 #endif
drivers/base/cpu.c +8 -0
@@ -546,11 +546,18 @@ ssize_t __weak cpu_show_l1tf(struct devi
 	return sprintf(buf, "Not affected\n");
 }
 
+ssize_t __weak cpu_show_mds(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "Not affected\n");
+}
+
 static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
 static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
 static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
 static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL);
 static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL);
+static DEVICE_ATTR(mds, 0444, cpu_show_mds, NULL);
 
 static struct attribute *cpu_root_vulnerabilities_attrs[] = {
 	&dev_attr_meltdown.attr,
@@ -558,6 +565,7 @@ static struct attribute *cpu_root_vulner
 	&dev_attr_spectre_v2.attr,
 	&dev_attr_spec_store_bypass.attr,
 	&dev_attr_l1tf.attr,
+	&dev_attr_mds.attr,
 	NULL
 };
 
include/linux/cpu.h +2 -0
@@ -57,6 +57,8 @@ extern ssize_t cpu_show_spec_store_bypas
 					  struct device_attribute *attr, char *buf);
 extern ssize_t cpu_show_l1tf(struct device *dev,
 			     struct device_attribute *attr, char *buf);
+extern ssize_t cpu_show_mds(struct device *dev,
+			    struct device_attribute *attr, char *buf);
 
 extern __printf(4, 5)
 struct device *cpu_device_create(struct device *parent, void *drvdata,
#47 lore raw

PATCH v6 12/14 MDS basics 12

In reply to Thomas Gleixner

Subject: [patch V6 12/14] x86/speculation/mds: Add mitigation mode VMWERV
From: Thomas Gleixner <[email protected]>

In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the X86_FEATURE_MD_CLEAR CPUID bit to guests.

Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if X86_FEATURE_MD_CLEAR is not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.

That said: Virtual Machines Will Eventually Receive Vaccine

---
V2 -> V3: Rename mode.

---
 Documentation/x86/mds.rst        |   27 +++++++++++++++++++++++++++
 arch/x86/include/asm/processor.h |    1 +
 arch/x86/kernel/cpu/bugs.c       |   18 ++++++++++++------
 3 files changed, 40 insertions(+), 6 deletions(-)
Documentation/x86/mds.rst +27 -0
@@ -93,11 +93,38 @@ enters a C-state.
 The mitigation is invoked on kernel/userspace, hypervisor/guest and C-state
 (idle) transitions.
 
+As a special quirk to address virtualization scenarios where the host has
+the microcode updated, but the hypervisor does not (yet) expose the
+MD_CLEAR CPUID bit to guests, the kernel issues the VERW instruction in the
+hope that it might actually clear the buffers. The state is reflected
+accordingly.
+
 According to current knowledge additional mitigations inside the kernel
 itself are not required because the necessary gadgets to expose the leaked
 data cannot be controlled in a way which allows exploitation from malicious
 user space or VM guests.
 
+Kernel internal mitigation modes
+--------------------------------
+
+ ======= ============================================================
+ off      Mitigation is disabled. Either the CPU is not affected or
+          mds=off is supplied on the kernel command line
+
+ full     Mitigation is eanbled. CPU is affected and MD_CLEAR is
+          advertised in CPUID.
+
+ vmwerv	  Mitigation is enabled. CPU is affected and MD_CLEAR is not
+	  advertised in CPUID. That is mainly for virtualization
+	  scenarios where the host has the updated microcode but the
+	  hypervisor does not expose MD_CLEAR in CPUID. It's a best
+	  effort approach without guarantee.
+ ======= ============================================================
+
+If the CPU is affected and mds=off is not supplied on the kernel command
+line then the kernel selects the appropriate mitigation mode depending on
+the availability of the MD_CLEAR CPUID bit.
+
 Mitigation points
 -----------------
 
arch/x86/include/asm/processor.h +1 -0
@@ -995,6 +995,7 @@ extern enum l1tf_mitigations l1tf_mitiga
 enum mds_mitigations {
 	MDS_MITIGATION_OFF,
 	MDS_MITIGATION_FULL,
+	MDS_MITIGATION_VMWERV,
 };
 
 #endif /* _ASM_X86_PROCESSOR_H */
arch/x86/kernel/cpu/bugs.c +12 -6
@@ -224,7 +224,8 @@ static enum mds_mitigations mds_mitigati
 
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",
-	[MDS_MITIGATION_FULL]	= "Mitigation: Clear CPU buffers"
+	[MDS_MITIGATION_FULL]	= "Mitigation: Clear CPU buffers",
+	[MDS_MITIGATION_VMWERV]	= "Vulnerable: Clear CPU buffers attempted, no microcode",
 };
 
 static void mds_select_mitigation(void)
@@ -235,10 +236,9 @@ static void mds_select_mitigation(void)
 	}
 
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
-		if (boot_cpu_has(X86_FEATURE_MD_CLEAR))
-			static_branch_enable(&mds_user_clear);
-		else
-			mds_mitigation = MDS_MITIGATION_OFF;
+		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
+			mds_mitigation = MDS_MITIGATION_VMWERV;
+		static_branch_enable(&mds_user_clear);
 	}
 	pr_info("%s\n", mds_strings[mds_mitigation]);
 }
@@ -703,8 +703,14 @@ void arch_smt_update(void)
 		break;
 	}
 
-	if (mds_mitigation == MDS_MITIGATION_FULL)
+	switch(mds_mitigation) {
+	case MDS_MITIGATION_FULL:
+	case MDS_MITIGATION_VMWERV:
 		update_mds_branch_idle();
+		break;
+	case MDS_MITIGATION_OFF:
+		break;
+	}
 
 	mutex_unlock(&spec_ctrl_mutex);
 }
#48 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: [patch V6 12/14] MDS basics 12

Quoted 8 lines · speck for Thomas Gleixner

Subject: [patch V6 12/14] x86/speculation/mds: Add mitigation mode VMWERV
From: Thomas Gleixner <[email protected]>

In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the X86_FEATURE_MD_CLEAR CPUID bit to guests.

Quoted 7 lines

Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if X86_FEATURE_MD_CLEAR is not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.

That said: Virtual Machines Will Eventually Receive Vaccine

The effect of this patch, currently, is that a (bare metal) machine without updated ucode will print the following:

[    1.576602] MDS: Vulnerable: Clear CPU buffers attempted, no microcode

The intention of the patch is to say "hey, you might be on a VM, so we'll try anyway in case we didn't get told you had MD_CLEAR". But the effect on bare metal might be ambiguous. It's reasonable (for someone else) to assume we might be using a software sequence to try flushing.

Perhaps the wording should convey something like:

"MDS: Vulnerable: Clear CPU buffers may not work, no microcode"

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#49 lore raw

Re: Encrypted Message

Quoted 7 lines · speck for Jon Masters
Quoted 1 line

That said: Virtual Machines Will Eventually Receive Vaccine

The effect of this patch, currently, is that a (bare metal) machine without updated ucode will print the following:

[    1.576602] MDS: Vulnerable: Clear CPU buffers attempted, no microcode
Quoted 8 lines

The intention of the patch is to say "hey, you might be on a VM, so we'll try anyway in case we didn't get told you had MD_CLEAR". But the effect on bare metal might be ambiguous. It's reasonable (for someone else) to assume we might be using a software sequence to try flushing.

Perhaps the wording should convey something like:

"MDS: Vulnerable: Clear CPU buffers may not work, no microcode"

Yeah, we also could do something like the delta patch below:

Thanks,

tglx

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

arch/x86/kernel/cpu/bugs.c +16 -6
@@ -228,18 +228,28 @@ static const char * const mds_strings[]
 	[MDS_MITIGATION_VMWERV]	= "Vulnerable: Clear CPU buffers attempted, no microcode",
 };
 
-static void mds_select_mitigation(void)
+static void __init mds_check_md_clear(void)
+{
+	if (!boot_cpu_has(X86_FEATURE_MD_CLEAR)) {
+		if (hypervisor_is_type(X86_HYPER_NATIVE)) {
+			mds_mitigation = MDS_MITIGATION_OFF;
+			return;
+		}
+		mds_mitigation = MDS_MITIGATION_VMWERV;
+	}
+	static_branch_enable(&mds_user_clear);
+}
+
+static void __init mds_select_mitigation(void)
 {
 	if (!boot_cpu_has_bug(X86_BUG_MDS)) {
 		mds_mitigation = MDS_MITIGATION_OFF;
 		return;
 	}
 
-	if (mds_mitigation == MDS_MITIGATION_FULL) {
-		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
-			mds_mitigation = MDS_MITIGATION_VMWERV;
-		static_branch_enable(&mds_user_clear);
-	}
+	if (mds_mitigation == MDS_MITIGATION_FULL)
+		mds_check_md_clear();
+
 	pr_info("%s\n", mds_strings[mds_mitigation]);
 }
 
#50 lore raw

[MODERATED] Re: [patch V6 12/14] MDS basics 12

In reply to Thomas Gleixner
Quoted 9 lines · speck for Thomas Gleixner

Subject: [patch V6 12/14] x86/speculation/mds: Add mitigation mode VMWERV
From: Thomas Gleixner <[email protected]>

In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the X86_FEATURE_MD_CLEAR CPUID bit to guests.

Introduce an internal mitigation mode VWWERV which enables the invocation

minor type-oh. s/VWWERV/VMWERV/

--mark

Reviewed-by on v6 12/14
#51 lore raw

[MODERATED] Re: [patch V6 12/14] MDS basics 12

In reply to Thomas Gleixner
Quoted 24 lines · speck for Thomas Gleixner

Subject: [patch V6 12/14] x86/speculation/mds: Add mitigation mode VMWERV
From: Thomas Gleixner <[email protected]>

In virtualized environments it can happen that the host has the microcode update which utilizes the VERW instruction to clear CPU buffers, but the hypervisor is not yet updated to expose the X86_FEATURE_MD_CLEAR CPUID bit to guests.

Introduce an internal mitigation mode VWWERV which enables the invocation of the CPU buffer clearing even if X86_FEATURE_MD_CLEAR is not set. If the system has no updated microcode this results in a pointless execution of the VERW instruction wasting a few CPU cycles. If the microcode is updated, but not exposed to a guest then the CPU buffers will be cleared.

That said: Virtual Machines Will Eventually Receive Vaccine

---
V2 -> V3: Rename mode.

---
 Documentation/x86/mds.rst        |   27 +++++++++++++++++++++++++++
 arch/x86/include/asm/processor.h |    1 +
 arch/x86/kernel/cpu/bugs.c       |   18 ++++++++++++------
 3 files changed, 40 insertions(+), 6 deletions(-)

...

Quoted 15 lines
arch/x86/kernel/cpu/bugs.c +3 -4
@@ -235,10 +236,9 @@ static void mds_select_mitigation(void)
 	}
 
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
-		if (boot_cpu_has(X86_FEATURE_MD_CLEAR))
-			static_branch_enable(&mds_user_clear);
-		else
-			mds_mitigation = MDS_MITIGATION_OFF;
+		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
+			mds_mitigation = MDS_MITIGATION_VMWERV;
+		static_branch_enable(&mds_user_clear);
 	}
 	pr_info("%s\n", mds_strings[mds_mitigation]);
 }

arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 706

Quoted 5 lines
arch/x86/kernel/cpu/bugs.c +1 -1
@@ -703,8 +703,14 @@ void arch_smt_update(void)
 		break;
 	}
 
-	if (mds_mitigation == MDS_MITIGATION_FULL)
+	switch(mds_mitigation) {

ERROR: space required before the open parenthesis '(' #119: FILE: arch/x86/kernel/cpu/bugs.c:706:
+ switch(mds_mitigation) {

with that addressed:

Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#52 lore raw

PATCH v6 13/14 MDS basics 13

In reply to Thomas Gleixner

Subject: [patch V6 13/14] Documentation: Move L1TF to separate directory
From: Thomas Gleixner <[email protected]>

Move L!TF to a separate directory so the MDS stuff can be added at the side. Otherwise the all hardware vulnerabilites have their own top level entry. Should have done that right away.

---
 Documentation/admin-guide/hw-vuln/index.rst |   12 
 Documentation/admin-guide/hw-vuln/l1tf.rst  |  614 ++++++++++++++++++++++++++++
 Documentation/admin-guide/index.rst         |    6 
 Documentation/admin-guide/l1tf.rst          |  614 ----------------------------
 4 files changed, 628 insertions(+), 618 deletions(-)
Documentation/admin-guide/hw-vuln/index.rst new file +12 -0
@@ -0,0 +1,12 @@
+========================
+Hardware vulnerabilities
+========================
+
+This section describes CPU vulnerabilities and provides an overview of the
+possible mitigations along with guidance for selecting mitigations if they
+are configurable at compile, boot or run time.
+
+.. toctree::
+   :maxdepth: 1
+
+   l1tf
Documentation/admin-guide/hw-vuln/l1tf.rst new file +614 -0

614 lines not on this page · raw message

Documentation/admin-guide/index.rst +2 -4
@@ -17,14 +17,12 @@ etc.
    kernel-parameters
    devices
 
-This section describes CPU vulnerabilities and provides an overview of the
-possible mitigations along with guidance for selecting mitigations if they
-are configurable at compile, boot or run time.
+This section describes CPU vulnerabilities and their mitigations.
 
 .. toctree::
    :maxdepth: 1
 
-   l1tf
+   hw-vuln/index
 
 Here is a set of documents aimed at users who are trying to track down
 problems and bugs in particular.
Documentation/admin-guide/l1tf.rst deleted +0 -614

614 lines not on this page · raw message

#53 lore raw

[MODERATED] Re: [patch V6 13/14] MDS basics 13

Quoted 9 lines · speck for Thomas Gleixner

Subject: [patch V6 13/14] Documentation: Move L1TF to separate directory
From: Thomas Gleixner <[email protected]>

Move L!TF to a separate directory so the MDS stuff can be added at the side. Otherwise the all hardware vulnerabilites have their own top level entry. Should have done that right away.

$ git grep admin-guide |grep l1tf |grep -v hw-vuln
Documentation/ABI/testing/sysfs-devices-system-cpu:		Documentation/admin-guide/l1tf.rst
Documentation/admin-guide/kernel-parameters.txt:			For details see: Documentation/admin-guide/l1tf.rst
arch/x86/kernel/cpu/bugs.c:		pr_info("Reading https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html might help you decide.\n");
arch/x86/kvm/vmx/vmx.c:#define L1TF_MSG_SMT "L1TF CPU bug present and SMT on, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html for details.\n"
arch/x86/kvm/vmx/vmx.c:#define L1TF_MSG_L1D "L1TF CPU bug present and virtualization mitigation disabled, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html for details.\n"
Signature · 1 line
Josh
#54 lore raw

Re: [patch V6 13/14] MDS basics 13

Quoted 11 lines · speck for Josh Poimboeuf
Quoted 9 lines · speck for Thomas Gleixner

Subject: [patch V6 13/14] Documentation: Move L1TF to separate directory
From: Thomas Gleixner <[email protected]>

Move L!TF to a separate directory so the MDS stuff can be added at the side. Otherwise the all hardware vulnerabilites have their own top level entry. Should have done that right away.

Quoted 7 lines
$ git grep admin-guide |grep l1tf |grep -v hw-vuln
Documentation/ABI/testing/sysfs-devices-system-cpu:		Documentation/admin-guide/l1tf.rst
Documentation/admin-guide/kernel-parameters.txt:			For details see: Documentation/admin-guide/l1tf.rst
arch/x86/kernel/cpu/bugs.c:		pr_info("Reading https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html might help you decide.\n");
arch/x86/kvm/vmx/vmx.c:#define L1TF_MSG_SMT "L1TF CPU bug present and SMT on, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html for details.\n"
arch/x86/kvm/vmx/vmx.c:#define L1TF_MSG_L1D "L1TF CPU bug present and virtualization mitigation disabled, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html for details.\n"

Ah. Indeed....

#55 lore raw

[MODERATED] Re: [patch V6 13/14] MDS basics 13

In reply to Thomas Gleixner
Quoted 4 lines · speck for Thomas Gleixner

Subject: [patch V6 13/14] Documentation: Move L1TF to separate directory
From: Thomas Gleixner <[email protected]>

Move L!TF to a separate directory so the MDS stuff can be added at the

s/L!TF/L1TF

--mark

#56 lore raw

PATCH v6 14/14 MDS basics 14

In reply to Thomas Gleixner

Subject: [patch V6 14/14] Documentation: Add MDS vulnerability documentation
From: Thomas Gleixner <[email protected]>

Add the initial MDS vulnerability documentation.

---
V5 --> V6: Fix the protection matrix, minor tweaks vs. idle mitigation
and MSBDS only systems.
V4 --> V5: Remove 'auto' option. Adjust virt mitigation info. V1 --> V4: Added the missing pieces

---
 Documentation/admin-guide/hw-vuln/index.rst |    1 
 Documentation/admin-guide/hw-vuln/l1tf.rst  |    1 
 Documentation/admin-guide/hw-vuln/mds.rst   |  307 ++++++++++++++++++++++++++++
 3 files changed, 309 insertions(+)
Documentation/admin-guide/hw-vuln/index.rst +1 -0
@@ -10,3 +10,4 @@ are configurable at compile, boot or run
    :maxdepth: 1
 
    l1tf
+   mds
Documentation/admin-guide/hw-vuln/l1tf.rst +1 -0
@@ -445,6 +445,7 @@ The default is 'cond'. If 'l1tf=full,for
 line, then 'always' is enforced and the kvm-intel.vmentry_l1d_flush
 module parameter is ignored and writes to the sysfs file are rejected.
 
+.. _mitigation_selection:
 
 Mitigation selection guide
 --------------------------
Documentation/admin-guide/hw-vuln/mds.rst new file +307 -0

307 lines not on this page · raw message

#58 lore raw

[MODERATED] Encrypted Message

In reply to Thomas Gleixner

From: Jon Masters <[email protected]>
To: speck for Thomas Gleixner <[email protected]>
Subject: Re: [patch V6 00/14] MDS basics 0

Quoted 18 lines · speck for Thomas Gleixner

Changes vs. V5:

- Fix tools/ build (Josh)

- Dropped the AIRMONT_MID change as it needs confirmation from Intel

- Made the consolidated whitelist more readable and correct

- Added the MSBDS only quirk for XEON PHI, made the idle flush depend on it and updated the sysfs output accordingly.

- Fixed the protection matrix in the admin documentation and clarified the SMT situation vs. MSBDS only.

- Updated the KVM/VMX changelog.

Delta patch against V5 below.

Quoted 8 lines

Available from git:

cvs.ou.linutronix.de:linux/speck/linux WIP.mds

The linux-4.20.y, linux-4.19.y and linux-4.14.y branches are updated as well and contain the untested backports of the pile for reference.

I'll send git bundles of the pile as well.

Tested on Coffeelake with updated ucode successfully:

processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8086K CPU @ 4.00GHz
stepping : 10
microcode : 0xae

[jcm@stephen ~]$ dmesg|grep MDS

[    1.633165] MDS: Mitigation: Clear CPU buffers

[jcm@stephen ~]$ cat /sys/devices/system/cpu/vulnerabilities/mds
Mitigation: Clear CPU buffers; SMT vulnerable

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop