Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xtensa: enable KCSAN

Prefix arch-specific barrier macros with '__' to make use of instrumented
generic macros.
Prefix arch-specific bitops with 'arch_' to make use of instrumented
generic functions.
Provide stubs for 64-bit atomics when building with KCSAN.
Disable KCSAN instrumentation in arch/xtensa/boot.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Acked-by: Marco Elver <elver@google.com>

+73 -7
+1
arch/xtensa/Kconfig
··· 29 29 select HAVE_ARCH_AUDITSYSCALL 30 30 select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL 31 31 select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL 32 + select HAVE_ARCH_KCSAN 32 33 select HAVE_ARCH_SECCOMP_FILTER 33 34 select HAVE_ARCH_TRACEHOOK 34 35 select HAVE_CONTEXT_TRACKING
+1
arch/xtensa/boot/lib/Makefile
··· 16 16 endif 17 17 18 18 KASAN_SANITIZE := n 19 + KCSAN_SANITIZE := n 19 20 20 21 CFLAGS_REMOVE_inflate.o += -fstack-protector -fstack-protector-strong 21 22 CFLAGS_REMOVE_zmem.o += -fstack-protector -fstack-protector-strong
+9 -3
arch/xtensa/include/asm/barrier.h
··· 11 11 12 12 #include <asm/core.h> 13 13 14 - #define mb() ({ __asm__ __volatile__("memw" : : : "memory"); }) 15 - #define rmb() barrier() 16 - #define wmb() mb() 14 + #define __mb() ({ __asm__ __volatile__("memw" : : : "memory"); }) 15 + #define __rmb() barrier() 16 + #define __wmb() __mb() 17 + 18 + #ifdef CONFIG_SMP 19 + #define __smp_mb() __mb() 20 + #define __smp_rmb() __rmb() 21 + #define __smp_wmb() __wmb() 22 + #endif 17 23 18 24 #if XCHAL_HAVE_S32C1I 19 25 #define __smp_mb__before_atomic() barrier()
+6 -4
arch/xtensa/include/asm/bitops.h
··· 99 99 #if XCHAL_HAVE_EXCLUSIVE 100 100 101 101 #define BIT_OP(op, insn, inv) \ 102 - static inline void op##_bit(unsigned int bit, volatile unsigned long *p)\ 102 + static inline void arch_##op##_bit(unsigned int bit, volatile unsigned long *p)\ 103 103 { \ 104 104 unsigned long tmp; \ 105 105 unsigned long mask = 1UL << (bit & 31); \ ··· 119 119 120 120 #define TEST_AND_BIT_OP(op, insn, inv) \ 121 121 static inline int \ 122 - test_and_##op##_bit(unsigned int bit, volatile unsigned long *p) \ 122 + arch_test_and_##op##_bit(unsigned int bit, volatile unsigned long *p) \ 123 123 { \ 124 124 unsigned long tmp, value; \ 125 125 unsigned long mask = 1UL << (bit & 31); \ ··· 142 142 #elif XCHAL_HAVE_S32C1I 143 143 144 144 #define BIT_OP(op, insn, inv) \ 145 - static inline void op##_bit(unsigned int bit, volatile unsigned long *p)\ 145 + static inline void arch_##op##_bit(unsigned int bit, volatile unsigned long *p)\ 146 146 { \ 147 147 unsigned long tmp, value; \ 148 148 unsigned long mask = 1UL << (bit & 31); \ ··· 163 163 164 164 #define TEST_AND_BIT_OP(op, insn, inv) \ 165 165 static inline int \ 166 - test_and_##op##_bit(unsigned int bit, volatile unsigned long *p) \ 166 + arch_test_and_##op##_bit(unsigned int bit, volatile unsigned long *p) \ 167 167 { \ 168 168 unsigned long tmp, value; \ 169 169 unsigned long mask = 1UL << (bit & 31); \ ··· 204 204 #undef BIT_OPS 205 205 #undef BIT_OP 206 206 #undef TEST_AND_BIT_OP 207 + 208 + #include <asm-generic/bitops/instrumented-atomic.h> 207 209 208 210 #include <asm-generic/bitops/le.h> 209 211
+2
arch/xtensa/lib/Makefile
··· 8 8 divsi3.o udivsi3.o modsi3.o umodsi3.o mulsi3.o \ 9 9 usercopy.o strncpy_user.o strnlen_user.o 10 10 lib-$(CONFIG_PCI) += pci-auto.o 11 + lib-$(CONFIG_KCSAN) += kcsan-stubs.o 12 + KCSAN_SANITIZE_kcsan-stubs.o := n
+54
arch/xtensa/lib/kcsan-stubs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bug.h> 4 + #include <linux/types.h> 5 + 6 + void __atomic_store_8(volatile void *p, u64 v, int i) 7 + { 8 + BUG(); 9 + } 10 + 11 + u64 __atomic_load_8(const volatile void *p, int i) 12 + { 13 + BUG(); 14 + } 15 + 16 + u64 __atomic_exchange_8(volatile void *p, u64 v, int i) 17 + { 18 + BUG(); 19 + } 20 + 21 + bool __atomic_compare_exchange_8(volatile void *p1, void *p2, u64 v, bool b, int i1, int i2) 22 + { 23 + BUG(); 24 + } 25 + 26 + u64 __atomic_fetch_add_8(volatile void *p, u64 v, int i) 27 + { 28 + BUG(); 29 + } 30 + 31 + u64 __atomic_fetch_sub_8(volatile void *p, u64 v, int i) 32 + { 33 + BUG(); 34 + } 35 + 36 + u64 __atomic_fetch_and_8(volatile void *p, u64 v, int i) 37 + { 38 + BUG(); 39 + } 40 + 41 + u64 __atomic_fetch_or_8(volatile void *p, u64 v, int i) 42 + { 43 + BUG(); 44 + } 45 + 46 + u64 __atomic_fetch_xor_8(volatile void *p, u64 v, int i) 47 + { 48 + BUG(); 49 + } 50 + 51 + u64 __atomic_fetch_nand_8(volatile void *p, u64 v, int i) 52 + { 53 + BUG(); 54 + }