[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <D8A3PCB7F5L8.36WN92Y4Y9AP9@proton.me>
Date: Fri, 07 Mar 2025 14:24:32 +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 03/13] rust: hrtimer: implement `HrTimerPointer` for `Arc`
On Fri Mar 7, 2025 at 3:16 PM CET, Andreas Hindborg wrote:
> "Benno Lossin" <benno.lossin@...ton.me> writes:
>> On Fri Mar 7, 2025 at 2:27 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<T> RawHrTimerCallback for Arc<T>
>>>>> +where
>>>>> + T: 'static,
>>>>> + T: HasHrTimer<T>,
>>>>> + T: for<'a> HrTimerCallback<Pointer<'a> = Self>,
>>>>> +{
>>>>> + type CallbackTarget<'a> = ArcBorrow<'a, T>;
>>>>> +
>>>>> + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart {
>>>>> + // `HrTimer` is `repr(C)`
>>>>> + let timer_ptr = ptr.cast::<super::HrTimer<T>>();
>>>>> +
>>>>> + // SAFETY: By C API contract `ptr` is the pointer we passed when
>>>>> + // queuing the timer, so it is a `HrTimer<T>` embedded in a `T`.
>>>>> + let data_ptr = 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`.
>>>>
>>>> You're not justifying all safety requirements of `ArcBorrow::from_raw`.
>>>
>>> How is this:
>>>
>>> // SAFETY:
>>> // - `data_ptr` is derived form the pointer to the `T` that was used to
>>> // queue the timer.
>>> // - The `ArcTimerHandle` associated with this timer is guaranteed to
>>> // be alive for the duration of the lifetime of `receiver`, so the
>>
>> There is no `receiver` in this context?
>
> It's the value returned from the call, same line.
Ah my bad.
>
>> Is the reason for the handle staying alive that when it is dropped, it
>> calls `cancel` and that waits until the callback finishes? If so, did
>> you write that down somewhere here?
>
> Yes, it is in the safety requirement of the `HrTimerHandle` trait.
> Should I add that? It becomes quite a story.
Yeah, I think you should add it.
---
Cheers,
Benno
>>> // refcount of the underlying `Arc` is guaranteed to be nonzero for
>>> // the duration.
>>> // - We own one refcount in the `ArcTimerHandle` associted with this
>>> // timer, so it is not possible to get a `UniqueArc` to this
>>> // allocation from other `Arc` clones.
>>
>> Otherwise this sounds good.
>
> Cool.
>
>
> Best regards,
> Andreas Hindborg
Powered by blists - more mailing lists