arm64: define speculation barrier
James Huang [Thu, 1 Feb 2018 05:01:50 +0000 (13:01 +0800)]
The instruction sequency "dsb sy" followed by "isb" functions as
a speculation barrier, which prevents the instructions after that
from being speculatively executed.

Bug 2039126

Change-Id: I898aab771ff82b26b08214a06814d2e6e78969a7
Signed-off-by: Bo Yan <byan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1618222
Signed-off-by: James Huang <jamehuang@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1650093
(cherry picked from commit f125c60045878513902cac4a084fde9a516eb3e2)
Signed-off-by: Jeetesh Burman <jburman@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1682711
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>

arch/arm64/include/asm/barrier.h

index 9269edb..4657cf4 100644 (file)
@@ -99,6 +99,13 @@ do {                                                                 \
 #define set_mb(var, value)     do { var = value; smp_mb(); } while (0)
 #define nop()          asm volatile("nop");
 
+#define smp_mb__before_atomic()        smp_mb()
+#define smp_mb__after_atomic() smp_mb()
+
+#define speculation_barrier()                                           \
+        asm volatile(   "dsb sy\n"                                      \
+                       "isb\n" : : : "memory")
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_BARRIER_H */