From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BE6C209679; Mon, 3 Feb 2025 15:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595414; cv=none; b=QIANIaRQMJBHn0mCjf33N2afvwQUIaNQMxKS8RBJsjzDp5o1B7w9xfSNr7u93bSyQgLtwfL7M6+4REELIEhIQ0nCCSnbxgTZRolKTriFQNyLbCDfc16iTCqT88u1ECg1LC7jazWAcSlxPN5/cc1FkjDwp8QsT4cNpmMECubh03k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595414; c=relaxed/simple; bh=WcA3kPv5iDC8b2KCR1IFW4zckDGb5vp23+fuV9V0gKQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ICGCNZ7ppZ6Q942h86HbOYahhIonj+1/NrHLrVjekf9C+sW3BwxGprqOWtxobmqmIHqmnzV4ITcl31buEEID4mqy46k3sRRr+zkSjhA9Z/e9V4wtVhF2H/EGF+GvxqnsTe2lBn/UBh56oy9IKhFBukhgPrcZXfNG0WuwLZPN6Hw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SU8WEnVD; 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="SU8WEnVD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87AA3C4CED2; Mon, 3 Feb 2025 15:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595413; bh=WcA3kPv5iDC8b2KCR1IFW4zckDGb5vp23+fuV9V0gKQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SU8WEnVD2dQGPdU457jC2LBRdJt6P/fZeDAkPNZenkPoU8YSpqnYy3lvdQnseK0Io pOLrUEywh/BHw99GVph1QYlNV9O57O+Plny+0rIHZPRcI9lr1vXM6DFhHIKeaMurOi dtBD/BMJhuO+BRLdwhd8jZ3vueV3eXSyJP9ieVZR7yK4q1U0LVAnb6geOuE5/tM+gJ zau30X3OIQ62M2ABJ5TueTlwCNQszfbEWz8yJ0Jn4S89uY7aOOn46STNZCnNIOd8B1 LOIr/gAaKU8MKND9gRqIhNbfn4R1EfONwHQzjIxaFBb1WlB8oLaoOxNq6CRpqRfq+h 8uDLOeJ6qlY3g== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:47 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-1-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1427; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=vRt29LHxNF2wToo1w0j7/SlmbaaQNhsEhnpJ66ceDJk=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvOEVdoIQm4tNaY3DSs3z3ZzxIRa/RcWefFj xvkkbI2T/KJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6DbzgAKCRDhuBo+eShj dwDBEACj19cU32sMiC+xa6Z6bNfGrCvqB6vxAIUivHvmwuww735I3fibjLJZaN5cpEf5QhMi9sL ihckviGV3r51d5lGIyn8KtvAmXRPrUuz+DV8ZFNfhdsNkOtAK9deVw1bAgmrdRD5TfSe3nN52h3 l5JFyF36gDlMZvaBNDT+y3RoFYvMcevUz+fpw3GFZbzCLqYXZlYskvPxs64J4v16oAmeMOe98gP NF34P1MmjXP7WonvyFW7RF6W5NcuIRC6lRE3xLNBtUBq8A8IBRcUwxbwURbTuJ4VXP/PDu035Jq DExWC0FrbB5qfwnVgNldk9UMbyjk8FRW2vtTgov7XqCup8MwXdVqBAEFLu09CbreYNgXeGvGcxv KRwK0mAezmLJ5sd37yj8pfLP5PD8hkfwx+zUAPUZO2OS6cLzWGB1n3VJsJ30L053fPHzXL48AJR OZ9OYEg8lpn0JT+PlWsXsqWpp/cCBQzqTJUdTx3ni/hCenm/3tB8GvOPeigbyR6ssxw3+pyQ2um YLe8lm969ebwvs2JixPOLHn4yV35GQ+yFqgITn8QNc+cqytQ+2lxSRIpcqL9q3DDeQ/6qJ7ChUn l6Cyf54HPyWjNYGGZUVHM1HFvHxEF5SOlBxddfwyyBeJ7hCa74+bCQ95SuS2O/FkiNMDpvD30H0 lAdUjsbymvmc7dA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 From: Lyude Paul A simple function to turn the provided value in nanoseconds into a Ktime value. We allow any type which implements Into, which resolves to Into. This is useful for some of the older DRM APIs that never got moved to Ktime. Signed-off-by: Lyude Paul Reviewed-by: Lyude Paul Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 379c0f5772e575c9ceacb9c85255b13501db8f30..87e47f2f5618d6a4c2e534dd7ec= 663ced0e91503 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -8,6 +8,8 @@ //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 +use core::convert::Into; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 @@ -63,6 +65,12 @@ pub fn to_ns(self) -> i64 { pub fn to_ms(self) -> i64 { self.divns_constant::() } + + /// Creates a new Ktime from the given duration in nanoseconds. + #[inline] + pub fn from_nanos(ns: impl Into) -> Self { + Self { inner: ns.into() } + } } =20 /// Returns the number of milliseconds between two ktimes. --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EA6720AF8A; Mon, 3 Feb 2025 15:10:34 +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=1738595434; cv=none; b=CLiTVDMGO4osFqY6JE1ZjqRmlc2uoksVtAFoELPQivOLZvXijwSfOQpL9qFUzX1tia7feSTbR/t9oX+EG7WizY+WxVnQwkzX769uNbF7ufpw/IMiS6yMQmVvOBrKX/vrCjr2jDOrqMsjZ3D3f6GdYtl1Krc+/luxTnKzwNrHgJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595434; c=relaxed/simple; bh=jHHMaktyyXYLeTY5poXFGTxt1juB8cB36eNgrPIGZyQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dRNDAGxnBgUKBK8uSxoximVRZ2i3W6Ujicl4quwtCZBciM1IskSIAu7nErTjyZwlCkmH0WZu6ABEZBM18mZdwx4IOsHdaKee5KQFUUR3byeyQ7s9JhEm2wqysFtBnwCRnPQseBLTXAMCivwmZsixjdu4sCyvIhHNslMj1fDdTgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hBV56c21; 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="hBV56c21" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AA97C4CED2; Mon, 3 Feb 2025 15:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595434; bh=jHHMaktyyXYLeTY5poXFGTxt1juB8cB36eNgrPIGZyQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hBV56c21KNgJ7WGuucnCVPhl/fAYBtzKOUXzmTQWU7qZODIrBwafrklfF8uxfdSVv ymdEkci5XHd9QgEmlVNej9N6kVqVbPu1ZmuCLAzYUcE5blZhNuSZavgtrbHRkMZW3z bgD0UdshmNo3fj7r8lQh+xsaWVkfxZmu40Xx9wX1A1aQmdZh42l9A+JDTD6N+RvvVO TfJL8pIV29BzpxjSH+wbVc+4SRn4TVIli8FfGakWPRHcSllvzP8Gu5ejF1EXVigdyY GIhXbPsb+DVy4MRInradwH1YEKNEUKDX6Bs8JaiI4Hds+31meiEbzrnKXs/TIPwcHI qmwnDLDuHH6pw== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:48 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-2-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=13047; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=jHHMaktyyXYLeTY5poXFGTxt1juB8cB36eNgrPIGZyQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvP5Pfbjz9tBDK8SaC7NryO8Ribm1OHAQqGw 5dBdmk+7QeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6DbzwAKCRDhuBo+eShj d7VHEACJozHtGCf8I3S448wZT5BdGspuMbz7bz0ocXjGJ2DrS2JwnWXcfrkGEeaOay4bpItTpIq DAhT8rRtKpqgWwUyYFKqDu3Ya8xQW+NJgQ53pARy3R8tn0z/umuiGAMgsI47Wxit7NXbzH1UYv+ GR0WkeyYv8hAyUMWX38AGCEv1/6BPW9MzruPuMmr7Q+LItKD7G83W0roTt7HeinFJb3R5l/g079 ImtQNgdMvtVCRFXqVs4oHXxssjLvFPjL8PscAfJuwAd+WKZAgvRJe1ae/qG5Vs5Ql6MIBlbt37d +SMrbB4PgmVfyNTGtiGnbkMniFUFzJgvJBcFi4qBz8HBY+/CDyTuYsLj3vjesVZVmpZvPjspM3h ZZwtDNA7PtPAx+71UOgPlKrYg+KNsTFhLxMEiBM5efQwVMiz9zvEHiZlvO7sMD7E4rZHse7pNzC 19Wy+l/60rtwExUvpfg79pCGMYPxM/n3f5Sc6gzCjxIHW8MQXHvTnvi4mroM60QpcRBpsrN5Lpf DaDfE4+fZUg9IObDNUD5pHLng3xxBafLrFUBkLrlaNM7/j0HMP9I4ul3zGlQTyEfFarQJ1pOXHY O3fq39FyeW0WxDRZFuTxRSgpbiBqfpliZmh8yhnDQ/tqjfxKmyejSGPblxaPNv+AuRSy9/VIBFW M0pNAEM1PXqcPEg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This patch adds support for intrusive use of the hrtimer system. For now, only one timer can be embedded in a Rust struct. The hrtimer Rust API is based on the intrusive style pattern introduced by the Rust workqueue API. Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 2 + rust/kernel/time/hrtimer.rs | 312 ++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 314 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 87e47f2f5618d6a4c2e534dd7ec663ced0e91503..2cf365cfb412e753367152a18fe= d1805d8033111 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..a6332924efabd40c475a112bbc4= 34db77596a16f --- /dev/null +++ b/rust/kernel/time/hrtimer.rs @@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Intrusive high resolution timers. +//! +//! Allows running timer callbacks without doing allocations at the time of +//! starting the timer. For now, only one timer per type is allowed. +//! +//! # Vocabulary +//! +//! States: +//! +//! * Stopped +//! * Running +//! +//! Operations: +//! +//! * Start +//! * Cancel +//! * Stop +//! * Restart +//! +//! Events: +//! +//! * Expire +//! +//! ## State Diagram +//! +//! ```text +//! <-- Stop ---- +//! <-- Cancel -- +//! --- Start --> +//! +---------+ +---------+ +//! O--->| Stopped | | Running |---o +//! +---------+ +---------+ | +//! ^ | +//! <- Expire -- | | +//! o------o +//! Restart +//! ``` +//! +//! A timer is initialized in the **stopped** state. A stopped timer can be +//! **started** with an **expiry** time. After the timer is started, it is +//! **running**. When the timer **expires**, the timer handler is executed. +//! After the handler has executed, the timer may be **restarted** or +//! **stopped**. A running timer can be **canceled** before it's handler is +//! executed. A timer that is cancelled enters the **stopped** state. +//! + +use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque}; +use core::marker::PhantomData; + +/// A timer backed by a C `struct hrtimer`. +/// +/// # Invariants +/// +/// * `self.timer` is initialized by `bindings::hrtimer_setup`. +#[pin_data] +#[repr(C)] +pub struct HrTimer { + #[pin] + timer: Opaque, + _t: PhantomData, +} + +// SAFETY: Ownership of an `HrTimer` can be moved to other threads and +// used/dropped from there. +unsafe impl Send for HrTimer {} + +// SAFETY: Timer operations are locked on C side, so it is safe to operate= on a +// timer from multiple threads +unsafe impl Sync for HrTimer {} + +impl HrTimer { + /// Return an initializer for a new timer instance. + pub fn new() -> impl PinInit + where + T: HrTimerCallback, + { + pin_init!(Self { + // INVARIANTS: We initialize `timer` with `hrtimer_setup` belo= w. + timer <- Opaque::ffi_init(move |place: *mut bindings::hrtimer|= { + // SAFETY: By design of `pin_init!`, `place` is a pointer = to a + // live allocation. hrtimer_setup will initialize `place` = and + // does not require `place` to be initialized prior to the= call. + unsafe { + bindings::hrtimer_setup( + place, + Some(T::CallbackTarget::run), + bindings::CLOCK_MONOTONIC as i32, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + }), + _t: PhantomData, + }) + } + + /// Get a pointer to the contained `bindings::hrtimer`. + /// + /// # Safety + /// + /// `ptr` must point to a live allocation of at least the size of `Sel= f`. + unsafe fn raw_get(ptr: *const Self) -> *mut bindings::hrtimer { + // SAFETY: The field projection to `timer` does not go out of boun= ds, + // because the caller of this function promises that `ptr` points = to an + // allocation of at least the size of `Self`. + unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).timer)) } + } + + /// Cancel an initialized and potentially running timer. + /// + /// If the timer handler is running, this will block until the handler= is + /// finished. + /// + /// Users of the `HrTimer` API would not usually call this method dire= ctly. + /// Instead they would use the safe `cancel` method on the [`HrTimerHa= ndle`] + /// returned when the timer was started. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + #[allow(dead_code)] + pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; + + // If the handler is running, this will wait for the handler to fi= nish + // before returning. + // SAFETY: `c_timer_ptr` is initialized and valid. Synchronization= is + // handled on C side. + unsafe { bindings::hrtimer_cancel(c_timer_ptr) !=3D 0 } + } +} + +/// Implemented by pointer types that point to structs that embed a [`HrTi= mer`]. +/// +/// Target (pointee) must be [`Sync`] because timer callbacks happen in an= other +/// thread of execution (hard or soft interrupt context). +/// +/// Starting a timer returns a [`HrTimerHandle`] that can be used to manip= ulate +/// the timer. Note that it is OK to call the start function repeatedly, a= nd +/// that more than one [`HrTimerHandle`] associated with a [`HrTimerPointe= r`] may +/// exist. A timer can be manipulated through any of the handles, and a ha= ndle +/// may represent a cancelled timer. +pub trait HrTimerPointer: Sync + Sized { + /// A handle representing a started or restarted timer. + /// + /// If the timer is running or if the timer callback is executing when= the + /// handle is dropped, the drop method of [`HrTimerHandle`] should not= return + /// until the timer is stopped and the callback has completed. + /// + /// Note: When implementing this trait, consider that it is not unsafe= to + /// leak the handle. + type TimerHandle: HrTimerHandle; + + /// Start the timer with expiry after `expires` time units. If the tim= er was + /// already running, it is restarted with the new expiry time. + fn start(self, expires: Ktime) -> Self::TimerHandle; +} + +/// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a +/// function to call. +// This is split from `HrTimerPointer` to make it easier to specify trait = bounds. +pub trait RawHrTimerCallback { + /// Callback to be called from C when timer fires. + /// + /// # Safety + /// + /// Only to be called by C code in `hrtimer` subsystem. `ptr` must poi= nt to + /// the `bindings::hrtimer` structure that was used to start the timer. + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart; +} + +/// Implemented by structs that can be the target of a timer callback. +pub trait HrTimerCallback { + /// The type whose [`RawHrTimerCallback::run`] method will be invoked = when + /// the timer expires. + type CallbackTarget<'a>: RawHrTimerCallback; + + /// This type is passed to the timer callback function. It may be a bo= rrow + /// of [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` i= f the + /// implementation can guarantee exclusive access to the target during= timer + /// handler execution. + type CallbackTargetParameter<'a>; + + /// Called by the timer logic when the timer fires. + fn run(this: Self::CallbackTargetParameter<'_>) + where + Self: Sized; +} + +/// A handle representing a potentially running timer. +/// +/// More than one handle representing the same timer might exist. +/// +/// # Safety +/// +/// When dropped, the timer represented by this handle must be cancelled, = if it +/// is running. If the timer handler is running when the handle is dropped= , the +/// drop method must wait for the handler to finish before returning. +pub unsafe trait HrTimerHandle { + /// Cancel the timer, if it is running. If the timer handler is runnin= g, block + /// till the handler has finished. + fn cancel(&mut self) -> bool; +} + +/// Implemented by structs that contain timer nodes. +/// +/// Clients of the timer API would usually safely implement this trait by = using +/// the [`crate::impl_has_hr_timer`] macro. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that the implementer has a [`Hr= Timer`] +/// field at the offset specified by `OFFSET` and that all trait methods a= re +/// implemented according to their documentation. +/// +/// [`impl_has_timer`]: crate::impl_has_timer +pub unsafe trait HasHrTimer { + /// Offset of the [`HrTimer`] field within `Self` + const OFFSET: usize; + + /// Return a pointer to the [`HrTimer`] within `Self`. + /// + /// # Safety + /// + /// `ptr` must point to a valid struct of type `Self`. + unsafe fn raw_get_timer(ptr: *const Self) -> *const HrTimer { + // SAFETY: By the safety requirement of this trait, the trait + // implementor will have a `HrTimer` field at the specified offset. + unsafe { ptr.cast::().add(Self::OFFSET).cast::>() } + } + + /// Return a pointer to the struct that is embedding the [`HrTimer`] p= ointed + /// to by `ptr`. + /// + /// # Safety + /// + /// `ptr` must point to a [`HrTimer`] field in a struct of type `Se= lf`. + unsafe fn timer_container_of(ptr: *mut HrTimer) -> *mut Self + where + Self: Sized, + { + // SAFETY: By the safety requirement of this function and the `Has= HrTimer` + // trait, the following expression will yield a pointer to the `Se= lf` + // containing the timer addressed by `ptr`. + unsafe { ptr.cast::().sub(Self::OFFSET).cast::() } + } + + /// Get pointer to embedded `bindings::hrtimer` struct. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn c_timer_ptr(self_ptr: *const Self) -> *const bindings::hrtim= er { + // SAFETY: `self_ptr` is a valid pointer to a `Self`. + let timer_ptr =3D unsafe { Self::raw_get_timer(self_ptr) }; + + // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. + unsafe { HrTimer::raw_get(timer_ptr) } + } + + /// Start the timer contained in the `Self` pointed to by `self_ptr`. = If + /// it is already running it is removed and inserted. + /// + /// # Safety + /// + /// `self_ptr` must point to a valid `Self`. + unsafe fn start(self_ptr: *const Self, expires: Ktime) { + // SAFETY: By function safety requirement, `self_ptr`is a valid `S= elf`. + unsafe { + bindings::hrtimer_start_range_ns( + Self::c_timer_ptr(self_ptr).cast_mut(), + expires.to_ns(), + 0, + bindings::hrtimer_mode_HRTIMER_MODE_REL, + ); + } + } +} + +/// Use to implement the [`HasHrTimer`] trait. +/// +/// See [`module`] documentation for an example. +/// +/// [`module`]: crate::time::hrtimer +#[macro_export] +macro_rules! impl_has_hr_timer { + ( + impl$({$($generics:tt)*})? + HasHrTimer<$timer_type:ty> + for $self:ty + { self.$field:ident } + $($rest:tt)* + ) =3D> { + // SAFETY: This implementation of `raw_get_timer` only compiles if= the + // field has the right type. + unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$= timer_type> for $self { + const OFFSET: usize =3D ::core::mem::offset_of!(Self, $field) = as usize; + + #[inline] + unsafe fn raw_get_timer(ptr: *const Self) -> + *const $crate::time::hrtimer::HrTimer<$timer_type> + { + // SAFETY: The caller promises that the pointer is not dan= gling. + unsafe { + ::core::ptr::addr_of!((*ptr).$field) + } + } + } + } +} --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 835E4209F23; Mon, 3 Feb 2025 15:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595464; cv=none; b=VG+Cg9BGiEiYWXheCDWOboyThst8FxicDyAMZFPKITxbD0dkrst1iNlvI9QPNVt7UKnVP8REALphMD6G/j6HyAqANVtMMSuQZMTlWf30keboN8v5o1x5xJ51Kvv9cnzNf5CGpPTcfxqNtGHR+Ar47E1WiXJIzc+afLyeqoEo2/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595464; c=relaxed/simple; bh=aMQOiJg0/az+/dwZD+7hXRHe8iks+p3vCytu9xnUhec=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NCqdFt6jkQGJN2nZjFYifJOclZD+yWh7hOY1fRRv5djtN8mcF1ftyRJub1qzdjkZV2erkD0eIhmfdIx3jLJg8pGCQ4H+aZ2r0oW9Ufl6c9R/d+mb+rpCcUoyxAPIO9bXguMZlK3FeUmfmwHuxxdBlwyndXg9Pwoq6Q6F+A8TpyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dnvoadk1; 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="dnvoadk1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74957C4CEE0; Mon, 3 Feb 2025 15:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595464; bh=aMQOiJg0/az+/dwZD+7hXRHe8iks+p3vCytu9xnUhec=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dnvoadk1oGORlH90eiNC2x+Tw6YzLJL8+Bn1nb4MOzXQJkXrehRr6bUzGTrg5rPOL Xk65AyE2HFzqqlFtH1tdDG0gR4FJpQA689ni9EK2NRD/BIpSVkBHTsoKQEjrJZ7tQr dhX4tB1J+wSPnA6A0Bo8tcnlPww/osU8TYGOcbg5IPusPJ/etOU1aom7QR+bL8hWoe nynPFo+lttYxK6fnTPaL0nCJWVz/2jGTW3yQo2c8Ro/Pt9yUdXCVBeQJijwm4NAlb9 NfR7F6YNpzq0U6hUWrrBrvsJ0FDf9bl+KkFurBMxId7YeldpT82aLdQx0lGzmIMg6O PQNfrzth3q66g== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:49 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-3-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1953; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=aMQOiJg0/az+/dwZD+7hXRHe8iks+p3vCytu9xnUhec=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvQKrjCssePbzr4oyEYmgf9rJ8ez/pDuFatd 8LZqNRKcJCJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db0AAKCRDhuBo+eShj d5DnEACqap/7g3HJ8Gfd9z0oa/mlRuBmg0sJGWpyVvy5LpcSZCXUX4+tFXKpYcg8JdOE9/kXIaf UC0dlwEM6T+eLvFTij72/hkNtH0JzASqR+xHgxTGc8PrD87cySYVjImBD5nZmZxvaeX7z/sK5Lr VguBgAKkm0Rc0JbhPYzNkd9e3Sxv9V11wnv43N8hjRyGcyP4U2t/o2f/Q6wjxCetfuBdgyD2BYc +gMPuLWkG8Ui+uWxFBcDjtynsOQqBnvLMG0f2F6LZTp0r3/BVamptQCiWuVuE3h88cAPUxNDxmp AHhlNuCLXP2A9fpmkbSpaaPy8LDN9Yiud4PxX4uJbC/ZXHTxfRjjq5zqWLMZvrkMrZHbvztDWP9 S+91fjeQlR/otg1nhhsCl4CU3azWJ47WXlRrSGVsLjZ45b33GRief/WOzbysmxkEhZOIw4lC3iL 2QE0V0ejpD1I65U9xooLSyc2NbBFI6nLavCFziBLF8iYnh+pnnk4pBDO1QOr6ZnLv6qgeTbRNom LWKitxE9Z2KmFwPdr8sT1adJK16seMafLXgknmQ3EBi2ohDmKloboPEwKyZ1YFtbBmcn5WZMihY VDQXOKNCgORaKZoNTT8kNUKZ1zSJNe7Txh15FUMsOu4POkDOqYomnustls0DM4/nxlECKFlllRL NajAtwpqOyDnAjA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a method to get a pointer to the data contained in an `Arc`. Reviewed-by: Lyude Paul Reviewed-by: Alice Ryhl Signed-off-by: Andreas Hindborg --- This is a dependency for: rust: hrtimer: implement `HrTimerPointer` for `Arc` --- rust/kernel/sync/arc.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 3cefda7a43725581dc0eaa8441e2528c161162e1..1dfa75714f9d696d138cc40c840= cb3aff61b32f5 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -246,6 +246,15 @@ pub fn into_raw(self) -> *const T { unsafe { core::ptr::addr_of!((*ptr).data) } } =20 + /// Return a raw pointer to the data in this arc. + pub fn as_ptr(this: &Self) -> *const T { + let ptr =3D this.ptr.as_ptr(); + + // SAFETY: As `ptr` points to a valid allocation of type `ArcInner= `, + // field projection to `data`is within bounds of the allocation. + unsafe { core::ptr::addr_of!((*ptr).data) } + } + /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::= into_raw`]. /// /// # Safety @@ -539,11 +548,11 @@ unsafe fn new(inner: NonNull>) -> Self { } =20 /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been de= constructed with - /// [`Arc::into_raw`]. + /// [`Arc::into_raw`] or [`Arc::as_ptr`]. /// /// # Safety /// - /// * The provided pointer must originate from a call to [`Arc::into_r= aw`]. + /// * The provided pointer must originate from a call to [`Arc::into_r= aw`] or [`Arc::as_ptr`]. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = the reference count must /// not hit zero. /// * For the duration of the lifetime annotated on this `ArcBorrow`, = there must not be a --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E79C209677; Mon, 3 Feb 2025 15:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595404; cv=none; b=sXFZ5MyBXOvgdGbebfWdk462/bD8Rj/s03TnrIJyCZ9OP8rx9Aj8CKZz/5Bm3IWHOPo6HeLDEemNmIflWTMQJ2VqPvxrOLcRDf6TqNWFlib5S+ekaOHHo5bUQm81wctKB8y7w2kQni2yQXuGqnsySG3+Ogq3pbVw7AaeskiHNQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595404; c=relaxed/simple; bh=tdx7r4vSfrS9rsxrw5JRdGhUboswpdY99BStdzOSy7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LEJXkRHiskJi/2iRJIKRQu13atiL3aFJDJONNIXY6L81q9R1/faU5uvsX19AOQqlP8rOEbgKLjGcj6HwqiYUsUzLDvVvYZ+ARXPVc3orxcm2BTfmkkbHCCWyQxzM4AdOuP4uyF7EcJXuqt5aAfogGfhanFZAVAQIdnuoEUFTdQo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u+WSsG5N; 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="u+WSsG5N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA11FC4CEE0; Mon, 3 Feb 2025 15:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595403; bh=tdx7r4vSfrS9rsxrw5JRdGhUboswpdY99BStdzOSy7M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=u+WSsG5N3fY6KrRi8mjrr9/oBzTEK0HUPJ3M/NDQIMruc8WUXGz78BQMQnoM9PFGf VjNG5CoyZpDJRmkG4LufoakBolhXm/Z/iINFMrqoPDeKQk1wNnmfP6RFVyZiHs1wz/ BJF67EbO1iYPVNU/hK/pIcHak807t6OMoXaiFUy7IuyEPMDuFsv4JrmucSOaE0kVU1 Q55ZAochBhFhot+QszswOuimTjUSqKwOAjxWRNCsC+KE0wKiabnjQRFjkEDFwsL2EA 2KGVZsuAgW/xANLonamKQ5j3IBxquZOKXFJThdKtDKoy02jh5J3FmsThrnT0cvSQoy Q5S8hE3+Py9ug== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:50 +0100 Subject: [PATCH v7 04/14] rust: hrtimer: implement `HrTimerPointer` for `Arc` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-4-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4151; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=tdx7r4vSfrS9rsxrw5JRdGhUboswpdY99BStdzOSy7M=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvRLXZYWWrH5PN9gONSE3JyhSufrV/q7leMo mefpd2A6mGJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db0QAKCRDhuBo+eShj dwY/D/49tDJZd1gG5GTepWDHZ+uluuU5dTYM6hex5rT6vEkW96gtpx9UXPKheP9maUCWGWIoQ2J yt4wHNJE0Kd4Fe3ggBuQvhfeX5MpB+IgqAlTBo9Cj9YK1Ii7jzz4tFP3weiM6oOuAINZUuoNnXQ GMYhkDQiKX2gLmw9/SlurIWJeGcsEIaCOVkhoV3I/M1QRgVSohoMbHxtAvEf0/31MPIYzxMmuZN nkZEiGsKxYNglTObqP81R1tg5rMQOceAzOESjkDXxTxUzvg1oW4Tw36C1C18xLcy4X+Bo6AHrYZ RNPEJ5+JGbZmQ0/23nqg+Ah7RSly2R9m2sELo9OJ/O1801MOqvYF+Q5yLi9yFFGfZ/Q4rN9NwrB aj458+ssdTd3KFw0nIyCnoSwwTAqn78BUsfPerbxoiGzZ6hCUJVSoY6SWem2NZxRBZxH1FuSbux s4293t36RmA4ArxCKiOr8GeLc4i9OVLjFazAqqLRKKKD7qvzQv6Td9n6pRn0kXXkQRojx8tjZ9Y 7cmfBFDzuLhLqduOP5odnPiduEMNqgm9mjhCfBxZQFvMuwE1fJIZ0mCLNT47GK/4+5077p8+Kxz LYaiaQT+p28n5+zZa7fhnJesM5N8Ho45DbvIM6WmMUpe+ytbGItQdi2oafunye+woJFX7yv3+Gt 1fdLc/Ig6z2hODw== 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 a6332924efabd40c475a112bbc434db77596a16f..3494c00481a4bd25735edf44b6b= dcbec9810243e 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -119,7 +119,6 @@ unsafe fn raw_get(ptr: *const Self) -> *mut bindings::h= rtimer { /// # Safety /// /// `self_ptr` must point to a valid `Self`. - #[allow(dead_code)] pub(crate) unsafe fn raw_cancel(self_ptr: *const Self) -> bool { // SAFETY: timer_ptr points to an allocation of at least `HrTimer`= size. let c_timer_ptr =3D unsafe { HrTimer::raw_get(self_ptr) }; @@ -310,3 +309,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..d1c90631d00362bdc38be1ccc75= 429ae294ab544 --- /dev/null +++ b/rust/kernel/time/hrtimer/arc.rs @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::HrTimerPointer; +use super::RawHrTimerCallback; +use crate::sync::Arc; +use crate::sync::ArcBorrow; +use crate::time::Ktime; + +/// A handle for an `Arc>` returned by a call to +/// [`HrTimerPointer::start`]. +pub struct ArcHrTimerHandle +where + T: HasHrTimer, +{ + pub(crate) inner: Arc, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl HrTimerHandle for ArcHrTimerHandle +where + T: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr =3D Arc::as_ptr(&self.inner); + + // SAFETY: As we obtained `self_ptr` from a valid reference above,= it + // must point to a valid `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` points into `T` and `T` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for ArcHrTimerHandle +where + T: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +impl HrTimerPointer for Arc +where + T: Send + Sync, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Self>, +{ + type TimerHandle =3D ArcHrTimerHandle; + + fn start(self, expires: Ktime) -> ArcHrTimerHandle { + // SAFETY: Since we generate the pointer passed to `start` from a + // valid reference, it is a valid pointer. + unsafe { T::start(Arc::as_ptr(&self), expires) }; + + ArcHrTimerHandle { inner: self } + } +} + +impl RawHrTimerCallback for Arc +where + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Self>, + T: for<'a> HrTimerCallback =3D ArcBorrow<'= a, T>>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr.cast::>(); + + // SAFETY: By C API contract `ptr` is the pointer we passed when + // queuing the timer, so it is a `HrTimer` embedded in a `T`. + let data_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: `data_ptr` points to the `T` that was used to queue the + // timer. This `T` is contained in an `Arc`. + let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; + + T::run(receiver); + + bindings::hrtimer_restart_HRTIMER_NORESTART + } +} --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 594F3208978; Mon, 3 Feb 2025 15:10: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=1738595424; cv=none; b=b3ejyCocrzI3myeDj4WbWAr4s4HXihcbQFeuanNKCarF0yAe6FceVqGZJji7Qo6XRQpAtBEr+bNczH7D/0TVl0LewE1u1yrWeFoA6LpjuSIKokrtFx22GRcSzuv8UCQp4nbJY6RWgWwDkvHP8u0jytZH4gFTU3hPGPfoa6qbcBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595424; c=relaxed/simple; bh=d2IJqaWH63Pns1hiifXnCmRVS0Gds6m+BDdNnp+PTN4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kk/86hDplgPoBQMHsKdCIUfbDzKU6FKIOuMnxnfJJp+RsqyUlOGK9EdrWduW8OXMWimA5wBRrIJDyfQOe7odEfzaFqYU9XyYuYEcCvtK3vVFDdC/pSwsbSqWPBx+6vqJaUdyyjfmlqiLd7zO2EuL8fUtTc2U2VlWQ5TxKN841a4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QJ8z7MwP; 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="QJ8z7MwP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B6BBC4CEE3; Mon, 3 Feb 2025 15:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595423; bh=d2IJqaWH63Pns1hiifXnCmRVS0Gds6m+BDdNnp+PTN4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QJ8z7MwP2h5O9cLHGtKkqL8Oy1kcDBfX0QlzdTbTC+UL4pp4DaEuyaz0lx035H80+ P6DOSgzuYL3EfgnkKBlzxI1jckeNltcrl1HXcvBqM04nCAEzxMO0B27cOlkywxaNqx lvll0hZk3MNIBO6KFiH6NpTFHfX6A/GYVXL4Am6ZjyAwff+GR52CKTB5RUO1QjIKSh NDWg2VBM1I4Ktm71JZrUI6HT4+b38OicHL1xuqOx/lcoaRdzudGwXvl40PnuOlodiS CVFwwu3Fqdy2iq/wIUNcYhNmIydzSvuLLxcz5sldpPMGVpQLDpWJkN5XLA0XcNfYs6 CEnKOzgcbwUQg== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:51 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-5-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2541; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=d2IJqaWH63Pns1hiifXnCmRVS0Gds6m+BDdNnp+PTN4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvSVkNoE+hMIzaTfEZByT9GPrTgvapfS3gol IFt8h4p9RSJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db0gAKCRDhuBo+eShj d5hFEACxLpe7wrrNf3ATC/4OO/XO5LzoqvwYgdXYHKCRjZbFd8WzFC57k0N279UEAqEBh9ry1SV ma0fPFzrYCilOZaoWa0cMT95mZf1NOYiEmZGggmpeH6Tf+ky+w/uvFWjkmD1bIiOjBIbcIMMSvP +pSAysrDijpx77g9i1jngTQwPLYhHEhUvrPpYjgxtK2iR0+nkMqELr5BiPBksmOfpym98S9EZ61 o3QZMma9kJ1GplfpubkQbiZIvibtleFxahDTkgTOBo6nDiY8EfwLqMXrZ/T7W7bv1ug4TLvz/C5 H3fmTpUvIiLjYfuoqLmP0BJ54YYcDW96vTZclLhN3azOLlB1Fo8TBmuHp5lUMWNCm5DfHMcBwTn RG2uYBg10e2TVmxRnf8/Xg04RH73VKM8ZG/tNOlH3RK/tJcRpy90AbtWjZxvVJZikAlzUTTWR19 ZXy3NgsJ3+zOsb5xoS6ohGbAUNYmpFA+EhyBZRfikaMD8S8pU5YFzuzX9utZ2NUKhrGKDPy4kVU c7L6+T9NNQ8j6srMXvdjaqRCYBoF+DHAH2C+W96R99QSl68LPm+UBXt6SNszYIExVL/WMNV59rt /SNnJRMgVnf8kPWOpzbP8MuZDvz4XBwe2hgQ8Bi4RuKqD0jVIwj2lFehAI8vLObruvWj65mB+hB Z4iWYU+kKMPwjDg== 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 | 28 +++++++++++++++++++++++++++- rust/kernel/time/hrtimer/arc.rs | 4 +--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 3494c00481a4bd25735edf44b6bdcbec9810243e..3ed7f5ee92fc5f9f4cc108c373a= c40480f5307d1 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -183,7 +183,7 @@ pub trait HrTimerCallback { type CallbackTargetParameter<'a>; =20 /// Called by the timer logic when the timer fires. - fn run(this: Self::CallbackTargetParameter<'_>) + fn run(this: Self::CallbackTargetParameter<'_>) -> HrTimerRestart where Self: Sized; } @@ -278,6 +278,32 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime)= { } } =20 +/// Restart policy for timers. +pub enum HrTimerRestart { + /// Timer should not be restarted. + NoRestart, + /// Timer should be restarted. + Restart, +} + +impl From for HrTimerRestart { + fn from(value: u32) -> Self { + match value { + bindings::hrtimer_restart_HRTIMER_NORESTART =3D> Self::NoResta= rt, + _ =3D> Self::Restart, + } + } +} + +impl From for bindings::hrtimer_restart { + fn from(value: HrTimerRestart) -> Self { + match value { + HrTimerRestart::NoRestart =3D> bindings::hrtimer_restart_HRTIM= ER_NORESTART, + HrTimerRestart::Restart =3D> bindings::hrtimer_restart_HRTIMER= _RESTART, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs index d1c90631d00362bdc38be1ccc75429ae294ab544..109eded0e73be853313abbe1a35= 40a5b1b8706d7 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -82,8 +82,6 @@ impl RawHrTimerCallback for Arc // timer. This `T` is contained in an `Arc`. let receiver =3D unsafe { ArcBorrow::from_raw(data_ptr) }; =20 - T::run(receiver); - - bindings::hrtimer_restart_HRTIMER_NORESTART + T::run(receiver).into() } } --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 652A0209F23; Mon, 3 Feb 2025 15:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595459; cv=none; b=XLZTiVg0l9q2lvJznUjQShyPyfs62hnxKzN2c5UWflR1LAY4iWf5CzilDfUhZLlslwMrtNYhY4k7578IlNP82/HorlBi4GdL1aG7UvUEavO7pWKcpjmJ+S8bL5ceSeciUc5YA5C/urpyo3wzp4v+F5riIDfsM1Y73zxIPpraoyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595459; c=relaxed/simple; bh=HZoGD1YbTc2gd4teU8xM+77OxuJ93bWRZzduVcfa/38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ner3ryQptqvpU/xezbLUH4fZ0g5ENLaoFA7zdvgqnW+Po6B7/mKVCd0t23izH/tS4yawbqwTN9A1YFoXqT2z6Jqgt0LAj9LOd/DxsHSVvzI0suiLa01ZWyEwi20jr4ADxlWknWH9bj5HZTEiBHSfg9duonWSeeY7V5GvzPbtiFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AzjRKqEL; 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="AzjRKqEL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAC29C4CED2; Mon, 3 Feb 2025 15:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595458; bh=HZoGD1YbTc2gd4teU8xM+77OxuJ93bWRZzduVcfa/38=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AzjRKqELTZ9G+YwfqXMSbm/r4o7wsKMoVfGnayrmjzw4pu2kyz+kNMpgkh+pN8TvN KblJiucN6NR4gFweHNG1LTnmNxjhg7SB7kgzMs7rbrQ0aZopPzg3SsI+7AfqW2gAf7 YRyUnJMHjgeCJvFfroxAXOmS5DRSYV1W/1Bj7ClhzRFSyev2ncck72vnilZ/bQk+bO Xg7GTUu9uIgwSt8r+HoyEBos0k+a1+Y/QR148RIEdTUuYo+tdb/V5EgRMwq/HQ+Tkm w12XzSwppcFEwCtuJEsH34U2QCJ21wBp/dYX8tTF4FejUQDYX8dW/owVfVmXHYrHZH 1rD9JBTUaZQFQ== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:52 +0100 Subject: [PATCH v7 06/14] rust: hrtimer: add `UnsafeHrTimerPointer` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-6-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2123; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=HZoGD1YbTc2gd4teU8xM+77OxuJ93bWRZzduVcfa/38=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvTpw6F6f0HK86YQSnRtdtnxTyRrgMfry/RB hGyasKtHo+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db0wAKCRDhuBo+eShj dy97D/9nXmE3elTd/sz/RGVMLpNUWCQkvu47IRMaapAx1lc0FJ8mWORtDHSn/7jdfzjyJpIRaAf lNax661vCNO9FJbqdho4Xp3TfQZU4i+SIQSSh5SekwjHY+lWkpZZqneKWtxcQkfVWGbCuZyq+b8 MUJuTtlCBNCdYKjF1oy+7avBHVYXh6bOUi5YTwv5DiY2klT4fdoem3M+Q5ORcguBKA/URLbLTgm sV/opHzc2dH2SRMsgsLYx0COf2WcV0n4bFJQd/N3P68+c6IP2C2OHC0mHusbFC1xVF7DSYC0jw8 wU/HJ1rJMxFxA0kwYqYZj19W7MpiPWMt5lk15xFE/VK5pMkz04ljZst2zICNbAcrngypM098Ec0 HkiYAOtaJSnLwEaGp0Zbr/IeRaj42rf6chazsPvFI8rEQa+YBwm13qL9CUrIvf3MyNctIvqTWeW dEVA0mrVXBWyPg8x/tfOWWIWxdwaUHhqtrC8oX6InNPl2OUza1jUfa8rUQ7lT6CcZ057gv/Ej2N qCtAUt/H7DhdzF7gmEFRaFxAP3D5/34oWo/QRWHjY6RmV6DAdLwDX2t9GlGRCsq7enHpXZc9ELT lBk0fblafwHHAE5z9F5ggDfudJrz122p+kUaWdX/qG5SVNr89OR46MClNzP4AFfWyf8zL+bR3GB pJx6tTp1FdlKn3Q== 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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 3ed7f5ee92fc5f9f4cc108c373ac40480f5307d1..f5b360c9472b2a4a90c608be1a4= 70222204ffcf5 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -157,6 +157,37 @@ pub trait HrTimerPointer: Sync + Sized { fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// Unsafe version of [`HrTimerPointer`] for situations where leaking the +/// [`HrTimerHandle`] returned by `start` would be unsound. This is the ca= se for +/// stack allocated timers. +/// +/// Typical implementers are pinned references such as [`Pin<&T>`]. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that instances of types impleme= nting +/// [`UnsafeHrTimerPointer`] outlives any associated [`HrTimerPointer::Tim= erHandle`] +/// instances. +pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { + /// A handle representing a running timer. + /// + /// # Safety + /// + /// If the timer is running, or if the timer callback is executing whe= n the + /// handle is dropped, the drop method of [`Self::TimerHandle`] must n= ot return + /// until the timer is stopped and the callback has completed. + type TimerHandle: HrTimerHandle; + + /// Start the timer after `expires` time units. If the timer was alrea= dy + /// running, it is restarted at the new expiry time. + /// + /// # Safety + /// + /// Caller promises keep the timer structure alive until the timer is = dead. + /// Caller can ensure this by not leaking the returned [`Self::TimerHa= ndle`]. + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; +} + /// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a /// function to call. // This is split from `HrTimerPointer` to make it easier to specify trait = bounds. --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6E3B205AD5; Mon, 3 Feb 2025 15:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595387; cv=none; b=pFLJLGsODAvdD+Degne0tHUZxRuGmu4JrUtv71KQSPkgZRoDhvlGW2b/Ch7UbOO9k5H89dO0FjHeNVrmc0+ozzL+jWqkKbLRGsFXbq4Zl9v01kWe1b8vaHOzHXOJN0h4nHSZdmOutfd1Cdv6Utehbnt9v40nydfYlysIavGOCsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595387; c=relaxed/simple; bh=koTsfaELOAtmEpKSGKM4AVcZqtKOTEJWBGKssbsuAso=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Aw8PRwE9AFFL63UtYtsPr5qqoeHSmMOt5m/r5c9XkVVXowbkTPSqyMyZsoPc6+4MJTYxtnnGKePxce052bECFC6QoI31Qi44YoUgrneDCmIXeksCeJjbBpwqWdg55WqD1oM3yImCoU+5KCw617sEDZkav/gmHDXi4cD4ABOolos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D1cLqpZM; 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="D1cLqpZM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5A2FC4CED2; Mon, 3 Feb 2025 15:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595387; bh=koTsfaELOAtmEpKSGKM4AVcZqtKOTEJWBGKssbsuAso=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=D1cLqpZMpm67PS1kZDwUBXJOuhVQJnIPL3M2K8fd/P/Xn211CdydqRsXApJ8BYwzb ZH1G8FztAHXsII71JW56iIdA6RVdSxEZMTlFhqSnlpTluua+QKhK9At78on38yM5aP f1ZChl5g9h7ruPAr6Rp4QphkvMWByqO0hOYcuLAfrTN+owp2sxR6PMYYcl2ICaH8Eu OUghubW9YYk7qRYUg57anqh+bHnli2s19sMxCDKzYOzwM6bPiUJY8WOwY5S6t87d0p HLcJfTF3BNlfR8AxAJR+7FM8zoHkDJieeHQb91ASQTfvoGhZZfuJ3ZA291lp+LgZS3 SGj0uoedjwoLw== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:53 +0100 Subject: [PATCH v7 07/14] rust: hrtimer: add `hrtimer::ScopedHrTimerPointer` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-7-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2093; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=koTsfaELOAtmEpKSGKM4AVcZqtKOTEJWBGKssbsuAso=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvU/C8Nmpvkfj22QXlj5bIXKfGG3P/znoy0G 1v6bi09wzWJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db1AAKCRDhuBo+eShj d/gYD/wKfNG1FyKEJXc/6I+XxguJA+/IHGx4wRPznUqfCZIBXzJ6OTds4IWqymdwyECzvkACXCm dN4OD9c069s7zk7mp1KxO1KSX6fYdF60+RXtyS5u+H5nhb/4Lh2GHahds4Z5fHBqgZmflMlsX5a 2tdIV6JNHAjxKoUbRP6/L2b9NxSVSPLvwEcDEFiCXWRpaDh/kSmgDHI2qmT/QP4nlKSJbl3/aWH unPfN0zZgPWRo+Ew+ioJkUpmsVpd/e9ef+w0OoAD6PMLv9xBl5opZQjl0xmpvI8qxhejPyIHvGe LsIeaHKtlh6YqXtqNJ+2p7ZkrAVntSqyfOZRElLLRKFn33xcr/dZpbAfNNle4FEIFzk9TXzVhqe fTa6/HIxlnKBD949ra1+neTGMqydVJlaYI+nYGkHoUJel8hVu0ONmGC+DYYDDpEaoWtPxGa3YQt RZU181DPwtsAarIiVa14Lo2izEfwNK11GoQxEInIp6ipYz5lCQXmoLIzQOydTjV621cV6h2BXVZ mMvYi0VKY9mJie6vAtwW5M5NSOZ0YXlwljJDpairC2pOYhS+JVrUfsx+1jB6LFeq84gU+SDbvhB /7Ds9Qfs6naqC+oXkgCyUk1+oHX8xKvwyg/LGaGFD/D2GM3lTRzxRCoY/33i1dHem1yIy1NGg0J 2rsJGU1BmTHWLoA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add the trait `ScopedHrTimerPointer` to allow safe use of stack allocated timers. Safety is achieved by pinning the stack in place while timers are running. Implement the trait for all types that implement `UnsafeHrTimerPointer`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index f5b360c9472b2a4a90c608be1a470222204ffcf5..4d39c3526a897cba3b76589f21d= 0866beaae0c4f 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -188,6 +188,39 @@ pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// A trait for stack allocated timers. +/// +/// # Safety +/// +/// Implementers must ensure that `start_scoped` does not return until the +/// timer is dead and the timer handler is not running. +pub unsafe trait ScopedHrTimerPointer { + /// Start the timer to run after `expires` time units and immediately + /// after call `f`. When `f` returns, the timer is cancelled. + fn start_scoped(self, expires: Ktime, f: F) -> T + where + F: FnOnce() -> T; +} + +// SAFETY: By the safety requirement of [`UnsafeHrTimerPointer`], dropping= the +// handle returned by [`UnsafeHrTimerPointer::start`] ensures that the tim= er is +// killed. +unsafe impl ScopedHrTimerPointer for T +where + T: UnsafeHrTimerPointer, +{ + fn start_scoped(self, expires: Ktime, f: F) -> U + where + F: FnOnce() -> U, + { + // SAFETY: We drop the timer handle below before returning. + let handle =3D unsafe { UnsafeHrTimerPointer::start(self, expires)= }; + let t =3D f(); + drop(handle); + t + } +} + /// Implemented by [`HrTimerPointer`] implementers to give the C timer cal= lback a /// function to call. // This is split from `HrTimerPointer` to make it easier to specify trait = bounds. --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80815208969; Mon, 3 Feb 2025 15:10:44 +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=1738595445; cv=none; b=aOuhLm17cKq9lYGheRyFa+zzGhQuDOu5I6SJmmNyUfmtlc71dV2yVIRtv0ayuyGIzi7N+ENhlgDWzysmlKdl55QOeCXRy7C3AXt58rI5Hla4HhiqRCwF9Sfw8X5vLW9kDQKKgCrCxmyBHItmcRk1GO27Q59ZEegM+aueRNAClRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595445; c=relaxed/simple; bh=z6dq9MgZd6A4V47mI6yKmeT701L5XLek+ujKgro9aNY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kyeA+iiAUYVbBDsYULuwaYRFXS8agZDapS7r+g/K6QGBOV/dS5Ju3UxbnzWAweEa5UPfiWsAV4U3GNYENWyWInyiACQ/PmHTIXWGtQDdpqoyK9gcnkqL+o1Afy4+AC7mqgnUw5a9KHh6FGNHVd5K00vgkdx6xr3ygS7D5FsbKIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YCVHYx1V; 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="YCVHYx1V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96A46C4CED2; Mon, 3 Feb 2025 15:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595444; bh=z6dq9MgZd6A4V47mI6yKmeT701L5XLek+ujKgro9aNY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YCVHYx1VR1ox1m9YeTDbxRKZvQGyyHexZ5tMqu7XfBuKonkDe8WtJpWWHvb60Y6ol +K+YBaVQp+YzJua1KmkM4x1dzNxwkmy8p/tu/edlik4sOqtv1iCIZdWHwh1KdDrTP9 ASrl2ypfCgvoHURbzfA8LwPnFv04DboCgAAJ2ckY809EJAS+n5VoTSdNrwMjaaHi97 BrEDrzHsgO9B7uj2hhnDhTxWM2jQgcWndwa2FMH7mHcD4YWzpKq2Yumdk8Abxtzj2k PnN6bjkVjSlzIx4+SOrqJWfSkDTYsZIPuZqmPTHSLY9R+kMEJ9+KrHqqf1MplbG2QA G9P1AMGX4leLA== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:54 +0100 Subject: [PATCH v7 08/14] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-8-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4086; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=z6dq9MgZd6A4V47mI6yKmeT701L5XLek+ujKgro9aNY=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvVy4IOoK6JjwcmgPujlQnf56YPvFIt2FaVO CW5ERrL1b+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db1QAKCRDhuBo+eShj d3psEAC/bW1FL17/2FuWme+MGhR/7Mb0z163fY6n2o50naQiYF92p4xKiBrS60IgwU/vg0fmy4x 4M0XShqlLh3P6uhPdCZupUzRmO3uviEj5KQ0uCC46FeX0SH+boa+iQ7EDQHymRs994sMVDcr8Au BycTgFbFi5wm+RuDglMijm3QqZPaJQRltVUU2sUXIHBXNwhAO2Oyjq5C6Ou80LfHyOeEAKa2now T8OEYliSS/Vbp2vOV04WmcMXfG5hZJLBY+ScPEqqCt9XHvdHjMjCoJ5dNPtDKc21pcIeS0eZ+uD saACRpc7FyLKVKGHnSWH3lHT+SmOfHCbDzfy8BBDWzeNhiMeNGk4munlZEDtvWlt9PsoR8u4Zuo 4a9r+Do7ZUt9O/blC4Q+AJ25rVIQoNggyZeDIoe97q6QAlqJsTXLuC0oUiWIJsafX6Ov0TT51P5 13aW8L8I6H2Za1DW5B6BfwXjciA+5+7dJX5WFu4hTb4AzSyT6ZxAewzr6J9sj6iUamsVHHCK0eO lMIYgXUXCd0A6w2mAA/mQ096XWFsRubIa6ICr8/f/HApoFJG+NOXK4hn4i4+SKCpJUQLVjQSfeV D7AUJtT+jyJRHaVTEvAR1A3AP5KUmsRUjvbSa8SIFU/gtF6iT7tc+XHYi4g/dhp37lyNUpjQWX6 5yW/kghcuw9KXBg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned references to structs that contain a `HrTimer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 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 4d39c3526a897cba3b76589f21d0866beaae0c4f..5d05c1bca8412a64f9ecdd79e0e= c8f10afe800b5 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -401,3 +401,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..ecab39118662e29a4e3e2ee365c= 25b7da7a953c5 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin.rs @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::RawHrTimerCallback; +use super::UnsafeHrTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&HasHrTimer>`. When the handle exists, the timer m= ight be +/// running. +pub struct PinHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + pub(crate) inner: Pin<&'a T>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, T> HrTimerHandle for PinHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + let self_ptr: *const T =3D self.inner.get_ref(); + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `HrTimer`. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, T> Drop for PinHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a `PinHrTimerH= andle`, +// so `Self` will outlive the handle. +unsafe impl<'a, T> UnsafeHrTimerPointer for Pin<&'a T> +where + T: Send + Sync, + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `T`. + unsafe { T::start(self_ptr, expires) }; + + PinHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, + T: HrTimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr as *mut HrTimer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + let receiver_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + let receiver_ref =3D unsafe { &*receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + T::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F50E208969; Mon, 3 Feb 2025 15:10: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=1738595449; cv=none; b=cmkQtYe3dFT4Yl7FfEvtkHikvbzFx8uf85zo/hYf/UaBiWs6OBdCnONcvCjvGZDHYL95etpgIZXmHaAQmk/d3dioPBmOgF3lrLDCJYTex7cNjJo098xJwS7x/+zBMiBpjRXpwAsgLrohDzCiAqUq/rBZGfu5yEtRhzkAjnkWlVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595449; c=relaxed/simple; bh=0qlzk7jze9SXmQAdiXzFi4GXjUZy+CtrVoviTRMScZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pjelPklwqnVh9nWIMzLfIQ1uDNFpYQSJjhAmgc4UZMpvqFH5DYlVVjnuD58BlIY6Y9mGzNodSdF2oAebgSbtDQ9+xC9lkmb0l+14+R4NCg7Oa2k/cwPzb33AT1p0S2O7fYPEB5KDUXNXnt5mz2O55GhHMDPXSu5RbdH6V3a3Omk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ElCx8IOh; 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="ElCx8IOh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0CAEC4CEE3; Mon, 3 Feb 2025 15:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595449; bh=0qlzk7jze9SXmQAdiXzFi4GXjUZy+CtrVoviTRMScZ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ElCx8IOhS4OBfEAOb+A0V30XYpMFJItYkgG30x0tpoiAGJjArF09xvxlstlZtQ0cE 7AxYklpKwYYPBt0eTrG3VIiS7eKhlpeiaMSvyx9cP6icPD73dQWebtgdcPmUcTMhfs jyPksXSMD2RqsxyT/+pbSFS33QqgRl7GDavepZ3hazu1ohwQ+lxdpw2OnDtPp2ubSL d7Kp54J5GWzLpXKvpjEx0MX0ipg2rjUVqAETP1BcxoRJg6NOznMOt7JNO5ZjYc++Bo xgZZVR+UAH08FudqfnUCY9FnzXQZT++moH9ASVun+kg1IVx2D3NxKWor3V/LDkKWeR ywNfmQfLVfMcw== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:55 +0100 Subject: [PATCH v7 09/14] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-9-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4300; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=0qlzk7jze9SXmQAdiXzFi4GXjUZy+CtrVoviTRMScZ0=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvWe/3xQVpNrGBnhe3rCMr+quwU69itcp5Yv Sf8QivYLMmJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db1gAKCRDhuBo+eShj d7DlD/9ZLYfVo5gNl3RDJciDkXSQ1u71vGRAWPE4rnuyc3LjN144s7PWWg6LsY+DRAxJiE/FzN2 akcnFmvEpzm/kBnt8LfoK/VuIMSGIGHotfLFaM5KZmBUH6+MkSBMeEEZ65L6Fp9hioQRX6Gk1ym nC6Wauq7MYnq+pdzu/gEesgrAYwXWpIhHJuiqldk3WaXGAcSEbEXQpzqNFLNm66jJa7gVkBz62K YBB+g7LAmLyxClzLnrOTsc3is39W/psa6uMGntoHEGPqLgAt9ssxq5/A6X9SNvGCsSlW9f39wXP Bk7oTUjhZ0FRYvqTSUWE2P4FvR5xBiBXwooQ4GcTwHzgVgG6nhzQL8Gn3TvKOKklmNzHWaqs8zh 3nleUE5P8rxT5pcAjL63nNkB5zsLbNRsga8N9YsslxdjhCidLtl0xmavhQ5gKs0ZDKFNm1cAw6p gkQpQrzHYOZ/GR6oL+9JMbn23GBVzSm/ipUupI8kP6KEb+Zcpe8BR8xEowmUFhw2nNa+8Wb8Av6 jxFYan/mNm/RTC+scOj5pF/5S0iUPM8iWIN0/UJ6ORXaSXoEcUeLpqcAaFg6eNMwcxPdX4wtgZ6 Ouse3ILTEw5Y8cH8k/Vr87kQiwSc2wTt+u4upz6gM1jF7w4Qnmiozsu3XWTGDxun3Wj47waD2Xk iz8AXmFS1t26M8g== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow pinned mutable references to structs that contain a `HrTimer` node to be scheduled with the `hrtimer` subsystem. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 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 5d05c1bca8412a64f9ecdd79e0ec8f10afe800b5..69b3737f16978657531ea2bf97a= 1fff56cc91195 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -402,3 +402,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..153e89b86caf25f0c1b7e9e3b34= 940e57600d2d5 --- /dev/null +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::RawHrTimerCallback; +use super::UnsafeHrTimerPointer; +use crate::time::Ktime; +use core::pin::Pin; + +/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the tim= er might +/// be running. +pub struct PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + pub(crate) inner: Pin<&'a mut T>, +} + +// SAFETY: We cancel the timer when the handle is dropped. The implementat= ion of +// the `cancel` method will block if the timer handler is running. +unsafe impl<'a, T> HrTimerHandle for PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn cancel(&mut self) -> bool { + // SAFETY: We are not moving out of `self` or handing out mutable + // references to `self`. + let self_ptr =3D unsafe { self.inner.as_mut().get_unchecked_mut() = as *mut T }; + + // SAFETY: As we got `self_ptr` from a reference above, it must po= int to + // a valid `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f_ptr) }; + + // SAFETY: As `timer_ptr` is derived from a reference, it must poi= nt to + // a valid and initialized `HrTimer`. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl<'a, T> Drop for PinMutHrTimerHandle<'a, T> +where + T: HasHrTimer, +{ + fn drop(&mut self) { + self.cancel(); + } +} + +// SAFETY: We capture the lifetime of `Self` when we create a +// `PinMutHrTimerHandle`, so `Self` will outlive the handle. +unsafe impl<'a, T> UnsafeHrTimerPointer for Pin<&'a mut T> +where + T: Send + Sync, + T: HasHrTimer, + T: HrTimerCallback =3D Self>, +{ + type TimerHandle =3D PinMutHrTimerHandle<'a, T>; + + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + // Cast to pointer + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: As we derive `self_ptr` from a reference above, it must= point + // to a valid `T`. + unsafe { T::start(self_ptr, expires) }; + + PinMutHrTimerHandle { inner: self } + } +} + +impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> +where + T: HasHrTimer, + T: HrTimerCallback =3D Self>, + T: HrTimerCallback =3D Self>, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr as *mut HrTimer; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + let receiver_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: By the safety requirement of this function, `timer_ptr` + // points to a `HrTimer` contained in an `T`. + let receiver_ref =3D unsafe { &mut *receiver_ptr }; + + // SAFETY: `receiver_ref` only exists as pinned, so it is safe to = pin it + // here. + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }; + + T::run(receiver_pin).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FDC420897E; Mon, 3 Feb 2025 15:10: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=1738595429; cv=none; b=ayAW7bYdCdCqqGxRxZZICMNYaLSRpxLopFXUz0r+7QFwBJtfefvuyfWs7T3b0zx4Nqe3Ud7r+eR65CHxJp33gF2mnZ04AvH7oxYXzIhtxv8PHkRfDZhYl7hrOKphjBDyeL2q3KGJgCL8BeRdhHqCka5PFQb6kb+RrWt91wDk8Jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595429; c=relaxed/simple; bh=J2HWkapAlDPb03vUi+fyTbxy9Aafi2wdXodrO3hGSEg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tfiSalB/gkJLU5r2UJ9sOYcLBUaeCNjTxeRLhjWedkF7581paMB5Lkpbsosqtp3PZC8XxUdSw/C/SfrgmV101VkaWn25NYfkA0+LTOyYYn2HFQ66l6m2lkJ+RwzVsLHapEQSWVbqLknraJglU+NOlH1B0PF+e2bU530bmKUJ/vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RfOyfWdX; 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="RfOyfWdX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EA19C4CED2; Mon, 3 Feb 2025 15:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595428; bh=J2HWkapAlDPb03vUi+fyTbxy9Aafi2wdXodrO3hGSEg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RfOyfWdXP68WZSbeS1/TVughysecDzQ+NBUm26QxVy5B/gRmEOZzlwSsgKy8qqdzI hWxNQtzLhWTOgq+Xzd/IgdRS/gExucdcU8rRzUo9BKV0wuXhfjKoaZLmzFJ/36n6hh ai1S21yeiMU1D5SRqAtmkO+4clVfOrMMYxGd6treW2e0zjY9jCbu9Gc5nzrrCg5bdN WBtmW2zZhHmdqVMbwQo8lWP/CXXw6W5fLimncN/uYV625xzVauQjT0IMHo0E2Y4LvC MHBRg2TsWrbd14MuxwyIOp4BPRMc03E20ZjsbvOL6xluz76lqBUcR0bn2dI1dYRxBo IVb7eSGU+xq+w== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:56 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-10-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1082; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=J2HWkapAlDPb03vUi+fyTbxy9Aafi2wdXodrO3hGSEg=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvXEsY5s7zwXQhuY+I3r7Qd31/OjS1dRfx6e 4uARiB3STuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db1wAKCRDhuBo+eShj d6soD/9pY/y5DQzhpFj6Hd0wYDwa12Rw4UBMO7/xT+9XYfy36rDLKhtaqqVQJb4S/EzbiLFH23p pp8Twp2QuIBr61MZvQngUZf3ONYplWN68CwdaohOEsvmzvKNXgQ5PMkDBLPD3Cg8wvd5Ugx0y4x oVezjhOpmcyNiTYZwJqpQ6f4Q0hQ4Ff8PazBv9O9zWj02BnuTFJcbLHqMKtGu/Tm3Y4ffvpMj+S lYSuWkTimjtnTbhxelXPE4xh8cheFcJG/Oc3f9fY2XfbJcsb7dZxcSyPZTJUW/ORJSJt3adWfJX He/RLp4VlG0v8bwDs7bxSxFQddP6XiGQUcsZQQSxPQRq/6F4HMzB8I16IGxTmFH6xxSeCfWVYtp n98cEV65msdAP0H1dQpQAQPCZi+n+NiEmZ5GwKn4evaDbFjnNUrcMEDr+/tzhBmpJHcPPqt98OG sRMz5nuA6tSHRkw/Z4PGOrjlE305EVMYT1nCpCAjDF5qsyOUGAk71BoeDnEhMIWyCUDGyo4mWYa kLcz13iMESbckId3moTSBbnA+Rod2taSH5Efr0418AmdomN/tqKzCYvoxQYQTty0O5PdGkvkiIQ C93m6OPAjxRX5x/ho12AwTmfd3BVLHHXKTBEQKQ3fKVD3hSfBS81RJtuw/lRbOrUOhZW92V74AO vj5YsihPSrxr5Yg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add an associated function to convert a `Box` into a `Pin>`. Acked-by: Danilo Krummrich Signed-off-by: Andreas Hindborg --- 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 cb4ebea3b07422ca0f402512b7c66d66fd212042..9da4a32e60bc3fdfe88e595a38e= cb9e3454e083f 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -245,6 +245,12 @@ pub fn pin(x: T, flags: Flags) -> Result= >, AllocError> Ok(Self::new(x, flags)?.into()) } =20 + /// Convert a [`Box`] to a [`Pin>`]. If `T` does not imp= lement + /// [`Unpin`], then `x` will be pinned in memory and can't be moved. + pub fn into_pin(this: Self) -> Pin { + this.into() + } + /// Forgets the contents (does not run the destructor), but keeps the = allocation. fn forget_contents(this: Self) -> Box, A> { let ptr =3D Self::into_raw(this); --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43F6B20A5EC; Mon, 3 Feb 2025 15:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595454; cv=none; b=ITkxR5alRMzKDs9gKFU8xZH7keyKETO8/HAN8LSH0o3odzcxJ8RjzFPXOYY/lt1ccewgo5VFJhQ3KlVNz+/ob1KHhq5koJPBeQ68Fv6XoqArpBhD/o9nQu4/PSopVSC+s5gMcaNimZXVjcIRT8nB1eU0n7wi9vy56VhD2hgfW5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595454; c=relaxed/simple; bh=QmpIeaDX7rQ/r9mC0uOtqkDNaNC/fM0iAj5up4a4Wtg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ASLcmhmnW0ZOpzpFkcccmbbRi9R+tsR/AcuE3mz/n58XRiHjvRUABlOKWcMI3/X2HoRcDHxvbCRI6CWdknOj8Jcdprb84jFzs1uD/8PY2yPw1A263JiR+loKBREla5mXLhtC5kpdL2NO77ve79MXwWT/VwIuF2QrkklbEwOE00E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uQ280ZQe; 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="uQ280ZQe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8FC4C4CED2; Mon, 3 Feb 2025 15:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595454; bh=QmpIeaDX7rQ/r9mC0uOtqkDNaNC/fM0iAj5up4a4Wtg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uQ280ZQeyxx2ybDUUlBakOOfjneHGv9BUgwwj/kuVVxXFfOz2880h4JlWdXV9tDHW +KQ24WpS59qJRr8eLsjlolOD7JDscPodNlQOJgk2F7dDy+O7aOyqjCOkNfODk5q70q 7Gzr0XtH1F73ImAjiZT1C1+UjOww738f2RUhcmbPckGqGM5c+jm19LS2v4nhbdNTVa iI9JPUNx0MYr7kgXwvnzT1PQYuhnwWHcdaJ7oRZyqyQgp0wdC72o7XMo3ytIhZApcY oDRH40SFA8JwwB5hwQN+8G+Nik3KimWAhoWYWC09SRntIyz1+iwfpz6nnAGliJc3ti Zz8MpT4Qp9TcQ== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:57 +0100 Subject: [PATCH v7 11/14] rust: hrtimer: implement `HrTimerPointer` for `Pin>` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-11-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4491; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=QmpIeaDX7rQ/r9mC0uOtqkDNaNC/fM0iAj5up4a4Wtg=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvY/guIuvL0rR3vVhB/Hxk9lpH1cmkqvnlmE 85R1oSEtJeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db2AAKCRDhuBo+eShj d1vtEAClR1C2jFxkDR5euYrjB9vc14ZRWKw0Ue+fWy44xjXQRMgWTuBHxxN/TRINBGRrybenVVX 1Y4akNlnIDNcYiAqfXR3yWJnN2Py/SCgsUdPTWwbmB9StCUBUJW77OQPfvn9w+UH45Cx31i3k1g ucQpu2FHcKvWvRXiFbVyqLD0JRPZAbhd/4fnG1XjgXUd8CkJEvCYo2+SZjyQC0443AvF8VkMI/e cRsHAUjp2O6w4H7/sF1WpnRChRFMlIET9XtvgfPvxdo49kcNchwD+2YSr050v9fhDgZmWndjaq1 PItorqmhgfgnRcrjRODwKDItlM2DfMnx6sW3/POP+wanbkZ0H8tuq6pZlxzkPzZd0j8EIJopQKz aUltYGjrQqzp/N08O/65qjFX2FTyCRld9VDE3PkvwuAXKkWHbjeYF/GVJ346DKEHNI2/+AGVwKY ze5FjmGm5xZBX0Gt/d4twtzYr17nj1b5u2qoBUJPciOkTGFpsrr7+4dMHcKB0b9kbSeEGI+Cy3Z IE6gwD1qZJ19mk+Gwj42vf9i40Pkepev3AamGOTmxFdleyTvaVo2WZ1ziI8DQD104keGJqiaekm 9gLo6StXXAO/0YqCXV9d8ATkS0jB9/wFH5e5bnoJXFP/1mLsK81atgAVyfYWCJG2nIvCb6yUyn4 SOb1Q7Gp5WfW+pw== 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 | 2 + rust/kernel/time/hrtimer/tbox.rs | 102 +++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 104 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 69b3737f16978657531ea2bf97a1fff56cc91195..5eaf86fd099566e9d837a1d394e= 666fcb8f8dab4 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -403,3 +403,5 @@ unsafe fn raw_get_timer(ptr: *const Self) -> mod arc; mod pin; mod pin_mut; +// `box` is a reserved keyword, so prefix with `t` for timer +mod tbox; diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs new file mode 100644 index 0000000000000000000000000000000000000000..39db96de023a8caa69442591c73= b2e1322df3a30 --- /dev/null +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::HasHrTimer; +use super::HrTimer; +use super::HrTimerCallback; +use super::HrTimerHandle; +use super::HrTimerPointer; +use super::RawHrTimerCallback; +use crate::prelude::*; +use crate::time::Ktime; +use core::mem::ManuallyDrop; + +/// A handle for a [`Box>`] returned by a call to +/// [`HrTimerPointer::start`]. +pub struct BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + pub(crate) inner: *mut T, + _p: core::marker::PhantomData, +} + +// SAFETY: We implement drop below, and we cancel the timer in the drop +// implementation. +unsafe impl HrTimerHandle for BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + fn cancel(&mut self) -> bool { + // SAFETY: As we obtained `self.inner` from a valid reference when= we + // created `self`, it must point to a valid `T`. + let timer_ptr =3D unsafe { >::raw_get_timer(sel= f.inner) }; + + // SAFETY: As `timer_ptr` points into `T` and `T` is valid, `timer= _ptr` + // must point to a valid `HrTimer` instance. + unsafe { HrTimer::::raw_cancel(timer_ptr) } + } +} + +impl Drop for BoxHrTimerHandle +where + T: HasHrTimer, + A: crate::alloc::Allocator, +{ + fn drop(&mut self) { + self.cancel(); + // SAFETY: `self.inner` came from a `Box::into_raw` call + drop(unsafe { Box::::from_raw(self.inner) }) + } +} + +impl HrTimerPointer for Pin> +where + T: Send + Sync, + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + T: for<'a> HrTimerCallback =3D Pin<&'a T>>, + A: crate::alloc::Allocator, +{ + type TimerHandle =3D BoxHrTimerHandle; + + fn start(self, expires: Ktime) -> Self::TimerHandle { + let self_ptr: *const T =3D ::deref(&self= ); + + // SAFETY: Since we generate the pointer passed to `start` from a = valid + // reference, it is a valid pointer. + unsafe { T::start(self_ptr, expires) }; + + // SAFETY: We will not move out of this box during timer callback = (we + // pass an immutable reference to the callback). + let inner =3D unsafe { Pin::into_inner_unchecked(self) }; + + BoxHrTimerHandle { + inner: Box::into_raw(inner), + _p: core::marker::PhantomData, + } + } +} + +impl RawHrTimerCallback for Pin> +where + T: HasHrTimer, + T: for<'a> HrTimerCallback =3D Pin>>, + T: for<'a> HrTimerCallback =3D Pin<&'a T>>, + A: crate::alloc::Allocator, +{ + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { + // `HrTimer` is `repr(C)` + let timer_ptr =3D ptr.cast::>(); + + // SAFETY: By C API contract `ptr` is the pointer we passed when + // queuing the timer, so it is a `HrTimer` embedded in a `T`. + let data_ptr =3D unsafe { T::timer_container_of(timer_ptr) }; + + // SAFETY: We called `Box::into_raw` when we queued the timer. + let tbox =3D ManuallyDrop::new(Box::into_pin(unsafe { Box:::= :from_raw(data_ptr) })); + + T::run(tbox.as_ref()).into() + } +} --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF986209F24; Mon, 3 Feb 2025 15:10: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=1738595418; cv=none; b=NcJEAbXah0uSTLPrH18QtlVAoNGsldjwFzP/e3jEsFDC2IiN0P+71B92cfW45p2Pmar0atW5PM8sMCDzRmr56NbSjKMpLMbc/3vTbBvwoA7JOtweYLkrUp23Sge0dIYzpDjQMj3yW04qSYe+3rJHp6IndTgf3P1hkjKPOhc+I4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595418; c=relaxed/simple; bh=8XpJSLJ55SDaveXMAsKmhWitbwmSWaNN5s8GVphJwa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SZCH0FQ17gUZszGOYR9xy+LxFjRSdvUefrZcROnxvT2N3P9k8asmZrTY2G4JjyNdS3QCp/qYCALdsRV4mosDX6U+S0a+qdt8m9hyrNJRFlzVDYKKtYYh+GwFqNaqmsMGzpI0YZ8YPO7sTNfDfyyAyLCjpo8F/lKIA0GhhtC0RSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JJpJHC0x; 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="JJpJHC0x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8904CC4CED2; Mon, 3 Feb 2025 15:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595418; bh=8XpJSLJ55SDaveXMAsKmhWitbwmSWaNN5s8GVphJwa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JJpJHC0x07Y5CchLCvOLz9TBYC47t98cl7rBlbmGvZmzuB4MO0SV1xH2KeNTUMES9 8oZ5v8uvofJpXq+xCl6bY3nVryrpcKi5508RYFjclcNKQtIODnxyEFbxL2/6qrFpjw sAENjnBXtZlu4uZuRlAwXo7KObmUNCsgsWYZbl9VVOPbrTRpsBAAVpC/9pOsqek6dD AcwnNYTmIlkrTZ6eFJpGf+9tCmcAz8WKW/WFk7G4lvi249f9VHKBcMRgCq8dOINwXp qjFL3RUELAMpS6Ulo6WK/o6SbRVkjW6PYXbtn/wGVnd3mwwcR887MvwUhrb0GYw7XI Uf+1WPAXUSN9g== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:58 +0100 Subject: [PATCH v7 12/14] rust: hrtimer: add `HrTimerMode` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250203-hrtimer-v3-v6-12-rc2-v7-12-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5684; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=8XpJSLJ55SDaveXMAsKmhWitbwmSWaNN5s8GVphJwa8=; b=kA0DAAgB4bgaPnkoY3cByyZiAGeg29mg1CJLD7qglfAHRz/AtnmuDAWDlGEUKD7x6RpE6GPnU okCMwQAAQgAHRYhBBLB+UdWv3wqFdbAEuG4Gj55KGN3BQJnoNvZAAoJEOG4Gj55KGN3YpcP/iLA gqInH0l83EXOodpR/B8oqfNyHqnar4uAQDSpdPSle4fraeRVX3z3rZd6lluyQqxXjXOzy/PncGi GBij8nbsfXul45u36eeSzmOxy/s52lKWZYeHWB0kSF2v2m62tZ+cB5IQTIVdf83k8pV0NmeTdoU CKUTNEgIi99pp/04bMepRhdIQ1Igi38qyBpJzpK4VEZ1OzHV5B9YEL1LwxgvPfUj6fRVhydJGGH Lfvq9ivD0X3nueLIUksz7WV1tEzVuamtjtx8IYhxdJeRGgYtPiQrswfJmT4X6uVMhB3T/JAc3u9 3jU/U4ICGJa+AU8X79zVEG6L73uoP7Mukj2KS5ZIDh/NIr1A8YjcvQuxok8VRTTloDjE4Cp2DjH vDoNKbH+fkCejJsZ74/s7z9x88XENwo0F0wgBmfkzTtMS9KeuSCo/2WmdquDcUAu5lUeolMkzxy dKXAppVLndtZkP7t/DPqIqFmnzKXw13Nq1ga0mCrH3baaNArzfAQOjeLsw1Jrv4w2bim7S48K5C ZAGGfozWybrplFLsugU23uzGBfnT6iLG0HW8RvaNBjM/j0zHjS2H/wQ3Dkt64A+suaXASctjnH4 A3OGxdBC3nWeK5uw8EwDqUglot6z9bTePFkoy5uc6TaJ2TpmPPKBPVcvQHbbYdy+r7Ulb8LdKIz riESH X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selection of timer mode by passing a `HrTimerMode` variant to `HrTimer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 86 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 5eaf86fd099566e9d837a1d394e666fcb8f8dab4..6a7344cb32647b6ed033c22fc37= 74981708c3a67 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -59,6 +59,7 @@ pub struct HrTimer { #[pin] timer: Opaque, + mode: HrTimerMode, _t: PhantomData, } =20 @@ -72,7 +73,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new() -> impl PinInit + pub fn new(mode: HrTimerMode) -> impl PinInit where T: HrTimerCallback, { @@ -87,10 +88,11 @@ pub fn new() -> impl PinInit place, Some(T::CallbackTarget::run), bindings::CLOCK_MONOTONIC as i32, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + mode.into(), ); } }), + mode: mode, _t: PhantomData, }) } @@ -336,7 +338,7 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) { Self::c_timer_ptr(self_ptr).cast_mut(), expires.to_ns(), 0, - bindings::hrtimer_mode_HRTIMER_MODE_REL, + (*Self::raw_get_timer(self_ptr)).mode.into(), ); } } @@ -368,6 +370,84 @@ fn from(value: HrTimerRestart) -> Self { } } =20 +/// Operational mode of [`HrTimer`]. +#[derive(Clone, Copy)] +pub enum HrTimerMode { + /// Timer expires at the given expiration time. + Absolute, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + Relative, + /// Timer does not move between CPU cores. + Pinned, + /// Timer handler is executed in soft irq context. + Soft, + /// Timer handler is executed in hard irq context. + Hard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + AbsolutePinned, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + RelativePinned, + /// Timer expires at the given expiration time. + /// Timer handler is executed in soft irq context. + AbsoluteSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in soft irq context. + RelativeSoft, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + AbsolutePinnedSoft, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in soft irq context. + RelativePinnedSoft, + /// Timer expires at the given expiration time. + /// Timer handler is executed in hard irq context. + AbsoluteHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer handler is executed in hard irq context. + RelativeHard, + /// Timer expires at the given expiration time. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + AbsolutePinnedHard, + /// Timer expires after the given expiration time interpreted as a dur= ation from now. + /// Timer does not move between CPU cores. + /// Timer handler is executed in hard irq context. + RelativePinnedHard, +} + +impl From for bindings::hrtimer_mode { + fn from(value: HrTimerMode) -> Self { + use bindings::*; + match value { + HrTimerMode::Absolute =3D> hrtimer_mode_HRTIMER_MODE_ABS, + HrTimerMode::Relative =3D> hrtimer_mode_HRTIMER_MODE_REL, + HrTimerMode::Pinned =3D> hrtimer_mode_HRTIMER_MODE_PINNED, + HrTimerMode::Soft =3D> hrtimer_mode_HRTIMER_MODE_SOFT, + HrTimerMode::Hard =3D> hrtimer_mode_HRTIMER_MODE_HARD, + HrTimerMode::AbsolutePinned =3D> hrtimer_mode_HRTIMER_MODE_ABS= _PINNED, + HrTimerMode::RelativePinned =3D> hrtimer_mode_HRTIMER_MODE_REL= _PINNED, + HrTimerMode::AbsoluteSoft =3D> hrtimer_mode_HRTIMER_MODE_ABS_S= OFT, + HrTimerMode::RelativeSoft =3D> hrtimer_mode_HRTIMER_MODE_REL_S= OFT, + HrTimerMode::AbsolutePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_SOFT, + HrTimerMode::RelativePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_SOFT, + HrTimerMode::AbsoluteHard =3D> hrtimer_mode_HRTIMER_MODE_ABS_H= ARD, + HrTimerMode::RelativeHard =3D> hrtimer_mode_HRTIMER_MODE_REL_H= ARD, + HrTimerMode::AbsolutePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_HARD, + HrTimerMode::RelativePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_HARD, + } + } +} + +impl From for u64 { + fn from(value: HrTimerMode) -> Self { + Into::::into(value) as u64 + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E89CE208969; Mon, 3 Feb 2025 15:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595394; cv=none; b=CuZprf71RYda5FOKmj/VZFi/XTXPHtD9wZWW/T7E+WEoWRyQALlHW6s3Ix/WB/sizIYAweYRQhco5sXKfjdlLRBGLWVP6qYZi+aDCOho2E6v4oUal1G39PNpe73a7DYvZM7Gdp2LVq9W/tQ/Sp3Pogt685mW/B2hyt5qrD1qvGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595394; c=relaxed/simple; bh=mPCXOTNw3fV8ROYk0QkFsga+IGKpcdmhxz0eOJ4TGTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AwVYCa6StZ+hvLWWHH4lJcUk6CSB11aU8XAe0oq6BNuAyY4yWzHqWoVm0ShtUQ2UzTVfzX+xglOf6uXYV3ogMIHHXYJHExtkvAeNWOFEUHW0mgBuE5tEU6i0iCUAdhtpzewmJw2tcCyrw3aGazaBx91rODw69Vcm2IGz17CYaAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YAfO20X6; 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="YAfO20X6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA906C4CEE0; Mon, 3 Feb 2025 15:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595392; bh=mPCXOTNw3fV8ROYk0QkFsga+IGKpcdmhxz0eOJ4TGTM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YAfO20X6BfQmjZbJxZ1tHMRmWtaaL3OgdurpnWGG+5Mh8MZH3n9aXDAs6qEtA+FGF UTXN2G7TINh/fTl9l4qe3r3B6gLcWjG4QKFpyl/51TaPVLXjAsTbw19n6W8NFFLakR QfdeDhSQGgr5JZ9ApK7Or9a0IxBx6/c9zOwnukPx5pLLB2/DkPc9auirhQ7wBSgD+1 2KWXo2GTp3vkdp/HIpGJkEUaBh6at01d/CKl7lb3kWVUKvVpgExEzJbW0zoME92adg SOlb8tnxkhw7m7s9alEw40j5kxMZOg52wbobrYKvDHT1gSNT0etcQFwhb3z+Z1/ktW eTXa9Jk45NxDg== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:07:59 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-13-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4052; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=mPCXOTNw3fV8ROYk0QkFsga+IGKpcdmhxz0eOJ4TGTM=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvayf8eo7Va9PqH1uyARlh3GcrEKsLMbWZKH IKUDGLSZN2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db2gAKCRDhuBo+eShj d4NUD/45zBevqrRd7f059HTRKFT3T49H/E22kn7Eo7nzGlLUz+HKFIqRsTCNh3ciCVewuMWkEx5 Y/DJ+V0e16YDuE0sTzxz9JNpU4iWOqvVr+ugwhy86OyDhF/rwLNnbNZATzsrx0F6uQ7h1NTs+eS WZuu5i7Lz9Llhrn9y0RJTbkVHcnWegq8AE1XRgrc2bbbtsHMWWvdReEEMa8uE0Qbg7ll+dyCnSF fWC2el2SzgIFiqizYv3d5+d2Tke5GHm48jDojr+1xYNFgY+cBxxu5WT1qGlsPqne4+lrijM/NaJ Y4gIj4l/tjn9vRuxIzlzWtY2MYTTzTLgrZCjBsjOpTWpJivvhDtbxkrnpE/5eupC0f1PAy3XY3i WTu/bTTM8vb377Ymz/uiACPs55mDwKZFjv2yneSxcPABIF9an32XCMd7DpkKrf+TCC66bolUTWY yk4+dIQeYqrYOmn6BVlS2SSS6MEDonx1dqqgzdgik0Jaj5NPIRWRQPkchCazVxv/2BwOOMO8iq7 Budmh+gbYwwgdJHk2s9CywoMEz7NGSaJduJc9poP0GZtVOwaeVm+LsTdeMou0WI0XRxnBSP//Oz HIVzeFt3vJKnpCI5iAZvIvf1/jU4sr0XqvSv9zsGpkoNC45MxN1m9qGQNPSDNiTYcH61tn1Hj2R MM2i3eszGSBAxyQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow selecting a clock source for timers by passing a `ClockSource` variant to `HrTimer::new`. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 52 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 6a7344cb32647b6ed033c22fc3774981708c3a67..6de8c9d52fd57c491c9ce5eac69= 04ed89039ba0c 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -73,7 +73,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new(mode: HrTimerMode) -> impl PinInit + pub fn new(mode: HrTimerMode, clock: ClockSource) -> impl PinInit where T: HrTimerCallback, { @@ -87,7 +87,7 @@ pub fn new(mode: HrTimerMode) -> impl PinInit bindings::hrtimer_setup( place, Some(T::CallbackTarget::run), - bindings::CLOCK_MONOTONIC as i32, + clock.into(), mode.into(), ); } @@ -448,6 +448,54 @@ fn from(value: HrTimerMode) -> Self { } } =20 +/// The clock source to use for a [`HrTimer`]. +pub enum ClockSource { + /// A settable system-wide clock that measures real (i.e., wall-clock)= time. + /// Setting this clock requires appropriate privileges. This clock is + /// affected by discontinuous jumps in the system time (e.g., if the s= ystem + /// administrator manually changes the clock), and by frequency adjust= ments + /// performed by NTP and similar applications via adjtime(3), adjtimex= (2), + /// clock_adjtime(2), and ntp_adjtime(3). This clock normally counts t= he + /// number of seconds since 1970-01-01 00:00:00 Coordinated Universal = Time + /// (UTC) except that it ignores leap seconds; near a leap second it is + /// typically adjusted by NTP to stay roughly in sync with UTC. + RealTime, + /// A nonsettable system-wide clock that represents monotonic time sin= ce=E2=80=94as + /// described by POSIX=E2=80=94"some unspecified point in the past". O= n Linux, that + /// point corresponds to the number of seconds that the system has been + /// running since it was booted. + /// + /// The CLOCK_MONOTONIC clock is not affected by discontinuous jumps i= n the + /// system time (e.g., if the system administrator manually changes the + /// clock), but is affected by frequency adjustments. This clock does = not + /// count time that the system is suspended. + Monotonic, + /// A nonsettable system-wide clock that is identical to CLOCK_MONOTON= IC, + /// except that it also includes any time that the system is suspended= . This + /// allows applications to get a suspend-aware monotonic clock without + /// having to deal with the complications of CLOCK_REALTIME, which may= have + /// discontinuities if the time is changed using settimeofday(2) or si= milar. + BootTime, + /// A nonsettable system-wide clock derived from wall-clock time but + /// counting leap seconds. This clock does not experience discontinuit= ies or + /// frequency adjustments caused by inserting leap seconds as CLOCK_RE= ALTIME + /// does. + /// + /// The acronym TAI refers to International Atomic Time. + TAI, +} + +impl From for bindings::clockid_t { + fn from(value: ClockSource) -> Self { + match value { + ClockSource::RealTime =3D> bindings::CLOCK_REALTIME as i32, + ClockSource::Monotonic =3D> bindings::CLOCK_MONOTONIC as i32, + ClockSource::BootTime =3D> bindings::CLOCK_BOOTTIME as i32, + ClockSource::TAI =3D> bindings::CLOCK_TAI as i32, + } + } +} + /// Use to implement the [`HasHrTimer`] trait. /// /// See [`module`] documentation for an example. --=20 2.47.0 From nobody Sun Feb 8 15:01:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DE75208969; Mon, 3 Feb 2025 15:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595398; cv=none; b=KvHJLhUozTuSCqRDxzTeTVeYoW5+HIBqtq8WIZR05EgIXpmNZxEo0F9/ol0XNaaQG1f8BqCt/A6PXNoF+KbPwf+urCM3CnY7MLmSs4FVfoJocwqLetrL+ebXS357vgM1VCKHFOZpK66AZTxdJZuakefp6gbbPjfGKNULTSrZBHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738595398; c=relaxed/simple; bh=/UZpvRA67HxsywtAor/ry48Oc3HuQY3KQS+pRcQdRrc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xs4lKqWcTVKdJPBllQJ85XeGt1mNA1/OhgcSDOQY5mXb62SZDxc3FERHkmKNoo0ns7XsDl/Xby13aWdM/fuhrMwUdK4+1Gjh6M0z0XIDxK9XVd6deMVXdWSRaagIgQeEs4Tyy7rjmb618mwPaYL1kevJVgAVpimvzHHfI04fHJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f9+SSj+L; 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="f9+SSj+L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 040C1C4CED2; Mon, 3 Feb 2025 15:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738595397; bh=/UZpvRA67HxsywtAor/ry48Oc3HuQY3KQS+pRcQdRrc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=f9+SSj+LoKmUHxCf7yrq4GqBNE/6DcX3Kj+CgoEvWzm+HpgtEBHOUbEccQFQG0A3v lCeX69RNLP6Y984m1Ypji1ESNdqq8d4/eJK3ScRDi0YVAeBgAZyLKMANeAJCzgfC8d 8RqwU51wTT3lXxkm4LR5T9XDCMyGGxi1Y5ZHI8DjvhALn32vpgGbsY73pLhu/HSEt3 SWvVOwRoHhZR5HbwZgr1fPXWB+eD7x0qgzmrC9ULhy14yWrEtyevc6jDdDU2leYdrn PGXIk+EiW49QKT/5st/EIS/YhbnaDoY5uStTxjOJki0uKBjmIznTmPEH37p76fxMlw BkObQWG24U2Hg== From: Andreas Hindborg Date: Mon, 03 Feb 2025 16:08:00 +0100 Subject: [PATCH v7 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: <20250203-hrtimer-v3-v6-12-rc2-v7-14-189144725399@kernel.org> References: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> In-Reply-To: <20250203-hrtimer-v3-v6-12-rc2-v7-0-189144725399@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=995; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=/UZpvRA67HxsywtAor/ry48Oc3HuQY3KQS+pRcQdRrc=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBnoNvbIRaLV5P15ah2l0mZuN0T8cgdq5k0DuSHx vhYFx8u/UaJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCZ6Db2wAKCRDhuBo+eShj d0FWEACZNWgT+1stRqTEskc7X2kC6dNamvxQ38KC3RnEjrJBy7W/Q/WLzvh5TdAY2H49cI1Mdb+ bl/gNUVcvjUHKdZkvIjqheetLj+WnMRFKD2A/wE/pfGkLeKgxLskErgnu8OWUtDPZ4fz0CURklU fjeWkj3b1enbxj8cMChuPqG9W+QcJxzZ9obIgujIqdKoP7hYgOqwUJco8Sz7xhltWVNO9dOQXoQ k1KRyJ0U8rDI4xUIawlsjgA5tSvDC1xnbEyFudiU9nZ19UCupLqlezVPx+dey1kLHupRkSNCj5g oBCCsf9OP4jmq5isV/c3u5k6MHG1YaFDBvD9r+Yk64QOwnVQoZR3TLpiJ3MTwpaVKcHeAkawh6d 25n48tmIbAwdc5l46LaJKPF+4cZJBJ4OCoe6Y98h3VZ10VMsiTkt1cJj4mwkiCtIeItbzuqz/s6 25mCQmdF1w6XZ+mmPPYUG01+KRX/RhZqLT7+CCy/VBQELtloGaGZ8/SKlFe6d0JIB0dvozM/+UY Zdu0ZpC9dpyy8bPkDgTwd4KZDxeDr6+t0UGsvQ79IyPAOk1Q3Saf5PcZB94f5zgxe4WtFVOdGoj sdNVArsuh9eN3VlPMhJhp3r0dTea2FtsYXg6OpCnpDnRzZoA4EptKyCWw1JEwocLsZdfVSsBH7Q HOxh0Rn8dsUe/6w== 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 896a307fa06545e2861abe46ea7029f9b4d3628e..60fa77c41b3fb22f859d330e3ea= f2701bcda3b3f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10355,6 +10355,16 @@ F: kernel/time/timer_list.c F: kernel/time/timer_migration.* F: tools/testing/selftests/timers/ =20 +HIGH-RESOLUTION TIMERS [RUST] +M: Andreas Hindborg +R: Boqun Feng +L: rust-for-linux@vger.kernel.org +S: Supported +W: https://rust-for-linux.com +B: https://github.com/Rust-for-Linux/linux/issues +F: rust/kernel/time/hrtimer.rs +F: rust/kernel/time/hrtimer/ + HIGH-SPEED SCC DRIVER FOR AX.25 L: linux-hams@vger.kernel.org S: Orphan --=20 2.47.0