Re: [PATCH v11 08/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>`
From: Andreas Hindborg
Date: Sun Mar 09 2025 - 05:50:35 EST
"Benno Lossin" <benno.lossin@xxxxxxxxx> writes:
> On Fri Mar 7, 2025 at 10:38 PM CET, Andreas Hindborg wrote:
>> Allow pinned mutable references to structs that contain a `HrTimer` node to
>> be scheduled with the `hrtimer` subsystem.
>>
>> Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
>> Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>
> One problem below, with that fixed:
>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
Thanks, will fix.
>
>> ---
>> rust/kernel/time/hrtimer.rs | 2 +
>> rust/kernel/time/hrtimer/pin_mut.rs | 110 ++++++++++++++++++++++++++++++++++++
>> 2 files changed, 112 insertions(+)
>>
>> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
>> index fee8e44447ee..ab0950a964e8 100644
>> --- a/rust/kernel/time/hrtimer.rs
>> +++ b/rust/kernel/time/hrtimer.rs
>> @@ -433,3 +433,5 @@ unsafe fn timer_container_of(
>> pub use arc::ArcHrTimerHandle;
>> mod pin;
>> pub use pin::PinHrTimerHandle;
>> +mod pin_mut;
>> +pub use pin_mut::PinMutHrTimerHandle;
>> diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer/pin_mut.rs
>> new file mode 100644
>> index 000000000000..007f47d26df6
>> --- /dev/null
>> +++ b/rust/kernel/time/hrtimer/pin_mut.rs
>> @@ -0,0 +1,110 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +use super::{
>> + HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, RawHrTimerCallback, UnsafeHrTimerPointer,
>> +};
>> +use crate::time::Ktime;
>> +use core::{marker::PhantomData, pin::Pin, ptr::NonNull};
>> +
>> +/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the timer might
>> +/// be running.
>> +pub struct PinMutHrTimerHandle<'a, T>
>> +where
>> + T: HasHrTimer<T>,
>> +{
>> + pub(crate) inner: NonNull<T>,
>> + _p: PhantomData<&'a T>,
>
> This should be `PhantomData<&'a mut T>`.
Nice catch!
Best regards,
Andreas Hindborg