From nobody Mon Feb 9 05:40:20 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 B07281531C1 for ; Wed, 28 Jan 2026 23:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769643774; cv=none; b=BZXnnRRSEE6WrqziXkfV8JaWjym1hKGnuOXPZVM2yHWtqrh0VZVf/Llp0T0w7RFhDgrvrCXB9mVKbBs9FLTOF6soT/oG+537rhiEVPHfWrKbolDbQlDJjIwwQIW+8oRwyjCGEim+X+H2V7KJxAImk33H4ZAAV08BJCPv+61fRIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769643774; c=relaxed/simple; bh=OUnhhLpw0G4jfOUrV0sIe5rYFeDBYm/rgYAQew5ALOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rP0XqjJCWV/ipiaFmb4I8He3NoRzGku0k3wqXiz7wMErsz5En70fBI8BoEKsm9H7ij9e4eRuHjbNaPXxkLA4MnHZ9i3cwqXjf5EEnlHcxn2zwJ1Q4Qk87Fef+CwvNaANnNGV5dW4SbfiV03VH5/rje18LrNRmSmENLIctLRXAWg= 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=AbAp+qlA; arc=none smtp.client-ip=209.85.214.179 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="AbAp+qlA" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2a743050256so1852175ad.3 for ; Wed, 28 Jan 2026 15:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769643772; x=1770248572; 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=ZwleCKT0WC1y4r31KovKxSZY4leqC3/LnghDg5OFIfc=; b=AbAp+qlAItQzE/RpQxbexcqVGThucphcw8KAclwxE9mDG6nG3IWbY1suER+Lxv0L4W fnEDiDs/2Q3JfpcSc6l1xbMxQrcnFojJXoR6aVDtay95y6iPhLx4Vpc6XZZIVzOJ0BFf FqqeuInLBKv9s8Ahw5WAHTPJDkwVTROZ5vbgXtjiCxLYomHNhdi7sURodo8KmeqmAQnq z5l6Tm9mxlPTLF+xaHGd2PKcZI109K7hnRxAvYP5DwVgP4dMXGn9sNtnJUq5uCh10Al0 sc+e4gK6NOwLrp+3Znsy21lLZOZlEzcdj4NHpotbnNZv24O0WdNGngUJC6yysr9HN61h 7Gsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769643772; x=1770248572; 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=ZwleCKT0WC1y4r31KovKxSZY4leqC3/LnghDg5OFIfc=; b=Z/0UaR+OXMsB8VnhKD7FBeh3ue9lrW9Uw33NkcFuPHgG2w8fKV3IEsIiBIFW7F7F0O ZIsl8nPXnaMEWykxYAz61AsGZjT9vt4temJVJfkHtfNji6ZB5EjtMLEadHpSW6vsijqT FG8slTxfHE2tkdO3IP1KcDc5jj3sE8pJ/Q32/rEWpZgschTsV53Ah5Imfm/AvFYH1VqP hMZzhfCJPGJFPQj1dWVXFxxX9QjKHer/BM5qH7g/e1Uw8/8jzQlTHPjGPem5WPdBNwLY LAURijb2GnlwXwnXQJGXmr7xRLihfPblCvapR9EnFUAYrnpTSSC7KNXy+vcQccyivRJ/ /mBg== X-Gm-Message-State: AOJu0YwnN2sTofGzugikpMPsXDaO/wSzotvWUzeJB3nIDC0YVBPtoP2O n0SJtKkBFtqhG1oxdtya/UzkOlvVVDTbfrXvLLt+uqSS2NBn4yNhUrKII5sn4g== X-Gm-Gg: AZuq6aLpFHsuIzCZ04CcxG1PjjolGizBZXdJ7ojABDd6/5wEvNfmmO1gPVBoYdptdbA iBF4t0AiEHu1qlVYCXYHEKiLxoxBW6ofDLgwUSQDqrN7tvoZRuP1HfGbYDE25PXltAoa+dumf+o obafN96Pg6uzmLVrlc5DFCgQIlA6m9z1sAKmkraQqQvI2K+8NJ3yBcsa02p1YnUqMCM0/lrKLfI MWXpBIsg37dUzS9zZuacRwX619q4cTl5K504Z7oksNnOD933jwATPmBmvUCwrPmvhGK5qaH8Cnx hNWPo5ToDhR0E1/+YmEPguazz/95bfXUhuieqzeh2+sbgKYLS2CqSR4onsKORlFT6D5zCOC/zIj ldnAcdZGWbRf2jWLZdOWP9i7g32jFK1VnrRFXpHAfbLMIl8Umou1Ujcw+FVqP+IH5ZhyKh0l/66 cGSd2uGzQDkFn5BRR9JKypV8jt1xkeWxyhNZoIDlXSYl1/H+FfAJBkqfN+qXE+78aM9mLbfACWF dqfiXt7ou+BG1c= X-Received: by 2002:ad4:5f0f:0:b0:888:3d1e:f95 with SMTP id 6a1803df08f44-894cc8c97dbmr102202586d6.32.1769637217348; Wed, 28 Jan 2026 13:53:37 -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 6a1803df08f44-894d373fe92sm25727956d6.32.2026.01.28.13.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 13:53:37 -0800 (PST) Received: from phl-compute-07.internal (phl-compute-07.internal [10.202.2.47]) by mailfauth.phl.internal (Postfix) with ESMTP id 28E16F4006C; Wed, 28 Jan 2026 16:53:36 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Wed, 28 Jan 2026 16:53:36 -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:35 -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 2/7] rust: time: hrtimer: Make `HasField` a super-trait of `HasHrTimer` Date: Wed, 28 Jan 2026 13:53:25 -0800 Message-ID: <20260128215330.58410-3-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" This decouples the hrtimer mode part from the `HasField` part of a `HasHrTimer`, `impl_has_hr_timer` also gets removed, as we can do: #[has_field] #[pin] struct MyStruct { a: i32, #[field] timer: HrTimer, } impl HasHrTimer for MyStruct { type TimerMode =3D ...; } Signed-off-by: Boqun Feng --- rust/kernel/time/hrtimer.rs | 70 ++++++++----------------------------- 1 file changed, 15 insertions(+), 55 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 856d2d929a00..eef6d60f5adb 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -98,6 +98,8 @@ unsafe impl Send for HrTimer {} // on a timer from multiple threads. unsafe impl Sync for HrTimer {} =20 +impl Field for HrTimer {} + impl HrTimer { /// Return an initializer for a new timer instance. pub fn new() -> impl PinInit @@ -417,17 +419,7 @@ pub unsafe trait HrTimerHandle { } =20 /// Implemented by structs that contain timer nodes. -/// -/// Clients of the timer API would usually safely implement this trait by = using -/// the [`crate::impl_has_hr_timer`] macro. -/// -/// # Safety -/// -/// Implementers of this trait must ensure that the implementer has a -/// [`HrTimer`] field and that all trait methods are implemented according= to -/// their documentation. All the methods of this trait must operate on the= same -/// field. -pub unsafe trait HasHrTimer { +pub trait HasHrTimer: HasField> { /// The operational mode associated with this timer. /// /// This defines how the expiration value is interpreted. @@ -441,7 +433,11 @@ pub unsafe trait HasHrTimer { /// # Safety /// /// `this` must be a valid pointer. - unsafe fn raw_get_timer(this: *const Self) -> *const HrTimer; + #[inline] + unsafe fn raw_get_timer(this: *const Self) -> *const HrTimer { + // SAFETY: Per function safety requirement, `this` is a valid poin= ter. + unsafe { >::raw_get_field(this.cast_mut()) = }.cast_const() + } =20 /// Return a pointer to the struct that is containing the [`HrTimer`] = pointed /// to by `ptr`. @@ -452,9 +448,15 @@ pub unsafe trait HasHrTimer { /// # Safety /// /// `ptr` must point to a [`HrTimer`] field in a struct of type `Se= lf`. + #[inline] unsafe fn timer_container_of(ptr: *mut HrTimer) -> *mut Self where - Self: Sized; + Self: Sized, + { + // SAFETY: Per function safety requirement, `ptr` is a valid point= er and points to a + // `HrTimer` field in a struct. + unsafe { >::field_container_of(ptr) } + } =20 /// Get pointer to the contained `bindings::hrtimer` struct. /// @@ -731,48 +733,6 @@ pub fn forward_now(&mut self, duration: Delta) -> u64 { } } =20 -/// Use to implement the [`HasHrTimer`] trait. -/// -/// See [`module`] documentation for an example. -/// -/// [`module`]: crate::time::hrtimer -#[macro_export] -macro_rules! impl_has_hr_timer { - ( - impl$({$($generics:tt)*})? - HasHrTimer<$timer_type:ty> - for $self:ty - { - mode : $mode:ty, - field : self.$field:ident $(,)? - } - $($rest:tt)* - ) =3D> { - // SAFETY: This implementation of `raw_get_timer` only compiles if= the - // field has the right type. - unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$= timer_type> for $self { - type TimerMode =3D $mode; - - #[inline] - unsafe fn raw_get_timer( - this: *const Self, - ) -> *const $crate::time::hrtimer::HrTimer<$timer_type> { - // SAFETY: The caller promises that the pointer is not dan= gling. - unsafe { ::core::ptr::addr_of!((*this).$field) } - } - - #[inline] - unsafe fn timer_container_of( - ptr: *mut $crate::time::hrtimer::HrTimer<$timer_type>, - ) -> *mut Self { - // SAFETY: As per the safety requirement of this function,= `ptr` - // is pointing inside a `$timer_type`. - unsafe { ::kernel::container_of!(ptr, $timer_type, $field)= } - } - } - } -} - mod arc; pub use arc::ArcHrTimerHandle; mod pin; --=20 2.50.1 (Apple Git-155)