From: Heiko Carstens Date: Tue, 13 Dec 2016 08:50:30 +0000 (+0100) Subject: s390/lib: add missing memory barriers to string inline assemblies X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7a71fd1c59dfd20fac4d14486d63d3d5ab70498a;p=linux.git s390/lib: add missing memory barriers to string inline assemblies 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 Signed-off-by: Martin Schwidefsky --- diff --git a/arch/s390/include/asm/string.h b/arch/s390/include/asm/string.h index 15a3c005c2742..e5f5c7074f2c9 100644 --- a/arch/s390/include/asm/string.h +++ b/arch/s390/include/asm/string.h @@ -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 */ diff --git a/arch/s390/lib/string.c b/arch/s390/lib/string.c index 48352bffbc929..f71d9f6559703 100644 --- a/arch/s390/lib/string.c +++ b/arch/s390/lib/string.c @@ -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);