Skip to contentSkip to conversation

Linux Patch 2

PATCH Superseded [email protected] 1 participant 1 message Apr 18, 2018

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/7 Linux Patch 2

mdd stands for "Memory Disambiguation Disable" and we have two knobs:

nomdd
mdd=[off,auto,userspace,boot]

(We couldn't use 'md' as that is used by multipath).

Memory Disambiguation is a feature that contemporary processors have - which is where store and load operations can run in parallel (even for the same address). Eventually when the memory is fetched with the data value will the store (and load) be fixed up and the execution operations re-run through the CPU.

Thanks to the nature of this store-load-store operations can run in parallel. The 'mdd' allows the OS to disable this optimization.

Some CPUs have a bug where a load may pass an older overlapping store (speculatively of course).

By default this feature is enabled hence the parameters are:

- auto - if possible will disable memory disambiguation at boot if CPU is vulnerable to speculation attacks using memory disambgiuation..
- boot - disable memory disambiguation at boot.
- userspace - disable memory disambiguation when entering userspace, but enable it in the kernel.
- off - do not _disable_ memory disambiguation.

And as mentioned - some CPU may have memory dismabiguation that does not lead to speculative vulnerabilities - and for those the 'auto' will pick the right choice.

---
v3:
- Wrong array was used when figuring mdd_v4= arguments
- If broken microcode found, also disable MD feature.
- s/mdd_v4/mdd/
- s/kernel/userpsace/
- Fix up the commit description

---
 Documentation/admin-guide/kernel-parameters.txt | 11 +++
 arch/x86/include/asm/cpufeatures.h              |  1 +
 arch/x86/include/asm/nospec-branch.h            |  6 ++
 arch/x86/kernel/cpu/bugs.c                      | 93 ++++++++++++++++++++++++-
 arch/x86/kernel/cpu/intel.c                     |  1 +
 5 files changed, 111 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +11 -0
index 1d1d53f85ddd..2c22ca7e90a6 100644
@@ -2173,6 +2173,15 @@
 	md=		[HW] RAID subsystems devices and level
 			See Documentation/admin-guide/md.rst.
 
+	mdd=		[X86] Control memory disambiguation disable mitigation.
+
+			auto - kernel detects whether your CPU model is
+			       vulnerable and picks the most appropiate way
+			userspace - disable memory disambiguation in userspace,
+                               and enable it in the kernel.
+			boot  - disable memory disambiguation all the time (default).
+			off  - do not control memory disambiguation (insecure)
+
 	mdacon=		[MDA]
 			Format: <first>,<last>
 			Specifies range of consoles to be captured by the MDA.
@@ -2647,6 +2656,8 @@
 			allow data leaks with this option, which is equivalent
 			to spectre_v2=off.
 
+	nomdd		[X86] Disable all mitigations for the memory disambiguation vulnerability.
+
 	noxsave		[BUGS=X86] Disables x86 extended register state save
 			and restore using xsave. The kernel will fallback to
 			enabling legacy floating-point and sse state.
arch/x86/include/asm/cpufeatures.h +1 -0
index 4393c10fcc6f..7490798a70e9 100644
@@ -333,6 +333,7 @@
 #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 */
 #define X86_FEATURE_ARCH_CAPABILITIES	(18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
+#define X86_FEATURE_MDD			(18*32+31) /* Intel Memory Disambiguation Disable. */
 
 /*
  * BUG word(s)
arch/x86/include/asm/nospec-branch.h +6 -0
index f928ad9b143f..2c098a3250eb 100644
@@ -216,6 +216,12 @@ enum spectre_v2_mitigation {
 	SPECTRE_V2_RETPOLINE_AMD,
 	SPECTRE_V2_IBRS,
 };
+/* The MD mitigation variants */
+enum md_mitigation {
+	MD_NONE,
+	MD_BOOT_ON,
+	MD_KERNEL_ON,
+};
 
 extern char __indirect_thunk_start[];
 extern char __indirect_thunk_end[];
arch/x86/kernel/cpu/bugs.c +92 -1

116 lines not on this page · raw message

arch/x86/kernel/cpu/intel.c +1 -0
index c3af167d0a70..16ee38d8977a 100644
@@ -189,6 +189,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
 		setup_clear_cpu_cap(X86_FEATURE_STIBP);
 		setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
 		setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
+		setup_clear_cpu_cap(X86_FEATURE_MDD);
 	}
 
 	/*
Signature · 1 line
2.14.3