[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH for-next v3 6/7] x86/nospec: Move array_index_mask_nospec() into nospec.h
system.h isn't an appropriate place to live, now that asm/nospec.h exists. This should arguably have been part of c/s db591d6e76e No functional change. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Wei Liu <wl@xxxxxxx> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> CC: Juergen Gross <jgross@xxxxxxxx> This is probably post-4.13 content --- xen/include/asm-x86/nospec.h | 22 ++++++++++++++++++++++ xen/include/asm-x86/system.h | 24 ------------------------ xen/include/xen/nospec.h | 3 ++- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/xen/include/asm-x86/nospec.h b/xen/include/asm-x86/nospec.h index f6eb84eee5..0039cd2713 100644 --- a/xen/include/asm-x86/nospec.h +++ b/xen/include/asm-x86/nospec.h @@ -6,6 +6,28 @@ #include <asm/alternative.h> +/** + * 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) + */ +#define array_index_mask_nospec array_index_mask_nospec +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; +} + /* Allow to insert a read memory barrier into conditionals */ static always_inline bool barrier_nospec_true(void) { diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h index 069f422f0d..9f1b296855 100644 --- a/xen/include/asm-x86/system.h +++ b/xen/include/asm-x86/system.h @@ -233,30 +233,6 @@ static always_inline unsigned long __xadd( #define set_mb(var, value) do { xchg(&var, value); } while (0) #define set_wmb(var, value) do { var = value; smp_wmb(); } 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/include/xen/nospec.h b/xen/include/xen/nospec.h index 76255bc46e..7578210f16 100644 --- a/xen/include/xen/nospec.h +++ b/xen/include/xen/nospec.h @@ -7,7 +7,8 @@ #ifndef XEN_NOSPEC_H #define XEN_NOSPEC_H -#include <asm/system.h> +#include <xen/compiler.h> + #include <asm/nospec.h> /** -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |