mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Tejun Heo <tj@kernel.org>
Cc: "Lai Jiangshan" <jiangshanlai@gmail.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"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: Mon, 30 Nov 2026 18:04:50 +0100	[thread overview]
Message-ID: <CAH5fLgiHrwhyMRwTewySJM4yHyVer_bw2fjzu2RTG5o3jeuiMA@mail.gmail.com> (raw)
In-Reply-To: <2ac377700fd9cd17c32aae2a9d3dbea7@kernel.org>

On Fri, Nov 27, 2026 at 5:12 PM Tejun Heo <tj@kernel.org> wrote:
>
> Hello, Alice.
>
> On Thu, Nov 26, 2026 at 12:43:07PM +0000, Alice Ryhl wrote:
> > Of course, there may be other ways to enforce the non-reentrance
> > conditions hold, which could let me get rid of the lifetime. But the
> > lifetime is there to handle the cleanup before destroy_workqueue() is
> > called case, so a percpu refcount does not come into play.
>
> I didn't explain myself well. I'm not saying that the current scheme
> doesn't work. My concern is how easy the interface is to use, and I wonder
> whether taking workqueue lifetime out of the compiler-managed lifetime
> rules could make it simpler. Something like the following:
>
> - Every Rust work item and delayed work item is bound to one workqueue.
>
> - A Rust workqueue has a percpu refcnt and each work item bound to it
>   holds a reference.
>
> - Destroying the workqueue waits for the refcnt to reach zero. A leaked
>   work item then stalls workqueue destruction, which seems like an okay
>   failure mode.
>
> Work items bound this way never move between workqueues, and neither
> delayed work items nor ScopedWork would need the workqueue to be 'static
> or carry its lifetime. This doesn't solve data or device lifetimes but it
> decouples them from the workqueue's, and device accesses can use workqueue
> destruction as the draining point.
>
> We can add whatever is needed on the workqueue side to make draining work
> well, e.g. an operation which expires a workqueue so that work items
> queued on it afterwards are dropped without running, self-freeing ones
> included.
>
> Workqueue looks the way it does because it's C and leaves all lifetime
> management to its users. Carrying the same model over to Rust and then
> wrapping it for each use case seems like a missed opportunity. I don't
> know Rust well, so I could just be blowing hot air.

I guess we could always just store the address of the workqueue it's
tied to, and require a reference to it on enqueue(), with an equality
check. That way, it's not a problem if the workqueue gets freed before
the work item, but we still enforce no workqueue migration.

Alice

  parent reply	other threads:[~2026-11-30 17:05 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 [this message]
2026-11-25 17:09   ` Gary Guo

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=CAH5fLgiHrwhyMRwTewySJM4yHyVer_bw2fjzu2RTG5o3jeuiMA@mail.gmail.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.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=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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®