From: "Gary Guo" <gary@garyguo.net>
To: "Marco Elver" <elver@google.com>
Cc: "Alexander Potapenko" <glider@google.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
"Dmitry Vyukov" <dvyukov@google.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nsc@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
"Asahi Lina" <lina+kernel@asahilina.net>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Yury Norov" <ynorov@nvidia.com>,
"David Gow" <david@davidgow.net>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Alvin Sun" <alvin.sun@linux.dev>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Petr Mladek" <pmladek@suse.com>,
workflows@vger.kernel.org, linux-doc@vger.kernel.org,
rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH v2 1/2] kbuild: rust: enable KCSAN support
Date: Mon, 19 Oct 2026 16:26:47 +0100 [thread overview]
Message-ID: <DM8X51YCN6AA.1HV7J3R3PIYY9@garyguo.net> (raw)
In-Reply-To: <20261015145714.3327543-1-elver@google.com>
On Thu Oct 15, 2026 at 3:56 PM BST, Marco Elver wrote:
> Rust supports ThreadSanitizer instrumentation via LLVM, which is what
> KCSAN relies on; however, Rust code is not currently instrumented.
>
> Pass -Zsanitizer=thread and the same TSan backend options used for C
> code to rustc. Wire up KCSAN_SANITIZE in scripts/Makefile.lib for parity
> with C (though rustc currently rejects linking crates with mismatched
> instrumentation).
>
> rustc only accepts -Zsanitizer=thread for targets that declare support
> for it. Of the targets used by the kernel, this is only possible for the
> generated x86_64 target specification, so restrict instrumentation of
> Rust code to x86_64 for now via HAVE_KCSAN_RUSTC. On other architectures
> Rust code remains uninstrumented as before.
>
> All TSan options used are supported by the LLVM versions of the minimum
> supported rustc, so no rustc-option checks are needed (they would also
> fail, because x86_64-unknown-none used for option checks does not
> support -Zsanitizer=thread).
>
> Unlike Clang and GCC, an equivalent to -fno-optimize-sibling-calls is
> omitted for Rust because rustc provides no corresponding option. While
> disabling tail-call optimizations helps preserve complete stacks traces
> in reports, it is optional and not required for KCSAN to function.
>
> With this enabled we can detect data races in kernel Rust code and
> between Rust and C code.
>
> Acked-by: Miguel Ojeda <ojeda@kernel.org>
> Acked-by: Boqun Feng <boqun@kernel.org>
> Signed-off-by: Marco Elver <elver@google.com>
Acked-by: Gary Guo <gary@garyguo.net>
> ---
> v2:
> * Add note on -fno-optimize-sibling-calls to commit message.
> ---
> Documentation/dev-tools/kcsan.rst | 7 +++++++
> lib/Kconfig.kcsan | 7 +++++++
> scripts/Makefile.kcsan | 13 +++++++++++++
> scripts/Makefile.lib | 3 +++
> scripts/generate_rust_target.rs | 2 +-
> 5 files changed, 31 insertions(+), 1 deletion(-)
next prev parent reply other threads:[~2026-10-19 15:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:56 Marco Elver
2026-10-15 14:56 ` [PATCH v2 2/2] rust: kcsan: add KUnit test for data race detection Marco Elver
2026-10-19 15:26 ` Gary Guo [this message]
2026-10-19 21:58 ` [PATCH v2 1/2] kbuild: rust: enable KCSAN support Marco Elver
2026-10-20 10:26 ` Miguel Ojeda
2026-10-20 10:34 ` Marco Elver
2026-10-20 17:09 ` Miguel Ojeda
2026-10-20 18:21 ` Marco Elver
2026-10-20 19:09 ` Miguel Ojeda
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=DM8X51YCN6AA.1HV7J3R3PIYY9@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=alvin.sun@linux.dev \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=boqun@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=joelagnelf@nvidia.com \
--cc=jpoimboe@kernel.org \
--cc=justinstitt@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=lina+kernel@asahilina.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=llvm@lists.linux.dev \
--cc=lossin@kernel.org \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=pmladek@suse.com \
--cc=rdunlap@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=workflows@vger.kernel.org \
--cc=ynorov@nvidia.com \
/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
all inboxes | Powered by JetHome®