From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591761DEFD7; Sun, 9 Mar 2025 15:23: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=1741533793; cv=none; b=hFQ1kG3orO6za4JLzMajiCKp5f6bSsWAuaknBNw/d42yycgeR0OzSMT6tB5r3tXPRBJB8BRoQ05Sl8yzj/WLmS5610VdAsRO5OmapqedsLqVtmeA2heMSz5JIQExku32O03q9R06VsALOQ0pbAabfC1PL+vTDZnUnSBHbBvEHsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533793; c=relaxed/simple; bh=bWqwQAWawfp93QDfTX+eqJJXeZHAqgBI5SHqzrnlYd4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GZszmEZtDna3//byIjwUwhnnY7ALh110ZmA4RgNmPqosvLIyUf3PPs4IkYY20LEb8zAfIq16uRXamsg7/pxQlKXWrapxzyLDHvsstFwuUYU3+Eb46TjB7gi8cfV4XC6FXKm54+wN2+O6a6/O3WiCbuo1bkpjtPDjKlQWJYq6fnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EaX2IHTF; 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="EaX2IHTF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25F3BC4CEEE; Sun, 9 Mar 2025 15:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533792; bh=bWqwQAWawfp93QDfTX+eqJJXeZHAqgBI5SHqzrnlYd4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EaX2IHTF5+8qzdu/YiFOoxHpWwvK6gWbXvC02BwwekRdtZ/giJbdIRkIVfXheVi2j WW344IMLU4MVqVGMQWQ3xgiDC84kjAEj23l33dn4wTs89ANImHW7Qmbk1vhr4rgGEH L6VBGf1ThIk023Dm0KNzUXgHSdxLSQiqLBP1UctRoIYkSdUF+6mcQEbM/Zri9YzOZh 0e2Lb0qSEIoI0U4QV8db0xP1g5db8vFXWeUF467WTy3zIFIV9wdc+L+b5XhoEVbP7W hRoQneGm65rU+C+ZL9FdZ8TyNSCN/7DvUl38FCuwVGuI8ccx3B5ZEg3XbQqY3p3dS8 02V273OQJhtEQ== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:52 +0100 Subject: [PATCH v12 01/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-1-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=16086; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=bWqwQAWawfp93QDfTX+eqJJXeZHAqgBI5SHqzrnlYd4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFnupSHYCBcO/pO5XRwPw43OPYPyNY0o1Cmi mRPHqJTzQWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xZwAKCRDhuBo+eShj d/eREACdOUI5HJhy0nuD4Y19lbDLWasp/8P0JRsk0Cp9c/IYWTcknkS/afyOJCGSZV0mvR2cQoF PA0ynWOWKsXzmUGIX0TsWWnqfN+eC307m39WZXywXYgMX22F95WAmRHWUafrIb3PNmiG+BEWyCo PQGNHZCqNp9W4LhqJjbkibZG9rjFFime/J6gXhhf4PAsm7XOvKB8YvYAq8zyCPZSJRKgxELcNud Ka0yl4DTo0x+P2MhClAb5tfjfJAV9jg52LyxkyuMVhI5meB0ICrkeniUnzfiDqz+beJ9bUwNQEI I8L7rZRro30VK/auUgE6xJ0BQ9IIpE6I9h3jsg8vv3aV1oOre4gd80shte9mUX2lks4zgvYwj7r CTaEswEkzpH+X/AXzff3VSRMoUikBIiEAEiv3CagDtFkLhEqTHdiwtGc127I9zKLTF+Baw0CqI/ bDYq10oRry8+cBjd5FHRDilNYVlDIzJ3+EeeSo+qg2Uu2jOgzXSG74bhuR9mhMTjW3nOXLGOuDg cu5pKPUF6CMl2QtCkTWu8PAeEHl7y8iXRYVmPnIVTFcYALmxXFhAPXH7WuOtApIONbCXc9OPm1D oT8TAC+V6YHspLrmzVbEjxVLpvEfz/mvQm7emadu/h6EBpbfP6L3pT7Fz/C3wDZlnAmxJpwDFaR vFCcfPMTNnY0Hng== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add support for intrusive use of the hrtimer system. For now, only add support for embedding one timer per Rust struct. The hrtimer Rust API is based on the intrusive style pattern introduced by the Rust workqueue API. Acked-by: Frederic Weisbecker Reviewed-by: Benno Lossin Reviewed-by: Tamir Duberstein Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner Reviewed-by: Lyude Paul --- rust/kernel/time.rs | 2 + rust/kernel/time/hrtimer.rs | 352 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 354 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e5..fab1dadfa589 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 +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 000000000000..20d3440c2a02 --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,352 @@ +// 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: initialized but not started, or cancelled, or not restarted. +//! - Started: initialized and started or restarted. +//! - Running: executing the callback. +//! +//! Operations: +//! +//! * Start +//! * Cancel +//! * Restart +//! +//! Events: +//! +//! * Expire +//! +//! ## State Diagram +//! +//! ```text +//! Return NoRestart +//! +-----------------------------------------------= ----------------------+ +//! | = | +//! | = | +//! | = | +//! | Return= Restart | +//! | +--------= ----------------+ | +//! | | = | | +//! | | = | | +//! v v = | | +//! +-----------------+ Start +------------------+ = +--------+-----+--+ +//! | +---------------->| | = | | +//! Init | | | | Ex= pire | | +//! --------->| Stopped | | Started +----= ------>| Running | +//! | | Cancel | | = | | +//! | |<----------------+ | = | | +//! +-----------------+ +---------------+--+ = +-----------------+ +//! ^ | +//! | | +//! +---------+ +//! Restart +//! ``` +//! +//! +//! A timer is initialized in the **stopped** state. A stopped timer can be +//! **started** by the `start` operation, with an **expiry** time. After t= he +//! `start` operation, the timer is in the **started** state. When the tim= er +//! **expires**, the timer enters the **running** state and the handler is +//! executed. After the handler has returned, the timer may enter the +//! **started* or **stopped** state, depending on the return value of the +//! handler. A timer in the **started** or **running** state may be **canc= eled** +//! by the `cancel` operation. A timer that is cancelled enters the **stop= ped** +//! state. +//! +//! A `cancel` or `restart` operation on a timer in the **running** state = takes +//! effect after the handler has returned and the timer has transitioned +//! out of the **running** state. +//! +//! A `restart` operation on a timer in the **stopped** state is equivalen= t to a +//! `start` operation. + +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 the C side, so it is safe to ope= rate +// 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 { + // INVARIANT: We initialize `timer` with `hrtimer_setup` below. + 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::Pointer::run), + bindings::CLOCK_MONOTONIC as i32, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + }), + _t: PhantomData, + }) + } + + /// Get a pointer to the contained `bindings::hrtimer`. + /// + /// This function is useful to get access to the value without creating + /// intermediate references. + /// + /// # Safety + /// + /// `this` must point to a live allocation of at least the size of `Se= lf`. + unsafe fn raw_get(this: *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 `this` points= to an + // allocation of at least the size of `Self`. + unsafe { Opaque::raw_get(core::ptr::addr_of!((*this).timer)) } + } + + /// Cancel an initialized and potentially running timer. + /// + /// If the timer handler is running, this function will block until the + /// handler returns. + /// + /// Note that the timer might be started by a concurrent start operati= on. If + /// so, the timer might not be in the **stopped** state when this func= tion + /// returns. + /// + /// Users of the `HrTimer` API would not usually call this method dire= ctly. + /// Instead they would use the safe [`HrTimerHandle::cancel`] on the h= andle + /// returned when the timer was started. + /// + /// This function is useful to get access to the value without creating + /// intermediate references. + /// + /// # Safety + /// + /// `this` must point to a valid `Self`. + #[allow(dead_code)] + pub(crate) unsafe fn raw_cancel(this: *const Self) -> bool { + // SAFETY: `this` points to an allocation of at least `HrTimer` si= ze. + let c_timer_ptr =3D unsafe { HrTimer::raw_get(this) }; + + // If the handler is running, this will wait for the handler to re= turn + // before returning. + // SAFETY: `c_timer_ptr` is initialized and valid. Synchronization= is + // handled on the C side. + unsafe { bindings::hrtimer_cancel(c_timer_ptr) !=3D 0 } + } +} + +/// Implemented by pointer types that point to structs that contain a [`Hr= Timer`]. +/// +/// `Self` must be [`Sync`] because it is passed to timer callbacks in ano= ther +/// 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 { + /// Type of the parameter passed to [`HrTimerCallback::run`]. It may be + /// [`Self`], or a pointer type derived from [`Self`]. + type CallbackTarget<'a>; + + /// Callback to be called from C when timer fires. + /// + /// # Safety + /// + /// Only to be called by C code in the `hrtimer` subsystem. `this` mus= t point + /// to the `bindings::hrtimer` structure that was used to start the ti= mer. + unsafe extern "C" fn run(this: *mut bindings::hrtimer) -> bindings::hr= timer_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 Pointer<'a>: RawHrTimerCallback; + + /// Called by the timer logic when the timer fires. + fn run(this: as RawHrTimerCallback>::CallbackTarget= <'_>) + 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 return before returning. +/// +/// Note: One way to satisfy the safety requirement is to call `Self::canc= el` in +/// the drop implementation for `Self.` +pub unsafe trait HrTimerHandle { + /// Cancel the timer. If the timer is in the running state, block till= the + /// handler has returned. + /// + /// Note that the timer might be started by a concurrent start operati= on. If + /// so, the timer might not be in the **stopped** state when this func= tion + /// returns. + /// + 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 +/// [`HrTimer`] field and that all trait methods are implemented according= to +/// their documentation. All the methods of this trait must operate on the= same +/// field. +pub unsafe trait HasHrTimer { + /// Return a pointer to the [`HrTimer`] within `Self`. + /// + /// This function is useful to get access to the value without creating + /// intermediate references. + /// + /// # Safety + /// + /// `this` must be a valid pointer. + unsafe fn raw_get_timer(this: *const Self) -> *const HrTimer; + + /// Return a pointer to the struct that is containing the [`HrTimer`] = pointed + /// to by `ptr`. + /// + /// This function is useful to get access to the value without creating + /// intermediate references. + /// + /// # 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; + + /// Get pointer to the contained `bindings::hrtimer` struct. + /// + /// This function is useful to get access to the value without creating + /// intermediate references. + /// + /// # Safety + /// + /// `this` must be a valid pointer. + unsafe fn c_timer_ptr(this: *const Self) -> *const bindings::hrtimer { + // SAFETY: `this` is a valid pointer to a `Self`. + let timer_ptr =3D unsafe { Self::raw_get_timer(this) }; + + // 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 + /// + /// - `this` must point to a valid `Self`. + /// - Caller must ensure that the pointee of `this` lives until the ti= mer + /// fires or is canceled. + unsafe fn start(this: *const Self, expires: Ktime) { + // SAFETY: By function safety requirement, `this`is a valid `Self`. + unsafe { + bindings::hrtimer_start_range_ns( + Self::c_timer_ptr(this).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 { + + #[inline] + unsafe fn raw_get_timer( + this: *const Self, + ) -> *const $crate::time::hrtimer::HrTimer<$timer_type> { + // SAFETY: The caller promises that the pointer is not dan= gling. + unsafe { ::core::ptr::addr_of!((*this).$field) } + } + + #[inline] + unsafe fn timer_container_of( + ptr: *mut $crate::time::hrtimer::HrTimer<$timer_type>, + ) -> *mut Self { + // SAFETY: As per the safety requirement of this function,= `ptr` + // is pointing inside a `$timer_type`. + unsafe { ::kernel::container_of!(ptr, $timer_type, $field)= .cast_mut() } + } + } + } +} --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66D2B1DE88D; Sun, 9 Mar 2025 15:23:30 +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=1741533810; cv=none; b=JmmIJQGTHcgZMquCoF3L86uXI+xndcqn4CL68XdTpnsoeIxuXVi/hL2hU9ADI1fMCPLaETkpq9VddOgRtFD+KTURHRksy/ZiEvHyD3q2Lb26SBs3ESqx5a4u8jkn4lcNqDyZWhlxBQhCQ9bidpsku4FjVxRkgPFo//IBgc8LZgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533810; c=relaxed/simple; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q3dH1NvzYc+pwdy0x40uWZnib6Sfcy1YVfGaMzcPP0UATMsHMNAnifFjiSzqBl3M27kZVrXGk/+1LwJsSbbKTSw9bEiPkMtIA7PflsEjl4h65n2hKan+BB68AGD7meukBBR+hDizmk57SHETttygLcj6cOJ7Eif3jRYlye/cNRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lifuUnW9; 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="lifuUnW9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CF31C4CEF0; Sun, 9 Mar 2025 15:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533809; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lifuUnW9VTJO6b1EaevXAteYIcj4+ENT2modzKW5G0+zTkfRCWH78oYcDrRdBZ0S3 GmTqWLTzujOu6Gh4USsR7FFIebj2iqvvsXI+mmIaScSCJlPlpirZDCHvsYe6l7tRPS 0a9uv/7PJDGwo+FnzNwfqPL5H5wWhHgVAud+6YvV4PVTHdv/DR/gr6NEhItulCAPvS 6+qbNSKMVbajXx6cIsmXNG79tJbOKAQ9WxnzwBcI89J/zBV2DN4bMLews5m+6Tnx4z GlQS8Rc6NAWOdv0vuf1UEP4nyJDEAG90n6QK4bcqYilIsmoAyDKVSDOcbOA6ZxUhQ0 DLTa/Z9N/sDYQ== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:53 +0100 Subject: [PATCH v12 02/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-2-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=1949; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFoc4QCddRfOBqTbH64MPdX14gT/LUfOwrrZ O8zhs3+bgiJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xaAAKCRDhuBo+eShj d1p4D/4iOQYzLnxtexmkJroI6Xc2DFwLLtvwShqZCZaNrnd7qLHQ0Shdl/fN1M8bdlrvcE+vw3W k7R+y4x/fzkWcqnAJU0uVBfxNlKCH0VCIq/35DR2HW+9gVpAkr68guzLCs9dGCQAJuuDORcVMib i8x8z0CcQ+KkkA5g4kl4uzK68hO2gUtVEUIQQ55B4qKIzWSbeEUt/4feAE4FzfxBAncYccZqDyY nhAQkh1zvzr1mtNJIeRNJnvgAJOu/Ge08y1AaZ6xdisHkkfsyPz7Z4ROVpyj+9CkcBUYc0wEpjb tfDDbt/Y4J2xjXn0eKBBJJ0QstuN+tTLr57zFP0PJpggCs43ilH7PyYEShdoIvsWVxLh+KT1dN7 O9S0TQ1ohn5pF2NSmy1ZZhqr3OBKWAgYGCUziKhhcsPTESVMr5VdrCuh0gyumHf9DRUWUeat82f 3h80s45OK5+0NPk4czjMOR9F2R7c6QwaeWtiZS+fjua09Dp7S7qJgDpODvoAsif+JlAXtgKZIlW G1AX6OHtK3rZwKdjbqB0SUYjTVrHMmHx0fm4vVwCDeyifs0/cgaVjfGMlBZ3BOR9/XZn+kODWz3 22QMbV/7AqIVjMjRQ3QF7YB4lAalscyZO1J6fc5IX1CGBOtu3dbBm6ptymZFfANrMP3iQpJ+rWG AyKYHNUAD+vbzZQ== 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 Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- 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 3cefda7a4372..1dfa75714f9d 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 Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 198A61CAA88; Sun, 9 Mar 2025 15:22:29 +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=1741533750; cv=none; b=pqXX+uEIvODU6ESDDc6aIQC5pmcl4PIGhM3pDVIrx+Yo8FIVuBF8W9tgcnNeg7+LChIeDG2Hxa513NAZUJhan973EcRnDEicKxOY/zkIxqtt07NlN1dK5eJxw698bFpH8RTTZKAqeNBDtPfOVf37aGTN2JLYD1RxosSZECt6CYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533750; c=relaxed/simple; bh=e4Tg3ElvZajihJllWZKR6PZYEY6OPwlUgxWEPUgKJaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rZ2GHqTXjHHogidpRFAJbdpzycd3ePYjVuHQgXBk5s2Ub5lKZSy+7M6BwIsImAfNnOW4WUuHH/9rJxAohL4fRubm2o5t1Shp0Lp6fpuF/eKb85+CFJhLfY5ZgqKIjORk1KvC04gnPiARoRyu6TWe+FLfZFR91GJXAEMKBUrCAJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xb37gByU; 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="Xb37gByU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 611A5C4CEF0; Sun, 9 Mar 2025 15:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533749; bh=e4Tg3ElvZajihJllWZKR6PZYEY6OPwlUgxWEPUgKJaQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Xb37gByUwbmUhphReK41NKFGFmZWiNdhmkRVu95aGXBsORGRIsbYPAX2Nmtq/ME4j Mq1M0hnvORl1k++XVeIGHQUxLjHOlLU6QIlyAjS/yUuBY2gNjC0KyPvKZ45WqP18e4 ysM0BQvlnPmUCTKh7z6EaPTfwlQe+6v5ZaqhurwrLk4WXqGdevXzZaxuL4DJRVT78h 1iYa/4w7wByj1Oh0v3d8V8zXCcQ6/turaoQiON4OX1CssDaYRjieUxISoBOUKjNSJP tOkWX1Mi7WiyFu2sibageeEoVGjYQR40PkY3LN2BmH6Hb8N8gUBUiDID8zn3OKL1+6 BSwBkYRsaVcMw== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:54 +0100 Subject: [PATCH v12 03/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-3-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=4895; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=e4Tg3ElvZajihJllWZKR6PZYEY6OPwlUgxWEPUgKJaQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFp5FCvVV3WA5AMThM5Sq+0QmUM8ndC5ntSW uugHPsjzAeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xaQAKCRDhuBo+eShj d1DBD/9VrWKK+aPlF71ZdMc4S0JtrNfrHariNMg3NdcudXGw2OeEE2YJogplCuyrbh9aRhBB/yV zu6TT8qCTDWCcVYsbyHZsPCfC0GE/TK+Z3B6hp8hpRlfAdcLCQ8/6nBdQZ5OaljAc6UEbbJwVbI EUT2YlPF/iTvfiqn8ZnuJl08b8g/oiCfNrLAlq3kb5669YFnpci1zLueFyPAUX+UsWqrUkCHrqh s+kPA6PSMRi4PIHKkOuCKqQSNDA9yth1hufInyK0+B2jY7BcD/HFGzAgGJVDkAmG4KqrXaswkEv wJF1svE096lo1Mwps99xCbQW0jIfqru4hD+GcBvYOnZpHx6jgXRJie66WA9UjjJP0zp/lLJwTL1 MG9Jr6WILQB1Jf0zG5QNbOLGyQTLDfWU+qe4ujJG7NrbpbbbP80ozTh1za2w0uUCEKcxwx0HeMY sL2hxcgRNyHMPdKPkn9ubDR1yeoZfZ+aPeLbpxzGUXvPLHoCzXYo7yFeCcNOYQXAicslJuj/S6l Z6jU+kqjSva+wYxAKnok7iZ4eZvoUMHuOVDll7dLjI2OBwrPYbfcxzShCjXgymdPh6GLEy3u0Ts 6lwhTLfizbNYj9qRw9G5uTTMlGWtoarhH/xan19iW9V9nUswSCIHVqFoEDw3UrIjY+ve80ullMm 7A8a9DDMcf8ydMw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow the use of intrusive `hrtimer` fields in structs that are managed by an `Arc` by implementing `HrTimerPointer` and `RawTimerCallbck` for `Arc`. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time/hrtimer.rs | 4 +- rust/kernel/time/hrtimer/arc.rs | 102 ++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 20d3440c2a02..c6d6eaed31aa 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -150,7 +150,6 @@ unsafe fn raw_get(this: *const Self) -> *mut bindings::= hrtimer { /// # Safety /// /// `this` must point to a valid `Self`. - #[allow(dead_code)] pub(crate) unsafe fn raw_cancel(this: *const Self) -> bool { // SAFETY: `this` points to an allocation of at least `HrTimer` si= ze. let c_timer_ptr =3D unsafe { HrTimer::raw_get(this) }; @@ -350,3 +349,6 @@ unsafe fn timer_container_of( } } } + +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 000000000000..df97fade0aa1 --- /dev/null +++ b/rust/kernel/time/hrtimer/arc.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::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: 'static, + T: Send + Sync, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Self>, +{ + type TimerHandle =3D ArcHrTimerHandle; + + fn start(self, expires: Ktime) -> ArcHrTimerHandle { + // SAFETY: + // - We keep `self` alive by wrapping it in a handle below. + // - 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: 'static, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Self>, +{ + type CallbackTarget<'a> =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` is derived form the pointer to the `T` that was u= sed to + // queue the timer. + // - As per the safety requirements of the trait `HrTimerHandle`,= the + // `ArcHrTimerHandle` associated with this timer is guaranteed = to + // be alive until this method returns. That handle borrows the = `T` + // behind `data_ptr` thus guaranteeing the validity of + // the `ArcBorrow` created below. + // - We own one refcount in the `ArcTimerHandle` associated with = this + // timer, so it is not possible to get a `UniqueArc` to this + // allocation from other `Arc` clones. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + T::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9074F46426; Sun, 9 Mar 2025 15:22: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=1741533733; cv=none; b=HO+btwDxb3PZFnAvKWvMgGnRz10ZYGLwXC8qwAdGiqWWKVzWY3DOy7mp5VL9M5FixqeE9uQkEr7DsDHEPMh6JLwUOCsJCC91G4HY8kwDOqndtndeh+PLsMWMgeeBBo0aJpf6VXsd/2da3BsDGnZHfyfGwcgcq5GD/SlDHp6zRWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533733; c=relaxed/simple; bh=rhf4QgkZueY9HFyMVTo8jhUZj4hOFxWhVw+dFxDVS9k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QuVPIvLaKG75defX+ua5udTAKN+t1dRQ8l5B4Rp02VmGSmAqGoBpUb4vE0NSRYDWyYgCTBypFSqycylpnjqpNXqZEW9RP4Fou1VHD+c39iC48AjFg+7brqsyu3wYzc8mx4Lh/VHgL6R8MOq4Q7bESO7jkFXEdzpUPDMF4HZjBLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uhmo34Eg; 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="Uhmo34Eg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE8AAC4CEEF; Sun, 9 Mar 2025 15:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533733; bh=rhf4QgkZueY9HFyMVTo8jhUZj4hOFxWhVw+dFxDVS9k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Uhmo34EgLRzFS/Y6lolYe3EneZYp7Kf83xdZQgZA/t7QrEvEitTXCOdOMulpMsA+O bjB4cSJZ6q3Kw97T+uadRscH+16PAW858jq3vySlSpFDVrEO04ZTv9zqGoa64doQEb 85vYScvN/zBMlGfI6lDrLQYN9Qwd2j2ZiuwIwSgfG2worJoTELyinCGWrzEtVLg53j RuJ51bQzplU9u7vXoz/3Yxy2v3HM4P36EW8+8oMGR/EMwn7s/Y1ASNN4U0MNOVPCcd OkvJGYFjHJS9dt3fNmswp4NpI2U+setULihPefyodn4nTj/dKEHbYYFxOP8zte1x6a WhQYZb2n3M4sA== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:55 +0100 Subject: [PATCH v12 04/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-4-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=2194; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=rhf4QgkZueY9HFyMVTo8jhUZj4hOFxWhVw+dFxDVS9k=; b=kA0DAAgB4bgaPnkoY3cByyZiAGfNsWqhMY17PgPAHsAra7TmTnaME+neyL5IqqbgA2/7t3O0r okCMwQAAQgAHRYhBBLB+UdWv3wqFdbAEuG4Gj55KGN3BQJnzbFqAAoJEOG4Gj55KGN3ix4P/2+J 0E18AJ2hkNjD+Yd/K/hMKPA8n8K+SIqRmyxDcXLEnb9uPLpUrX8+nGsCPedlRT5Xvq3mSNul4Oj 4TS9yMH44dMx4+0sfxpiMrPB+lu001ULUodmrsAmwpdWIRzggIIecpsmVErdog1Aq0YRgitiK+T jMQqFeYJ5URRq0d6+H2t67QxHigxzOsFLqHyHx/2P5TlMWsjrE9FNl4EE8TNgkuv8tzgqscX4zM D7RiY7IxCCpKLUrtKg5Cyln8OEsJbsO4eG3PK5XSU3C/DR0RMJFveKM+q69Dxg0BT9IAGmRSeVe jsW6FLcI6RZWO6QLY8GaadwSkCpGKG1M2GSIbpIt2RJhn/licoLarHdDGFjKWazjZlCXl9OLAx5 yQ08cTF4+dXwBDtpyfNzlf7LXatErV2kUg/AS6K6nwYVGIvepKcOE6cyD20T4lI/KA3tCAvf8lX AeudGVMdmJ1s3Qe/FnUl6nD/DlilE9x9JZ99bx/MapqiChoeUjUJSgsVkutpMp6KZ7V+Zt1cJ0T NaMzQ6Y1jPrk+wKXK7WjH6a4ZrMi0eVrNX5g/fNqXj0j0Qg8rqeRNx/WNacCBUltbmaBeWCJjiW sKnP7hy/V/J7S9PFZsN8ssFHV92gI4aLhhPJgEFvjw91ze8kDld7xXutW67tINR0FQzPyRiE/ZN /kb/8 X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow timer handlers to report that they want a timer to be restarted after the timer handler has finished executing. Acked-by: Frederic Weisbecker Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner Reviewed-by: Tamir Duberstein --- rust/kernel/time/hrtimer.rs | 18 +++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index c6d6eaed31aa..78afb093aee8 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -212,7 +212,7 @@ pub trait HrTimerCallback { type Pointer<'a>: RawHrTimerCallback; =20 /// Called by the timer logic when the timer fires. - fn run(this: as RawHrTimerCallback>::CallbackTarget= <'_>) + fn run(this: as RawHrTimerCallback>::CallbackTarget= <'_>) -> HrTimerRestart where Self: Sized; } @@ -312,6 +312,22 @@ unsafe fn start(this: *const Self, expires: Ktime) { } } =20 +/// Restart policy for timers. +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[repr(u32)] +pub enum HrTimerRestart { + /// Timer should not be restarted. + NoRestart =3D bindings::hrtimer_restart_HRTIMER_NORESTART, + /// Timer should be restarted. + Restart =3D bindings::hrtimer_restart_HRTIMER_RESTART, +} + +impl HrTimerRestart { + fn into_c(self) -> bindings::hrtimer_restart { + self as bindings::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 df97fade0aa1..4a984d85b4a1 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -95,8 +95,6 @@ impl RawHrTimerCallback for Arc // allocation from other `Arc` clones. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - T::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + T::run(receiver).into_c() } } --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC2531DF268; Sun, 9 Mar 2025 15:22:54 +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=1741533774; cv=none; b=VnW5aw5k0WwvD/yJo68uw3TaVpI3d63Q5Mfe2E5YpMlnVmk2je/sx7wNhff5EWG6nIQVLfLxQAKBjq8p3cYOwW1Lu77F3rg8M+u578cQSKzIrsFUHjso0Aqb1dAbllinIp/V7NhmvzHg9D/F8c4gpQg+CymAtFmCIHhDDGMscWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533774; c=relaxed/simple; bh=DwVZIip6YffDFOKj/P5+b+mVe4Ium7/J5/6ey3jh4Lg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nJRnkLMi2/5FNYitnGUlcIfY4XwSbyTY38+vG1KUjomdotif0+IjCkPhwtjNklO96NgLX2aXv7yEZ1+jUk9yegguOT6r3tg5TyKzXld7/6rqL4UlaAfbm9a9i0Gjc6BW+bgWfIIUvnboMv9oE8JykY9wH6n42NG8APk1GXw63kM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WvMiLCwa; 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="WvMiLCwa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E8E5C4CEF0; Sun, 9 Mar 2025 15:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533774; bh=DwVZIip6YffDFOKj/P5+b+mVe4Ium7/J5/6ey3jh4Lg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WvMiLCwaN9iRE2PJLvEIURPdJbfcx9XuM4dv0gnRkbD5LHbEDX8hFIyTXBX1kRxN9 qDkA8RltR1l14LFPTA3M5MAtvrGPTO+cg9fFcva9C+sYdsQi5+pEbLyUjlBYMiNxl5 H6xgKhOXKzn7XxYypF0LmO51cUxNOlm6N7Y4p1tcLMljXrqQOgjmgZFViicspBv605 +ifwAHwwCwKu5MoRIvJBAcGpwjE+97CSd6IS/G9XocV8g7kKxsh18Hp/X++Q5V8g61 LdWTRtVcFATkQvrMWmugwrLcQEKtqGoqhs0WitPuuyvitm2fZE33AxT8sJBUwATzyr +VU+YYrTkipnw== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:56 +0100 Subject: [PATCH v12 05/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-5-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=2216; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=DwVZIip6YffDFOKj/P5+b+mVe4Ium7/J5/6ey3jh4Lg=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFrduYuZDMu3VkzOXc0pl/c6PQOsXoR93SMy ASfP2X8qhWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xawAKCRDhuBo+eShj d3A9D/44BsscnA2s+Mkhz2BcQ1kjqzljdUTnre8L99O2WD4G9kv9h1EFODep106880asrsZPfjO 4H5p3wDlZMZqswhPf/pyGWUHjeQwgZvvbWmV1yRpWt6jAJ5I8QmD8cirDwOXI5h8wcxZBgeuim8 wKyZlTq4/+BHV+MFYgZjBJEaGwL6Lz1WCuBX7WvGCIyBxnfbLtJTASf7gJFQhv4FMFWyaHCHaXr LhOP43c+xgifqOzWXghxVmwXllvShqp9QNGys0lK15tPfrJs80CxPgmHIeyFwok+BSJssoCy5ez /oNmRNTuw9ToepZtjBNjv3f/IC8keImdqPaS4smeFZUxAsteCKXPHSM+B7T4YfI4uEBxvl5MvYg 6TOalYVZveTnwm5ZX1jBrUVXdSPDhMTAhprBewAyNpyVxN/Iezf5dAEGtYbiQzfSLl1pNlnxz0F ielqe+NjPgys5gdpGtMGOy+eowT/jlKP+jk8aCiz9zOAXprtvom2O2Ac78gbSBCEfsLvBOUTjqD DWtIb6r3ES1d8jliF/PXx+klLZdNmF0xEApUaTkM+zwWBg85vpkKYewb+G2D+klYIFZ+ucQ5PbZ bTMasPsFC2w7kBE0erqSw+t/Va0TUC7/4+NZ23Y/bVFu8UnAnM++VhImv8e66Z/9qgOwXgOPdwU 1ggUruqA+UbOHCg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a trait to allow unsafely queuing stack allocated timers. Acked-by: Frederic Weisbecker Reviewed-by: Benno Lossin Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- 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 78afb093aee8..0a9ca18df665 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -188,6 +188,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 Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17CFB46426; Sun, 9 Mar 2025 15:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533725; cv=none; b=tLLXXdqAJaHzRj4PBimvuKjhM6DD4eDv+NuoEX8uRSmj8F8P9GRrNWmddjEUKsggcqgpYFS5kXt4AoullI6lHHyGgeQuAsmHtAO5c/Y63jpw5lM9ikCkBnl2EgFcZppJciexduvzFCT64w7/2v7lsabSzI8jG7mL078hIe3StTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533725; c=relaxed/simple; bh=Ky9iD1F674vvwmdNmX1iOwy1bdlneXIh0b9IeMManG4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U2Zrs69IP8qT+4RTQ5wcpX9bY5iFvz2H9kp4udAYtmgiHh0tOlg6K8QDKgdihncTrMuy6dW5cOWHkvplYtZRIYERkTKmurZn9JWY7GoqKEQ+Wx8ucC9N3kXd0y5eNLdwa8i+jTNJ8OnwjkODfHB+bqQaLZS6qPUi6RbTZGDEwyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rsHnY3lw; 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="rsHnY3lw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 454A0C4CEE5; Sun, 9 Mar 2025 15:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533724; bh=Ky9iD1F674vvwmdNmX1iOwy1bdlneXIh0b9IeMManG4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rsHnY3lw7fSzz9P4LG73Au2fTiZc3Cql5uie1eKH8I2EuurKLubFgvh55+LlBz7BN NWpFg3RHMZiX02eeh1QDUrTzcpn7mT9k98mZXwSC9+wUWd+yrq4mOLK4MD0oxRVUIk RSRcxgTzE1H3qd+XSW/vko6rIrvGXGNmaJUbF4+q8Kc0Lkk3Jd4z8L2Sm8mbIGySp/ znh4qhLnJfXPa1EZfLsw/LF7lfU0QL7xw6CVJoN8Xcoabq3Z9Dcio15DZGQxHgw3bK vZgs+xJA0rwSPqLNYbjhKytuMN0z+8l85OkOkHyEqtmhI/8JgoxwGhoQaUWfTBfl93 gEjie2XGJMqww== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:57 +0100 Subject: [PATCH v12 06/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-6-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=2186; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Ky9iD1F674vvwmdNmX1iOwy1bdlneXIh0b9IeMManG4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFsX5ukJ8Jdm2B5D7ifYODzlQf7PI7W5bbhI 3p+koP4ElGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xbAAKCRDhuBo+eShj d1AGEAC9jBl6aWS8sob+yPtYSFcUVFlFlzLaZbonK9O7AXrfFoqrJXZ1Wf2fowhYrVpH6GcE+WQ ZrNiixRd1a84JsgBKMS6ljQbLnAwSrclGv2imlYgYEYpqtzLQ1c6T3XqRVO+a0qhsqn6Ik204Qe 4KP0GglEQK/n/KBmiPw6TWwWxO5wQAmuEha1LY0rSFcQO6Vyv22w2oA69TV0KB4T/ddjeKYXqab mRT66/9/9GF2TJGbQPyYwm+IeVNBut5HDN+kJxsQtwfYtqvjiECjIgzM1TdEyYTs+AIrF999k7k PlI2HHe3bRmWxWwQOk6cvzlwXAZ2dpJS0F3rxCWS+GkzZjWFBF03Xi6KQdGIoAA0RDb2AT+0cxl kjAiZvzgJsdifz3H1wPSdRz+y34p2VFJ2cKZb+bELaLmuAKknEnaTuAXHd2NWnbtxB6YE8U5rdt eNykYtTCfcXdEU6CTL7XomsVHF/xKZj43/TGo5dCRNSyuWHLZOTFo6vkPVNnVp8wRtqDVOYEHPC 46nJ3rlwD1NkWEe3I4qhQ9bKw6D2AWyBzzfiBGbjVxJGKFtOxRsUqmxVLCUu6xrNnHuvQLL+Vmg rFISarivNNVPnq7561DZ0Bj0uga+aTJzanI1IhRVl9DId/trqfpeAt07Yv9UhepxKi7Tfxm5LvU wBVjmBNJ6752DzA== 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`. Acked-by: Frederic Weisbecker Reviewed-by: Benno Lossin Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- 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 0a9ca18df665..f9b2323a305a 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -219,6 +219,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 Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D72401CAA93; Sun, 9 Mar 2025 15:22:46 +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=1741533766; cv=none; b=SdAuAzL7PcW7ZaJmKXHGgT1wcRgOZ2gfnmSxcfOjYFHnp0bQ6gMfjc6j4yb0nxq61caEmiIudQbbuGlxEX9DD3cv5zSN+IdAp+n5zdxvqsW+Gwct1iSgQ3e7qvM6mNH5jwX9CH6UUgAH/G8K3uzLM5yPXkrBmkNj+gHgJ16150g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533766; c=relaxed/simple; bh=xw2lAfKBPsk0cxwZygCBVdqZbLCzth76URvjiDmFDxM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jv93FMohw+SSa9WcOBXeNgU8MHhvShlioOkKFC7uo0ujsOXhvC50AkUyqLI5WToAAwZsbZb95I2KAWE75YcrgzXw/oOrBlZxC6jiy//aNtgRiYNeK6wOiYqsS2jxv2H6bVvgK3G6a5sKpHHBVY+TMIDqLBxYYcko7QTrqkvP2wA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jgQBcpyz; 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="jgQBcpyz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D130AC4CEE3; Sun, 9 Mar 2025 15:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533766; bh=xw2lAfKBPsk0cxwZygCBVdqZbLCzth76URvjiDmFDxM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jgQBcpyz/mn3/uJgfC2UTClx2C0eAh2ALFyDr/XuRu2/R3VOsso34b6se8zm1GtBe jgTJFpZqURNDJQGUrJR750ObGQ4FQEGp7Oh1Z5GmYoD4nHrWJ8DDQvnM35E5YNEj4T xQD7FOPf5tt91Ki9abZlAg4zW3vPhrE6PsGcLwwu5gixlM+2pFtXEqU3NHEfLRlRvO 5exdSsjOLFqKXHwmGl21vttECHyv88c4sOYrTNZDdv/ckfHdBuiL1hYc2OufZ+NNg/ 1szKBdwUCNZF0fWqd4Nehf3fcc6GzEacPZh2axlFlQQ9RiViSUiJw3juqTnWfIHOGS RgTFFEKrE3pyg== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:58 +0100 Subject: [PATCH v12 07/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-7-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=4581; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=xw2lAfKBPsk0cxwZygCBVdqZbLCzth76URvjiDmFDxM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFtZ312wCzyv7F8m7L/M6Yd3DrbjcxrC+HOe GQ2Te+/wxOJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xbQAKCRDhuBo+eShj d7dNEACfIpNfV1Orb6Xs6ljA3Gg1EsoQ6z0rtWQ85uUlIuzOo06NakwlNPcXsGBAvrdzcoabOlZ TfGlQTTBUW4BLIvSjHRLwJTafQKu30mw5tyvy5mCOywJK3Lo5rzNP1e352F5EWHFM2WQiwdDI4Q NwPN9wOQN1iBmL39ypfZKtPnC1ocMWTIgEA/sKkczTwqby7yMdlD+615d4bwre2PIcveL+8cfoT omaFGZwbL54wS/RXkDk2aDVmuPYTTwuYcI58md6oNezKZp4DJiHtaU5UGWNonGh8+UIp2vmMwsy f1m5D00Igg4UnAP1B+LW5kGllcdT3N3asAJNnx9i8iMhKFryvgbbH/ye+MsEUgQbYDjBZo1f4vG cEEOUeCA6gomiL+JQ+NpZ2bXckbVJDBW4FU+55U+piKAZgzGEh25Oyl4FOrcDViHZ07/CVbUISK GRY7fzbc3Fwy92NFklm5DFumROezEeba52wsmBjLOrbdLDXVHt3UUfk+HnFC2sa/QfxT7OQ0qnE wvZs4w14Tng2tqtx+Q5kxIFWbqyNZP5FhvN5bPhU1avrky2u2hJ1sRdBgRlwSH+LizzB8/NCASN FuQa5ESo1CEVX/7CkYkIubEAOUdHWiP483P3xDCQiFHvf+GvGEVj9m+NkrJ/gi78F4Fht2xRF0o hZKipbC42CwfNZg== 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. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/pin.rs | 104 ++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 106 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index f9b2323a305a..abcaa505f7d8 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -432,3 +432,5 @@ unsafe fn timer_container_of( =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 000000000000..f760db265c7b --- /dev/null +++ b/rust/kernel/time/hrtimer/pin.rs @@ -0,0 +1,104 @@ +// 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 self.get_ref(); + + // SAFETY: + // - As we derive `self_ptr` from a reference above, it must poin= t to a + // valid `T`. + // - We keep `self` alive by wrapping it in a handle below. + unsafe { T::start(self_ptr, expires) }; + + PinHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type CallbackTarget<'b> =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`. + // - As per the safety requirements of the trait `HrTimerHandle`,= the + // `PinHrTimerHandle` associated with this timer is guaranteed = to + // be alive until this method returns. That handle borrows the = `T` + // behind `receiver_ptr`, thus guaranteeing the validity of + // the reference created below. + 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_c() + } +} --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A5441DE4CA; Sun, 9 Mar 2025 15:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533784; cv=none; b=epgleedisTSvAwzPsDN227L1h6+KNYYeJeXTWOO3FYf7uXjU79txUW6RKCTuHElYnMaq6fz1KdiZUjqrr1DC24/w+z6XmVIksGYbftVC1xqDtkILl5XKO2b0df2tynEUrhF/k/DvL5WlO0QThYf0V+pr1ab7xen8870TuQzWMtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533784; c=relaxed/simple; bh=Psxseb9eW3+jpOO87puAyXZ+ypUuGK/8ZvM6S/VLMIs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OLG5dBZfc9SqsS9gtsiDArj12TjXk0+7D8mfeSZGaaH7urHOb63fgoZ0S2LSzBmZ/AoaOzms02YcgqhuYbKvbCc9AmgklnTiZDWjODoBKG/7kTQWVsOeXg5bEtLOT35lm/1LbkUuKlJgt8eNVs+k2flE1evIEfgRH5Kr31/lBac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RLDzv6ak; 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="RLDzv6ak" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42BFAC4CEE3; Sun, 9 Mar 2025 15:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533784; bh=Psxseb9eW3+jpOO87puAyXZ+ypUuGK/8ZvM6S/VLMIs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RLDzv6ak7W/AmtrU/yerz5bZofiu42ipbkGK5hkaYxONz0Do1EEQO0DZC8EatB6sT Gc2QXTxNaij2NwiyHEIX2HDPRsYI5UtZWjPRbARqS2joo+NT/DhnCKeQ+dxwkXRUtN oseBxzHgwqrcCEzbETnvvLY9+v4X2+t2u2qYwsk6+jyGFaP0UbG3SZA9frcpS2KBrq CKpd8FdVYGe0uM2YjV8/f/Mju6Pku4VrHocaGAmmo3UU3J0vc/YmY+U1tfe18rdlsQ LWqWUc8wE2pfZdbz5IyuU6Q/Mld+nvzdLlfcWpCz0P7kNrhRQ3EZsP0TahfJ6akqlw CvtS0dQtJ5UkA== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:18:59 +0100 Subject: [PATCH v12 08/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-8-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=5022; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Psxseb9eW3+jpOO87puAyXZ+ypUuGK/8ZvM6S/VLMIs=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFuGLOvoaRkGjPbGYEmJFrsRsoKC/EJ2i8Av 3Qm3RWEek6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xbgAKCRDhuBo+eShj dxJXD/sFK4FI+aZNHSj1jiCZV8WCDu1Nfw8+5ZABaLEriPFWQDujPvXqPc6s6UXV/MgCRe1wymN jX99p9g0gdrslXaLUYfqXJdY8umJ9Yhscp95jODiRrfntdLkfOqnBgdgij6rSpbBNRBvRGFHlta g+sNLr40ZvXIRFfC3shubUnvyIrG29T/lsKTnx9nWA2TpctBjnnz6lW/EHFNJadYErnlcZfNnje arELUwAzlIebKi5u4abJGAGT4ICiNHgLdFzys5LCM2YDOYzaa6+BQKFilzciKQJQm1pBz5gGdW6 14/JPV6/Wa6m0gUEbhtCXqsSiFH2JW7DtLCvbRXRncgmoSqMHHIr2baJW2fzDmaCtlPNg+eRsdu D5iE98j1SqjVgsF8eWqFE41eAAcZVn5w3ki6VjHzUt0WYVsRTMYv/Go1Sw9Y9tL3phWFUNTcgQE l0m3DtIvtXEtl2u2SPpb6LA8/ZSjvFhBETa76x2L2DcXwM2deyYe+VsgZkjdVz8GRZOYm+Ycg6i QjUwlDwmH/XPLQYME5ffPWWvU1nGnMXt96iY6HJLiKrOegGTFEE0SejGGw7hdoaY2Oi0eJogZws G/pe1l0i0+Oz0Zxw121X3FPr24fHsab95NU8yZXnHYCDnpBpUaCGZAe/LZ2jH6OKhJRDxqM3L07 JG4c9US1f97b4mw== 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. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/pin_mut.rs | 108 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 110 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index abcaa505f7d8..4e81505d6675 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -434,3 +434,5 @@ unsafe fn timer_container_of( 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 000000000000..90c0351d62e4 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::{ + HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, RawHrTimerCallbac= k, UnsafeHrTimerPointer, +}; +use crate::time::Ktime; +use core::{marker::PhantomData, pin::Pin, ptr::NonNull}; + +/// 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: NonNull, + _p: PhantomData<&'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 { + let self_ptr =3D self.inner.as_ptr(); + + // 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(mut self, expires: Ktime) -> Self::TimerHandle { + // SAFETY: + // - We promise not to move out of `self`. We only pass `self` + // back to the caller as a `Pin<&mut self>`. + // - The return value of `get_unchecked_mut` is guaranteed not to = be null. + let self_ptr =3D unsafe { NonNull::new_unchecked(self.as_mut().get= _unchecked_mut()) }; + + // SAFETY: + // - As we derive `self_ptr` from a reference above, it must poin= t to a + // valid `T`. + // - We keep `self` alive by wrapping it in a handle below. + unsafe { T::start(self_ptr.as_ptr(), expires) }; + + PinMutHrTimerHandle { + inner: self_ptr, + _p: PhantomData, + } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type CallbackTarget<'b> =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`. + // - As per the safety requirements of the trait `HrTimerHandle`,= the + // `PinMutHrTimerHandle` associated with this timer is guarante= ed to + // be alive until this method returns. That handle borrows the = `T` + // behind `receiver_ptr` mutably thus guaranteeing the validity= of + // the reference created below. + 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_c() + } +} --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 550B01DF24A; Sun, 9 Mar 2025 15:23:21 +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=1741533801; cv=none; b=h9a13UDgqbwKPyZr6BGce4OShEOx7dvZROcTpxFC9ihpN+AVmw257OxAOqyF6jE5sdBuD+lMYF1CTGmbroazULfD5TvBka4W3LkwgidIueb1lSNBBDXNQ3dkS79qCUO4cDD1WDPgPdxtoyzWgAnjWcfdvQR7ioJVKJnsFC1ryYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533801; c=relaxed/simple; bh=Wo/kUAupEBOIsOdnruISz8EyJEcYwqNCGfSTf35FejE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BXihp/x9iBPvwagCCb780Tc/ruUDeCqtvjLfMvDjFNA7gjh4+I+ne4phMiSNCkoWRlNVSYFp/isFHuTnO71EQJg+MAeNXMVl+p057G67MhhevuhFhuiVCUPlBLrPtfYfCxlLLeKiS8nx43Lu9hK2ipS9cXBsMeEuUd0t91zF7AE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1u/Mnxo; 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="E1u/Mnxo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDBA7C4CEE3; Sun, 9 Mar 2025 15:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533801; bh=Wo/kUAupEBOIsOdnruISz8EyJEcYwqNCGfSTf35FejE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E1u/MnxoXx1A7LDzg0kPddqiAowRHyGn/RdL8JrL/U98+OC0OMh19kZJPwigs28lw GuNYucLMOBZTQZdbyL+q2UWYxY9N57V3CZ3/uWyQmVI0ifRAL12MiNcaoofJT1IAPd eECeyTnyCJrd+vlyNPjj4QF5rA8Z31+1z2rwiKw6Hz8haaRFpLYKz4TM3kR81jgLLl M1F1xQLYw+fYOzllKZz84fGTh3Xojvx9zxQt9fhjrxWAS/j9dydu+gwroDBLA1qycd +HVocNgemfHuMLCe0d8vEpZ/I/Uqww9H8oDo4oNu9as8y4AH4GgUoh07L1nhp3Fq2t M/HVBQk9T/HWQ== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:19:00 +0100 Subject: [PATCH v12 09/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-9-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=1122; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Wo/kUAupEBOIsOdnruISz8EyJEcYwqNCGfSTf35FejE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFvMqC0QKWGh83nKT2AC3rlw7wZqeANJ3wNn V/HPDO0f52JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xbwAKCRDhuBo+eShj d0PGD/9zIwXJPnYU1QuDIUlbYFsznGHG12KC+Xa/JFJ+z7E+4zDRc4B+aoMRo348dOx/GJfWgVW y0FsBRIn1uT0RoDdqr0sXvRF/2aV82hLZb8do7GRaJ7xvOeEmtnLqsJf1eMPfjmE3//bwuTrcF3 lv3TESLYJm1YGhaic5VWQhXaCZma1ZBaL9QvSqKRUurQ1ZtTs2nlqyz06S6U34TwYiKNe9xu0vP YkE4hiAjExfGoK8hTKNjp6cZJaw4+5VkSY325FTy3SaBR84cXYybj/WEsg5JZKIF8W5sXyXDSwm Iy1pVF6+7tpu5ZRKQTuCWjBeRd2pBEBvvchWL8YcUQvnxKhtCn1eejb1su0u7+ptBs7DBu/4dh/ QHgLfh7iQ9itXdS6hkEyE3EAO99LYbA0/nCDEFmyx8zSC7szB2bPPI8YIjikfZ2yuKrt3YwzMPz rl9CAzEl93XEmndCJoABr1WLamm1nAANlB2IKEi+Njz5ppExS4rXaUaIdkG7ZSOG5ESDXI7qydA esyGPcjTV6O0Fci/TUJoq+Pcm8Yjg1D/Eb874Vioa0jEokeTUlST2YmyH/WrZ8eh0rBCHfR6OA0 kvVb0hdxC1WyiS1GK3meVpaPwWO0qNfaiEmrKEa+zXy6W9m1JghvH31uVP5SdE5wAl4XS0Uc4uv uFq7dnanJOa68kg== 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 Reviewed-by: Benno Lossin Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- 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 cb4ebea3b074..9da4a32e60bc 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 Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1AD046426; Sun, 9 Mar 2025 15:21:56 +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=1741533718; cv=none; b=i5k+dB70G26ZMJXfUxdimmCGLATKTBHBYbK0RRbl/vSBiDbgkzstVrKSDntGSRNAgZ7c3pDZIsdr/+vs3hL+xK17iQ1HcZjn26k3f6XMzgTJMHm/yMfcRR4yGDJk6JAT2OyW/iObRiZ32oiE0u2EfcmM8Mhyeq871NpqH71AZD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533718; c=relaxed/simple; bh=XC9i27LoAS9Ry1i3YnpjdFGuLigUZQ8uGI9xUepInAo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tVCH8nF/7elckGojYgpx+BzNMXyuLPnQdE6Mmy+8TvchI2ACIdt0Tu+KqYiUlS58R8R6Bi0k9UFK1Wk7+FuNF4boVUjc8DdULpO19i4/xQia4d33IURSYC0dNJ5p1XZf4lpc8uy4jveIHCbTHGETCy9zgAFNy+vHbFJU/3Qqgmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dSTA3p/r; 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="dSTA3p/r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654C6C4CEE3; Sun, 9 Mar 2025 15:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533716; bh=XC9i27LoAS9Ry1i3YnpjdFGuLigUZQ8uGI9xUepInAo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dSTA3p/rjFhZVaq7XuTB7cHTtoQFU8szYfKBKjoFhF+FWkJhf/E62+oVWLvgNyFBq fTmeF45CVGwCYz+w2PUJ4p6LlV4DmJlKE2XPlhXxJDfIZCM4Q81YHYnLPccfw7Stc5 +ifBRNLByTI2l86gd5Me+89qfBtULYaBw3qVXPktcgP+y1q87wr6PTQaq5GsMeQTi/ RQtD4ePQuS+WIEbhhQvOVnBb6VdG61duBRWwXHnFznCG1bjZDPSmpSY07PZzcXnBTm Mg6RpDi+SrgCeC58tFXi1orrfotvxSm8+mGBX6HeKh2RjjnE//5EmlzEkrHBInkWqd DLSpr9QLM2rOg== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:19:01 +0100 Subject: [PATCH v12 10/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-10-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=5248; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=XC9i27LoAS9Ry1i3YnpjdFGuLigUZQ8uGI9xUepInAo=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFwsMfSYXGzay2VmyZm/9TwgBGlB70D+9pqy qgiwsxeRhuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xcAAKCRDhuBo+eShj dzcpEACeSez4lj0cALJhMZt5DeuNuKs1/xt4h1DStGe1vtGNPn+XmDVdfRVbA2jPhp1ucQo+lG8 ez8TTQyZoPrEEKeVQO3ExmCUhhKxszMgdOb99oTISe44p5OjmqISgFt+Hlt4Gl5O5KxxggW0t5n 7qo6nQmqRSRfSlLzB7e+i1Ik79jFcqMPWWvugeff6cGCVmM9abh+i9OTYdad1L6w6i2uv7Hm08x G4WIaMefzo+Wnu7A+8GcisdTMRIb9tFtk3H44cHfosfLMpRgp5/PX5uRYt9KxHvLg3m8+lyfEDK zk/ZPAJTS1nIW0TQmaqDU5Iq8rVDOhTrhgVudtyo3rUsOEkhrr5P68TlZaHx8Zr0Qq5PyMEEe5L rIxzLg5ks1lJxAozvfzRnFHaCj/Yq9HOKI4cgX70EZu0l8j6yIqj4EiGBl/MN7EnBPT42cbWWqx pVCty9bYTfWQxv4jc8ROvy6NsypTphmfrsjbi2Lcwt79Q0SNyiPCxFokB1L9JTL9phP3EsIbxVa mcwyShsBnJZglJW8IPBUdE6FoHofuy7TVHSGzPC0g1egMiCf2rq8NbDXtL7n4TcsyUUYFPReCXY Mw9NW10zy5wShs17WJ/RTTS599FqQA9Tc/He1mr1kZJKsrfADC5KzUm9QD2NQbY6gEzs9yi/nHQ CEjZx36DlLa3FpQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow `Pin>` to be the target of a timer callback. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time/hrtimer.rs | 3 + rust/kernel/time/hrtimer/tbox.rs | 120 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 123 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 4e81505d6675..2436f04d02c7 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -436,3 +436,6 @@ unsafe fn timer_container_of( 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 000000000000..2071cae07234 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,120 @@ +// 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::ptr::NonNull; + +/// A handle for a [`Box>`] returned by a call to +/// [`HrTimerPointer::start`]. +/// +/// # Invariants +/// +/// - `self.inner` comes from a `Box::into_raw` call. +pub struct BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: NonNull, + _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.as_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 BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + fn drop(&mut self) { + self.cancel(); + // SAFETY: By type invariant, `self.inner` came from a `Box::into_= raw` + // call. + drop(unsafe { Box::::from_raw(self.inner.as_ptr()) }) + } +} + +impl HrTimerPointer for Pin> +where + T: 'static, + T: Send + Sync, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + A: crate::alloc::Allocator, +{ + type TimerHandle =3D BoxHrTimerHandle; + + fn start(self, expires: Ktime) -> Self::TimerHandle { + // SAFETY: + // - We will not move out of this box during timer callback (we p= ass an + // immutable reference to the callback). + // - `Box::into_raw` is guaranteed to return a valid pointer. + let inner =3D + unsafe { NonNull::new_unchecked(Box::into_raw(Pin::into_inner_= unchecked(self))) }; + + // SAFETY: + // - We keep `self` alive by wrapping it in a handle below. + // - Since we generate the pointer passed to `start` from a valid + // reference, it is a valid pointer. + unsafe { T::start(inner.as_ptr(), expires) }; + + // INVARIANT: `inner` came from `Box::into_raw` above. + BoxHrTimerHandle { + inner, + _p: core::marker::PhantomData, + } + } +} + +impl RawHrTimerCallback for Pin> +where + T: 'static, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + A: crate::alloc::Allocator, +{ + type CallbackTarget<'a> =3D Pin<&'a mut 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: + // - As per the safety requirements of the trait `HrTimerHandle`,= the + // `BoxHrTimerHandle` associated with this timer is guaranteed to + // be alive until this method returns. That handle owns the `T` + // behind `data_ptr` thus guaranteeing the validity of + // the reference created below. + // - As `data_ptr` comes from a `Pin>`, only pinned referen= ces to + // `data_ptr` exist. + let data_mut_ref =3D unsafe { Pin::new_unchecked(&mut *data_ptr) }; + + T::run(data_mut_ref).into_c() + } +} --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 450D91DEFCC; Sun, 9 Mar 2025 15:23:46 +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=1741533827; cv=none; b=Fjqkdoee6ifHnC5CEN8Cgn2XVoBfmEFEd0zyzxXTtjsm6pOVat7ElaOJIU6Bvrew762R3hXJXTpvyQc1M2GfEYOA50KhkKIeYiaubw15SHA4zFK4+ZznI43sm1wZk7B/8vjT4kuZCZe7JAwx/6gqYxLBYUrOIACCfn2rueA9qxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533827; c=relaxed/simple; bh=HSLjqfjdBIhaXMsLbsdst2hy06e5MEpZKeMpRKHgG8U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SwpXEoRMztnMAzHJpLGXMAlOm6GIRRIAJuVZBQ+UGq4q54kMC7Aok1cxzXoFZKYc4cyf0XC1y8NbjlPUWOsEUbN/Ggs+70m9OuVPLbZdb6DLfaISo2IBVx2nmrmvGmKGjAekgbxFS/4vYAUlN1hprx5Nri8fNC8LsyZxcTdB5mk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e8P4e8c7; 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="e8P4e8c7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49E90C4AF09; Sun, 9 Mar 2025 15:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533826; bh=HSLjqfjdBIhaXMsLbsdst2hy06e5MEpZKeMpRKHgG8U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=e8P4e8c7OtuLO8GpGUcaTxqibQMveaq3ZnfA7WxzgUSM4xQ0hg69D07RZARUDYuqi HBlP72aJtrIW72AHEM9yEf8aiIP2S/je1lgIEsusPed7TeCph9imTr9EVPGQGF+Wok Tz1gV5ACH0suNMfxvVEAfu+zFFJdl1mGDfdeooea1YYFJNaHz/ZZtKYFZ4tEyZiDXC GFo+EalkVbrcbWv9OdNsnkyvEcUk0rmgwPdP1XSx7MvAGg+Kx290KWTx1J3YNE6Hxv e1NgP42+ekUS+WvZccksp4gRUMp6eTkoL1YVSvcgpFs2EtbzA07VmOaFLsukE1U3u8 Fmhc10E6ZzLkA== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:19:02 +0100 Subject: [PATCH v12 11/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-11-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=5724; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=HSLjqfjdBIhaXMsLbsdst2hy06e5MEpZKeMpRKHgG8U=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFxgdVUI8t3tDsgFgU1BpO34+SPpbGIikJj9 3m1TsLERTGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xcQAKCRDhuBo+eShj dxPhD/0bBQhSlw8P4a8Q/M3fsnN0UsB4HXRV8x3KVK3dg632NQPAUNC7fpFA/Psp4sRj1vQ/3Vt B/5m0oh/+Z50IpR33NTIMaTMiTletYB0BDFDR1I+9N8+Z4SsHRSbcysmvCdJYSJkha5PXMRbvLr 328NrIz2XWmhS28pQ6/+VoDyA+QaaPFJs7Woiksqkk3vSwV84v+F+dVQC1P+NZ5T61M2f0E9zBe zoDNzw/l1jmgH8U0++UQj6S4ye7LkQivuVQ9h2/+wGFJOqQjTX6PWg59l92WYmpXpcIJ3p7kUee +L16VUgpq3+8fQ5SgwC+Zi8Wyf27z1Ku8krKooShRg2GslJ43T8zYUDqs4RyHFRye7ERndCsio1 iFKvu40bo6un8onHcOua/KK8PJvM8wfKxGf3chDAZnWUjZ80HWmEqS/GjC9IdtMnqWcrzA5o5OM WKzqrDKyhLP/3XE1R+qFSCd+QgfeA7lIuPj18YsPwyhy/kzMBsMISURU5Kuetoy5p5AIi2Z9L4b 8a/alOu18wkWwxnrlTs7ohrt7Zkd45f3VtkETwE46lFBpKw+jqwq9iXkBAqTTPTSVhcQJp1Eql8 T9DnmZuCi/+Ni3Cxw0JHFtucjW6XR9S6NNG+4GgygtVM8p6zz8YBVKQqhPtlJM8cGhLAPfubTLT CtviW1HnorosHmg== 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`. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time/hrtimer.rs | 82 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 2436f04d02c7..9dde7ec14619 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -80,6 +80,7 @@ pub struct HrTimer { #[pin] timer: Opaque, + mode: HrTimerMode, _t: PhantomData, } =20 @@ -93,7 +94,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, { @@ -108,10 +109,11 @@ pub fn new() -> impl PinInit place, Some(T::Pointer::run), bindings::CLOCK_MONOTONIC as i32, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + mode.into_c(), ); } }), + mode: mode, _t: PhantomData, }) } @@ -370,7 +372,7 @@ unsafe fn start(this: *const Self, expires: Ktime) { Self::c_timer_ptr(this).cast_mut(), expires.to_ns(), 0, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + (*Self::raw_get_timer(this)).mode.into_c(), ); } } @@ -392,6 +394,80 @@ fn into_c(self) -> bindings::hrtimer_restart { } } =20 +/// Operational mode of [`HrTimer`]. +// NOTE: Some of these have the same encoding on the C side, so we keep +// `repr(Rust)` and convert elsewhere. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +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 HrTimerMode { + fn into_c(self) -> bindings::hrtimer_mode { + use bindings::*; + match self { + 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, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 564B21DE88C; Sun, 9 Mar 2025 15:22: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=1741533758; cv=none; b=icKy1rlL37R44WKbar2fchg0AWZ83xdTssHEveUI3W/XJM2ZN2gOk2PhGiWm+VyWpvjXfveYid3CzWUPZf/jKYXiclfMhiB+zF4L1SaHbUCwqjKMtdXYkhz3gD3NC9bi0D9hcyGI7Y22QhsMrFv7J7And+vL/RY5A1ycwo039FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533758; c=relaxed/simple; bh=6O7okn1mcXVIv3GXQ11TWHToOjVvqXB5rzKFLA2QK0M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e2fD2zsywPegU7OKTPaYgT+aCLATaERSLQXlgqlOKlPf64Oi/uMxAdBSnxURZf/l8cOlwmlmH5vhsPyrFLguBk3N+SCHzVVOXkHsgshz/4L/T11rfwu2Aq4cW/8QhNGvyJ2fL11QGf67L3U8FNxTqCxglQOnIzXZe8BDL16W1g4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ebGjHCVL; 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="ebGjHCVL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CE41C4CEF1; Sun, 9 Mar 2025 15:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533757; bh=6O7okn1mcXVIv3GXQ11TWHToOjVvqXB5rzKFLA2QK0M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ebGjHCVLiKp9Nh14XCB7sdAMyFE49BZtiNV9bpaYwP7LJE/CnQa9GcoDBEMKa1jx6 rxfaIkZ4VB9NCp351vqlYgMMg6YEliGjzWXnEpcVLKViypvNQLQkvm+keSZMf5J63B 3XicBOJL/GjAcIM3eA6Yj/i1qE65Zweo4UYtcbWxU410PIDKpmrngwJ843noY/RbVM EGrmiK7zpkI4ueDgnD5OcBCQUCv1DepVJPJHiaiDfl/fz+j8x4xyla0ne/uj6kxTS4 hm2Yskg+gPIc/g3q5bAqRk/cRq2w9+edwy3BnTDJzMcbXTURk1NWiWr9hOELapknbB tbJNkWWnnXhxQ== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:19:03 +0100 Subject: [PATCH v12 12/13] rust: hrtimer: add clocksource selection through `ClockId` 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: <20250309-hrtimer-v3-v6-12-rc2-v12-12-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=5570; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=6O7okn1mcXVIv3GXQ11TWHToOjVvqXB5rzKFLA2QK0M=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFyqiDvUPaSIaU7qAQsU6wCPS5hgSZtZ4R9x gjA/AYkvV2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xcgAKCRDhuBo+eShj d8sCD/46HzktbEKchTJjHglBvuUdFE9QKtqXeQlxPIxbynGw8gbO/QH67Qj6ZOQCS84uYTOGH1P VCn4HtnAv98YI+StFq7RXrgA3YNtgmtC6XPtYPP+PJXNr3kOe/cqHRvJcoI7bSKfdnYk2br4/vS go/06QVtVdPotesMSBVqh9IVUiUECb4an+2hPC4ljOVwsIKlrURpk7UjsXsh37bEASly7Vaz9XY FWMa8u6xm/8gQz2fS5yqSLXKislxPgLI3103fFni4vRwgqftR9SAPs6LZWFQqrOL9wzo0lFbxZp SkF+1gMdf9QZ9ZTiH8CIJlELuqX7N/4XDwJGeAGM5NfMnpOGwL7vl16fFQl4Yc0KqTVaTZ1LME8 sAxr7Jyh9ACc3hTM0L9MGL+IGRwC8OlRbMWDtXsWlPy0fQzABBnoPJxaSuJY6MpX+VgxnjtpT9V cEt8E/+octL3QiipZ+NmJxL7W2ODCX38PlBtaD7ulKTuiOXrvMR31cu2sIzMMth36LerxVotfze cHys6iVvpOHMAMB/ZBlaCQjtPf/eSLssRMYJZwYj94egoUW4UnM6MiSOPeYw/+Fxe7tu8gJsO8I Zt9nbYhLaHbluKE+6xv5i1WeUIOqgakx/1K2x/vL4gE/2In00Qw7E+8iSOJ443lnBUntWA5UXBI R8ep6iNNIufnOPA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selecting a clock source for timers by passing a `ClockId` variant to `HrTimer::new`. Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Reviewed-by: Benno Lossin Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- rust/kernel/time.rs | 66 +++++++++++++++++++++++++++++++++++++++++= ++++ rust/kernel/time/hrtimer.rs | 5 ++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index fab1dadfa589..f509cb0eb71e 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -83,3 +83,69 @@ fn sub(self, other: Ktime) -> Ktime { } } } + +/// An identifier for a clock. Used when specifying clock sources. +/// +/// +/// Selection of the clock depends on the use case. In some cases the usag= e of a +/// particular clock is mandatory, e.g. in network protocols, filesystems.= In other +/// cases the user of the clock has to decide which clock is best suited f= or the +/// purpose. In most scenarios clock [`ClockId::Monotonic`] is the best ch= oice as it +/// provides a accurate monotonic notion of time (leap second smearing ign= ored). +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[repr(u32)] +pub enum ClockId { + /// 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 m= ay be + /// adjusted by leap second smearing to stay roughly in sync with UTC.= Leap + /// second smearing applies frequency adjustments to the clock to spee= d up + /// or slow down the clock to account for the leap second without + /// discontinuities in the clock. If leap second smearing is not appli= ed, + /// the clock will experience discontinuity around leap second adjustm= ent. + RealTime =3D bindings::CLOCK_REALTIME, + /// A monotonically increasing clock. + /// + /// 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 + /// CLOCK_REAL (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 =3D bindings::CLOCK_MONOTONIC, + /// A monotonic that ticks while system is suspended. + /// + /// 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 =3D bindings::CLOCK_BOOTTIME, + /// International Atomic Time. + /// + /// A system-wide clock derived from wall-clock time but counting leap= seconds. + /// + /// This clock is coupled to CLOCK_REALTIME and will be set when CLOCK= _REALTIME is + /// set, or when the offset to CLOCK_REALTIME is changed via adjtimex(= 2). This + /// usually happens during boot and **should** not happen during norma= l operations. + /// However, if NTP or another application adjusts CLOCK_REALTIME by l= eap second + /// smearing, this clock will not be precise during leap second smeari= ng. + /// + /// The acronym TAI refers to International Atomic Time. + TAI =3D bindings::CLOCK_TAI, +} + +impl ClockId { + fn into_c(self) -> bindings::clockid_t { + self as bindings::clockid_t + } +} diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 9dde7ec14619..85fcf29574f9 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -67,6 +67,7 @@ //! A `restart` operation on a timer in the **stopped** state is equivalen= t to a //! `start` operation. =20 +use super::ClockId; use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque}; use core::marker::PhantomData; =20 @@ -94,7 +95,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: ClockId) -> impl PinInit where T: HrTimerCallback, { @@ -108,7 +109,7 @@ pub fn new(mode: HrTimerMode) -> impl PinInit bindings::hrtimer_setup( place, Some(T::Pointer::run), - bindings::CLOCK_MONOTONIC as i32, + clock.into_c(), mode.into_c(), ); } --=20 2.47.0 From nobody Wed Dec 17 19:36:32 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FB551DED5D; Sun, 9 Mar 2025 15:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533818; cv=none; b=aaytlHqLRGLMKZ2B/uLbtn9CUjhiqFG6wXtBg/YVc1xoxsJiL9rLPLNrf1Z0dPjV/+AYNIOgaajL8vxvDpUmJXMQ0SnrDIY28P6t1Wl9lYO5Klug4hdvputF+3AGtlbeu0NcWqYE+ztp9NJgNEsh3W2Upw2c3J2fY/ZtpzTKSKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741533818; c=relaxed/simple; bh=dIjGlvzNhHkBxSc0U14VbDDTWmgvVt6lr6a6kbU7+mg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V8+qAK8TdI3lujQeCaycWt/xdUaiEiAo4oRw+lfm2QTzD34IYvwlSDqUKBAegd98zvlMSnYgiEYP/rmwHkTtVjFncJf/hUHmKjV5G5YGl7ASkVdDnS5AXeC2AB6+k/9VCPZ88jiIOn+A4vkyqdWIjrrLx6dvbpwCHpw+Oc2wLTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PZrixR+O; 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="PZrixR+O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E632BC4CEF0; Sun, 9 Mar 2025 15:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741533818; bh=dIjGlvzNhHkBxSc0U14VbDDTWmgvVt6lr6a6kbU7+mg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PZrixR+Oy4TaJHR9aupSCHmGGRCwwODcDO9I8m96Z2rr8WBa1jdwljgBapARWfyrl 1e/5SNj/jSo31PQwuxy95uphLGk3zobn1V+iInX9ParvfIkURjbhM+AXNVQlBDJ8b/ m4Cz0Rx7BpRIMKt+HAWuRCBUgodD8urxrZSgSUP/iqVOK3AaNaTMNOFkHuQkAUG6pt XiMuWY+GbI7iurYj9qU1BA589ZTAYd6tx2w4DoOWTbpwjqa3q1EbAoXpV2x/aYMWWM gTPIS/xF1P9boIU372dm6BE4byAH9k5/egrXkZZW2YcZGcn1ZI8fdoBDlJL4HyEmK/ Iv4M/cvtcBp5A== From: Andreas Hindborg Date: Sun, 09 Mar 2025 16:19:04 +0100 Subject: [PATCH v12 13/13] 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: <20250309-hrtimer-v3-v6-12-rc2-v12-13-73586e2bd5f1@kernel.org> References: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@kernel.org> In-Reply-To: <20250309-hrtimer-v3-v6-12-rc2-v12-0-73586e2bd5f1@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 , Markus Elfring , 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=1282; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=dIjGlvzNhHkBxSc0U14VbDDTWmgvVt6lr6a6kbU7+mg=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnzbFzTyoN2/cdZriiqf8WvA1cLfj4GB+lRsVWn qyt9owqkQyJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ82xcwAKCRDhuBo+eShj d10fD/sENM1jxlfijjWmHsafxDcO7fBUgTHMkBhxLKXvDEmkl41NFRL7NpfP2ZtudbzoqrS++iG QI5XIpQfIeADVRmGiddTT2STzU/vhjzm2xuAR3OdDznvHxJN1a/cp6rsxRi+KUXBxqoLK0N9DG1 URdkzflZWz/zGSskHr0//FtDb4b7M4iu4SxTBWDvNOEgPFwKZ9ao0XdCH3XllKbcgaAFi453vTS ZwtzJIIsD6D79zO5/S+ySORv6wSLojbf8PqvXQFUZ7YLfZmAlXeM/ZnkBlHE9PjILb4X46KQ8GD 5/WslqzVlQW0jqrlfe6+M5kQIPCHurgXUmX5ifJxzwhnOUg7lckFaxeZTEYBqXMi3GOTsC1/nyb xJsWzOXo/ovxXvkMt8sm5ENvF5+5A7iq8zojidrjt0rOp7ienFr9rvzrQgVFM8r20Kz5MbvyQR+ ETZwB5zNUBScW9BYV59v8HUyNMQkNzotvOEl6MgupXSWPmhHK6mGmNRnb/oe4kcOf6YPJvsLUJR jTM1fjw1aO78y+ZYJIlMqSUqQed96JuPxqGc694eBDLpQPXlYapmxvJkxXqX/YqoBgZg/aUX/MG FBkykHsq5BW0rlcXSWYOg871aP/nQCTopBqJQs12fB+mf7c7eo7QT6EcPLml0K4e0HCMBgLdUch 4Fhwc4AXNb0SrRw== 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. Acked-by: Boqun Feng Acked-by: Frederic Weisbecker Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg Acked-by: Thomas Gleixner --- MAINTAINERS | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 896a307fa065..ba8e802faabf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10355,6 +10355,21 @@ 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 +R: Frederic Weisbecker +R: Lyude Paul +R: Thomas Gleixner +R: Anna-Maria Behnsen +L: rust-for-linux@vger.kernel.org +S: Supported +W: https://rust-for-linux.com +B: https://github.com/Rust-for-Linux/linux/issues +T: git https://github.com/Rust-for-Linux/linux.git hrtimer-next +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