Skip to content

Commit 7a71fd1

Browse files
heicarstMartin Schwidefsky
authored andcommitted
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 <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 259acc5 commit 7a71fd1

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎arch/s390/include/asm/string.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static inline void *memchr(const void * s, int c, size_t n)
6262
" jl 1f\n"
6363
" la %0,0\n"
6464
"1:"
65-
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
65+
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
6666
return (void *) ret;
6767
}
6868

@@ -74,7 +74,7 @@ static inline void *memscan(void *s, int c, size_t n)
7474
asm volatile(
7575
"0: srst %0,%1\n"
7676
" jo 0b\n"
77-
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
77+
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
7878
return (void *) ret;
7979
}
8080

@@ -115,7 +115,7 @@ static inline size_t strlen(const char *s)
115115
asm volatile(
116116
"0: srst %0,%1\n"
117117
" jo 0b"
118-
: "+d" (r0), "+a" (tmp) : : "cc");
118+
: "+d" (r0), "+a" (tmp) : : "cc", "memory");
119119
return r0 - (unsigned long) s;
120120
}
121121

@@ -128,7 +128,7 @@ static inline size_t strnlen(const char * s, size_t n)
128128
asm volatile(
129129
"0: srst %0,%1\n"
130130
" jo 0b"
131-
: "+a" (end), "+a" (tmp) : "d" (r0) : "cc");
131+
: "+a" (end), "+a" (tmp) : "d" (r0) : "cc", "memory");
132132
return end - s;
133133
}
134134
#else /* IN_ARCH_STRING_C */

‎arch/s390/lib/string.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static inline char *__strend(const char *s)
2020

2121
asm volatile ("0: srst %0,%1\n"
2222
" jo 0b"
23-
: "+d" (r0), "+a" (s) : : "cc" );
23+
: "+d" (r0), "+a" (s) : : "cc", "memory");
2424
return (char *) r0;
2525
}
2626

@@ -31,7 +31,7 @@ static inline char *__strnend(const char *s, size_t n)
3131

3232
asm volatile ("0: srst %0,%1\n"
3333
" jo 0b"
34-
: "+d" (p), "+a" (s) : "d" (r0) : "cc" );
34+
: "+d" (p), "+a" (s) : "d" (r0) : "cc", "memory");
3535
return (char *) p;
3636
}
3737

@@ -213,7 +213,7 @@ int strcmp(const char *cs, const char *ct)
213213
" sr %0,%1\n"
214214
"1:"
215215
: "+d" (ret), "+d" (r0), "+a" (cs), "+a" (ct)
216-
: : "cc" );
216+
: : "cc", "memory");
217217
return ret;
218218
}
219219
EXPORT_SYMBOL(strcmp);
@@ -250,7 +250,7 @@ static inline int clcle(const char *s1, unsigned long l1,
250250
" ipm %0\n"
251251
" srl %0,28"
252252
: "=&d" (cc), "+a" (r2), "+a" (r3),
253-
"+a" (r4), "+a" (r5) : : "cc");
253+
"+a" (r4), "+a" (r5) : : "cc", "memory");
254254
return cc;
255255
}
256256

@@ -298,7 +298,7 @@ void *memchr(const void *s, int c, size_t n)
298298
" jl 1f\n"
299299
" la %0,0\n"
300300
"1:"
301-
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc" );
301+
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
302302
return (void *) ret;
303303
}
304304
EXPORT_SYMBOL(memchr);
@@ -336,7 +336,7 @@ void *memscan(void *s, int c, size_t n)
336336

337337
asm volatile ("0: srst %0,%1\n"
338338
" jo 0b\n"
339-
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc" );
339+
: "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
340340
return (void *) ret;
341341
}
342342
EXPORT_SYMBOL(memscan);

0 commit comments

Comments
 (0)