]> git.hungrycats.org Git - linux/commitdiff
s390: add optimized array_index_mask_nospec
authorMartin Schwidefsky <schwidefsky@de.ibm.com>
Fri, 27 Apr 2018 05:36:49 +0000 (07:36 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 29 Apr 2018 05:50:02 +0000 (07:50 +0200)
[ Upstream commit e2dd833389cc4069a96b57bdd24227b5f52288f5 ]

Add an optimized version of the array_index_mask_nospec function for
s390 based on a compare and a subtract with borrow.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/s390/include/asm/barrier.h

index d68e11e0df5eada7e600f58529e8cbe60fab41c7..e903b28e735834d10b9716f4a83f4a4dc8493eac 100644 (file)
@@ -53,4 +53,28 @@ do {                                                                 \
        ___p1;                                                          \
 })
 
+/**
+ * array_index_mask_nospec - generate a mask for array_idx() that is
+ * ~0UL when the bounds check succeeds and 0 otherwise
+ * @index: array element index
+ * @size: number of elements in array
+ */
+#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;
+
+       if (__builtin_constant_p(size) && size > 0) {
+               asm("   clgr    %2,%1\n"
+                   "   slbgr   %0,%0\n"
+                   :"=d" (mask) : "d" (size-1), "d" (index) :"cc");
+               return mask;
+       }
+       asm("   clgr    %1,%2\n"
+           "   slbgr   %0,%0\n"
+           :"=d" (mask) : "d" (size), "d" (index) :"cc");
+       return ~mask;
+}
+
 #endif /* __ASM_BARRIER_H */