From nobody Mon Feb 9 00:54:59 2026 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 8C7B733ADA5 for ; Wed, 28 Jan 2026 21:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769637230; cv=none; b=BWjKB6KOnPkRdTLYHTGyBOoQFLXeJjc7YRA7W6eFrPB0daG28j6CNcxnL0OWn1Scg4IWe96z825E3JG+LU7aS4Vv6Eg3vc33BMPnunJNnB0cz+wKfIkui4WRlj+7qXewqP6yKChyXJim4yKwYXWQT2a2vOr77SRjvVT6cniSUbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769637230; c=relaxed/simple; bh=VS2vDVTbhryM2iG2RFEe63s3RzGceDZw2ywU6GaaAO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SViFpbT9ruqtkpj9Al+H4R6cNGcuY+kQEzOJD5fSzTF9scev5KGmy8HkS/DohfWV8Yw1bnt1MUB8d/9ZC87Tvdllnf7kFaiGhuoVRXSi+0D30KPZdADycIlAFlfvv1kgGUoUZrJaiwWoqMKjr9gIx2GDxn77RP5Q980MdiKZeRo= 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=UWP2xgle; arc=none smtp.client-ip=209.85.222.181 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="UWP2xgle" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-8c6a822068eso48514585a.3 for ; Wed, 28 Jan 2026 13:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769637225; x=1770242025; 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=NJefVb7bf1Dw+gUw0ZVM3yqaOt6rhoTdHQFIKu4uZfc=; b=UWP2xglezd+cyTnP70i7txqJuIktFy1MIxQeWsY/RIamcg0lhDKpL462kDCtgm6234 G3KembYWEBOoCiBQ/7+NP5InQ7Wsf8BmcnA7f+Vb3Tti1TIoFUu9xBNOELTnk+o8xVI1 92d/o900HVXi6GQRz1M+UPNhov8j3rcoBJsUlV0/uvHej1JIGnSXKY0FrfcQ6ilqefsq aaKtxY5PEEtwSs/YaNuxvf48nyG7mfRLk37I5j1bfbvU1Y3kxqvPjR4gC54ryd93J9uN 6ckHCCN/gVfOYyuNpFs/P5LD09r+9j6b4CAqTVGUB7KtIBFPMT8nd1lJheeeEQs6XN+x s4nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769637225; x=1770242025; 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=NJefVb7bf1Dw+gUw0ZVM3yqaOt6rhoTdHQFIKu4uZfc=; b=RdVqNzReEQd8G3nJvdusbzJrv/Z0CGwG/QCeILExC7/v0qk6uNqm9cpoMW3+HZuVak qFXN8Jgv3ftXA6TaL9FhHPd0B9XbWmiSNixRyMfL19mYHfzkeXagmFdkLPZRBvlm1V98 5QothTGn/M0ujNMJdI26ly9qNj8l4yu7Z1VokR1bO5ZJDa2wyYTKTD82D69BOir61uaf DIvjKlCNya3hUafam66/qComIty6ShPgS0f+vfj1idh/Atm5TMPHxPBzVOTGBsmvHX5n 5/qiyI2opUEf3iKb2iNd36BDoH/cSVTjkiXDprJKOk6jzuJj9nArCpHpCMJToYe0q6TX IQbg== X-Gm-Message-State: AOJu0Yx9PaAmG7zxl385Ne/o+VT9ym7QfIBbsc3B+6AN26Gug4mgYnTr uU8EA8DV+1DvrqlV3/QR01kSsWNX1Hh4abghtYp1CtkthwQ3cPoUholB X-Gm-Gg: AZuq6aJVTApl9f1LYLsLA0xvREBRFUchZ/RBBvWmEwnFTRZM6IxUfS1Z1/cH3Y7pnil lL7Vlk5koE3Bdsl/6llFjC1ElUrDArTlmdL9ha+AtJTUzkdbLWQzkgw5JQ+3IJK9YbThbfsd+5m DKsKjAXaVg1bljx+3ZbwLv7VMqHiSB+PgT861HCSAbOskYT+VEfT3h9+d4kJNASwULn7tvJVh0h 1sO8VNOrKDDpmi5rBIw8zunyF6b7yh2XhrJwDLvEcRk3xIbHt2fjjvHZ8ekLvH4LaHEYrm5bx8m RTYnQFagSPmuDPmtoy9Y0cQuTdJs4ho5DHdGDp+n9pUQuKUOIxUsPDJR1QsMP+HV9qLy9tdlX/F +oo5Zwnwz4nLdFtjf231amYKnXhX3JxieYWShxtxEyXgXLnaywRSxL5Li6DzhKHibbMHwmw/vH0 O/x/pKzkUBPucBaRaVrOHUVuDdJsQxKE1w7oyDxDYEVV4z/fzVlSgZhI6lItyDtlWnMdqak49uq VUBWWmQfGL/DLU= X-Received: by 2002:a05:620a:1988:b0:8c1:6018:b186 with SMTP id af79cd13be357-8c70b927a0dmr857145285a.87.1769637225168; Wed, 28 Jan 2026 13:53:45 -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-8c711b96fbdsm261644985a.14.2026.01.28.13.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 13:53:44 -0800 (PST) Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfauth.phl.internal (Postfix) with ESMTP id EE44BF4006D; Wed, 28 Jan 2026 16:53:43 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 28 Jan 2026 16:53:43 -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:43 -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 7/7] rust: sync: rcu: Introduce RcuHead Date: Wed, 28 Jan 2026 13:53:30 -0800 Message-ID: <20260128215330.58410-8-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" In order to support RCU delay free (call_rcu() and kfree_rcu()), the abstraction of the `rcu_head` is introduced. Types that want to support RCU delay free can specify a `RcuHead` in it, e.g. #[derive(HasField)] struct Foo { a: i32, b: i32, #[field] rcu_head: RcuHead, } A wrapper `WithRcuHead` is also provided for users that want to specify a generic `T` with a rcu_head. Signed-off-by: Boqun Feng --- rust/kernel/sync/rcu.rs | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs index a32bef6e490b..694ca2f54953 100644 --- a/rust/kernel/sync/rcu.rs +++ b/rust/kernel/sync/rcu.rs @@ -4,7 +4,14 @@ //! //! C header: [`include/linux/rcupdate.h`](srctree/include/linux/rcupdate.= h) =20 -use crate::{bindings, types::NotThreadSafe}; +use crate::{ + bindings, + field::{Field, HasField}, + macros::HasField, + types::{NotThreadSafe, Opaque}, +}; + +use core::ops::Deref; =20 /// Evidence that the RCU read side lock is held on the current thread/CPU. /// @@ -50,3 +57,63 @@ fn drop(&mut self) { pub fn read_lock() -> Guard { Guard::new() } + +/// RCU head for call backs. +/// +/// # Examples +/// +/// Use `#[derive(HasField)]` macro to specify a struct has a RCU head. +/// +/// ``` +/// use kernel::sync::rcu::RcuHead; +/// +/// #[derive(HasField)] +/// struct Foo { +/// a: i32, +/// #[field] +/// rcu_head: RcuHead, +/// b: i32, +/// } +/// +/// const _: () =3D { +/// const fn assert_has_field>() { } +/// assert_has_field::(); +/// }; +/// ``` +#[repr(transparent)] +pub struct RcuHead(Opaque); + +impl Field for RcuHead {} + +// SAFETY: `callback_head` doesn't hold anything local to the current exec= ution context, so it's +// safe to transfer to another execution context. +unsafe impl Send for RcuHead {} +// SAFETY: `callback_head` should only be used when it's in the destructor= , and accesses to it are +// already unsafe, hence make it `Sync`. +unsafe impl Sync for RcuHead {} + +/// A wrapper that adds an `RcuHead` on `T`. +#[derive(HasField)] +pub struct WithRcuHead { + #[field] + head: RcuHead, + data: T, +} + +impl WithRcuHead { + /// Creates a new wrapper on `T` with `RcuHead`. + pub fn new(data: T) -> Self { + Self { + head: RcuHead(Opaque::zeroed()), + data, + } + } +} + +impl Deref for WithRcuHead { + type Target =3D T; + + fn deref(&self) -> &Self::Target { + &self.data + } +} --=20 2.50.1 (Apple Git-155)