From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Gary Guo" <gary@garyguo.net>,
"FUJITA Tomonori" <tomo@aliasing.net>
Cc: <ojeda@kernel.org>, <dirk.behme@de.bosch.com>,
<aliceryhl@google.com>, <anna-maria@linutronix.de>,
<bjorn3_gh@protonmail.com>, <boqun@kernel.org>, <dakr@kernel.org>,
<frederic@kernel.org>, <jstultz@google.com>, <lossin@kernel.org>,
<lyude@redhat.com>, <sboyd@kernel.org>, <tglx@kernel.org>,
<tmgross@umich.edu>, <rust-for-linux@vger.kernel.org>,
<fujita.tomonori@gmail.com>
Subject: Re: [PATCH v2] rust: hrtimer: Restrict expires() to safe contexts
Date: Mon, 23 Mar 2026 12:41:30 +0000 [thread overview]
Message-ID: <DHA643CROTOZ.X3N2KZKS8HB5@garyguo.net> (raw)
In-Reply-To: <87ldg0m6rp.fsf@t14s.mail-host-address-is-not-set>
On Tue Mar 10, 2026 at 8:24 AM GMT, Andreas Hindborg wrote:
> "Gary Guo" <gary@garyguo.net> writes:
>
>> On Sat Feb 28, 2026 at 1:26 AM GMT, FUJITA Tomonori wrote:
>>> On Fri, 27 Feb 2026 12:32:05 +0000
>>> "Gary Guo" <gary@garyguo.net> wrote:
>>>
>>>> On Thu Feb 26, 2026 at 6:33 PM GMT, Andreas Hindborg wrote:
>>>>> "Gary Guo" <gary@garyguo.net> writes:
>>>>>
>>>>>> Does it make sense to simply have `HrTimerCallback<'a, T: ...>(&'a HrTimer<T>)`?
>>>>>
>>>>> I assume you mean `HrTimerCallbackContext`.
>>>>>
>>>>> Could it be a mut reference? We are supposed to have exclusive access
>>>>> when we have the context.
>>>>
>>>> If `Pin<&mut Hrtimer>` would work, then we can perhaps remove the
>>>> `HrTimerCallbackContext` type and just pass a `Pin<&mut HrTimer>` to the callback?
>>>
>>> During the callback, ArcTimerHandle still holds Arc<T>, and the
>>> callback receives ArcBorrow<T>. Creating Pin<&mut HrTimer<T>> would
>>> cause aliasing between &HrTimer<T> and &mut HrTimer<T>?
>>
>> This is fine from an aliasing POV as `Opaque` cancels the noalias requirement
>> of `&mut` already.
>>
>> As long as we can guarantee that no method on `Pin<&mut HrTimer<T>>` can race
>> with methods on `&HrTimer<T>` it should be okay.
>
> Is this really OK?
>
> struct Foo {
> timer: HrTimer<Foo>,
> }
>
> Surely it cannot be OK to hold both `&Foo` and `Pin<&mut HrTimer<Foo>>`,
> even though the internals of `HrTimer<_>` is an `Opaque` field?
It's not UB to hold both, otherwise you cannot write intrusive data structures.
It might be useful to think the mutable reference that the hrtime callback
receives is th same as getting a reference to mutex content, while others can
still reference the mutex.
We can probably have two types, where one can have shared refs (for starting the
timer) and the other is exclusive only?
Best,
Gary
prev parent reply other threads:[~2026-03-23 12:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 13:25 [PATCH v2] rust: hrtimer: Restrict expires() to safe contexts FUJITA Tomonori
2026-02-26 11:42 ` Gary Guo
2026-02-26 12:50 ` FUJITA Tomonori
2026-02-26 13:19 ` Andreas Hindborg
2026-02-26 14:16 ` Gary Guo
2026-02-26 18:33 ` Andreas Hindborg
2026-02-27 12:32 ` Gary Guo
2026-02-28 1:26 ` FUJITA Tomonori
2026-02-28 13:02 ` Gary Guo
2026-02-28 21:23 ` FUJITA Tomonori
2026-03-10 8:24 ` Andreas Hindborg
2026-03-23 12:41 ` Gary Guo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DHA643CROTOZ.X3N2KZKS8HB5@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=dirk.behme@de.bosch.com \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=jstultz@google.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=tmgross@umich.edu \
--cc=tomo@aliasing.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox