From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA4322248A5; Fri, 10 Jan 2025 20:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540293; cv=none; b=hdyVLnehPzGu2dFWTkNpR1wDlK7JLmEsVeMqFcI5fL6xNrnTgi6NyfysNMJCnpyE2ojcrXo4nfE0NhxGTdoPig1ssXUV7rqEofknkxMUz97iLoy4yzs+cDCoamqrn5iTsFbkOBN+dS2DJYAaSJu7ysgW39JcPVPvFVUiqwGPlSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540293; c=relaxed/simple; bh=/ybNIO+z0YMt7NQe0O7P3cxsv0vraqHKkL76VnTITTw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a8B4W6siHlEKOe3fdK2ODxKRMKNG0B/4/709lEq4ujE+AUqyrVbr0ovq9JxX8XWzZkHUvP3SEjnJCrFJBSRJd+WQ8In75bbls/fgPRYccAqSypJmsZ2z15owXBYhxR4MPbM7nJVeJx3pRElLGcb8+xrah9b60y0ElGTOcnephLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BSohGVOO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BSohGVOO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9204EC4CED6; Fri, 10 Jan 2025 20:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540292; bh=/ybNIO+z0YMt7NQe0O7P3cxsv0vraqHKkL76VnTITTw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BSohGVOO1IlFdBgoSdYbGJVGszHzfgQ4TwmIBGcHmaTnawezclRTuATOErXyRvBKs k2/U1ys/o9Ko9i1VfiJVVQQ7WFQZ/zJyNZ+uSdpoBYQLdTWw5EGFJ6lVqQsvmPJl4Y 5B0CV2ykwFzF33Ls9MBMt5h0opoVJhB2v2FnVEr4AACvTAWgDG8gGEJzKfSNe/HfHN 2mcNFwY0WOcJJdkoYWvZwjKIUx5a/DIfRnOZhE3phfedx4BGSF/JyEceh/PvlRLy3n 7J5dKuAwVEoPaNsKu2tqOiZS3eGz1/FfCXqIS86QRrL03ICy8htD3jj47T8eKVF/1D /TLRMcCDTW/uw== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:24 +0100 Subject: [PATCH v6 01/14] rust: time: Add Ktime::from_ns() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-1-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1377; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=zvxjVReWexH5OF8VhuSFOtSXv8mRCanz1tBYjzejoHo=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/g4zdQ52qSi4nEXeCOuczc7KAu72uF3omkJ xmJ7goW0KGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/4AAKCRDhuBo+eShj dyoXEACvJ/3bmgDymZarAfdrNrlCA1Zoz9YbojSS2MYrJ9wTxn77y0dVeGTwZWv0VY13bO4K8gL 3ZELSmmvhoQDyAIUVD1XkZAhHJDROh6OEMeGs924SWBN8u2Tgha58ZO2wxKTCKXboyeszSiE6ho 2u94Lh3buUGK2WfdSQ4AXQVvxOs5CNDhcl2xptUnPl/NNi8+7iN8r5JQa3+DCRp9sBxk+s0tzPc F5jE25IexTDA6WFbhJ+s9bnz/CpkvMr+R4dvHNP93D9reIhYbQlMLcBgroOHIRJtwgQbX8QUSRz d2V38CYGgeR8iZ3R0rjlKD6xr5/kYosnHD4K4HW35p8elW2eZ/i/a9gCUegga0SbFlyRxlf+lmF XXjhf4Vx4wNUvgWMNekhwNKOQFJFkNyII9UKSGuYSpPwtSeZ6M6IWQqG1lqvKfYGLuHUGm8ZpKO EzUp3SiBvJ2vBqI6XllCvQDDDhAHb3XXMcf0Q4hE+5OIhi6BFDC34hiBMKvCwbrN8ITJVVtA/VD 1aM1QIf7gNSPrhBuY05b+MxVP/c/6E1qSKbDjcxn7vn5QLCojfPNvkESPHoTnYoAtYDbCP40Kml ktsYeEdyALRuBKxkdyjpcps3tvM0WpYUjsUMe333RxfkV23OCssAICWmk+f6i3dOkCdd0fedNsi 8vnqfnaBNAeElZQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 From: Lyude Paul A simple function to turn the provided value in nanoseconds into a Ktime value. We allow any type which implements Into, which resolves to Into. This is useful for some of the older DRM APIs that never got moved to Ktime Signed-off-by: Lyude Paul Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e575c9ceacb9c85255b13501db8f30..f59e0fea79d3acfddd922f601f5= 69353609aeec1 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -8,6 +8,8 @@ //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 +use core::convert::Into; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 @@ -63,6 +65,12 @@ pub fn to_ns(self) -> i64 { pub fn to_ms(self) -> i64 { self.divns_constant::() } + + /// Creates a new Ktime from the given duration in nanoseconds + #[inline] + pub fn from_ns(ns: impl Into) -> Self { + Self { inner: ns.into() } + } } =20 /// Returns the number of milliseconds between two ktimes. --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3D24216605; Fri, 10 Jan 2025 20:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540249; cv=none; b=sldBwPoeGn9GvKLacR7EwXQkGNBXPGwkYKCYk3xcbHbsVaIxnPIhvkz6WSRjNNMCfexiYPUY+hWKfizVqo3qg3VNaMmQa5AXyMV4YZuk0l2DWQ0n5Ok/zmSSa4evi2Mo8u0ifr616IaGSP9leyoaBFnpB8QlTkpPu9yucEGxlsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540249; c=relaxed/simple; bh=WI1QQEthNUXkpNxEYU0KTttYKrKnItbb/aigqwxV3+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bEbMvsYkRW9ZG6UeagqxJGmGezasYP8qvV+rVQgt9V1SkIHukx8x1DDznTn1cXBNa0TyT69Q7tDogPRYBHLCek6RZO8KW7+WLTO7m4r8MeT2K+NTBKKkZBXTl6vNY6fUTiK1Nbn7PZ9xFcD8szEe8YOHsJNPH88p9FAAvFk2wGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WDbkVTfQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WDbkVTfQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26698C4CEDD; Fri, 10 Jan 2025 20:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540248; bh=WI1QQEthNUXkpNxEYU0KTttYKrKnItbb/aigqwxV3+k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WDbkVTfQaIW43iyh6+06COvUtK4M0I4yfWhIVsF/7oKSyG2np3/Hn07ze9ajUGuGO YsGdjLa27GAq/eYcErUS9eYPHIrLTOWN6S+jiXJr6WDhmyDKFZMtt2MAFV3bWwqC+V G7KicqV0NMWMWvkmAbJzbnWcsQ1dJ+suWlV+60fgbKq+qAkpRVuMkzjdTwWqPGuZ3B 2dbDTRIBUX24hpaq6fL2IqGB8UxpmgNoe6yy2wpqM/bvF8RgW90mtTaGbzBv5QXoPN YutaP4cUexvjhqsILLDz0P6mIo8+W2R4nVRTOGCU6GqINj5I4TT2jykheww8d//jdP 2ebhoutJ0Hg6w== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:25 +0100 Subject: [PATCH v6 02/14] rust: hrtimer: introduce hrtimer support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-2-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=12380; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=WI1QQEthNUXkpNxEYU0KTttYKrKnItbb/aigqwxV3+k=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/g0DmBALe8IDpO6WL1vfrNUfQPuezd4hvhc dd+CCRrdcKJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/4AAKCRDhuBo+eShj d+ThD/9A9vn9DTN8tEFe0W2SzHH8Vek4QOcwGLJpcLGeSWpTurw0K5fFTSQWHVHeAaGWTNAjR0E +IPXYyX3IR/2nFRA2ElWS/SB07MNZrOoAExoPwnwwYSdrHPEvlRd8jO3DDm+gExHZYEoRMNNNAE gykbXwj0dyJp6Xp1pvQ0QF0NyavddB2KhI1sdTf4yf7ioPZFmfxgAo5rt7htHxB4YfgWchBPtaH DsxAVB/R5UD51GuJy7Vr4hE+TwsuXYHN6cP03MZxYU+f/qyMRk2Y6fc+ZiSpWmZpvL7N7qr8tjX gseVcEYi0bC8rZW7pKak2+fEcU0M4B7PSLOg5cozUUQOkyO+e8IDtOJMthOOylPa8JfAbrTzrUd O0/MxF3W8UsRTYRqaCmIj7SloISH0bewxKTJqiYiMumhXoxB6ACpA58IwFWaaR8TxZ16ynvNwUz uzwYA498vLzx0KxvIYUAEQvRjAO8YEIdp8Fs3TFIL47Q5Op0bmEjOt3LokHyo2IjsD3v7Tg6a2e TFCdsZu16SFrVFiBbtl4Up8zR2AqydOYlJXvR6digf9Z1F2ZKcs1r0urzkPOUk1wlA6PdrFrgIp s0+5pR+jyqf5awM/OKVSt69M/MRslQd1JH1WRRVJTURZFlgniU/4CbWroyrtAZkxCUjIV/ukIxv Z1yJpQZrTXeDnPA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch adds support for intrusive use of the hrtimer system. For now, only one timer can be embedded in a Rust struct. The hrtimer Rust API is based on the intrusive style pattern introduced by the Rust workqueue API. Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 2 + rust/kernel/time/hrtimer.rs | 296 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 298 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index f59e0fea79d3acfddd922f601f569353609aeec1..51c3532eee0184495ed5b7d7178= 60c9980ff2a43 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -10,6 +10,8 @@ =20 use core::convert::Into; =20 +pub mod hrtimer; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs new file mode 100644 index 0000000000000000000000000000000000000000..31c461ddd2c377101ed6c1c7e00= 9f7dccf458ebc --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Intrusive high resolution timers. +//! +//! Allows running timer callbacks without doing allocations at the time of +//! starting the timer. For now, only one timer per type is allowed. +//! +//! # Vocabulary +//! +//! A timer is initialized in the **stopped** state. A stopped timer can be +//! **started** with an **expiry** time. After the timer is started, it is +//! **running**. When the timer **expires**, the timer handler is executed. +//! After the handler has executed, the timer may be **restarted** or +//! **stopped**. A running timer can be **cancelled** before it's handler = is +//! executed. A timer that is cancelled enters the **stopped** state. +//! +//! States: +//! +//! * Stopped +//! * Running +//! +//! Operations: +//! +//! * Start +//! * Cancel +//! * Stop +//! * Restart +//! +//! Events: +//! +//! * Expire + +use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque}; +use core::marker::PhantomData; + +/// A timer backed by a C `struct hrtimer`. +/// +/// # Invariants +/// +/// * `self.timer` is initialized by `bindings::hrtimer_setup`. +#[pin_data] +#[repr(C)] +pub struct HrTimer { + #[pin] + timer: Opaque, + _t: PhantomData, +} + +// SAFETY: A `HrTimer` can be moved to other threads and used/dropped from= there. +unsafe impl Send for HrTimer {} + +// SAFETY: Timer operations are locked on C side, so it is safe to operate= on a +// timer from multiple threads +unsafe impl Sync for HrTimer {} + +impl HrTimer { + /// Return an initializer for a new timer instance. + pub fn new() -> impl PinInit + where + T: HrTimerCallback, + { + pin_init!(Self { + // INVARIANTS: We initialize `timer` with `hrtimer_setup` belo= w. + timer <- Opaque::ffi_init(move |place: *mut bindings::hrtimer|= { + // SAFETY: By design of `pin_init!`, `place` is a pointer = live + // allocation. hrtimer_setup will initialize `place` and d= oes + // not require `place` to be initialized prior to the call. + unsafe { + bindings::hrtimer_setup( + place, + Some(T::CallbackTarget::run), + bindings::CLOCK_MONOTONIC as i32, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + }), + _t: PhantomData, + }) + } + + /// Get a pointer to the contained `bindings::hrtimer`. + /// + /// # Safety + /// + /// `ptr` must point to a live allocation of at least the size of `Sel= f`. + unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrtimer { + // SAFETY: The field projection to `timer` does not go out of boun= ds, + // because the caller of this function promises that `ptr` points = to an + // allocation of at least the size of `Self`. + unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).timer)) } + } + + /// Cancel an initialized and potentially running timer. + /// + /// If the timer handler is running, this will block until the handler= is + /// finished. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + #[allow(dead_code)] + pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; + + // If handler is running, this will wait for handler to finish bef= ore + // returning. + // SAFETY: `c_timer_ptr` is initialized and valid. Synchronization= is + // handled on C side. + unsafe { bindings::hrtimer_cancel(c_timer_ptr) !=3D 0 } + } +} + +/// Implemented by pointer types that point to structs that embed a [`HrTi= mer`]. +/// +/// Typical implementers would be [`Box`], [`Arc`], [`ARef`] wher= e `T` +/// has a field of type [`HrTimer`]. +/// +/// Target must be [`Sync`] because timer callbacks happen in another thre= ad of +/// execution (hard or soft interrupt context). +/// +/// Starting a timer returns a [`HrTimerHandle`] that can be used to manip= ulate +/// the timer. Note that it is OK to call the start function repeatedly, a= nd +/// that more than one [`HrTimerHandle`] associated with a [`HrTimerPointe= r`] may +/// exist. A timer can be manipulated through any of the handles, and a ha= ndle +/// may represent a cancelled timer. +/// +/// [`Box`]: Box +/// [`Arc`]: crate::sync::Arc +/// [`ARef`]: crate::types::ARef +pub trait HrTimerPointer: Sync + Sized { + /// A handle representing a running timer. + /// + /// If the timer is running or if the timer callback is executing when= the + /// handle is dropped, the drop method of [`HrTimerHandle`] should not= return + /// until the timer is stopped and the callback has completed. + /// + /// Note: It must be safe to leak the handle. + type TimerHandle: HrTimerHandle; + + /// Start the timer with expiry after `expires` time units. If the tim= er was + /// already running, it is restarted with the new expiry time. + fn start(self, expires: Ktime) -> Self::TimerHandle; +} + +/// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a +/// function to call. +// This is split from `HrTimerPointer` to make it easier to specify trait = bounds. +pub trait RawHrTimerCallback { + /// Callback to be called from C when timer fires. + /// + /// # Safety + /// + /// Only to be called by C code in `hrtimer` subsystem. `ptr` must poi= nt to + /// the `bindings::hrtimer` structure that was used to start the timer. + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart; +} + +/// Implemented by structs that can the target of a timer callback. +pub trait HrTimerCallback { + /// The type that was used for starting the timer. + type CallbackTarget<'a>: RawHrTimerCallback; + + /// This type is passed to the timer callback function. It may be a bo= rrow + /// of [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` i= f the + /// implementation can guarantee exclusive access to the target during= timer + /// handler execution. + type CallbackTargetParameter<'a>; + + /// Called by the timer logic when the timer fires. + fn run(this: Self::CallbackTargetParameter<'_>) + where + Self: Sized; +} + +/// A handle representing a potentially running timer. +/// +/// More than one handle representing the same timer might exist. +/// +/// # Safety +/// +/// When dropped, the timer represented by this handle must be cancelled, = if it +/// is running. If the timer handler is running when the handle is dropped= , the +/// drop method must wait for the handler to finish before returning. +pub unsafe trait HrTimerHandle { + /// Cancel the timer, if it is running. If the timer handler is runnin= g, block + /// till the handler has finished. + fn cancel(&mut self) -> bool; +} + +/// 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 [`Hr= Timer`] +/// field at the offset specified by `OFFSET` and that all trait methods a= re +/// implemented according to their documentation. +/// +/// [`impl_has_timer`]: crate::impl_has_timer +pub unsafe trait HasHrTimer { + /// Offset of the [`HrTimer`] field within `Self` + const OFFSET: usize; + + /// Return a pointer to the [`HrTimer`] within `Self`. + /// + /// # Safety + /// + /// `ptr` must point to a valid struct of type `Self`. + unsafe fn raw_get_timer(ptr: *const Self) -> *const HrTimer { + // SAFETY: By the safety requirement of this trait, the trait + // implementor will have a `HrTimer` field at the specified offset. + unsafe { ptr.cast::().add(Self::OFFSET).cast::>() } + } + + /// Return a pointer to the struct that is embedding the [`HrTimer`] p= ointed + /// to by `ptr`. + /// + /// # Safety + /// + /// `ptr` must point to a [`HrTimer`] field in a struct of type `Se= lf`. + unsafe fn timer_container_of(ptr: *mut HrTimer) -> *mut Self + where + Self: Sized, + { + // SAFETY: By the safety requirement of this function and the `Has= HrTimer` + // trait, the following expression will yield a pointer to the `Se= lf` + // containing the timer addressed by `ptr`. + unsafe { ptr.cast::().sub(Self::OFFSET).cast::() } + } + + /// Get pointer to embedded `bindings::hrtimer` struct. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn c_timer_ptr(self_ptr: *const Self) -> *const bindings::hrtim= er { + // SAFETY: `self_ptr` is a valid pointer to a `Self`. + let timer_ptr =3D unsafe { Self::raw_get_timer(self_ptr) }; + + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + unsafe { HrTimer::raw_get(timer_ptr) } + } + + /// Start the timer contained in the `Self` pointed to by `self_ptr`. = If + /// it is already running it is removed and inserted. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn start(self_ptr: *const Self, expires: Ktime) { + // SAFETY: By function safety requirement, `self_ptr`is a valid `S= elf`. + unsafe { + bindings::hrtimer_start_range_ns( + Self::c_timer_ptr(self_ptr).cast_mut(), + expires.to_ns(), + 0, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + } +} + +/// 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 + { 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 { + const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; + + #[inline] + unsafe fn raw_get_timer(ptr: *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!((*ptr).$field) + } + } + } + } +} --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E582063FB; Fri, 10 Jan 2025 20:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540263; cv=none; b=BgRt7Cx7aTnCxCMfgprwfTm5nKTqitnYPn6waGZWD+ewQ8Jr0jL5q5FRw4viXJrRWtKbF//OSgnVYQTpnpiI3r3UpwX4fl3ahYJjStugOnTn2NmzlFvIcGMa3tIauveatK8q9JOMB8ycfOJiJAkqCYNmV/Djx+fXgIWD3+JGf5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540263; c=relaxed/simple; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X5HGkk9aZNsfeparG4kMAaNxqR8eBOrORaEUI/GweEUdMGOq7XnppJIH+/YFH106wMNJCEk6bUBnnW/qZ/se+bIgHdLPqS7Es6nozFGsf2jUINfQdO2LBok8Gz0W+a5LQaZ+10quWiEEpiBOUJG15tVGe1XkuGlsU25GpriNj60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pwZbVymm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pwZbVymm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE89BC4CED6; Fri, 10 Jan 2025 20:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540263; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pwZbVymm45Tm6p1Iut4Amaj3bR/FhIHPQh082TcyoFXaWUgsa6gFVx7cJbfAtG1YG 5PAuBfMsFKGnwOdyv0H0fgVYo/wwBEA1D+Z/OKXOSttxN7OIlMtwp8I1aZciy+HNLu hZTL5zM79DEMRyiFQcuzjdzk4jSgGQybdgUxSilV0UDVvLYN2oN2UVJQjFKafM+c9C 6YdyH18j3t44hN2QJykXXhqFkr1AAyfOO6xvMgR/dpcucG/ug6qhrxoAGYfJXZIZ01 sl2PcjZsNleRIfjGxbhPonQGiSuKqXgSwASVjUcciCHv6MQi4S8jkZ5w7g4XMM3ANn 3kihKVQV3bTcg== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:26 +0100 Subject: [PATCH v6 03/14] rust: sync: add `Arc::as_ptr` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-3-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1772; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/hTO1CSieyfVZSB6Qki2DBY/nYSd8Zls9sP ROkhjjVnFiJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/4QAKCRDhuBo+eShj d2CCEACgQeBXdnCmpZnOa5JMa8yndJLhY57/2Calqg5+6/MumfGBETDL7dZkc6sIfTNR6CnYSWk VLM8O+o73HJ4CO4bauopE1MF9hTUm1qCHmX25bYlkQis5nmO8YaNCcG2z22E7HaQuS7mJwJq8DS GrQtAiRuFZ2P8g398qtDJOfR6lKgOYBqQbcHeUzZAlZqy2UPftVB07RokAwbnN+rxHLZH4aXWrs N5bnxxe6sg97alHhgxrHElJIDSDGHO1iZkiLMn4dCzhr/gTw5O/m7C7iVcUjwHXt0rk8XQiA6jt zzdKy4Z2eVJuLQ8r1Ync7Q529MuzQrJmXalff2gY6SkFWsmTGSguixsOCkIGiF4Mf1GwQ9jimg7 vYoj6MVfDVwHbHZJ++DxqO7yapxujMPLRsvpSdFjIsGLYT9PpTl3PjZfDv8dIJ6JRbta6yUC2ta rBaBh/4CHeq57be7eotKBMP5/IUwRxHfqgoZ4Y4xhENVrTNPIHOP7pZz2r1P8jJG14P8PuyDyCf tr+hhGDGuCUYxZ/DLbcQ2pXhyZqImbYK1KRRecMEkaGS1lDKti2mQmhKm/9Em4480nELVok4O+N MTv1NFrRvYFc82dfESf/GvGCoKz0dWXOQYZ4ACejN3h6jg5Ijx2tJMS6nCuzRkdsEJ3zAjZeRAQ oQNxwUEO0zhEclg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a method to get a pointer to the data contained in an `Arc`. Signed-off-by: Andreas Hindborg Reviewed-by: Alice Ryhl --- rust/kernel/sync/arc.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index fa4509406ee909ca0677b78d5ece966089ce6366..3d6111ddb007285b26eca2177a4= 12033f4ac5dcb 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -233,6 +233,15 @@ pub fn into_raw(self) -> *const T { unsafe { core::ptr::addr_of!((*ptr).data) } } =20 + /// Return a raw pointer to the data in this arc. + pub fn as_ptr(this: &Self) -> *const T { + let ptr =3D this.ptr.as_ptr(); + + // SAFETY: As `ptr` points to a valid allocation of type `ArcInner= `, + // field projection to `data`is within bounds of the allocation. + unsafe { core::ptr::addr_of!((*ptr).data) } + } + /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::= into_raw`]. /// /// # Safety @@ -508,11 +517,11 @@ unsafe fn new(inner: NonNull>) -> Self { } =20 /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been de= constructed with - /// [`Arc::into_raw`]. + /// [`Arc::into_raw`] or [`Arc::as_ptr`]. /// /// # Safety /// - /// * The provided pointer must originate from a call to [`Arc::into_r= aw`]. + /// * The provided pointer must originate from a call to [`Arc::into_r= aw`] or [`Arc::as_ptr`]. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = the reference count must /// not hit zero. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = there must not be a --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8486D1FFC58; Fri, 10 Jan 2025 20:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540224; cv=none; b=nNdqbwBQQZE45UQO61bhEHgb8DXdWHxdzn+DiHFSUZzcKKNrd6KY3cCx2rcsZfVTHcgkxgRwF1ddgPYcWVgzQsRkGbKQiX+e7Dzj+St/7LIntHVsBu46ihWUkXteitxBjBHSSiu1euj4Zpt0yK0tsP5VG61Hw+ctBibl3a19d+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540224; c=relaxed/simple; bh=qevyQGi54SiChRrkv5bMU+zfjKyXvB34zP2FU0YLPBU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EUFHcV4OxPgBUCRJ4+Tw2XQdMhap790rCvZazxUG3s2mLrOISDhVS5yxP3MB2QAKdGSN2g7YvWDO+ZFnw8Z8tEHs1cegcDSY8rfLKEjyjUHaBzaoiKN5mRDJB8JEwdiXzBPv5RQ2do2tOUU3KlTxwEzkKKvZP8iRE/uJbwmrQes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VSIAlsV8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VSIAlsV8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5044C4CED6; Fri, 10 Jan 2025 20:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540224; bh=qevyQGi54SiChRrkv5bMU+zfjKyXvB34zP2FU0YLPBU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VSIAlsV8X8xXM4CdZT50c5IYE5Asov2ionP4SMqfwgEjr46AcxTO6hdwPajXf3I+w UDp39Zwsz2HALodzt6EJ8p5L7cDlTOUn0bHQirhHuQVz240OuULm3eJ76rb2TavT6O bubjoJm9Kypj2D8rHPcMdjzEcG5uiNaxqQyITFRPVdbqY4Kj24Zchm+xCEBsMMt69x Iw4YHAMvlJtV0FH96ZRlSLLo38nAI6vokA3KS6er45Mh7aQsOgfEzC25HoYeSCTjDo ExPcrVL7/dcZ75ufJfDuNZjdgthAdJ6SiegbYFUpo+je1ePXlBgRF3jElhwhJXpO2M 6l2lbKkIZS7Xg== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:27 +0100 Subject: [PATCH v6 04/14] rust: hrtimer: implement `HrTimerPointer` for `Arc` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-4-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4149; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=qevyQGi54SiChRrkv5bMU+zfjKyXvB34zP2FU0YLPBU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/iLlWGjZB4syjgL3Eh8EKbHga7P7UGgteMP URVPZWQ7+iJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/4gAKCRDhuBo+eShj dyrcD/4h9Ub08sfnkOMJyNBce0ubVEkDWIBz63fuGULjDWnS9CXfFWgGhz7udDHv1tGvT8hWwKe rjOP/kdB1DLHWVCMBAmJ/oB1aGU9MWSMxtWGRmcefWoxp8DnXIBKAQ+dXXQB6YsT0TELtxTc2PR 9En1/si4Zdb5LUjjZSzboQsH75+e2Ce03jt9qYfbqhiL1F0h1+9LIRd7g3LhbhT+07b/6rCmWWP m84ztrXIy4etkMqP5qa+cbS2grmXUP3WvEwf0Rc0EhE7pMAlGB6Zm+6WwkUg/lBsHlUfecFYvPX gJMuQcKCr68aMSTRCG58SlIs3TUpz6RA/LYqbzQVpP0hAcGAvAw66ln3mEVVpplOsOpU68cpg4i ST8BDPxVtNRUXDx5b6SnAC4pJlqhix513eYHHu7SPHA1+vBfWl6OlWp6gMnpmypijN1+FOJ1J01 EfS5ynuklZJrQi13LxQu6xqO9DJp/zWZxfMIGJEquEOKXz/na9+Ft8LmwvUBPPQ9W90jr4PyF11 mBlNKlqlcGt5cVkHtjRvzNxMWxBhP5MgG1yu5pkg0/+XLVRCIZDOVFHFdpG+yEvCDhQDGUaehsJ EUBKBKnOqcaW2npfEgcz+3Agtdw5RVR68rxOgsyAl9cjmbTMgZ6fkU4ZrOeLrfTVPn7vcybJF8l vZJwIltnvLyyyAQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows the use of intrusive `hrtimer` fields in structs that are managed by an `Arc`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 3 +- rust/kernel/time/hrtimer/arc.rs | 89 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 31c461ddd2c377101ed6c1c7e009f7dccf458ebc..d0842c7c4c6ddffeef9a79cbf97= 27819060e4333 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -98,7 +98,6 @@ unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrt= imer { /// # Safety /// /// `self_ptr` must point to a valid `Self`. - #[allow(dead_code)] pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; @@ -294,3 +293,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } } } + +mod arc; diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs new file mode 100644 index 0000000000000000000000000000000000000000..4c1812f190bc7a9e0b2fcd5ea2e= 320f45ba584bc --- /dev/null +++ b/rust/kernel/time/hrtimer/arc.rs @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::HrTimerPointer; +use super::RawHrTimerCallback; +use crate::sync::Arc; +use crate::sync::ArcBorrow; +use crate::time::Ktime; + +/// A handle for an `Arc>` returned by a call to +/// [`HrTimerPointer::start`]. +pub struct ArcHrTimerHandle +where + U: HasHrTimer, +{ + pub(crate) inner: Arc, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl HrTimerHandle for ArcHrTimerHandle +where + U: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr =3D Arc::as_ptr(&self.inner); + + // SAFETY: As we obtained `self_ptr` from a valid reference above,= it + // must point to a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` points into `U` and `U` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for ArcHrTimerHandle +where + U: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +impl HrTimerPointer for Arc +where + U: Send + Sync, + U: HasHrTimer, + U: for<'a> HrTimerCallback =3D Self>, +{ + type TimerHandle =3D ArcHrTimerHandle; + + fn start(self, expires: Ktime) -> ArcHrTimerHandle { + // SAFETY: Since we generate the pointer passed to `start` from a + // valid reference, it is a valid pointer. + unsafe { U::start(Arc::as_ptr(&self), expires) }; + + ArcHrTimerHandle { inner: self } + } +} + +impl RawHrTimerCallback for Arc +where + U: HasHrTimer, + U: for<'a> HrTimerCallback =3D Self>, + U: for<'a> HrTimerCallback =3D ArcBorrow<'= a, U>>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr.cast::>(); + + // SAFETY: By C API contract `ptr` is the pointer we passed when + // queuing the timer, so it is a `HrTimer` embedded in a `T`. + let data_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: `data_ptr` points to the `U` that was used to queue the + // timer. This `U` is contained in an `Arc`. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + U::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CFD9218592; Fri, 10 Jan 2025 20:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540235; cv=none; b=WP/jS5qosbyzyTHJ4Nw1qvRWrdoCgw0NwvFSC+XHY4gPOTymGcVcvlfJAgMO1xzPUBOTnoJfUEOG6Xt9Q3uktbgVNffIpWQ4iMikST7RGfe++VdSzp58AQjKGlCNywrXus0ahRg9oiWv3Ty2lPiYsFDs/Z3MxLjfdGW004yRKAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540235; c=relaxed/simple; bh=nPGdlJp4Nza1iyCRFxL+z26yGf76gLwJEu+2wLItMsA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=au7S6NuaFlyxbM4dzNGcKpZI2WzvFODGzfkJs8C0ktRuhD/5d5qsHghasgr2LRdJjAzmsKr2ZwmNEkAu6w7W5/RZKr62EzQnudpBXHUyABSNIIJWL0RKQkSyg9HAmC7B0/6IFk6HsiX0e7ZgxyMYQsMcjvqrxi7mOBkkppQ9ywQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iitC+UxZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iitC+UxZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF260C4CED6; Fri, 10 Jan 2025 20:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540233; bh=nPGdlJp4Nza1iyCRFxL+z26yGf76gLwJEu+2wLItMsA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iitC+UxZuJI5S7Hj8M7QTCsGRvMmy9m0ySuJ6YmmAEPTJ8XmRLG/T8HnOtnb2zzVh pxYTOaYsAQk+v73cJXDF6k+PoQAW/Ni/alrbrSTNtsxjWIBax465d3TaZy05OOG9gr mevsBfCa+/5WBLMdiiKcMH/DL29hwBZhH02TXrwE0B068EoBzl/GM/6gJs+cJoGzt2 3TJYq8Y9Y6YxpBqteM5Z+ExwDoPUuiQFab/3twvVdUafZXWmQjueJyYt6oZMNulfH9 xhS7ylTEnFtpfnY1Exx4bMPGXuhlmlDrX67QbzBFkrj2NB1o1NSRRtcnPgHdm+i0YL 58Fjpyr3Z6FWQ== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:28 +0100 Subject: [PATCH v6 05/14] rust: hrtimer: allow timer restart from timer handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-5-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2681; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=nPGdlJp4Nza1iyCRFxL+z26yGf76gLwJEu+2wLItMsA=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/jvGsC63ejg77FE9GT3c7583mCWWo1jkAEW 88iKj14Z9uJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/4wAKCRDhuBo+eShj d+52D/0aLkeZXH33X2KCz6HJk1V7f/4YSS/MrRH0nA9qV3zVtNySlMyIuKeB2LyNZl8Smu4M3eD chb1OYZWfzE3UYrfPV5oCTqMwZcI8Q3sNabi6AofqL61MJV+hHjx04FDUQwv0SZq1SuuBG4axyR CAP7crM3wbEPbu9hQFiulnvXhmdw/W2wQ1KoEULufh9nlWoKqzca+sxbGuE3yjYMJQ6zWQpaimh zST8DDtnfoY4H2nfTzfFOQu4ez5RR2xIJKIVGhk+kfbAgpw6FI0R0Y/z/4dcB45oQ9zF8Ht2GQw tuJLq9Qe9EOi7mnvnSl3ypfCoMy+3OLk4kh15uno9w15XY2lzOwdvDjC9Pf+wx+tNoq7/WexWRG 4oirBivmQHTxG6xxlo/9S60vVIp2z6f4oyKDSU7thxzmOUnKI5qNIWaoj2un80cYeyYi7SFwkN+ PyJJLCBn8MLQB72GQP6p/eNrTN6JS0E0ii05PZwKdQRQHZ05Uu9tarY6bIen4M/Linrl8KpjO0n Zbfv6D83ntuWhfjU93ueBpDA5vx4xrC1Hcc4ik4v58+W1Kvwfl++3TnE3ETYctzcYKrjEBcjISL b0x4uy9PDqHYlH0dEqDGHGxBvJNMTmoMj8sn20TFzt9f3+fDWxZb+E1kuGusHivEd2K7AV7pt+p Xv3Byquz89e9XNA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows timer handlers to report that they want a timer to be restarted after the timer handler has finished executing. Also update the `hrtimer` documentation to showcase the new feature. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 37 ++++++++++++++++++++++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index d0842c7c4c6ddffeef9a79cbf9727819060e4333..50e8c23578b5cf7196893ac88d9= 547fc027f1f04 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -167,7 +167,7 @@ pub trait HrTimerCallback { type CallbackTargetParameter<'a>; =20 /// Called by the timer logic when the timer fires. - fn run(this: Self::CallbackTargetParameter<'_>) + fn run(this: Self::CallbackTargetParameter<'_>) -> HrTimerRestart where Self: Sized; } @@ -262,6 +262,41 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime)= { } } =20 +/// Restart policy for timers. +pub enum HrTimerRestart { + /// Timer should not be restarted. + NoRestart, + /// Timer should be restarted. + Restart, +} + +impl From for HrTimerRestart { + fn from(value: u32) -> Self { + match value { + 0 =3D> Self::NoRestart, + _ =3D> Self::Restart, + } + } +} + +impl From for HrTimerRestart { + fn from(value: i32) -> Self { + match value { + 0 =3D> Self::NoRestart, + _ =3D> Self::Restart, + } + } +} + +impl From for bindings::hrtimer_restart { + fn from(value: HrTimerRestart) -> Self { + match value { + HrTimerRestart::NoRestart =3D> bindings::hrtimer_restart_HRTIM= ER_NORESTART, + HrTimerRestart::Restart =3D> bindings::hrtimer_restart_HRTIMER= _RESTART, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs index 4c1812f190bc7a9e0b2fcd5ea2e320f45ba584bc..cee143b04aa21fa6c60c3363cd9= 5f7a67360cbf8 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -82,8 +82,6 @@ impl RawHrTimerCallback for Arc // timer. This `U` is contained in an `Arc`. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - U::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + U::run(receiver).into() } } --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B891211293; Fri, 10 Jan 2025 20:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540238; cv=none; b=PgPNnuXtWL0tFMLq3PU1ijAyKD/ugnVovgCw/vxgu6v+jMb7PFAHH1K9DlIXWuzL5yo36Z8qx2jwZiUcgDMDnNKabDje/8CUobEJm0Fp7KtNkIimr16yAeftjUs7Bt98+fUwoc2syFR26iuJfsHfOPIZSqn2ezzMwpFzVNO1Zaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540238; c=relaxed/simple; bh=LCgcVTcyzsEKe4YQ3SqZUDNTdG+7NYQXBadOUqn4/2Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HhovZ4KqiFqZ3CVYmswNjtYk+O9YYnBFeae6zHHpkNzzdS7DmO6SOSaVrqsKypSy1k+nEFbgAacVPHfAjeHzY21sPPgfvundpUCNBMwiBZ55ilNq1NiptLTWs/T9zaOs3fdLWYhcitTwSqWVJ+FM2I1sT0GaijYvOgaiWb7ydjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WU2YPOMV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WU2YPOMV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82624C4CEDD; Fri, 10 Jan 2025 20:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540238; bh=LCgcVTcyzsEKe4YQ3SqZUDNTdG+7NYQXBadOUqn4/2Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WU2YPOMV7x7qhBHP/xo1Pg8nVMQcLPZOfRKVpmRpUOTjOIZY7PRHRMo+1hpGUm/EY bQWycqkto4lhDstgQVsGQwsSVKjK8FFF4DxC1V9hBn8QXpFbjC4G3iAaWFz76deMRr 5U3SWjtuyfsykywh/KQ4lQFrJJg3veW98bSiocd8Xg7L1aYcePnu0ZpxAewul5FjRJ HSgb0jTykmGCfzyKOTDPhPi14C++EXiXQ6A3DIbd9qmCEMEnt9t4byix4InfsG15Io VwwnG/BqMavN+D4ZkQ0//F/YXP5oxqTtC9Bjb7DRZXr+b7Mu+2nFx4bjj7zSD4+Us6 zB24R3pURYn2A== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:29 +0100 Subject: [PATCH v6 06/14] rust: hrtimer: add `UnsafeHrTimerPointer` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-6-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2123; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=LCgcVTcyzsEKe4YQ3SqZUDNTdG+7NYQXBadOUqn4/2Q=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/kij7Y6DfzKBNgjNnODHOQNarvbZpxQUU+w ahfabMpwM2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/5AAKCRDhuBo+eShj d1enD/9Hgf9hRb45eW2Iru+exfiPAAydRq0JMc1jDkPXIhfe0UiQSwQSSre6FIJ52oyK7tjps1E r4ThLJIeG/nphiWNl9CMfDjL2IeObAkABKnA4toNNFvHdc+wJ9bEv8AzQbmLB4ZOAj4Juw+kraX UkzGytJokoGRHR1cCJPPcOksPHxBZ5Vlc3WIbRza0/iFymrJ4hMJ0bZNlIYHWGI2xGP7nE7Quqr 0/78BgzVndLEiQDZjGB8+yNn9/1mVHjF2lPS0h9Xreu8pPz3ysGvLnAEWCwxcI0SXp9zu/dlT/a cH9q01fwGNV+EurxFGhSPfHBaxmDUSwtGjJ1JN6+bcL9xYi8erehQNaw8JHS78VMX4zwYDSpYDU ePOLavpE42g3WFNqT1XKHLsSR0CKIy9PbUXVJYBqBbbxqfNofSOywwE0zqSB11QwiCoRdFvPGFH M8sbR5k/VO9+qqRaHwD93HkwgJAYiUQD19Bo1tf8rkS4tjDxGW5N/WNBVLNHsSgjUlQtLOR4Zte 2yK4IAygfHQ8IZa9bSOnbfjDSkSyNW5oJ4NtwHO1lo0lgrXREvodDvkHRRq6P7ItorjqeuW1t+T OWSbtLT/kokqeV3/sn+dK3q10p9bYL28BnhxA4G0IgZMoG0UKhWX5n2rXtFmzSZKivSgufk4bKB 4ogyRVOr2GzkRUw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a trait to allow unsafely queuing stack allocated timers. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 50e8c23578b5cf7196893ac88d9547fc027f1f04..aab998b02f19b774d5b04ae2c89= b669f13c4b0c7 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -142,6 +142,37 @@ pub trait HrTimerPointer: Sync + Sized { fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// Unsafe version of [`HrTimerPointer`] for situations where leaking the +/// [`HrTimerHandle`] returned by `start` would be unsound. This is the ca= se for +/// stack allocated timers. +/// +/// Typical implementers are pinned references such as [`Pin<&T>`]. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that instances of types impleme= nting +/// [`UnsafeHrTimerPointer`] outlives any associated [`HrTimerPointer::Tim= erHandle`] +/// instances. +pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { + /// A handle representing a running timer. + /// + /// # Safety + /// + /// If the timer is running, or if the timer callback is executing whe= n the + /// handle is dropped, the drop method of [`Self::TimerHandle`] must n= ot return + /// until the timer is stopped and the callback has completed. + type TimerHandle: HrTimerHandle; + + /// Start the timer after `expires` time units. If the timer was alrea= dy + /// running, it is restarted at the new expiry time. + /// + /// # Safety + /// + /// Caller promises keep the timer structure alive until the timer is = dead. + /// Caller can ensure this by not leaking the returned [`Self::TimerHa= ndle`]. + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; +} + /// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a /// function to call. // This is split from `HrTimerPointer` to make it easier to specify trait = bounds. --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AEFF215195; Fri, 10 Jan 2025 20:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540243; cv=none; b=LtHp7rG/HFobqJ23T0xO6G3MUkmJQKrmAwIApgR6W1DY9pjfMQ72J7WFealr4FtbAYVu3Isgk5BG9ygH1zZ/NC63chZtRoPg6eemrkpqNJlRFObQzp0Gxyxc3CETg0O9DrYtJPyoyGYG1u1/3DH7SV/YlX4r+6XPAmeKuuXdTsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540243; c=relaxed/simple; bh=sDYU+nUyIdb+VKBxdBiq95UuW2yrY3C0WdXaHg/sCFY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a+abWYDwEYl3f4LuE+nSAHz9x/QS1zBjuNAXfLe6M5JXuDyOINtlar5W0rG8RuSqfaHhQlH+8c/oA/YEUfYZ8Co3fDZiq2nHKQNQc00kMpOG+LhPTO7x5MKXxiPQenyQzMwMm3qb7HTodjAJffB1Z+/dJCPi7nsQFH0PogrT504= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FhE8DQuB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FhE8DQuB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AED2C4CEDD; Fri, 10 Jan 2025 20:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540243; bh=sDYU+nUyIdb+VKBxdBiq95UuW2yrY3C0WdXaHg/sCFY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FhE8DQuBLTtcNQjXaiqiiZo7JaEaYbgz9du35lr+/wLfIf8DkkTWDCBGc1QT6TyZT tnz7Fe64lhkHN0xzTd0RVuOq6xsdjOwWKTuFv7fWpQq9lmdbX6Y0OdVxTm/vPBlwOe vC2FJxVmquF2UYbuHw2hnkmZCCdtw5M79k9Ssm4KsgG2Xtn34Lw2HW+D6c8GbscalQ s8F1LZR3KMiyFR6kl6+KXPSwIIQt85nXTPb0DS6qjiUi0kwRKuqxDyPifn2Nd2H2xc +p1/PDuOaQfaI/YqxM848vVsaFi3l1VjGST/B1cFEk/+GJSNefX8ct/KC36GVMyFsM XvE6di/yo5gow== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:30 +0100 Subject: [PATCH v6 07/14] rust: hrtimer: add `hrtimer::ScopedHrTimerPointer` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-7-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2093; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=sDYU+nUyIdb+VKBxdBiq95UuW2yrY3C0WdXaHg/sCFY=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/lLHotfFxCxaeXyuMCPCBwvrv0+Z18x8VDh itk8VuZLbGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/5QAKCRDhuBo+eShj d8ZgEACE+rzW+PC6YjBEj3iFjB7Jx+5XVpAEsipwVgNJN6BNWS00BFvH2gxgpvq+03WkO/2tMSc kQJ5FIUo4KcPIg6jHz/LA+trGlvWe+4birklpSd8XjZg2Bz404Q9bS8MWfkUOHSQjT7S1G7nysw QHl0/JXQFlbNZj12Ts0y+7wb+oIYlw8laFmDoI/fHnVkAqSOvhTyNCXfSoIpDb1VBZ0kf/nHHuJ A8iV7QzvEt5TfaekK2PYmjgvCdnMCbdHH9gUsFHrmS4AllTsdtJCYjSQjsPbivSCYPDRd4HwEIS dLYAmi1mkXt8V/YtIfHm1OVy2Ya5jACxs+KZl+d880ResFCOiE67iOUFYuO6hY9Um/ovpOMly5J xAtAxcwHfD6LkbO6EGcaVOSprFPnU4Si4mpIaAXnbNvgxR3YnLRIMpLuvI13bIA+6IifVbzZtpX 4lNxURyvHMaJwKV+cABPXzVa7dXie+TdWzX68Rgrf+NjXE6Z3W3FeY4yp5JuLRvLGxDVtm+U314 ac+ptqBjwjS07pKRXoK6IzdUZf27ndNMKLM4z1AQaDbYXaatTmWV7tQO1LT6+EIjx760/7iIFQA fU6W4PxjS3VU38DZA2+TFZc+kY0pwmsWp4xdkAdFQuv5R8XOxGD1V8lYQs/DIj5NF6D3vehDxRa p5MXr6rajRepS3w== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add the trait `ScopedHrTimerPointer` to allow safe use of stack allocated timers. Safety is achieved by pinning the stack in place while timers are running. Implement the trait for all types that implement `UnsafeHrTimerPointer`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index aab998b02f19b774d5b04ae2c89b669f13c4b0c7..3cf81b5bb4c7071e095948f3220= 232a15116ed5b 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -173,6 +173,39 @@ pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// A trait for stack allocated timers. +/// +/// # Safety +/// +/// Implementers must ensure that `start_scoped` does not return until the +/// timer is dead and the timer handler is not running. +pub unsafe trait ScopedHrTimerPointer { + /// Start the timer to run after `expires` time units and immediately + /// after call `f`. When `f` returns, the timer is cancelled. + fn start_scoped(self, expires: Ktime, f: F) -> T + where + F: FnOnce() -> T; +} + +// SAFETY: By the safety requirement of [`UnsafeHrTimerPointer`], dropping= the +// handle returned by [`UnsafeHrTimerPointer::start`] ensures that the tim= er is +// killed. +unsafe impl ScopedHrTimerPointer for U +where + U: UnsafeHrTimerPointer, +{ + fn start_scoped(self, expires: Ktime, f: F) -> T + where + F: FnOnce() -> T, + { + // SAFETY: We drop the timer handle below before returning. + let handle =3D unsafe { UnsafeHrTimerPointer::start(self, expires)= }; + let t =3D f(); + drop(handle); + t + } +} + /// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a /// function to call. // This is split from `HrTimerPointer` to make it easier to specify trait = bounds. --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C071521D582; Fri, 10 Jan 2025 20:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540253; cv=none; b=pya1mLoZoIgCYlFlZXC3iX/HFS3K4ZAkuIUZQ36cJfNvBGLJNHgVxTfHqiG206Knaalb9ZiFhuZlw79lPbexksJdxq7kv4pTXft11wuYZ8X/R8/A5Jiq0BDNTKNAnSiZA/pa93k54Ab6Vo0EnZmVwGhYxV6z2OVlE+CVWmEKL7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540253; c=relaxed/simple; bh=zomgbshZi6OHqg5Y1mE0Df1ZCQ0F2yAc8VQTQ21hLQc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q/KMfFyZ9TWs+BuHzW+/CSQbYNtQg4g54WWp1KwhmpSsbt2RHswqqB2iwuTWUAbyPNRYtNWCUkpP5XVEikkrTfl01LHKRYz5greBL0hYkCU4octmZ2egUL3m7O5Ekr7Nh2BPcXcJ65ZjtELZFz3yH5l/MxAP4WABfz5hNeEUvRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HDRwvUpd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HDRwvUpd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11E3DC4CED6; Fri, 10 Jan 2025 20:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540253; bh=zomgbshZi6OHqg5Y1mE0Df1ZCQ0F2yAc8VQTQ21hLQc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HDRwvUpdGPzVM8tH98Q9AASYdYQK9Ie10xe0lgCG5jhabIliaH2zMUBdr9DsP/krr DhXcOAPwkDgVC8mm4Y7ovQsLWzEa/HNsUIbQk8/Pkou0sPOnH0cMnz2lJTPdV+GAZ/ z5l3h99mfBezGVqYGC78g/MglmgFkTH37lsaPwrI/vlNf0V5h03GKGRC8nfD+hBPCH KPf162nJBwDRDw3Ds6MSrUgdXgvgkgchtCk0LxB572w3RFyYfXTvPlW2VQ1M1ctqbw 2Ydl8lxA3vYcacE10wU2yzB2E73eJbIPg6n76Q5lUnGNr1PKd0O6lBAzV1KhY91iSv e9BunkQUXnKgw== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:31 +0100 Subject: [PATCH v6 08/14] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-8-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4086; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=zomgbshZi6OHqg5Y1mE0Df1ZCQ0F2yAc8VQTQ21hLQc=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/mRVS9CM6G+mx+PmnxWVWSs8v9zDpM+R+gm 461iuvRL8CJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/5gAKCRDhuBo+eShj d+5DEACn94SoGniFSSy5vS7DaoGk2UMUi1nIn8ywJJHbbDUOSDDeInDahPWM9l+yOwVo+n5jnRu e1k17SSNelLxD7B0rntvuICt6i3t0limCEFVKPEZkxGULvvxeHKODdSnz+2GJEovqmOuoQHOTGa iLn7uc4K9WMfN7JZp+OQOMTxpDaWWtL9W8DDPJnHv+4oIqXW7IgRP8JvejJ19ujF+ZO4oYuF0S2 GHYuflPaIjA35tt7kRbRrqGczKYLjeuLVzqr7e8Ud1WAxf1Wady1uWUyC9uCf0vLRXDiy3XAD0V xtbSTuy8jZnY8IGXIMfC5m7UadjlTUmMW65Ns62o5nJ8kKap0G0tft61GhwOld52dT80EId/J9v 7yLdHldmknrTVjm8pW229S1C9Kzy2dbi2xmmZ12YfgdmzW9QnatrEb+e0y3GtUbo5kPAp0Vz5BJ VhcFMPw7sDRiRNbO2blXfeRcEOF+rDIIioglk3VFq95Uzuaw7n+7F5CiPBXYA9Q2uh/85B5i8By CM5/vnR9urZ2VhiLVpterKxgTamMLwUtqaE2zOR424dMGDodziS4Mll7zSGGfV+Jg29yhJBq8+Q joAmRUxOpQVfTpFbPno9yjvpcHomEZhUDsE+v4CW4sltZUrbIWFSAM4zHCZ4xBJGAuzxRTSPXDk slV9T154ChsJkOA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned references to structs that contain a `HrTimer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 1 + rust/kernel/time/hrtimer/pin.rs | 95 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 96 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 3cf81b5bb4c7071e095948f3220232a15116ed5b..d776e93584a87dfdc646816a16b= acf19e444217d 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -394,3 +394,4 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } =20 mod arc; +mod pin; diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs new file mode 100644 index 0000000000000000000000000000000000000000..2f2d1312566c5b8a763fdb8e028= 3dedb0ca3e231 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin.rs @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::RawHrTimerCallback; +use super::UnsafeHrTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&HasHrTimer>`. When the handle exists, the timer m= ight be +/// running. +pub struct PinHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + pub(crate) inner: Pin<&'a U>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, U> HrTimerHandle for PinHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr: *const U =3D self.inner.get_ref(); + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `HrTimer`. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, U> Drop for PinHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a `PinHrTimerH= andle`, +// so `Self` will outlive the handle. +unsafe impl<'a, U> UnsafeHrTimerPointer for Pin<&'a U> +where + U: Send + Sync, + U: HasHrTimer, + U: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinHrTimerHandle<'a, U>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `U`. + unsafe { U::start(self_ptr, expires) }; + + PinHrTimerHandle { inner: self } + } +} + +impl<'a, U> RawHrTimerCallback for Pin<&'a U> +where + U: HasHrTimer, + U: HrTimerCallback =3D Self>, + U: HrTimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr as *mut HrTimer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `U`. + let receiver_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `U`. + let receiver_ref =3D unsafe { &*receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + U::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD401218EAB; Fri, 10 Jan 2025 20:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540258; cv=none; b=CeQ2yHoXqtaVSjkeYbUl5JrKMzvmLCBhvFe2NULAooqYo9fwnRALAcrKH+1THfOPALMHUIru1rS02RuK7cyqDYTj0A3evTtjGYIiZfqrlgqsSVH3tdvU9YECKINf91XQlmS6TV8OvEDqA5Hliw1DTosmHE60+N6hwo5O9grzNIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540258; c=relaxed/simple; bh=cmhFauQI7O/oexdgGkRHky+PEc+0YuhEk/L5EibWW7Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U59kFkF2ClevHMQUgFX55moAKMf/J5gkNTe+4FdcpJByAsvcTidkIIL/IwwmDbigyiVFF7hgNUwNsqhGhoTA2AYieNOiLrhLLbxdjg6Twva4RWNTpe7QjbIRyThuEEIuepWFEdFEmdRJjNypnGHPwUTT5rZWsLJPgFvbUyxizAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CHG1waOK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CHG1waOK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F08B9C4CED6; Fri, 10 Jan 2025 20:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540258; bh=cmhFauQI7O/oexdgGkRHky+PEc+0YuhEk/L5EibWW7Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CHG1waOKDdZap58v4etPY0gb2mU4wNnq9hnHZm3Gvque2RJ4jC/uVxlxTLt4UJYh4 tYuXcypK2uvF6OBQVngXJIWjLzzGX4UnkCzdTHCesjQUF8oGEuL9nmN85kauT4fjdR gI0Ddb4hWUHrxFM1KX3YSZMvlIGhO2NURA+9yaS1Pc9t7oIfuaVf38NYY6PLE9svlL RonngYC6myVtia/LQ0BjQRxpK5rBVNywNsHJMjKht+IIS+UHgbfZpmCuzlGodLcgt+ 8VtV28jR9owL5xM4/hlfRa48UGNKJl2GFp+6dlxc7VCIitW1xXpWgUH948h61aPjTs ++R8ff6nBqSyQ== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:32 +0100 Subject: [PATCH v6 09/14] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-9-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4300; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=cmhFauQI7O/oexdgGkRHky+PEc+0YuhEk/L5EibWW7Y=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/nIFloagUvml305A/oD00NwmJqUOyb8W7W1 l+o+yTCxKiJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/5wAKCRDhuBo+eShj d1B7EADDGS8fKhObnpKbqA9/q0G1Z10/jt4FSTtfV30dWxL9jQexu22m+pkXFk+d6S8/+ooH2t5 6bh6IcTmBEwfq6OglMUi3c3Wu8dTyhapfwXxMLjXQhUJkMKvKKSSBOT17ui1UARFqGAE95SglCv XwM30TrqhB7aohgpNHVBO6yUH0OL6+0lF9A6JFFcEJTaLWF0p2l7oL0lpmBzwXLr/l+cMZztdj1 7iP0/eunkGbreQpKTkQUe8iEL6hDIIU4B69sDuHL/B6tr+lK4KGL/+PSmXn7VSQPMt9xpTaezUA UoXZyrsNn7w4SmwiZHdvTO6vUjSy772QO6F7T5ONOXk3CYM91Ys7FLP2BTsdNgaINtmBrbljgED WdSUmbXEUVtbnwgepAuE8vYAeSkmRIxAdXRB5ZiqfrF39n3qzaYz6upDP/TaF2X3ZQaiUY76VGl m0SxEPo0uSKV9hW+ls+RyidT2BR7vG6ug1GwLPm+EqgRnDcW8P93L92cS/VQ6y71lFvA+9ewyK/ NQ/ebJuZff5JKtCpTJn9xQNs5D5u5XRlJ1jfj3eR7msrimJgF7DisSMBH9fxYH/2aMG01XzsVCq UHFWVLWDAiMSVOTM/cUCLgB8DBPiLjmT/ybn9U4rn5q5a8A0TnrTlFQJ/V03g8OFR/KvKoe0oX2 TsBpsV5CbZd6O3w== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned mutable references to structs that contain a `HrTimer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 1 + rust/kernel/time/hrtimer/pin_mut.rs | 97 +++++++++++++++++++++++++++++++++= ++++ 2 files changed, 98 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index d776e93584a87dfdc646816a16bacf19e444217d..9220a8f559271c7eda8d457dbd5= 2cf9e4800ec14 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -395,3 +395,4 @@ unsafe fn raw_get_timer(ptr: *const Self) -> =20 mod arc; mod pin; +mod pin_mut; diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs new file mode 100644 index 0000000000000000000000000000000000000000..adcbba2b5ca9759fbdcc235ba75= e006e35724d10 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::RawHrTimerCallback; +use super::UnsafeHrTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the tim= er might +/// be running. +pub struct PinMutHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + pub(crate) inner: Pin<&'a mut U>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, U> HrTimerHandle for PinMutHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + // SAFETY: We are not moving out of `self` or handing out mutable + // references to `self`. + let self_ptr =3D unsafe { self.inner.as_mut().get_unchecked_mut() = as *mut U }; + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `HrTimer`. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, U> Drop for PinMutHrTimerHandle<'a, U> +where + U: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a +// `PinMutHrTimerHandle`, so `Self` will outlive the handle. +unsafe impl<'a, U> UnsafeHrTimerPointer for Pin<&'a mut U> +where + U: Send + Sync, + U: HasHrTimer, + U: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinMutHrTimerHandle<'a, U>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `U`. + unsafe { U::start(self_ptr, expires) }; + + PinMutHrTimerHandle { inner: self } + } +} + +impl<'a, U> RawHrTimerCallback for Pin<&'a mut U> +where + U: HasHrTimer, + U: HrTimerCallback =3D Self>, + U: HrTimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr as *mut HrTimer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `U`. + let receiver_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `U`. + let receiver_ref =3D unsafe { &mut *receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + U::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B624218591; Fri, 10 Jan 2025 20:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540273; cv=none; b=qpKqPpSJVByr/mfAXUTs7hz8bgetA6RrC/TwX3icbs5J2xleuKE1U7HL4+E+FH+DuR+f5t1zMK2OuZNXn2cW52XLVAAlmjvWhNojgsNvfRLM4ImhHtGLRcyQGVx7adR4zI2Vak2ViFtWf2F/a76b0/AimaSklyfflprGX/kxNwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540273; c=relaxed/simple; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lAolsiDN2tL6jWqmd5vP7Pf3q3Qi8n04RrLd4VyJrd/rHZoU17T3c/VqT0DgE0UaCXcuwBelBZTxjpbnqYuQbJfslo/ccM0kHs8b1i7f6s1vAbhCrmiltJ0tbVhuxzToaczG/chRSX8X/fEsbFmSB7wtnAuryqZGmGw738NfNWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n34ZU7Kq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n34ZU7Kq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3162C4CEDD; Fri, 10 Jan 2025 20:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540272; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n34ZU7Kq3P1MBaOpwEDTfDSvv7WWjyaJdpaCwccYPzqJ4rVYAbgXQV8JKQiEZ36Hw HBtELsuOrI6szk+4y+Ghvbz8F+fovwOiFltLfOjEzqk/FECYvdjH+/57f3/ZlbTL5v brAMojToNmw62YRzex/sK0aqrokeF0TrodGSzlgjS5jTSN6QItkCHihLSGnPRhHopK zkrUBiszzbY9/4IgjIzHDrW90/cAimVWHPV3/bKF2ZB6BdimGAcIyoJwHX9ZZiFMmQ AmOzrrmj5MSAqd4nFUlIpqe9huYBVFFl97nF9Sue5nqRtCBTpgTt30iGwz2AD0zP2b NpIDM9nVoMljg== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:33 +0100 Subject: [PATCH v6 10/14] rust: alloc: add `Box::into_pin` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-10-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1038; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/oOsQNDhHkpQXDDPcdFRBxzT/F2wCQNzHEW H70jfLunpuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/6AAKCRDhuBo+eShj d2bmD/0Xkf35dAsl4/d44U1yWTvbND7/B5ulUuD0nu47wpqDZGW9gRBKSSSvehQo3B49IhrN/vl c2OA+Kd3EPcpA+VpUcXxyOnZbHeKr4rrI55sf+WQ/q24yhNGD7NvR7dkShv/saGlxtYB1mAgyP9 NgZRXH0Inj6kq3K/jz2m80Hj4ZcwrSkgNPESPTTYZ74SEgsq32Orq7cK5MiqX1fupphjOPUcIAZ u+Spsm2SNiiwuqoyZ9v8JdMMdyeAP/sxkBEIB36saGmbWV26hvGmfk2Sx/LbSN8P5BeQ9YvHMlV 9pj+FAg8MsjWPJYIVKeviCQFelVF59O8vE/LGHdEdnxxzEQe9UwmfrUQkoJX//ISK8yfMwkG8Fn l5nbGoUwDk+JNpEP04RwoU6demSGLty0+1dnJyDvVyi4YhDA/2hZid/ttF7yKcdybJ2SLp5I+Js 0Nk/P0dUXGH/weIzmSrq5l0wk6nPeXi3sSlVTxXE3ZGu2F6pvyiI9efUNxCgLlqw3fbsDAKjJyg 1e450zNFKmeDcW8PsQt/0Bh9sO0FsbjjVvEvfleiAPBfN6nEdZck5cmcPcVyH1f1na80fts8pYf xtPGuYiWXnTYxc7mJ3PTJTp32dD8j/8UMi6gbCYAglUw1qG6YAqNItM+PZ+W7FXU/YLpkC2Q7Qk jULqMKo+Yinkqeg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add an associated function to convert a `Box` into a `Pin>`. Signed-off-by: Andreas Hindborg Acked-by: Danilo Krummrich --- rust/kernel/alloc/kbox.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index 9ce414361c2c6dd8eea09b11041f6c307cbc7864..76f29e2ac085e19871f18653cfd= df11d2594682c 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -245,6 +245,12 @@ pub fn pin(x: T, flags: Flags) -> Result= >, AllocError> Ok(Self::new(x, flags)?.into()) } =20 + /// Convert a [`Box`] to a [`Pin>`]. If `T` does not imp= lement + /// [`Unpin`], then `x` will be pinned in memory and can't be moved. + pub fn into_pin(boxed: Self) -> Pin { + boxed.into() + } + /// Forgets the contents (does not run the destructor), but keeps the = allocation. fn forget_contents(this: Self) -> Box, A> { let ptr =3D Self::into_raw(this); --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DFB8223302; Fri, 10 Jan 2025 20:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540269; cv=none; b=s85jfuC1iE1W29nm83ecU293I8qTS+S45sp9k1/JuL5j7caTn8N/8/qbKoOvSj+Ni3ASSvxVNtIeHUgYeunPV9QfHm8NlupIaha7Vklrhdw5uUi0GwHQ01wwzCtXfEwPbJOlUiRZyhiI1ep+JXRtR46fb5F69IXR+WbySvdXbaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540269; c=relaxed/simple; bh=KHFb+IIBdpz2xEoLQwymEqJKgA02luyWT3ITRG1L3T0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nGVpNEo3vuNrgKzU1PKfhp0HV4dWvxBxMHCydNs5ReTOK1K/3NQsH0MxeFwP0UPBmg37Bqh2XJeMrLPqH440UAUmh9RbZpsjJyKhNuO+5wfpLDEPOgHwmMsQ0LM7PfQ61zhm7gAp8B7x3acJEU3MCt6Jkw7cfaUFI459GJKh/Ss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dWfNMsx8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dWfNMsx8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7C35C4CED6; Fri, 10 Jan 2025 20:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540268; bh=KHFb+IIBdpz2xEoLQwymEqJKgA02luyWT3ITRG1L3T0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dWfNMsx8FEtfj501J1ijdXyPsa5Jk283UzeCkvt4mLXAUIHVboYkarZq+DxMKjXFd nF9WZ8Pr/EtD8baqqiz+pstTCiZlciJKz0IK9XnM0Y10WZDvZdObd2XIiE9j8zAAOm ZuLCnjMNMpISyJ2aDfnk9abSzE44OnXXoiqwOSC225w8jBhWFbiUHtwnkzU9i7eYcu eB+BZDTURDyDPC679Ku0W7gv+ezNnF2uhCodKGqgUC38RF+u3u1Nkk9Ztz4wBr5KEP aQlIx32Rp3sugGQhZETVgZZw5H47Ojap7VlSqlCP6EcAhdEu7o83WgDkB9BcyIEDmp SuDRqx0o1bd2Q== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:34 +0100 Subject: [PATCH v6 11/14] rust: hrtimer: implement `HrTimerPointer` for `Pin>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-11-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4491; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=KHFb+IIBdpz2xEoLQwymEqJKgA02luyWT3ITRG1L3T0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/pLLmxswTtGDeunIFRnAQ0SzJrga3tn5D6A qpWM3TqVYyJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/6QAKCRDhuBo+eShj d4JtD/4i0TiVEfyHUkux+vyLMAzAP8haAi5HuyJnrmHgXIFgi0SehATaOxZKOcfGbeJbtlTO/86 aQpIJvKUQINRyWz0xY0E2qD1cBxqBbnfytT2E6hsa0L2Xkpc4N/Tty+HtiHE2STFykpHFqOqwbZ MBcAN7X/NAJ44fKmm1H+t/OCe9R2PfpOy4eKYQsfyZGW/KMYIsj7SGoUDjKUJqmb2YDjuxt9BOz uZvFL5zZaHBaL3CsgYl0twWZMwwtg1lTh4814LAgS8VgIewy8mURrDyyESubsC8UZT3Mj5Vh9eK nBH3qVNajfAv0k5MJrCzJf7XUjokAOmvddg3AyjKps3+deXACTOEvsrpvON0YnYE+ib4j26Za1X FrQk/brK/gy3Ctm8FnylsIiNP2boBzVOzxhX8VXoI0/YeaLKOYTZ2M2Lz+rJrVKuB4WjeAfTm3D sgsmy51PqMOo/NaJygyxhDGko9fxvMw5I29EcQ5tAvV0qqrPScb7VnKA+snOrrvsIGBj34a0y/s zWc9bK6RxK9b3XN88raYzNt+4nPvpaABbQsSFIWO+SeNcTDnvT4dttk683hUXFsy3KQyuAQgtuQ PWVuL1bUEa/w2g2V5ckwFYryJwkCPubF4Y/5Z9SxMiZuoLFtQikQgcN2OU2upWIQOEHdRNQtCgC WNIGGkOhL5xjRrg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow `Pin>` to be the target of a timer callback. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/tbox.rs | 102 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 104 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 9220a8f559271c7eda8d457dbd52cf9e4800ec14..885d1772f7466725d2a421990f1= ae154290ccf60 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -396,3 +396,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> mod arc; mod pin; mod pin_mut; +// `box` is a reserved keyword, so prefix with `t` for timer +mod tbox; diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs new file mode 100644 index 0000000000000000000000000000000000000000..8dec40f7313921cd9f5bf357bb8= 4962480385359 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::HrTimerPointer; +use super::RawHrTimerCallback; +use crate::prelude::*; +use crate::time::Ktime; +use core::mem::ManuallyDrop; + +/// A handle for a [`Box>`] returned by a call to +/// [`HrTimerPointer::start`]. +pub struct BoxHrTimerHandle +where + U: HasHrTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: *mut U, + _p: core::marker::PhantomData, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl HrTimerHandle for BoxHrTimerHandle +where + U: HasHrTimer, + A: crate::alloc::Allocator, +{ + fn cancel(&mut self) -> bool { + // SAFETY: As we obtained `self.inner` from a valid reference when= we + // created `self`, it must point to a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f.inner) }; + + // SAFETY: As `timer_ptr` points into `U` and `U` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for BoxHrTimerHandle +where + U: HasHrTimer, + A: crate::alloc::Allocator, +{ + fn drop(&mut self) { + self.cancel(); + // SAFETY: `self.inner` came from a `Box::into_raw` call + drop(unsafe { Box::::from_raw(self.inner) }) + } +} + +impl HrTimerPointer for Pin> +where + U: Send + Sync, + U: HasHrTimer, + U: for<'a> HrTimerCallback =3D Pin>>, + U: for<'a> HrTimerCallback =3D Pin<&'a U>>, + A: crate::alloc::Allocator, +{ + type TimerHandle =3D BoxHrTimerHandle; + + fn start(self, expires: Ktime) -> Self::TimerHandle { + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: Since we generate the pointer passed to `start` from a = valid + // reference, it is a valid pointer. + unsafe { U::start(self_ptr, expires) }; + + // SAFETY: We will not move out of this box during timer callback = (we + // pass an immutable reference to the callback). + let inner =3D unsafe { Pin::into_inner_unchecked(self) }; + + BoxHrTimerHandle { + inner: Box::into_raw(inner), + _p: core::marker::PhantomData, + } + } +} + +impl RawHrTimerCallback for Pin> +where + U: HasHrTimer, + U: for<'a> HrTimerCallback =3D Pin>>, + U: for<'a> HrTimerCallback =3D Pin<&'a U>>, + A: crate::alloc::Allocator, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr.cast::>(); + + // SAFETY: By C API contract `ptr` is the pointer we passed when + // queuing the timer, so it is a `HrTimer` embedded in a `T`. + let data_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: We called `Box::into_raw` when we queued the timer. + let tbox =3D ManuallyDrop::new(Box::into_pin(unsafe { Box:::= :from_raw(data_ptr) })); + + U::run(tbox.as_ref()).into() + } +} --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 740EA21576E; Fri, 10 Jan 2025 20:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540229; cv=none; b=OPAEqmtuz9LoWXSM52a41mFajWwXaGSpm2UUfxEof/q1fUGKRHDoXXjKQNKWie95LEY9URMcMKfXLP4BbeCxXKTaUZQTR67Q74/Y7Fhj0M99T3GE/OdWu3bKr439nxCKPnA3btzIKRAxPOqoNLvYwse6ZBHCKplAnL1JJXMtyEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540229; c=relaxed/simple; bh=2B8YKUuxQpOsHzf/q9lV+i1do3MHPZjzaDxDa768d2A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a0TZ5nn5ZYbIJnP24vF0J+hlnu72ZqbIkRrMExMIHsZkwsU3GgBmkZwA0FwOq6OgFD2e3psZ/ZxqF9WMzA44jYrK8pMy0qweMA8f+R4eVbd+hWefmE9Vs2l1Nxch2K74HagOxuXDWA0dufEGIQgRDZHzF3QEXa/mlm4/FbhYdy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mijCMLQE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mijCMLQE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3C91C4CED6; Fri, 10 Jan 2025 20:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540229; bh=2B8YKUuxQpOsHzf/q9lV+i1do3MHPZjzaDxDa768d2A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mijCMLQEtTH4tTIu9MGSpNY0WMzhuFyMxY4/27UTiXxSAYL+I2lcjy63Sqem7aA5L iDTKgG3GMRY78hPGPV3UWmRZMWmnyqokPDeWIb7aMlcTpm8s+si6Wy8It8ww0nmiep nf8+YBFjGiuvo8dUJCsk7zY2msItceN5KnG3hLVl2Q5jfsgjY30Eq/n6Ay+8LWMK1K /aeS5KYXWvOmmtRGi4jrFpOf4NIM6V1gfC/uCkDL2CxP0JCHeLKffUZ3Z97SRaQFya jcqWWP6rQmV5fAJWcWurmobPFvOtwinIOAniAESx/E9tbTrFPa0uZ7PaI4F2k5QI6m Q1J+8t3Iz32oQ== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:35 +0100 Subject: [PATCH v6 12/14] rust: hrtimer: add `HrTimerMode` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-12-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5755; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=2B8YKUuxQpOsHzf/q9lV+i1do3MHPZjzaDxDa768d2A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/qAunfSjPVSarQMG9m8wJTSIFkRKoIr7BlE SU9ZI/cdOqJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/6gAKCRDhuBo+eShj d0TlD/0SuXfCjWDLVNGEuvYwrmwhY6XdNTVUl7v0m56D3HeWYyIFmuvKwxVkOzfxSRN1/jCiWce E6r6b+FMy7M7LJM5pydVynyaUYcjuzEQeE2Tb+NSkf6p+478pjq8jMwBDKtRcYGbldMAfChqxMJ taE4hKX7YiV9yEiyILkIORRdwTOpUl0zeFtMw8JnHBqvpVpQ1fiG/qKxV61lfSbADIj3n9rvWkZ BcvyyKrVfGKe0CCeEsF9CDBWwcY42nTnEV9cNs0l+3M3w6hdLMmohvY6EqadEaV19mQqSSHahcm YGNp9KS5DScA5DnkzfijItKQO226uLC5HBoQ6TRxhRQ/k5NQm27KS9l0xhP3jprTTBqH0xsrLDX +tSsFq2pply8EgFtJXXjrM/OuD4sD4eEPGoT1a3OC8vMRrFykq/WotvwV5KFOVXtzA8fGAeILvC hYXkkbRdGhPeRCWnMIVz/ohpnYZrPFX3TZ9wfr4EeBy+xREXvXihFhWEKQsf6vjB3NJY/k74smq 9mHer5HccV1eHz30nbBkj+ebBWsr8oQ6Ce9YAgZWjXnliWxpUuv+Ui501/OVaoeeoDo1Xznp1Yg Du5KbaDlRF3VkhTjp2JaY+hxqNuWL06hlQHQVDyEXZJXnjv9IJsCEil+Ij7T+CHLWznXdJEXFl+ WWtHKbsuACWxWDg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selection of timer mode by passing a `HrTimerMode` variant to `HrTimer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 87 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 885d1772f7466725d2a421990f1ae154290ccf60..232af60f7c38370a4b2414a4c37= 80e06d2aa0c7d 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -43,6 +43,8 @@ pub struct HrTimer { #[pin] timer: Opaque, + // This field goes away when `bindings::hrtimer_setup` is added. + mode: HrTimerMode, _t: PhantomData, } =20 @@ -55,7 +57,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new() -> impl PinInit + pub fn new(mode: HrTimerMode) -> impl PinInit where T: HrTimerCallback, { @@ -70,10 +72,11 @@ pub fn new() -> impl PinInit place, Some(T::CallbackTarget::run), bindings::CLOCK_MONOTONIC as i32, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + mode.into(), ); } }), + mode: mode, _t: PhantomData, }) } @@ -320,7 +323,7 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) { Self::c_timer_ptr(self_ptr).cast_mut(), expires.to_ns(), 0, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + (*Self::raw_get_timer(self_ptr)).mode.into(), ); } } @@ -361,6 +364,84 @@ fn from(value: HrTimerRestart) -> Self { } } =20 +/// Operational mode of [`HrTimer`]. +#[derive(Clone, Copy)] +pub enum HrTimerMode { + /// Timer expires at the given expiration time. + Absolute, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + Relative, + /// Timer does not move between CPU cores. + Pinned, + /// Timer handler is executed in soft irq context. + Soft, + /// Timer handler is executed in hard irq context. + Hard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + AbsolutePinned, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + RelativePinned, + /// Timer expires at the given expiration time. + /// Timer handler is executed in soft irq context. + AbsoluteSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in soft irq context. + RelativeSoft, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + AbsolutePinnedSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + RelativePinnedSoft, + /// Timer expires at the given expiration time. + /// Timer handler is executed in hard irq context. + AbsoluteHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in hard irq context. + RelativeHard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + AbsolutePinnedHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + RelativePinnedHard, +} + +impl From for bindings::hrtimer_mode { + fn from(value: HrTimerMode) -> Self { + use bindings::*; + match value { + HrTimerMode::Absolute =3D> hrtimer_mode_HRTIMER_MODE_ABS, + HrTimerMode::Relative =3D> hrtimer_mode_HRTIMER_MODE_REL, + HrTimerMode::Pinned =3D> hrtimer_mode_HRTIMER_MODE_PINNED, + HrTimerMode::Soft =3D> hrtimer_mode_HRTIMER_MODE_SOFT, + HrTimerMode::Hard =3D> hrtimer_mode_HRTIMER_MODE_HARD, + HrTimerMode::AbsolutePinned =3D> hrtimer_mode_HRTIMER_MODE_ABS= _PINNED, + HrTimerMode::RelativePinned =3D> hrtimer_mode_HRTIMER_MODE_REL= _PINNED, + HrTimerMode::AbsoluteSoft =3D> hrtimer_mode_HRTIMER_MODE_ABS_S= OFT, + HrTimerMode::RelativeSoft =3D> hrtimer_mode_HRTIMER_MODE_REL_S= OFT, + HrTimerMode::AbsolutePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_SOFT, + HrTimerMode::RelativePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_SOFT, + HrTimerMode::AbsoluteHard =3D> hrtimer_mode_HRTIMER_MODE_ABS_H= ARD, + HrTimerMode::RelativeHard =3D> hrtimer_mode_HRTIMER_MODE_REL_H= ARD, + HrTimerMode::AbsolutePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_HARD, + HrTimerMode::RelativePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_HARD, + } + } +} + +impl From for u64 { + fn from(value: HrTimerMode) -> Self { + Into::::into(value) as u64 + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDFA4215798; Fri, 10 Jan 2025 20:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540283; cv=none; b=u/FAO6SCPXMNbwpOh60svW1enSLNkHsteCytmv/i3uy8y60fYyMtIRcqehe+m4GTxwvbVW1zFrQ2Pu3i53Wbz4Q0gmVESRsjvmfPwrYMXyFJpI4msDGbiCFsDzlKcWPspdBpJUYNO5qA9dyLSV0VZJerqhMysVSZA7EjdY4DsHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540283; c=relaxed/simple; bh=7YYK1zfbksfue6c6EzJtcg6I8IGSx1gOujBm6uDCW/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RTbxaCncI1kk/qMa4eP0bYyGZkhGp8DkErSox9mvOlsRvnPu5Dcz19mgu5rIXEU90cl6sr2JJVPzvG+RMZTRurV4/MQF10AImUChorOsOozVc9+YE9TI7hqZgjv9G1x0Zqiyxvi8T2x0xRkld5LOZtMLXu/7X6BHgt0uBecsW1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3V+8qI8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l3V+8qI8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 897BEC4CED6; Fri, 10 Jan 2025 20:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540282; bh=7YYK1zfbksfue6c6EzJtcg6I8IGSx1gOujBm6uDCW/A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=l3V+8qI8Ng2+Lbnz+2NVzBbpDe6zLP1Jo77waljX2r62d4qPs02jPlB1jcjzOIKmR gg/F3inU/WimCEty7myziRc24ECSDyXniuV0tXBhoPfsrqKa2EBsbio02S/JHTwd+k jQa8GTuW8RIiKN+7bVqtEBekTmrmPwe9TzR5B8fSis/cq55QbppK9C1bsfkeJuMf49 CeRBEjc5K//7V568l0jMrNcw2QuoVgfciYICas26akpcwJY9/6NwTPfIStmUzNh2uG sqXgjTOIk8McdK2ytk4Hk75FRXSpLUeL43S8w0w/DoWkR6gWeUuK70ctKsO1sZ0zsR HOx5JZhxGezWw== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:36 +0100 Subject: [PATCH v6 13/14] rust: hrtimer: add clocksource selection through `ClockSource` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-13-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4052; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=7YYK1zfbksfue6c6EzJtcg6I8IGSx1gOujBm6uDCW/A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/rVL3r3gDMnhL43bR5LOHXlB6eubzvyXa4k EixfBjPOsWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/6wAKCRDhuBo+eShj d4sOD/0cXvWCnjl5CJ0vgi3p7l3mN5O8Q3lUTtt1uutyrCj1FVZdm1wkdgrQjhprLfAl2eOwGhL qH2Vs9MrC5IQICHr4KfmLhnN3ogWc3Es4zCxn47YmoP5L8prknV1icoR9YpTbxHhYf6Q0F+iSyN iUL3tnQ8SpRPXtW+cHaYQWhMwtnDHkaL3Kgb4iiIXXM5i+tf5zSl5aYkbby+NilYu26FIxzSR33 lXHu2Iw9t0HIvr8GoCzkRBDCz8aeYRHrN98p+sFR1ZJ9lfrQzsVKayqNTDSJF7uSV2EwHbxFMU3 5PSpD24BbKfmhAlD3FA98cCN6DAuCeIgtOqvHGNMZdH72ncCsWntehAQQ6ovbILv0QBmBJo6J2I AdGKkR4a/TmbETlpaJ8y2mD7lU/ivLaB8AL6Oic80dnP2S9+wLOqJthTcPP4Kwlm4hnVbM0+FXP R+1SdMoHePcuxqQD9sVw/7K0Q98jF/d36GixwpiN0rOROKiojUa8vmcxaWUrPjkI9vxDVwMFJeX UweUh4wijjjWlEl1ICnFUPTsyRrov4BF7EotEVquAYVBlM5dsTQ9SUMmBFOt8o+kro7zVlQVPvN uUAdckxy1hCpxCSjg/MpKNpsutQHG01dlxPnkBckHXH2oizpDCk0a1pzCBY5gmy1sgrS0HbGeqQ GHzRatvtSd4qwBg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selecting a clock source for timers by passing a `ClockSource` variant to `HrTimer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 52 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 232af60f7c38370a4b2414a4c3780e06d2aa0c7d..f759e4b1aa9f9fa6d55d5c144de= edccc5d0590ae 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -57,7 +57,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new(mode: HrTimerMode) -> impl PinInit + pub fn new(mode: HrTimerMode, clock: ClockSource) -> impl PinInit where T: HrTimerCallback, { @@ -71,7 +71,7 @@ pub fn new(mode: HrTimerMode) -> impl PinInit bindings::hrtimer_setup( place, Some(T::CallbackTarget::run), - bindings::CLOCK_MONOTONIC as i32, + clock.into(), mode.into(), ); } @@ -442,6 +442,54 @@ fn from(value: HrTimerMode) -> Self { } } =20 +/// The clock source to use for a [`HrTimer`]. +pub enum ClockSource { + /// A settable system-wide clock that measures real (i.e., wall-clock)= time. + /// Setting this clock requires appropriate privileges. This clock is + /// affected by discontinuous jumps in the system time (e.g., if the s= ystem + /// administrator manually changes the clock), and by frequency adjust= ments + /// performed by NTP and similar applications via adjtime(3), adjtimex= (2), + /// clock_adjtime(2), and ntp_adjtime(3). This clock normally counts t= he + /// number of seconds since 1970-01-01 00:00:00 Coordinated Universal = Time + /// (UTC) except that it ignores leap seconds; near a leap second it is + /// typically adjusted by NTP to stay roughly in sync with UTC. + RealTime, + /// A nonsettable system-wide clock that represents monotonic time sin= ce=E2=80=94as + /// described by POSIX=E2=80=94"some unspecified point in the past". O= n Linux, that + /// point corresponds to the number of seconds that the system has been + /// running since it was booted. + /// + /// The CLOCK_MONOTONIC clock is not affected by discontinuous jumps i= n the + /// system time (e.g., if the system administrator manually changes the + /// clock), but is affected by frequency adjustments. This clock does = not + /// count time that the system is suspended. + Monotonic, + /// A nonsettable system-wide clock that is identical to CLOCK_MONOTON= IC, + /// except that it also includes any time that the system is suspended= . This + /// allows applications to get a suspend-aware monotonic clock without + /// having to deal with the complications of CLOCK_REALTIME, which may= have + /// discontinuities if the time is changed using settimeofday(2) or si= milar. + BootTime, + /// A nonsettable system-wide clock derived from wall-clock time but + /// counting leap seconds. This clock does not experience discontinuit= ies or + /// frequency adjustments caused by inserting leap seconds as CLOCK_RE= ALTIME + /// does. + /// + /// The acronym TAI refers to International Atomic Time. + TAI, +} + +impl From for bindings::clockid_t { + fn from(value: ClockSource) -> Self { + match value { + ClockSource::RealTime =3D> bindings::CLOCK_REALTIME as i32, + ClockSource::Monotonic =3D> bindings::CLOCK_MONOTONIC as i32, + ClockSource::BootTime =3D> bindings::CLOCK_BOOTTIME as i32, + ClockSource::TAI =3D> bindings::CLOCK_TAI as i32, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Fri Dec 19 20:34:52 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5446021B8E1; Fri, 10 Jan 2025 20:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540278; cv=none; b=e+DkkREluwrfbN9oJyQmuEz+qCSGvzmRiU5gNctYuGUHwyzkCBupAxS7BQBRkOytZIReE6o+mv7nJ4unOofXz3eUvAUxkoPZ9HsDLIFb01JkfRkESOAcJYVkSxEtBqU2MKtoXAAUzlK2jBe6Gy5+uH8U9Y9S8qigjFAyXRR0vXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736540278; c=relaxed/simple; bh=gbJnMsHsGxqNRgpKg6CpvUhSKKmts7MnS/ouHzzjaWY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EvPKno9JDnHKssm7atFZqESDN7e1tVJlnLKP6Kt2bZjyT4eAbRPC1pX2AoAN9EMtWIRwFoxBt87MgqOjHuC0MislASprvUD7D6HGnlTGRkmhmSG9A/m05q+ht4sjIhy2NN4oBbty1ZEx1Za/mGvmX3rfetkexbBYm/aQtSjSCe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BBgdf3on; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BBgdf3on" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EDC2C4CEDD; Fri, 10 Jan 2025 20:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736540277; bh=gbJnMsHsGxqNRgpKg6CpvUhSKKmts7MnS/ouHzzjaWY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BBgdf3onJZMwKz4FpYo/kLmSjdJKtbMKfMR6Z7JhJDIKz3eFAxDH4aKvq+HbTmZnB T8ZvMblgo+FZG3gk0ybqby8mx++dB6xSZo4asc6qU+FfG71mOUOD4LyN+CN6DS/rHJ 1eZ6NB9HgJ5Euc63ytwpH35ftc/Xiu6EDK+/byaOZII5aQgtewhcqAU7vsJKE5YDmZ /jIJAtUbr7wxne4w9Hqqt96R0GoFSeCV5SNA8HLnSRvccaxfhXXRfsXG2sxNLKksHG gv+tK68p4aCscMayzyWf5YU7+nWKiIE77kd9fPZOY4JIr1Mu/2ljpGcmmC58IlNmV0 BO3zFR34urcmQ== From: Andreas Hindborg Date: Fri, 10 Jan 2025 21:15:37 +0100 Subject: [PATCH v6 14/14] rust: hrtimer: add maintainer entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250110-hrtimer-v3-v6-12-rc2-v6-14-f71d50f16482@kernel.org> References: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> In-Reply-To: <20250110-hrtimer-v3-v6-12-rc2-v6-0-f71d50f16482@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=995; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=gbJnMsHsGxqNRgpKg6CpvUhSKKmts7MnS/ouHzzjaWY=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBngX/simGNi6BoqKzEWCBqjL+1qfRND7OeTOe2i hq2kruksY2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ4F/7AAKCRDhuBo+eShj d7qhD/4pk/AHetUJGnQydKxgcPcTNHBGPpv7g9QyXh96ZtFbQstifnhfBb/K+mg0Ftb3G7KjHV4 6fNujFhUXmthMUjIqYzkXOzrZVm7ho0WdJMWLb5A8IVasMa3dLK18zyZIs0T8QazKp5RmJTVVYf i1NQAD2IEPBG6glr/lWhwzUV5Iy6+NNBNyQSuJ/GjhUc8lJnd+AVpjwj7wPsCbTWzGsgb5+Twoe dPVoejDCzUh2Sh8tdiBj1ThoVDGB6bPpDVwcZFhRhZGLvKhRV60pw+C8d6YTGvMMgIIDeY6DB1F 7zcv35XCqth5x7HJhXf/WEi3DIXmb0b/Wz1BQ8ZWOWxUe3EVzjewQrqIGa5bEqQpXp36RsY2KN0 bc+HRZf5ZjDsTlAhwiuu/HKrbkRSdhh95NU/LeBXpwfr5NKuY8kDu73mfkB6n6BbJ2uEOmWupCB blRQ3xz4cisTGvqfbqm3ir3GWqvkdokR9WCt89J2n9QQsgnLJz2lU1SnpPoF2S2+Iy9y0b1VpPM mqv93iIwyHNGrVwBLYBjeWW0ko/S2nm8bAuD5zPlHU8xBTbOxZU+Kz7cMweO95JuwbPbdsGDi8d e8NpOklrYWtYuCaowIhV09YLl5xL3iHx8uCV9xSdaXdvGaQYBsPfNpl2cy++xhqrnWtfA7l0mqh IvE+EO0KKwgC2eA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add Andreas Hindborg as maintainer for Rust `hrtimer` abstractions. Also add Boqun Feng as reviewer. Signed-off-by: Andreas Hindborg Acked-by: Boqun Feng --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 30cbc3d44cd53e6b1a81d56161004d7ab825d7a9..926e1b4c548494ad84eab218167= a3075c125908b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10253,6 +10253,16 @@ F: kernel/time/timer_list.c F: kernel/time/timer_migration.* F: tools/testing/selftests/timers/ =20 +HIGH-RESOLUTION TIMERS [RUST] +M: Andreas Hindborg +R: Boqun Feng +L: rust-for-linux@vger.kernel.org +S: Supported +W: https://rust-for-linux.com +B: https://github.com/Rust-for-Linux/linux/issues +F: rust/kernel/time/hrtimer.rs +F: rust/kernel/time/hrtimer/ + HIGH-SPEED SCC DRIVER FOR AX.25 L: linux-hams@vger.kernel.org S: Orphan --=20 2.47.0