* [PATCH v4 0/5] workqueue: OwnedQueue and ScopedWork
@ 2026-11-19 14:12 Alice Ryhl
2026-11-19 14:12 ` [PATCH v4 2/5] rust: workqueue: restrict delayed work to global wqs Alice Ryhl
0 siblings, 1 reply; 2+ messages in thread
From: Alice Ryhl @ 2026-11-19 14:12 UTC (permalink / raw)
To: Tejun Heo, Lai Jiangshan, Danilo Krummrich
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
John Hubbard, Philipp Stanner, rust-for-linux, linux-kernel,
driver-core, Alice Ryhl, stable
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/20260312-create-workqueue-v4-0-ea39c351c38f@google.com
[2] https://lore.kernel.org/all/20260617144645.253444-1-work@onurozkan.dev
[3] https://lore.kernel.org/all/20261014-rust-workqueue-system-fix-v2-1-c018b8f870f9@google.com
[4] https://lore.kernel.org/all/20260807165252.3849875-1-dakr@kernel.org
[5] https://lore.kernel.org/r/20261118-ordered-wq-cancel-v1-0-916e01f9affe@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
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/20261020-rust-workqueue-v3-0-ea7c74d02068@google.com
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/20260807165252.3849875-1-dakr@kernel.org
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,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH v4 2/5] rust: workqueue: restrict delayed work to global wqs
2026-11-19 14:12 [PATCH v4 0/5] workqueue: OwnedQueue and ScopedWork Alice Ryhl
@ 2026-11-19 14:12 ` Alice Ryhl
0 siblings, 0 replies; 2+ messages in thread
From: Alice Ryhl @ 2026-11-19 14:12 UTC (permalink / raw)
To: Tejun Heo, Lai Jiangshan, Danilo Krummrich
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan,
John Hubbard, Philipp Stanner, rust-for-linux, linux-kernel,
driver-core, Alice Ryhl, stable
When a workqueue is shut down, delayed work that is pending but not
scheduled does not get properly cleaned up, so it's not safe to use
`enqueue_delayed` on a workqueue that might be destroyed. To fix this,
restricted `enqueue_delayed` to static queues.
This may be fixed in the future by an approach along the lines of [1].
Cc: stable@vger.kernel.org
Fixes: 7c098cd5eaae ("workqueue: rust: add delayed work items")
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250423-destroy-workqueue-flush-v1-1-3d74820780a5@google.com [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
rust/kernel/workqueue.rs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs
index 6eb6c40138f2..5ef807ed6a33 100644
--- a/rust/kernel/workqueue.rs
+++ b/rust/kernel/workqueue.rs
@@ -302,8 +302,15 @@ pub fn enqueue<W, const ID: u64>(&self, w: W) -> W::EnqueueOutput
///
/// This may fail if the work item is already enqueued in a workqueue.
///
+ /// This is only valid for global workqueues (with static lifetimes) because those are the only
+ /// ones that outlive all possible delayed work items.
+ ///
/// The work item will be submitted using `WORK_CPU_UNBOUND`.
- pub fn enqueue_delayed<W, const ID: u64>(&self, w: W, delay: Jiffies) -> W::EnqueueOutput
+ pub fn enqueue_delayed<W, const ID: u64>(
+ &'static self,
+ w: W,
+ delay: Jiffies,
+ ) -> W::EnqueueOutput
where
W: RawDelayedWorkItem<ID> + Send + 'static,
{
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 14:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 14:12 [PATCH v4 0/5] workqueue: OwnedQueue and ScopedWork Alice Ryhl
2026-11-19 14:12 ` [PATCH v4 2/5] rust: workqueue: restrict delayed work to global wqs Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox