All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Alice Ryhl" <aliceryhl@google.com>, "Tejun Heo" <tj@kernel.org>,
	"Lai Jiangshan" <jiangshanlai@gmail.com>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	driver-core@lists.linux.dev
Subject: Re: [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items
Date: Wed, 25 Nov 2026 17:09:49 +0000	[thread overview]
Message-ID: <DN4GI3DQIAHM.2PMLPQ3JOYW7V@garyguo.net> (raw)
In-Reply-To: <20261119-rust-workqueue-v4-5-707c68994940@google.com>

On Thu Nov 19, 2026 at 2:12 PM GMT, Alice Ryhl wrote:
> From: Danilo Krummrich <dakr@kernel.org>
> 
> Add ScopedWork<'wq, T>, a work item wrapper bound to a specific
> &'wq Queue whose destructor calls cancel_work_sync(), allowing T to
> carry non-'static lifetimes. Ownership of the data is not transferred to
> the workqueue; instead, the synchronous cancellation on drop guarantees
> the work function is not running when the data is freed.
> 
> Each ScopedWork<'wq, T> is bound to a single Queue at construction and
> enqueued via ScopedWork::enqueue() to uphold the non-reentrance
> conditions documented in Documentation/core-api/workqueue.rst: queuing
> an in-flight work item onto a different workqueue violates those
> conditions, in which case cancel_work_sync() only waits for execution on
> the last queued workqueue and may return while an earlier execution is
> still running.
> 
> Because the cancellation guarantee only holds if the destructor runs
> before the bound Queue or any lifetime in T expires, ScopedWork::new()
> (and thus new_scoped_work!) is unsafe and requires that the resulting
> value is never forgotten and is dropped before 'wq or T's lifetimes end.
> In return, ScopedWork::enqueue() is a safe method.
> 
> ScopedWork does not use the Work/WorkItem machinery: it embeds the
> work_struct directly and registers its own C callback, which recovers
> the &ScopedWork<'_, T> via container_of!() and passes it to
> ScopedWorkItem::run(). The work_struct, queue pointer, and user data
> live in a private Inner<T> that is wrapped in Opaque as a whole, so that
> the &mut Self held by the destructor while cancel_work_sync() waits does
> not claim uniqueness over memory (including padding) that a worker
> thread may still be reading through &ScopedWork<'_, T>.
> 
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> Co-developed-by: Alice Ryhl <aliceryhl@google.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  rust/kernel/workqueue/mod.rs    |  13 ++
>  rust/kernel/workqueue/scoped.rs | 410 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 423 insertions(+)


      parent reply	other threads:[~2026-11-25 17:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 14:12 [PATCH v4 0/5] workqueue: OwnedQueue and ScopedWork Alice Ryhl
2026-11-19 14:12 ` [PATCH v4 1/5] rust: workqueue: support stack-allocated work items Alice Ryhl
2026-11-19 14:37   ` Gary Guo
2026-11-19 15:17     ` Alice Ryhl
2026-11-25 16:56       ` Gary Guo
2026-11-19 14:12 ` [PATCH v4 2/5] rust: workqueue: restrict delayed work to global wqs Alice Ryhl
2026-11-19 14:12 ` [PATCH v4 3/5] rust: workqueue: create workqueue subdirectory Alice Ryhl
2026-11-19 14:37   ` Gary Guo
2026-11-19 14:12 ` [PATCH v4 4/5] rust: workqueue: add creation of workqueues Alice Ryhl
2026-11-25 16:57   ` Gary Guo
2026-11-26  7:56   ` kernel test robot
2026-11-19 14:12 ` [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items Alice Ryhl
2026-11-25 16:44   ` Tejun Heo
2026-11-25 17:09     ` Gary Guo
2026-11-25 18:17     ` Alice Ryhl
2026-11-26 12:22       ` Tejun Heo
2026-11-26 12:43         ` Alice Ryhl
2026-11-27 16:12           ` Tejun Heo
2026-11-30 17:02             ` Philipp Stanner
2026-11-30 17:04             ` Alice Ryhl
2026-11-25 17:09   ` Gary Guo [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=DN4GI3DQIAHM.2PMLPQ3JOYW7V@garyguo.net \
    --to=gary@garyguo.net \
    --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=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=jhubbard@nvidia.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=phasta@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 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.