]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
s390/lib: add missing memory barriers to string inline assemblies
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Tue, 13 Dec 2016 08:50:30 +0000 (09:50 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 14 Dec 2016 15:33:41 +0000 (16:33 +0100)
We have a couple of inline assemblies like memchr() and strlen() that
read from memory, but tell the compiler only they need the addresses
of the strings they access.
This allows the compiler to omit the initialization of such strings
and therefore generate broken code. Add the missing memory barrier to
all string related inline assemblies to fix this potential issue. It
looks like the compiler currently does not generate broken code due to
these bugs.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/include/asm/string.h
arch/s390/lib/string.c

index 15a3c005c2742f98b717806bbd9c7a568e8b1c1a..e5f5c7074f2c96f7c54ff1fe2b3b4cbe422c8a8d 100644 (file)
@@ -62,7 +62,7 @@ static inline void *memchr(const void * s, int c, size_t n)
                "       jl      1f\n"
                "       la      %0,0\n"
                "1:"
-               : "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
+               : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
        return (void *) ret;
 }
 
@@ -74,7 +74,7 @@ static inline void *memscan(void *s, int c, size_t n)
        asm volatile(
                "0:     srst    %0,%1\n"
                "       jo      0b\n"
-               : "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
+               : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
        return (void *) ret;
 }
 
@@ -115,7 +115,7 @@ static inline size_t strlen(const char *s)
        asm volatile(
                "0:     srst    %0,%1\n"
                "       jo      0b"
-               : "+d" (r0), "+a" (tmp) :  : "cc");
+               : "+d" (r0), "+a" (tmp) :  : "cc", "memory");
        return r0 - (unsigned long) s;
 }
 
@@ -128,7 +128,7 @@ static inline size_t strnlen(const char * s, size_t n)
        asm volatile(
                "0:     srst    %0,%1\n"
                "       jo      0b"
-               : "+a" (end), "+a" (tmp) : "d" (r0)  : "cc");
+               : "+a" (end), "+a" (tmp) : "d" (r0)  : "cc", "memory");
        return end - s;
 }
 #else /* IN_ARCH_STRING_C */
index 48352bffbc929cdc43cec471e92cc49bb23996fc..f71d9f655970398dad205fb23ab2ff331850fe71 100644 (file)
@@ -20,7 +20,7 @@ static inline char *__strend(const char *s)
 
        asm volatile ("0: srst  %0,%1\n"
                      "   jo    0b"
-                     : "+d" (r0), "+a" (s) :  : "cc" );
+                     : "+d" (r0), "+a" (s) :  : "cc", "memory");
        return (char *) r0;
 }
 
@@ -31,7 +31,7 @@ static inline char *__strnend(const char *s, size_t n)
 
        asm volatile ("0: srst  %0,%1\n"
                      "   jo    0b"
-                     : "+d" (p), "+a" (s) : "d" (r0) : "cc" );
+                     : "+d" (p), "+a" (s) : "d" (r0) : "cc", "memory");
        return (char *) p;
 }
 
@@ -213,7 +213,7 @@ int strcmp(const char *cs, const char *ct)
                      "   sr   %0,%1\n"
                      "1:"
                      : "+d" (ret), "+d" (r0), "+a" (cs), "+a" (ct)
-                     : : "cc" );
+                     : : "cc", "memory");
        return ret;
 }
 EXPORT_SYMBOL(strcmp);
@@ -250,7 +250,7 @@ static inline int clcle(const char *s1, unsigned long l1,
                      "   ipm   %0\n"
                      "   srl   %0,28"
                      : "=&d" (cc), "+a" (r2), "+a" (r3),
-                       "+a" (r4), "+a" (r5) : : "cc");
+                       "+a" (r4), "+a" (r5) : : "cc", "memory");
        return cc;
 }
 
@@ -298,7 +298,7 @@ void *memchr(const void *s, int c, size_t n)
                      "   jl    1f\n"
                      "   la    %0,0\n"
                      "1:"
-                     : "+a" (ret), "+&a" (s) : "d" (r0) : "cc" );
+                     : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
        return (void *) ret;
 }
 EXPORT_SYMBOL(memchr);
@@ -336,7 +336,7 @@ void *memscan(void *s, int c, size_t n)
 
        asm volatile ("0: srst  %0,%1\n"
                      "   jo    0b\n"
-                     : "+a" (ret), "+&a" (s) : "d" (r0) : "cc" );
+                     : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
        return (void *) ret;
 }
 EXPORT_SYMBOL(memscan);