public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
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: Fri, 27 Feb 2026 12:32:05 +0000	[thread overview]
Message-ID: <DGPQVSXND3M9.1738YQZSFDNDJ@garyguo.net> (raw)
In-Reply-To: <87qzq7bbig.fsf@t14s.mail-host-address-is-not-set>

On Thu Feb 26, 2026 at 6:33 PM GMT, Andreas Hindborg wrote:
> "Gary Guo" <gary@garyguo.net> writes:
>
>> On Thu Feb 26, 2026 at 1:19 PM GMT, Andreas Hindborg wrote:
>>> FUJITA Tomonori <tomo@aliasing.net> writes:
>>>
>>>> On Thu, 26 Feb 2026 11:42:39 +0000
>>>> "Gary Guo" <gary@garyguo.net> wrote:
>>>>
>>>> >> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
>>>> >> index 856d2d929a00..78e2343fd016 100644
>>>> >> --- a/rust/kernel/time/hrtimer.rs
>>>> >> +++ b/rust/kernel/time/hrtimer.rs
>>>> >> @@ -224,27 +224,39 @@ pub fn forward_now(self: Pin<&mut Self>, interval: Delta) -> u64
>>>> >>          self.forward(HrTimerInstant::<T>::now(), interval)
>>>> >>      }
>>>> >>
>>>> >> +    /// Return the time expiry for this [`HrTimer`].
>>>> >> +    ///
>>>> >> +    /// # Safety
>>>> >> +    ///
>>>> >> +    /// - `self_ptr` must point to a valid `Self`.
>>>> >> +    /// - The caller must either have exclusive access to the data pointed to by `self_ptr`, or be
>>>> >> +    ///   within the context of the timer callback.
>>>> >> +    #[inline]
>>>> >> +    unsafe fn raw_expires(self_ptr: *const Self) -> HrTimerInstant<T>
>>>> >
>>>> > I guess the signature of this can also be
>>>> >
>>>> > `unsafe fn raw_expires(&self) -> HrTimerInstant<T>`? Then you can remove the
>>>> > first safety requirement.
>>>>
>>>> Thanks, I've updated the signature to use &self.
>>>>
>>>> Andreas, this breaks the consistency with raw_forward. Is this
>>>> acceptable?
>>>
>>> If we do this, we get to argue that the NonNull we have in the callback context
>>> is convertible to a reference. Either way is fine with me.
>>>
>>> If you change this to a reference, then I think we should rename the function to
>>> `expires_unchecked`. The `raw` usually refers to operations on pointers rather
>>> than references.
>>
>> 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?

Best,
Gary

>
>
> Best regards,
> Andreas Hindborg


  reply	other threads:[~2026-02-27 12:32 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 [this message]
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

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=DGPQVSXND3M9.1738YQZSFDNDJ@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