From e4fb43902a0b2e76926b19a90c89f9be229b656a Mon Sep 17 00:00:00 2001
From: Andy Whitcroft <apw@canonical.com>
Date: Tue, 20 Feb 2018 13:53:31 +0000
Subject: [PATCH 008/131] Revert "UBUNTU: SAUCE: x86/cpu/AMD: Remove now unused
 definition of MFENCE_RDTSC feature"

CVE-2017-5753 (revert embargoed)
CVE-2017-5715 (revert embargoed)

This reverts commit 5a9fc7213b0fe87816f968ed6100a8dec0738331.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 arch/x86/include/asm/barrier.h    | 4 +++-
 arch/x86/include/asm/cpufeature.h | 2 +-
 arch/x86/um/asm/barrier.h         | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index eb5aa1cbcef1..90be66de9bb2 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -24,7 +24,8 @@
 #define wmb()	asm volatile("sfence" ::: "memory")
 #endif
 
-#define gmb() alternative("", "lfence", X86_FEATURE_LFENCE_RDTSC);
+#define gmb() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \
+				"lfence", X86_FEATURE_LFENCE_RDTSC);
 
 /**
  * read_barrier_depends - Flush all pending reads that subsequents reads
@@ -152,6 +153,7 @@ do {									\
  */
 static __always_inline void rdtsc_barrier(void)
 {
+	alternative(ASM_NOP3, "mfence", X86_FEATURE_MFENCE_RDTSC);
 	alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
 }
 
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 7e89e296b911..9717149e476d 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -88,7 +88,7 @@
 #define X86_FEATURE_SYSCALL32	(3*32+14) /* "" syscall in ia32 userspace */
 #define X86_FEATURE_SYSENTER32	(3*32+15) /* "" sysenter in ia32 userspace */
 #define X86_FEATURE_REP_GOOD	(3*32+16) /* rep microcode works well */
-
+#define X86_FEATURE_MFENCE_RDTSC (3*32+17) /* "" Mfence synchronizes RDTSC */
 #define X86_FEATURE_LFENCE_RDTSC (3*32+18) /* "" Lfence synchronizes RDTSC */
 #define X86_FEATURE_11AP	(3*32+19) /* "" Bad local APIC aka 11AP */
 #define X86_FEATURE_NOPL	(3*32+20) /* The NOPL (0F 1F) instructions */
diff --git a/arch/x86/um/asm/barrier.h b/arch/x86/um/asm/barrier.h
index 14634ffc6f0e..7d01b8c56c00 100644
--- a/arch/x86/um/asm/barrier.h
+++ b/arch/x86/um/asm/barrier.h
@@ -68,6 +68,7 @@
  */
 static inline void rdtsc_barrier(void)
 {
+	alternative(ASM_NOP3, "mfence", X86_FEATURE_MFENCE_RDTSC);
 	alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
 }
 
-- 
2.15.1

