summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2018-11-07 11:43:55 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-23 08:20:39 +0100
commit8a4ae2876f6c03e3def6fb1d438cc5f01932cdc1 (patch)
tree62470f82a3056457cbd025a44c73f2a04351360f /arch
parentabdeed7e61be1b3a92c7dc02762b36f49d14d7fa (diff)
downloadlinux-stable-8a4ae2876f6c03e3def6fb1d438cc5f01932cdc1.tar.gz
linux-stable-8a4ae2876f6c03e3def6fb1d438cc5f01932cdc1.tar.bz2
linux-stable-8a4ae2876f6c03e3def6fb1d438cc5f01932cdc1.zip
ARM: spectre-v1: add array_index_mask_nospec() implementation
Commit 1d4238c56f9816ce0f9c8dbe42d7f2ad81cb6613 upstream. 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> Signed-off-by: David A. Long <dave.long@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch')
-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 6f00dac6ad8e..513e03d138ea 100644
--- a/arch/arm/include/asm/barrier.h
+++ b/arch/arm/include/asm/barrier.h
@@ -75,6 +75,25 @@ extern void arm_heavy_mb(void);
#define __smp_rmb() __smp_mb()
#define __smp_wmb() dmb(ishst)
+#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
+
#include <asm-generic/barrier.h>
#endif /* !__ASSEMBLY__ */