From nobody Sun Feb 8 07:50:40 2026 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 342AE269B15; Tue, 18 Feb 2025 13:28:08 +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=1739885288; cv=none; b=Pm9MSkMGkSlKuTiY0bQW+bSSPFzbe99oBTOH/pGFhYG6RYDKG40ngt8O9ntxoo9FXHgxcRWJYHYVBz+EkhpNB4uwR/yzyE+VnTE2jx2TJNhf71Mmov/SG2glQv/fgMyE4uBodVaiZdF5RGNsytWwT0qECuoBgdIKBasj9aJHogg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885288; c=relaxed/simple; bh=fv9JapopXp9S0KlZSEhULwSrLVlfd4Fs0oJ269tvLlg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PrEnNYCYqAHX60FtdnkzQEWmoknFrrM/Y17DBfNkTwtuARIRScJdvnUhpEL4BAVZDhywqh+/RzRRdjmoiUcD4DHSxxIrho2D545iMxmPVvn5resvi7RaXqmImdpNihpCszpYlwixKJY1ZdKVnba22SNzAvmibrRkfEodxYcPGKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iNR9a4Yu; 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="iNR9a4Yu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8773FC4CEE8; Tue, 18 Feb 2025 13:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885288; bh=fv9JapopXp9S0KlZSEhULwSrLVlfd4Fs0oJ269tvLlg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iNR9a4Yu9Wu0C3DfmRPaveT6+6+TROwQ9VvGmhAiy7ddv2ezBy1NwlA8PQu1x8lzb 1DQztneGSo1VvoyuXC7n1GM8n/L1PIYozujnGLaV4ojP5KW8JR7kQhV+pdYaofG6C7 lTPthF4+aVUWfqzr/H6wyBGvWyquE7moHSsiK54CWO3ykbtzdTk1f9OLR4Jl0ejReb rrBbz6KAEeQC+M2EK2q71vIs8DE/ODU5eVnadmPzbRUmWW2nd5bFIb7FUhxN46H/Dx RMVO8RkIztBRnXcLg0Kk7mUMwJ5AEIPMgo0RqtEW1qMvHWFm3kxShCzbZM62YOEGEl +y1lfNcG9D8Lg== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:06 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-1-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=1373; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=ZTiCs0Q48kNHhodERi8HFfU/OwlrOIEVdq8syuCNH4A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIqvibbhkMUmTWZVYPx6A8d60jatjWh01z7kq cO+DllDjEGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKrwAKCRDhuBo+eShj d0xMEACXJOI9grvtZQ7HYMKKNVDqL6iFv5zp207TikCuv8eqrerf4N84wrGMaNnfCkFPSOYPuZV 8zeF2EHqRYD/7x6BEsg4weueFtpVCz74bYYxCp4uDcxTMiauRnx8WnXIh5oU7+Ne+Nf+t/QiDsZ yciKMHq/S5D2IOamWyv02tsSZS3nZThpeVYZ0fAOG8DCetb/lrAgRskLEUZ2q5en7wIc3yiCe6X 8yXTDHuKKu+v2wWc3CUnJlvSvM63Pf5+HcQyrsyi7c9zVWiKemFR4sRZMix098REFj3bU6vUKVN QH+XTrIrssKqyj4mIKBAIuKVmwxcX6klRks2e/pHPqRqSwz7cBSD3yJbdet01YQ4B26kzCMQlOJ Juw8p3ATKSmWAR0NauuCobxfyM3zNOjX6LWZln5SW9CRk2fqE+dwdWvhe8U/Q8DrpTiJhN9KUW/ RT6iSbW6XjrD/c3Dj+cyGHRqCGjZFsqmI9Wwt7+tvXmfQ0crJPWkzdHEW+ytjkWSnBKjIQ8OCek XX4ySmK0+esRVF5DkirbHMvlfCAF8YYSQ/ZtAhMWkMyaXUdoLrVIE+dPJAyveCi+Lm2FgdUokTE 6ip7RoNQt0F//2sXNlF3ymLMYtVaGusb0w9LLH6L1GpAMW0S7wV5Ey+oV8447rMV+EeI7CrDcEa LxXWANaPrLioMaA== 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 Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- rust/kernel/time.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e57..87e47f2f5618d 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_nanos(ns: impl Into) -> Self { + Self { inner: ns.into() } + } } =20 /// Returns the number of milliseconds between two ktimes. --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 55DAB26A0B9; Tue, 18 Feb 2025 13:29:07 +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=1739885348; cv=none; b=Iwuq+s/DDEDCXwzwgMSqRJTu4zGj/NV6T/18tAFRT7Dzcg/1gev/fA9UCVvyAWd8L3AUrFJvIBcn+OukF4SC24K+eagSb3qvy7REpOifYixgSmibEkv13jdNHUaJoDoxHqCyQ6ZVtYE+bLutVUT0bDXw2Wwm/Ysj8KSW3yCqvfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885348; c=relaxed/simple; bh=lN5+CQUa4AoWls2NexT8gnVu15FEJjN7LDCy+Mvwpaw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ct5IK6swJTXqTEXIYPyZ6o0kVTdUGd68yiRfh1fWR2Sasq/9pRw0Xa5/GbliWUi9YNEzkQdnoXPl2Ke/pjgoAWg5hdvpSwSZblKWZr11b/IHblJ1xuM2Tt4t+rcT2bIwuihAAYonaDDlrfwqxIIodbxgnv/JLl8PmBFcF8Z58B0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YMNBD1SP; 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="YMNBD1SP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F710C4CEE2; Tue, 18 Feb 2025 13:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885347; bh=lN5+CQUa4AoWls2NexT8gnVu15FEJjN7LDCy+Mvwpaw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YMNBD1SP/DpipE58/znMXXuyAqf1wwz+MvJsKr0bq41g3P3nboHD5WNcewX3lOYiq V/aAeScIC8w2lQaze4G3CTWvMSZ1fhh3yC6vEbULTAb5FSrgtpwaJRPkO6vPj/mJXQ zxBLtZf3Xfw2S09+tH4+j1Kgg5+/AZdoKrzrAcYKPblBeE/VSjb7RTY7r8LGYtkqrD rYpjc563sI3lP5Md7zY6CiKrL46PzFj+dOmCSEpe1IpvQ+cIfYusoQgh5C0k4bJ4dl Q6U8dgbFiYnKSZFldRkpOFV1R5zTjnnB0pz58FrIZ0u62M5G48eaiw7c3C352jBJhR cw1pBpwMP7cyA== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:07 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-2-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=12939; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=lN5+CQUa4AoWls2NexT8gnVu15FEJjN7LDCy+Mvwpaw=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIqw79p81DLuM018ujkNjgAGnd4KPAZZFdwRS AeP1d7LFJuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKsAAKCRDhuBo+eShj dyRjD/9flCn4gLkNwCOwd4k1/H81j7DJqYloo8Shkr1yQa1PpjxJ7se5mYMGviWpdfk4P0CVoDg cZt3D23jBVoTSM2BLMrrKiAVtl4kSyg7vYcNaUGi3evTbweXtp02/r7OlTqEblYNXjtNvp5ABQl XXC1SR0dS4xfcyc8gyb90dVDV5NGGQ+JQI8U5kXgTcj4ruSJviAgSF6DWedfbm0yVmYCmlRfo7j Vpjg09pUI/DhweHtT4DZ+exT5wDsSaf7gmQM+PyWA98yQU/AAxcw23zafZ7xpzikJdINjAOdAqx Ei4Cx4cyGPmuMaw4ZyknFSoFI5NnxV2Nua9tweKTU3QApu9oK1xkmcCGrW5hKANvTCvcrfBSx+7 fWsAeK46ycNgSyY55rZUXDval/qBFO3w30WrqyZracg8y0KEglniYgdEGESH0P0ae7YCWyQjmcv 4ZcklJgORCE1A9BQXycbl4Jtww3FsuOlKggHOzEssNpYdRLVsgVe6mqpcSAhds/wUUYRjLwkhir 0ylWLB0LX0Oz1lMq+g3qmICJn0N+IApXcju5l4lcJJVDKfKiTwUAsYQUvU2YnT0+vV4afiDWR1M KyOzEXJHcuxN49cnFXYd9L8B2bQ051TX8LhJKoY6AoLSrutrpqUIsXDk15TA458R2qc/Onhuewm 8r5ifNIVup1I7fQ== 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 | 312 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 314 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 87e47f2f5618d..2cf365cfb412e 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 0000000000000..a6332924efabd --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,312 @@ +// 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 +//! +//! States: +//! +//! * Stopped +//! * Running +//! +//! Operations: +//! +//! * Start +//! * Cancel +//! * Stop +//! * Restart +//! +//! Events: +//! +//! * Expire +//! +//! ## State Diagram +//! +//! ```text +//! <-- Stop ---- +//! <-- Cancel -- +//! --- Start --> +//! +---------+ +---------+ +//! O--->| Stopped | | Running |---o +//! +---------+ +---------+ | +//! ^ | +//! <- Expire -- | | +//! o------o +//! Restart +//! ``` +//! +//! 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 **canceled** before it's handler is +//! executed. A timer that is cancelled enters the **stopped** state. +//! + +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: Ownership of an `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 = to a + // live allocation. hrtimer_setup will initialize `place` = and + // does 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. + /// + /// Users of the `HrTimer` API would not usually call this method dire= ctly. + /// Instead they would use the safe `cancel` method on the [`HrTimerHa= ndle`] + /// returned when the timer was started. + /// + /// # 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 the handler is running, this will wait for the handler to fi= nish + // before 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`]. +/// +/// Target (pointee) must be [`Sync`] because timer callbacks happen in an= other +/// thread 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. +pub trait HrTimerPointer: Sync + Sized { + /// A handle representing a started or restarted 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: When implementing this trait, consider that it is not unsafe= 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 be the target of a timer callback. +pub trait HrTimerCallback { + /// The type whose [`RawHrTimerCallback::run`] method will be invoked = when + /// the timer expires. + 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 Sun Feb 8 07:50:40 2026 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 83FDF26FA44; Tue, 18 Feb 2025 13:29: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=1739885353; cv=none; b=I2IdXeOe6pzJtz/pJt9nLCr2SsXkiD4Xsc0V6+bK43p+l1jxKnFpULBmAKuw4EJRQKYoFwMxNKBI3dFjtH7wK4OS/sOR6P6NySzrZFIHxs/8GjmggfSvW0E15JN9D0KAsQFnNFT7fVMxSFLFSBGHRdDy9+3Mq8cXZ3258WlccHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885353; c=relaxed/simple; bh=Ez4aj26Rj9v0Tc5hX/M4I+wHtR6Yagi0UV+Q7KodWVw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OX9RwsQkCn8lHREr+E7U9SSEd1V/iHZrqpF8YkhjsoVyleE1Js4NZGoNLLJRD6TzvxODdYKoIbwU6yB+YCSQjiQvwfgYXmaUaFiIzKmR2YrZa4Tc29MtwdKyOt0c0yXuQE40Aa0O/jE1GxQNXhe21UhSo+Dyh2FTGrrQ2wH9j5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LeWEHhiO; 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="LeWEHhiO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA5DAC4CEE2; Tue, 18 Feb 2025 13:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885353; bh=Ez4aj26Rj9v0Tc5hX/M4I+wHtR6Yagi0UV+Q7KodWVw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LeWEHhiOChKpDCaVnffjNtrv/FRpoNfvfUmpPDdVJ3b2t/xkil7kcRHfnZU94k80d dYbmInce+hLU5fAz5DJfSOb+TC86BKMnjFSOEmmOfvJces63qkRswuTmf8Hmii/SCB /jrTkOjcM3EKHsnDcD4YAQNq+6mbyT/T6OaUmaDpn39xoditFYx5dAJ6iM3chcllWt 6/hYyMqW8XYXjG13xfdXsSK7CC5VMg3y+hYpLQdpOS9SC0OND11a+pHnmQoEN01Dwt FISBUXOq5aUV1W24ok8a0+a/SqT8yb+2zMoHBHiV5J9EEyboLv1mXBOyD28Kub4Aiw ZoNXmhtByPf5w== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:08 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-3-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=1899; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Ez4aj26Rj9v0Tc5hX/M4I+wHtR6Yagi0UV+Q7KodWVw=; b=kA0DAAgB4bgaPnkoY3cByyZiAGe0irHIh2mK2WwXbNVDufwNITe4i9OKLLfpI4G1lkwVGeoR4 YkCMwQAAQgAHRYhBBLB+UdWv3wqFdbAEuG4Gj55KGN3BQJntIqxAAoJEOG4Gj55KGN3RCMP/0Nx y5tXia/7wo0PPkzyFt8tH1JzhoBlbp1F7dD2Cu4rHBnkoMdvXonDWbaNPEpa057799LMgu9DpAs rU0YU0zBgAczpfGw8VOPUR9rD6bFJdBRjLcVhsJGHBRf/qiiqFWgTh0Quio+L+v/V8XXu4b2c4g yZjTCXtToNBvj+MW2e6OKIEFFHLtbmPsXxZLnFt4Ou34YEucjBJ8H5LpDNFGp7vOb6RikgGVkm5 BIk3aWrkpDXgv1s1RR6tsbfq5Dn2GfimTvMWowzUirm4JFpzKZOR4n9uYHhM4ViSbJZ3JjLsdt7 TkDgo8Cu8kIqHLooiYnKbn5ZuEiZ0Y/1fDcVukncWmXsXt8oZQVW1t4BJl5Zg1QmbrVifwh0Ha7 2bt63naeBXH0iz7gywbNeHcidkNttxgmTERITEldDQvfooZ6ScWDai3z4TFctDo2pKuUyfkoGRD Y4Yygbai8oU+Cerf8Ctb7QWLhheusEAJrT835spTE302TrQsnwGWFWTnUMhguCBOut4iSihKCnH EkMDSYWIxuIZKn44qHXiV5EfXwY7V4DTyCxdAAzH8fLbXWctGdnVZXfH1dD9N4Nt7Es54G8iTdm bnEamz5Kk+pgBJFVJ5rDFfCagNq0c/UtQmsYdnnhPpw67yWFuvDwlbOm7HRQNArBTDmJz+7IWsA kB0Ls 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`. Reviewed-by: Lyude Paul Reviewed-by: Alice Ryhl Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- This is a dependency for: rust: hrtimer: implement `HrTimerPointer` for `Arc` --- 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 3cefda7a43725..1dfa75714f9d6 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -246,6 +246,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 @@ -539,11 +548,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 Sun Feb 8 07:50:40 2026 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 51E41269836; Tue, 18 Feb 2025 13:28:42 +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=1739885323; cv=none; b=Ii0BfOsdmRYPhxSEpcjZsQ1M5GHUzsyvExwj8h7dSrtdlsiEiXpeqgNAiow6X1deF6k4y7hcrSehZTOF9M7gHnJzocpY2NtiJ5Oy7i50w1Jz6x8nDT1jAf9mx32qLAvjJ8K50wvite169YwibdNHp9LL1uoGV5K9W8GCFxA8rS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885323; c=relaxed/simple; bh=GeVoHgN4g9suu3ZWHUakKEFm2O49qSurYACSKMyug+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eH7gfIO6oz3vbjZGRwzk/VGowklGGMvoupGyYzON2iPf/F6ycSUQG/+022QGnXuxe4deqlBhEj8UDVCD+krOq0fefu4CD7wHsSELzc9ceT/q6hltKqIJStDlTPvlyMqlQFJPZilfqV7ws6l9JlM+Z973NbIqIU7q5FAtfm1C20U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hh3EjmsE; 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="Hh3EjmsE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7ACC4CEE2; Tue, 18 Feb 2025 13:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885322; bh=GeVoHgN4g9suu3ZWHUakKEFm2O49qSurYACSKMyug+o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Hh3EjmsEl5JBHcyhzSfib9DadqpWWMBhZhqpyS0rkgVx8Noyf1BV3VionZDhoXBIK fEs4oxUAImFyaJ704bQRFdkiZGvjCc0aUYrMkH3anoGbczRL0AgwZph5gYm9bOppVa IlgXS6jUfjH04uidz5ik0NDUsYqC+ua1A0w7cjcqSOSZOUqBi7MbZdTwwbxI/uPGJe ZwtGpxMLiIVjTvUfFNvC0xm7mU+7bbgy0MB0/nBWYcAhyZZZ+aYZTLDmEUBZZR2dxp xdGvcpdCtFko+EWK4xAXY2ypsQd0zu6Py2+XlrfpcrzQdU9zKw+k2tsYKBdPnJ/2An 3y5P2BxayxfqQ== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:09 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-4-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=4076; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=GeVoHgN4g9suu3ZWHUakKEFm2O49qSurYACSKMyug+o=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIqyPSprRcDJC8rDFTSKiIRTWYQuo8q+38Q/e ghJGmX0yryJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKsgAKCRDhuBo+eShj d2mwD/wIQ7sSWSehJj2wttz7HaIe0AUXtOL9lqmvGay/UxadIjkAGikE7VXNoAL/UHvwqELnBPn u0w/IX/iG4hdva79x2hQ+gozcSiSFWYzJeoqDAQXZ2lxnj8NYkiq4pHY7iQfwut2xQIc253rwPm W6TMcpYSXIH3awsRRpAPYkGLuUCxthYnWOTVpyAe+n6q7YL3CJg5NvVyIOx/MucQmpvUdUIABoB wMru6KoXbZTBaU7t4e/VeyFiUW7b3N2TZyw678NIqRMDb+QojWHpRiJhIylJD+srgiLScYwL9Fy ZteyJYu6ELCyJsyIG4LuavLPw1/z6ULUfTphTkU96/bGq34DkeZwJFC7LUrT57+3ncfDvLc/tte 5DTzKJnB3uv0VY6lQtjRoMYOD1FITHKUaPoue8YUhoLnWx9ohcVzX3ODJL9Ue/up9OF9KlOTRVy Wh0qKkvy7BCx4R3FAFCRdGglYOewg86jh4CcNvJnODrMjc7KW06B8ymUxoRwZ+Nsoxm5n83DXnY sgzy46QtyQcKZ+dNwbDmlhkmuNDR0gIuhf9tGxI/TOuKCI2XjE44XvXERLu0MjEBPeiJomEo7wK YjUzeXSjT1nb/1WzeDQcYtHkbf6TQ0mfE8YglNPTNIEVK+kku7C3uBUdqOHKhUYhxbbFNJxeEDA Fp6SYsa7Bt8tGNg== 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 | 4 +- rust/kernel/time/hrtimer/arc.rs | 89 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index a6332924efabd..b2a3130bc21d7 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -119,7 +119,6 @@ unsafe fn raw_get(ptr: *const Self) -> *mut bindings::h= rtimer { /// # 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) }; @@ -310,3 +309,6 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } } } + +mod arc; +pub use arc::ArcHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs new file mode 100644 index 0000000000000..d1c90631d0036 --- /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 + T: 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 + T: 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 `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` points into `T` and `T` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for ArcHrTimerHandle +where + T: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +impl HrTimerPointer for Arc +where + T: Send + Sync, + T: HasHrTimer, + T: 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 { T::start(Arc::as_ptr(&self), expires) }; + + ArcHrTimerHandle { inner: self } + } +} + +impl RawHrTimerCallback for Arc +where + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Self>, + T: for<'a> HrTimerCallback =3D ArcBorrow<'= a, T>>, +{ + 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 { T::timer_container_of(timer_ptr) }; + + // SAFETY: `data_ptr` points to the `T` that was used to queue the + // timer. This `T` is contained in an `Arc`. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + T::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 E561A26B2A8; Tue, 18 Feb 2025 13:28: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=1739885293; cv=none; b=YBqYvyagKRV5SiKlelVHorjkV6HROiajPzeJmhwPxd96zsxnpRP53ZKaerZkdafTFNpnFP2nPlQD6Ga00bef01Mx8Pks2JdtUOFjkGOIQ05ZhH89Zk0IQ168so8hhfpVIOyPQ/BfukxgS9dA5mEuv/BqN+dtZn5MYqZpdY7IBh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885293; c=relaxed/simple; bh=3m8fQyyEUwu/wXRv42ZRgQGKOJiZ2h/DVDw/+PrbPak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pTxy25DdGyQ3SCphdhgNBhS1sbSF4fF9QxJ/D54H0VWUGx5SthTcR0EbCgsC6D2K9L43F0ZUERMoeaFmLBKH/V6t6KyhEo6EerdRmdvq0M9ydpKMnfQdOLP7UtVyjTCBVavhHsZwfhRNxs0f4hz7VmGLWSZXTy3UjcPK1AIVXYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oojFB0Up; 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="oojFB0Up" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A26E2C4CEE9; Tue, 18 Feb 2025 13:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885292; bh=3m8fQyyEUwu/wXRv42ZRgQGKOJiZ2h/DVDw/+PrbPak=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oojFB0Up4YkV669kWHdw7XaNbThpcKkyKlJyjcKvq3DJzGWz6w1sI2k25Nd39ovaf NLTm2x7jMNWgBw5gW6lDCyxdvBHIFP/dB95AicR5XCmFiiux8JrJiZR68wmC0oFhtw h4Q+9+09TIJvDSXcNUDtHKMdgtsmI1xZoYb3lnQKYkiokfdwc0wWdwkt1DK+E0deVF mc2apgBOgsIdwRVJG1nAnr2lNDJMC541Z5KiGyGKfoJDOY/nYbN+jJKhxvvR3tQ6Mp ui/cIWfHJB9F+q58M+Qigf/AeohH1Yp9AZOo+54tG6/1qDlqb5hEgXq2QMquktcLaO 1w2sn5fTXHq2A== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:10 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-5-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=2433; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=3m8fQyyEUwu/wXRv42ZRgQGKOJiZ2h/DVDw/+PrbPak=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIqz2gUH5s8VTdU5zwWYcKc8wrTt/Am6FW7RL b6BHWOfanaJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKswAKCRDhuBo+eShj d6lFD/9kF0CQioS0AzCQ9jYv5jIoGEJvPRrKkhsRm1QwQG/uSoszsFnhiCdya1B1XY15vO00wjA zuv67CLDNLj4eWPrWwbV4ViQAKrARkvFgSeUNsFP39NXs+44fcVlEjBnYF9XFvZOqDXygdjs0A/ iEzxqMWJQJXPACbgWIc1tGFtz41UPdw4p+yII6EVM05IobbNEipKyW69dqf0j2fAuSZmCvasL9o TLNmASsydn64aOnS5bJV2jCwTgmn4udV064wojl3Yk/x2hQRXpj6ZmZGCuE2DT6gs2SyKH4Sbvm W7UMwJvIQJSRa3TKJcWxr+odpUOL5oFkDPCBx8TsCNNrojk/WGTpNV/6U9hXWpjHPOdYD6QaYYH 2p4wq1H9AkN3r+/ItqxCPbvqwE8/6iMkW9z1A8muWsZmly/kVYV6S25uvnDqZkCaAqd1GnDTAK6 ukUJCJuPuCNSb8NGlLX0V1HTtRqyke+3GtEvSueyy7XsChep/JwLXTmLEyDdIObYFhPqqQsnU18 T4Ll6dSvPKQwJt2+K2Rd51bvpYSJGTXRcUmFXjIqrNlpY/1lXD0+Z8F46stRAheZ69v/47Nvjsq c2IIx+Zr6Fj1lReB4QQKQyagO6auqmLr+/CdK1lFDnyneRfEeMwNWEr/PDJkM+bPPJbpcuwItZg KX8LgXebRjkpd6Q== 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 Reviewed-by: Benno Lossin --- rust/kernel/time/hrtimer.rs | 28 +++++++++++++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index b2a3130bc21d7..e342193f985eb 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -183,7 +183,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; } @@ -278,6 +278,32 @@ 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 { + bindings::hrtimer_restart_HRTIMER_NORESTART =3D> Self::NoResta= rt, + _ =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 d1c90631d0036..109eded0e73be 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 `T` is contained in an `Arc`. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - T::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + T::run(receiver).into() } } --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 EB85A26E635; Tue, 18 Feb 2025 13:28:47 +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=1739885328; cv=none; b=kx74OSX8uO5ZajdWO2iAE9DMur8USxrJdlpgnW3uZGQptq+navsiuUQFcMrAw51MzLKhweWoc87SNn8tWZV202LBNR0Lu9wKe/Z3dcOlzfDPiQ74nscEyaq/GErE6vM5vLVFN2pfBYmB2gnUmer0Zk5xXRd7GRoawRcTlijoiz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885328; c=relaxed/simple; bh=5zKmv+EsEhW1FYM93252zgD+dCvrJvBVgpU7OYF8fdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EodF2rBkzRQ7k+zbNlIoKqYbQoo/WwHrcoKMmjGKfUT0MgGUzO0K8NPoIudg3e/THlcjXq2TRklKXBnFXZ6uZSc48OnH/4sWZtiR5w329Va0owW4xUqb2h0TH82977PDRqwluVwEjtUzKLhdd2Gg8U+ozAWj5WnxFE511FSNufs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oitTKfF7; 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="oitTKfF7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E062C4CEE6; Tue, 18 Feb 2025 13:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885327; bh=5zKmv+EsEhW1FYM93252zgD+dCvrJvBVgpU7OYF8fdU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oitTKfF7Z/+2zadTAfeF9FNl5r2SHiM3vti+nv+Pkk9u3XtHbQwD1o9vYfCIOZ/9/ +m6+IMf2phg8uIXNqWX0O448Bavz0mnQ3WQhEpAgQ2hJd1o9IF8xOWIZ5Whmov+Nls S9ccFK8bTv0ymFHwVL2x/XE4igYMnbhwEvdw4yvQrgwPiMNptKkH3tjAKd0g/4PUvt k0DvrDu8MsLmeVqzoIHqBF/Igf6fxVSst6CoR6K6udhFHCgKEuD1upWYqBfwJZU9gN Q/+T3l2KrdW9Z2D4wCDH1AAlgRZb6H+58lW5nnlhUiILvSlRCBM1Eexz5AmQAvp9n3 JCvaQZPvwU+Ig== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:11 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-6-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=2069; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=5zKmv+EsEhW1FYM93252zgD+dCvrJvBVgpU7OYF8fdU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq0OJaXqxS62j07wi5/IylZb66zoyJOV8Xr4 +bvuk2yc9+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKtAAKCRDhuBo+eShj d6YBEAC6aFhdy1ccGG1znaRc0mI3LCTPOEmpVuk7wTYbx3AqM8u8vggaUbWnT6XG8pr6oMH+Sx4 q9KMrSATex8oC8fsR7WZ/prg7pTqJmLSxx8AbcElYxfu21+Ii3/OxP/TyGfP2TEGJfmmPhU14ba fPO8QmzIB573TE+tmmOdqgWzP3j1VVYrvT5lyQgWuOm7hDk2aH+bEb5E/szTSCUwO7FvBOhbbej Fq3BRBC3+ocq12uOE4sNCoPSC8ayhOhMbKGBitCMbuHmtbtgQaP7cgKRWrjU/m+9RF6DgfPtCGk CL+nWrn2ZmSdnijjZfGvOP1s0ARu8ldtbOdLNEcCP99lNraED1qkaEqUhhGF9zsANvGJObFj4xq +xRvC6Wl9aJSMXQ0OrnB2IqopbTVAgfO4Zctz5fc9ebUe495bPCFJrhJk0iKtKvPRNloo8WcvCX G2qnWvTptXZblxOUeQStnJEQnWxMN6uSmMmHO/dwwXwxEWBiKlshEGqscnerUm+jD0Lxge4Brna yJQHTbbqeNqhFCRYmS9g2PFah6sJahsf+JfQLiIG+R7LAYd/R8ifnARa8MjZT7lOnbz1azdk/oI NoYnfLSVEygEUEtGv95gdbnZcRls4bvOiYGmvoGCelef7BbveSGdxkIEZsfEiGT6uUvSOBbTIwD AF1ZCeLeb7BYCSA== 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 Reviewed-by: Benno Lossin --- 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 e342193f985eb..196794089f033 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -157,6 +157,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 Sun Feb 8 07:50:40 2026 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 09D17269D19; Tue, 18 Feb 2025 13:28:52 +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=1739885333; cv=none; b=Dee82EgUTlwQWLzxOMcuNGM5/q5A37GTK5hcIVB59tiYCzqj6snJ2itS917o7QL+MdI6YvZyXaN2VWr0d6t6EftMFD1l7bnldCqCqm5E4Tc508nYveWAFXJdlPP/Z3D9+2Z7j9/wvFcCFaAPJVpyM6FUHYmK2fAKJgGbx4lgp4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885333; c=relaxed/simple; bh=eG4ncH1UpYgaVh2bHTMXHYfnt6y7lXx/vhY2bJebvmk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fGlLWJ/D5EJJSlQpzM4Mq3KXPIKl4YgbcKOoDo0jIuxkWDPSYxwDZeCBJreoDGq/1lkfPRvaYOno6l5DIRg76iiOWxA9obSG0OZ7liV6HU+OsyBx+kk5xQjINcoFVHKv1HfmG+iXyfEY7YeiLOg2DDGjDu46Yv1S/rG0IUJnkRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n8AWdgWl; 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="n8AWdgWl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26F4BC4CEE6; Tue, 18 Feb 2025 13:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885332; bh=eG4ncH1UpYgaVh2bHTMXHYfnt6y7lXx/vhY2bJebvmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n8AWdgWllC23AxEpooosl8nepwYudG4h/jaEXTBcBOuXt6fDKmSeL3hvCzPD9F/s+ LNxoYmbgG6BMJAIhXA8bHI4tFaz6pkYeCocHAV1GUe8Hgs4PUZgux+rVWIZ2ffVVXk rEylj9vo1P0mDMtLv5zjRBkyzRLlorbCFsrHWwOzIX825CKLq5Lybu+jckvky9OAEX YDlj/LxRpdmeiP1eNiZxLq8gK+cdmIbaeSBW2i6gqtoqx/IblzlI+FTiyWEpmnnV/6 O+iTGaR7SXRIC7FHdjfrJf7r9qvq9LTKiHE4dPj7WaEqQSkNrN7337Tftv89hZ8AWX N+Hj6rnEPqPGA== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:12 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-7-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=2039; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=eG4ncH1UpYgaVh2bHTMXHYfnt6y7lXx/vhY2bJebvmk=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq1p6ks8VywJik0hkPMD6Zjviq3fHfnEQsuG 3qg5YdiekyJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKtQAKCRDhuBo+eShj d9V3EAC2FtW1buWNFpDSd6arpX4//wpy/ItGaUM0JT6r5yJ3JTz3F3KO7s0jRTny/bM61WNlLGS xn32/hNxfRQ+vFQn4UIji+8+p+ljGOio9u4IKktdY+6BB9GxAgJwMii5G3PCnrQkx+t3c+MFUip 2IgwnNytRJasVeZV3LlLiJHktaVFIx7sVybAPj9GdiRtt+wZ+5z9IKlc7q3040Gvvm0ZPZEySJN mptiNGci8KHkG2c1CKR+v0m0diECzaSVwKZKVS0s0yioqyKJMDYPpz1AwXb5c8Eq6jll3NA3Cvi HqNoqkYhBdWNWUye/b53A0Gbz2Y7XP0SOTcriy09yCqimRFujymS86pGqXmnqVga0dtmuKCKvZU xri+qOBxyi1mJNoXawpDMSBzyQVRFJphcPhnDTUgG7gyP7cL+l5xJPpYHGlsBdnlDPMnYJN9dMe IMbS9d35vSJc/wYz41aAinzUg2f7GBUG0X4JCCBS536El91ay9fwrFp6E++xKhQScREj1VPUYCM Nk4Rt2cG/rJgO+iuQi8npNAT7pGjtCSSzkjmJ1V9Tj5UybbcAzW2Ix6SMiXxKvGItxIFs56xJ4h stCS07wBzMCguKc3dB7vtEKhv2DdmZA7BmOAAPDMNgmZ20ZZsX9LepSmF5BIlRPC+ikfcDyLhCG 4OHIfGyOIlj4ufA== 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 196794089f033..666bcd6e46a11 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -188,6 +188,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 T +where + T: UnsafeHrTimerPointer, +{ + fn start_scoped(self, expires: Ktime, f: F) -> U + where + F: FnOnce() -> U, + { + // 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 Sun Feb 8 07:50:40 2026 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 A20AB26A08A; Tue, 18 Feb 2025 13:28: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=1739885337; cv=none; b=qyDSmNBvvCUnAW4YHSRd1XR2Y2PI2KPq9wsUQn6jUsLZ6GY3aS49bHKk/p0mQ0Dfmnrs5vmmW/8XG18nDKFCOXbDFcX00WzYJngJ6tztCjEuNhZtQGsRWTC1zkIFxun1aSg+MvTsFLwV2BzI+Rv050xYDHCE1roTTYKZNamMpPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885337; c=relaxed/simple; bh=dsJMGL8Vy5ZK8N2dXrkHVY1AwzDKsAsYWk8CdjvAtOU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ckKVZkUjMMHqUj1AA2zdxWUWelP2476ZLmkwGc1h4/fjtjk2Ns6QG1Zmc04xWu6xGkmlC2wd/EAv25rxra25JMdA6yikqjG2+DqNe14LeebhC4zQvZkTGStHV7OQrvYWwyCFL3JKnYSFyhuRVuUL/pXIap+IidViVXswRhCr51E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lj3RfYk3; 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="lj3RfYk3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AFE7C4CEE2; Tue, 18 Feb 2025 13:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885337; bh=dsJMGL8Vy5ZK8N2dXrkHVY1AwzDKsAsYWk8CdjvAtOU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lj3RfYk36xYBq2iN6O13H0x1mXEbGhBjIL0s72A7LUUw0TfaEvmHXr7OTeBU/wgjw yIDzdkld5GXeFG5km4+MVBRKQaZ04ZWJToxm3bzJGvsIbpFl9HAwtCuewaeofF+eNw hKvqPiWM2tqLc+qNIPEW+xmpW2a+Ci/SGqXT74ApFbsvDADAhTgVxF+nVXnN4EnMk+ mcPHJFiQGKsP4kHqvFNOoI+LAf3fTLN3PIiqNclhpZtjnckuEZ3pRbaKKJrhfJdpPq d+q+qE6Bi6mnx/kLN3ltuJZ2pOkSI0ijzAk9DkvKrsUniHhwYaQBujTdluKkOj0+C8 nTT485Y3KuPZg== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:13 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-8-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=4040; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=dsJMGL8Vy5ZK8N2dXrkHVY1AwzDKsAsYWk8CdjvAtOU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq2B+VeCZle6Hpm68NBzkhYeYXvs9yGkVwyx QFd6y0xY3WJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKtgAKCRDhuBo+eShj d21vD/kB8mENb+jhiLrI06aJfIMC0nN/65vxIyMtor8H/LwuUdhNlRyrIjAThff3Z2NHffsnlon hlINGL3pGS8Hr1chIOfaeEBE25pc2EAgdpuJ+qJ3C1E4izU2ZpeEB/TO1N8wF0/9mnCKqLUG+yB Wyiemcslwspsgb/4ZJ5u2BIpmmS8+sf04pnFvSAS/JJBAYsIBeOfNiN888ctwbl7SqczX+IWc6x gn31a/bm0kowBDE18g4U+AeHyNvtKHQevDhzRwXh5/mS6B5F/n8hE0tKYNqrGTkwYWMm0XWpAns ht17qdtOmct0jGAOjNduen5OQV/gR+JYpHksGQkihFxcdsdJt1hUtpJoLJiDZIBQPiarNhjhYCv Lq5iNgy8grhUUrpyt6Wpft14R9Mc9J7GBTuVYN9LjIOsJASxQYNgnUaGQCll2ytsZLTE/NvooKm KbN7nfPiOJUcd/zGwCV5Z1VW1XknWOJjAt9h8p1Flpdioz93git8L+lMC6oOJisGXMrcpPO43/A 26XmTMQ5lKiQpisJgauCtYHuzyk6zYnsIe4XgZbjNRcBBYct1LoQBn6SoHDp/5WCkZ1j6HGP19E M5aVj3BvMz66LgzDUO+jCH3QvxwDC09/fjJT3wHWmMFq1zu7pW0k7GRB3YF16e6CwuL8LNfBPXx 0GDg7LGA9iyR2nQ== 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 | 2 + rust/kernel/time/hrtimer/pin.rs | 95 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 97 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 666bcd6e46a11..3228ed916b4fe 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -402,3 +402,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> =20 mod arc; pub use arc::ArcHrTimerHandle; +mod pin; +pub use pin::PinHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs new file mode 100644 index 0000000000000..ecab39118662e --- /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, T> +where + T: HasHrTimer, +{ + pub(crate) inner: Pin<&'a T>, +} + +// 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, T> HrTimerHandle for PinHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr: *const T =3D self.inner.get_ref(); + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `T`. + 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, T> Drop for PinHrTimerHandle<'a, T> +where + T: 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, T> UnsafeHrTimerPointer for Pin<&'a T> +where + T: Send + Sync, + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `T`. + unsafe { T::start(self_ptr, expires) }; + + PinHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, + T: 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 `T`. + let receiver_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + 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) }; + + T::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 3D0F62698BE; Tue, 18 Feb 2025 13:28:32 +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=1739885313; cv=none; b=ss1ZdRpi/e86BKqLC/Om3Eik+fTXK2iZxEV+vGsLGDOGvEb3q6ndaprZiz4faIvjari7MyF4Jpn5HzYx7KNKTRiy6AD3SXt6rrOUbVcICmroPMCVM35oh1uZbEiGO7LjaJjQN3AnzdJ7443SUF2qh1OV2mHT6VGdBoulv/Yirf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885313; c=relaxed/simple; bh=tCj5oG07VVNWC3t2NiX5T+MQC44KNGSqCWE3dxpeY4w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ta7AXerytKBUto+RTdHdny5ziNWGZFaMgerRYUfgAkosiHtpy8zyawEqXGrhaKuZ6m74bgBznmY0DRC10alzyyil6+wcpuB2zCWr7TXVqhDo/L2wAIKXcFDKg2XaOpCU9Oad9PtHHope/NbDmJrOlbjsUK2fbGBm74irMru9ovU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q0xcoQ1d; 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="q0xcoQ1d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48031C4CEE2; Tue, 18 Feb 2025 13:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885312; bh=tCj5oG07VVNWC3t2NiX5T+MQC44KNGSqCWE3dxpeY4w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q0xcoQ1dyAfrpjApojfVmkK5S5A4+tCyTHLRxycYKrX9UzsYd9C+U7PIpua2iN/WS raxxW2bIn8ge4TnQbbmP59rQbb4zBgk69ySVBy88YK5j66TaYZdZUs7bHhKfjSkem2 QhaIOCBVDzsxWj+IiZw6NzPOtsl/pPz3v0A69y7QEEUAY4RVq54dzJV2M1+VACs/+L Q6cGerWY4kWTcIlb2dj8jr9tVW40yv1VkQadxdRkBp9N6USlaCWDiTGIAcLMczREty nVmoFAjyKKDJpskLD17owkxkB2r24U6dn1uNjJtVjGHgKYFqDQ0tHUDADG61aH95pk RHJ/vfIjO6Iag== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:14 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-9-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=4284; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=tCj5oG07VVNWC3t2NiX5T+MQC44KNGSqCWE3dxpeY4w=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq3JhXcbaxidghDp23kfXOfb2Q44iEwGK6lz KZ+CjxxyNOJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKtwAKCRDhuBo+eShj d5OFD/96oSJfnFjuj02Wr2gQxx8vg/OGGWz2rENPs6al9YhetgWGvc5H4n0xUqy7YPHBVSkDpOR 6CBkqtRkDuemUI8aim0qdVOZenEShHgqHafVrjAh2K5cms0zAVuUbi5MIMI/iYuePUpZTX0+Ua0 PRLuvVQXK9xS1ugQCz28kAm9Z3MWteGgYdPr2nZ2igp7pyRHDRnYTASErGTAeLEDvp8jIKBJMgB /mv0bRMiuo/gtUymvXwPW6MEAu27BViZuOrBjauZ2PD6jnUAhg8dNl6Rb242WgDPoYhRzjdJH0+ GAFZB3TMiA+5u25w5vUY4dJV738grgHzU2eVY4a6elc7hOr66QgutuiYgqYn/ND1vzcB5q5n9dW OO7JAsEsg2iRlE9H8XfzBqtEl3bgnlpi3eqEH/U7M1CSUaDlOW1wwYViLaGIkCljHSPogca/kU7 DBqS1YTaemhxeXKUI65kPsHZV/DxDBUqV7r4Nsz14ksFaIJ3CnmUUwMaYhpJdZtuVsUo8y99qAC 5RnUZ643MV9Zx72Iiai5v5KmIHnLu5vPfvTSa/8FPpMS5IvRdFRKz8QWH/3wNh06rD3S1I3cFUY RjsMHw8Fa2kQU2JZgIVZZRkCtwaDFhUb0iFY9oFvIoJaozToO+mo1/B88Rr3O7q40SA8wB7Bk4e /FDUss1rlH2HsTw== 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 | 2 + rust/kernel/time/hrtimer/pin_mut.rs | 97 +++++++++++++++++++++++++++++++++= ++++ 2 files changed, 99 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 3228ed916b4fe..f36513cba4351 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -404,3 +404,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> pub use arc::ArcHrTimerHandle; mod pin; pub use pin::PinHrTimerHandle; +mod pin_mut; +pub use pin_mut::PinMutHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs new file mode 100644 index 0000000000000..153e89b86caf2 --- /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, T> +where + T: HasHrTimer, +{ + pub(crate) inner: Pin<&'a mut T>, +} + +// 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, T> HrTimerHandle for PinMutHrTimerHandle<'a, T> +where + T: 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 T }; + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `T`. + 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, T> Drop for PinMutHrTimerHandle<'a, T> +where + T: 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, T> UnsafeHrTimerPointer for Pin<&'a mut T> +where + T: Send + Sync, + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinMutHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `T`. + unsafe { T::start(self_ptr, expires) }; + + PinMutHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, + T: 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 `T`. + let receiver_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + 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) }; + + T::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 7861A270EB2; Tue, 18 Feb 2025 13:29: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=1739885358; cv=none; b=hEJceVpDQRGwJMNfcIFcFCqlaJeMI1sJfSMdr8y1ngoazPueQwXIoZAUxSY6/cte5NdfE1FiJjTwFTZhSOB+LKTp+Z1wiUvzUWXKIybIyIj4F+CRHorpzJ2Mk5mJq7DMVzZd9Z0GEKKoENqYCGm8/xylg4rVUteQKbZUebGXzTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885358; c=relaxed/simple; bh=nwZNyOuiuprl7SMNik85pXwE5CG7wJ0i0TbeV7CGEdQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OUJd5sNAnWUiBw/X5LcsznBzl8q03p9+N467pRKPYpNNd5cUb1sI4rTBFJnnE5xeB9RV8XOk2RzsdfsW/wm/btbF2+nJ6JkKUO3ZeTD9SUh1CiufrviBnI1MmPRnBJqeWzb+LwGKz9HyrLgD8aJBCWCeP6oVdwgxFomvYRSCQRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JoXYkXxP; 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="JoXYkXxP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8431C4CEE8; Tue, 18 Feb 2025 13:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885357; bh=nwZNyOuiuprl7SMNik85pXwE5CG7wJ0i0TbeV7CGEdQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JoXYkXxPyMu3iy5hwEg66jQ6u0cvQTiSiJLVOaO+PIA14hlaiVxbc6p/EX9hiJoQo ZjG6fOEGbRfKdaBR4hf0l6+gQWmAomsMdwvUc5TB9t1W8KmYmJqjjC6gvIC8Q0mIyv CmJNTvZ7qyRsRoeIhg3gNNWoLFyBu2AJh3XAWeTi2rK+MFaIavzeet/uTdiE8X9Cap T1yx5pW7cZq/XffY+a/8ItjRkmDlU8mxYeDnSZvQYebe+wClJz1+Of5Nb8BLULHyTO /oOBiTQ9xIZbZdd3nD5qsXsG5SOZ2Iro8YMfnbZ2huOpq76hMQtUCH18eoqJr+I079 W+CCrTjrlks/Q== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:15 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-10-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=1028; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=nwZNyOuiuprl7SMNik85pXwE5CG7wJ0i0TbeV7CGEdQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq4n7RTCoXhS7u6DlebG7p92eiZABT4YHP5x 7oX1G8mO2OJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKuAAKCRDhuBo+eShj d4DVEACCRkXBowHgAhVf9vblwxpFJ08MKHX/n5XuydtczVTxeVxJy0PzSJc6vzvHwmlLa16KeIi IST+3WPFNSsMi9IlgjelLF7w7qBS94ohS9uiQgX9B5HZmUUEvYaQzqfkiNcLhu3A/bw9RlSY4il TD+OErdZnCd3t8oZ4PcfpIhVozWT7HCYHvkk5hOVaS7fKCfA1AVxcXWOcYq+Y7+U1k59qGybvyj Zy2Xta4gNKKzXoezfFipFcoUDbI1J/1WXOgV/uVPzO3EqRxzeHuVAgdiA2fbhHUbbMncPft/XYD yYWZfElKrlfZ4n52aLGp3AqaD/QB8g2+15f1Bac8LSvL5mrFXJJCpIvndzhrhuTutHxfjvTAokd 3108VGr4YHqYXD7Q4P2yZko0z7AC6zPDgg27u+9HxGiIQsk07ogbRnYHNUQJwBX3K9CfxXVl3P9 jCW2DPFzlNGKynpyyvM8eGyatjyfPEldA4MvJnlZGbRhfTv0RO5/2gsC20Ls/+ZYxE0Uij3MSbB t2IA4RyIWw87+EORCGNtRX6WZujuWxuus022vM9qaOS79zB3S/9WGo/3S9AFMjWbCcFGmuEosfd j5RRCDdHXVmFbiMsLFZMiJRFo702xNyHGNXePui3Z30rqLRlGmqdte3kSEL+iQRYnMtNcz4mEzq s67gzzN+BwyDzKg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add an associated function to convert a `Box` into a `Pin>`. Acked-by: Danilo Krummrich Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- 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 cb4ebea3b0742..9da4a32e60bc3 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(this: Self) -> Pin { + this.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 Sun Feb 8 07:50:40 2026 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 0E19826FA44; Tue, 18 Feb 2025 13:29:03 +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=1739885343; cv=none; b=Na4xh2UIMAY9hAdDHT6m5bjCDW6FNIY0gUwyLB19I3hWOG142wONxu+cWsbQBxNsSSXHgOz8q1DvUr7xS/gi67G2XA/OHtFPvO2mAu8UiFHE/y4rQyw3mruVSQqormo5+UXy8q3ZYKi0vJTdDfLDq4M0zlXjro6nfxfYm4MbICg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885343; c=relaxed/simple; bh=GdL8CTL8TdtXCZlxISGaGmp4Wk2SYeeszwVWXNJKMCI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=USxJjWG5UO+t7dPmYqBwRAldAUeEcHl1QpPQkYNI9i4gu+ZAuzyelSrE71jdGu16chP+Gnr9XOuddOZXdrOGPeL82FShWFhTEVc0LDOEC9BTtoY5RVdBYUXyw4EfAanvTy+Z4g/S6YCLk3m8caUvrmjBuThxmUOhAAWTyj3hayc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NBGtdo4L; 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="NBGtdo4L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 371DBC4CEE2; Tue, 18 Feb 2025 13:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885342; bh=GdL8CTL8TdtXCZlxISGaGmp4Wk2SYeeszwVWXNJKMCI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NBGtdo4LnLQq/f5/qh3Pisu7RsVglvKrl0UQeCVXQto4yWEXVQT4PVR9U4GThf8Hn QjHs0+Rs5/vTKfoidw27wuG7G/ays2tIKrHK0rfVquWKTzJu1SB73apJJa7vogqG9z hMrutUQSFdJcOABRZGnOZUqqQ0iJIECZip4G1zAvynje+evWN/7eX7LqpAdwVq5/62 Pn/cybxMkwvDKys5x9F/Gxv77ECYMA9c+7WRvQp9s96yqk7EWEjPWanVfmXYCWRXbB +cJMPCmK8KRJL24OmCZFT449MoNY1NQ6wjA0nVx9WGb1GUv6/Xnu196D9O6WVNrCH0 5Tks3+WZInX5A== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:16 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-11-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=4469; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=GdL8CTL8TdtXCZlxISGaGmp4Wk2SYeeszwVWXNJKMCI=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq57brDPBamIbPGr9m9UZYAMYq8jcTUB2P7p ZwgpnnwgT+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKuQAKCRDhuBo+eShj d7n2D/0UTT7fHs5f6dRnOmrTmqt4R68Fao3gkxme+cq42UDz28lCvMldQZgK/J/O4CpxwSK5jQw 8Gh7ElavclkqzOhPQ+efUs/ap19rEG10cJ+OaZADxOeJt3P8gzES24Cc57xs0gewy8/x60VvLP7 fjQdqxVlDP31Xvkq2OQLo5CEHzdgSxwhTF83oDL0p6AIZqT7QY5a3SNaWq0EgTmYe+MmphE+wSh 4kmP0AE7tZymz6h3YfAJqPhTKSI7sTnIOknDVrbNu20GZxhoIeu8QZHFCZnvUTU2fxyO6dg093H 4Wor0t2jaCwVh4iwmgI/dL8bx5EajEnNT4R/l2k3EQNFDiTrJwM52OHj5uaEvNt8ns9YrYt8jHM DZ0G5dZJbnMlJ1ST89nDvbggFyvyK3pLEmh+3KCRCaNfUll01CDcvvZsCMDVRjdLi/BqRx97LT5 0cOVwqsx5zdjw7qMgjvlzt47XcsniNB6Q5KpgHM8hpWSpfOfavh/2EBftc8bGdFbt1oXqscGtKK 7eopjhWU57pyhxU+TQSI60/IxqfyT6458+EAflhh0gw3JAFh2bHk4oPi8E3a67mIFewE3oyvG1L JC4RH+ZfETLcBNddhBni7GNYNEIqrDs+vhCuvk+3Dg8qGKmUg3VPy/4tplkwutrysQTRy1qQXrZ FO7hmnNNX4/6tNg== 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 | 3 ++ rust/kernel/time/hrtimer/tbox.rs | 102 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 105 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index f36513cba4351..de9edf52ebb07 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -406,3 +406,6 @@ unsafe fn raw_get_timer(ptr: *const Self) -> pub use pin::PinHrTimerHandle; mod pin_mut; pub use pin_mut::PinMutHrTimerHandle; +// `box` is a reserved keyword, so prefix with `t` for timer +mod tbox; +pub use tbox::BoxHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs new file mode 100644 index 0000000000000..39db96de023a8 --- /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 + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: *mut T, + _p: core::marker::PhantomData, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl HrTimerHandle for BoxHrTimerHandle +where + T: 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 `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f.inner) }; + + // SAFETY: As `timer_ptr` points into `T` and `T` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for BoxHrTimerHandle +where + T: 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 + T: Send + Sync, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + T: for<'a> HrTimerCallback =3D Pin<&'a T>>, + A: crate::alloc::Allocator, +{ + type TimerHandle =3D BoxHrTimerHandle; + + fn start(self, expires: Ktime) -> Self::TimerHandle { + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: Since we generate the pointer passed to `start` from a = valid + // reference, it is a valid pointer. + unsafe { T::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 + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + T: for<'a> HrTimerCallback =3D Pin<&'a T>>, + 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 { T::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) })); + + T::run(tbox.as_ref()).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 07:50:40 2026 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 59B9926E159; Tue, 18 Feb 2025 13:28:37 +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=1739885318; cv=none; b=E9j+PY9/EdKS3EkIi2a3Z4mXlA1RqOZh8JumwcGSiDSG6SINJO3yEtM3omKcbxH2lQeRDIB2ghufWk3U377wNiUko2eDOeJ7PyDMoPmk3qZbKHMViqglhKorXLkPANdZ/LYxO/Q0fztiTMMmY60Dt75xAUdAZJG4157UrhNw6fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885318; c=relaxed/simple; bh=DyhUM3cGjVtemPeWulojmVfZzFOhawmRI1WoCDW0lco=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kJe/qhzzAr0skwnVCgGUFHhr78B/tOW+ZFY42FbALl5imI8f8gEQ+7JRLn1wObhiyZA7asCD+G5nFoaCDdxcTIPbkQxGeaWC+16rIKLCzfAp9quF+l33aNhlP0fFqUmab7O6br6TnHUcIH8tx6AoKNS3KkT/I5zNWOF6Oy85PE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kBdiLfwq; 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="kBdiLfwq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85913C4CEE2; Tue, 18 Feb 2025 13:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885317; bh=DyhUM3cGjVtemPeWulojmVfZzFOhawmRI1WoCDW0lco=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kBdiLfwqVtuzzcLtHIANm8uGSMzt3AhSjj4bJCLeAHFPJwuJ/AWVhs9c+2y+cghyV Y4O9519ZhrcRBRUwL20ikr6JsHLfgU9WYmEtnfh1MPGL+xstYABQhytpUCpeM9jb13 H/vicXRfa6epehvXWrwgwsKqZ1eBwZL9deCOCDC/F6b7qnZOcZyG/EYAbw3lPTk5rS Aq3ABZSZLVa/ndN7KJe3lnhxd/jWLzCZ5VX8ZfQqrT790B7WmcvdZDQbTmFecYwIub XAlsisy2IfZX0D7vXm9yPUHHMaXWaumba94TORLtIg+JBaY13OU+56EI1Z5fvtA64X 9YzDnGxnx/xDw== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:17 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-12-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=5630; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=DyhUM3cGjVtemPeWulojmVfZzFOhawmRI1WoCDW0lco=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq6G0x9tlCXaZyowuUdqMeWq/ugWljtfVYLG CmD+pOsfcWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKugAKCRDhuBo+eShj dwiND/9VRcJFusNBC/ZUFz7YLB0Ww16mltK+RCd809GwsbeVoVjahAidQY5LMqZ4UrJ9gqjWGe1 LkONkE5UE/uQiDqXWoyzBWJPQ20Bl/TQBbYfgOuS3GlTWqGw2esmXakRnsJo0mJE2uYwYtTRgXx SnKn36uAYZlHEaSJnIgGoLeTiVtsXSZqJpnWxMTM/6ADS6/nhCzfiuxhcKDZ3Klz+RAFElLIn6l p8c14pi0XaGuDm/ZvYcQZDfy+4rzkeTKJFjqC7REAxfPexUpffOb+gRIRyqfoJUmOe5j3lRGFP3 D/h7GY93uqsWNL1QQs1hzfTeLeLDYuec5KmB1eQ8BCdDIC7X2MO8Uv+LmqjEsTQkPf7lcbEq/yw oTb+TSQ8mBb8b0lYIBV5w8aXhxCxY3MKOG5CeSMHvN5UqKgOKKbApJeZrY/6wQKBkjBWK+z5TZp PTpfGBg9RMut1xbF1EX77OhoctiJtqrVupv93wrDKNF9U33EEU7lrHYALJ2MJO2zfwtleYwiBTL EqqJ8B166ep3E5cd7SvUbbs4+6OkpvUR6TqNmLnpm53C1RhtvIn54vH5KNXm94CSIntTcJSayRO VLnQr37p2Ypa72YgYlO9Mm3yL/sXQO7NG58BLudv3I4ol/VDyo52sq3NurjsjT2wK7sfge4jLTo Zug6p9hMI50y3tg== 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 | 86 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index de9edf52ebb07..db49061f830c3 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -59,6 +59,7 @@ pub struct HrTimer { #[pin] timer: Opaque, + mode: HrTimerMode, _t: PhantomData, } =20 @@ -72,7 +73,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, { @@ -87,10 +88,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, }) } @@ -336,7 +338,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(), ); } } @@ -368,6 +370,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 Sun Feb 8 07:50:40 2026 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 C6C9226B2BC; Tue, 18 Feb 2025 13:28:27 +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=1739885307; cv=none; b=tisHondUjz+Ai6cLXZFWvs7bBzKglypS+lp5m3N/ZtEFUqGGnVzPWgp/4uyutS9Dl0k9JtsefG294/bJwbBsYXXlj3tDx8+704BQfFtXzAOM2pcsyynDA4f/G9+zKwl9L6E9/VlrcZFsZk01VtZjuDF36bupuSoWdT/1AapzBsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885307; c=relaxed/simple; bh=FhqC9LeTi3i3E4qvwVUGdTQsRHg4Tojfkv9D1HoCLaY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LKC7wOP4c7OD79Lyoq92w0UHid7Ef4drKZ4mC+G2aOeXpA+N/S8qqxMPIM2zkCEkrTlNeE2OA8LitFcoZ1U6y+5tBgtz5KCFjAw0BLlXbA5N9bIOKbdooC6NHldhlhQN02zYAQ5JHfc+mpZhbWQ05YIHcqesufgOrTU/I4mGm0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gbGtZKTW; 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="gbGtZKTW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B119C4CEE2; Tue, 18 Feb 2025 13:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885307; bh=FhqC9LeTi3i3E4qvwVUGdTQsRHg4Tojfkv9D1HoCLaY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gbGtZKTW2FJWDPdnVdTEZhbjBEOKYBUPY7xUPGt53p5IaZm2EEti2wwt/0bKGjRgN qhylmTn0Wx0bd2QOEcJ/WaecEOMahBUkKwImSHIVMiy3WJStaUSY1inHGmVMxbyaUU zrZPPdvJc7BrAoJHwKJimo/dvimme/8QZk5H1Z1nNzcBpZU2SqAcDDrmXaJ9XRwrCl e8x54eYPbe2YAFfAsXTgay9LQVWLmI5dL/YiphTS4//wnseabDuvCURdV2h3FB+cWQ IL7F8n7G45yquQX95+x5G9l8Fc8A9VYyeZcYM3SCM/R5LpFE6e5u5DAQYqzImpC/kx x3ZhUchNjgpow== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:18 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-13-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=3998; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=FhqC9LeTi3i3E4qvwVUGdTQsRHg4Tojfkv9D1HoCLaY=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq7YANcgZqMzDeuuifIn4VXRQuerYmLWVIzq 0LW2VbwvwSJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKuwAKCRDhuBo+eShj d06KEADFvgDST9bU+byuR3mbPkPDWudF54VYxCyLiNZuiN5ItEinvOIi/zJzqXKFS+47g6BcF9a nwmbAKtfNaiJHhigOGUZlyx/U4WfakMM+y8uI9bA0wjgfaFD/9IbOvlZJL4pbrCsbyjj7fBq0hw +Y2ZA8XR5eaEDJouSrlW2BSnI6ncQqn2hyX+eTxpkvqZvJB+Lb3O5kkRsA049Bz8Ib0twbsu++t qXJoOKhiwnN11vJaDUh1u5gEfC56fF9DNQJtC2/5bOynD6sl9WjfJMQd5+LT4fELpGF/oQeONbY Yb7SwWT6AtiGG33qnuXtENWhRUSJSpcorD3qELRycRsSq8rxLrBOaZAEPln+S20ucNgMPmrknR0 GIQgqTD1BqJ+/o2CaX4lSDT7VY9QdJGu0/biMy1GCtuvnkFogu7A84cFG0dKQzYeDoJopu09071 TMXNr2N0Rld68QNN+Grct/l/E1ukMwr29LKqjx2gs44HCJHseIoKndKmFU5ljYYdPeBm7nENyzA KShBoxfuZEJrA9mf4AoYg0G2WOlK7QDHJFJkP9u5rO8yd2KxPir6WDwqjbMfAj2bPudzqCjIMGT tHNw2CtR52VGZO86ccTnNKb063R2pGvS07OQY6o/QHMI7kYbf5+MA0tZQMoEFO7cV5Xx+Fkx/er O7c9LR63TFsCzVw== 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 db49061f830c3..2b46d66eaa313 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -73,7 +73,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, { @@ -87,7 +87,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(), ); } @@ -448,6 +448,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 Sun Feb 8 07:50:40 2026 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 04D4A269CE2; Tue, 18 Feb 2025 13:28:17 +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=1739885298; cv=none; b=TNflHzADui5W6V5pO6Qqcg1BZ7Lo5kZdNXrZQxTi6DRE5f+D+cr1mwDKhGpRIc6HwnIFunMpTR+lKX2HYRzgMwWibvGvQ4ZfKbvQktcRlE6yIjLaB+gYB2AABkVXBUBn2beIL7EKrTSrkSwOMaAWQ6H78Eoc9yCq4VO0n4tPOQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739885298; c=relaxed/simple; bh=ROEeOJKEp/vl6zYT9awrPNL+gZGZt1QW/GbDdFhlY5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MLeqg4etG6thvAR3f6DcknjZ5QzLQ5MMR40IP9CR/dI/TdCE7nwizPaGp3Kd9P2Nw5v4RP+HzqfKeNe2bhu6v5IYpEy3DtJ+fj82TMwFIAAXpNepI/B+owy707Y5kc1IRm3AnROvC7cgnsaFJIkL85BC/ov5Fy+HGfDtdPoCmfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCuZ/Yyo; 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="TCuZ/Yyo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74997C4CEE2; Tue, 18 Feb 2025 13:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739885297; bh=ROEeOJKEp/vl6zYT9awrPNL+gZGZt1QW/GbDdFhlY5g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TCuZ/Yyo4F1StrSNGFI6vYgUjFSiZ6G5J2/jvPN0Y1oAkaiEuWLM8eVJdtZJGfynr 2bro+jcsi7dc+QAqqeLr9FigdB38DM459TIS0q+blW9kuMOgrLyi/QbGqsNAl/xNqx AdTDnR81aJ+LRi2ByV9UZjoMJZvsxUvPxQkks5RwBBQ90rOPbiKmvtCUjphci0ntXS isFMYn6YdKnhVOFYMgAh3W+8KLFc9DSMLoQGS+Foq4POPWpTI1dcfxy40+aPQC6JPb ZVT5O25Q0H5+m6UhRLweJqMyj7JLzi0SvAoAzXUxP0JUAU/y2fsSdNW+ZNWK3c4pYW cJjug/phqEblw== From: Andreas Hindborg Date: Tue, 18 Feb 2025 14:27:19 +0100 Subject: [PATCH v8 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: <20250218-hrtimer-v3-v6-12-rc2-v8-14-48dedb015eb3@kernel.org> References: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@kernel.org> In-Reply-To: <20250218-hrtimer-v3-v6-12-rc2-v8-0-48dedb015eb3@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 , Tamir Duberstein , 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=941; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=ROEeOJKEp/vl6zYT9awrPNL+gZGZt1QW/GbDdFhlY5g=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBntIq8VlMF5pCTBVJzMb9uAqKb9vLeY9xbRZk2y RAZM1TR1b+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7SKvAAKCRDhuBo+eShj d+OOEACswkOIH7Rxy/sQgKUNHkHQilMWXxyBxWIyu8Uxz9oEY3O49b/NZnojP3xsUMgBrpNeQUg TtKk2bxfLepdZ08/HJhPPQV3BVXm9ITWHblU855Z/5C5mS3k7p+2XZGx3N7lJ4OM5JI/wbpMG8i Im6oYotBYKmU0ZgpScNF2Iq4cvqGQv8vbmDVFiVL0luwI/bIcf2YaK+iwwiUYcL7YVCdoxRYNI7 mpQfe5ZedKEm1oOotUto/gEQP76T/CNxJTkBwVV1dJInnkhVJ5nlMVarWIirwj4oriv8lMk0Oaz X00hbleDGdyCyG6sX+nnnSJF7PlzY8lwb653toSE0QB5V5ArXoHGZrNDUCrAqBfOwSeOiLRjeBs aymbE55AxVGDD29bqq8J0Cus5Sgje54BaEWNyAU0TzVsQROkEyVPqAUfEp6iBui7ghmbe9KqHIO VuJgIUTPt7/ivVAM5i/1xs/cTg65ZPPg49ExJcxwwDEqa41NeP5JwTiA3wYKGATG4g1fU7iTlly 3+9zQI8eYzMBCA/BLnj/4wNvz/OlrZZ4Xt06EC2TrBEJXx43fGmEA5qg1FfbrXEzohdbVJ+W/s+ sP2me97AkMFN7ay93mOiwfHuqJkRPfHyIHK/2amiEWAw/HSPi2Ax6QUDy1Z5G1qbeY5pJFljUQU ZBfoNtjr/Y62rPQ== 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 896a307fa0654..60fa77c41b3fb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10355,6 +10355,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