Re: [PATCH] kcsan, compiler_types: avoid duplicate type issues in BPF Type Format

From: Yonghong Song

Date: Fri Jan 16 2026 - 12:27:06 EST




On 1/16/26 1:17 AM, Alan Maguire wrote:
Enabling KCSAN is causing a large number of duplicate types
in BTF for core kernel structs like task_struct [1].
This is due to the definition in include/linux/compiler_types.h

`#ifdef __SANITIZE_THREAD__
...
`#define __data_racy volatile
..
`#else
...
`#define __data_racy
...
`#endif

Because some objects in the kernel are compiled without
KCSAN flags (KCSAN_SANITIZE) we sometimes get the empty
__data_racy annotation for objects; as a result we get multiple
conflicting representations of the associated structs in DWARF,
and these lead to multiple instances of core kernel types in
BTF since they cannot be deduplicated due to the additional
modifier in some instances.

Moving the __data_racy definition under CONFIG_KCSAN
avoids this problem, since the volatile modifier will
be present for both KCSAN and KCSAN_SANITIZE objects
in a CONFIG_KCSAN=y kernel.

Fixes: 31f605a308e6 ("kcsan, compiler_types: Introduce __data_racy type qualifier")
Reported-by: Nilay Shroff <nilay@xxxxxxxxxxxxx>
Suggested-by: Marco Elver <elver@xxxxxxxxxx>
Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>

Tested on gcc15 and llvm22 and all works okay. Also
the patch itself makes sense, so

Acked-by: Yonghong Song <yonghong.song@xxxxxxxxx>