From nobody Sun Feb 8 08:47:47 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 C51DD2571A9; Mon, 24 Feb 2025 12:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398772; cv=none; b=Cj7wXaKhPRq0vcwvI6biUuzQjD73ePiUMf+utUDwnOQaqI1aIztYtGkwXwPEqvRtu7GrK3Hp58r7co+/62CpKhkjkqCXI7MRkg+IbvnZ3px/FYj6eLuRw0N/HWSt8aJVQ8668UGQBgYYxVD3ev4jjxWqmnJVz5QRfCP9ZuHHBPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398772; c=relaxed/simple; bh=Nzuene3NVidCaFeicx6mpxQJsNDAEReuoanj6ttvvKA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DRvy5t3UvFtwKp5jKeT1xr8zbdwqV/hmFDaUH31Oiraoy8iqQRHbIueBpp6+3mLW9kKBO9Q3LUsrVWgjgHQjw9lPQQ92E5N4TZCWb0I12goq17vMgX8HS8+9NeKTQdT7Wxyd8aGgCYa8eGzVHC5yMG9+6qfHjkYoju97D90Y8Gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DQ134fp7; 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="DQ134fp7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7872C4CED6; Mon, 24 Feb 2025 12:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398772; bh=Nzuene3NVidCaFeicx6mpxQJsNDAEReuoanj6ttvvKA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DQ134fp7SNZYMQvRPkpD95AMDuvKYakZoeSjWPxZHmMKC37IC7wh090+Mqcpj5YZS d2g+kDc0YZNtGGKAM4wF9XTenYLBoLN6Lx6dEhJEdjUuC0OevwBWn5aaH/NehuC/fb TB9lbb4RR8D24glRSbZ4syuFEBoItZ/hdNERj+tMVebUQiIEny8rkyOqH+NJm/UdTn ZSNs/eklNV6gbfxHcu04elqbnsV6tknVVU5UHKguxJqe1H42mkkDyjlV+k5uD9QRsm PqoN6qTpZ5+wviUjBV/G9cohQrcCk0andVlPBq2k2poWLmgtRqTxTFfPZnXmz6DHnB WjZVoG8E8D/OQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:35 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-1-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=16531; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Nzuene3NVidCaFeicx6mpxQJsNDAEReuoanj6ttvvKA=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAcBc3wloRfg0eFVJIIDVxOlNR9u5AtPaDek geOjdNpiaeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgHAAKCRDhuBo+eShj d3amD/99F1R9JD49ne3hqcLsUF2uxohsMy8jToWC1HrkURQGdO6ytxMN9I0hxkS0d1WvIafGMpw Rpg0uCT3Lps2g/nwO03vnGh6ww6gz6kZVTSxTHxHjKW1nYYVOoiQSY4NtrJblXSdfUbQwkzWNtA tvoOagyPFDE4VSPaoTjpJ041Izh6RRxlnz8Bw6AT+DV6gcg+8c2IRg9m5pbBlpS1HRL1QFLPXah +fojXhZjC/9fnVm/0n3bmUOo6kESokhy/O5RROfQK2Yan9fxxbgdTUsjnKN6YPHS7vXC60OlQcN N+uCTmpFp3AXN0VdoykSbeObnharu9cJtVzG1y+DDvoOJsvV+bXbAyWiYDWdp6W2alwuNN20uqk aE08Oquyb2kumHZPV3CKOeJibikFfD+F+mtCJhYmdY7ARcd7gwHAZEHnaitNIuIC6jIDcjOgrh8 bNYSp72wvWUCQMnR+pXJFpL5h4ESSfvjLlWI/msvoAThm+uxrwTEhzlfeXzaUyJ+WQA1aUZfbkN GzHKkuN9eB4CcccZhYs8SgcekV39556iWYMjqGbzTRyiG9FT5pD85iqCWYPwCJW3eO50czLygVx Lb2iGqKArEGDVWkzfQ5I/fAbengzhOV7MBD7LIKdh1myA3eyETUhcqFewT2zfXvn5Qh0EsXRBWs YLNICDy+dyvlKgg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch adds support for intrusive use of the hrtimer system. For now, only one timer can be embedded in a Rust struct. The hrtimer Rust API is based on the intrusive style pattern introduced by the Rust workqueue API. Signed-off-by: Andreas Hindborg --- kernel/time/Kconfig | 13 ++ rust/kernel/time.rs | 3 + rust/kernel/time/hrtimer.rs | 347 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 363 insertions(+) diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index b0b97a60aaa6..7726e14ca3e2 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -211,3 +211,16 @@ config CLOCKSOURCE_WATCHDOG_MAX_SKEW_US =20 endmenu endif + +config RUST_HRTIMER + bool "Enable Rust hrtimer API" + depends on RUST + default y + help + This option allows exclusion of the Rust hrtimer API from the build. + This allows testing out changes to the C API without having to update + the Rust abstractions during initial development. + + Say Y if you wish to build the Rust hrtimer API. + + Say N if you wish to exclude the Rust hrtimer API from the build. diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e5..e928b1340ee3 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -8,6 +8,9 @@ //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 +#[cfg(CONFIG_RUST_HRTIMER)] +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..fe20405d8bfe --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,347 @@ +// 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 finished executing, the timer may ente= r the +//! **started* or **stopped** state, depending on the return value of the +//! handler. A running timer can be **canceled** by the `cancel` operation= . A +//! timer that is cancelled enters the **stopped** state. +//! +//! A `cancel` or `restart` operation on a timer in the **running** state = takes +//! effect after the handler has finished executing and the timer has tran= sitioned +//! 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 C side, so it is safe to operate= on a +// timer from multiple threads +unsafe impl Sync for HrTimer {} + +impl HrTimer { + /// Return an initializer for a new timer instance. + pub fn new() -> impl PinInit + where + T: HrTimerCallback, + { + pin_init!(Self { + // INVARIANTS: We initialize `timer` with `hrtimer_setup` belo= w. + timer <- Opaque::ffi_init(move |place: *mut bindings::hrtimer|= { + // SAFETY: By design of `pin_init!`, `place` is a pointer = to a + // live allocation. hrtimer_setup will initialize `place` = and + // does not require `place` to be initialized prior to the= call. + unsafe { + bindings::hrtimer_setup( + place, + Some(T::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 do not create any references. + /// + /// # Safety + /// + /// `ptr` must point to a live allocation of at least the size of `Sel= f`. + unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrtimer { + // SAFETY: The field projection to `timer` does not go out of boun= ds, + // because the caller of this function promises that `ptr` points = to an + // allocation of at least the size of `Self`. + unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).timer)) } + } + + /// Cancel an initialized and potentially running timer. + /// + /// If the timer handler is running, this will block until the handler= is + /// finished. + /// + /// Users of the `HrTimer` API would not usually call this method dire= ctly. + /// Instead they would use the safe [`HrTimerHandle::cancel`] on the h= andle + /// returned when the timer was started. + /// + /// This function does not create any references. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + #[allow(dead_code)] + pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; + + // If the handler is running, this will wait for the handler to fi= nish + // before returning. + // SAFETY: `c_timer_ptr` is initialized and valid. Synchronization= is + // handled on C side. + unsafe { bindings::hrtimer_cancel(c_timer_ptr) !=3D 0 } + } +} + +/// Implemented by pointer types that point to structs that embed a [`HrTi= mer`]. +/// +/// Target (pointee) must be [`Sync`] because timer callbacks happen in an= other +/// thread of execution (hard or soft interrupt context). +/// +/// Starting a timer returns a [`HrTimerHandle`] that can be used to manip= ulate +/// the timer. Note that it is OK to call the start function repeatedly, a= nd +/// that more than one [`HrTimerHandle`] associated with a [`HrTimerPointe= r`] may +/// exist. A timer can be manipulated through any of the handles, and a ha= ndle +/// may represent a cancelled timer. +pub trait HrTimerPointer: Sync + Sized { + /// A handle representing a started or restarted timer. + /// + /// If the timer is running or if the timer callback is executing when= the + /// handle is dropped, the drop method of [`HrTimerHandle`] should not= return + /// until the timer is stopped and the callback has completed. + /// + /// Note: When implementing this trait, consider that it is not unsafe= to + /// leak the handle. + type TimerHandle: HrTimerHandle; + + /// Start the timer with expiry after `expires` time units. If the tim= er was + /// already running, it is restarted with the new expiry time. + fn start(self, expires: Ktime) -> Self::TimerHandle; +} + +/// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a +/// function to call. +// This is split from `HrTimerPointer` to make it easier to specify trait = bounds. +pub trait RawHrTimerCallback { + /// This type is passed to [`HrTimerCallback::run`]. It may be a borro= w of + /// [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` if t= he + /// implementation can guarantee correct access (exclusive or shared + /// depending on the type) to the target during timer handler executio= n. + type CallbackTarget<'a>; + + /// Callback to be called from C when timer fires. + /// + /// # Safety + /// + /// Only to be called by C code in `hrtimer` subsystem. `ptr` must poi= nt to + /// the `bindings::hrtimer` structure that was used to start the timer. + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart; +} + +/// Implemented by structs that can be the target of a timer callback. +pub trait HrTimerCallback { + /// The type whose [`RawHrTimerCallback::run`] method will be invoked = when + /// the timer expires. + type 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 finish 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 it is running. If the timer handler is runnin= g, block + /// till the handler has finished. + fn cancel(&mut self) -> bool; +} + +/// Implemented by structs that contain timer nodes. +/// +/// Clients of the timer API would usually safely implement this trait by = using +/// the [`crate::impl_has_hr_timer`] macro. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that the implementer has a [`Hr= Timer`] +/// field at the offset specified by `OFFSET` and that all trait methods a= re +/// implemented according to their documentation. +/// +/// [`impl_has_timer`]: crate::impl_has_timer +pub unsafe trait HasHrTimer { + /// Offset of the [`HrTimer`] field within `Self` + const OFFSET: usize; + + /// Return a pointer to the [`HrTimer`] within `Self`. + /// + /// This function does not create any references. + /// + /// # Safety + /// + /// `ptr` must point to a valid struct of type `Self`. + unsafe fn raw_get_timer(ptr: *const Self) -> *const HrTimer { + // SAFETY: By the safety requirement of this trait, the trait + // implementor will have a `HrTimer` field at the specified offset. + unsafe { ptr.cast::().add(Self::OFFSET).cast::>() } + } + + /// Return a pointer to the struct that is embedding the [`HrTimer`] p= ointed + /// to by `ptr`. + /// + /// This function does not create any 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, + { + // SAFETY: By the safety requirement of this function and the `Has= HrTimer` + // trait, the following expression will yield a pointer to the `Se= lf` + // containing the timer addressed by `ptr`. + unsafe { ptr.cast::().sub(Self::OFFSET).cast::() } + } + + /// Get pointer to embedded `bindings::hrtimer` struct. + /// + /// This function does not create any references. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn c_timer_ptr(self_ptr: *const Self) -> *const bindings::hrtim= er { + // SAFETY: `self_ptr` is a valid pointer to a `Self`. + let timer_ptr =3D unsafe { Self::raw_get_timer(self_ptr) }; + + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + unsafe { HrTimer::raw_get(timer_ptr) } + } + + /// Start the timer contained in the `Self` pointed to by `self_ptr`. = If + /// it is already running it is removed and inserted. + /// + /// # Safety + /// + /// - `self_ptr` must point to a valid `Self`. + /// - Caller must ensure that `self` lives until the timer fires or is + /// canceled. + unsafe fn start(self_ptr: *const Self, expires: Ktime) { + // SAFETY: By function safety requirement, `self_ptr`is a valid `S= elf`. + unsafe { + bindings::hrtimer_start_range_ns( + Self::c_timer_ptr(self_ptr).cast_mut(), + expires.to_ns(), + 0, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + } +} + +/// Use to implement the [`HasHrTimer`] trait. +/// +/// See [`module`] documentation for an example. +/// +/// [`module`]: crate::time::hrtimer +#[macro_export] +macro_rules! impl_has_hr_timer { + ( + impl$({$($generics:tt)*})? + HasHrTimer<$timer_type:ty> + for $self:ty + { self.$field:ident } + $($rest:tt)* + ) =3D> { + // SAFETY: This implementation of `raw_get_timer` only compiles if= the + // field has the right type. + unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$= timer_type> for $self { + const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; + + #[inline] + unsafe fn raw_get_timer(ptr: *const Self) -> + *const $crate::time::hrtimer::HrTimer<$timer_type> + { + // SAFETY: The caller promises that the pointer is not dan= gling. + unsafe { + ::core::ptr::addr_of!((*ptr).$field) + } + } + } + } +} --=20 2.47.0 From nobody Sun Feb 8 08:47:47 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 CBCCF2512D2; Mon, 24 Feb 2025 12:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398798; cv=none; b=U19QfjuX+HxecL6g9nnfk3CtT6dZly+MyePSXAjTKO2KFUz11zMnEFdrQJIBFnY4Zx21tB2eCAE5o/DkzpImW9lJlWfO3GwATFfwDulZDPKRRDYK3mW9LXHZXZwXuOXQ5O/9QB4BIM+Q6stgrQjjvn2ZGqo56Xu4E4ZUVS/fRsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398798; c=relaxed/simple; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OhNXgOxgOkv0BjHz6g+obKr8oay3LumRJaQ6ePTf6AlOPN+R1xg3ujSEG8t6iPmArYSLvBAA8t0a9UKI7CW09hacmArHBvp2a0k+hqHY2YLuG2Z/R3rk/zS0yKWl0G7surrIFNjohPaqDBLqbCrCQrC7n1z8jtMyvWesfQ9A1W4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jehlrj6F; 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="Jehlrj6F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C6F1C4CEE6; Mon, 24 Feb 2025 12:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398798; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jehlrj6Fy59ueGbZq184namXTNyWTvz3YHbpUpN7GJn6+lNlZdX1rDphQEorxTeZf koeWXzIUk+0ytmYKTSTyRYkPsEp3CWsOJ8hfAtOpKiqkrZA7kDZdBELAIXQsAAYSRj 96pNizEzIoCLRzbDjPLCfv1QwvqJLg58qG9uTHfa/0k3BqAuyIpvamfb59nc0EWQfS JyLknZvoZv2ShjUmMZkGcJOy7+rQqXpYh4GSmf3pBdEiboC7we1syd45OJ804/XOVd /eBHaldSUYCrcRehy0ZFyNd+lRaaCGJuhAKRCwX3FiLG12fzswrf0yDY6mX8WokJx4 iVSVe8gk0OBbg== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:36 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-2-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1949; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=+Kma+nbFYfjc4yGFhq1umBDIXU4Jat/HmaZ3lk50G20=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAdj+YLySAKo9zDsGZQfQxAHbhFR3dO/o6Pu o+8gKS8KsaJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgHQAKCRDhuBo+eShj dzs7D/9Pl4CTzAU6DWHc1V180GZY0GWKM6oRmN1DbXI3UIwFNqXgcKt0VJ3f3pZFrck+sRrG2aL V4ipXkQsMK0eOyzb7Z9HwKyi6Uy2X0siWoZXoqBiiLR90wfIx42rd8TT1m92LC99veyGH1seE6z 63w7voF0h/3MIs4Kl1Ow1HmBFALjJkPQ/VJVcSOAF1+0Pu1v5zrFeeDdeTw+kJzVk9FE2gniz/j IY3eHqu71jMCo8KZtWF60gtUkt2be3irhPK3EhKLl1q2KNqzLYRzEEJNBGBXghlAY9rwhdPxh7X +3lHR10opiF/X3xLq7iTRLVRqz1HiGYrrFPds0hccPgn176O1tNuZ38RK4l0OOpVQ5Jqunyckbj dmiRFPWMJKZJhu1ccfysIeD9QvE0iMOHJjNrYs3zBNRmgsyhhXUpfHF8Xop3T4A4GAPKEufBNH1 xqu6PAuZraipJowThYSUivuwQ1PvkzOEiXq6uPSoAfsXXb9f3SwSv6vSjvRvZoevY93Q9+cAMWX OO3cA3Zb+G/Oiwdycf2n+APDOBHGYS4qRpMuxYe30y5YZzkznyMheyrxymuIb6jvvC/TWy2/VdR PsVjs88K339iCaAsyS6HAaAftyIPGugPokYoV5q+ilvX7jKVn9eTTCepG9x20uziCgI7CS6iSqR 8uZIFYs2i1iEQjg== 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 08:47:47 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 480A824EF89; Mon, 24 Feb 2025 12:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398787; cv=none; b=BJ3qI+zr1+L9h7axWbh11plFnO/YTpRaQUgK8PCQDzJ7xthd5LKe5BDRs0KN8i6VNau+JApq+m38muQrQernq73Ey1mxyMc6rArRAEOWabUACz8r8wExZC/eOwSFBWfAsEer565uWtYiSisUaSofKsJLgjYyBucoWdhOqm4rIlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398787; c=relaxed/simple; bh=Cz+PPybrgL3Hjwl6SQDfq7mfUBbxBMfLAxxhdBqy5pM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SGnHzmpQX/fAIOShlPvRIKmmAtC37dnuYy5qZbZbiBpp7tdJtDFjWfugeAQJmDMtq35u/771GWlPVCNTgFLlfCUKTLvfECvN221jwatE1LWjprAItBungRnwsp7B9UNg4Mjs9DQApcLHuPfWmvVdCbBRq8NOzvsZHzwPK/GFKqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n1pqX9pT; 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="n1pqX9pT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDA93C4CED6; Mon, 24 Feb 2025 12:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398787; bh=Cz+PPybrgL3Hjwl6SQDfq7mfUBbxBMfLAxxhdBqy5pM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n1pqX9pT/mG0mGatUilT03znChbge1Z0gnTT3jXhRsUlvGKW96Cj14v9czRaeUyVi TkC2DeDZNfepsSOq5wTkRxiLeMOMjW+Tzi3BZScW0EPZLVMttmLaWhgLibe2FZjiSZ szwirEyGQM5zd/x6YlZ1JwFA4D+CI4jRYAQYqpbJEB/D/u7dCjTXwsmgqy64A4O5qp l+djFLwn8FiMKxsZV1Xme+XreHL7w6wyzPf+HsI2Dhs5Emm3gMDlE7fD5I2qianWWE mz7ZG8urVRtQoyC8nPNNA5N27qz78Dc2Q7OT74u/7iZymMFYWgABG1QEz+jRG4jLiw /4nPHmX9EbOJQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:37 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-3-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4286; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Cz+PPybrgL3Hjwl6SQDfq7mfUBbxBMfLAxxhdBqy5pM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAe/84kGb1/9Af6ccIKbZAboSmZkU3vH06A1 dFEhQIc5HmJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgHgAKCRDhuBo+eShj dygVEACqHjNH3F2N3GA11As7RSYy6OuRCmqMz27+i7mQL0jxdgDYm2Oz8ztjMyz7JvBc3YNEGLK t9XIPFLt+WtVqG7ZqXRrMb4ssDAXEjxcshIOTn/Zp2MwKyE9MxUp9PQaD8KFcJoGVdr1r7B8Lyz KAHslxEx6lSZ/t6FlO029DiWy7FnsHmKkmgLFwRwlty5PYmrXkGEhjuSpGACzOxukG8tsU3e9EU 9jgxgPUc6l2toNS+IVoJarB6BkHCMSscjfJEvzplKrfKM+CfzhgVVfSgXVfhAjZhcKwO0e1GZ93 yZOm51aLVlHDChT1ey5KmtbIeIR39Otb9jHKu+zBuv/xlYHa8bLB+tBr6B23BsAX5ALpb0e8CXF kYoDhfjsd9ihOW77AqUoEYllvh8tUXJb3qevbUU/7IZD8wuQSXBbMajbjMj87DaNYpDUtlBxyxs dgx/qrWt70RehG31zmGFYcxf4bKnqecvXhFqfMIB6jXQwks5ANl7h23LCeU0KKHbJq+HPFUPXfA 4dJxmthU7FmFWZkjNlEZQczdKwGy3phqxYef6yF14Y4m9/LBDajZBWxXNF8bVHfCqlGQVOXoFXb ixcjpCvrkMjvCX3cqiXiro5LVFfsnD1Tw+ry+kqPCdj1aQiEVpKLc+OLCzzoqCjDq1TUS1kZmaL FsUNsN2E8ThBsrw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows the use of intrusive `hrtimer` fields in structs that are managed by an `Arc`. Acked-by: Frederic Weisbecker Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 4 +- rust/kernel/time/hrtimer/arc.rs | 94 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index fe20405d8bfe..d08fd7de158d 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -143,7 +143,6 @@ unsafe fn raw_get(ptr: *const Self) -> *mut bindings::h= rtimer { /// # Safety /// /// `self_ptr` must point to a valid `Self`. - #[allow(dead_code)] pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; @@ -345,3 +344,6 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } } } + +mod arc; +pub use arc::ArcHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs new file mode 100644 index 000000000000..5c916489fc13 --- /dev/null +++ b/rust/kernel/time/hrtimer/arc.rs @@ -0,0 +1,94 @@ +// 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>, + Arc: for<'a> RawHrTimerCallback =3D ArcBorrow<'a= , T>>, +{ + 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` points to the `T` that was used to queue the + // timer. This `T` is contained in an `Arc`. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + T::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Sun Feb 8 08:47:47 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 0CC952571B3; Mon, 24 Feb 2025 12:05:41 +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=1740398742; cv=none; b=ZNfRderSspkvDAT7G7NOzFID1E+HQ1n0ZcPK7R+4zMC5EF4jMfTNndSg0BjhKGJyOQlKhSXyebrvR7iAkjwazb1NrwzLrldAYlJ65X5AfO1kBGqj2d2e9cPoStJsUdNNdLJ7GuxIkI/9z6EiwR5yk37cwWl/3qU9lzHvsTVMEjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398742; c=relaxed/simple; bh=r0ULufztfH0jkbivZ6XHvmJt5U9rOvca14UhqyDENSQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ly0VpEZOND/BDVFFHMvGwGZLwpI6VORg8Cq0+a5YDyNdYKZb/cfJBwV006BRbYN3yyTBtTqjCXpO6yXXA0d6hmI64rzPg+3oY+sSDiNdyIqkjkJ6U0WXTvEBSXCRkcSK0bB+cPnt6v7GrimIjdffkHGFPuh2tL9eX1aDw9fIP+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oC6ZLa7G; 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="oC6ZLa7G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA0A5C4CED6; Mon, 24 Feb 2025 12:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398741; bh=r0ULufztfH0jkbivZ6XHvmJt5U9rOvca14UhqyDENSQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oC6ZLa7GGoGY16F7GmHz0aIYKHUIGGmogF6iJ2sEcp7YzFwaxLdbNqMQdbaYqsI1t twBrXYq5CHrwE9XePu572URJa8UxAYxBHzyGdEsxl7XlISFWt5/gcmTZ/dboEPooQ3 oJHb1ajFbcQ5CLPcmXDf1h8682GELdFJm0k1xBB5H/jKgGzvMLv5oJZlhb37lNphEt tamAwHNTyHB7IQgK+y8YMSZIXPCVtC7NZ/VoJ0OgmYAo2mRDrrtzO//jmJp0Ev3Hew fV2gmzIWtM0hd2Kjgps07KkNVrd+38x1/0sW4DYV7hSqS8E78d3EGSO7GusZufW5d4 AFdO7FB7QmaWQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:38 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-4-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2245; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=r0ULufztfH0jkbivZ6XHvmJt5U9rOvca14UhqyDENSQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAfZIY6GwQg1mkzYRtfYxHgkQOI9Q09DDGMC 2uaCQ9wbzuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgHwAKCRDhuBo+eShj d6a3EACOCNej3koLmz/QD0fxGY5xscFd80oYkF3TM+gwTB6/JKNBH+VyBOrh8+HrGGRuI291LGI B181Iw/0ovVIX0BwCOTwv2D/3qku4bWbvmnVQDWhlnQTndZkvsB4SihCp7N6bi01T/WwewmGo2Z Lm9XEQXzaSUQ4cnXIIma+yeD0BAMPb0Ku8QlNcJ9WSYzxWHMXOfS44hXNfAx5dKXMIoFuXu1yoD ksa5yHlHckKRSZEeFEm3GReuHOtFz/Gd+NbKx0mm/PC0HNzlyhI5+4nVIuQ9AeD6TIkOspjwqsQ wYIWWzUJ6X4P8ZDmuGXZkfjf4PTjZEQ7jA0aj1pXoWjVhLOurisYyaVMX7u7XWuXN3+uqtXoCyp uvLpqEhw+GJ2jYJJIPCm9e66uhRoQPzWeUh82nIkOowW35SV1Q86HFv4qv+E3EzexxiB2sNykQi olwvLNc9XC/wfcD53eorkPWR421Si99uxjkka4S701Y01n/UDJTQi07FoeTbY/Zl8Ea7JMrqdwx pfKWjSK673MZ5Mh8zgSrrcqz5x06cGZer991FByuxfA2Ar/z5iCdIMGp1UHQtu/TdK5yFfPjfbw Ns8zaQgPmJRE9CNUAyc1oesK4Ze/8qYEmdPjA5qGU4YsWpjq+6VBHUOaUS+UKs/cbyPQ9XhT3gR o4WDGRCAZBqKAug== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows timer handlers to report that they want a timer to be restarted after the timer handler has finished executing. Also update the `hrtimer` documentation to showcase the new feature. Acked-by: Frederic Weisbecker Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 19 ++++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index d08fd7de158d..a431c8b728ae 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -207,7 +207,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; } @@ -313,6 +313,23 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime)= { } } =20 +/// Restart policy for timers. +pub enum HrTimerRestart { + /// Timer should not be restarted. + NoRestart, + /// Timer should be restarted. + Restart, +} + +impl HrTimerRestart { + fn into_c(self) -> bindings::hrtimer_restart { + match self { + HrTimerRestart::NoRestart =3D> bindings::hrtimer_restart_HRTIM= ER_NORESTART, + HrTimerRestart::Restart =3D> bindings::hrtimer_restart_HRTIMER= _RESTART, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs index 5c916489fc13..7152fa414b37 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -87,8 +87,6 @@ impl RawHrTimerCallback for Arc // timer. This `T` is contained in an `Arc`. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - T::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + T::run(receiver).into_c() } } --=20 2.47.0 From nobody Sun Feb 8 08:47:47 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 9C96C194A44; Mon, 24 Feb 2025 12:05: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=1740398736; cv=none; b=aBBC6LSsgZbj8GlSP6yfbkLLfaU+FlRcJN3dacorfH1OCwv4MWvQwFHOVeWKCcm0GkKimRWwWmwwEmvaNbNfE6kQ5N0DlRkc3PsXZLWwOef96/LXby/TAiFQDmQGmaZxD7kPLbkoGbh9AeSfTxgoXfEAiR4brxkxOSKppAbvDYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398736; c=relaxed/simple; bh=6yblkzK1pz5dd37z4/n6G451i8mJWfMrogL9Rec+Zt4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KChmlu+kE+zwq1a0r2zZdnpnCMKiaUypaq6E7jIJOQ/aRCiVksCL5ZNLJC+v1Niw9JR2WQKp0nFdOhd0dq0q5afAL+Kv2OFBMHJKH7woBATRnUKeQ04TpcE1V1/gZNuWpe3YnNjVTdvxOqBS944pcRyHKbnMrAAV1QQWWLwpHbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wofc7sKN; 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="Wofc7sKN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC96BC4CED6; Mon, 24 Feb 2025 12:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398736; bh=6yblkzK1pz5dd37z4/n6G451i8mJWfMrogL9Rec+Zt4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Wofc7sKNo4JZJHjtKMojNqC59eA2mEzHwuO9BS6r6Ed6A4xeT7Hl9tPOuMIpdQJnL WUhXYxiKiw1Ozgrs2hNnTQWC//0lq3oppl6bv5slxMAka2FlWS47YpKwfj0TiJ7Aag wPLFlYngdB2ca9JoiA7Tr9Bi2dV/PnobPWlOgEMCHjcY6OKHL/OrQPkNj0oLd8e3IG tw0YbXY4eF2GqS85JmXE0p1KTH7eS5jcO0i6VPLyKysmkcoZiQlmAkH2PLN0EuvUso 9XNGmGx95BGwQioDT6AmHq09Q25YqpSR7AUmNEhwx6gIooD5E2PXdJSAVWLG18YNn4 Olgir54j2iYXQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:39 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-5-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2172; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=6yblkzK1pz5dd37z4/n6G451i8mJWfMrogL9Rec+Zt4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAg0WqlV8YFGx4153xbg6pvXPxIbjxwcjFW2 +2bMVzYTheJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgIAAKCRDhuBo+eShj d4jmEACgoSWncK3Qf0rzl0Z3MjXoSzuL4+FEp6J9Psz4amLCPpp8wmKX0D92LyphsBmK8N1Cpul quW49w95B1X1VUNceOzdyd0WH072UIzGeUcN1ieHXbw7faP13oowr05cEgIlMcdFYMMF65SHS0D DeGOCCn97B68r+2V4I2GDz6RCgsMwfIo69Qott9Gm9Aq4IkaXkkRn1soEgp7WIpjSEWogB9SVLT idogELUQOxHtedKKogkvjXGHDtsoBbyOsbGjYnHb+8Vf6FEiT+3WBYf+4Kt5jHlcdKooFylS0LJ tJau7Vo7Kx8sA/udlt+L92Ta8CUPApSqS6cZh1JHmwHE6yX0HUXP3tSNDl3VCyyXq96V/W78HMB 6VdFhosRB+mg2a0+sxLtQ0EckC1IlVC1t0FoxpXIxBPSCb3WI6aR0RIYfdw4P+O8FEPSPxy8gXe 1sDP8DLtRC+G8QHIodzgZ9xn7XhN79PsJXiArfPR+kEsm21/xeUMUcANSh7f6U0sanuA6k4Lt+7 1wbxAYOdZca97OgiqK1idz6S7axmKG118LirtMzEI0QM6VWYQo5CJ7tJFls/VW+99i84CY7b2z5 LTsXH79dQQLBn7wSbeNUa8rjNeDnqgjGM0p/YcTE7L/4Ilrhg2iOoznEc0WdmOp4oB3CH54XEO2 fqdLmULsIjSPh9g== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- 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 a431c8b728ae..2cb40b011673 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -181,6 +181,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 08:47:47 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 54D552192E9; Mon, 24 Feb 2025 12:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398757; cv=none; b=TOk9ZD+LlrtabfMcx6fpZTI9y2R4E0lvrtVPuGqzXduGSIZwyesI4RcYnZbPzYfCjWaEiooyQjO2lfcfFOA7pykivEUUpfEyUOmEOL08yMPYInxVXGHV1t5jYMDybUwkCUDtMeo3Ml04wWtlxMYTQVuZbtnDNiWxrbT+sKVcM0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398757; c=relaxed/simple; bh=axnRrBYF0OzH4Xe3HtChGMprmiCY28WJpn50yBixF8Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uQTSeMC3fVGBVbz5/TGwEGqTgWyxCrfsO7dwGK5NZ+ge74ceOqq5VMY0KMA+VpkRS9OHxyxSWMfCCCx4wMjH3fKYRBT/wZL8iwUkk4UgTJ7LW2EljfJtXq4jh1FokmN+cpgcrYAfncav+xWf6qopBMscMHSb0OjiU3d/2yll3Dw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nz86b+8F; 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="Nz86b+8F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A20C4CEE8; Mon, 24 Feb 2025 12:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398757; bh=axnRrBYF0OzH4Xe3HtChGMprmiCY28WJpn50yBixF8Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Nz86b+8FudUOzgHQsh6b7LKg+gIllBoqeLzYyzNZhhIKsOuXh3NkQ7MFzxfHLL2mL In4yog2RNOy/KTVX2gaBxfWIJ7UDrQYxAWY32jFBKmRhJMPJU+9M6p6hNI7fPBdsXb JAGTiEvGu3xae0Iy9imHxA9NX5JRQhC25l5C6Qjg1j0HMBtGyizSjOh8Q6GOFpMdGd e5faG7K/8pdD6JJPimWhqLkI42ftiJHw12dJd9ppgiNiG21kkcNytfn9TgN8MH6cdK qAaUGmA1z6i8v7DOeXf05M05K9ykovmNkQeQhVGdt2OPLr3oOQbQX7iC0K6qGU93UC 4ECzmiTAwrfaw== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:40 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-6-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2142; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=axnRrBYF0OzH4Xe3HtChGMprmiCY28WJpn50yBixF8Q=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAh4GeSYqfarAY5Is4mpXvIwk8iIYJmmCL7y wmEZfFvEamJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgIQAKCRDhuBo+eShj d6ntEACyVIPeMBea1LuWbKmj470DtBYDPZn3+rL1M/QrQPAWm/o5G7v3EJabAgDR2Td5jtj1OT2 lLvwY7qYUQ9Mozel0uwUCnMNHWusAIa0INL2Lu57jGeXZkNftfiXQSr7mDK/0WeW3WnmwfObHaK LWcfBId057SuOEQfR1qpBdOJa2+qXiEFa0RthidzX5E/CRlLMJx34KSS0MJSrvHa27E2eOFba44 HU0hY/s2XLUCH6bc7NRKMQHaIFU+xb7ltc62PTuqV656K4H050LXxzJUTI09dwL3oKoKFO5J1I2 Iem0D1uqXkPUQfut6bmReAO2RZ1421HDjKBXbaorsOQiJBEaFRmpC9zu5jXI/KfQUWoVuT0MvAU DvwQRYLdFTbN5POZUnLEe3ys8UkSkNkb9ov497G0rG0Od42AfXWko84rScomF0V4aP1THWENl4H dmDjSlscyD8Rvf2U2AtozmfeYBu6V+yb+5lhPzpXCr1BVqG5hkPh6yHEYD6/IrpP33QUWV+yVJ6 kns6R9ibcHzkXglAdla3m5Es3vagIvnn1j1XxEp45z05AdbOCMGF9bOVecfh+lGVr7oA00+JBDQ qo+ZLGmREdbRW0wPCpw2zBuoSNrs5depsCxurJiuKaRCSARq+8h2Fq9lKMmo56H7IG/qq9R27/v 2VdMn5BkFl300zA== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- 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 2cb40b011673..64b769ad59cc 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -212,6 +212,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 08:47:47 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 8F8812571A0; Mon, 24 Feb 2025 12:05:31 +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=1740398731; cv=none; b=ltd+dH2+EqGAv2hVveuzO2PaZNgt4ZZTnNOhoB/LwhbJOrMtERndDwfIhJs0gBmYfGm+cmOFDNyRkg8c9G2hZR3vixuib/gnW44WREWLEXRNhgKDymORHnfSwA8lDHYDdEQOgysGRuojeTO8IPmOai1CHil5ByxvOAGtnpvo7ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398731; c=relaxed/simple; bh=+j5W9iNg5qA4s2ao7e3w2gC8NaVgZMD/chrZEXGXXxQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xn+/ras7SSn8ApjNf847MX/ciHmIwY4UmowfAMusc3EMKyoJ0m2SIWGcEbDRkYFP3fdrrxO22NDsJyE5GwYeiLiTOYa591dj4KfjbHe0bgQV9dRvc19SlSCbLaNax1eYZYlR9UiLGVNN6lGwr5k/XZOSNhXUUcsq7Jk1WJ8vvk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MnA9Wtsi; 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="MnA9Wtsi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC83BC4CED6; Mon, 24 Feb 2025 12:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398731; bh=+j5W9iNg5qA4s2ao7e3w2gC8NaVgZMD/chrZEXGXXxQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MnA9Wtsi04Oovc2JkfVw1wa3nsdO3U+h3k8gS0/dkzUuxXibR9HA4GjxYZ19GM3CW PU2xHLp0kOfcDcbIKc47SB3dWRBlEOZeXip+QVaBGuHFIYBQkQe2L9GvhkTeFMUvze EzX7/8HtpUZ5hnUVC1v7or+AHb0Vhd5ye42XbEGMv7SfgMKNuPDza6O0irhE9w3onz Imi1iDKwxZ/gglQwiU+u7Cl1h+CC/T1OhP2gDdSbacEB8eqaywm+kLwfWywmx9GdvZ kwDVkprmHvbUrxljmBeUaPECbsJbM7sufD63Yv0MLVF+eES3wWNVgq3w3uejONLIg6 e41N8ef/ncClA== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:41 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-7-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4212; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=+j5W9iNg5qA4s2ao7e3w2gC8NaVgZMD/chrZEXGXXxQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAis0fH/72lIovOHz/fg8NTAbiLn84YI7qON 7mBf47d23mJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgIgAKCRDhuBo+eShj dzcID/wNJ+tA+eRLsh4tDs7Ep0qdqpxvbkvq4Ji+Hts+9TPFkiuNiTLkfeOXJA3Xh023xisTE6u Mbi19Ayp4B66zxCJwdD9CZpdbAIg/+uUTWUaeT0vIGae5+WTAXZ2sVX1QF7YF8GoCNRJu3t+yGm T3c1MDCLlfrFa1K2zIZkHqjJyXkuFO6qeMa6FvFmIXH6pOa3jI+HgIvikJkhMX1JhY/8RRh88LH Ih5fiZtzyYHaL5vsA3fraeDCXkHUE4mzMwN4B59Up6BTHWWFaljTvBMFecUAJ09kZ6tnvnmkomh Sart3WAdBxQIgs7U4YnDQtQN90jjg0LX0UC+mWuhTYQP9bqoR/ZbALgdD4k5d1g7Q+a2TYJC5Jf YN4+cTNHjuHmrcOFt4LvRGev5Ru/0UWIjlce0mXRXvGF7pIgo1ysBWGtwh7Cx2fq7Y/sXLXrj1r ZDiBqUWMFu+S8VDRiksUzopVgcTnkZCBq1Y6x5tmi4Q1IVwEjQwN7SqYpl7LO7jnw/Fi8tK3FSK piH8TvWhShtvhA39xzSII3SgdssfONNJpBab1G259MRJuxyWHehOi89WuoXsTcVaVu8qqp5zFbN e8KJNcw2NWtS/V00blwUDvTxhZHKFaRDcVGy0fpzjasB8j8GDbOLiNwc8Zz5d52xRAgn+p2bZD4 taFAhqNzD0x7AlQ== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/pin.rs | 99 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 101 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 64b769ad59cc..52a3dd1c3984 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -428,3 +428,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> =20 mod arc; pub use arc::ArcHrTimerHandle; +mod pin; +pub use pin::PinHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs new file mode 100644 index 000000000000..6c9f2190f8e1 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin.rs @@ -0,0 +1,99 @@ +// 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>, + Pin<&'a T>: RawHrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: + // - As we derive `self_ptr` from a reference above, it must 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`. + 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 08:47:47 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 69D93248879; Mon, 24 Feb 2025 12:06:22 +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=1740398782; cv=none; b=EhykUhQvkAKzuXArPRJlM+WhWDBYN4ZrOUU6k90dCvmML+r9cNtJdyGibOhyCJnCPac6zu9tnH9FFMQKOaG+Pwcesaqp7eAh7GA/x70OoxzF3oC4RvjlIUc1uf/MhkMVpfDRHukUMXSYY/sl5fImyZ1uaZV0+sl2WTaQ2wxUsRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398782; c=relaxed/simple; bh=l/WE/Iyt5IAfurnrT002wpnh8ahQZE+ejk/Q/RlMt6I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IxZ01htkZ3+EcUr4bfGIGbT10968/KX1QM3NfGIo3tXlTvlpqNo4jnXdBjuN1d8z5biMQM3ij7wbU9F0b1Xm6YbqlKfAo1RkDGR4pOQ+5KzMFteuhLG5+K0Dx4Y2eL81U0mm/OIcnr3bwWvcpLuFIrWh1GWaJ68dRsnAb+pyXlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B0y/+s5S; 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="B0y/+s5S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8055C4CEEC; Mon, 24 Feb 2025 12:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398782; bh=l/WE/Iyt5IAfurnrT002wpnh8ahQZE+ejk/Q/RlMt6I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B0y/+s5SPe5pWrYPKdhk/v+Ph52JXnqurNOEx1JJtsKRBt/2kDSSojN1Rg+wRoMwT t4Bsq9054Nf3l96xuwwp91oDn6APRQ9m1eo/f53RIeNvBzM85zTp+zQln479RK0IG0 Okn9c7CueCCfS/cE+rAGTBtpJdIc1e95Gedeg01LaOJCB9fVnKs/lKlyt8BifywnhF 756VLOjNuIugYul2aG3BNmhaaeZLPXtVHUWbgNqaVx9n+hJ0a9YOp3q3AoqUMO/3xE kiWO/o1wVF7jnBE8VxRbD8u3WXUJTYJAf3Z0MhdtqBfaPpusHMJgTBExXO2cwfQXAa AwMDA9Y2d6NYQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:42 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-8-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4462; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=l/WE/Iyt5IAfurnrT002wpnh8ahQZE+ejk/Q/RlMt6I=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAjmeNKjyJa36N7rTzlZdrLwwpDVBGIaBQch xCGBItaPaCJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgIwAKCRDhuBo+eShj d5f0D/4zOL9VmopzOXR5gnUKJoAo8ZBhlCNY2HXwpt/ay47V6RaSq4RM4A9LBogTpj9hWWTAJJU bYa3tQZpOpI/oZLVuLNtRHeguAb2/TyCsbYgB0SpCuF48j3tdgwx8OmL/Ff/0jCBXRHsCRVuKkF hrWd3ovIh72D9V8F8uwLWENgzBWj/bxJ+eaGw3tBqCqyoB/qf5tMMQE9zBEuhm7STA3cUjLST1Y Fem0rCvUv74xb/YlQ14iO0+aCcBYPpqHt3aFCaqcZggFMQEZVS84pzemRp/BPNggZoOFt+Afy8J A9+Ux0GjXCy/ej7VlUdRGLUJ+p1KcP+nNFUy7OfadOXBEQfTjsby27831n4vPMQcJOmNFlfIwTH aVMu3iBgs8GyrgM8/zQ22FbMMi+m63oWo0GD6jnt8wYSbrbb1crk6NIP7YpNWwdh5kxQluDk1Ru iKBTOIla+YVWnuB2molUI2oW7AaUJo1EjsTi1b6p++FBke7jjTM+OxbagZhivnr0eGykin7tsXA qrnzsawLveGpByZjCxD1wwHJsD9HZazlPu8xgW2G7Zxgin/BDvqa5UUfxvJnqRY6lyO126CICDs QIp3+5dpNL+9nyaYwNl5mSYgID9gad5DEE7Bb1Jwad38tdtlpAITyRjpc1VqHa7+uSFcpesuvbm NfO1W9xuXdaVm5Q== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 2 + rust/kernel/time/hrtimer/pin_mut.rs | 101 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 103 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 52a3dd1c3984..07b19699d4e8 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -430,3 +430,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> pub use arc::ArcHrTimerHandle; mod pin; pub use pin::PinHrTimerHandle; +mod pin_mut; +pub use pin_mut::PinMutHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs new file mode 100644 index 000000000000..4f4a9e9602d8 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::RawHrTimerCallback; +use super::UnsafeHrTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the tim= er might +/// be running. +pub struct PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + pub(crate) inner: Pin<&'a mut T>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, T> HrTimerHandle for PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + // SAFETY: We are not moving out of `self` or handing out mutable + // references to `self`. + let self_ptr =3D unsafe { self.inner.as_mut().get_unchecked_mut() = as *mut T }; + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `HrTimer`. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, T> Drop for PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a +// `PinMutHrTimerHandle`, so `Self` will outlive the handle. +unsafe impl<'a, T> UnsafeHrTimerPointer for Pin<&'a mut T> +where + T: Send + Sync, + T: HasHrTimer, + T: HrTimerCallback =3D Self>, + Pin<&'a mut T>: RawHrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinMutHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: + // - As we derive `self_ptr` from a reference above, it must poin= t to a + // valid `T`. + // - We keep `self` alive by wrapping it in a handle below. + unsafe { T::start(self_ptr, expires) }; + + PinMutHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + 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`. + 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 08:47:47 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 5A8D32571AF; Mon, 24 Feb 2025 12:05:51 +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=1740398752; cv=none; b=TYdLay5bXNVa+2Ou8eG0EBL4H048WY8k/e8SWsO7FkKwfj/vgQFrOnUUc+2ULSd+QDNX0BLmQLS24tfK9IC34XTiFYMAuRrTtlphEQuItqdno8Rbi7/+yjjAaRLhjBLejTLHUcKYgFQzsDg3WxPyLQ3jWmjbyB729XhZJzAroBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398752; c=relaxed/simple; bh=KyRv9U8051weSTZd8kIi5Ms6sAzIrGz2/6k73qD/frk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PomKGbuGMVR/5mn4n3h60+R2pZjlPoFvCgeQ3OGR6xwicEAHr8MbCaQYgWw7FfFUDD4L728dka8Un8bftSRF5Sb6tTPJkPGjkzky1oiCGrmJVAqVIscjDpJQxdyovzOUpK1QTSaorYpj79V2TlRcy04bH4H4FvR69ZMIiyNGgGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ssYWvRPD; 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="ssYWvRPD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52782C4CEE6; Mon, 24 Feb 2025 12:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398751; bh=KyRv9U8051weSTZd8kIi5Ms6sAzIrGz2/6k73qD/frk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ssYWvRPDbY2189UpnKSqy2Y9jwstzajC7ELmwVXefkKNG3aP1C7csCTqiOgKn+nIC fFmSwAd++NqhxVtkss7FSxkMchO7xS0yRql8h/wn47/5oCnCXbf2svgsqzlkpKZlCE VBvijNHSipxWT6uZJrFA1eSv9B9mxId0mDTeRqvXWakN3F/RBdsnzpt/efTg/2rIZP MKZNl9A53pn43BaXGFLv43W5LSCa0iqTO54wppId0iOh9BuA0xgbR7WQVieOb3pio0 Oy9Bn9MfEEY6yDFNTM/5YlZ/YarDjlZcTWmViEUpzwM2fs2zqA8otNZQOdiFDe0tK6 EI43k7IrXXUIQ== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:43 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-9-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1078; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=KyRv9U8051weSTZd8kIi5Ms6sAzIrGz2/6k73qD/frk=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAkQWtjGodQLW4tALY0jSA9lpLHTC5fOUlpG 360ZMN5d/iJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgJAAKCRDhuBo+eShj d71jEACrVO9TMxmnAzqxlZrqLpnLqpP2/pPRzcrGxh3mwLMJ/Pz7+Hgq9rk8bmVD5tRUeVqMNxd UN9K3I2XCSUs2CztGW4C1IbCjrvvNM7JXteaUj3/1+78YlhmRU+dEzDpiahLpx2wXlCTw7LZDfO Dv+tV6X+8hUDG87vB1K26DpE3efB+cQ4kSXJOs0dp5iywteG5dEl/cZysdlxBGDmyId++uPTW3K qBoer+QT+zk4fg1ajsSB2ZldX2ND0wcvlti1k+0yS9gIpZroAK+PdsDpLN119C63AsBmKxuSXzH SRTWJmfqxpAxgtqa8jyD5efOZPSqROJPugBNgqN4aoY+OmisiyXrW81nV7isj4tBJGGJi6W3HGT 9/BxjShNvHrlgz/XcM2cjjvr9x6NowPLQWRAfceOs7h0LDdXfxY+yWv103bmkQ4NphtoOmTbbJT XYAQORmCWnGE2x+eEsBP3Kecya0p0ISaSWjwrfiK+Y0l7qIXBOceaOVbpeT2kCoaQ2gHrUIzApt yq2eMBFlhUCQNpAHduHpVdHTKn/3jHw5sZZ8VU4SYugneKGyWhSMOHEkhyzJ13FTmoehfiuwtHp Wsc2AVciSJQ3XJ0jVwaPjCVmgoLJccOj5k8Vy0ZuAAp0p8pisHz8SRXvhJOV9rRCvcxPFvqpVzU GCzRoIOC8fSTbhw== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- 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 08:47:47 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 0A3D821A424; Mon, 24 Feb 2025 12:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398793; cv=none; b=tLS1+o2cuCBekh91aPE6eewljWt1rrCGrntSwdvISqx9EofamVbwR6lfskhlA1dUG/xotW2LA9t8M4liZG3cbN35MUIm6kFkSYDtmUHWJldYUdvv30rQmrnuQt+3K2h6B7iGTCO2BqwpTLcLVo7ACLIlP68TlurMM9EejJzckIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398793; c=relaxed/simple; bh=llc7zOHamY6xKtss+EvtekopfzOfsV9jJqRh+gsSyCc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QUhPYhdQu/zBhP7cIt0y3G7LVHQwuzB1rkGVgOPQ+Je2U3AoQVmxMjCJ1hQxJd65psC1oDqIU9tE0WawlWBpArP9TPt035pPm3ma37wAWv2v7mvexBZqvuwls4bmjZt/F6brntLOJGGX9gvWMpl+DvK/8+ujjAqgFwbqYBPG4B8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M3Xtwy7w; 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="M3Xtwy7w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04F20C4CED6; Mon, 24 Feb 2025 12:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398792; bh=llc7zOHamY6xKtss+EvtekopfzOfsV9jJqRh+gsSyCc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=M3Xtwy7wrQqxTskfUqWJbgbhMpDej0IyCGkEADsvaSClgbwk5tc7bd1geqS9DZglz aWYHilsY8/ZiomRmsA+al1tJK6f9x9ZIQA7Eewm6SWT+BCQinxeLevW/mqeBMnezm4 lkK9fCWt+/1CRqQcIUw4HNXfw+xPu2WOlpWy13GUqneLpOA088qP8WXIP0voYBE53W 53G4s2/7gcqkkGJdHlfzcpYcFv9jnSv3PS5pCCpfgqmK5IG6/kc56IBp4cCcTPTG51 PFc4FlGrSyKK3y3OF82EvntkQ9YBifHJwvseRV/M5Trpk5kqSJDTxTkbutwnjiJVUl HP0CL90d5V9fA== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:44 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-10-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4707; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=llc7zOHamY6xKtss+EvtekopfzOfsV9jJqRh+gsSyCc=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAkT3Xg5K0oFkbT0YXJzRRIjym+i0t1snfzB fx01Ffgkc6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgJAAKCRDhuBo+eShj d5uGD/9iJ3OVwKM9qb66nHejnrfq8VDMUgnvy4LBF7hJFXzEaDHJBwT0XjUBpOgkDT+Z05iHsi/ uAdv21julj35bz2R4ofmpIZ7W6ThaLBTPMVVHU2hQnBAtfktAXpjTkzWxHi/X29+TlBGFveYxPI u1GfPJdN8FzL7639SM3eG/9dGqttcpFEI4oFORaIxfrD3tNLvqQkYe7Dxo0/BIGgnkL+YwY3Sz8 1rjaJxo8rscCNG8aepg4eyczNg6PDP7do7nBPXElhdJusL2wndvyNAp5LNQ7K315iGcsuajyDw8 aBkAKNfFqTSPeV8kzL6qe/MWxjwXeGV1M3h049MrJISx1fJCFy89wD5TBOP6ofmlEUa08JYtYkp F64349U/2nQhK1sBkv/qXncR7/3DgJQOOYvDFoq5tp40tXshRCGUX5eCaUI3wWsCzPoiFUdqmNd vYzC7ze3cXjpfwECqpewg2r9aditzpuzgaQfBC5PpU7H9KZuJQCadKrXYfzWf4rxR+7h6AHb0go VBaD7desB+oscbJxkgERCwUD1JvoQBerJNDylBLBIUjoIsmeu6t7zJMPlSW/Uund8snDWSVkF5D zT4RxG7TaFkN/YyFCsL5XbzMMb9pr/LKX3JNcCTyVYcfeywrfOOXF8yJtFFQd3d8uZFOoUjtRP3 8+MShHfydOR7zKQ== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 3 ++ rust/kernel/time/hrtimer/tbox.rs | 109 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 112 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 07b19699d4e8..fc4625ac2009 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -432,3 +432,6 @@ unsafe fn raw_get_timer(ptr: *const Self) -> pub use pin::PinHrTimerHandle; mod pin_mut; pub use pin_mut::PinMutHrTimerHandle; +// `box` is a reserved keyword, so prefix with `t` for timer +mod tbox; +pub use tbox::BoxHrTimerHandle; diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs new file mode 100644 index 000000000000..a3b2ed849050 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::HrTimerPointer; +use super::RawHrTimerCallback; +use crate::prelude::*; +use crate::time::Ktime; +use core::mem::ManuallyDrop; +use core::ptr::NonNull; + +/// A handle for a [`Box>`] returned by a call to +/// [`HrTimerPointer::start`]. +pub struct BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: 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: `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>>, + Pin>: for<'a> RawHrTimerCallback =3D Pin<= &'a T>>, + 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) }; + + 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 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: We called `Box::into_raw` when we queued the timer. + let tbox =3D ManuallyDrop::new(Box::into_pin(unsafe { Box:::= :from_raw(data_ptr) })); + + T::run(tbox.as_ref()).into_c() + } +} --=20 2.47.0 From nobody Sun Feb 8 08:47:47 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 273712571AF; Mon, 24 Feb 2025 12:05: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=1740398747; cv=none; b=WA8yGGjtgcweJ3zP3hZc8VAu3sx62lziIlKM5ris9YXAXy7tz2Xt8tTAzojBLI55nPMsLI21Qpz35tDQ5N6D8OvSdw5inpejFfrTOgofJjQdkRjqVQiII6X7Z/zbnIxmZCpGCfj0ihnoe3w/AK1RPTqHlpl1Eb2PoKvEu9rm5B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398747; c=relaxed/simple; bh=68obgfc+2OHQofSGZkb2YIGN660KlZzCALimTCdZfds=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CVu0lHYRw/Pw7dN5TAlP6gXssLLdjYGtbm2HGXbqyHrw4y/dNLB0wfuemfMS+kLK2txw57P9uiQoTRzezYwG7fe6omwS3lsK7HRj4Z5WyLDCYplaMtHxHHO6sXkOmVW05hlvvaurJMMvt/E9YNfzFrIfArm9bMloAj6gG5YlNSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uiTxdRmQ; 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="uiTxdRmQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 217BDC4CEE9; Mon, 24 Feb 2025 12:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398746; bh=68obgfc+2OHQofSGZkb2YIGN660KlZzCALimTCdZfds=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uiTxdRmQ8vdu73D34G8fIsJqggJEkx1JHF7zMBfn5tTB6Tt/l81Q23ahb98bJk0VM DGkdGmHns3mIlZyTf0EfVI66kFq9teu5NVT6JxADltrARvOAzjFzCvgUY+/lwyJjhW QKEbImCg+hspaXEci+aU5O2BE6EiUzaXggj1s5FV49x9X+Szm2Y1pBWm/eJ4qoENfJ K4yI3nO3Qbgz1qnU+JLa1AW2PDWP5T2NJxlSi0VU4kqYkjR6sQuWJpiknSg1HqXxof Vc7ZXn8n20V1EhMTD/zl5hPVZkxhZP6/Hg5+h9MjAvWR5RHEH4sDxFyY71AJqB4eZT A2j63J2qL1Lpw== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:45 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-11-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5503; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=68obgfc+2OHQofSGZkb2YIGN660KlZzCALimTCdZfds=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAmWt1scoialav2+XM5RBCikrGcnUkVBDL5q 1Dm8Kz2g5iJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgJgAKCRDhuBo+eShj d7huD/9ZZ57dCQXMPwj8JB5Gp69+C6dHAkvJexaKFyXMSOBoQG/3sTkaVWKHGRvS4QbCjsA1ttk 0q2wpdWGIs/1mu3WNnzEm/Q4XIWz/pOkQzfr5LFmUFgrC6iiL/OM+ePrjo4MWYXPv6ByMbDoII7 z+5ghUqonQUsHunzOHhWQJOWibSoUW8kPEBLIUKIhJVs2cRLiNp+2c3AhbfASlGAFXB1cfPynP7 M08kr12vUoMjzeZmYHmkUbumQONspKGnZXf87H4idkf/XWOa39BB9uFk0EXR2NMhW3ErpV65cYm tmUJg0pLjjiDEteWiWHZQKAEJd3oQ14Vn2wlcPBc0Vo98tF4X0midrKuuAvdIwI3wxWuKwu989G MZvxbiuJTnrQL0QyO4JqXWo1ttpMJ/c8TrUc1HJT2xc5zS03E4RL/AtLsa888WF6gVwaIZvVF5H hJba4YH0AElFjMIda056ej+KI2/gNaJBikF1rjTWfkG54mSmAdqXXuxtMsfsmWjJOLkQU7r8rUJ nICCxUoXEAHd0TPqDI/9LfUDGmlhtA1JyWs+o5txJrzRem/85oaMvlomc2+4LTgB31mglZk/W7R U1W+1LHaPtJMTMkB9PvS5Ob7QWR5WVx4k42R5bOMAiQMcOT5A2vXORiONCjaYwBX66IdNBdU/Q6 myV3aQ/v3R5K7Fw== 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 Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 80 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index fc4625ac2009..160df73a2d44 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -79,6 +79,7 @@ pub struct HrTimer { #[pin] timer: Opaque, + mode: HrTimerMode, _t: PhantomData, } =20 @@ -92,7 +93,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, { @@ -107,10 +108,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, }) } @@ -371,7 +373,7 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) { Self::c_timer_ptr(self_ptr).cast_mut(), expires.to_ns(), 0, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + (*Self::raw_get_timer(self_ptr)).mode.into_c(), ); } } @@ -394,6 +396,78 @@ fn into_c(self) -> bindings::hrtimer_restart { } } =20 +/// Operational mode of [`HrTimer`]. +#[derive(Clone, Copy)] +pub enum HrTimerMode { + /// Timer expires at the given expiration time. + Absolute, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + Relative, + /// Timer does not move between CPU cores. + Pinned, + /// Timer handler is executed in soft irq context. + Soft, + /// Timer handler is executed in hard irq context. + Hard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + AbsolutePinned, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + RelativePinned, + /// Timer expires at the given expiration time. + /// Timer handler is executed in soft irq context. + AbsoluteSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in soft irq context. + RelativeSoft, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + AbsolutePinnedSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + RelativePinnedSoft, + /// Timer expires at the given expiration time. + /// Timer handler is executed in hard irq context. + AbsoluteHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in hard irq context. + RelativeHard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + AbsolutePinnedHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + RelativePinnedHard, +} + +impl 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 08:47:47 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 A254FEEB5; Mon, 24 Feb 2025 12:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398767; cv=none; b=AhCHUkUmMgP2C8d3OD77Of3KRcsNt+JbMpxYTAFzzlKlJfVK68lSxXF5R6UUeKDkywtfuXXMAM2K9ofHgIxXn8LtA6gCZiTXGDgVTulAMaiE9rtwuX3aiZwQuVYmkZLrz5mu0M+HWJd6+3775igiU74oNzQx3wAf3LpQWop1m8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398767; c=relaxed/simple; bh=DuU3evB+1LgFZLESTxh1PCvMJv87DbYXfEPsG7tHlYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k8kZx8OG23pESkOBqFIKnTPf13je73rZOj25ZgoYbA8kUw7ByVvEz3u6/ObVaVk2DvDFabSl//Ne3/eanywBMGF6jhyn70Lo12SGn6WwtCDG/V+KQ1iqIpvSlA7um4VdsAHJEQLiBMXhfeY7snRb28jT4f5Jja51sn0m5b7u0gI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q+y5KfLQ; 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="q+y5KfLQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3C46C4CEED; Mon, 24 Feb 2025 12:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398767; bh=DuU3evB+1LgFZLESTxh1PCvMJv87DbYXfEPsG7tHlYM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q+y5KfLQbE29GkzRAHkNCqnV3UHl5zPUNJZMTWNd+ArvI7CoutxD59m6Cay+aOcnl 0+Aa7Pk0f9Qy921VOZNjqawqmd5sXLD3Cu8QHEzSlvyQQndn2peH2LttLCJQkDfSrA 33DueDQQpFbdWI2kqdfttquybWdqXrTDL6ytZgEHeLD9Roj7ndUIyHxhImlvbMpHC+ oP/hxBnhb2TyHNGoWISuxYaaK2ozICbPrHODWTArNuXWM3dER6yv1K3dxSyYZ2ufo9 Q6dilPSIGuvcwcTrHLsCO2xrrfdxMNGxWtl936WLi5dZMPBOjqoOo9evtL0oC3TiWk p3MJ1kk3YHvQg== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:46 +0100 Subject: [PATCH v9 12/13] rust: hrtimer: add clocksource selection through `ClockSource` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250224-hrtimer-v3-v6-12-rc2-v9-12-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4207; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=DuU3evB+1LgFZLESTxh1PCvMJv87DbYXfEPsG7tHlYM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAm1O6CWWrm8R3i5ADwYFUlMwUMBoI623Lcr qvSRb+NA4aJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgJgAKCRDhuBo+eShj dzT5D/4n1CJIE9B6+23HwQi5XXPk9H5DOlzJOy3d1uMdSHNnF6fSRuLfj/WJPoDKA122t7JzQb6 VbxDLPpa8QWEJafd464zVUVvO0dL/P1e99S0+0MLeWryeoRD7Cd8rImx/5le4GOIknW5ru724L3 zbM5XKCqROZJOuJEdy6TqiBBSfOJxnKUbHwkYOi8az2BP+nqI85XYmoocz95FBq3UlVX+4Kairb Eh1kKe5H7cYAgRDYQaJ14q+OuUmYn90m6zQqrrlOrhFhNusAafAQmz5QHU2sDn/kHCJnY/nqoKx DPuw0RsgNHjU8ks3zACL7CHaG6U3PG5eabuzxd+I8t3TH4DhTnkaUYkVMzpOhnwOcamkTDhqrwi pfIt89Et3ZfWA1zPLsm/TYGJeD4xq0ocG+OckX8GbKlGab+2GzYFnl1NpVc/BRn3QJWZoi+sjZD ovWk5YA1ytGj63sJWOS+qqjo7F2E48AKtAfz/H4q/2Khz+usq1l6R9Auu3VFpre14idhurAJxTY mRbiivlO3GfxzikgCR/gjhnRLyFgZtjt3qzmpcueiwwJMSM8EgCT96LL2orYtRjc3IZ5UrWf+9g NTLXaHTNIFQ7R4dQdlNywNum4C4fQMh5u12z404YrqgQ5mO5ifbG8OlQ1FAg6+p11IJ8kBq6vlb i1e1OOpuwBrVkUw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selecting a clock source for timers by passing a `ClockSource` variant to `HrTimer::new`. Acked-by: Frederic Weisbecker Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- rust/kernel/time/hrtimer.rs | 59 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 160df73a2d44..77b8748ec29f 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -93,7 +93,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new(mode: HrTimerMode) -> impl PinInit + pub fn new(mode: HrTimerMode, clock: ClockSource) -> impl PinInit where T: HrTimerCallback, { @@ -107,7 +107,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(), ); } @@ -468,6 +468,61 @@ fn into_c(self) -> bindings::hrtimer_mode { } } =20 +/// The clock source to use for a [`HrTimer`]. +pub enum ClockSource { + /// A settable system-wide clock that measures real (i.e., wall-clock)= time. + /// + /// Setting this clock requires appropriate privileges. This clock is + /// affected by discontinuous jumps in the system time (e.g., if the s= ystem + /// administrator manually changes the clock), and by frequency adjust= ments + /// performed by NTP and similar applications via adjtime(3), adjtimex= (2), + /// clock_adjtime(2), and ntp_adjtime(3). This clock normally counts t= he + /// number of seconds since 1970-01-01 00:00:00 Coordinated Universal = Time + /// (UTC) except that it ignores leap seconds; near a leap second it is + /// typically adjusted by NTP to stay roughly in sync with UTC. + RealTime, + /// A 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 + /// system time (e.g., if the system administrator manually changes the + /// clock), but is affected by frequency adjustments. This clock does = not + /// count time that the system is suspended. + Monotonic, + /// A 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, + /// International Atomic Time. + /// + /// A nonsettable system-wide clock derived from wall-clock time but + /// counting leap seconds. This clock does not experience discontinuit= ies or + /// frequency adjustments caused by inserting leap seconds as CLOCK_RE= ALTIME + /// does. + /// + /// The acronym TAI refers to International Atomic Time. + TAI, +} + +impl ClockSource { + fn into_c(self) -> bindings::clockid_t { + match self { + ClockSource::RealTime =3D> bindings::CLOCK_REALTIME as i32, + ClockSource::Monotonic =3D> bindings::CLOCK_MONOTONIC as i32, + ClockSource::BootTime =3D> bindings::CLOCK_BOOTTIME as i32, + ClockSource::TAI =3D> bindings::CLOCK_TAI as i32, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Sun Feb 8 08:47:47 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 3BCA1233739; Mon, 24 Feb 2025 12:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398762; cv=none; b=uj/odBD+duHtIk40y+2VpqZgti419phKZXXeLprtVJP8i4PTxloB9DcYtm1EhOqSc/hAvFcbFC9n60+4WjJBLfARHTRQsn6Trv6ohTnt5lOLS84AtakFC3weKbbGf6Utr4LYYXgBZNLVOe1S1z31uWBAiPjuSq9elTAcwgw91TQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740398762; c=relaxed/simple; bh=r22q6T3iTRPtwznESGgzBK1H2yg/6SOqkTHLXaFCMZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PtGmBnSbNjYReOJwkweD1Z8iOYu+nXCKRg230hTMmDfpNBD2qVsBZ8IFIgSvDf1Fp+d9ScWPLWWTHpy+8tJXUGF0afYo4u2DzFCbzkNov1se8LJRoqbJiDOpkUhEem8+d4SDEe49aOjTUKKLkJ0qKrS6nJgxIYsY19oBG15KUzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G43zGPOZ; 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="G43zGPOZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF338C4CEE9; Mon, 24 Feb 2025 12:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740398762; bh=r22q6T3iTRPtwznESGgzBK1H2yg/6SOqkTHLXaFCMZ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G43zGPOZLKJL7CjAnhgTGwwQ1aFDZD601rLcEm/8xoaSGsUbBQrfNBWfbfVzD33jS ghrbfh+ulg3c+DTWC4sJnStQ2RFezaxqjRDIy7D7zxnUjq2DyM7gXWtrAwWT8oPePn +R1yvTErZVwDShmFamV9k3o7bO1T4IMdsqXc4aDSDYTcYrTinUlPWZgk3fEFn6DiOm 8/Woolj0EiMuMl23eaNwvL9mqjLOehIsFi2OiBlXCKj+dFe/rBfeAvwj/kXp1FwHnV 4fYu5zS5NrcyQVMC7R+wiAxQ3hXFqvBqJnooaPyFTpHNjeRgD73UKpRfhWcyrpFvkI wFXZItYjM/X5w== From: Andreas Hindborg Date: Mon, 24 Feb 2025 13:03:47 +0100 Subject: [PATCH v9 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: <20250224-hrtimer-v3-v6-12-rc2-v9-13-5bd3bf0ce6cc@kernel.org> References: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> In-Reply-To: <20250224-hrtimer-v3-v6-12-rc2-v9-0-5bd3bf0ce6cc@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1044; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=r22q6T3iTRPtwznESGgzBK1H2yg/6SOqkTHLXaFCMZ0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnvGAnim0wmOoDxbgma7+5R5YqYhB9vpvyTzENt a6C5dHvGdWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ7xgJwAKCRDhuBo+eShj dzNuEACYMCAkXcodBftvIU5ttxbYTan/TCeKQjhiNMzF732OmA3/+SeZ3x3KQ73PZ7M5gs2/aTE gnwQBDSTwI951ld18eiN1aezYvaBVW64omvj0m5QBf//sYTSgX0xmIEyHJ7M94wjLtPKbIAjIIg kAo1dKZ4wBySk1WPfMoWnc+jWA7te1f0aVu5odRmmfxPcgBRFPSFqRux463uifazf+xQy3HDHy0 tTVgEd32ri0GXHLERHCiF5Dq4A3uJVvCYIJGwlKAGWGTx7SNu5ZsGiOyKp3X1goGYtUlSZ9nNH7 mkPgtsZebQng+8xA9mPLx5ma7/AYdxyNRjGXcERKD4A38nl/OFgV1brQs5RQkZNxWNDGzwIxAtl NBkwtepiNYE59gCyJDlPUm3GRFu7Cnsj+ZRaBAjGZTNA9ojLEp1JJyN8GU6zthTOSeK+SNZjI98 nu5Jt0feqvX8Dh2rIuhsn52vqjjjEeW+dFa7hiSvJ39oYauhGWRaah7elZKTABrQXA8G4NgqBRD YABZD/oEEYaaeHCQYHeEkMDJG5jOrsKOtaJTjVwGzm/hp7/Szk22AfSd4n3lbmV2EYjqAYU6JOe HJrGUYciRRWSOE4OgB1/CbNbT9PGHRy4poUCr3+tdKbL4jfvsZDIXGRcGP2FK+GmUFc7nJkjGVG s6l2l47gTJyMlew== 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: Benno Lossin Signed-off-by: Andreas Hindborg Reviewed-by: Lyude Paul --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 896a307fa065..60fa77c41b3f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10355,6 +10355,16 @@ F: kernel/time/timer_list.c F: kernel/time/timer_migration.* F: tools/testing/selftests/timers/ =20 +HIGH-RESOLUTION TIMERS [RUST] +M: Andreas Hindborg +R: Boqun Feng +L: rust-for-linux@vger.kernel.org +S: Supported +W: https://rust-for-linux.com +B: https://github.com/Rust-for-Linux/linux/issues +F: rust/kernel/time/hrtimer.rs +F: rust/kernel/time/hrtimer/ + HIGH-SPEED SCC DRIVER FOR AX.25 L: linux-hams@vger.kernel.org S: Orphan --=20 2.47.0