Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Mon,  5 Feb 2018 10:22:58 -0800
From: Greg Kroah-Hartman <>
Cc: Greg Kroah-Hartman <>,,
	Linus Torvalds <>,
	Andi Kleen <>,
	Ingo Molnar <>,
	Dan Williams <>,
	Thomas Gleixner <>,,
	Tom Lendacky <>,
	Kees Cook <>,,
	Al Viro <>,
Subject: [PATCH 4.14 39/64] x86: Introduce barrier_nospec

4.14-stable review patch.  If anyone has any objections, please let me know.


From: Dan Williams

commit b3d7ad85b80bbc404635dca80f5b129f6242bc7a

Rename the open coded form of this instruction sequence from
rdtsc_ordered() into a generic barrier primitive, barrier_nospec().

One of the mitigations for Spectre variant1 vulnerabilities is to fence
speculative execution after successfully validating a bounds check. I.e.
force the result of a bounds check to resolve in the instruction pipeline
to ensure speculative execution honors that result before potentially
operating on out-of-bounds data.

No functional changes.

Suggested-by: Linus Torvalds <>
Suggested-by: Andi Kleen <>
Suggested-by: Ingo Molnar <>
Signed-off-by: Dan Williams <>
Signed-off-by: Thomas Gleixner <>
Cc: Tom Lendacky <>
Cc: Kees Cook <>
Cc: Al Viro <>
Signed-off-by: Greg Kroah-Hartman <>

 arch/x86/include/asm/barrier.h |    4 ++++
 arch/x86/include/asm/msr.h     |    3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)

--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -48,6 +48,10 @@ static inline unsigned long array_index_
 /* Override the default implementation from linux/nospec.h. */
 #define array_index_mask_nospec array_index_mask_nospec
+/* Prevent speculative execution past this barrier. */
+#define barrier_nospec() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \
+					   "lfence", X86_FEATURE_LFENCE_RDTSC)
 #define dma_rmb()	rmb()
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -214,8 +214,7 @@ static __always_inline unsigned long lon
 	 * that some other imaginary CPU is updating continuously with a
 	 * time stamp.
-	alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC,
-			  "lfence", X86_FEATURE_LFENCE_RDTSC);
+	barrier_nospec();
 	return rdtsc();

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.