[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <D8A3PZPLKPA0.1CWNFJG4RSWKE@proton.me>
Date: Fri, 07 Mar 2025 14:25:24 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>, Anna-Maria Behnsen <anna-maria@...utronix.de>, Frederic Weisbecker <frederic@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Danilo Krummrich <dakr@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, Lyude Paul <lyude@...hat.com>, Guangbo Cui <2407018371@...com>, Dirk Behme <dirk.behme@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>, Tamir Duberstein <tamird@...il.com>, Markus Elfring <Markus.Elfring@....de>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v10 07/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>`
On Fri Mar 7, 2025 at 3:21 PM CET, Andreas Hindborg wrote:
> "Benno Lossin" <benno.lossin@...ton.me> writes:
>
>> On Fri Mar 7, 2025 at 2:37 PM CET, Andreas Hindborg wrote:
>>> "Benno Lossin" <benno.lossin@...ton.me> writes:
>>>> On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote:
>>>>> +impl<'a, T> RawHrTimerCallback for Pin<&'a T>
>>>>> +where
>>>>> + T: HasHrTimer<T>,
>>>>> + T: HrTimerCallback<Pointer<'a> = Self>,
>>>>> +{
>>>>> + type CallbackTarget<'b> = Self;
>>>>> +
>>>>> + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart {
>>>>> + // `HrTimer` is `repr(C)`
>>>>> + let timer_ptr = ptr as *mut HrTimer<T>;
>>>>> +
>>>>> + // SAFETY: By the safety requirement of this function, `timer_ptr`
>>>>> + // points to a `HrTimer<T>` contained in an `T`.
>>>>> + let receiver_ptr = unsafe { T::timer_container_of(timer_ptr) };
>>>>> +
>>>>> + // SAFETY: By the safety requirement of this function, `timer_ptr`
>>>>> + // points to a `HrTimer<T>` contained in an `T`.
>>>>
>>>> This justification seems wrong it talks about `HrTimer<T>`, but here we
>>>> have a `*const T`... Also see [1] (I am mainly interested in your
>>>> justification for the lifetime).
>>>>
>>>> [1]: https://doc.rust-lang.org/std/ptr/index.html#pointer-to-reference-conversion
>>>
>>> How is this:
>>>
>>> // SAFETY:
>>> // - By the safety requirement of this function, `timer_ptr`
>>> // points to a `HrTimer<T>` contained in an `T`.
>>> // - The `PinHrTimerHandle` associated with this timer is guaranteed to
>>> // be alive until this method returns. As the handle borrows from
>>> // `T`, `T` is also guaranteed to be alive for the duration of this
>>> // function.
>>
>> Sounds good, if you can also explain (probably somewhere else, as every
>> `RawHrTimerCallback` implementer will rely on this) why the handle lives
>> for the duration of the callback.
>
> It is in the safety requirement for the `HrTimerHandle` trait already.
> Should I reference it here?
Yes please!
---
Cheers,
Benno
Powered by blists - more mailing lists