From: sashiko-bot@kernel.org
To: "Marco Elver" <elver@google.com>
Cc: "Alexander Potapenko" <glider@google.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
kasan-dev@googlegroups.com, "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>,
linux-kbuild@vger.kernel.org
Subject: Re: [PATCH v2 2/2] rust: kcsan: add KUnit test for data race detection
Date: Fri, 16 Oct 2026 14:57:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-174506@kernel.org> (raw)
In-Reply-To: <20261015145714.3327543-2-elver@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kunit: rust: KCSAN test stalls and spuriously fails on UP/PREEMPT_NONE
--
commit 8335c11e7a640669968685ad30c1312fe11f4a68
Author: Marco Elver <elver@google.com>
rust: kcsan: add KUnit test for data race detection
Add a minimal KUnit test that checks that KCSAN detects data races in
Rust code: two threads concurrently increment a shared counter without
synchronization, and a probe on the console tracepoint waits for the
KCSAN report.
> diff --git a/rust/kernel/Kconfig.test b/rust/kernel/Kconfig.test
> index 3bf4194f28c7c..26bcd91a48211 100644
> --- a/rust/kernel/Kconfig.test
> +++ b/rust/kernel/Kconfig.test
> @@ -104,4 +104,15 @@ config RUST_TIME_KUNIT_TEST
>
> If unsure, say N.
>
> +config RUST_KCSAN_KUNIT_TEST
> + bool "KUnit test for KCSAN instrumentation of Rust code" if !KUNIT_ALL_TESTS
> + depends on KCSAN && HAVE_KCSAN_RUSTC && TRACEPOINTS
[Severity: High]
Should the RUST_KCSAN_KUNIT_TEST configuration in rust/kernel/Kconfig.test
include a depends on SMP requirement?
The help text notes that the test requires at least 2 CPUs to reliably
observe a data race. Without an SMP dependency, the test can be built
and may spuriously fail on UP configurations.
> + default KUNIT_ALL_TESTS
> + help
> + This option enables a KUnit test checking that KCSAN detects data
> + races in Rust code. The test needs at least 2 CPUs to reliably
> + observe a data race.
> +
> + If unsure, say N.
> +
> endif
> diff --git a/rust/kernel/kcsan_test.rs b/rust/kernel/kcsan_test.rs
> new file mode 100644
> index 0000000000000..24810cf2970a0
> --- /dev/null
> +++ b/rust/kernel/kcsan_test.rs
[ ... ]
> + #[test]
> + fn data_race() -> Result {
[ ... ]
> + let worker = ctx.clone();
> + workqueue::system_unbound().try_spawn(GFP_KERNEL, move || {
> + while !worker.stop.load(Relaxed) {
> + racy_inc();
> + }
> + worker.done.complete_all();
> + })?;
> +
> + let start = Instant::<Monotonic>::now();
> + while !OBSERVED.load(Relaxed) && start.elapsed() < Delta::from_secs(10) {
> + racy_inc();
> + }
[Severity: High]
Could this loop in data_race() lead to a CPU stall or spurious test failure
on uniprocessor systems or when PREEMPT_NONE is set?
The main thread spins tightly in kernel mode for up to 10 seconds without
yielding. If the worker thread is scheduled on the same CPU, it is prevented
from executing.
After 10 seconds, the main thread exits the spin loop, sets the stop flag,
and waits for completion. The worker finally runs, sees the stop flag
immediately, and exits without performing any concurrent increments. The
assert!(OBSERVED.load(Relaxed)) assertion will then spuriously fail.
Would it make sense to yield the CPU during this loop, for example, using
cond_resched()?
> +
> + ctx.stop.store(true, Relaxed);
> + ctx.done.wait_for_completion();
> + drop(_unregister);
> +
> + assert!(OBSERVED.load(Relaxed));
> + Ok(())
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261015145714.3327543-1-elver@google.com?part=2
next prev parent reply other threads:[~2026-10-16 14:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:56 [PATCH v2 1/2] kbuild: rust: enable KCSAN support Marco Elver
2026-10-15 14:56 ` [PATCH v2 2/2] rust: kcsan: add KUnit test for data race detection Marco Elver
2026-10-16 14:57 ` sashiko-bot [this message]
2026-10-16 15:41 ` Marco Elver
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=sashiko-outbox-174506@kernel.org \
--to=sashiko-bot@kernel.org \
--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=gary@garyguo.net \
--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-kbuild@vger.kernel.org \
--cc=ljs@kernel.org \
--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=sashiko-reviews@lists.linux.dev \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.