Skip to content

workqueue: OwnedQueue and ScopedWork

Alice Ryhl driver-core lkml rust-for-linux stable 6 versions – In review

Get series with b4
b4 am [email protected] change-id 20250411-create-workqueue-d053158c7a4b

Versions newest first

  1. v4 Latest posting 2/25 patches 3 repliesIn review
  2. v3 posting 2/24 patches 1 replySuperseded inferred link
  3. v4 posting 1/23 patches 12 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v3 posting 1/22 patches22 repliesSuperseded
v22 patches9 repliesSuperseded
v11 patch20 repliesSuperseded

Changes in v4 from the cover letter

- Rebase on v7.4-rc3
- ScopedWork: bind ScopedWork<'wq, T> to &'wq Queue at construction and replace Queue::enqueue_scoped() with ScopedWork::enqueue() so a work
item cannot be migrated across workqueues
- Add patch to pass object_is_on_stack() in init_work_with_key() and
call destroy_work_on_stack() when Work is dropped
- ScopedWork: call destroy_work_on_stack() on drop for CONFIG_DEBUG_OBJECTS_WORK support
- ScopedWork: initialize data before work_struct in ScopedWork::new() so init_work_with_key() is not called if the data initializer fails
- ScopedWork: add INVARIANT comments in ScopedWork::new()
- ScopedWork: require Sync on ScopedWorkItem
- Add Queue::as_raw()
- Pick up Reviewed-by tag from Philipp
- Link to v3: https://lore.kernel.org/r/[email protected]

Patches in v4 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5rust: workqueue: support stack-allocated work itemsrust/helpers/workqueue.c rust/kernel/workqueue.rs+17 -52 replies
2/5rust: workqueue: restrict delayed work to global wqsrust/kernel/workqueue.rs+8 -10 replies
3/5rust: workqueue: create workqueue subdirectoryMAINTAINERS rust/kernel/workqueue/mod.rs+1 -01 reply
4/5rust: workqueue: add creation of workqueuesrust/helpers/workqueue.c rust/kernel/workqueue/builder.rs rust/kernel/workqueue/mod.rs+425 -30 replies
5/5rust: workqueue: add ScopedWork for non-'static work itemsrust/kernel/workqueue/mod.rs rust/kernel/workqueue/scoped.rs+423 -00 replies

Reviews trailers per patch

3 of 5 patches have a Reviewed-by or Acked-by.

PatchJohn HubbardDanilo KrummrichGary GuoAndreas HindborgDaniel AlmeidaPhilipp Stanner
1/5
2/5R-b R-b R-b R-b R-b
3/5R-b R-b R-b
4/5R-b R-b
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 6 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/5] workqueue: OwnedQueue and ScopedWork

This series extends the Rust workqueue bindings with the ability to create custom workqueues (OwnedQueue), and introduces ScopedWork, a work item type that cancels synchronously on drop, allowing drivers to use workqueues with lifetime-bound data.

This is a continuation of Danilo's v2 [4], which picked up my earlier series [1] and Onur's ScopedQueue work [2].

Patch 1/6 of v2, "rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq", is a fix that was sent separately [3] and landed upstream in v7.4-rc1.

The soundness of this series depends on the ordered workqueue cancellation fix series [5].

[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/all/[email protected]
[5] https://lore.kernel.org/r/[email protected]

---
Changes in v4:
- Rebase on v7.4-rc3
- ScopedWork: bind ScopedWork<'wq, T> to &'wq Queue at construction and replace Queue::enqueue_scoped() with ScopedWork::enqueue() so a work
item cannot be migrated across workqueues
- Add patch to pass object_is_on_stack() in init_work_with_key() and
call destroy_work_on_stack() when Work is dropped
- ScopedWork: call destroy_work_on_stack() on drop for CONFIG_DEBUG_OBJECTS_WORK support
- ScopedWork: initialize data before work_struct in ScopedWork::new() so init_work_with_key() is not called if the data initializer fails
- ScopedWork: add INVARIANT comments in ScopedWork::new()
- ScopedWork: require Sync on ScopedWorkItem
- Add Queue::as_raw()
- Pick up Reviewed-by tag from Philipp
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Rebase on v7.3-rc7
- Split out the system_wq patch and send it separately as a fix [3]; this series no longer depends on it
- Drop ScopedQueue: with the ScopedWork changes below it is no longer needed to enqueue non-'static work items, and it has no other user
- ScopedWork: make ScopedWork::new() unsafe instead of Queue::enqueue_scoped(), which is now a safe method accepting &ScopedWork<T> on any queue
- ScopedWork: drop the WorkItem/WorkItemPointer/HasWork impls and the public ScopedWorkRef type; embed the work_struct directly with a dedicated callback, and keep the Opaque-wrapped payload private
- ScopedWork: drop T on drop (Opaque does not run destructors)
- ScopedWork: propagate the initializer's error type from new()
- Builder: new_power_efficient() uses WQ_PERCPU | WQ_POWER_EFFICIENT; remove the now pointless percpu() modifier
- Pick up Reviewed-by tags from Daniel
- Link to v2: https://lore.kernel.org/all/[email protected]

Changes in v2:
- Merge scoped_work.rs and scoped_queue.rs into scoped.rs
- Introduce ScopedWorkRef<T> and wrap it in Opaque inside ScopedWork to avoid &mut aliasing in drop
- Pass &ScopedWorkRef<Self> to ScopedWorkItem::run to enable self-re-enqueue
- Add Deref<Target = Queue> for ScopedQueue; remove duplicate enqueue_scoped()
- Add Send + Sync for OwnedQueue
- Fix stale workqueue::system() references in docs
- Drop Work::cancel_work_sync()
- Make sysfs() available on ordered workqueues
- Add #[inline] annotations throughout

---
Alice Ryhl (4):
rust: workqueue: support stack-allocated work items
rust: workqueue: restrict delayed work to global wqs
rust: workqueue: create workqueue subdirectory
rust: workqueue: add creation of workqueues

Danilo Krummrich (1):
rust: workqueue: add ScopedWork for non-'static work items

 MAINTAINERS                                    |   1 +
 rust/helpers/workqueue.c                       |  16 +-
 rust/kernel/workqueue/builder.rs               | 370 ++++++++++++++++++++++
 rust/kernel/{workqueue.rs => workqueue/mod.rs} |  86 +++++-
 rust/kernel/workqueue/scoped.rs                | 410 +++++++++++++++++++++++++
 5 files changed, 874 insertions(+), 9 deletions(-)

---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261012-rust-workqueue-658cd0fbe770

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>