[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANpmjNM=w46BDuLsvAW6oM7JbPvrhN1ddaEUNSvsfZVU-514cQ@mail.gmail.com>
Date: Fri, 16 Jan 2026 11:13:32 +0100
From: Marco Elver <elver@...gle.com>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: kees@...nel.org, nathan@...nel.org, peterz@...radead.org, ojeda@...nel.org,
akpm@...ux-foundation.org, ubizjak@...il.com, Jason@...c4.com,
Marc.Herbert@...ux.intel.com, hca@...ux.ibm.com, hpa@...or.com,
namjain@...ux.microsoft.com, paulmck@...nel.org, linux-kernel@...r.kernel.org,
andrii.nakryiko@...il.com, yonghong.song@...ux.dev, ast@...nel.org,
jolsa@...nel.org, daniel@...earbox.net, martin.lau@...ux.dev,
eddyz87@...il.com, song@...nel.org, john.fastabend@...il.com,
kpsingh@...nel.org, sdf@...ichev.me, haoluo@...gle.com, bvanassche@....org,
nilay@...ux.ibm.com, bpf@...r.kernel.org
Subject: Re: [PATCH] kcsan, compiler_types: avoid duplicate type issues in BPF
Type Format
On Fri, 16 Jan 2026 at 10:17, Alan Maguire <alan.maguire@...cle.com> 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.
"KCSAN and KCSAN_SANITIZE objects" doesn't make sense.
"KCSAN_SANITIZE.. := n" objects?
Or just "instrumented and uninstrumented source files".
Anyway, I know what you mean, but others might not. :-)
> Fixes: 31f605a308e6 ("kcsan, compiler_types: Introduce __data_racy type qualifier")
> Reported-by: Nilay Shroff <nilay@...ux.ibm.com>
> Suggested-by: Marco Elver <elver@...gle.com>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
Reviewed-by: Marco Elver <elver@...gle.com>
> ---
> include/linux/compiler_types.h | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index d3318a3c2577..86111a189a87 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -303,6 +303,22 @@ struct ftrace_likely_data {
> # define __no_kasan_or_inline __always_inline
> #endif
>
> +#ifdef CONFIG_KCSAN
> +/*
> + * Type qualifier to mark variables where all data-racy accesses should be
> + * ignored by KCSAN. Note, the implementation simply marks these variables as
> + * volatile, since KCSAN will treat such accesses as "marked".
> + *
> + * Defined here because defining __data_racy as volatile for KCSAN objects only
> + * causes problems in BPF Type Format (BTF) generation since struct members
> + * of core kernel data structs will be volatile in some objects and not in
> + * others. Instead define it globally for KCSAN kernels.
> + */
> +# define __data_racy volatile
> +#else
> +# define __data_racy
> +#endif
> +
> #ifdef __SANITIZE_THREAD__
> /*
> * Clang still emits instrumentation for __tsan_func_{entry,exit}() and builtin
> @@ -314,16 +330,9 @@ struct ftrace_likely_data {
> * disable all instrumentation. See Kconfig.kcsan where this is mandatory.
> */
> # define __no_kcsan __no_sanitize_thread __disable_sanitizer_instrumentation
> -/*
> - * Type qualifier to mark variables where all data-racy accesses should be
> - * ignored by KCSAN. Note, the implementation simply marks these variables as
> - * volatile, since KCSAN will treat such accesses as "marked".
> - */
> -# define __data_racy volatile
> # define __no_sanitize_or_inline __no_kcsan notrace __maybe_unused
> #else
> # define __no_kcsan
> -# define __data_racy
> #endif
>
> #ifdef __SANITIZE_MEMORY__
> --
> 2.39.3
>
Powered by blists - more mailing lists