]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - arch/x86/include/asm/nospec-branch.h
x86/speculation/mds: Add mds_clear_cpu_buffers()
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / include / asm / nospec-branch.h
index 13a29b270cc075f23dc8100a65e249d76405a45f..8b17d67277c635460e99707403ee3e35034e4f04 100644 (file)
@@ -318,6 +318,31 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_stibp);
 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__ */
 
 /*