From: Malte Wechter <maltewechter@gmail.com>
To: "Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>,
"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>
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Malte Wechter <maltewechter@gmail.com>
Subject: [PATCH 2/2] rust: kunit: add config to fail kunit if TAINT_WARN is set
Date: Tue, 18 Aug 2026 17:20:22 +0200 [thread overview]
Message-ID: <20260818-lockdep-kunit-v1-2-66ceb1a272e3@gmail.com> (raw)
In-Reply-To: <20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com>
Triggering a `BUG: sleeping function called from invalid context` does
not mark the unit test as failed. Add a CONFIG_RUST_TAINT_WARN_CHECK to
enable the assertion of TAINT_WARN being set during a unit test.
Signed-off-by: Malte Wechter <maltewechter@gmail.com>
---
lib/kunit/Kconfig | 11 +++++++++++
rust/macros/kunit.rs | 11 +++++++++++
2 files changed, 22 insertions(+)
diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig
index 30bac00c42ce1..4025b5b305549 100644
--- a/lib/kunit/Kconfig
+++ b/lib/kunit/Kconfig
@@ -154,5 +154,16 @@ config RUST_LOCKDEP_KUNIT_DEBUG_LOCKS
this makes it so the KUnit test does not succeed if the test assertions are
true, but a lockdep warning is triggered.
+ If unsure, say N.
+
+config RUST_KUNIT_TAINT_WARN_CHECK
+ bool "Enable extra taint assertion in KUnit tests"
+ depends on RUST
+ default n
+ help
+ Adds an extra assertion to each Rust kunit test case that asserts
+ that the kernel is not tainted. If the kernel becomes tainted with a TAINT_WARN,
+ Enabling this config marks the test as failed.
+
If unsure, say N.
endif # KUNIT
diff --git a/rust/macros/kunit.rs b/rust/macros/kunit.rs
index d1cd0349f86f0..90264ef54a3a8 100644
--- a/rust/macros/kunit.rs
+++ b/rust/macros/kunit.rs
@@ -146,6 +146,10 @@ macro_rules! assert_eq {
{
#[cfg(CONFIG_RUST_LOCKDEP_KUNIT_DEBUG_LOCKS)]
let __debug_locks_snapshot = ::kernel::bindings::debug_locks;
+ #[cfg(CONFIG_RUST_KUNIT_TAINT_WARN_CHECK)]
+ let __is_tainted_snapshot =
+ ::kernel::bindings::test_taint(::kernel::bindings::TAINT_WARN);
+
(*_test).status = ::kernel::bindings::kunit_status_KUNIT_SUCCESS;
use ::kernel::kunit::is_test_result_ok;
@@ -157,6 +161,13 @@ macro_rules! assert_eq {
::kernel::bindings::debug_locks == __debug_locks_snapshot;
assert!(__debug_locks_ok);
}
+ #[cfg(CONFIG_RUST_KUNIT_TAINT_WARN_CHECK)]
+ {
+ let __is_tainted =
+ ::kernel::bindings::test_taint(::kernel::bindings::TAINT_WARN)
+ == __is_tainted_snapshot;
+ assert!(__is_tainted);
+ }
}
}
});
--
2.51.2
next prev parent reply other threads:[~2026-08-18 15:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 15:20 [PATCH 0/2] rust: kunit: add optional assertions to catch taint and lockdep warnings Malte Wechter
2026-08-18 15:20 ` [PATCH 1/2] rust: kunit: add config to fail kunit tests if a lockdep warning is triggered Malte Wechter
2026-08-21 8:40 ` Andreas Hindborg
2026-08-18 15:20 ` Malte Wechter [this message]
2026-08-21 9:01 ` [PATCH 0/2] rust: kunit: add optional assertions to catch taint and lockdep warnings David Gow
2026-08-21 9:03 ` Miguel Ojeda
2026-08-21 10:18 ` Malte Wechter
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=20260818-lockdep-kunit-v1-2-66ceb1a272e3@gmail.com \
--to=maltewechter@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=gary@garyguo.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.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