From: Daniel Almeida <daniel.almeida@collabora.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Benno Lossin" <lossin@kernel.org>,
"Dirk Behme" <dirk.behme@gmail.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH] rust: irq: add &Device<Bound> argument to irq callbacks
Date: Sun, 10 Aug 2025 21:49:14 -0300 [thread overview]
Message-ID: <0303C763-76CC-456D-AB76-215DF253560C@collabora.com> (raw)
In-Reply-To: <CAH5fLghRi-QAqGdxOhPPdp6bMyGSuDifnxMFBn3a3NWzN4G4vQ@mail.gmail.com>
> On 21 Jul 2025, at 16:33, Alice Ryhl <aliceryhl@google.com> wrote:
>
> On Mon, Jul 21, 2025 at 9:14 PM Daniel Almeida
> <daniel.almeida@collabora.com> wrote:
>>
>> Alice,
>>
>>> On 21 Jul 2025, at 11:38, Alice Ryhl <aliceryhl@google.com> wrote:
>>>
>>> When working with a bus device, many operations are only possible while
>>> the device is still bound. The &Device<Bound> type represents a proof in
>>> the type system that you are in a scope where the device is guaranteed
>>> to still be bound. Since we deregister irq callbacks when unbinding a
>>> device, if an irq callback is running, that implies that the device has
>>> not yet been unbound.
>>>
>>> To allow drivers to take advantage of that, add an additional argument
>>> to irq callbacks.
>>>
>>> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
>>> ---
>>> This patch is a follow-up to Daniel's irq series [1] that adds a
>>> &Device<Bound> argument to all irq callbacks. This allows you to use
>>> operations that are only safe on a bound device inside an irq callback.
>>>
>>> The patch is otherwise based on top of driver-core-next.
>>>
>>> [1]: https://lore.kernel.org/r/20250715-topics-tyr-request_irq2-v7-0-d469c0f37c07@collabora.com
>>
>> I am having a hard time applying this locally.
>
> Your irq series currently doesn't apply cleanly on top of
> driver-core-next and requires resolving a minor conflict. You can find
> the commits here:
> https://github.com/Darksonn/linux/commits/sent/20250721-irq-bound-device-c9fdbfdd8cd9-v1/
Ah, we’ve already discussed this, it seems.
>
>>> ///
>>> /// This function should be only used as the callback in `request_irq`.
>>> unsafe extern "C" fn handle_irq_callback<T: Handler>(_irq: i32, ptr: *mut c_void) -> c_uint {
>>> - // SAFETY: `ptr` is a pointer to T set in `Registration::new`
>>> - let handler = unsafe { &*(ptr as *const T) };
>>> - T::handle(handler) as c_uint
>>> + // SAFETY: `ptr` is a pointer to `Registration<T>` set in `Registration::new`
>>> + let registration = unsafe { &*(ptr as *const Registration<T>) };
>>> + // SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq
>>> + // callback is running implies that the device has not yet been unbound.
>>> + let device = unsafe { registration.inner.device().as_bound() };
>>
>> Where was this function introduced? i.e. I am missing the change that brought
>> in RegistrationInner::device(), or maybe some Deref impl that would make this
>> possible?
>
> In this series:
> https://lore.kernel.org/all/20250713182737.64448-2-dakr@kernel.org/
>
>> Also, I wonder if we can't make the scope of this unsafe block smaller?
>
> I guess we could with an extra `let` statement.
>
> Alice
next prev parent reply other threads:[~2025-08-11 0:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 14:38 Alice Ryhl
2025-07-21 19:13 ` Daniel Almeida
2025-07-21 19:33 ` Alice Ryhl
2025-08-11 0:49 ` Daniel Almeida [this message]
2025-08-11 6:54 ` Alice Ryhl
2025-07-22 11:47 ` Dirk Behme
2025-08-11 0:39 ` Daniel Almeida
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=0303C763-76CC-456D-AB76-215DF253560C@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=dirk.behme@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®