s390: add KCSAN instrumentation to barriers and spinlocks
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 19 Apr 2022 15:40:29 +0000 (17:40 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 25 Apr 2022 11:54:16 +0000 (13:54 +0200)
test_barrier fails on s390 because of the missing KCSAN instrumentation
for several synchronization primitives.

Add it to barriers by defining __mb(), __rmb(), __wmb(), __dma_rmb()
and __dma_wmb(), and letting the common code in asm-generic/barrier.h
do the rest.

Spinlocks require instrumentation only on the unlock path; notify KCSAN
that the CPU cannot move memory accesses outside of the spin lock. In
reality it also cannot move stores inside of it, but this is not
important and can be omitted.

Reported-by: Tobias Huschle <huschle@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/barrier.h
arch/s390/include/asm/spinlock.h

index 2c057e1f32000a6d15e2c9d6317b0a66cbd36519..82de2a7c41605fca221c4d0c86553b56362c850e 100644 (file)
@@ -26,14 +26,14 @@ static __always_inline void bcr_serialize(void)
        asm volatile(__ASM_BCR_SERIALIZE : : : "memory");
 }
 
-#define mb()           bcr_serialize()
-#define rmb()          barrier()
-#define wmb()          barrier()
-#define dma_rmb()      mb()
-#define dma_wmb()      mb()
-#define __smp_mb()     mb()
-#define __smp_rmb()    rmb()
-#define __smp_wmb()    wmb()
+#define __mb()         bcr_serialize()
+#define __rmb()                barrier()
+#define __wmb()                barrier()
+#define __dma_rmb()    __mb()
+#define __dma_wmb()    __mb()
+#define __smp_mb()     __mb()
+#define __smp_rmb()    __rmb()
+#define __smp_wmb()    __wmb()
 
 #define __smp_store_release(p, v)                                      \
 do {                                                                   \
index 24a54443c8652a1512f7ea3cf5a75f6324f29fe4..10a460762e940e6ee62aa04d1c2a3ac5a0003b4f 100644 (file)
@@ -77,6 +77,7 @@ static inline int arch_spin_trylock(arch_spinlock_t *lp)
 static inline void arch_spin_unlock(arch_spinlock_t *lp)
 {
        typecheck(int, lp->lock);
+       kcsan_release();
        asm_inline volatile(
                ALTERNATIVE("", ".insn rre,0xb2fa0000,7,0", 49) /* NIAI 7 */
                "       sth     %1,%0\n"