Merge tag 'rust-fixes-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux

Pull Rust fixes from Miguel Ojeda:
 "Toolchain and infrastructure:

   - Fix 'objtool' warnings for the upcoming Rust 1.101.0 (expected
     2026-12-24) by adding one more 'noreturn' function

  'kernel' crate:

   - Fix KCFI failures on every call from C to Rust IRQ handlers and
     'hrtimer' callbacks by giving the C enum bindings the correct
     'cfi_encoding'. Also prevent the same issue for DMA callbacks
     taking 'dma_data_direction'

   - 'workqueue' module: fix a runtime warning when queueing work on the
     deprecated 'system_wq' by switching to 'system_{percpu,dfl}_wq'"

* tag 'rust-fixes-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux:
  rust: dma: declare cfi_encoding for dma_data_direction
  rust: hrtimer: declare cfi_encoding for hrtimer_restart
  rust: irq: declare cfi_encoding for irqreturn
  objtool/rust: add one more `noreturn` Rust function for Rust 1.101.0
  rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq
This commit is contained in:
Linus Torvalds
2026-10-29 09:40:12 -10:00
11 changed files with 71 additions and 55 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ operator are also supported as usual, e.g.:
/// ```
/// # use kernel::{spawn_work_item, workqueue};
/// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?;
/// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?;
/// # Ok::<(), Error>(())
/// ```
@@ -93,7 +93,7 @@ KUnit 测试即文档测试
/// ```
/// # use kernel::{spawn_work_item, workqueue};
/// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?;
/// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?;
/// # Ok::<(), Error>(())
/// ```
+2 -2
View File
@@ -1731,7 +1731,7 @@ impl Process {
if should_schedule {
// Ignore failures to schedule to the workqueue. Those just mean that we're already
// scheduled for execution.
let _ = workqueue::system().enqueue(this);
let _ = workqueue::system_percpu().enqueue(this);
}
drop(binderfs_file);
@@ -1748,7 +1748,7 @@ impl Process {
if should_schedule {
// Ignore failures to schedule to the workqueue. Those just mean that we're already
// scheduled for execution.
let _ = workqueue::system().enqueue(Arc::from(this));
let _ = workqueue::system_percpu().enqueue(Arc::from(this));
}
Ok(())
}
+6
View File
@@ -29,6 +29,12 @@
# enums that appear in indirect function calls should specify a cfi type
--newtype-enum fwctl_rpc_scope
--with-attribute-custom-enum=fwctl_rpc_scope='#[cfi_encoding="15fwctl_rpc_scope"]'
--newtype-enum dma_data_direction
--with-attribute-custom-enum=dma_data_direction='#[cfi_encoding="18dma_data_direction"]'
--newtype-enum hrtimer_restart
--with-attribute-custom-enum=hrtimer_restart='#[cfi_encoding="15hrtimer_restart"]'
--newtype-enum irqreturn
--with-attribute-custom-enum=irqreturn='#[cfi_encoding="9irqreturn"]'
--newtype-enum lru_status
--with-attribute-custom-enum=lru_status='#[cfi_encoding="10lru_status"]'
+11 -10
View File
@@ -309,25 +309,25 @@ pub enum DataDirection {
///
/// This is used when the buffer can be both read from and written to by the device.
/// The cache for the corresponding memory region is both flushed and invalidated.
Bidirectional = Self::const_cast(bindings::dma_data_direction_DMA_BIDIRECTIONAL),
Bidirectional = Self::const_cast(bindings::dma_data_direction::DMA_BIDIRECTIONAL),
/// The DMA mapping is for data transfer from memory to the device (write).
///
/// The CPU has prepared data in the buffer, and the device will read it.
/// The cache for the corresponding memory region is flushed before device access.
ToDevice = Self::const_cast(bindings::dma_data_direction_DMA_TO_DEVICE),
ToDevice = Self::const_cast(bindings::dma_data_direction::DMA_TO_DEVICE),
/// The DMA mapping is for data transfer from the device to memory (read).
///
/// The device will write data into the buffer for the CPU to read.
/// The cache for the corresponding memory region is invalidated before CPU access.
FromDevice = Self::const_cast(bindings::dma_data_direction_DMA_FROM_DEVICE),
FromDevice = Self::const_cast(bindings::dma_data_direction::DMA_FROM_DEVICE),
/// The DMA mapping is not for data transfer.
///
/// This is primarily for debugging purposes. With this direction, the DMA mapping API
/// will not perform any cache coherency operations.
None = Self::const_cast(bindings::dma_data_direction_DMA_NONE),
None = Self::const_cast(bindings::dma_data_direction::DMA_NONE),
}
impl DataDirection {
@@ -339,7 +339,7 @@ impl DataDirection {
// CAST: The C standard allows compilers to choose different integer types for enums.
// To safely check the value, we cast it to a wide signed integer type (`i128`)
// which can hold any standard C integer enum type without truncation.
let wide_val = val as i128;
let wide_val = val.0 as i128;
// Check if the value is outside the valid range for the target type `u32`.
// CAST: `u32::MAX` is cast to `i128` to match the type of `wide_val` for the comparison.
@@ -357,11 +357,12 @@ impl DataDirection {
impl From<DataDirection> for bindings::dma_data_direction {
/// Returns the raw representation of [`enum dma_data_direction`].
fn from(direction: DataDirection) -> Self {
// CAST: `direction as u32` gets the underlying representation of our `#[repr(u32)]` enum.
// The subsequent cast to `Self` (the bindgen type) assumes the C enum is compatible
// with the enum variants of `DataDirection`, which is a valid assumption given our
// compile-time checks.
direction as u32 as Self
match direction {
DataDirection::Bidirectional => Self::DMA_BIDIRECTIONAL,
DataDirection::ToDevice => Self::DMA_TO_DEVICE,
DataDirection::FromDevice => Self::DMA_FROM_DEVICE,
DataDirection::None => Self::DMA_NONE,
}
}
}
+17 -11
View File
@@ -25,10 +25,10 @@ use crate::{
#[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.
@@ -240,25 +240,28 @@ impl<T: Handler> PinnedDrop for Registration<'_, T> {
/// # Safety
///
/// This function should be only used as the callback in `request_irq`.
unsafe extern "C" fn handle_irq_callback<T: Handler>(_irq: i32, ptr: *mut c_void) -> c_uint {
unsafe extern "C" fn handle_irq_callback<T: Handler>(
_irq: i32,
ptr: *mut c_void,
) -> bindings::irqreturn_t {
let ptr = ptr.cast_const().cast::<Registration<'_, T>>();
// SAFETY: `ptr` is a pointer to `Registration<'_, T>` set in `Registration::new()`.
let registration = unsafe { &*ptr };
T::handle(&registration.handler) as c_uint
bindings::irqreturn_t(T::handle(&registration.handler) 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.
@@ -461,23 +464,26 @@ impl<T: ThreadedHandler> PinnedDrop for ThreadedRegistration<'_, T> {
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
_irq: i32,
ptr: *mut c_void,
) -> c_uint {
) -> bindings::irqreturn_t {
let ptr = ptr.cast_const().cast::<ThreadedRegistration<'_, T>>();
// SAFETY: `ptr` is a pointer to `ThreadedRegistration<'_, T>` set in
// `ThreadedRegistration::new()`.
let registration = unsafe { &*ptr };
T::handle(&registration.handler) as c_uint
bindings::irqreturn_t(T::handle(&registration.handler) as c_uint)
}
/// # Safety
///
/// This function should be only used as the callback in `request_threaded_irq`.
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(_irq: i32, ptr: *mut c_void) -> c_uint {
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(
_irq: i32,
ptr: *mut c_void,
) -> bindings::irqreturn_t {
let ptr = ptr.cast_const().cast::<ThreadedRegistration<'_, T>>();
// SAFETY: `ptr` is a pointer to `ThreadedRegistration<'_, T>` set in
// `ThreadedRegistration::new()`.
let registration = unsafe { &*ptr };
T::handle_threaded(&registration.handler) as c_uint
bindings::irqreturn_t(T::handle_threaded(&registration.handler) as c_uint)
}
+1 -1
View File
@@ -38,7 +38,7 @@ use crate::{bindings, prelude::*, types::Opaque};
/// done <- Completion::new(),
/// }), GFP_KERNEL)?;
///
/// let _ = workqueue::system().enqueue(this.clone());
/// let _ = workqueue::system_dfl().enqueue(this.clone());
///
/// Ok(this)
/// }
+1 -1
View File
@@ -450,7 +450,7 @@ mod tests {
fn spinlock_irq_condvar() -> Result {
let testdata = Test::new()?;
let _ = workqueue::system().enqueue(testdata.clone());
let _ = workqueue::system_dfl().enqueue(testdata.clone());
// Let the updater know when we're ready to wait
let mut state = testdata.state.lock();
+3 -3
View File
@@ -845,14 +845,14 @@ pub unsafe trait HasHrTimer<T> {
#[repr(u32)]
pub enum HrTimerRestart {
/// Timer should not be restarted.
NoRestart = bindings::hrtimer_restart_HRTIMER_NORESTART,
NoRestart = bindings::hrtimer_restart::HRTIMER_NORESTART.0,
/// Timer should be restarted.
Restart = bindings::hrtimer_restart_HRTIMER_RESTART,
Restart = bindings::hrtimer_restart::HRTIMER_RESTART.0,
}
impl HrTimerRestart {
fn into_c(self) -> bindings::hrtimer_restart {
self as bindings::hrtimer_restart
bindings::hrtimer_restart(self as c_uint)
}
}
+27 -25
View File
@@ -67,7 +67,7 @@
//! /// This method will enqueue the struct for execution on the system workqueue, where its value
//! /// will be printed.
//! fn print_later(val: Arc<MyStruct>) {
//! let _ = workqueue::system().enqueue(val);
//! let _ = workqueue::system_dfl().enqueue(val);
//! }
//! # print_later(MyStruct::new(42).unwrap());
//! ```
@@ -121,11 +121,11 @@
//! }
//!
//! fn print_1_later(val: Arc<MyStruct>) {
//! let _ = workqueue::system().enqueue::<Arc<MyStruct>, 1>(val);
//! let _ = workqueue::system_dfl().enqueue::<Arc<MyStruct>, 1>(val);
//! }
//!
//! fn print_2_later(val: Arc<MyStruct>) {
//! let _ = workqueue::system().enqueue::<Arc<MyStruct>, 2>(val);
//! let _ = workqueue::system_dfl().enqueue::<Arc<MyStruct>, 2>(val);
//! }
//! # print_1_later(MyStruct::new(24, 25).unwrap());
//! # print_2_later(MyStruct::new(41, 42).unwrap());
@@ -171,13 +171,13 @@
//! /// This method will enqueue the struct for execution on the system workqueue, where its value
//! /// will be printed 12 jiffies later.
//! fn print_later(val: Arc<MyStruct>) {
//! let _ = workqueue::system().enqueue_delayed(val, 12);
//! let _ = workqueue::system_dfl().enqueue_delayed(val, 12);
//! }
//!
//! /// It is also possible to use the ordinary `enqueue` method together with `DelayedWork`. This
//! /// is equivalent to calling `enqueue_delayed` with a delay of zero.
//! fn print_now(val: Arc<MyStruct>) {
//! let _ = workqueue::system().enqueue(val);
//! let _ = workqueue::system_dfl().enqueue(val);
//! }
//! # print_later(MyStruct::new(42).unwrap());
//! # print_now(MyStruct::new(42).unwrap());
@@ -1024,20 +1024,32 @@ where
{
}
/// Returns the system work queue (`system_wq`).
/// Returns the system per-cpu work queue (`system_percpu_wq`).
///
/// It is the one used by `schedule[_delayed]_work[_on]()`. Multi-CPU multi-threaded. There are
/// users which expect relatively short queue flush time.
///
/// Callers shouldn't queue work items which can run for too long.
pub fn system() -> &'static Queue {
// SAFETY: `system_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_wq) }
#[inline]
pub fn system_percpu() -> &'static Queue {
// SAFETY: `system_percpu_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_percpu_wq) }
}
/// Returns the system default (unbound) work queue (`system_dfl_wq`).
///
/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items
/// are executed immediately as long as `max_active` limit is not reached and resources are
/// available.
#[inline]
pub fn system_dfl() -> &'static Queue {
// SAFETY: `system_dfl_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_dfl_wq) }
}
/// Returns the system high-priority work queue (`system_highpri_wq`).
///
/// It is similar to the one returned by [`system`] but for work items which require higher
/// It is similar to the one returned by [`system_percpu`] but for work items which require higher
/// scheduling priority.
pub fn system_highpri() -> &'static Queue {
// SAFETY: `system_highpri_wq` is a C global, always available.
@@ -1046,26 +1058,16 @@ pub fn system_highpri() -> &'static Queue {
/// Returns the system work queue for potentially long-running work items (`system_long_wq`).
///
/// It is similar to the one returned by [`system`] but may host long running work items. Queue
/// flushing might take relatively long.
/// It is similar to the one returned by [`system_percpu`] but may host long running work items.
/// Queue flushing might take relatively long.
pub fn system_long() -> &'static Queue {
// SAFETY: `system_long_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_long_wq) }
}
/// Returns the system unbound work queue (`system_unbound_wq`).
///
/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items
/// are executed immediately as long as `max_active` limit is not reached and resources are
/// available.
pub fn system_unbound() -> &'static Queue {
// SAFETY: `system_unbound_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_unbound_wq) }
}
/// Returns the system freezable work queue (`system_freezable_wq`).
///
/// It is equivalent to the one returned by [`system`] except that it's freezable.
/// It is equivalent to the one returned by [`system_percpu`] except that it's freezable.
///
/// A freezable workqueue participates in the freeze phase of the system suspend operations. Work
/// items on the workqueue are drained and no new work item starts execution until thawed.
@@ -1078,7 +1080,7 @@ pub fn system_freezable() -> &'static Queue {
///
/// It is inclined towards saving power and is converted to "unbound" variants if the
/// `workqueue.power_efficient` kernel parameter is specified; otherwise, it is similar to the one
/// returned by [`system`].
/// returned by [`system_percpu`].
pub fn system_power_efficient() -> &'static Queue {
// SAFETY: `system_power_efficient_wq` is a C global, always available.
unsafe { Queue::from_raw(bindings::system_power_efficient_wq) }
@@ -1097,7 +1099,7 @@ pub fn system_freezable_power_efficient() -> &'static Queue {
/// Returns the system bottom halves work queue (`system_bh_wq`).
///
/// It is similar to the one returned by [`system`] but for work items which
/// It is similar to the one returned by [`system_percpu`] but for work items which
/// need to run from a softirq context.
pub fn system_bh() -> &'static Queue {
// SAFETY: `system_bh_wq` is a C global, always available.
+1
View File
@@ -201,6 +201,7 @@ static bool is_rust_noreturn(const struct symbol *func)
str_ends_with(func->name, "_4core6option13expect_failed") ||
str_ends_with(func->name, "_4core6option13unwrap_failed") ||
str_ends_with(func->name, "_4core6result13unwrap_failed") ||
str_ends_with(func->name, "_4core6result13unwrap_failed19unwrap_failed_inner") ||
str_ends_with(func->name, "_4core9panicking5panic") ||
str_ends_with(func->name, "_4core9panicking9panic_fmt") ||
str_ends_with(func->name, "_4core9panicking14panic_explicit") ||