[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] arch: move array_index_mask_nospec()



commit 9174674c3b4ad5f4a0a0401da25cb27e343b2b38
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon Mar 4 10:45:10 2024 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Mar 4 10:45:10 2024 +0100

    arch: move array_index_mask_nospec()
    
    At the time they were introduced, there were no asm/nospec.h yet, so
    they were placed in system.h. Move them to nospec.h and drop
    xen/nospec.h's including of asm/system.h; there's one unrelated #include
    that needs adding in exchange, on x86.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/arch/arm/include/asm/arm32/nospec.h | 31 +++++++++++++++++++++++++++++
 xen/arch/arm/include/asm/arm32/system.h | 18 -----------------
 xen/arch/arm/include/asm/arm64/nospec.h | 35 +++++++++++++++++++++++++++++++++
 xen/arch/arm/include/asm/arm64/system.h | 22 ---------------------
 xen/arch/arm/include/asm/nospec.h       |  8 ++++++++
 xen/arch/x86/include/asm/nospec.h       | 24 ++++++++++++++++++++++
 xen/arch/x86/include/asm/system.h       | 24 ----------------------
 xen/arch/x86/include/asm/x86_emulate.h  |  1 +
 xen/include/xen/nospec.h                |  1 -
 9 files changed, 99 insertions(+), 65 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm32/nospec.h 
b/xen/arch/arm/include/asm/arm32/nospec.h
new file mode 100644
index 0000000000..be3c7712c8
--- /dev/null
+++ b/xen/arch/arm/include/asm/arm32/nospec.h
@@ -0,0 +1,31 @@
+/* Portions taken from Linux arch arm */
+#ifndef __ASM_ARM32_NOSPEC_H
+#define __ASM_ARM32_NOSPEC_H
+
+#define CSDB    ".inst  0xe320f014"
+
+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 /* __ASM_ARM32_NOSPEC_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/include/asm/arm32/system.h 
b/xen/arch/arm/include/asm/arm32/system.h
index ab57abfbc5..c617b40438 100644
--- a/xen/arch/arm/include/asm/arm32/system.h
+++ b/xen/arch/arm/include/asm/arm32/system.h
@@ -48,24 +48,6 @@ static inline int local_fiq_is_enabled(void)
     return !(flags & PSR_FIQ_MASK);
 }
 
-#define CSDB    ".inst  0xe320f014"
-
-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
 /*
  * Local variables:
diff --git a/xen/arch/arm/include/asm/arm64/nospec.h 
b/xen/arch/arm/include/asm/arm64/nospec.h
new file mode 100644
index 0000000000..2364ca692b
--- /dev/null
+++ b/xen/arch/arm/include/asm/arm64/nospec.h
@@ -0,0 +1,35 @@
+/* Portions taken from Linux arch arm64 */
+#ifndef __ASM_ARM64_NOSPEC_H
+#define __ASM_ARM64_NOSPEC_H
+
+#define csdb()  asm volatile ( "hint #20" : : : "memory" )
+
+/*
+ * Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz
+ * and 0 otherwise.
+ */
+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, xzr, xzr\n"
+                   : "=r" (mask)
+                   : "r" (idx), "Ir" (sz)
+                   : "cc" );
+    csdb();
+
+    return mask;
+}
+#define array_index_mask_nospec array_index_mask_nospec
+
+#endif /* __ASM_ARM64_NOSPEC_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/include/asm/arm64/system.h 
b/xen/arch/arm/include/asm/arm64/system.h
index 2e36573ac6..2e2ee212a1 100644
--- a/xen/arch/arm/include/asm/arm64/system.h
+++ b/xen/arch/arm/include/asm/arm64/system.h
@@ -58,28 +58,6 @@ static inline int local_fiq_is_enabled(void)
     return !(flags & PSR_FIQ_MASK);
 }
 
-#define csdb()  asm volatile ( "hint #20" : : : "memory" )
-
-/*
- * Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz
- * and 0 otherwise.
- */
-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, xzr, xzr\n"
-                   : "=r" (mask)
-                   : "r" (idx), "Ir" (sz)
-                   : "cc" );
-    csdb();
-
-    return mask;
-}
-#define array_index_mask_nospec array_index_mask_nospec
-
 #endif
 /*
  * Local variables:
diff --git a/xen/arch/arm/include/asm/nospec.h 
b/xen/arch/arm/include/asm/nospec.h
index 51c7aea4f4..efac51fc03 100644
--- a/xen/arch/arm/include/asm/nospec.h
+++ b/xen/arch/arm/include/asm/nospec.h
@@ -4,6 +4,14 @@
 #ifndef _ASM_ARM_NOSPEC_H
 #define _ASM_ARM_NOSPEC_H
 
+#if defined(CONFIG_ARM_32)
+# include <asm/arm32/nospec.h>
+#elif defined(CONFIG_ARM_64)
+# include <asm/arm64/nospec.h>
+#else
+# error "unknown ARM variant"
+#endif
+
 static inline bool evaluate_nospec(bool condition)
 {
     return condition;
diff --git a/xen/arch/x86/include/asm/nospec.h 
b/xen/arch/x86/include/asm/nospec.h
index 7150e76b87..07606834c4 100644
--- a/xen/arch/x86/include/asm/nospec.h
+++ b/xen/arch/x86/include/asm/nospec.h
@@ -38,6 +38,30 @@ static always_inline void block_speculation(void)
     barrier_nospec_true();
 }
 
+/**
+ * array_index_mask_nospec() - generate a mask that is ~0UL when the
+ *      bounds check succeeds and 0 otherwise
+ * @index: array element index
+ * @size: number of elements in array
+ *
+ * Returns:
+ *     0 - (index < size)
+ */
+static inline unsigned long array_index_mask_nospec(unsigned long index,
+                                                    unsigned long size)
+{
+    unsigned long mask;
+
+    asm volatile ( "cmp %[size], %[index]; sbb %[mask], %[mask];"
+                   : [mask] "=r" (mask)
+                   : [size] "g" (size), [index] "r" (index) );
+
+    return mask;
+}
+
+/* Override default implementation in nospec.h. */
+#define array_index_mask_nospec array_index_mask_nospec
+
 #endif /* _ASM_X86_NOSPEC_H */
 
 /*
diff --git a/xen/arch/x86/include/asm/system.h 
b/xen/arch/x86/include/asm/system.h
index debf6bfa17..73cb16ca68 100644
--- a/xen/arch/x86/include/asm/system.h
+++ b/xen/arch/x86/include/asm/system.h
@@ -224,30 +224,6 @@ static always_inline unsigned long __xadd(
 #define smp_mb__before_atomic()    do { } while (0)
 #define smp_mb__after_atomic()     do { } while (0)
 
-/**
- * array_index_mask_nospec() - generate a mask that is ~0UL when the
- *      bounds check succeeds and 0 otherwise
- * @index: array element index
- * @size: number of elements in array
- *
- * Returns:
- *     0 - (index < size)
- */
-static inline unsigned long array_index_mask_nospec(unsigned long index,
-                                                    unsigned long size)
-{
-    unsigned long mask;
-
-    asm volatile ( "cmp %[size], %[index]; sbb %[mask], %[mask];"
-                   : [mask] "=r" (mask)
-                   : [size] "g" (size), [index] "r" (index) );
-
-    return mask;
-}
-
-/* Override default implementation in nospec.h. */
-#define array_index_mask_nospec array_index_mask_nospec
-
 #define local_irq_disable()     asm volatile ( "cli" : : : "memory" )
 #define local_irq_enable()      asm volatile ( "sti" : : : "memory" )
 
diff --git a/xen/arch/x86/include/asm/x86_emulate.h 
b/xen/arch/x86/include/asm/x86_emulate.h
index c184c0053c..2b75f7f8e2 100644
--- a/xen/arch/x86/include/asm/x86_emulate.h
+++ b/xen/arch/x86/include/asm/x86_emulate.h
@@ -15,6 +15,7 @@
 #include <xen/types.h>
 #include <xen/lib.h>
 #include <asm/regs.h>
+#include <asm/x86-defns.h>
 
 #include "../../x86_emulate/x86_emulate.h"
 
diff --git a/xen/include/xen/nospec.h b/xen/include/xen/nospec.h
index 76255bc46e..4c250ebbd6 100644
--- a/xen/include/xen/nospec.h
+++ b/xen/include/xen/nospec.h
@@ -7,7 +7,6 @@
 #ifndef XEN_NOSPEC_H
 #define XEN_NOSPEC_H
 
-#include <asm/system.h>
 #include <asm/nospec.h>
 
 /**
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.