From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Sami Tolvanen <samitolvanen@google.com>,
Alice Ryhl <aliceryhl@google.com>, Gary Guo <gary@garyguo.net>,
Danilo Krummrich <dakr@kernel.org>,
Miguel Ojeda <ojeda@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y] rust: irq: declare cfi_encoding for irqreturn
Date: Wed, 4 Nov 2026 17:36:48 -0500 [thread overview]
Message-ID: <20261104223318.627233-1-sashal@kernel.org> (raw)
In-Reply-To: <2026110407-hydrated-decipher-a8a9@gregkh>
From: Sami Tolvanen <samitolvanen@google.com>
[ Upstream commit 01f3e6b4b1c8c1748e59ba53631ab1f5d9ad0ea4 ]
The IRQ callbacks return c_uint. C calls them through irq_handler_t,
which returns enum irqreturn. kCFI encodes enum types by name even with
integer normalization, so the type ids never match and every call fails
the CFI check.
Generate irqreturn as a newtype with a cfi_encoding, as is done for
lru_status, and return bindings::irqreturn_t from the callbacks.
Fixes: 0851d34a8cc3 ("rust: irq: add support for non-threaded IRQs and handlers")
Fixes: 135d40523244 ("rust: irq: add support for threaded IRQs and handlers")
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261019-rust-cfi-fixes-v1-1-9503472ba738@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
[ sashal: replaced bindgen's custom enum attribute option with sed post-processing to support older bindgen ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
rust/Makefile | 3 ++-
rust/bindgen_parameters | 3 +++
rust/bindings/lib.rs | 1 +
rust/kernel/irq/request.rs | 22 +++++++++++-----------
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index d4618f646b05b..3867ff14fbdec 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -367,7 +367,8 @@ quiet_cmd_bindgen = BINDGEN $@
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
- sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@
+ sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@; \
+ sed -Ei 's/^pub struct irqreturn\(/#[cfi_encoding="9irqreturn"]\n&/' $@
$(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
$(src)/bindgen_parameters FORCE
$(call if_changed_dep,bindgen)
diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters
index e13c6f9dd17b2..9e02500dc9792 100644
--- a/rust/bindgen_parameters
+++ b/rust/bindgen_parameters
@@ -23,6 +23,9 @@
# warning. We don't need to peek into it anyway.
--opaque-type spinlock
+# enums that appear in indirect function calls should specify a cfi type
+--newtype-enum irqreturn
+
# `seccomp`'s comment gets understood as a doctest
--no-doc-comments
diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs
index 8305adbdf8cbf..37f584727eba1 100644
--- a/rust/bindings/lib.rs
+++ b/rust/bindings/lib.rs
@@ -23,6 +23,7 @@
unreachable_pub,
unsafe_op_in_unsafe_fn
)]
+#![feature(cfi_encoding)]
#[allow(dead_code)]
#[allow(clippy::as_underscore)]
diff --git a/rust/kernel/irq/request.rs b/rust/kernel/irq/request.rs
index 70700f43ddd37..4f2b315856b9b 100644
--- a/rust/kernel/irq/request.rs
+++ b/rust/kernel/irq/request.rs
@@ -20,10 +20,10 @@
#[repr(u32)]
pub enum IrqReturn {
/// The interrupt was not from this device or was not handled.
- None = bindings::irqreturn_IRQ_NONE,
+ None = bindings::irqreturn::IRQ_NONE.0,
/// The interrupt was handled by this device.
- Handled = bindings::irqreturn_IRQ_HANDLED,
+ Handled = bindings::irqreturn::IRQ_HANDLED.0,
}
/// Callbacks for an IRQ handler.
@@ -275,7 +275,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(
_irq: i32,
ptr: *mut c_void,
-) -> c_uint {
+) -> bindings::irqreturn_t {
// SAFETY: `ptr` is a pointer to `RegistrationInner` set in `Registration::new`
let inner = unsafe { &*(ptr as *const RegistrationInner) };
// SAFETY: `inner.handler` is a pointer to `T` set in `Registration::new`
@@ -284,20 +284,20 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
// callback is running implies that the device has not yet been unbound.
let device = unsafe { inner.dev.as_bound() };
- T::handle(handler, device) as c_uint
+ bindings::irqreturn_t(T::handle(handler, device) as c_uint)
}
/// The value that can be returned from [`ThreadedHandler::handle`].
#[repr(u32)]
pub enum ThreadedIrqReturn {
/// The interrupt was not from this device or was not handled.
- None = bindings::irqreturn_IRQ_NONE,
+ None = bindings::irqreturn::IRQ_NONE.0,
/// The interrupt was handled by this device.
- Handled = bindings::irqreturn_IRQ_HANDLED,
+ Handled = bindings::irqreturn::IRQ_HANDLED.0,
/// The handler wants the handler thread to wake up.
- WakeThread = bindings::irqreturn_IRQ_WAKE_THREAD,
+ WakeThread = bindings::irqreturn::IRQ_WAKE_THREAD.0,
}
/// Callbacks for a threaded IRQ handler.
@@ -501,7 +501,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
_irq: i32,
ptr: *mut c_void,
-) -> c_uint {
+) -> bindings::irqreturn_t {
// SAFETY: `ptr` is a pointer to `RegistrationInner` set in `ThreadedRegistration::new`
let inner = unsafe { &*(ptr as *const RegistrationInner) };
// SAFETY: `inner.handler` is a pointer to `T` set in `ThreadedRegistration::new`
@@ -510,7 +510,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
// callback is running implies that the device has not yet been unbound.
let device = unsafe { inner.dev.as_bound() };
- T::handle(handler, device) as c_uint
+ bindings::irqreturn_t(T::handle(handler, device) as c_uint)
}
/// # Safety
@@ -519,7 +519,7 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
_irq: i32,
ptr: *mut c_void,
-) -> c_uint {
+) -> bindings::irqreturn_t {
// SAFETY: `ptr` is a pointer to `RegistrationInner` set in `ThreadedRegistration::new`
let inner = unsafe { &*(ptr as *const RegistrationInner) };
// SAFETY: `inner.handler` is a pointer to `T` set in `ThreadedRegistration::new`
@@ -528,5 +528,5 @@ pub fn synchronize(&self, dev: &Device<Bound>) -> Result {
// callback is running implies that the device has not yet been unbound.
let device = unsafe { inner.dev.as_bound() };
- T::handle_threaded(handler, device) as c_uint
+ bindings::irqreturn_t(T::handle_threaded(handler, device) as c_uint)
}
--
2.53.0
next prev parent reply other threads:[~2026-11-04 22:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 14:14 FAILED: patch "[PATCH] rust: irq: declare cfi_encoding for irqreturn" failed to apply to 6.18-stable tree gregkh
2026-11-04 22:36 ` Sasha Levin [this message]
2026-11-06 10:46 ` [PATCH 6.18.y] rust: irq: declare cfi_encoding for irqreturn Miguel Ojeda
2026-11-06 14:47 ` [PATCH 6.18.y 1/2] rust: hrtimer: declare cfi_encoding for hrtimer_restart Miguel Ojeda
2026-11-06 14:47 ` [PATCH 6.18.y 2/2] rust: dma: declare cfi_encoding for dma_data_direction Miguel Ojeda
2026-11-06 16:35 ` [PATCH 6.18.y 1/2] rust: hrtimer: declare cfi_encoding for hrtimer_restart Sasha Levin
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=20261104223318.627233-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=aliceryhl@google.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=samitolvanen@google.com \
--cc=stable@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 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.