Commit b3d7ad85 authored by Dan Williams's avatar Dan Williams Committed by Thomas Gleixner
Browse files

x86: Introduce barrier_nospec

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: default avatarLinus Torvalds <>
Suggested-by: default avatarAndi Kleen <>
Suggested-by: default avatarIngo Molnar <>
Signed-off-by: default avatarDan Williams <>
Signed-off-by: default avatarThomas Gleixner <>
Cc: Tom Lendacky <>
Cc: Kees Cook <>
Cc: Al Viro <>
parent babdde26
......@@ -48,6 +48,10 @@ static inline unsigned long array_index_mask_nospec(unsigned long 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, \
#define dma_rmb() rmb()
......@@ -214,8 +214,7 @@ static __always_inline unsigned long long rdtsc_ordered(void)
* that some other imaginary CPU is updating continuously with a
* time stamp.
alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC,
return rdtsc();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment