diff options
author | Russell King <rmk+kernel@armlinux.org.uk> | 2018-05-11 10:06:58 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@armlinux.org.uk> | 2018-05-31 18:27:21 -0400 |
commit | 1d4238c56f9816ce0f9c8dbe42d7f2ad81cb6613 (patch) | |
tree | 02ce63e527d19829f5f0059b1cea00897da1469a | |
parent | a78d156587931a2c3b354534aa772febf6c9e855 (diff) |
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: Russell King <rmk+kernel@armlinux.org.uk>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Boot-tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Tony Lindgren <tony@atomide.com>
-rw-r--r-- | arch/arm/include/asm/barrier.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h index 3d9c1d4b7e75..69772e742a0a 100644 --- a/arch/arm/include/asm/barrier.h +++ b/arch/arm/include/asm/barrier.h | |||
@@ -76,6 +76,25 @@ extern void arm_heavy_mb(void); | |||
76 | #define __smp_rmb() __smp_mb() | 76 | #define __smp_rmb() __smp_mb() |
77 | #define __smp_wmb() dmb(ishst) | 77 | #define __smp_wmb() dmb(ishst) |
78 | 78 | ||
79 | #ifdef CONFIG_CPU_SPECTRE | ||
80 | static inline unsigned long array_index_mask_nospec(unsigned long idx, | ||
81 | unsigned long sz) | ||
82 | { | ||
83 | unsigned long mask; | ||
84 | |||
85 | asm volatile( | ||
86 | "cmp %1, %2\n" | ||
87 | " sbc %0, %1, %1\n" | ||
88 | CSDB | ||
89 | : "=r" (mask) | ||
90 | : "r" (idx), "Ir" (sz) | ||
91 | : "cc"); | ||
92 | |||
93 | return mask; | ||
94 | } | ||
95 | #define array_index_mask_nospec array_index_mask_nospec | ||
96 | #endif | ||
97 | |||
79 | #include <asm-generic/barrier.h> | 98 | #include <asm-generic/barrier.h> |
80 | 99 | ||
81 | #endif /* !__ASSEMBLY__ */ | 100 | #endif /* !__ASSEMBLY__ */ |