From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B1DD1F75A6; Tue, 17 Dec 2024 15:20:01 +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=1734448801; cv=none; b=q83DrBTpTpSBE8FCR7cH/hFjii5/C12/NGamjbhm8SIRXhswSWwOK26vG25KI1Y6pNpwFB5IY6/AoTKA3C84yqmHFR39gcQfNv0CrAIpUXIjc6I23YO9eDegkHEWkz530ea6dGckV3wNc3wpI3ThdT6gGra66IRJUXZ2/uhPqbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448801; c=relaxed/simple; bh=/ybNIO+z0YMt7NQe0O7P3cxsv0vraqHKkL76VnTITTw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r7zV+nEtYX+22LWOosTAcvo1rgVAlC4cE33AiOADyW9tGvA/dsrztsbyxj7tj/fYHwHIU/wChuFtXzl/6GrZohRrhtYsacG2oSOWNF2N2M435jpEARd4NQUP1chjFq99UF3lRzW9SOhzt/teuhTdjHblRJFtungeNRjClL0T5zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nc3/LszT; 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="nc3/LszT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBD5C4CEE0; Tue, 17 Dec 2024 15:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448801; bh=/ybNIO+z0YMt7NQe0O7P3cxsv0vraqHKkL76VnTITTw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nc3/LszTi9GWy0K9sTjN6vOuCsKLUT/FL0BazaU7V3G8WbmuirrbJVFAlXSeuNjN/ w4Ow30LPsglg2W1GnDd8eit8hjoAEJUzp7O2TSwtr2wB79r5AhQdpMRmriy8z8mt0y Ce96eJhjUEA4bHIjmzCNP3v5Sy51MUyzSIqrG6fucjBb2C2gj79DZp7RCLyak7jH2Y yZPA/PyAJ11MiEXaEPC47VjEkffxFx+cB+M+6zrKmaMezhjqzkEgEdKTdKbOLzUP1c qkZ4Ljs+LBfZrUCHW56G8RpeGgrh1hVXiXLupN8nxKSVa+hLEVQjkjEiqWKMHjMFV9 2cWZBbit5WP+A== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:32 +0100 Subject: [PATCH v5 01/14] rust: time: Add Ktime::from_ns() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-1-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1377; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=zvxjVReWexH5OF8VhuSFOtSXv8mRCanz1tBYjzejoHo=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYRnvVPrMLQSBo9/TW28kFLLIJnJQRiXNwI5 EjBOqQGQ2iJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWEQAKCRDhuBo+eShj d8GxD/wJZIeTygsVvsTFdKxvI/6oExJIZfJsVNodXip5ZpNxljXmHLxQqAZF/1NzdDeduYzG65k QfbUfa4OM4zxOWsyqWwEGkGK66qvvPpGdgUsQsOHQ+pfmOdMQ/BFhM5sSfOnr5sebHb5qB1/UES WSM5yDP4U422Z06V9HH4RuzeBpUOdv/o3YMnWa4KF8G5CAVk6E/HSy9JYE5gxdW5/kKoIPn6c/x vVBYnhOC/uV85PjLGTQbdQ1j2nyqrgruGefvbyrz07+7I5Z5w0gN39kmKaekmTWp3y3vR13MaAl 5i97WM81nEreHcQ4FrCzp6V7DC4lHDJQJ6tgep4NZzeEVowgCxIcl1PEbCPGDpe3U6QURCtVrY4 fuS14NJbOGnAVsWYDTSHMHhWvtdPtPAcgKYfzG4V1uE1I0YRhTJPQ4k4jpasD0sg/S581ZAMqiw sXDDt+ykQ+pukSh+Iq7zsahSXhDxH9sG/lcKAhYyWCte5pqAlnQH4qBsbv3vd6jJn9WtT6n62XY nMxunbss0O/lQuLxdUicYlqZoH6LaJhVZERTuT3iPGHVKR9xv9c0plplxJNcBSKc+y4QDAi3yK7 +4SwQj3WfQnPlmKCc5eL+/kNwWhqyqYLZFywtBxaIY5GYBkNr5L7qzyt4LpTWTKYcdubquiekln 87H6r1Q2Y2M89FA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 From: Lyude Paul A simple function to turn the provided value in nanoseconds into a Ktime value. We allow any type which implements Into, which resolves to Into. This is useful for some of the older DRM APIs that never got moved to Ktime Signed-off-by: Lyude Paul Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e575c9ceacb9c85255b13501db8f30..f59e0fea79d3acfddd922f601f5= 69353609aeec1 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -8,6 +8,8 @@ //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 +use core::convert::Into; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 @@ -63,6 +65,12 @@ pub fn to_ns(self) -> i64 { pub fn to_ms(self) -> i64 { self.divns_constant::() } + + /// Creates a new Ktime from the given duration in nanoseconds + #[inline] + pub fn from_ns(ns: impl Into) -> Self { + Self { inner: ns.into() } + } } =20 /// Returns the number of milliseconds between two ktimes. --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAD911F7082; Tue, 17 Dec 2024 15:19: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=1734448762; cv=none; b=knHB50pxH7nodTDzZJRQK1zJIriDiUX6T7xiinC2UR5TyRkXaFZ1pOlezx2Fuw6s2tJxxiCKd9uQi+vUuwDUTZnWJW6TPfRtE+eIaSGgtPfZ9VVmoUZpipekteZGXZdqLYilcU3Lm+/85gmeiWIlp7vy+4+aAgKyAVMwVwP+oF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448762; c=relaxed/simple; bh=8HAOeJ5aPV3wyZF3YtER7fXarEqO15cVRrMfd0GEa4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t2nWZanZIjX1oGpPU3FQwEqHK8Ti9VS7jAQiswpq1CIz2HYDnbIhnOQEs4NvRCU8zWyU3XUIZ8VSYMC5Pe0ewiAAGJdopOIfXYYkYvlOR3hRN6U3h8BRQDEFN+Qy6ifju9rcZ/8baSGSKd+mNZAk3IjUNyqvz+eWufsBU3ufHGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e4YHbE+v; 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="e4YHbE+v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31EF5C4CED3; Tue, 17 Dec 2024 15:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448762; bh=8HAOeJ5aPV3wyZF3YtER7fXarEqO15cVRrMfd0GEa4o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=e4YHbE+vOXZLPUanzm8BdnpuWtHGhVcYYY13JmpzUnNZwczZP2MCzLCqJzq4XRe4e VIY/Qe9mEdOFJkhg1oOOxZvi1gD9KmXcR7TWC+aB1tf7LUuFS/0l6UaK+by14ktG4S TvPYVmm+PBecjzwpWHu10oNEpvTNSHeHHeLFO64zut9ou7YwdfeNJwr4NydXOffB6h DHSbKN8N4hr8/rKYQs9Q31h8FKhUPAGS+eVBmqk2kO3EE3iVSuW3fE8uZYyGtq7TVq UwIa38jHWdkKQ2B4ZmSVgA93qoyBJnPf/Qb62lGB7nLYLp/dbf/sYvP8+Dk6JmaO7r Btjai/LmlNFuw== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:33 +0100 Subject: [PATCH v5 02/14] rust: hrtimer: introduce hrtimer support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-2-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12283; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=8HAOeJ5aPV3wyZF3YtER7fXarEqO15cVRrMfd0GEa4o=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYScrbVH27Uv8iLaZVPZfjEBxLwX+oQU+g/Y sNWvqx170KJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWEgAKCRDhuBo+eShj d143D/9JX8nM3TmzER7yEDpBqJiyPqul7SBIpUCh4gSgdqkLwsgwqjcaETbhFKv6oTcUM7DLyT6 50R6LlcrzPOhv4fTGPxoHV/TuJ6lzn+fe7+lTpqvUtwEBy55OPaF9WMVEDyShBaRP+u21CmFBC4 DPdZAVE0VJANapFnV16aEJuf9jwgqTt2cdipcnNVRcNnWEoW/tDVbl+JRzAULMR/zSz8UKOvkA7 SHOr+K3yrx64stmhSLPiOMS9vluT2mNRqNVdOxtMfK/vh/99fhpq5wHlqEdU0LR9eeyVbb39o0b g8HcQXxoVT2e3W9ooZ3yMZU1osD5h1tUmVSimMND3Q+tM61XhvVk1u1Qv5e14BqIOGTftGfOyyr KzsR4mJabWMtCr4nAybVhMMyrko7xsRb9qHkj935yE5gcblYpQ4vDf/Lma2GT1QpI972PnVhETv S/0gEQCiCWhMT1VqiMOkxpK7T1I+hjre1Xl/zgksCFuP+bTTs9WxCg7wqIKr0rf+vguyFjNotkq pAD2ryjkuhfOUclgIz5PWvMzGTGbOPWGjU4oY4+nWNpaCoWpQNWFGem0p3pR1QwmJUne++dEPsm GsCXxym1n0QFxn8kIpeBeCtV+W6jtwTDjRk1MDs4cJxuUrrHCIbgpfPYRYgux7m9VkVIzLY3rBy mqyUS/zmdLxAe4w== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch adds support for intrusive use of the hrtimer system. For now, only one timer can be embedded in a Rust struct. The hrtimer Rust API is based on the intrusive style pattern introduced by the Rust workqueue API. Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 2 + rust/kernel/time/hrtimer.rs | 296 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 298 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index f59e0fea79d3acfddd922f601f569353609aeec1..51c3532eee0184495ed5b7d7178= 60c9980ff2a43 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -10,6 +10,8 @@ =20 use core::convert::Into; =20 +pub mod hrtimer; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs new file mode 100644 index 0000000000000000000000000000000000000000..b09bdb8bc2037bf116a9a87b162= 71f4045f53aa9 --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Intrusive high resolution timers. +//! +//! Allows running timer callbacks without doing allocations at the time of +//! starting the timer. For now, only one timer per type is allowed. +//! +//! # Vocabulary +//! +//! A timer is initialized in the **stopped** state. A stopped timer can be +//! **started** with an **expiry** time. After the timer is started, it is +//! **running**. When the timer **expires**, the timer handler is executed. +//! After the handler has executed, the timer may be **restarted** or +//! **stopped**. A running timer can be **cancelled** before it's handler = is +//! executed. A timer that is cancelled enters the **stopped** state. +//! +//! States: +//! +//! * Stopped +//! * Running +//! +//! Operations: +//! +//! * Start +//! * Cancel +//! * Stop +//! * Restart +//! +//! Events: +//! +//! * Expire + +use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque}; +use core::marker::PhantomData; + +/// A timer backed by a C `struct hrtimer`. +/// +/// # Invariants +/// +/// * `self.timer` is initialized by `bindings::hrtimer_setup`. +#[pin_data] +#[repr(C)] +pub struct Timer { + #[pin] + timer: Opaque, + _t: PhantomData, +} + +// SAFETY: A `Timer` can be moved to other threads and used/dropped from t= here. +unsafe impl Send for Timer {} + +// SAFETY: Timer operations are locked on C side, so it is safe to operate= on a +// timer from multiple threads +unsafe impl Sync for Timer {} + +impl Timer { + /// Return an initializer for a new timer instance. + pub fn new() -> impl PinInit + where + T: TimerCallback, + { + pin_init!(Self { + // INVARIANTS: We initialize `timer` with `hrtimer_setup` belo= w. + timer <- Opaque::ffi_init(move |place: *mut bindings::hrtimer|= { + // SAFETY: By design of `pin_init!`, `place` is a pointer = live + // allocation. hrtimer_setup will initialize `place` and d= oes + // not require `place` to be initialized prior to the call. + unsafe { + bindings::hrtimer_setup( + place, + Some(T::CallbackTarget::run), + bindings::CLOCK_MONOTONIC as i32, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + }), + _t: PhantomData, + }) + } + + /// Get a pointer to the contained `bindings::hrtimer`. + /// + /// # Safety + /// + /// `ptr` must point to a live allocation of at least the size of `Sel= f`. + unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrtimer { + // SAFETY: The field projection to `timer` does not go out of boun= ds, + // because the caller of this function promises that `ptr` points = to an + // allocation of at least the size of `Self`. + unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).timer)) } + } + + /// Cancel an initialized and potentially running timer. + /// + /// If the timer handler is running, this will block until the handler= is + /// finished. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + #[allow(dead_code)] + pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { + // SAFETY: timer_ptr points to an allocation of at least `Timer` s= ize. + let c_timer_ptr =3D unsafe { Timer::raw_get(self_ptr) }; + + // If handler is running, this will wait for handler to finish bef= ore + // returning. + // SAFETY: `c_timer_ptr` is initialized and valid. Synchronization= is + // handled on C side. + unsafe { bindings::hrtimer_cancel(c_timer_ptr) !=3D 0 } + } +} + +/// Implemented by pointer types that point to structs that embed a [`Time= r`]. +/// +/// Typical implementers would be [`Box`], [`Arc`], [`ARef`] wher= e `T` +/// has a field of type `Timer`. +/// +/// Target must be [`Sync`] because timer callbacks happen in another thre= ad of +/// execution (hard or soft interrupt context). +/// +/// Starting a timer returns a [`TimerHandle`] that can be used to manipul= ate +/// the timer. Note that it is OK to call the start function repeatedly, a= nd +/// that more than one [`TimerHandle`] associated with a `TimerPointer` may +/// exist. A timer can be manipulated through any of the handles, and a ha= ndle +/// may represent a cancelled timer. +/// +/// [`Box`]: Box +/// [`Arc`]: crate::sync::Arc +/// [`ARef`]: crate::types::ARef +pub trait TimerPointer: Sync + Sized { + /// A handle representing a running timer. + /// + /// If the timer is running or if the timer callback is executing when= the + /// handle is dropped, the drop method of `TimerHandle` should not ret= urn + /// until the timer is stopped and the callback has completed. + /// + /// Note: It must be safe to leak the handle. + type TimerHandle: TimerHandle; + + /// 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 [`TimerPointer`] implementers to give the C timer callb= ack a +/// function to call. +// This is split from `TimerPointer` to make it easier to specify trait bo= unds. +pub trait RawTimerCallback { + /// Callback to be called from C when timer fires. + /// + /// # Safety + /// + /// Only to be called by C code in `hrtimer` subsystem. `ptr` must poi= nt to + /// the `bindings::hrtimer` structure that was used to start the timer. + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart; +} + +/// Implemented by structs that can the target of a timer callback. +pub trait TimerCallback { + /// The type that was used for starting the timer. + type CallbackTarget<'a>: RawTimerCallback; + + /// This type is passed to the timer callback function. It may be a bo= rrow + /// of [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` i= f the + /// implementation can guarantee exclusive access to the target during= timer + /// handler execution. + type CallbackTargetParameter<'a>; + + /// Called by the timer logic when the timer fires. + fn run(this: Self::CallbackTargetParameter<'_>) + where + Self: Sized; +} + +/// A handle representing a potentially running timer. +/// +/// More than one handle representing the same timer might exist. +/// +/// # Safety +/// +/// When dropped, the timer represented by this handle must be cancelled, = if it +/// is running. If the timer handler is running when the handle is dropped= , the +/// drop method must wait for the handler to finish before returning. +pub unsafe trait TimerHandle { + /// 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 [`impl_has_timer`] macro. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that the implementer has a [`Ti= mer`] +/// 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 HasTimer { + /// Offset of the [`Timer`] field within `Self` + const OFFSET: usize; + + /// Return a pointer to the [`Timer`] within `Self`. + /// + /// # Safety + /// + /// `ptr` must point to a valid struct of type `Self`. + unsafe fn raw_get_timer(ptr: *const Self) -> *const Timer { + // SAFETY: By the safety requirement of this trait, the trait + // implementor will have a `Timer` field at the specified offset. + unsafe { ptr.cast::().add(Self::OFFSET).cast::>() } + } + + /// Return a pointer to the struct that is embedding the [`Timer`] poi= nted + /// to by `ptr`. + /// + /// # Safety + /// + /// `ptr` must point to a [`Timer`] field in a struct of type `Self= `. + unsafe fn timer_container_of(ptr: *mut Timer) -> *mut Self + where + Self: Sized, + { + // SAFETY: By the safety requirement of this function and the `Has= Timer` + // trait, the following expression will yield a pointer to the `Se= lf` + // containing the timer addressed by `ptr`. + unsafe { ptr.cast::().sub(Self::OFFSET).cast::() } + } + + /// Get pointer to embedded `bindings::hrtimer` struct. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn c_timer_ptr(self_ptr: *const Self) -> *const bindings::hrtim= er { + // SAFETY: `self_ptr` is a valid pointer to a `Self`. + let timer_ptr =3D unsafe { Self::raw_get_timer(self_ptr) }; + + // SAFETY: timer_ptr points to an allocation of at least `Timer` s= ize. + unsafe { Timer::raw_get(timer_ptr) } + } + + /// Start the timer contained in the `Self` pointed to by `self_ptr`. = If + /// it is already running it is removed and inserted. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn start(self_ptr: *const Self, expires: Ktime) { + // SAFETY: By function safety requirement, `self_ptr`is a valid `S= elf`. + unsafe { + bindings::hrtimer_start_range_ns( + Self::c_timer_ptr(self_ptr).cast_mut(), + expires.to_ns(), + 0, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + } +} + +/// Use to implement the [`HasTimer`] trait. +/// +/// See [`module`] documentation for an example. +/// +/// [`module`]: crate::time::hrtimer +#[macro_export] +macro_rules! impl_has_timer { + ( + impl$({$($generics:tt)*})? + HasTimer<$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::HasTimer<$ti= mer_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::Timer<$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 Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CA2A1482E7; Tue, 17 Dec 2024 15:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448823; cv=none; b=Iqt8FDGLHAPb6Rj3JVYEQoPrW0gSReVUMpf3HuQK1t/TaqKRV0+5nfjTyJCJmTfXeF+2fc7ttZA0ID7QK7WtmHeawYJnxsjvOOyVWpysVG5DDNgqfdO2mmcNZAbTJvn1fWbfe6HDd8FknEccIpmnXGXF3HZCq4VMoOGD1cPi7Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448823; c=relaxed/simple; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B90E61LaPn8Bw95bU9pkZQBm1Q9frs6e43olXNKa+t2tjeo7pvNMEn34VFx0WS414YyyETLwuqN/IL5BceXI6ApuCK3qz9WfRSHPLWjuLoQXg4qCd7r+NXXGkTyaE3/m3qlQRMJ0zYoA4BBFIPzho5mfMHE9kkTHb8Ax6lufNcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dr9FyvHy; 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="Dr9FyvHy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBB0FC4CED3; Tue, 17 Dec 2024 15:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448823; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Dr9FyvHyXhgQm7+T+4Xt+K/TDxwLRsN92+LzoSyMl6CF3l7AYDAjO0uzhhmCqalTB YUqlOk4yGGRs3nvVw0PWb8alzJwQfevAF+LxKcnibNJ00/oXshsifVKDLoIAjagNoU 7Al81evqBUp0p4hckgmagRGseiWyIKmo/ROv80pBLySphwYgqZvnfHvm3djtdf4Qnw C9pBLEfk2N9KnkoeYRxbxHjAccivF0iDKvZSvuYTKS3xdacWDHVUWxG5K+FbyZ4djX ereyIAP1BUVQ95E+Qk7bPuMYaWfKNbN/mltin8VrKLXqeamdvr39OqEOkb14couFR/ 6hPFYGgARQyEA== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:34 +0100 Subject: [PATCH v5 03/14] rust: sync: add `Arc::as_ptr` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-3-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1772; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=aU3i369UGy3y1q8jWHIGozb7YdRezhyOhvtwK08LAa8=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYTGjzQEzj8dKhz3E/Exy2volMGLExqfJVVT xvzZjs2sE6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWEwAKCRDhuBo+eShj d5vKD/9gXTHnCWwOkdFZm7xlp10yG1nHe7MR2A72J8VS8V5RvV0gLgn8tLUSDFxfVlZ5Vryev0E aInNLWa9C7VEF4xcWmxcTGzd9A7RVuxuJebgQTd+xmbrfTfu+6NTI3ST7aHMCWZXfLUWE2Yzkdn gG3ndW+JfNy/lFBoEyK+VqROmaAlZaExIzsDcwnRJy6WMabBJybewAmqqCKHFjMEpQz7rY1VgKt hIf9t6G9bQopI0erEEbQjbB/8BvG16pkz6VztcOMs6T01ynKZz6Dvioor8sVadsvZkhjYrSBOV6 N8kLS4g/L1uLUhKT/NjlVnLx8kMjVPXauCw/EjxUpcCB8Ls8uZY2LE3DfAU5V179D/T6pkjgH7B j4J/+roKdf5ZZaUG1QhknNhagpEvaF9/Ma73YzBtBWxZdTW5/lU2uFH7Ds9ereOJ2qwxJgRAVCW trz1Icv3yY5LS0rUk1u8GfqeS46ZT2ORjeGFT2aD1az8kb/buJAMVyMvZsN8d56RFizk5+Vx5ET BPVgpiMDP714ECPaCyoCvDwUUCEAGqqWuOl7oKbtgtv7LSIM6sbaoquWn6LkdVURs498YxGXUfc 6qrJ/7zcVau+s9WBf4zNnX1eLBnki/JOLIc9AIYKaVX4iF4sxpgfJsi1ywm1hPlR+u2g25dEXtg mP438o+E1GlkOPA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a method to get a pointer to the data contained in an `Arc`. Signed-off-by: Andreas Hindborg --- rust/kernel/sync/arc.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index fa4509406ee909ca0677b78d5ece966089ce6366..3d6111ddb007285b26eca2177a4= 12033f4ac5dcb 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -233,6 +233,15 @@ pub fn into_raw(self) -> *const T { unsafe { core::ptr::addr_of!((*ptr).data) } } =20 + /// Return a raw pointer to the data in this arc. + pub fn as_ptr(this: &Self) -> *const T { + let ptr =3D this.ptr.as_ptr(); + + // SAFETY: As `ptr` points to a valid allocation of type `ArcInner= `, + // field projection to `data`is within bounds of the allocation. + unsafe { core::ptr::addr_of!((*ptr).data) } + } + /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::= into_raw`]. /// /// # Safety @@ -508,11 +517,11 @@ unsafe fn new(inner: NonNull>) -> Self { } =20 /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been de= constructed with - /// [`Arc::into_raw`]. + /// [`Arc::into_raw`] or [`Arc::as_ptr`]. /// /// # Safety /// - /// * The provided pointer must originate from a call to [`Arc::into_r= aw`]. + /// * The provided pointer must originate from a call to [`Arc::into_r= aw`] or [`Arc::as_ptr`]. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = the reference count must /// not hit zero. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = there must not be a --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CEDC1F75B3; Tue, 17 Dec 2024 15:19: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=1734448767; cv=none; b=eYUhYxGTctW6kiljqFIyQQQ0+m3B+npisDAGnvz0bSKQYw9W3X1UJuI4/6IUiQ2H6xDtOAu0z32/uHL7CgxY0/UB2vBhZAzB0Lez/29cXGYepAC7UgWH7guv4/yLE71xT4W7GUvaLLommdYXU6Khagr8/VOLLLDn2KEOZeELliw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448767; c=relaxed/simple; bh=BaTuornQU3iUrsBJYToH5jffWKxOeX6MZ6yKQClRNP4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AHqKllb3r5GK7YtY3+9r5tBQRHXLJqtie4TCPH5MZNDnsLH0iOu/UmIXuEF3U4ML+yvq6yWmSccpXPLJpjlihZKDNo3c/mAQQp95GukcAdwW1e7OgkUn+v1BWxK6jAQfVdFfk/aioo9wyQPeKCCwVStnrbgFiET2yq2mc4CYRR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s1uOa9Ui; 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="s1uOa9Ui" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 406B3C4CED3; Tue, 17 Dec 2024 15:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448767; bh=BaTuornQU3iUrsBJYToH5jffWKxOeX6MZ6yKQClRNP4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=s1uOa9Ui8PH3FdfEoLNS2zRGEIr08ESeru/DjbJY11sXInf/B4Q3mf2mNtWPVcrXN IRxPhQbSK+p5ox/Z/1CZAWHG89ltDFfQnvdlCTmc1iAZk33/MnHiN7Q3aQMZmV5Gfg ufzeKUfUuqODBXflfz/ftTHWgZJU3JWdL7E3JK105ENuGyTkZy9fnPs6bRelTF7gAQ +cdMjBrNlAEQ3SeeeNJYG2EROBfVWTHI8VRjIq+b/LPxjvGohoMhUM/Yxk5f/BogLr iq9AK8YoGFEtOuniSGFjM77cC/j/9RJWFsDl937Arm+EA+KKr0Rn96JzoduF7ZExjG 381vGpiTYOrCQ== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:35 +0100 Subject: [PATCH v5 04/14] rust: hrtimer: implement `TimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-4-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4083; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=BaTuornQU3iUrsBJYToH5jffWKxOeX6MZ6yKQClRNP4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYUS97FjsFDuPCGga3mD82Qi8nX/p76r59Oj aozsTEWV1WJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWFAAKCRDhuBo+eShj d1BfEACXuRovJYFU0XRzpzLqYd2ptStuEotCZbBoMT6450d2V0TKC5QzCwySESo5Ec00t7qHvQ/ K1Ec1Z2pKlrja307ii6SIZHeaf1yHSXL3kkziSBRY/e4GxPwO8KVt0ePoaUROm5csNSt9+BDjIo 01kGUEyM0/oqEhJGD4+7xGLw1Twf/tJXZG57AbI5kEJQWuRwrts5iqxoYnGx3H4aa7s0/D6I2g7 bJCDlQW+EqKd2T6rQJJlujSzGGHa1mDhNHj0G5ORZ9FRigukZ6DQlLeVciZlcxPXEFB8vUbtVH0 2YGIOmvQd6WeZ8OXGayvOJp7SYmzg/q2gJlwwp8Gr7an44K7mgAwBL2I7kq58iylNfoeEIyAxbv OkU59NcIjD70iMV0zcfnHfBJZuz79+h298VmC8ymy1GI1+Q4eaNqD5z5fPng/BohjgdwpvF8jl/ wPwwxSaF8evC1Jf6BAoruMTCDbsXawo1EtH64R3rd8exv65dVP/c1KiN/6n/cjbl/ePYLEKtzXO NMwMZTNVodErZEtVr1Xvr53XyQoLLhcsqSFvJWg3kLFhaydJA8cDJuKJxBJfcw48/iwL7go3RCQ rMuPqyNqkv/nLiCKuj+PdVz6nC0OvM+EZU7eQFP9L79zeVZ9GN7YLPg2qRS7LtCuMFjdSGO2jo1 X0wTRcGPV51O//g== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows the use of intrusive `hrtimer` fields in structs that are managed by an `Arc`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 3 +- rust/kernel/time/hrtimer/arc.rs | 89 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index b09bdb8bc2037bf116a9a87b16271f4045f53aa9..178e33c1f656d2f834e45b00448= 6f6e5fe1813dd 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -98,7 +98,6 @@ unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrt= imer { /// # Safety /// /// `self_ptr` must point to a valid `Self`. - #[allow(dead_code)] pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { // SAFETY: timer_ptr points to an allocation of at least `Timer` s= ize. let c_timer_ptr =3D unsafe { Timer::raw_get(self_ptr) }; @@ -294,3 +293,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } } } + +mod arc; diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs new file mode 100644 index 0000000000000000000000000000000000000000..3b256292bc86160a495f7b192b3= eda92f2dfcb31 --- /dev/null +++ b/rust/kernel/time/hrtimer/arc.rs @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasTimer; +use super::RawTimerCallback; +use super::Timer; +use super::TimerCallback; +use super::TimerHandle; +use super::TimerPointer; +use crate::sync::Arc; +use crate::sync::ArcBorrow; +use crate::time::Ktime; + +/// A handle for an `Arc>` returned by a call to +/// [`TimerPointer::start`]. +pub struct ArcTimerHandle +where + U: HasTimer, +{ + pub(crate) inner: Arc, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl TimerHandle for ArcTimerHandle +where + U: HasTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr =3D Arc::as_ptr(&self.inner); + + // SAFETY: As we obtained `self_ptr` from a valid reference above,= it + // must point to a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(self_= ptr) }; + + // SAFETY: As `timer_ptr` points into `U` and `U` is valid, `timer= _ptr` + // must point to a valid `Timer` instance. + unsafe { Timer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for ArcTimerHandle +where + U: HasTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +impl TimerPointer for Arc +where + U: Send + Sync, + U: HasTimer, + U: for<'a> TimerCallback =3D Self>, +{ + type TimerHandle =3D ArcTimerHandle; + + fn start(self, expires: Ktime) -> ArcTimerHandle { + // SAFETY: Since we generate the pointer passed to `start` from a + // valid reference, it is a valid pointer. + unsafe { U::start(Arc::as_ptr(&self), expires) }; + + ArcTimerHandle { inner: self } + } +} + +impl RawTimerCallback for Arc +where + U: HasTimer, + U: for<'a> TimerCallback =3D Self>, + U: for<'a> TimerCallback =3D ArcBorrow<'a,= U>>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `Timer` 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 `Timer` embedded in a `T`. + let data_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: `data_ptr` points to the `U` that was used to queue the + // timer. This `U` is contained in an `Arc`. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + U::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56D001F7578; Tue, 17 Dec 2024 15:20: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=1734448807; cv=none; b=ezlKlutpzCF2lOgmKCrnFLiW/C6R/WpKrq1C8tbMPpRdhnEcbdej7T3Vi+SwHl49KBKcYa5McLHQkPGqZa88VjhyMmPvS2Da3E5Lby1Ui7IHXzmG94NkC4IjYdRTRaJ1HN9Yfxw6CZHCKG4DEczLQuMgHQbSlAqT8cD6Uaf/RxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448807; c=relaxed/simple; bh=a+16RE4oWB4CXjb0tnUwQPdz5BFsFTklO8F1PqwecHM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8TVWEmmUNkLmpKcPmjui5RCCHVTEk7kitkh1WnWBA828WcpunJ0jgvKvq9xJM9slmoEQYKK8enaFHJ6gfpS4jTo36ebBVI7iEMm4cCUqOAremaZJYBeacm5r4NcRTzUibov++fmcuVoarqo8PKWOjTVeaWXgD/omiiCTRJH+HE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jSIdhtta; 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="jSIdhtta" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DC11C4CED3; Tue, 17 Dec 2024 15:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448806; bh=a+16RE4oWB4CXjb0tnUwQPdz5BFsFTklO8F1PqwecHM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jSIdhttaeu+p8d5nta4JpW/RDOWU94uFygnp7t4qZoH49gX8zoNI/CQZ+zHvA9/Zm LQTBXx55LldPTR7PgKb7S9S4fypy445Ztbq1ocDSIEaf8yP+O/auheJJNg3TLKHpDY rc/0ouapwoK8SG/fQ8eJOq/3cSQMhPhvE/U8dbyeo9ImFG4F1j2/J7AdNfIaubkZfV 0bfUnru6xtC+QzoRCSixO1/rjyPS/1iw51KZcrre6MDn5Vl7Cwef5oxPUgN92QD20j ZGNnbPUKCCzkEgiQDXGBy+c86B7CV5d+aHNrquOjyM8njt1OLkG8aiWzrPJuBLRWnt 2NI+33uO3zN1g== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:36 +0100 Subject: [PATCH v5 05/14] rust: hrtimer: allow timer restart from timer handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-5-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2659; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=a+16RE4oWB4CXjb0tnUwQPdz5BFsFTklO8F1PqwecHM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYV2tRbCy289iAqUS0zjW5qVNIU0UUI3XqLJ TwMTBaMuQ6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWFQAKCRDhuBo+eShj d9wcEADCj6RftvFeqkqKmeiKYqIswROCsIXwS58U1U82frlcEmaYa+bR9pNQfP+ro8/XjV2ba7D Vsb6eNtPtxS5o1woQ8eAfYith30rhRkmNLPTUQJGMkO364VaTgn7GGPLo2OKzcnaItfIdYIVZhm NMQJ1JLHSXjKFVwZ5tO4ocwAnDUZKPbbjZdCO9MhxN9rHVF+j2awd4pTjDy6r4RSL49qAvgzKGC JAFXPu0/prOWKKSr6rNM+/gWPTDFMLktxS/C4XnuheoecP4nTgI1NO5v7W/BPmtbrzFLZEEUT5o y56BViEO9EeNgQaVg4jmIi6pK6wohZ69Hy6wK133DnT5aCLlb/EbdmHdihqr7WN+rBVlJ2/Hpa2 EJibkSBd7tpgnMOOODsSOmjKUBT5YIyXz3VRQ63d9FScUoACTwFm9uBLvQCLJ2Tvn5DHFkTtsuw QlWZwlowxvZC6iyI57KrAO/wFDnJfybcPQCZtrV7Xwky69rEvuh/fxOjpaIzQwRsX11j/iBdlh6 nSKITto/epjAf4WM7GwdwFNtNaU/eTlbrwHU1T37nrzZUX7s+ai2rIJC0TwOSHyc6tYw6i4Mu+6 cd4PP8PBh7UVGS4q0ajaMqdKfo9J5TMLLA+vb4p/9NbWy3Np964/4HfKEL+VmDoS0w0J9TGyPXZ 6JbyyvQiIx6QK7A== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch allows timer handlers to report that they want a timer to be restarted after the timer handler has finished executing. Also update the `hrtimer` documentation to showcase the new feature. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 37 ++++++++++++++++++++++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 178e33c1f656d2f834e45b004486f6e5fe1813dd..38a8251ea6ba4d84dadad009ed5= 40c150bea4775 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -167,7 +167,7 @@ pub trait TimerCallback { type CallbackTargetParameter<'a>; =20 /// Called by the timer logic when the timer fires. - fn run(this: Self::CallbackTargetParameter<'_>) + fn run(this: Self::CallbackTargetParameter<'_>) -> TimerRestart where Self: Sized; } @@ -262,6 +262,41 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime)= { } } =20 +/// Restart policy for timers. +pub enum TimerRestart { + /// Timer should not be restarted. + NoRestart, + /// Timer should be restarted. + Restart, +} + +impl From for TimerRestart { + fn from(value: u32) -> Self { + match value { + 0 =3D> Self::NoRestart, + _ =3D> Self::Restart, + } + } +} + +impl From for TimerRestart { + fn from(value: i32) -> Self { + match value { + 0 =3D> Self::NoRestart, + _ =3D> Self::Restart, + } + } +} + +impl From for bindings::hrtimer_restart { + fn from(value: TimerRestart) -> Self { + match value { + TimerRestart::NoRestart =3D> bindings::hrtimer_restart_HRTIMER= _NORESTART, + TimerRestart::Restart =3D> bindings::hrtimer_restart_HRTIMER_R= ESTART, + } + } +} + /// Use to implement the [`HasTimer`] trait. /// /// See [`module`] documentation for an example. diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs index 3b256292bc86160a495f7b192b3eda92f2dfcb31..1711b41ab32aef0c6f5263eab38= bc61d6c2a189c 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -82,8 +82,6 @@ impl RawTimerCallback for Arc // timer. This `U` is contained in an `Arc`. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - U::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + U::run(receiver).into() } } --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92D681F76D7; Tue, 17 Dec 2024 15:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448835; cv=none; b=DgxJSpXaA3LfweidSEoR/IMALn0PUEIYCjlGD0yMsvoXKRIVCPKmzV0LFDqNMsUIKABKiDQUB3R+qC3tVFUmXHHWXUqqfPpCwVojxfuXxujiFWsDe3rr0hGBktmDPyU1dKZejQAkqXUwtuSqlSymGFVL5AoX3gc13TZhEkT2R/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448835; c=relaxed/simple; bh=PL/P/k1EasTopinIiSOzrV7o07tpGR6uAbv10aSKQj0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kSxRD7a4MMOpUWidewDtOrgPZ0TtLuAsN5WwZRwdpfgZs35Fh0o4o03+1oowjYy+BqY4394EVo7lw5UwyEPwYzk00QpxUI40W3Z1bVRDeKNw6MR2DhkVCaxq039dbXKc9+Ce0j6SrQp7tv6eG/ETbp0WD/OSDcq4aWid8CoEt3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kGumXfkY; 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="kGumXfkY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE1DC4CED3; Tue, 17 Dec 2024 15:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448835; bh=PL/P/k1EasTopinIiSOzrV7o07tpGR6uAbv10aSKQj0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kGumXfkY8q8bM8OvHiqaWo9tImvDkIEUkafzMXjeuj7lz+0x++0fN3m7nMeeBUu09 AQvWtD6alUmU+QQ7rg/sf4pFmth4BDjeTmfF9KP+2GNX2Py4vm9fi+V4lGggT5DlDI 2Ruyfb+b53hrA5t1iGL7IOFWlNZDtZ2cGDsGwzMLTiFf+El/BSTYcs+lcORSALB8yb 7Ci+ogJf71JHcz+JZBdZ2X4VHSygXWke/pnhKlj1xmpA3BRDJ97iOtyE95hZuQgiZN v8KUeuV35j3zqsDp9eo2c24PAJF3uAbL/gjF9TzDFzg74sBxeA0rHcCljFAUrpQrVl bscCCXKOGSKtQ== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:37 +0100 Subject: [PATCH v5 06/14] rust: hrtimer: add `UnsafeTimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-6-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2124; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=PL/P/k1EasTopinIiSOzrV7o07tpGR6uAbv10aSKQj0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYWPNFv0sIzctht0bDA4QzEKBPWNPTfT0x2L EU3IXrQGvSJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWFgAKCRDhuBo+eShj d+i6D/9mEsn1EYvscjqoGMr6VHU2ehx/wZ8FA3z/CRgm6OJxtBtW9rGCixBDzIckEs2/dcFb0YQ 7kQAj59tCq974P1LukhS4gLSyx5hOdqS8S8c+uxfAbtHYuwLW7LM+H225WCGxCMRJATf7eqgwEq kghtp+hLffmicmGyRB/ux1MVk8a1Zch/eQUtsTuKwloJoUOVnFb/uftz2mEIUmoULDme6+5KxRa 13okQcMiDQDbpxInU3V/v1Gvo1Hum5I7c1w5dXHCDZL9gbTVV0hB0J/QKVAsZtJaC+6RhQIHfYn Noxn6KL7ON0Xk1Y4Lp5hT9ylsLJUBwIf0gWRAVQL7F901qBDlxHV+DTiZTZRxBbxbuAoOukk8kG WhwOBjI/G1hWWup1yO5USMxfTgDG0SJ5BClCAnFwIjUYSP7W1fXrEBPvejGBwgv8C5XD1jaBzbs jqH+Mxaoto+jBLX867TRGnHkiDpKcIu781Zf1JFlTcYI0Poy7ijYATrCqNIMaq/9IwdwnzBTEND w70xYFIaEIli9EBfZZX1V1WcZoAC/ecGvHgsaEgJ4wKpsg+s79LnwxKUDZ/C+/5vf+AMVaYM8Jq 2I9fomQx2cAVW24uIo0LDmieRiZjM3jY6DBlg0xF7jLqJx3Jw44C3YLS0pVQMGb3vewlZvb7qd+ BJNuP8duZIhyp2Q== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a trait to allow unsafely queuing stack allocated timers. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 38a8251ea6ba4d84dadad009ed540c150bea4775..df0f6e720f1644ca31e0b64cd0f= 05a4a46098ec4 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -142,6 +142,39 @@ pub trait TimerPointer: Sync + Sized { fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// Unsafe version of [`TimerPointer`] for situations where leaking the +/// `TimerHandle` returned by `start` would be unsound. This is the case f= or +/// 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 +/// [`UnsafeTimerPointer`] outlives any associated [`TimerPointer::TimerHa= ndle`] +/// instances. +/// +/// [`Pin<&T>`]: Box +pub unsafe trait UnsafeTimerPointer: 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 `TimerHandle` must not return + /// until the timer is stopped and the callback has completed. + type TimerHandle: TimerHandle; + + /// 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::TimerHan= dle`. + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; +} + /// Implemented by [`TimerPointer`] implementers to give the C timer callb= ack a /// function to call. // This is split from `TimerPointer` to make it easier to specify trait bo= unds. --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84C051F7564; Tue, 17 Dec 2024 15:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448818; cv=none; b=VYYxKWq02eB77muS+EK8uLazu+1RiNKHYS9mGpY6hZZ6RUFGlBTIEMx6Eb65g4LC84sW3gugTJvivDegnbWzZN0Z2dyF+MJaXGMeeS1FZX0RAAIyThuOd5H6+VlQPNZpbQkE7r2ltH7a+CdfvpSure044tyMwbUpDSRQEj3KYG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448818; c=relaxed/simple; bh=F8fHHiPIwGJJkmQTQhR8tSNJzBkPpwYBHUBQlyRvMm0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q/Z9JZZcqfF3LUzd+NiBg188+wwX+GBN6ZXXFq5xkwW3wUhPqkcTOFser1JXTywTibiNNTbSwq2Jo9gEK/uC+RprYMFji2wIg1XomRB/PM3eigeZARstrYj8/JGPQSXSxwPm1CV02tySqUbJ91VtuSQaV1d8xgzp19qouVNG61o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ClTxW8Ts; 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="ClTxW8Ts" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9804BC4CED3; Tue, 17 Dec 2024 15:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448818; bh=F8fHHiPIwGJJkmQTQhR8tSNJzBkPpwYBHUBQlyRvMm0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ClTxW8Tsi4z0q49zURu50Jsffe93qkuehziWHvt28jiV1kqqQe7K2CSpDnO5zqCCn 07iGUsNVlhPjaJSBJBmXjILStxT/ctKSqDU//f97D7AIT/Oxb69EDKMN8K10osQB9x LSkwJSUE5ZxLzbtBx7slUIeTNQi/zeSH1K5l/ZEwslfacxxu+xzgGnq7IFIIFZ7F9M VKRpuV5wfVFZF6h+vsf+MHfQF2H54pBNNER6bA08OdpgRI5HwWnhpCt4mMTNlwjdqi sWzkdhS4gqyOVja32FHMdbHZwJV7QIESmjX9yKreuvnzmQ/4eFtlP5zQ+3zNnD3Pqp TMcQqvklBcbxA== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:38 +0100 Subject: [PATCH v5 07/14] rust: hrtimer: add `hrtimer::ScopedTimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-7-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2069; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=F8fHHiPIwGJJkmQTQhR8tSNJzBkPpwYBHUBQlyRvMm0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYX6L4mGMd7FXY2UgbYulFj0HfvBqmyrdxAT Pa4fZ8TtgeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWFwAKCRDhuBo+eShj d3IuD/9eYidi//zkKWvmxTuQp0NIf4d1fcJPotJ5gAlDxM6SbBM+CQDsCQ4QJUqZB59F6TdrAfa d6wmchZhQ7hpFlnhQgqCyZdQ5DyCdEoK+yYWfHGFg3/C+rKVfsK3Kd5NlFY3rqbM1Tawaxn17y/ TSUGZYGPZgHsvym5ri351KFmjm/i63zbERCfl4jZECKmYifOf6NQ+LAZ2ZIF+bNfFTN0/k84EvQ WDvOWuddVNJkDFi7SrmfXH8v80/Tff3twaP98yzj9wHhD8xxHLNx3mBMUEQFXdQEggQ6+OhikFn 2ErF+IDGArLMZ739AYF6EjytqD7abrLU3oeZps1bJnlDzVX9FOvwGAKQFbopJpwTxhae9oH0iHx vHRbXVOs2JTf2RTvSUiTIy1rRQOm4ULyzB3KuZByUBMEwhmOIGhFbb+KWtMp5UDXY20b2zmfgUI iJax/7Jv4N0dWQIrNGVomTSE29cOsGkbSCCNtfNba8DH8YrFFZPTiH3mYmM4CRbm0e0IpLwIbQy R6KASYKEHRM3QKtYby3QX+Sk1Lt6mIUd0VgxCTpEiczYjS+4Ri1zd9ioEq6nJ2LshOFt46A/Kgf x+AATYo45naDx1zsXIHleZiTyi5mTe3+91QmvykGV4vkqtRngqHsw9Vnn6XMvvBo+Q7XuAzjpN7 Fq1cp+Cr1z69kCw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add the trait `ScopedTimerPointer` 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 `UnsafeTimerPointer`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index df0f6e720f1644ca31e0b64cd0f05a4a46098ec4..6b03eb4b42dbd6447728c42949a= 2f93d736dc3b0 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -175,6 +175,39 @@ pub unsafe trait UnsafeTimerPointer: 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 ScopedTimerPointer { + /// 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 `UnsafeTimerPointer`, dropping the +// handle returned by [`UnsafeTimerPointer::start`] ensures that the timer= is +// killed. +unsafe impl ScopedTimerPointer for U +where + U: UnsafeTimerPointer, +{ + fn start_scoped(self, expires: Ktime, f: F) -> T + where + F: FnOnce() -> T, + { + // SAFETY: We drop the timer handle below before returning. + let handle =3D unsafe { UnsafeTimerPointer::start(self, expires) }; + let t =3D f(); + drop(handle); + t + } +} + /// Implemented by [`TimerPointer`] implementers to give the C timer callb= ack a /// function to call. // This is split from `TimerPointer` to make it easier to specify trait bo= unds. --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AAE61F707F; Tue, 17 Dec 2024 15:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448783; cv=none; b=BN5OQM9BL7hGjbLPXDnLpYieRRDZGngqXPxdU8fT/ZPsHmrxxD/dxC/Cu7qM/E3oSh97MkqH5jfY4e6zgWGPzULYb5JjyVdA8rfVlSHVuF22NB2ITU8Gb/8X7hP6UBLM1h1w+scTkTAYMXy4S1UKMhXIjgxfBAge3jVFD9Y5ZWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448783; c=relaxed/simple; bh=AGCwY1Om71mI6/3ZTwWXymP7dzg0hkZbFbkHu2TONUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Zn10bMgSXB0UcOgvShBlYrwhpaT6nXMKap60bv0IBtaZlCD0x/Sw05veM42x4pvz1+IKH2YfEJH6euEGzFN1dRvkf2wCnWTQs2vEC8ryjIefPgAqz9GPej/NV+nOnS4DFZ36vqadrOICwUnCrHs1YiiAtSMvpgPyhNbfLl67dNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SGGg3QFN; 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="SGGg3QFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B89FC4CEDE; Tue, 17 Dec 2024 15:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448783; bh=AGCwY1Om71mI6/3ZTwWXymP7dzg0hkZbFbkHu2TONUo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SGGg3QFNVk5/K9U+VkQM4Vvdg61UVFiRVDW0GLR8HJSWZJwZ7WA/O2asjN/PTKwym ODMmONGUkS2i87cIZtS4Yzc3fDePHAPp+ASKg0DzhoFRuK5SbCNymWRCoo6agmOx7+ v5esgH736HUtdVdZZBp/UWpox6zahcr1JObJ+rAk/jdH07zAwTbSgcgg0d7SgRoHiR 3V8aEhHj0+TwHhdl/VUFnvscDjDSCh9+EZitNxpwweX48+9kBhKZWTmGrNkk1YRFbI uz38IShxkzxNAJ+qTGnsfayHZKgIx0hUpEXDQVsd14u6jOTFV7Y+/PYnQVHV5Vj7Ws 2J+xXLjsJuA6g== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:39 +0100 Subject: [PATCH v5 08/14] rust: hrtimer: implement `UnsafeTimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-8-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4022; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=AGCwY1Om71mI6/3ZTwWXymP7dzg0hkZbFbkHu2TONUo=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYYwtCBpF0UKh7xFacK6svSlIP1W/4Uem2wy JnDK0TyvH+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWGAAKCRDhuBo+eShj d/lkEACfvalN6T5UYMPXsLzwVE9GbPqTgKceSu5/qW3Ql8ujryRhq6/zKMunRSwTJXvuO3vtxM+ R79BRWlQMD5kKi7Hzh0swOPRE1+tsHHRtV5gIGZPDa21zoawbtBa87HdCFnE3K2Mizu9QcYBHKq Mp5DU2IYM1WYpsAUbusBLcrUeSeRQT8qG9i9BLR01AtD7GLNwAMdQoz39q9N1FB5/fRrR8U9vin sgzQahZMOvM5jmxMXOW4+OkuB7Dg/Stt8H//5H01uJdb3gpEQ1hUQLZk7Q6YBtmVK6gr55Rx31M hq2C422ycUMKFf2GpeTWVaSpT8TrjWfdR57+7WO9uW1s1+vB6w22nDj3t2eiF/BvCHVetn/psS9 J+I5zurw+NsFSoSW5jsaCD69+MjJUxannOxmMf2T8eMtkQkZRLZ/PVX7OxqgZx9mBVf6MYiM+Jb gyoRkakN/MLB22otzn6IIvdy4UfCRb3ilupgg/41iy+EZwbtHUvgVe1QZXKuvms4jrNfdydlYWo /p3zqtbnO9dvoXYfAW9HfJiXQyozITvsnAmUtNAxc2PEnRh3qeJITIrMvVUd3l3SXATwlTvzO6A hg/QPGd8qHvUJvmoEcDiQoeBJ+GeQNiAgbf7wvk5SfvxyBjWn4NrflykHmdjWaHK2rs1/saHTBz Ts3YMaZptsKodmQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned references to structs that contain a `Timer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 1 + rust/kernel/time/hrtimer/pin.rs | 95 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 96 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 6b03eb4b42dbd6447728c42949a2f93d736dc3b0..00172cb50ff153ef2b911f5025b= dca40b995e825 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -396,3 +396,4 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } =20 mod arc; +mod pin; diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs new file mode 100644 index 0000000000000000000000000000000000000000..7b251f157b2c196a3bde220b126= 19ce0c0ecce6c --- /dev/null +++ b/rust/kernel/time/hrtimer/pin.rs @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasTimer; +use super::RawTimerCallback; +use super::Timer; +use super::TimerCallback; +use super::TimerHandle; +use super::UnsafeTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&HasTimer>`. When the handle exists, the timer mig= ht be +/// running. +pub struct PinTimerHandle<'a, U> +where + U: HasTimer, +{ + pub(crate) inner: Pin<&'a U>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, U> TimerHandle for PinTimerHandle<'a, U> +where + U: HasTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr: *const U =3D self.inner.get_ref(); + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(self_= ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `Timer`. + unsafe { Timer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, U> Drop for PinTimerHandle<'a, U> +where + U: HasTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a `PinTimerHan= dle`, +// so `Self` will outlive the handle. +unsafe impl<'a, U> UnsafeTimerPointer for Pin<&'a U> +where + U: Send + Sync, + U: HasTimer, + U: TimerCallback =3D Self>, +{ + type TimerHandle =3D PinTimerHandle<'a, U>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `U`. + unsafe { U::start(self_ptr, expires) }; + + PinTimerHandle { inner: self } + } +} + +impl<'a, U> RawTimerCallback for Pin<&'a U> +where + U: HasTimer, + U: TimerCallback =3D Self>, + U: TimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `Timer` is `repr(C)` + let timer_ptr =3D ptr as *mut Timer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `Timer` contained in an `U`. + let receiver_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `Timer` contained in an `U`. + let receiver_ref =3D unsafe { &*receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + U::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Thu Dec 18 00:05:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E413B1F8666; Tue, 17 Dec 2024 15:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448841; cv=none; b=ftL5llK6CUG2vcTGD0u+7sOdmS4gphBMlp1FDcaOilEqvq1k/4t56PhPLscdGSrmYoiGOZFsgjmCTICA0aNZww7WRn3EbI1Y9PeMSs8bIBcIjGtXsWEx7wWz8PrxLRHcqqmCWql0HR+ycZulgG+CpgvYC2ZV9if8vCnQ2HdNXnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448841; c=relaxed/simple; bh=5Yt7jBm0gYPrBh6n87ngEjFAFMCg7ynZ/CL4taawfrw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oUYsb7CPyDVy94+hpRWaZTgknOsRUbGQnB6xiLSJE6v1grPILBTOqqpiCDc48nXB3SDfZYIbIeAHCpCy+RVctXcsZd061wisFqoOgaHzrrl1ktXbA8rftL80f/SxWpRWI46N4CMd4SMEtJjuNhYzglhhvpSzuQhQ5eJZQ+rVB70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EMRlDaAT; 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="EMRlDaAT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F163EC4CED3; Tue, 17 Dec 2024 15:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448840; bh=5Yt7jBm0gYPrBh6n87ngEjFAFMCg7ynZ/CL4taawfrw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EMRlDaATeJ4kwnqvpwPwM1LwaJ8qV6bfkXnBAW91Ty/KYbLfkZtIY0P4aW1Lx/Xap qSQ3CeiB4c/j/SeE8V+qxrRtQcqBI1zJDlS/cnLRWGZH+44xmEjB2igT8/AvnDw7pM wD6jYYaZhSARmlvbWrdO8DH5ZHrdOQGyyEC/1niBV2ZPXZZ9sxvuhj4SC8t2LKY9AC bS0zUBKjZ6XQ+k6Q5zhbX9zpWPwwtxnlqMbfRRGCYGgcvs1ne61MvY4kXwvSW3o2CZ cEKnBiTrdFwkFcY9ayaO/V8OpUvCsJLI29uXagDhNQN29HFqew8zZpg1xxhIintx80 935MeEeGoPLPw== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:40 +0100 Subject: [PATCH v5 09/14] rust: hrtimer: implement `UnsafeTimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-9-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4236; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=5Yt7jBm0gYPrBh6n87ngEjFAFMCg7ynZ/CL4taawfrw=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYZOg/XWDhRuPjFHq4lXw7hp3WhvDU8418iI YC0YuKebmaJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWGQAKCRDhuBo+eShj d8wVEACYy/zUfMd+xmKlTGeUy8uAumKd2euRbCwuHmIcyCjFcoxHLd4PKPwtbAZoIakWBtM0o6c 5xgGIjq98qubyg8+VnjR0gYt2qjVmuvEXjnl00mah3qkhevkC1msGzIEwkdE36VC64zr26ILCB6 eg+WrVrtGWVdQdv30odBd1ENH58Mz09hbBIpLptr6K2iaA7Y6N+Bj/k8Cemv+qqVYxixABANXXR Xwob9CoJwDtRv0vt7LdwmN9xjRzFg9M6dL7tnWUIiVSXrKVJ0dKnd+F8g2xu/+LwjpE+FIb79XG IN7cBllcBjMijo4dV5MHa89GBTPnsfQb1MZSJN/+M/5H6LsM10aBGb7lLXOfN7Bz0ceIFmC+Pkg aEs6pVRNNlwT3BdSE8ypA84OBTKlTKSRLBSvLb65NBsc77jgZQJ/t0ytVC+vrXvm2I2wwQQeduS 6A1/dEHEt8yvSBowk9DC548SPaLNDSw1nxtXYhSMNnHKpEK1LroAENOHJbXNWSo484lrrcbi9Ka Y7+LestMhTudIFWrru/JPsd0mlKkR44DWa4okMYCr9jLzMLW5qhrcoj/qd4x1oMmKHMShJVc3hg ol+LnouFrhgbRnbfO4UICKJXuMHmLqwNjqD6ebIhaKIdrawtkCwuDn8rfKGhEHIS6nmfNekXMix ZAxYthucH2T/zlA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned mutable references to structs that contain a `Timer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 1 + rust/kernel/time/hrtimer/pin_mut.rs | 97 +++++++++++++++++++++++++++++++++= ++++ 2 files changed, 98 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 00172cb50ff153ef2b911f5025bdca40b995e825..c223f1385c723a0b75e7f8184de= adbca38872e0a 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -397,3 +397,4 @@ unsafe fn raw_get_timer(ptr: *const Self) -> =20 mod arc; mod pin; +mod pin_mut; diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs new file mode 100644 index 0000000000000000000000000000000000000000..50ba9109919838aa9b09381000b= ab4ab8d3a2340 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasTimer; +use super::RawTimerCallback; +use super::Timer; +use super::TimerCallback; +use super::TimerHandle; +use super::UnsafeTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&mut HasTimer>`. When the handle exists, the timer= might +/// be running. +pub struct PinMutTimerHandle<'a, U> +where + U: HasTimer, +{ + pub(crate) inner: Pin<&'a mut U>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, U> TimerHandle for PinMutTimerHandle<'a, U> +where + U: HasTimer, +{ + fn cancel(&mut self) -> bool { + // SAFETY: We are not moving out of `self` or handing out mutable + // references to `self`. + let self_ptr =3D unsafe { self.inner.as_mut().get_unchecked_mut() = as *mut U }; + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(self_= ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `Timer`. + unsafe { Timer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, U> Drop for PinMutTimerHandle<'a, U> +where + U: HasTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a +// `PinMutTimerHandle`, so `Self` will outlive the handle. +unsafe impl<'a, U> UnsafeTimerPointer for Pin<&'a mut U> +where + U: Send + Sync, + U: HasTimer, + U: TimerCallback =3D Self>, +{ + type TimerHandle =3D PinMutTimerHandle<'a, U>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `U`. + unsafe { U::start(self_ptr, expires) }; + + PinMutTimerHandle { inner: self } + } +} + +impl<'a, U> RawTimerCallback for Pin<&'a mut U> +where + U: HasTimer, + U: TimerCallback =3D Self>, + U: TimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `Timer` is `repr(C)` + let timer_ptr =3D ptr as *mut Timer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `Timer` contained in an `U`. + let receiver_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `Timer` contained in an `U`. + let receiver_ref =3D unsafe { &mut *receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + U::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Thu Dec 18 00:05:30 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B04951F756A; Tue, 17 Dec 2024 15:19:49 +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=1734448789; cv=none; b=EuddusZaHdl58mGuBThJXXAjoRV/KL8Y3elQ9goK7De9FFPqcfFvINFEKXiYvjRGxpfK/6q9CESHS2lRuf+16x4404+w0bBjqJ/SEfDBp9b932VZb/yCWjulGuJoVw2/5XqirHE9ER1ge86l902k68Bw9bQ40uXY3ykb/Rd0M78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448789; c=relaxed/simple; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DiVB460ern+XS1JbzDCBCXRIyHeo1eqCGNWEErdPURaHSVyJuR+IikfgAf6QXGEycu4E3bPO85ZNFOcfs2q0G8fh03CfE5irWYzXekQ18z3XoLU2uqXXR6dBX1LBaPxh3EcnYOeYauyrpTToE4qS/r7R2HbbIlMf8vuUrZklfhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g73mysGz; 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="g73mysGz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58E98C4CED3; Tue, 17 Dec 2024 15:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448789; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g73mysGzY4FlzIF/yXDocP6p6QPDOIltz9Z63FUBi2YT7QjK5dZus0UFra4KHbtcM h3LLo3OGh7VwAI+dIlVabRGl3x0X9RgBRSQ2hh26IjeJ4CLbzflqqdS1HNEOdR0dgo 4icpWoga0DKPJTDH4L2DVXs0oABe+wcw9V/TqZ441uRGWhdgjQ+u/EZo35Rt7YDN3+ UtKbQPAbR3gG//MUXmbtpJrW4UBIRR7VeCm9a4QiFIL7jyiJddT9qETgPQibICg0DI LpSQLZ5bBHfTkz7YzeJFl6df1dgOnZVnF7FFGDrIcO3zMqE636PhxkOpBe2FmYdWnO bf3jhi2oyOwzA== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:41 +0100 Subject: [PATCH v5 10/14] rust: alloc: add `Box::into_pin` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-10-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1038; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=tQDyXQBkG1q5qjeehMfyrhkTdqTA2BWMVmg+Cs7DewM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYa8FW1fCsxZGSXIoOnApX+Ctiyu18dNwdOD tIhiDcX7YCJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWGgAKCRDhuBo+eShj d1YeD/9iWxBXfT7oNlagXsQrkPOKezGkUUCsvIrHvGRLU4pup1NktEhrtqZ6hxUxxC6X3VLh1P8 1rCRAKEZDwdZ2acgwEefH+qhF2ARQ5Jc6JVkBQ2mBH/qSaxniFg/002Klz7FqatgQyIGl8G9MsR XNXb6vgPzjx6HUXLKjUwOo4Cb5neHOCjKkwOHbxdW6xAx5OUZTvItv72FyvYBcT/4E2JFZPUbLu pn7DxxvgSVNvY2taDG2tYy0GyNRHTNAO1jiC0ir3dQNlsW5dLI2YattkS6iXFR9WfEDiBKjme7E yUTsiqXw6xMZ4UhjjC/tq/Z1FtXWEjf83G2w91cV6FGXp7K5/mwAevpqckZTBvoascY/1bC4BXF +Gy4fTN7A6Jmyj1pV3EyIYAbGxusbhE4MuyJCxb9iiqllkNedCL4TMq14qSSwoqTBa3q37PH9My 6uvhfFx4honW1niDKMJfGSGIbcN6udyONqsggiHwusQZfyJTtZlCvnHZCM1vzIty90Wai9CH8hy Sy+87htlJypAkrPsoUqRpcpa6os2k+symoNAMT2dA6fTKWhC9PQpp0VzsLYI4Mtgl03xDIN1CPe T/adAoNnoce7KDCKXbwIvDpRKQM/axCNGDulAI90GC76SirDxbabTP+cnT3InwBmDoKQDssbmsg jWciMDnZTXhChRg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add an associated function to convert a `Box` into a `Pin>`. Signed-off-by: Andreas Hindborg --- rust/kernel/alloc/kbox.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index 9ce414361c2c6dd8eea09b11041f6c307cbc7864..76f29e2ac085e19871f18653cfd= df11d2594682c 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -245,6 +245,12 @@ pub fn pin(x: T, flags: Flags) -> Result= >, AllocError> Ok(Self::new(x, flags)?.into()) } =20 + /// Convert a [`Box`] to a [`Pin>`]. If `T` does not imp= lement + /// [`Unpin`], then `x` will be pinned in memory and can't be moved. + pub fn into_pin(boxed: Self) -> Pin { + boxed.into() + } + /// Forgets the contents (does not run the destructor), but keeps the = allocation. fn forget_contents(this: Self) -> Box, A> { let ptr =3D Self::into_raw(this); --=20 2.47.0 From nobody Thu Dec 18 00:05:30 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CD58148850; Tue, 17 Dec 2024 15:19: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=1734448772; cv=none; b=FlIdSNueckqJr9jzLvX3WrEgR7NK0+4go0CxymO4cuxFteBZaH9YVz56QXTYyeZf8RBI1Y9KLT5VAza3mXDnZagBmGor0vDnNFsi1NZgH48BdwC9dU16jv3qAGjmc80a4ko/5h7uG1YfwrQZhrTHY+k/yq7QU2gZ0sr/qdGHSnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448772; c=relaxed/simple; bh=IockKtI7QGJV7LebkeC6HsGmg4JRpkVZ9iWx/ck781A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L53GJmxKjTphY4qoBl5ut9viVirFUzODde9IDK7wKm0SIvCqYL2PbPNhv+B7wKUtsHRFZpN0OzeN5sB9pLA6FtbCjQE8gt59h1GxygV78Ow8tDgjEMTntziHvSRmhrRvK6BYZuZLSconzijRnWP3hOaf/8yTIHDHD/gx6hv21Qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g1cLTgo0; 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="g1cLTgo0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF432C4CED6; Tue, 17 Dec 2024 15:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448772; bh=IockKtI7QGJV7LebkeC6HsGmg4JRpkVZ9iWx/ck781A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g1cLTgo0pmaywInUfUscY/Q9kujnLjO+lBMaYtjabvNo6mKwISjgvD48am9vkEtgz vrYuTGg32sJhCFAB+EsXL2tkEgdlrxtRXZowVoOXMJWjcRKqPSEZY5PfgdyBEE8uTB d18R8lOd8pYz5GHyy+Fy4/S7jqIFqFLZWVRO6SE6O0wUbcKxgzFCXjrwPviKumUkZX DmNnbGUitAM3oOKVHawUKhMA/SK/AU46gVkMy1GkxjoLWAa5vwWZW7XkYnCzDs8EDc /nxH6729Hl+lwhLmnnCQdSCgALfg+4vbfvnHVOM+pRBFlfXmbr+/6YdboHLbIztKvT Pk2pTacqlKj7A== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:42 +0100 Subject: [PATCH v5 11/14] rust: hrtimer: implement `TimerPointer` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-11-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4446; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=IockKtI7QGJV7LebkeC6HsGmg4JRpkVZ9iWx/ck781A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYbVJ45/hEWh8UYwRE6hMhUIHwpq62jdxXhK ES/LrNETCuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWGwAKCRDhuBo+eShj d8qtD/9nfl55jzwMkmbLmSa+P5NcDaQYKMTNZIC2VGBPwoq49MxUF10Mtl2uq4NmCqWUeywPmUs 0zRBTAQhMOW9vaGwRuakB4UldRekWt0dD4EJqylb9fqW55dC+veNrT5pgq55JvxpnbpAFmBHNSx P1KIIoMguGwf1lyxlJm/dd+NHzNduN5YW9KYXzXfsQdduWy5BZxRWJp1zpQWGE02RpxtsqttW2t N7HURVG85M7BfiX8BDndNAWjXpBekDaYNiIXF0bB51f2Q81Jri2aHbnxPvgNgj13om/2F4pVwr7 SkwjUS6JCP6L4e/jQtY+3ejnEhNkJy5tmTRL9p1BZWwDYibMz+ml7AG7AE+n9Gyvci9CnmT95ax Y9oP6qC/uq96NrOnErMz5oyv0TE2TT1uMw81oO208Lbmv6EqNeyPnvLc2rtj5ynYpOrLj0NkT71 KJ/D/h70Hgv/GkwXxXBOCD9Ycny6OoWRzOD4BzPflYGJPzMZRgfd1R9n4CQv7RKAip5+C8Sh9cn RbB6LuIORoS2A0FZHTESRD54qgSZ6hOJ+cnqqG+JXen2BfaVh5N/pPO/g2188yFlUu9sQdShRPD NZuCrvS7dGv1JDrRBupVvdnezWJCkHMzU9oGEx+s/XrQchwKatSwhj1L93Fc0YXS1SaT1x/LBqV J7cEhf98uRLfBcg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow `Pin>` to be the target of a timer callback. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 3 ++ rust/kernel/time/hrtimer/tbox.rs | 102 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 105 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index c223f1385c723a0b75e7f8184deadbca38872e0a..46dbf0d7fe30d271a2b76af89cc= 4e9e18b42a19a 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -395,6 +395,9 @@ unsafe fn raw_get_timer(ptr: *const Self) -> } } =20 +// `box` is a reserved keyword, so prefix with `t` for timer +mod tbox; + mod arc; mod pin; mod pin_mut; diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs new file mode 100644 index 0000000000000000000000000000000000000000..4b932a20cf6fcacdff7c40fc280= f8d73a45addc0 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasTimer; +use super::RawTimerCallback; +use super::Timer; +use super::TimerCallback; +use super::TimerHandle; +use super::TimerPointer; +use crate::prelude::*; +use crate::time::Ktime; +use core::mem::ManuallyDrop; + +/// A handle for a `Box>` returned by a call to +/// [`TimerPointer::start`]. +pub struct BoxTimerHandle +where + U: HasTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: *mut U, + _p: core::marker::PhantomData, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl TimerHandle for BoxTimerHandle +where + U: HasTimer, + A: crate::alloc::Allocator, +{ + fn cancel(&mut self) -> bool { + // SAFETY: As we obtained `self.inner` from a valid reference when= we + // created `self`, it must point to a valid `U`. + let timer_ptr =3D unsafe { >::raw_get_timer(self.= inner) }; + + // SAFETY: As `timer_ptr` points into `U` and `U` is valid, `timer= _ptr` + // must point to a valid `Timer` instance. + unsafe { Timer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for BoxTimerHandle +where + U: HasTimer, + A: crate::alloc::Allocator, +{ + fn drop(&mut self) { + self.cancel(); + // SAFETY: `self.inner` came from a `Box::into_raw` call + drop(unsafe { Box::::from_raw(self.inner) }) + } +} + +impl TimerPointer for Pin> +where + U: Send + Sync, + U: HasTimer, + U: for<'a> TimerCallback =3D Pin>>, + U: for<'a> TimerCallback =3D Pin<&'a U>>, + A: crate::alloc::Allocator, +{ + type TimerHandle =3D BoxTimerHandle; + + fn start(self, expires: Ktime) -> Self::TimerHandle { + let self_ptr: *const U =3D ::deref(&self= ); + + // SAFETY: Since we generate the pointer passed to `start` from a = valid + // reference, it is a valid pointer. + unsafe { U::start(self_ptr, expires) }; + + // SAFETY: We will not move out of this box during timer callback = (we + // pass an immutable reference to the callback). + let inner =3D unsafe { Pin::into_inner_unchecked(self) }; + + BoxTimerHandle { + inner: Box::into_raw(inner), + _p: core::marker::PhantomData, + } + } +} + +impl RawTimerCallback for Pin> +where + U: HasTimer, + U: for<'a> TimerCallback =3D Pin>>, + U: for<'a> TimerCallback =3D Pin<&'a U>>, + A: crate::alloc::Allocator, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `Timer` 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 `Timer` embedded in a `T`. + let data_ptr =3D unsafe { U::timer_container_of(timer_ptr) }; + + // SAFETY: We called `Box::into_raw` when we queued the timer. + let tbox =3D ManuallyDrop::new(Box::into_pin(unsafe { Box:::= :from_raw(data_ptr) })); + + U::run(tbox.as_ref()).into() + } +} --=20 2.47.0 From nobody Thu Dec 18 00:05:30 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7B191F7597; Tue, 17 Dec 2024 15:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448777; cv=none; b=ri7VmhoDDKwNjCXWavdlYJFin+ebiJz8mD8udKGarjpz2xW5RDT15iXFg4hU9oErCRYJprRf0+9NusOiFK8ezc+UcXsUFtUtUr2z1Cs5MZ+01D4Nel6tsevcmdfR/UWUdP3lsi8apVMB/cFmaCw40o/Ael71Kv/8fiq/jAGYd2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448777; c=relaxed/simple; bh=PgyZwM1wmVnFNYZFv0HvXUEMJw1qjAFl5cH9ilxk0H0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cshUgbOBAooN17hllviX/XOPJ4bQyLjiEgOt5gH01aQCvEYrR6/lBLVQGMBDgJ+2cQTZ0LDbuo+oYDsb16WgJvt9gRgL9DTJc3rD3+VyXNHKFhNfVHc5JyEnwNROqulzT4Dh8voMWbKwq5NT8C4TVZ+NKZuXvjQiogvve/TgZ/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kdXiYmp/; 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="kdXiYmp/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C02D1C4CED6; Tue, 17 Dec 2024 15:19:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448777; bh=PgyZwM1wmVnFNYZFv0HvXUEMJw1qjAFl5cH9ilxk0H0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kdXiYmp/S3GkNrWUmDZDSfHnntNq+MM4bu8mczW66UvayN85iDh7Bn+KpbATfiCNZ yczGj++oivgj+zR3svAGQpzS0l0Q1wyWJ/CskAIO/uWhW0AQAv4gs8GtMzyOW7fiR1 R4HXqOBEXcy4nu+YoTXzvCIOb9XYO0giSt7bL08IZB6nT5YaepOtuxh3oUJC2HkDGe uxWhTHjqrOBzKC+LsbF7hX+2nrR7lkrH+Y4kCgPpt5diEHviVINFGi5YrcBHQYFmvi eHqN9KlwFwlfHyh2Sh5Sr+4ugB1OkRX8t0Ge6cKIwhDY/jbxqtgmZJUbCf2hM2OFL3 9mzFnEk9P6Ehw== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:43 +0100 Subject: [PATCH v5 12/14] rust: hrtimer: add `TimerMode` 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: <20241217-hrtimer-v3-v6-12-rc2-v5-12-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5693; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=PgyZwM1wmVnFNYZFv0HvXUEMJw1qjAFl5cH9ilxk0H0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYcuvciGdEOtumQPS2SmX9EixXlRvlys19dA TWPd+ZSLg2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWHAAKCRDhuBo+eShj d50VD/0Z1mnaHnG27YpYmztMpg4SrnfRn9x9XcUAWXrcbUbNanaYtmr+ZoDIOUc7tU5xC/1R6Uz vCB1K6HtdS1Hn34cpUBd/t5ToKLpSe5XHiaEySGrwxLKYLKkGBfZYjVgFElvB8r8oUakL7GFClt G9gN78YPhKeklPxID/wSRv0noKYQ9SOEWO7PjHE8dkyBLG/wxntWbsYLRl2EhaHsLImQOlGoUyR 5Fh31PQ8FO8Nzu6KwEp67nI+1Nzo10Qpe3Ujj5rHqXKw9Z3+GbL9da2Kgj9cxoDtBXEbaa+yfaK Lswx8E44WwRfMTv9BaLoCz7kqGo+tmY8EeOndxawzdAgahJeUlVykUSFEfUW4bk2/dNIkBwCP3e wwqNPgfTXluS5Rakt1vikWBvkkJRdE2wY9czrcQ7rjHHhmOysSh2dM2v+abPJIWv1LC5LsIqh9i MRWLwvXh6NiEMX7WMSXKnSCCL2KLQGNIIJ/7X+JWuSTE6H494d9txpmHIXxTQm2kXmrc4RZgAi7 pWUBHk0ZYhvavHr2nayK4+FK7SqBfuo6pIGqjeF6p4hF5cl87rpbXyZUg0EiyEneyLhQFajKamm l5tur+PDDwcghLlmP+jDzUI8ADedoTuvtZDlYl8hcLNAxNKATnCTy9w9Q07daZIb5RR+7KkOSo3 K0/oVZyqlwCuoRA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selection of timer mode by passing a `TimerMode` variant to `Timer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 87 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 46dbf0d7fe30d271a2b76af89cc4e9e18b42a19a..17cf7c1d704d5e900ad4d08e642= e02b1e518badf 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -43,6 +43,8 @@ pub struct Timer { #[pin] timer: Opaque, + // This field goes away when `bindings::hrtimer_setup` is added. + mode: TimerMode, _t: PhantomData, } =20 @@ -55,7 +57,7 @@ unsafe impl Sync for Timer {} =20 impl Timer { /// Return an initializer for a new timer instance. - pub fn new() -> impl PinInit + pub fn new(mode: TimerMode) -> impl PinInit where T: TimerCallback, { @@ -70,10 +72,11 @@ pub fn new() -> impl PinInit place, Some(T::CallbackTarget::run), bindings::CLOCK_MONOTONIC as i32, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + mode.into(), ); } }), + mode: mode, _t: PhantomData, }) } @@ -322,7 +325,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(), ); } } @@ -363,6 +366,84 @@ fn from(value: TimerRestart) -> Self { } } =20 +/// Operational mode of [`Timer`]. +#[derive(Clone, Copy)] +pub enum TimerMode { + /// Timer expires at the given expiration time. + Absolute, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + Relative, + /// Timer does not move between CPU cores. + Pinned, + /// Timer handler is executed in soft irq context. + Soft, + /// Timer handler is executed in hard irq context. + Hard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + AbsolutePinned, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + RelativePinned, + /// Timer expires at the given expiration time. + /// Timer handler is executed in soft irq context. + AbsoluteSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in soft irq context. + RelativeSoft, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + AbsolutePinnedSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + RelativePinnedSoft, + /// Timer expires at the given expiration time. + /// Timer handler is executed in hard irq context. + AbsoluteHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in hard irq context. + RelativeHard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + AbsolutePinnedHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + RelativePinnedHard, +} + +impl From for bindings::hrtimer_mode { + fn from(value: TimerMode) -> Self { + use bindings::*; + match value { + TimerMode::Absolute =3D> hrtimer_mode_HRTIMER_MODE_ABS, + TimerMode::Relative =3D> hrtimer_mode_HRTIMER_MODE_REL, + TimerMode::Pinned =3D> hrtimer_mode_HRTIMER_MODE_PINNED, + TimerMode::Soft =3D> hrtimer_mode_HRTIMER_MODE_SOFT, + TimerMode::Hard =3D> hrtimer_mode_HRTIMER_MODE_HARD, + TimerMode::AbsolutePinned =3D> hrtimer_mode_HRTIMER_MODE_ABS_P= INNED, + TimerMode::RelativePinned =3D> hrtimer_mode_HRTIMER_MODE_REL_P= INNED, + TimerMode::AbsoluteSoft =3D> hrtimer_mode_HRTIMER_MODE_ABS_SOF= T, + TimerMode::RelativeSoft =3D> hrtimer_mode_HRTIMER_MODE_REL_SOF= T, + TimerMode::AbsolutePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE_A= BS_PINNED_SOFT, + TimerMode::RelativePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE_R= EL_PINNED_SOFT, + TimerMode::AbsoluteHard =3D> hrtimer_mode_HRTIMER_MODE_ABS_HAR= D, + TimerMode::RelativeHard =3D> hrtimer_mode_HRTIMER_MODE_REL_HAR= D, + TimerMode::AbsolutePinnedHard =3D> hrtimer_mode_HRTIMER_MODE_A= BS_PINNED_HARD, + TimerMode::RelativePinnedHard =3D> hrtimer_mode_HRTIMER_MODE_R= EL_PINNED_HARD, + } + } +} + +impl From for u64 { + fn from(value: TimerMode) -> Self { + Into::::into(value) as u64 + } +} + /// Use to implement the [`HasTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Thu Dec 18 00:05:30 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B19AD1F8906; Tue, 17 Dec 2024 15:19:55 +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=1734448795; cv=none; b=IyTrmz3AbC+BvaDdS0RYtRfsyR8GatxnwLSFv62j6igzNu8ztqsqh83YCAjSg7gPRWipqpFp/LhZ+OQaAXHJF+44fcgZux22+o5oFSyWcu7Kk9GdGS74wtv4RiREv3xJQgYYc+rTNtb/4mAQSIB0DxuSA6ybsmPOo03uDyli/VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448795; c=relaxed/simple; bh=9FNldwPp52UQBwi+GTczE3aFsHu8VA7iPdgnD1jtrW0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kUrL9EwM0i95EeWETriaJoOu+Aad3HT4MDCyO1alrKOwkJWNbEnnKeOuxVKH2ZoWSnZGTskdqGbO9BaFM4aTzryIrATrTvFe7Gx/nyxPn1b/NatP3glXbEUgSF94rTqZ6ssozzTWK/CkPMDHAL78IUDj4SQznkWRF2akcsBnVZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m9+aVcZ1; 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="m9+aVcZ1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CD4EC4CEDD; Tue, 17 Dec 2024 15:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448795; bh=9FNldwPp52UQBwi+GTczE3aFsHu8VA7iPdgnD1jtrW0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m9+aVcZ1ovDl6R4zpRgyYkvsmI7bfhYhHuQW2xFooFv8yfA5uPtswpLUOYOwfoDbo aERx9mnOwEJ89uF9qHxlAX4TNkcfWqm+UE8JJpLSFRetSz3JGoFrBSihuy5krww46U bcIjpJGaA0ysJe+zA0LChCqSp/crl5PjygCkjyjy7mwmjTrm9FQiTHu+Y9s8jVBDwC ctlG2gqQuh2XNs3PnsmUqF8N6viKZEQsfMLMGfPjXfAnGlnq0/VOvcIpsjMgOKBmII kKgGtDU+aoHOmCWfAAox3tEGL6wxp9w0VeoZETnmmploeUyccsJ+YA0l3lAJltqQDw q6qqsrjaTuRVA== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:44 +0100 Subject: [PATCH v5 13/14] rust: hrtimer: add clocksource selection through `ClockSource` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-13-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4032; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=9FNldwPp52UQBwi+GTczE3aFsHu8VA7iPdgnD1jtrW0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYdUHeHPy30TnlbH6nEd8VUbZrsFXanj9Qou CTWEIZv2GCJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWHQAKCRDhuBo+eShj d3b6D/9hXRtjJyRBMiwgOOzGEUlPaILg+QpYQEqN8KaDw8GR5lSYo2p1VCRJwTRvFu3JHwR3mCd +mPQmeD3XLmPTNTTi8oSTatyPN/R7/0Xks1Yussl8YeckxRyrsKwIzj0fXgdq7wtPyjVNrmlRPk xQMNEv4lmxRMecThEcekC1SiPCkqmq0SvZ6jyyFeXKuVFozMEfmC5KNU91A3bkWlxhn2DpodPlW nhhjADHub/rE107dOT4E/sFdDGNTEHXPRjEZLWoyhLw/+bTQ7prT7IHr7JmO6mi4YSOHHbnsqya rqgAHH6HIfwVqW5/Xh/Df8cuUBoCrIC/gF3Ajwb+iyZHR1j0lWUO6FBVE5bbmvduIh4Vjh/AmZc xwBEGRlgUk+02zdc6RluvYx48BgK2//LbqrALhG5aVrcI/XHrCNtO9Ia8ccs8bpL8GkLjDpbWNp y0LaA4j1i/Z9ubHZdFd2+WYdiB7C+O9f/uX0mKw4VKbrHdVN3c4Ljo+6d7TgCTbqH+Yh9BmvngY Z1VGQGEfbkyhJ3euFtlFuQqg7rOJHoazyCPrcRWBpIBIALp43MydsGXBQ9Y9OAn0VJGycDrjpsA z8H7vrZRS5a4dy4AL9kS/N3qG2bkrAyh5RTyJk9j90P2l6wVklfE2GNQcckoubU82ho1GSPiQEm srd6cOxMC6427tw== 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 `Timer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 52 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 17cf7c1d704d5e900ad4d08e642e02b1e518badf..f9be0fa43c896a09439601bea82= 5e5b17d0e995d 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -57,7 +57,7 @@ unsafe impl Sync for Timer {} =20 impl Timer { /// Return an initializer for a new timer instance. - pub fn new(mode: TimerMode) -> impl PinInit + pub fn new(mode: TimerMode, clock: ClockSource) -> impl PinInit where T: TimerCallback, { @@ -71,7 +71,7 @@ pub fn new(mode: TimerMode) -> impl PinInit bindings::hrtimer_setup( place, Some(T::CallbackTarget::run), - bindings::CLOCK_MONOTONIC as i32, + clock.into(), mode.into(), ); } @@ -444,6 +444,54 @@ fn from(value: TimerMode) -> Self { } } =20 +/// The clock source to use for a [`Timer`]. +pub enum ClockSource { + /// A settable system-wide clock that measures real (i.e., wall-clock)= time. + /// Setting this clock requires appropriate privileges. This clock is + /// affected by discontinuous jumps in the system time (e.g., if the s= ystem + /// administrator manually changes the clock), and by frequency adjust= ments + /// performed by NTP and similar applications via adjtime(3), adjtimex= (2), + /// clock_adjtime(2), and ntp_adjtime(3). This clock normally counts t= he + /// number of seconds since 1970-01-01 00:00:00 Coordinated Universal = Time + /// (UTC) except that it ignores leap seconds; near a leap second it is + /// typically adjusted by NTP to stay roughly in sync with UTC. + RealTime, + /// A nonsettable system-wide clock that represents monotonic time sin= ce=E2=80=94as + /// described by POSIX=E2=80=94"some unspecified point in the past". O= n Linux, that + /// point corresponds to the number of seconds that the system has been + /// running since it was booted. + /// + /// The CLOCK_MONOTONIC clock is not affected by discontinuous jumps i= n the + /// system time (e.g., if the system administrator manually changes the + /// clock), but is affected by frequency adjustments. This clock does = not + /// count time that the system is suspended. + Monotonic, + /// A nonsettable system-wide clock that is identical to CLOCK_MONOTON= IC, + /// except that it also includes any time that the system is suspended= . This + /// allows applications to get a suspend-aware monotonic clock without + /// having to deal with the complications of CLOCK_REALTIME, which may= have + /// discontinuities if the time is changed using settimeofday(2) or si= milar. + BootTime, + /// A nonsettable system-wide clock derived from wall-clock time but + /// counting leap seconds. This clock does not experience discontinuit= ies or + /// frequency adjustments caused by inserting leap seconds as CLOCK_RE= ALTIME + /// does. + /// + /// The acronym TAI refers to International Atomic Time. + TAI, +} + +impl From for bindings::clockid_t { + fn from(value: ClockSource) -> Self { + match value { + ClockSource::RealTime =3D> bindings::CLOCK_REALTIME as i32, + ClockSource::Monotonic =3D> bindings::CLOCK_MONOTONIC as i32, + ClockSource::BootTime =3D> bindings::CLOCK_BOOTTIME as i32, + ClockSource::TAI =3D> bindings::CLOCK_TAI as i32, + } + } +} + /// Use to implement the [`HasTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Thu Dec 18 00:05:30 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F3871482E7; Tue, 17 Dec 2024 15:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448829; cv=none; b=UysSFOBm5SkKov5aVseHhVOhiYGTpkFwbfIg9OCOt254k8xkw6HWbHXV3aefHwe1mjQWtiXvmUELjiXJozPlMfDshdDkWwV3+iugAxXYFTvb+k4qlmDioyP7OjDgp1tdV4LRZVJ3lPJIhTwY/vYRRGOvbqKVipxgL/QIqugqtlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448829; c=relaxed/simple; bh=HwVmaywQBF6mBbxl3xTMhNO72JJrVBJuegIGTS0ciAE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dLEDMlZolya6huM55lCiNSuqb7N7Qqdx0s812tJgpY9Ejbo31ogpkd4kSxRfV1hZ1ehzVARqhfFdq+PJpz7sS2ylxR9VJaPedSWApPhClFwCMgXQfcbLEQOpfBmCx834tRm5rH7f1gv0YEb9CaHyPDPbZNig8YZ+ztQq71DjPl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kTd3TOFs; 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="kTd3TOFs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A592C4CED3; Tue, 17 Dec 2024 15:20:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734448828; bh=HwVmaywQBF6mBbxl3xTMhNO72JJrVBJuegIGTS0ciAE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kTd3TOFsUafSgKyHjpD0bBazSzhL3nYj7AzVOSboMxeKj5k+xjwIRFYiwhhfYtLqI Lpdk50i3LbPCdUpx/V9uocuGAGIOUaHMiiqj9HF00Sfngv3OCpqRiie7o/d1RoWlye ymAlUTUhefEYI4fHhumK77ZsJsWFfaIBXaW6vI3ZhWqU/PeHwNxVta6g1j9Iy0Vmz9 owmI4aH9ugx6xhNoqjhMmNS23CVVzALhAOuPTV2Dd4HeoWIfBa9cistO5K4o3oQq6j HRmtSpe37OBKqlb082aE5wJf+yKYOmkmWfwIi0wsCvSRldTEp17wrmrt/6ie7NRMVM KXRLCYjdPbCbw== From: Andreas Hindborg Date: Tue, 17 Dec 2024 16:17:45 +0100 Subject: [PATCH v5 14/14] rust: hrtimer: add maintainer entry Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241217-hrtimer-v3-v6-12-rc2-v5-14-b34c20ac2cb7@kernel.org> References: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> In-Reply-To: <20241217-hrtimer-v3-v6-12-rc2-v5-0-b34c20ac2cb7@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=995; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=HwVmaywQBF6mBbxl3xTMhNO72JJrVBJuegIGTS0ciAE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnYZYeH5A1KHEcLUqMC28Fe/fPpBzACBJswt7Qh Mdkw08wLTGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ2GWHgAKCRDhuBo+eShj d6u1D/9XbLghAUxQYvgL4IIHukVZR/jwrAjtbXBi4EQ1jVAz9g2GShKJUujtfVEvHaV08n1/Da3 HtHeuf6r3k8Afemer7qWh4J9+/og2W6YESBERpV88bn/R5dhcBh+erObT98nrrjnnx2dvCUb5gr WqbyiIBKAW8HysaYP1AhTzz4JXsFlVuHVG93h8shuXR77V/LziuYo8Lu6AoVFnuW06Di1LIBIB7 MDb1tQ7J+Vb/DKJ1iyR+gvWfZhf4SjzbRDWLcuAYaT78gBKAmxU9SA6Ryj3+UCmFYkkpRzDm5VB kisa+NmlGW7z5UdPVMB46xWAdTF4NjQjtTPvkR6iJobdk/S2rVJmomBiCidFmI9FwQZcsmZxzCD X93HJTVY/brpeH7wI4SIq4s+INR/Yv8s/RR6Z1tkalXBVBTy0U6bx6pQJEIQEiM57JeicK8NJNT 6cqd/7c79QWMHt3eum0qKxOGGbeFMd2GMT5mZArXfKd6ujpVP2rmcrIFHWWp8NF8dBJggd4rQTi aQE8LxcCeWWbq2h3iHLN0ZdjswTkHuWku3Jff5GpdgcNpKKdSA+QoDFDZU16bMaXOXUAycAsm/3 e2YxzNBoDk1j0wh9jFRQTMimSHBsFwYT5m+E/KnruuXY/zWewgk7XHwPqlB646U2QbnjiUXQR9x 1bFySwMoDtEf/cw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add Andreas Hindborg as maintainer for Rust `hrtimer` abstractions. Also add Boqun Feng as reviewer. Signed-off-by: Andreas Hindborg Acked-by: Boqun Feng --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 1e930c7a58b13d8bbe6bf133ba7b36aa24c2b5e0..335ef0807516f047b5c84727f02= 76c4e88141c49 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10251,6 +10251,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