From nobody Mon Feb 9 13:00:45 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D99E61531C1 for ; Wed, 28 Jan 2026 23:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769643717; cv=none; b=hGa4aoJ99nMez8O+PjEkuSj+sbGgtGwpvJaVN/VXXGkrQcoFU9LPQBEdujndhoO+jZaNti08VNgBqkJg86apjXFYBNtX7GmrEqy36KOQBAyyLRPh2xC7J3PcORkWhcPmXKsmqemC/5o5CRIbVeSoRpGf1Ih8x7WYGl7aNDhpU9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769643717; c=relaxed/simple; bh=x68kyFMcXCVl2ap3eh7O4CQGneM+mz/6DOkFyCpzqd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nNv4UgBccjv0FzWxnB4YV8dPKyaC2gC3/j6t9k4lMu3G4gWf6+uhZ70+VxElnkflgf1RsV85LcBkApo4XjMlM8AbhHRxqyjhYLdizH9Po0oAeHN2wemUo6g6FYkAkJyKiaUHJvwdDFb+dDdH3jhPYJjecWgwH4MiysTaKEn1O4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=B3wDNKeI; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B3wDNKeI" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-81c72659e6bso335621b3a.0 for ; Wed, 28 Jan 2026 15:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769643715; x=1770248515; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=Kr5A9uFY8WKbxdwaztWr2I99L6qNUiDvl4AMlkp9MKU=; b=B3wDNKeIykeC7PrdyY6sJhCSu/rO/mUSL+FG/mots3HWo611aiPvX/S4aMWs1OY0EY 7Lm8ANIPdY5WP9nZo4DLLZ34c/nb16UZunobaZ5o0Qg23jusBsqIQiml2fqteYC/N/Pl ItySVLt03m0+NQqKAEj4FZbcQaTLDWoGfYO4U6ytgERkDe97bG5Q948JUGi3vu+jLN0u WZ78Tsw8KxnltiFBfCD8p2z7GIxv7f4vUSM/ssubckSFnE+iOEuTPpJTI91dBKkm8zAe lX816g4eYBRD4LyziagrZKB5IxUCxPj7qKpwVBInrfG7A0TUWnH2oIsDg9Z4vK7GzNA2 +MuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769643715; x=1770248515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kr5A9uFY8WKbxdwaztWr2I99L6qNUiDvl4AMlkp9MKU=; b=q7srYlRat9cLgPD7G1UcVtARATnGkATpbJWTSnHGI2plGhDqQzqBRafa1dEwr02GBY Oo1+22OfJ2HvBlVpcgBq9xrKslDxMSZ9O2ztgZxi7TjInHCRg4W8TV/R5pfQ4hBBVAA+ 25jZYYlYALAwbTRg3bl1hvEMpHm/7AlPwEK654oNmf0no/VRIDhRaou69TfGpuCCuI9F tCJMhCAWWUGAbvE9h5N6ZiW3nxpGu/lDMAYrN8d7HMv6C2Eqk1OpLs0bAS+s+CxyMSBG rMagzKVHgIC13tkHizRIPA9kWJr4JwHesO3O/t3h5X80sAfmvYd+7/4Ri8HikZPkfCxZ 8HhQ== X-Gm-Message-State: AOJu0Yzig6Wu8xUzH/lnBXQ88YcBepB4gMEGzLE1YsXyAOQ63kAABA0r e9G1O7FGTsZV8u8GkgSDV4sjZ38fGHz3arznajAL0Ts0KOoqT1TVpSk5cimNIw== X-Gm-Gg: AZuq6aL7MGkYSY8UYH7xHzf7c0GJxiCXeq1gczdYdFgHXlswgK6sRiRpTY9JyV+7nZm +Q67S/TIEtxadu9IX6ys8/mCqPCbbSRmZai421dtUaZA06l8DydhBiKK8+Q6JMcVhmxJsqCk/5K zHmwq1wi34DAGwo7GyQnAHHcsE3ImfOVSQEUYAyVnnhFd3dmNhsRSTj2SD9kPLpHoq59SiYK/eL KYvQVKUPCio0yuDlty4MImV13pAitPYzm6UXgzPQbp8OAaB5w/G56ZKBhNX5brN6lnkJ8MN71iL nwacXgPnGVawtPxVxXV0M2Oh0kT+XaVKE39BVe2vE9vRL4PjPr4eg2EleAV7giM0HBkYVWjxYIJ qOHz3UenePcRU+c2AhjMcx5YjGESoblHltDLahEUvPeKTSX2O0RCnFRX+so0NWpRvihuC7VHJO4 VE250N9uZdZUfV8MtpZl1mICi66+uWYqVyMjvEvPDWNYW2zaEpTsd1h71xLGr8INXrulUbqN9UF HmRbeLmW/ie5FM= X-Received: by 2002:a05:620a:d81:b0:8c5:310d:3b3a with SMTP id af79cd13be357-8c70b8f6964mr868040985a.70.1769637219381; Wed, 28 Jan 2026 13:53:39 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c711d61c6fsm263878285a.47.2026.01.28.13.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 13:53:38 -0800 (PST) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id 09698F4006C; Wed, 28 Jan 2026 16:53:38 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 28 Jan 2026 16:53:38 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduieeggeehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpeegleejiedthedvheeggfejveefjeejkefgveffieeujefhueeigfegueehgeeg gfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsoh hquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedq udejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmh gvrdhnrghmvgdpnhgspghrtghpthhtohepgedvpdhmohguvgepshhmthhpohhuthdprhgt phhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhr ghdprhgtphhtthhopehrtghusehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoh epghhrvghgkhhhsehlihhnuhigfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtohep rghrvhgvsegrnhgurhhoihgurdgtohhmpdhrtghpthhtohepthhkjhhoshesrghnughroh hiugdrtghomhdprhgtphhtthhopegsrhgruhhnvghrsehkvghrnhgvlhdrohhrghdprhgt phhtthhopegtmhhllhgrmhgrshesghhoohhglhgvrdgtohhmpdhrtghpthhtoheprghlih gtvghrhihhlhesghhoohhglhgvrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Jan 2026 16:53:37 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, rcu@vger.kernel.org Cc: Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , FUJITA Tomonori , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , "Yury Norov (NVIDIA)" , Vitaly Wool , Tamir Duberstein , Viresh Kumar , Daniel Almeida , Mitchell Levy , David Gow , Peter Novak , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Subject: [RFC PATCH 3/7] rust: workqueue: Add HasField support for Work Date: Wed, 28 Jan 2026 13:53:26 -0800 Message-ID: <20260128215330.58410-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260128215330.58410-1-boqun.feng@gmail.com> References: <20260128215330.58410-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement `HasWork` via `HasField` so that manually impl_has_work!() is no longer needed. Signed-off-by: Boqun Feng --- rust/kernel/workqueue.rs | 60 +++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 706e833e9702..2dcfd3eace39 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -34,19 +34,17 @@ //! //! ``` //! use kernel::sync::Arc; -//! use kernel::workqueue::{self, impl_has_work, new_work, Work, WorkItem}; +//! use kernel::workqueue::{self, new_work, Work, WorkItem}; //! +//! #[derive(HasField)] //! #[pin_data] //! struct MyStruct { //! value: i32, //! #[pin] +//! #[field] //! work: Work, //! } //! -//! impl_has_work! { -//! impl HasWork for MyStruct { self.work } -//! } -//! //! impl MyStruct { //! fn new(value: i32) -> Result> { //! Arc::pin_init(pin_init!(MyStruct { @@ -76,23 +74,21 @@ //! //! ``` //! use kernel::sync::Arc; -//! use kernel::workqueue::{self, impl_has_work, new_work, Work, WorkItem}; +//! use kernel::workqueue::{self, new_work, Work, WorkItem}; //! +//! #[derive(HasField)] //! #[pin_data] //! struct MyStruct { //! value_1: i32, //! value_2: i32, //! #[pin] +//! #[field] //! work_1: Work, //! #[pin] +//! #[field] //! work_2: Work, //! } //! -//! impl_has_work! { -//! impl HasWork for MyStruct { self.work_1 } -//! impl HasWork for MyStruct { self.work_2 } -//! } -//! //! impl MyStruct { //! fn new(value_1: i32, value_2: i32) -> Result> { //! Arc::pin_init(pin_init!(MyStruct { @@ -188,6 +184,11 @@ use crate::{ alloc::{AllocError, Flags}, container_of, + field::{ + Field, + HasField, // + }, + macros::HasField, prelude::*, sync::Arc, sync::LockClassKey, @@ -349,9 +350,11 @@ pub fn try_spawn( /// A helper type used in [`try_spawn`]. /// /// [`try_spawn`]: Queue::try_spawn +#[derive(HasField)] #[pin_data] struct ClosureWork { #[pin] + #[field] work: Work>, func: Option, } @@ -534,19 +537,17 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindi= ngs::work_struct { =20 /// Declares that a type contains a [`Work`]. /// -/// The intended way of using this trait is via the [`impl_has_work!`] mac= ro. You can use the macro -/// like this: +/// The intended way of using this trait is via the `#[derive(HasField)]` = macro. You can use the +/// macro like this: /// -/// ```no_run -/// use kernel::workqueue::{impl_has_work, Work}; +/// ``` +/// use kernel::workqueue::Work; /// +/// #[derive(HasField)] /// struct MyWorkItem { +/// #[field] /// work_field: Work, /// } -/// -/// impl_has_work! { -/// impl HasWork for MyWorkItem { self.work_field } -/// } /// ``` /// /// Note that since the [`Work`] type is annotated with an id, you can hav= e several `work_struct` @@ -559,7 +560,6 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut binding= s::work_struct { /// - `work_container_of(raw_get_work(ptr)) =3D=3D ptr` for any `ptr: *mut= Self`. /// - `raw_get_work(work_container_of(ptr)) =3D=3D ptr` for any `ptr: *mut= Work`. /// -/// [`impl_has_work!`]: crate::impl_has_work /// [`raw_get_work`]: HasWork::raw_get_work /// [`work_container_of`]: HasWork::work_container_of pub unsafe trait HasWork { @@ -627,8 +627,24 @@ unsafe fn work_container_of( } pub use impl_has_work; =20 -impl_has_work! { - impl{T} HasWork for ClosureWork { self.work } +impl Field for Work {} + +/// SAFETY: Per the safety requirement of `HasField`, `raw_get_field()` an= d `field_container_of()` +/// return valid pointers and are true inverses of each other, hence the i= mplementation below +/// fulfills `HasWork`'s safety requirement as well. +unsafe impl>, const ID: u64> HasWork for= T { + #[inline] + unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work { + // SAFETY: Per the function safety requirement, `ptr` is a valid p= ointer. + unsafe { >>::raw_get_field(ptr) } + } + + #[inline] + unsafe fn work_container_of(ptr: *mut Work) -> *mut Self { + // SAFETY: Per the function safety requirement, `ptr` is a valid p= ointer, and it points to + // a work field in struct `T`. + unsafe { >>::field_container_of(ptr) } + } } =20 /// Links for a delayed work item. --=20 2.50.1 (Apple Git-155)