From nobody Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3818D1A8F82; Fri, 7 Mar 2025 21:40:36 +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=1741383637; cv=none; b=L6Vz1L0SYWukeSBXAflC5/bC8ebjwua1GQac6RGjEei2/AMVHJ7ixhHhUy2dM/825KJc/A9NT+thsUhFSuio73PzGF7yiT/cSnKbEIBOeWeQUpfC1yksx0oSvpwG/ZILApz+viB30eKZIFK+nwnduou61qMfnHClQ+oMkxRjUAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383637; c=relaxed/simple; bh=h0iFl/xf9u7fHTzOfVbtZqGS0f6i0+1XWSChAEqV6XE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b8Yi3O04CQF/v3vIO/WOQlgrLJuHsPs2uVZgsFdzmVA/kzAHCxWc8pPSEpUtugvRLflhQVEeQ3FRcDhiUFc+F0KMkcLRZe/dKKtMaF9MZ4Zri+GrDeFO+WHdDtSOUQUVstubdz1Qv+8xwVzKFlDoPg1UkKf6J2E4eZjwKZXBLTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NWFELj+w; 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="NWFELj+w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E60E1C4CEE7; Fri, 7 Mar 2025 21:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383636; bh=h0iFl/xf9u7fHTzOfVbtZqGS0f6i0+1XWSChAEqV6XE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NWFELj+w9fdz6kxx31TyzH/Ik+/avWjmWkc1H7cPIaUvqs4OdVZeNx1FVmkt4gn/T fAQABR0PT+1ni9xtW1y3EwjSY037rvKKHBgTdcPOcw4OU4/g17aS8Smz9R3UkWTO6F OLU/cqDp2fCSvUmPQngHUDdY2uh6wy0HV/+0uIGIs383p9lGFmCMOZhUHBX/bxOdiV 37unLURd0haIIZpmQgE/JGKjS8b4+GdK7fdUAmSjtAEpVFzw9zXFhhG52t3tWUEQ/s xUiW/u9KmU3Od2IRCeo5Wc2fX8n0wCAvMNg9eDnRj6OWWS6slvdfJtn02t+gRU+RLE XTf08TF53OwLA== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:42 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-1-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=16004; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=h0iFl/xf9u7fHTzOfVbtZqGS0f6i0+1XWSChAEqV6XE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dp+I3BwgcUiusCVGdqW/W+/BNnGw82soAbN dfwAWQpeHCJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnaQAKCRDhuBo+eShj d3z3D/9FCXjFbvYOCgzeCB6h1DB0X6Vk8TFqIngc4XsQmh/D7Bd1TB+T+W51SW0pbtd+SACaGtk /MN6/zSSwQcuBW6CCtBXSTvE00NvMHJExYCgCroP98qoLaj3iyT+qNYBYRKg08WXCopQCiOXP/C sSE66fUyDiYSsfxeg0FcqAqZen5BDTcpeBN70rtJMEoogqpFVtWmU2IrgXrxMCm8k6p/4J8N8QM n7kw2bubZBmykuvoHuYxRcO3pYQBg40RQzTPdHR355T6nJLtj7WVdpY5ByseWdhhIlwL3A3GzJe eFM/ZzqXcUA2+sMNjSWauXKsFlNGLc/3/431K8YdijLxXoLPAy0NTkn6yIVOsNId7PykdI/F3mP 2Ftf5TYdM56AJ3GVXi/uKaDEPeURMs3gPrF9wP8WHoIF8VbhJ8LqTlpoQBr2hqmzETy3arW+XFX XAoLYWrRm/SahLL5JZnTEyA1bVFzO0pwY2B3bcIxlaqQhvBGXKNxJ/NPjanIcgUGqbVTYOi6kxe YrLBUNrfCICQDPEjIAd3XZ6G70w8A6/Z+ZJWp6rr4N7y4brMgCeRdMXQldCUEPfGcYes2MRbwDx AVi/qEbinS9YVuRJEuWNl0CuoeuWBA2YHh2VNFbxw14+mvGu1m6qSFqwue313D5yweRiyit66m8 gVdgGhLWbKDjGqQ== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Tamir Duberstein --- rust/kernel/time.rs | 2 + rust/kernel/time/hrtimer.rs | 351 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 353 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..dc64cef96dd4 --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,351 @@ +// 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 [`Hr= Timer`] +/// field at the offset specified by `OFFSET` and that all trait methods a= re +/// implemented according to their documentation. +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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 617CB2580DD; Fri, 7 Mar 2025 21:41: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=1741383690; cv=none; b=rwOtjAPVXH51pUvwwWRYMlPtlPKf7Zp7dCYjZmfs24KisifCa4JQbNWAVH7X+fDfMQqpskLFq/zRdSyNoi6WKKMqIGUci+4vzS8dNe7+jLzup85NbIIumRK7rWi5qi/OO0eBX4bBi8qSYIAL1AqJt2ZkNidsB8RN54RBacTqD70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383690; c=relaxed/simple; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HBBKomc4Jc7XO0ilXhMzhN4ENhG6ilTj8A+Fdc+OSA9nStKPRfkKKlvSXMWBsmy0msO3y81LKfaqhS2QlnFHvujXGkqakFPSMx/SsV72AcLxp0cvHuD5+9HWQoWUkcVwjoCWkfdMx1OsgcUHRHNApd0WUqFvG6ZWZ6vmTraPQO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QZQd26g2; 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="QZQd26g2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4334CC4CEE7; Fri, 7 Mar 2025 21:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383689; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QZQd26g2zHdYtvhX2t5RnyQ6MhMw0jR7KUeZUtTiMyrLmMxPHDuINeSICQRbJq8wW hetlsmpLxo+5EcVVfR1hO3g7LrmeK6Z8i9LF/18+Xkj8OJtlo6VQnvAjs4IriB/Fe0 iB6f3t9vpOXmSyxeIqRnMLtqI7Q2cDHCaN+54kR/gBg4xNGDsvARrcfvokiQ49X2e9 ORLLw5EpvCfQ6n+n5j80ZJPbf3rLM8FH/TXhUt8qqtcKBGQQkaJxE6DOlGOmicFRnE U4Xj3yZ/uTdNNQmiTHbjEl9FL/hs1i8YLD3ocf8I93U+2wgW1kAy2LVx/DIhaWPhni j7ia0QMWo6kGQ== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:43 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-2-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dq5Ev3oIBtW5pDlICfPa1x3atzm8cU94sow chUNrjg9W+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnagAKCRDhuBo+eShj d0fcD/9BfkMJ6JjTkjriudNavU6WsCEQCsc8ocvGKvXwjd8pNZ1TpLP14Y0d9apjOh9MRrtxqBC 2aK0K76212t5GqXhNtYPyu4kS/0BM9PWWwQJTFIfsNE4nmcXDYSnmut0Wr6M9h0j7dRznCsxrp7 UVRgT9TMsucGtsq0xke4GO8DoKHOwn8TYwWTjeGsTBQHxy/D7o7yZRXnbZx1E3GZ0FxvcMd+er5 2QXFK1fSCK9PY8ScMoLJQxzceugWOajrjC4GKTPt6K9gUqrEBwxlHrbyo1jC2VbzagWD7DclVY7 C988KJGRg+H+EXbhM3sbDhbg8eWYiuDJeOPJ4VIGfajaL3FFwQhXI7WR85EdjqOQLTpowJbvvdl nU8QdgJ7sRIuoG3mh/ZjHG39ywXNZzLio7bDgjrJCndc7lozE+coTQw+ZJoOMv/NUrHpd0NBDaN okcBOIif4aqbGuli+tP93ss6uFB2KgBWYRsf0MViHt7dFFsHDAx+Oz7vcrSNughh25JNgLw7/a/ qpVAs4W/XVjHA4kOM7sw4Clot7rixGfRIqyTd4PdYd5WMQOrkkS+i2mwBJHL/GtMCIHiBYZEH/U f4PF8RPf1uU87MVnlV1wGZhfrt7/HY9Y1ug+4oWp5WUSoLBhEL89ZXCUsCf7SYzynt0Le/zTWGC dxBI7CRepIcsaTA== 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 --- 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6377C257449; Fri, 7 Mar 2025 21:41:14 +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=1741383674; cv=none; b=pMr1LMdVd7OD/FEUD+Erhb2eb4f8eWw7BcL2BauIcyU/wV4kV6YeKuANt1fe1uIQ4HwpE1UcKY7tXMLjqp7NUczAP/grwve1EFn4pPOO1WCPtebZkYt0wRpMM9iihsNcrsag5yMEWnTDB2sJljBcSln6M+Sp1hXON+EpmiLhh+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383674; c=relaxed/simple; bh=PkP7dWERrpIqA772sTetspuSqId5QckTq9VZHzXUEeE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jm5AlF0bXlUp6AjR11XoetCuOdqoEcjkWKo1DNT68dx6Q1LWsebBbkg3kHBydL/aiy4sRrulVQeqB1jFFdtT1HhDwXnAqt4Ceu1+nT+zj+CKzxeRMW0fVQzwyss6iyP3BOqUhCKRjbF1TMINs166KFnssMBCzbwBrBQnziU6oZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m6uBesRz; 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="m6uBesRz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B162C4CED1; Fri, 7 Mar 2025 21:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383673; bh=PkP7dWERrpIqA772sTetspuSqId5QckTq9VZHzXUEeE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m6uBesRzzdwmjLaqdFSdUyrC2aXHmz1yxKyKsJK5/uXSlbR+KQQlguQZxnHO2kc0r BhjzUFfICW4Ed35xqCoc4xIJdTFLwKCD+FEKxLoMaFeRkceru1Wybcx5ShoRJfW4os ytBUw/He3/Vm8Umg7WD16J45PXQqv9bPpbwAkP6vpb93LirMPR1tANsgGsIpxiZFId oqr/zkTluSbx2ON2+zNNob9gXOsxDKvpKMJ1LsPHI1e/9vqlfZNXfv8FQEBcvMeMjY 90kqd2nv5K1bcSSIwvO3mXzLtbvHpnIGwYZiQq0y5Uaq4ExLEzA2jyi2afDkB7Lkkw Yf19UTe6RttaQ== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:44 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-3-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=4837; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=PkP7dWERrpIqA772sTetspuSqId5QckTq9VZHzXUEeE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2drZ+70NdG0bF2k9lywAloYOgmJ4cFbKhCvI IvmnmZBJx2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnawAKCRDhuBo+eShj dwXMD/0duRqTwqgvlCF44xsP2rKTxy8Ef/mBN5GZzmL/0EbOTjIXIDaCQRZG/pbbsbcPuQenVds uWV/GdkGTpbECtQtp6Y46sQJbvLsGQX8x61mpsqffr8eAp/HZBbylUTcb9/WBslXfXiMl6QylYv +tTdWIZrBk5v83fXtcmigywGt8vSfb396IE2H350z9bzfZgXt+3oMXranbJfAcXGR3IMVVtTDPl qNXA6zwinwuTvibOdo64y9ypwp0B2lHxviPdkUteeF5kbrryXckAL355N7DqMja+w4aVLbJ0Edd WJ9ACi1fNgTcPyIQIAJFY5vf5NjSQ8npIOcIuwYqDPcSiYAWtttQ9GdjmjF6H66zsfEKKQV91AL URW4kGR4kVr6bgKFaRLXf9TDhS5YUqC51FU/tJHISgJDR0uYkjt4nSGvAAjbiL4Fyg6B4bETuWU 7WCCXuQHnkHTRyrCWi3nE7goH2CloabDxj5/rEwH1mLbC0c/YnHoxOgvJVR3+vjumaoTmRQzANx TdkP3T7CB1sb7op7JlPfUGFLVpnEdR5Nnf8be2CD/dWd3H9X+4ppKJ5zMSGA7RzhVRwA30bZjHv 2fakWtWN45AmwIweWq6Jl8cHMflyCXaDMg5U15UL7jfS9fqK39jiIUdu6+ujR2QwnUcFSl6h7Rt QKXuWyA4cJD2LmQ== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- 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 dc64cef96dd4..f69a8483d21f 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) }; @@ -349,3 +348,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..fe3cb869bc9b --- /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 requirement for the trait `HrTimerHandle`,= the + // `ArcTimerHandle` associated with this timer is guaranteed to= be + // alive for the duration of the lifetime of `receiver`, so the + // refcount of the underlying `Arc` is guaranteed to be nonzero= for + // the duration. + // - 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C4182580CE; Fri, 7 Mar 2025 21:41:24 +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=1741383684; cv=none; b=MiBeLnaG+4mwXajxwekeJIEhc5xQ0s3UhMu7arn3mF5aVzMpG0c3M9D5fy6sTnm+hW1ENDniCr/5fDWDN9ZW4WGV60FJWNjmQmWTlpBYYvAtmx6sMOv2PKKJH7nff44cunHAinmPuupiAuaM6OQR28JuD3u3HfD15/9thO9e4PM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383684; c=relaxed/simple; bh=ASoQCki3bqk3buqrbvnnPUagvQUAYcUvR1YCaRZm1ac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lPaqfeQ0dBQ5lLwcOQSi0ufLfljyjkvUZHkCSH5gSBTzgW9/r9+tp6tDFlV8X+GWKA0gPj9NJ+GNfh5Nn9s71XKIwtVgwpSWcgYjyCCHJBI+btmbYTu74u+tQIHawQoOiUvQiiccCUIJfgFSHPLnzBwxcnvnIvxrnBAi5ZU2uw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vLAj1Ean; 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="vLAj1Ean" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEF6FC4CED1; Fri, 7 Mar 2025 21:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383684; bh=ASoQCki3bqk3buqrbvnnPUagvQUAYcUvR1YCaRZm1ac=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vLAj1Ean51Au9eTYGHb5WhIKnLEO9imwbsMKfz7UAb9MCR6CvGEWIHvmKsoLmOnXK KbS/wGdUgh3n1LSM+cl5txrQLpkXbOJAbViEcBGYwHSi3bzad77azzW2v248QQZyMo i7D7XqaaAWErjalsG7BJ5GPxD/YGnTGCdv/1x2Z/eibWp+hROzU9EqXiR0D08h9R3z sKJvmR4D+3gD8puBe+56TxibilNkAq8NWJWfDKJRsn4Q2iznNXmLtQXhsVJCJ+/fER wmI7Ac03TJ59n3ghGG2ErmerSfH4xWhoAprDgV8wYQdopc7Pzv0wruLvCm8eFicBK+ UyudTj4RvDwJA== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:45 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-4-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=ASoQCki3bqk3buqrbvnnPUagvQUAYcUvR1YCaRZm1ac=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dszkkYpDC1CPW6snfVC3lOU/Nb8VA7wlxad d9sV5tv8veJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnbAAKCRDhuBo+eShj dwptD/0acutbQ+b0CIn4lTOe0YHNNZmHxqoLDiZOyhF1J9oYHujRACGuJsIAmEcM6L+QfllV05p rMFJI4V6sEEHnosrq932IA1TiySa2fmtMt55Sn/X5RojkU4bEEsRWJdl9XHeSt76ne3nDdhSsVL Tdqwxlc1HSfR73IJM5uFfTMj9vlOz6sUcnNx2qNVgkh8jPtpYtyVOeuXfOxzAArjQRT28Jwn2JQ k0XHigQ5wiouCU3hVo5YeEplI0lOOprvsJvhOFDJ7Cxp15cGxfAMBGA1yQR/ZjiaFNL0qiR3ji8 hQwhsboYY1rOyHlt640lvV2jWeQfpmHzxviceX/py8ooIfKqcD43qjB7GRuGY78jSiI/ANAbyIr UprRv3ycbeX+cbabEGa7dFDQp8XV10TRh5lgtFImRTOKKe0xY0PeDEUARQQ5ZcmCIqgLvpVxKh1 WrO3dgjPSSKcHJ+mSBYPXp/f9Bh4SlDExhltEw9RPfOMIFKUI85sj8gcCCy4y/VBdaALU1V+gum LHHgHyy13enWhpLDtSVPAwK4HbZiC0k0Cc1vdxPUVOprAZwBuR+1FdbVyWZy1gnesZxLwOqEVIW Uyb70lnKZkcB9C/hX37q5ruk0ARVZg7/L2Fy0lHju666x203inOl2OpGeU+9oZfSGsa/QrXlfoa xnceeIOvudEuq4w== 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 Reviewed-by: Lyude Paul --- 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 f69a8483d21f..1a2d05ae7f21 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; } @@ -311,6 +311,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 fe3cb869bc9b..e149bd4db509 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A84EB259CA9; Fri, 7 Mar 2025 21:41:35 +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=1741383695; cv=none; b=ePXCsdT+BAV4ALMNje9uWHgCI7xC3Z7X82bigKBelAr/r4HLiLt0YOAFO15mXMqP3Rbhczxf8z5yFPZhVy/xvbIgAGC9Rb4fi9dBx62MtmRKgIMzCheyZXGi/pMbTTctftjJGzWCCcY6LtBE6afqedyDBSaDLQn9ghPwEQTlpus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383695; c=relaxed/simple; bh=3bxVBo82ddemMxGZRW0VqOyDMzHVGczdwTPgSxPEcss=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=exEf/8yrOT35WmU1F7C9NdEsrJdo2vc3Fb0Rv7HCHcHOfMArvJxSNrL8nyAG70pXTglOTO8B8KS9Zuot7YlMEt8eZ73f/CuyPhdBK/ISVfNxbOFUn5bBRCTxMqKlWpbWpd145GCZlFYFp2bspkaxc1ugYKYBPj8BMv9sECLe2Pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aCZcdMlB; 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="aCZcdMlB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D8E8C4CED1; Fri, 7 Mar 2025 21:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383695; bh=3bxVBo82ddemMxGZRW0VqOyDMzHVGczdwTPgSxPEcss=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aCZcdMlBrfoJ29BfxV4h/jzhmS839sxKnXiRfSdZjKaDZT/Yl0jz2NgVFL/EoJqCe dU6fn9TP4GHyRNUisxmz2zD7uemF0udjTIvRreRma6XFs2wCw0O/3SV+F4X4vCBx40 NdCLI9xAH/aa83C02ub+UqPiMLvxfXb1x6jEwkfHh6A7d1DBFMr37mLixHho0P8pyg Ks9SDdrGDwG2gHnEI9HVyrVmq3fp+vVD1GZPOjQmsNcDwi/+Y6lMJfmwYRxlCbuZ+7 dJlj/4WbZcz+0ALsZ9HWqsWV/Yul+BN1wDsSop0hCVBAKLNntyqf3XnSKTghkoBf2R YRoF7Rguh34Hg== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:46 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-5-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=3bxVBo82ddemMxGZRW0VqOyDMzHVGczdwTPgSxPEcss=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dt4+osDGoFPXRGn6+5hNbfHKA7/e86FGCl8 yi7XB6rl/KJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnbQAKCRDhuBo+eShj d5CxD/9Pe+iycansJ0N165MY67d8ZujTH2HIENnV+3zB2ieJQkG6rIlkP9tPZAuXyE2OSWv5OTa GJFmhz6gyrQ08iPDDtxadqE3+hxgdyNzuQPk/Urvot6wz9jrLv/LFubgIKeFZDcQuvqmuEgvdlu b84RnVyKcOF2jUTmnaZlyD3irUwtXpXutwN2FaC0cDlzclcdsbw9Gn+UBvUIP92k3U/RatlmsCF iv0tOu/qyf8esns6Ys8dxvhLXSgB+wdHn9N1FF4M9b93hV74AQTxwGzYIp31OUQO2VaXH820OAj 8IYVPFFy/eu6QdZTFNDRuGv8tbunGZ6bRssDV0IomfeXw9PA1qFy1uc39QVfmb2qsqSdCPaytJc ASR3Gz7USeZ0KNAmydz3DNQ16nUdTvx37bOozG9uJKGJ4XPGz6k8NeiapmBrg+D64pQh1fG+6TE RuVqHrsQlH6lnHavFzOBFqTZdSui9SPr5TN2HCTxzrFxxSkoad407R81xVS91wgs8ai5lzCKPP4 YWpFEjTMZdDe4JjBSgIa8794LzfNAa5FD1GdyrFN5OsLkOfZAK/6XdgbivpzRuxp0rTSBilhos3 pZqu3Ey8qVQ1GBLjHFRtUN1KiwRig9PaBaUPP5ryZNol+yP6DlCoMDHMrzFkrxGCHi/pS4iucEt u9Q7h2WQdKkt3kg== 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 --- 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 1a2d05ae7f21..07709c795022 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68F2A258CD5; Fri, 7 Mar 2025 21:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383663; cv=none; b=HLPULVHSSyj/hyJcwMq266wZ+st8KGlKIs2SoeY0v0kzK1R1QBHTgSBdmGeku68P4k6qTHHuF5P1qZXclqR0IPfZuTjsyykwkpatKCSz0HRKdfYkvXqS11iBYXinkz+QXIAw/gNHSuK2kfJ0FEk+ApE/+i5Gziwukp24PTmkHmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383663; c=relaxed/simple; bh=+68seFzrEi0GzijSyUe+gmFbssuxM4rVKQnDZNFI5WU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BCW2LxBwhddvQ8T02xvtsN6sBmBMcwStjKgSJsBMK/s/oQzr7c1L35gZM/HgH2B/AZYPrS0GUN38rFJk3WCocdoboRFEO0G9DDH2fKiIiBpV0rONPf1itUGD0b59ZcU9S2jnwpfC3GwXWbYpotGIZho0I/8xNZ4061hY5t+HYOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uqYd8Bst; 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="uqYd8Bst" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F6A1C4CED1; Fri, 7 Mar 2025 21:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383663; bh=+68seFzrEi0GzijSyUe+gmFbssuxM4rVKQnDZNFI5WU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uqYd8Bst81Tr3zUDU3ssjKMw9tOa57gckjBdWHuwyYlgsLkeoHgM+LVKiFk9ue7EB oAgIxxVS8dazp9qxDEju0U5BX0ach3qpxrCuzhQR8T7/T6ngt0IJaDcbBW/3YCx2Az 55fZUX6AAJf68liyI1HwDIfEvi2mgHtOzOMvlV35mQ+yriXmF8j0zxODssbHD8zCu/ sXeFhYuBlbTQ/1d/4L//1bH6UpZxwMUN4PL9x4rhMdJdswqUSKitLxoY1SvZdmgoYN blVaGEsrmR08mVHkM2dICaCsd4MwDeVd+obBygL4ccRshPKlqS7WjBE8xVjR6MGSRM mvRMpnLzpiZ+A== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:47 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-6-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=+68seFzrEi0GzijSyUe+gmFbssuxM4rVKQnDZNFI5WU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2du37D/hncQ/oolfD4OeASse0x3kbA751ihO uFXctFjSE+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnbgAKCRDhuBo+eShj d9aXD/9wLBn5mY33LIM2RUFBwJfmEPY67Xy+cXvB21ooUyxcg7E0vanDM67a2sUWAFibTUJSzJW dOYIinIz924CN5rEOdWogOsGjVZoU9DH2i62LfeD8jzLEmsNp2ZsdCw8rLwUMzgfkP0u1/F1xaS pblT765+J9iUbBGT5c4ByleyfBDDpv9ldHspLByXdcjm2Y/kIvZMIFcqMHWh/qvV4JsBvomaUDu eBW2Lez2G2DI98aW8fOI5rZEJIqiGVfK9RPi9R9S3yuFCTL2121VgpANXcdJUMdTxpRKnVUQyF+ ogEsHMu7kDhaZO4Ki0n2g7QA9cbEgVqVMsWoMmkuywm9UcdUzyX8NtRaI/CHI/YIr9H11mrlEo1 g2+c4mzDwv3DlNaDOp12Gl399VrVViT136HJnOv7eny3kjD/fZr8oUKssDAiFjGRaoAH/IMqLNv zy2SjWOo/rRLn6GdK1cTo+IVHvDKlBMTsuYUq8VKeUndKk5ptIIvUXk4LcAddaVSC/94JWJ7UCx b0/bqv9EtByzg3DRfI1Cl3Ws8+X0joXwcEv3PYgdEvgnGACDuojgSQiRYj1oM2XDM0AIJs5aazM a/1d1nFURovNt1cYvyqx4AYcJXrZWolXXnrpxAdBM4oxWNrmHIQdYrFUi/LRCP/Qn2GWhFXORNn mZH6Nlus07jAdwQ== 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 --- 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 07709c795022..8eae2d10b6a5 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 164422586C4; Fri, 7 Mar 2025 21:41: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=1741383706; cv=none; b=IFj/Fl4Zc09YwJ19s4xDkaYBDwA0Z5wMT4dzvd/SgqlMHuiR9bqPH5PWtyL3CZBtjSOo7N1nbqiFYEmtQ0aeOZaWtH42Ov3w2ZC3QfcL46EIxbnuiVxfIzV62XmBslvtLhl0En1fVzaHkZ2lSJTuQmvDINH7k/7NQJ1VHsa3Zac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383706; c=relaxed/simple; bh=39rjeFhd5rDBchJ7XrlQK09N9GOwtaFo3/g2FBx3D+g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=svBO5V+FFDyE6BzeFaufX64uE9oYDsHmwFZi46DZSs0O7AukwQjSKEDKMyV4NCJbdn2xbIXLgOMBQTGpFPQrWg4xYOhBDgnwVduZPFJgC//jxZ3uMwzlMBcXBCHksJCWk5nwZVcjiibH5Uf0itekjGtYcDOCXCFUG0bnRZZ6HaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gi9fJvxo; 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="gi9fJvxo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F3A5C4CED1; Fri, 7 Mar 2025 21:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383705; bh=39rjeFhd5rDBchJ7XrlQK09N9GOwtaFo3/g2FBx3D+g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gi9fJvxo0DjRN8llww8mewVdDC5QQXA29UVKAngnXgjxMGkE3K/UDWuwIihnwoeDf kLxHmLfDnaYKWUjLKe5xW8DTDGKwqd7bGQAlGOkqQBQCd32JMfKsyQs2uQfR5KIxKi PBDpFZQI53I+v1U1c5590t9glTBWqrPTfqJ+ZEkjiy7l3+kbpoiI0EhZjp7taIq0XL lnePnvDdwdFuF4maPvhTIQ3nEnlPQvylmrJejsPtlhIZc+U8q++Xxve78NdV0+aJ5H wEIcQ3XsdMbvgEq793wkHpOP7Ssmgzew+NZRd9ePFnFGgPqN7bfp65oTC1W4PvPR6w p8yOBmgwy4LuA== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:48 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-7-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=4516; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=39rjeFhd5rDBchJ7XrlQK09N9GOwtaFo3/g2FBx3D+g=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dvuXVIiwjg7SYPJcDZnDgzm4T09G/7qqV4Q yBkowivVIWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tnbwAKCRDhuBo+eShj dxIDD/9DKr4PsXs/ydaCBCDdosM99NwIJT1ooSJ2vkU6xqNrU+fvqKlKClYOizzOTgr6ZoHJjOh p2c6sTjYeJj2SJdUAmkpBz8hBVDiRIb7n5glR4cNdVQbJ/1KC1c8T351YSXtxftjOg719XGs0ue hcNY2hq5rjdUhIc79pGlsczctyPOAoGbMQ8TdHyUiRh/sQAPKS8ZAb+qeYEs0pTouUhZfNrbpxG zP0x+W2DmOvFmM20jAIsaUzsrYpxfaFArMHitC177MIZNyHYQve5W/NnE2D0VbcAylg4YesgKUS 5s4YhppNqwTWAvpx7aNP4JF7oZP92u/Tdc34zVPK0wnYymLBaqxc79kLtM95Fde724Dnow7mlVR 7RmrJWuCbLWtiI9jFrQLjxnKE+muoSXmYA+MyaAsUtBQJ6Smj2OXoi4YKZZM3lMmE9Jfl3f+o7o 6hO1PpDmamNqmYkllVtAE99bqgK+LLnLmZpv68XCohOpPnWdlCDVjZjOlL96QZnxMSEJBI6OCNx uTD2sBruW13ne45MVEhFgoRaBGsgwlOUYXQ2Bv6fUI7eB63DMD3uMIC1pppXDcSKwmwXpmOzLyN R6WE0sTf5X4MTxxmoDoOnLGsr5jHVIRlP5ltBpHklPn84zo1mjmXxN0uJevmkKC78DwRuO7XSdd V8YUvGx4KZHhuDg== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- 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 8eae2d10b6a5..fee8e44447ee 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -431,3 +431,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..215afbad23dd --- /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 he safety requirements of the trait `HrTimerHandle`, = the + // `PinHrTimerHandle` associated with this timer is guaranteed = to be + // alive until this method returns. As the handle borrows from = `T`, + // `T` is also guaranteed to be alive for the duration of this + // function. + 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E2E4258CC8; Fri, 7 Mar 2025 21:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383642; cv=none; b=EjuFlfYSBMdhSA8zQX4LmXzRTu8werETVELc6YQl4OBaNRlb+07HIqmUxqZD/bCSkhTbLEEQzan40vhVW7kQctuyAGIVq6od3N6E0j/7mrPWBUQ/GexMz6/bQpzQsQ+JCzOSQghuKUsGywycnH40prWx1PaClDdaonjZUWBBh80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383642; c=relaxed/simple; bh=VhJsbQKfMjuj9PdCzRWTYfUb7k+hB0p9SP5ael/b4P0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sBL0XiByiIECHWhprA6nU8frS4YlyKP6J3Rb9glj6DOa9hXXr8iSldHFTDk+yPzky1dv7qaeF6QZGxJ5shusRBE1Et36+roj3OESbTuKE1Rm1SQ3mkmOdabHavguyIuZmnLgLFNQNz6lNLjRvvLHEe6AHg3zu6svd5IF1A85nAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ovp8Lr6N; 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="ovp8Lr6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F234C4CED1; Fri, 7 Mar 2025 21:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383641; bh=VhJsbQKfMjuj9PdCzRWTYfUb7k+hB0p9SP5ael/b4P0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ovp8Lr6NNy+wgA2cGcykmix8OVw3ClYfqa4NvUp+K4RFQpZGNG49p/vCaybQRT1Ba V1TYP4Qfq0j3+FdHnYQukk1VB8+0qdKnOXQNok/pf/n33dTdC0LOQEAJcn7nWc3dXA 9xhKX23Pyx+HdXg9Nzx8Bmp7gRMQSBebuOCuj3WnFiFW1gRPizm7Y85y6YIWuYch8V UD+MtBrW1n6iFqc+DDpvs0qL5cn8WWEc+SXzq8QdJaRjM2AX/lq8+7w6dtNYTqZbkQ MQM3N5SxZDbgj2loMOOXr2bhknCYuQhhv/yuCEoYKCG6ErwHU9FJhWcUvyJq98TUy9 1UC8tX/OHxp+w== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:49 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-8-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=5089; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=VhJsbQKfMjuj9PdCzRWTYfUb7k+hB0p9SP5ael/b4P0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dwDd/B5I5XHoS4NT6uJl6tIIXWSndxjgIjw 3lEnwx40vGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tncAAKCRDhuBo+eShj d1HIEACk8oL/ITmAVZbUoaVG6WNUI0HlU8TSg9GbNa1ImwDdEur4qxzcQ6nAAdw/rOONjlrVbTX Z8Fduu3t3XNQfibyGSfcKTkYqAG9/eeKMcrWShL+SwrySRMgrXOuuOPgw1k2XQDBb5cKuXLurkm rHNpGIG90EswJiRxR20GA4XdEYyjSLbn05BCJ/5ojh9oT3RNSEcgIP3Hn8Rto8SAw2SPagU3NO+ JpM0wSq4JQO94y7Z7sM+iMFS4G/gW57nILpHI79POq5Rdasj7B+Btfr9piNvoONOtT9FOgBvWah 5AZeGynOUvG+gf4YHvkxu49s/LN8O2Esm1DD8CLFEnw0rI/AimlpsmmfSJ+PfdaKEJaelmemKfJ Bd211eaV6N81ebL5pwo6x7/vBfYC1hMejXivzznMj7bXEP5x81jzTpg2GIkhN9gRI31Tsq8DQet LsY3uiEV2hnAFnlx/RMSA42Un7sxnbRqBAIzSi/ln2fh1oXxf5XyLDvdfvLKw8xz+X0owwQEwfC mWbPJVofpTieG3u+LRomaaWHcDfCxiixxpTsgZP4dcS7gFG8mfuuDeHqoFKsqWWLP5AmxO3LfxJ rHsWLYJA4dgHII5cDO8NkwWwV1LKdgqpRH866TR+G/ML1tFYOAapvsupAZAySWhZAbgG+yy839R foQXbcD9VzJ8WNQ== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/pin_mut.rs | 110 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 112 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index fee8e44447ee..ab0950a964e8 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -433,3 +433,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..007f47d26df6 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,110 @@ +// 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 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 he safety requirements of the trait `HrTimerHandle`, = the + // `PinMutHrTimerHandle` associated with this timer is guarante= ed to + // be alive until this method returns. As the handle borrows fr= om + // `T`, `T` is also guaranteed to be alive for the duration of = this + // function. + // - Because `PinMutTimerHandle` borrows mutably from `T`, the + // reference we create here is guaranteed to be unique. + 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A39E2259499; Fri, 7 Mar 2025 21:41:19 +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=1741383679; cv=none; b=m/iM8jEIHBRX+CUmmuubsBBSCq/sNrXJXJdElzIx+Oe4Un0+VbPp+yI0tYyw7pHJZ0F8frLfKosDZ8PE26TztKdUiXquAbhDd4Q6iFNnlLLLGtbU/JwZv0CBdZi/DyNU0xpP7Kk9atXUfVOsO2OuB8fdEKBQnP1pr+7Vaw1EOdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383679; c=relaxed/simple; bh=Wo/kUAupEBOIsOdnruISz8EyJEcYwqNCGfSTf35FejE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pkp6tN7gzaF5lQ+WPXJzj4Wa7/QN/bHQWmQBocLhCwCRj0IbMJ+RSlholr/UCmJTGu50wIPjA86/+Xg2lOF971Qi9jaA5mFwlsliqx4WQS2D66YqCshnBxsBHBcc+Masznc6V62aQBRfsKQcyqf9qeYjmT4zkYQeCFSZnBxvQn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eesdVX97; 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="eesdVX97" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A057C4CED1; Fri, 7 Mar 2025 21:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383679; bh=Wo/kUAupEBOIsOdnruISz8EyJEcYwqNCGfSTf35FejE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eesdVX970O1ZLcX1890CYzVzhQZskAHIXQQ+L8O48lgJfnQldu4G4s6G5nN0nW1a0 fbdEskiN9yQPIkTnG4Lzj2RQNTkxlv9BEACJZt8nl6AxikqXzMMY/srfUwGRldSWaf Dxc2gZKZeKWahhAbsHF1oeHipASoqkfpy9lDvM0TOnDhaGTfBunEMLJvmoUTY+wmMl yVXRV8t+LY37xhbFuCsGHc31UMmkiCuZAsqJzr6ru9ALfwqBhgI/gFWgZ4904IWZfX vFHH0qbTnp0QWv+sDEoNrl6I/Q2PUJuSApXAi8WUcdpiGUetGDX4WQOI1uWRR8CdGw r0ZmV5ObKIcVQ== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:50 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-9-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dxu/uhgLXT7ISorpd9dg7cQ6aCdcpzjSVD0 hE6u7bqfmWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tncQAKCRDhuBo+eShj d3RkEACw0J7jf/OJbzg4z1iUe2dA9nuDP+2rFlcDoqbvi2uYACTPlOXgx72MhTE8C9KKGxvswUy D45WP+UEnVvxLwsWrHZxZWPl2KQExmrhsE/08x2/7W7HGDMI9Qc+mY7MtfOlI1gZZRf+85/hWOf EQ2EiY8a2AGvRs3mSCrmOyJFnZQMdEfUfQRufmCFuHGTvJt47tuz3EwkmAzd+UWJMouAB8TuT8O UaH6XWVWrwQbFQfhaDMhX/iOk0M6FbpodOZItKoD7nwv+Kde4GLYjdTCMlpJRdZo4uIg/K2iU5g 6qAvUc0nxfP1ahIqPCe294HhMGAA/byZdfb8+bFzGDK2qMFKW8s1qIhZbxigEmt/reK7zu57zkz Na2bbpAVjOarCMWo/jH0ymhCxyeNos1M3rsGN4CDOpcSMchxdVS3Xt0cNkFaj/MohNKdYmEw1Tn VY/nxdzaTdxM3dKggAYC6BEE8MwDBsNSXAOn2ilbEQa7x3AFWPeKEw+h0oqe6DKmmILGaFx6jm5 mHuKKogvyAWeA5iD3NUNVxfBt4JU6zLQasBzgY/01WidoRmUMRgjUrJ6joLZIlgDI2vsjDvDiBD T+3uNKhawh7+cKl06gBahMZ8iTLBuLqkE1ojcKUFvUlfAoNXyCKkmh7MMAK/d+ZLwwY7/VPXtLm SCElTRVrLjaeu1g== 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 --- 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B45F2586C4; Fri, 7 Mar 2025 21:41:40 +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=1741383701; cv=none; b=TyYFBzftJYlVEEaEMNc9x6mJHoelzKFe9Gb0jEujC2fqravADTqywoEUEMlOEL3s+0yCgTRrpnHL2h6KGtyKRPKriajdef92C5CXiZkr0aoAN5vR5c43+u1LswN3NapQTdY47lGCMKCrL455AXcMrmI7XmLE4LJuWlkDKOWDumw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383701; c=relaxed/simple; bh=8HZc2koQvpcFgAmxjbTk3cLLBpLCSExGOakb1JOglEg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cRBEkHRI3Xit495VKaunx0UAd/ggdpKhHwg+1+TIa9wT0klzFKjXb2bdt0jofeSHOD/O9WKoUi7wb+3Ze4cn/e3T0bJoIRqgiZMGj3ujuGyE7JW6ah70vmvF8TqYaicolrh5Hhr6s+PEG+g9PvBkG6i8tJ7C8jmc+aN5zvo/5m8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UrLWY8gr; 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="UrLWY8gr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BA7EC4CED1; Fri, 7 Mar 2025 21:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383700; bh=8HZc2koQvpcFgAmxjbTk3cLLBpLCSExGOakb1JOglEg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UrLWY8grBHVeub6sTOSp8ffC+pw+TIfdf6/QPHFMBf8PfJlfMIrYtqeCLYQ/UYEjU fwUGbXUpmVOgX38sTcO2ixZb0uEQ9g0An2zse/Fp+jgQ8qXKMs6wJHuuX9NfTcEhg5 AhdlKNKbDkc08L6e9T82/koBgvnGbToVMh7cIL105omW5nZm1tdV7/WCD9h4TAfSnH X9vw7uJx8DBHglLz/B0HgNj4ISngUtkLY7EvQiT+0TPHpU/dWt23+olsE/YBXHQeDh pxvEoVoJ9qvvBypp4KOxcq3xkxFIXkn0GzLoEtwewV8OPdACJBwIpPa49RvNbedEbP WM9L64MHTy4hw== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:51 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-10-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=5085; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=8HZc2koQvpcFgAmxjbTk3cLLBpLCSExGOakb1JOglEg=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dyHqHktX4I8RO9S6j6/h3c0NhM1k/lY4sAl etJ+Rr6r8mJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tncgAKCRDhuBo+eShj d/2oEAC0lW0q298CCj/+GL1al4Ren5SQYBWWIfpriuWggIz4cJBLINTUr6COlvi/p/sHoBdfS1+ c+CpLwplvGsAJmuZoCaDb0hsFTn6+CxJ8JSe+aMS6p95IlgyE/wbfeAcFX0FXe2yYTXZWXvW2j8 F3HOK8cY728HEgBHYDVStbhVPu00nwDtd3WlvHzGPChxRELOXYpGJsFndvkYmWFDERa0uLlPHd5 f4ucn6UWo2ZquWcHbKP5YCThRT4mXocremQh+euYMU7SQ7mFKV18YnuvS/BzII5z9/6DfdEUtmo HPQi8rASNTeEwYsF2OjuF4sfrHSLtjt0ymxM2RSXZum448KwbY55FIQ/DCwdsOCHfnA+oNJdKo1 9jJTzcoRfbn4eKdjbwO3zqjnz88Xr62+0ddjmchS7HmIVzq3B2eRrDMn2pICVoW3JzI3jesu136 kN8jmUzm9n7pLwto73SBPxw+MGO2hmb9NC72oAU/bc7srKJX7qfYJuoMDxhtN44xHh7/wFW/x0E 9zKw/n5fl2pZjr79x5TqMLQX7/XFKXh+qvgjVrfVHsBZd2q/KMlodTKJr5k6pekX4fijgPe2U4v cTxoWWQgecxGx+uB4LBdZaO2ODJoTNYT+6MJ9G26dkFJ9+hrJfGgC63uJODCHXwgaKV+M4YPwrj 82G9D/qOoJywjew== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Benno Lossin --- rust/kernel/time/hrtimer.rs | 3 + rust/kernel/time/hrtimer/tbox.rs | 118 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 121 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index ab0950a964e8..cb404daa12f8 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -435,3 +435,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..43a0aa245368 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,118 @@ +// 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: + // - `data_ptr` is valid for use as a mutable reference the + // `BoxHrTimerHandle` associated with this timer has a mutable b= orrow + // on the underlying `T` and we do not create other references t= o `T`. + // - 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88EF6257451; Fri, 7 Mar 2025 21:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383647; cv=none; b=XfrSYa6SFMm+hIgfv5jNA/2Ldr1GYOqMHx0PaabgVGXpwi/PyrD1gxX63iFGyt48tnDBWYNSC+l8yDGLZ/7FcxR/g5BruPqU1+kwtXthQ3tUy4L+MLKThmS///rzEt7wyliaWyixpe+OowBgOYlogIrMx953TLhoJFeKXD1rB/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383647; c=relaxed/simple; bh=EOkY/aoS6nNmxClR0QpR0OVOdPp6tEkN5Lzbu3qGboA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ahgSr2UUBToIMOhSjgQ90nim55xN6IJkPBJd7yo1doLLYntJZmCgYh9LHi/o6s6Z5cNUhLn131Fe6ofT9rVegfPOUtugGj+Oj0V2r/1Uzrh3T6Y7SbZrvVL9woEzhV8QwDgIlh4AOHmzSQ96G4DbeHDtcDWHusBGUbyYNzVSL7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AJz253yC; 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="AJz253yC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4E71C4CEE5; Fri, 7 Mar 2025 21:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383647; bh=EOkY/aoS6nNmxClR0QpR0OVOdPp6tEkN5Lzbu3qGboA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AJz253yCq1aISeytSMmpfLfy1Tqgz7/c/EeOj0bAMdVSpTpoG2H54D+1bUt+wt6mz Gj2rcLeFCSe+TVf1GwYhbW/2MOwkXBgoTjiZlW1TXAFsv0zrSeY8n7v4bpz3RDRf/4 B3T5J/bQ1My1hUOoTIDwQHoNYspMMaLCvlri5DI6CiN7CqOGbtZeV1seQ2QuXsFMe8 talltKPSseDWXyLyaceeoCr5rt+zBVQDX1r+u7r/kO+l6IgMrFxM2RD1jnkmcOoizO Q8UF+97UpnHILqmi2KpAeGZq2RuBBdGwRKjgKyOLaFBf00iO2/fc36zOtRkHmHhjJQ vKolUeztTHz8g== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:52 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-11-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=EOkY/aoS6nNmxClR0QpR0OVOdPp6tEkN5Lzbu3qGboA=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2dzeO2GJFPsAEmt3cDIy3IIjCvtfal7nJZ3M /RrGxBpo0KJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tncwAKCRDhuBo+eShj d8zQD/9OJcDxannRy66SlMeyi6zJbjgQYlzwiE2Ue/niTSb2K4xmQECFK9zeo6xdOV2k7omMrQI 8oxn6+PgjXTwbh6mvfcTwFuN83EdRJSJsqDWQX5nG2SUF8/DR8BmRzdqAo1UKbkTL0wi5xA1416 IIJDwJ4KRtLfXxFoEntqy6ZJtw+6FPh8kQ29qOYDN+vGnLU23tb0vF5PMsF0dMWVw5n5Wf+dVG3 Yb4ZScj0fMZtCxyaoIkwc4ri11OpuF5a1d9PuUJqNFcJa+v0MZiTkh/5G7HliU0pPsisfmTpTqp kn11D/bx4+mj4qGWf/UVquz/q3THzptgq3im+5qIyu8ZPxL3na+Nzjwerf3hCJWiKUHUr8i9B7z R5zre8RoxSlO1fNbtlIHjubAza5DJ94VsTHSn7wLnjT2VCGII0lj9eZ1no1ZlVv5aqy57QzoIol m3VRz1KAEKjW5G3WYD3XsGoNqG/Rx50oAgs9N6DyevpNBF3m1vPlGY6lASO1KxYjhveCX17djD5 s0k6Yld4ZgYoZA8mgWAut1pjVUhzeqk8yafP1JWNt40Xnvp+3WTHyXMZJNd+GekJOJznX+IDb3E Ch/Dpcz3y6ghl+318ox8P9QrHWkB4eZO7EKZMD8+QQTUAqPPhoKuPmNu0OYdt3NAQLnKF7nyGIZ QEnTspaiNSLQUSQ== 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 --- 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 cb404daa12f8..2b7ab112e187 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, }) } @@ -369,7 +371,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(), ); } } @@ -391,6 +393,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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15B292459F6; Fri, 7 Mar 2025 21:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383669; cv=none; b=iPhjpmUtdMPilk32BSvOo35V4mILpYLqtNSReJcM999g6E2X+I8Su0/itYblWE6p9A/EWH4XCLByVnIP5JtLHZTu57svDpfblCEPAX3/xSFl2YvjWvXBRbgXlLsFd218BmO/DNLE+1C1etPlyZMGsOIwrJs1mQpweg73diEmPT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383669; c=relaxed/simple; bh=6qkooi3B1u/j+X2E8Y+Wol50H//30QxUSdGcR9hM7AA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WizCHsgICP3mM+xpov6P9t/ifWISPj6wS8p0leza3egLLfEK1FmPiE295+3YUqPV76EKuHzoiH8KuaEwrOAqKzVsAYl5oMR7918i5SzJIO2f/1nxwR/vKZBOh4XQ/32fL9HhbOI3dymRg0S9xiU7qBW5omrOwmJk9Cl1qy1fqNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fF7Zqs+z; 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="fF7Zqs+z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEFFCC4CEEC; Fri, 7 Mar 2025 21:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383668; bh=6qkooi3B1u/j+X2E8Y+Wol50H//30QxUSdGcR9hM7AA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fF7Zqs+z1pSrwnOCAu6klnOakr8F3Xaa0wsWzuGPxACnASfgam0eK47gPeEgUilKJ GjJazRgesbaCbANBiTzdRFd6Ta6LVeSGxxK1rirtF+XGZFNjjS0VKuh3kSx/2fz2J3 7WHEKN27wDhlR15oBBjJEDcE5eYzOw2hyCxdQgKAjbyHfjOvaIyYGLCyUfY8l+hZvr cDCc2gPH515rIr1QX5VRxJE7/OdNXxPaTB30vdIZpv+B7SksMLjbLpnnYywzJQu93y ukP3UM2r7Ujg3zKBPVlRNdir353bW0Cq/hchhztgiR+s0ilQMKixCxxfugRvCXCtVg mcz9jDpSV7esg== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:53 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-12-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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=6qkooi3B1u/j+X2E8Y+Wol50H//30QxUSdGcR9hM7AA=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBny2d0koMifcrJGDJ28KxAtRgJOQiY1BpIucpKF 0msesDdAxyJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tndAAKCRDhuBo+eShj d7xZD/9WxngKNtWco6FWPM5P7cTkC3sLIg6C2SbmANOFExx/kF6QyVtvC1XoOpUcaa4XXNt+dFd N1WCQDA3/AF0Co+hRPXqEm9N3tvTn1ARpuKf9ru/ZAtId0MKYV5NPjAnpWOu/xMMQWegkH8URl4 k7na1x3BlvUvik1NHtsIpX31AupDGSufi4SnF4Oi6IScON2rzatRMAkdWQOQuigWw3BZX22ppHq k5Rc/Yc5G9QCaYfASTMYtfzHAFu9vS2XQUV7B0qkRwMG+OiMqLSVFe3QtVrrWocmpeDCnsee8ur DJgsrAdEPJl2oHssbdoJHpw2iKqLxrz1hwiGIFkfzzJgP0xqPxDXWSQjOKnM9rH3YjnhdoAULJs cPQjKM/KiNarNQ+f+h8cLAm2kBVlDcac5JsJXchpTfwWH72zN+g9mwHlGrQFqtJKg0JcAsVlVmw hp+l2p9e7DGGEx2UXooQNPiMGRrGTG68I5styv6+XVDDG5l6ozQkg9sQ2IaPMoVbdadwe8x0zeO Z2ixL1UZ8FmagIrXWQEl8BhwXt4x6idfxmg+y8fVcCuR7XNQUocqJAP5CatrDu6HmpaJzvXDX8N u0Rdqwbxvu8xY25NnKCexaRh1z44AeCNOmrDYtfjdIBcScyLBS1n1WrdiAWxWQnqpCGgt2rY0Ch 97cbL5pFRkTSE1A== 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 --- 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 2b7ab112e187..a75df68bbda9 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 Sun Feb 8 10:30:06 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E9282580ED; Fri, 7 Mar 2025 21:40:58 +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=1741383658; cv=none; b=TB9S1/CNbA6qMLuv+WDC4O0NE9tUMLCjigFqwQeZCUmpWJa0IvQXwdR8pGbtPKgf05qQnXqwJE7RqjYsXcTfEdLFvkiJNu9DUnsABkWjBnXdwAbGQxog4SzXqJfvU+2VlFCCz4woznVOESaqfRUin850Vt2AR38n5RrBKHXL1RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741383658; c=relaxed/simple; bh=dIjGlvzNhHkBxSc0U14VbDDTWmgvVt6lr6a6kbU7+mg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TSzFF/3pKFM1oV+GmggL5pFqM77MtvIIH+9spjyFfkkBxuLYS+XSXh9aNUaULu9PY9WTzqTkbyVt4zWQ5SII0Ud6YW17a3QFvCizKtcH/xInh448kolpHSKWtSWeEgT7//8zO1hkSAzNp3HfH1mHLfKSqgcUl2y1B1rGs6b+4nU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gcgGEGti; 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="gcgGEGti" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3108EC4CED1; Fri, 7 Mar 2025 21:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741383657; bh=dIjGlvzNhHkBxSc0U14VbDDTWmgvVt6lr6a6kbU7+mg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gcgGEGti906GxXQHFg2UnNItdm7fuBwHzBIkwmRO5drlIUkfa6wbcExGmdRcim9RP F/e3bnWtaT74PoZYLJe7vKbDp+2U7YKeuWcoOyDDS5gsdXTED4Qr2kCyzkW066fq8F Zsmdt5J8tmB7gZjw71HCzvOCL1a2Bk6K2Rq2EISYcURZXry8S6U3LVKmFm1Y83tk8J dtX/RSWiIAGlH7X0FS0rciuK6n5v6MAMREMQCuRuvXzDtxA3tQrSdTLJUbUj9mEBuG MVz3aFv8ZiVQdDL3IgyQR4iv3srkvsvL3P5pIuxT9IYeLw/hMlYbzrHfWp9HMXIAcU 6iidqY/bYNkgg== From: Andreas Hindborg Date: Fri, 07 Mar 2025 22:38:54 +0100 Subject: [PATCH v11 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: <20250307-hrtimer-v3-v6-12-rc2-v11-13-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@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/ZANAwAIAeG4Gj55KGN3AcsmYgBny2d1z03moddNvNr91OyadheiayqO0tyX83Tsz owja4GcqtiJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ8tndQAKCRDhuBo+eShj dwCEEADEjwlDNp6WoyGUOwHZaMHVYSdWawahVet7kCgBtIlwUR8UrnSIkEpp853DjnQmA2IkRp0 F0EbCFcI6oWEYBqUs9WAZBkEtOufS4/7cbhAQj4yq2jO4ugg0JxjCFQiOWcbTmX5M37yX1fWmI/ xh9AdA4VSoLhh6I5Ll+nlNB38trfC6kWVquAN9JzG34r6GsPwvY3VGwnKZowpVijCKtsDTiG1Gk IeMbIiyO7PKaMKt3J75FmXw45QSYpOy3uZq3dT+9cHPxupaDRcUyVrYDUjwJ4pJlGa5f4fOme1x jfzs8yKMXkz8R0KLo71hT2dqYsx8xWE1fvH2Unmx2xab9eTAo0aLKPmtYOnTvUpFWEOHXoNiXKP dNEa9+6sQ0ZqHnarSxHbbjOoOkgWsKCs3N/X4q4/cHDcTCJd4+xHw0cWR3pNiazA12AhWvFDjlI pIwPp6PremOdMz8mgm0ldeQ8M3TDWW/zi+P90yGbRY6tDLS/Emkoa9HkmSb8153N5QLkk3jSohE eg9nGoHts3sv7IWQDZG5xQoQxzeH8joUhuWrxLIgXxeovjtR6kkwyqkByTIKuHSvNQaU9zGlSgR Ftg6G3bJTqY4ArYbniJW66x4K18DbeKoegInXVucR7RyUYWDrfHK2rOHm3+bIfrktoVaDSGALaw cGyaVgwPDG6h8bA== 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 --- 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