Rust for Linux List
 help / color / mirror / Atom feed
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>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	 linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	 workflows@vger.kernel.org, linux-doc@vger.kernel.org,
	 Malte Wechter <maltewechter@gmail.com>
Subject: [PATCH v3 0/4] kunit: add optional assertions to catch taint and lockdep warnings
Date: Tue, 13 Oct 2026 12:22:20 +0200	[thread overview]
Message-ID: <20261013-lockdep-kunit-v3-0-cdb8ff720c1f@gmail.com> (raw)

This series extends KUnit to use existing kernel diagnostics to catch
certain locking-related bugs. Specifically, it adds assertions for
`debug_locks` from lockdep and the `TAINT_WARN` flag from panic. This
aims to catch bugs such as circular locking dependencies and sleeping
functions called from invalid context, by highlighting them when they
are triggered by a KUnit test.

Add CONFIG_KUNIT_FAIL_TEST_ON_WARN and CONFIG_KUNIT_FAIL_TEST_ON_LOCKDEP,
which enable the `TAINT_WARN` and `debug_locks` assertions respectively.
The assertions are run in two places:

    1. Before a test case is run: this ensures that no tests are run if
       the kernel is tainted and/or `debug_locks` has been turned off.

    2. After each test case: this checks whether `debug_locks` has been
       turned off or `TAINT_WARN` has been set between the start and the
       end of the test.

It is important to note that if assertion 1 fails, something other than
the KUnit test case turned off `debug_locks` or tainted the kernel. This
is not investigated further, but the kernel is treated as 'unreliable',
and all subsequent test cases are forcefully skipped.
For assertion 2, there is no guarantee that it was the thread
executing the test case that made the kernel 'unreliable'. This is not
investigated further either, but as with assertion 1, all subsequent
test cases are forcefully skipped and the KUnit log is shown.

Tests that trigger a `WARN()` on purpose are expected to use the warning
suppression added in commit 85347718ab0d ("bug/kunit: Core support for
suppressing warning backtraces"). Suppressed warnings do not taint the
kernel, so with `CONFIG_KUNIT_FAIL_TEST_ON_WARN` only unexpected
warnings fail a test. Running all KUnit tests with
`CONFIG_KUNIT_FAIL_TEST_ON_WARN` enabled currently fails `Log base 2 of
0` in `intlog2_test`, because it deliberately triggers a `WARN()`
without suppressing it, which force-skips all subsequent tests. Running
all tests with `CONFIG_KUNIT_FAIL_TEST_ON_LOCKDEP` enabled does not
change any existing test results.

The new options depend only on `CONFIG_KUNIT` (and `CONFIG_LOCKDEP` for
CONFIG_KUNIT_FAIL_TEST_ON_LOCKDEP) and can be enabled independently.

Signed-off-by: Malte Wechter <maltewechter@gmail.com>
---
Changes in v3:
- rebase onto v7.3-rc6
- add forced_skip logic to kunit, enabling marking tests as forcefully skipped
- split CONFIG_KUNIT_EXTRA_ASSERTS into two sepperate configs.
- extend kunit_parser.py and kunit_printer.py to handle forcefully skipped test cases
- make forcefully skipped tests be marked as failed in kunit_json
- add new section to kunit documention at Documentation/dev-tools/kunit/failing_on_warnings.rst
- Link to v2: https://patch.msgid.link/20260824-lockdep-kunit-v2-0-36a6fec9f72e@gmail.com

Changes in v2:
- Implement changes directly in C KUnit instead of Rust KUnit wrapper
- Remove rust specific configs and add general CONFIG_KUNIT_EXTRA_ASSERTS config
- Link to v1: https://patch.msgid.link/20260818-lockdep-kunit-v1-0-66ceb1a272e3@gmail.com

---
Malte Wechter (4):
      kunit: add logic for tracking forcefully skipped test cases/suites
      kunit: add assertions for lockdep inside of kunit
      kunit: add assertions for TAINT_WARN inside of kunit
      Documentation: kunit: add documentation and examples to kunit documentation

 .../dev-tools/kunit/failing_on_warnings.rst        |  78 ++++++++++++
 Documentation/dev-tools/kunit/index.rst            |   1 +
 include/kunit/test.h                               |   4 +
 lib/kunit/Kconfig                                  |  23 ++++
 lib/kunit/test.c                                   | 135 ++++++++++++++++++---
 rust/kernel/kunit.rs                               |   1 +
 tools/testing/kunit/kunit_json.py                  |   2 +
 tools/testing/kunit/kunit_parser.py                |  36 +++++-
 tools/testing/kunit/kunit_printer.py               |   3 +
 9 files changed, 258 insertions(+), 25 deletions(-)
---
base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
change-id: 20260812-lockdep-kunit-9628f4bcad90

Best regards,
--  
Malte Wechter <maltewechter@gmail.com>


             reply	other threads:[~2026-10-13 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 10:22 Malte Wechter [this message]
2026-10-13 10:22 ` [PATCH v3 1/4] kunit: add logic for tracking forcefully skipped test cases/suites Malte Wechter
2026-10-13 10:22 ` [PATCH v3 2/4] kunit: add assertions for lockdep inside of kunit Malte Wechter
2026-10-13 10:22 ` [PATCH v3 3/4] kunit: add assertions for TAINT_WARN " Malte Wechter
2026-10-13 10:22 ` [PATCH v3 4/4] Documentation: kunit: add documentation and examples to kunit documentation 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=20261013-lockdep-kunit-v3-0-cdb8ff720c1f@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=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=david@davidgow.net \
    --cc=gary@garyguo.net \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-doc@vger.kernel.org \
    --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=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 \
    /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