From: Nilay Shroff <nilay@linux.ibm.com>
To: Alan Maguire <alan.maguire@oracle.com>,
kees@kernel.org, nathan@kernel.org, peterz@infradead.org,
elver@google.com
Cc: ojeda@kernel.org, akpm@linux-foundation.org, ubizjak@gmail.com,
Jason@zx2c4.com, Marc.Herbert@linux.intel.com, hca@linux.ibm.com,
hpa@zytor.com, namjain@linux.microsoft.com, paulmck@kernel.org,
linux-kernel@vger.kernel.org, andrii.nakryiko@gmail.com,
yonghong.song@linux.dev, ast@kernel.org, jolsa@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, bvanassche@acm.org,
bpf@vger.kernel.org
Subject: Re: [PATCH] kcsan, compiler_types: avoid duplicate type issues in BPF Type Format
Date: Fri, 16 Jan 2026 18:45:08 +0530 [thread overview]
Message-ID: <cf1ec6d5-21e1-43fc-a694-b9e5a6258df1@linux.ibm.com> (raw)
In-Reply-To: <20260116091730.324322-1-alan.maguire@oracle.com>
On 1/16/26 2:47 PM, 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@linux.ibm.com>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.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__
Thanks Alan for working on this! I tested this change on my system and it works well.
So with that,
Tested-by: Nilay Shroff <nilay@linux.ibm.com>
next prev parent reply other threads:[~2026-01-16 13:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-16 9:17 [PATCH] kcsan, compiler_types: avoid duplicate type issues in BPF Type Format Alan Maguire
2026-01-16 10:13 ` Marco Elver
2026-01-27 23:08 ` Marco Elver
2026-01-27 23:31 ` Andrew Morton
2026-01-28 0:02 ` Alexei Starovoitov
2026-01-28 1:04 ` Andrew Morton
2026-01-28 1:44 ` Marco Elver
2026-01-16 13:15 ` Nilay Shroff [this message]
2026-01-16 17:26 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cf1ec6d5-21e1-43fc-a694-b9e5a6258df1@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=Jason@zx2c4.com \
--cc=Marc.Herbert@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=alan.maguire@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=bvanassche@acm.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=elver@google.com \
--cc=haoluo@google.com \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=namjain@linux.microsoft.com \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=ubizjak@gmail.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox