aboutsummaryrefslogtreecommitdiff
path: root/arch/arm
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2018-05-11 15:06:58 +0100
committerMoyster <oysterized@gmail.com>2019-05-03 18:15:52 +0200
commit8df7a210bdcb08abfc8fa35e5c8811a28671f9e8 (patch)
treeb2cc1b299155fcfbe6996043a6d10d4696513111 /arch/arm
parentc31a09121e04a757cf4b20efda49187cdd137a6f (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. Change-Id: I66d16e24b4725df0bf70f53c91a34be9f26fba98 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>
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/include/asm/barrier.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
index aaa76b4da..c01e88893 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -92,5 +92,24 @@ do { \
#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
+#ifdef CONFIG_CPU_SPECTRE
+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"
+ CSDB
+ : "=r" (mask)
+ : "r" (idx), "Ir" (sz)
+ : "cc");
+
+ return mask;
+}
+#define array_index_mask_nospec array_index_mask_nospec
+#endif
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_BARRIER_H */