From: Danilo Krummrich <dakr@kernel.org>
To: dakr@kernel.org, aliceryhl@google.com, airlied@gmail.com,
simona@ffwll.ch, ojeda@kernel.org, boqun@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu,
daniel.almeida@collabora.com, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev, jhubbard@nvidia.com,
apopple@nvidia.com, ecourtney@nvidia.com, lyude@redhat.com,
kherbst@redhat.com
Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org
Subject: [PATCH 2/3] rust: add kernel taint abstraction
Date: Mon, 19 Oct 2026 23:24:46 +0200 [thread overview]
Message-ID: <20261019212535.88390-3-dakr@kernel.org> (raw)
In-Reply-To: <20261019212535.88390-1-dakr@kernel.org>
Allow Rust code to taint the kernel to record conditions that may be
relevant when diagnosing subsequent kernel failures.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/bindings/bindings_helper.h | 1 +
rust/kernel/lib.rs | 1 +
rust/kernel/panic.rs | 50 +++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 rust/kernel/panic.rs
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 930e63290cdd..bc248918c99b 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -74,6 +74,7 @@
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/of_device.h>
+#include <linux/panic.h>
#include <linux/pci.h>
#include <linux/phy.h>
#include <linux/pid_namespace.h>
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index f9ef36217bb5..fd8fe9373401 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -112,6 +112,7 @@
#[cfg(CONFIG_PM_OPP)]
pub mod opp;
pub mod page;
+pub mod panic;
#[cfg(CONFIG_PCI)]
pub mod pci;
pub mod pid_namespace;
diff --git a/rust/kernel/panic.rs b/rust/kernel/panic.rs
new file mode 100644
index 000000000000..8a78591dfb8a
--- /dev/null
+++ b/rust/kernel/panic.rs
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Kernel taint tracking.
+//!
+//! C header: [`include/linux/panic.h`](srctree/include/linux/panic.h)
+//!
+//! See the [tainted-kernels documentation] for the meaning of each taint.
+//!
+//! [tainted-kernels documentation]: srctree/Documentation/admin-guide/tainted-kernels.rst
+
+/// A reason for tainting the kernel.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[repr(u32)]
+pub enum Taint {
+ /// Tainting was explicitly requested by the user.
+ User = bindings::TAINT_USER,
+}
+
+impl Taint {
+ #[inline]
+ const fn as_raw(self) -> u32 {
+ self as u32
+ }
+}
+
+/// Whether lock debugging remains reliable after a tainting event.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[repr(u32)]
+pub enum Lockdep {
+ /// Keep lock debugging enabled.
+ StillOk = bindings::lockdep_ok_LOCKDEP_STILL_OK,
+}
+
+impl Lockdep {
+ #[inline]
+ const fn as_raw(self) -> bindings::lockdep_ok {
+ self as u32
+ }
+}
+
+/// Adds a kernel taint flag.
+///
+/// Taint flags persist until reboot, even if the module that set them is unloaded.
+/// Use [`Lockdep::StillOk`] when the tainting event does not compromise lock debugging.
+/// This may panic if the kernel's `panic_on_taint` setting matches a set taint flag.
+#[inline]
+pub fn add_taint(flag: Taint, lockdep: Lockdep) {
+ // SAFETY: `Taint` and `Lockdep` restrict both arguments to valid C API values.
+ unsafe { bindings::add_taint(flag.as_raw(), lockdep.as_raw()) };
+}
--
2.56.0
next prev parent reply other threads:[~2026-10-19 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 21:24 [PATCH 0/3] drm/nova: make unstable uAPI use explicit Danilo Krummrich
2026-10-19 21:24 ` [PATCH 1/3] drm/nova: mark the uAPI header as unstable Danilo Krummrich
2026-10-19 22:08 ` Faith Ekstrand
2026-10-19 21:24 ` Danilo Krummrich [this message]
2026-10-19 21:24 ` [PATCH 3/3] drm/nova: require explicit opt-in to unstable uAPI Danilo Krummrich
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=20261019212535.88390-3-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=kherbst@redhat.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--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