Commit 1d4238c5 authored by Russell King's avatar Russell King
Browse files

ARM: spectre-v1: add array_index_mask_nospec() implementation

Add an implementation of the array_index_mask_nospec() function for
mitigating Spectre variant 1 throughout the kernel.
Signed-off-by: default avatarRussell King <>
Acked-by: default avatarMark Rutland <>
Boot-tested-by: default avatarTony Lindgren <>
Reviewed-by: default avatarTony Lindgren <>
parent a78d1565
......@@ -76,6 +76,25 @@ extern void arm_heavy_mb(void);
#define __smp_rmb() __smp_mb()
#define __smp_wmb() dmb(ishst)
static inline unsigned long array_index_mask_nospec(unsigned long idx,
unsigned long sz)
unsigned long mask;
asm volatile(
"cmp %1, %2\n"
" sbc %0, %1, %1\n"
: "=r" (mask)
: "r" (idx), "Ir" (sz)
: "cc");
return mask;
#define array_index_mask_nospec array_index_mask_nospec
#include <asm-generic/barrier.h>
#endif /* !__ASSEMBLY__ */
Markdown is supported
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