From: Daniel Almeida <daniel.almeida@collabora.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: tj@kernel.org, jiangshanlai@gmail.com, aliceryhl@google.com,
ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev, jhubbard@nvidia.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
driver-core@lists.linux.dev
Subject: Re: [PATCH v2 6/6] rust: workqueue: add ScopedWork for non-'static work items
Date: Thu, 27 Aug 2026 20:07:16 -0300 [thread overview]
Message-ID: <62F91620-6211-46BD-8095-4655726D52A2@collabora.com> (raw)
In-Reply-To: <20260807165252.3849875-7-dakr@kernel.org>
>
> /// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
> #[macro_export]
> @@ -283,23 +289,39 @@ pub unsafe fn from_raw<'a>(ptr: *const bindings::workqueue_struct) -> &'a Queue
> /// This may fail if the work item is already enqueued in a workqueue.
> ///
> /// The work item will be submitted using `WORK_CPU_UNBOUND`.
> + #[inline]
> pub fn enqueue<W, const ID: u64>(&self, w: W) -> W::EnqueueOutput
> where
> W: RawWorkItem<ID> + Send + 'static,
> + {
> + // SAFETY: `W: 'static` guarantees the work item remains valid indefinitely,
> + // so the `enqueue_scoped` requirement that the work item stays valid until
> + // the work function runs (or is cancelled) is trivially satisfied.
> + unsafe { self.enqueue_scoped(w) }
> + }
> +
> + /// Enqueues a work item that may not be `'static`.
> + ///
> + /// Unlike [`Queue::enqueue`], this does not require the work item to be `'static`.
> + ///
> + /// The work item will be submitted using `WORK_CPU_UNBOUND`.
> + ///
> + /// # Safety
> + ///
> + /// The caller must ensure that the work item's destructor runs before any
> + /// lifetime it captures expires (i.e., the work item must not be forgotten).
It seems like this requirement is due to cancel_work_sync(). But what happens
if the item is enqueued with enqueue_scoped() on two work queues
simultaneously? Would cancel_work_sync() wait for both queues?
Docs seem to warn against it, IIUC?
"Cancel work and wait for its execution to finish. This function can be used
even if the work re-queues itself or migrates to another workqueue. On return
from this function, work is guaranteed to be not pending or executing on any
CPU —> as long as there aren’t racing enqueues. <—"
> + #[inline]
> + pub unsafe fn enqueue_scoped<W, const ID: u64>(&self, w: W) -> W::EnqueueOutput
> + where
> + W: RawWorkItem<ID> + Send,
> {
prev parent reply other threads:[~2026-08-27 23:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 16:52 [PATCH v2 0/6] workqueue: OwnedQueue, ScopedQueue and ScopedWork Danilo Krummrich
2026-08-07 16:52 ` [PATCH v2 1/6] rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq Danilo Krummrich
2026-08-27 17:12 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 2/6] rust: workqueue: restrict delayed work to global wqs Danilo Krummrich
2026-08-27 17:13 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 3/6] rust: workqueue: create workqueue subdirectory Danilo Krummrich
2026-08-27 17:16 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 4/6] rust: workqueue: add creation of workqueues Danilo Krummrich
2026-08-07 22:39 ` Danilo Krummrich
2026-08-27 19:25 ` Daniel Almeida
2026-08-27 19:25 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 5/6] rust: workqueue: add ScopedQueue for lifetime bound items Danilo Krummrich
2026-08-27 21:39 ` Daniel Almeida
2026-08-07 16:52 ` [PATCH v2 6/6] rust: workqueue: add ScopedWork for non-'static work items Danilo Krummrich
2026-08-07 18:35 ` Danilo Krummrich
2026-08-27 23:07 ` Daniel Almeida [this message]
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=62F91620-6211-46BD-8095-4655726D52A2@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tj@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