[PATCH v3] arm64: Enable KCSAN

Joey Gouly joey.gouly at arm.com
Thu Dec 2 08:13:10 PST 2021


Hi all,

On Thu, Dec 02, 2021 at 10:33:31PM +0800, Kefeng Wang wrote:
> This patch enables KCSAN for arm64, with updates to build rules
> to not use KCSAN for several incompatible compilation units.
> 
> Resent GCC version(at least GCC10) made outline-atomics as the
> default option(unlike Clang), which will cause linker errors
> for kernel/kcsan/core.o. Disables the out-of-line atomics by
> no-outline-atomics to fix the linker errors.
> 
> Meanwhile, as Mark said[1], there is a specific issue on arm64
> about ARM64_BTI with Clang 11 if KCSAN enabled, which is fixed
> by Clang 12, add CLANG_VERSION check. And also some latent issues
> are need to be fixed which isn't just a KCSAN problem, we make
> the KCSAN depends on EXPERT for now.
> 
> Tested selftest and kcsan_test(built with GCC11 and Clang 13),
> and all passed.
> 
> [1] https://lkml.org/lkml/2021/12/1/354
> Signed-off-by: Kefeng Wang <wangkefeng.wang at huawei.com>

Confirming that I get KCSAN errors such as:

[  285.188576] ==================================================================
[  285.189514] BUG: KCSAN: data-race in el0_svc_common.constprop.0+0x84/0x14c
[  285.190599]
[  285.191092] race at unknown origin, with read to 0xffff0000e3ce3700 of 8 bytes by task 19946 on cpu 5:
[  285.192576]  el0_svc_common.constprop.0+0x84/0x14c
[  285.193601]  do_el0_svc+0x30/0x40
[  285.194457]  el0_svc+0x3c/0x70
[  285.194954]  el0t_64_sync_handler+0x9c/0x120
[  285.195618]  el0t_64_sync+0x18c/0x190
[  285.196371]
[  285.196823] value changed: 0x0000000000000008 -> 0x000000000000000a
[  285.197674]
[  285.198172] Reported by Kernel Concurrency Sanitizer on:
[  285.198941] CPU: 5 PID: 19946 Comm: stress-ng Not tainted 5.16.0-rc3+ #842 95517f70e70f029451088b9dec0b9074aa29ae52
[  285.201191] ==================================================================

This particular case is fixed by Mark's thread flag series [1], which is in linux-next now.

Tested with gcc 11 and clang 14.0 (built from git) on qemu and FVP.

Tested-by: Joey Gouly <joey.gouly at arm.com>

Thanks,
Joey

[1] https://lore.kernel.org/lkml/20211129130653.2037928-1-mark.rutland@arm.com/



More information about the linux-arm-kernel mailing list