From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>, "Gary Guo" <gary@garyguo.net>
Cc: <bhelgaas@google.com>, <kwilczynski@kernel.org>,
<aliceryhl@google.com>, <daniel.almeida@collabora.com>,
<ojeda@kernel.org>, <boqun@kernel.org>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<a.hindborg@kernel.org>, <tmgross@umich.edu>, <tamird@kernel.org>,
<acourbot@nvidia.com>, <work@onurozkan.dev>,
<jhubbard@nvidia.com>, <ttabi@nvidia.com>, <apopple@nvidia.com>,
<ecourtney@nvidia.com>, <shashanks@nvidia.com>, <zhiw@nvidia.com>,
<driver-core@lists.linux.dev>, <linux-pci@vger.kernel.org>,
<rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/5] rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type
Date: Wed, 12 Aug 2026 19:11:21 +0100 [thread overview]
Message-ID: <DKN6203R3WD1.1NLN19VVBZJO9@garyguo.net> (raw)
In-Reply-To: <DKN5C359PZP3.2BPH5HLM9H0HY@kernel.org>
On Wed Aug 12, 2026 at 6:37 PM BST, Danilo Krummrich wrote:
> On Wed Aug 12, 2026 at 6:26 PM CEST, Gary Guo wrote:
>>> /// IRQ type flags for PCI interrupt allocation.
>>> #[derive(Debug, Clone, Copy)]
>>> @@ -78,6 +75,7 @@ const fn as_raw(self) -> u32 {
>>> #[derive(Clone, Copy)]
>>> pub struct IrqVector<'a> {
>>> dev: &'a Device<Bound>,
>>> + reg: &'a IrqVectorRegistration<'a>,
>>
>> The registration has a refence to the device so we don't need to keep both reg
>> and dev?
>
> In this patch dev is still needed for the TryInto impl, but a subsquent patch
> does remove it in favor of IrqRequest.
>
>>> +pub struct IrqVectorRegistration<'a> {
>>> + dev: &'a Device<Bound>,
>>> + count: NonZero<usize>,
>>
>> I wonder if it should be called "len" as I view this as a collection of IRQ
>> vectors.
>
> Either sounds good to me.
>
>>> + #[inline]
>>> + pub fn vector(&self, index: usize) -> Result<IrqVector<'_>> {
>>> + if index >= self.count.get() {
>>> + return Err(EINVAL);
>>> + }
>>
>> Given that the error is for out-of-bound access only, perhaps return `Option`
>> like `get()` function of various containers?
>
> It's not really a case a driver would handle other than just follow it up with
> .ok_or(EINVAL)? anyways, so I'd like to keep that.
Well, I'd expect some drivers want to do `.vector(v).expect()` rather than just
propagating the error if `v` is a constant that is less than `min_vecs`..
Best,
Gary
>
> (Further consideration on a subsequent patch.)
>
>>> @@ -256,7 +249,21 @@ pub fn alloc_irq_vectors(
>>> min_vecs: u32,
>>> max_vecs: u32,
>>> irq_types: IrqTypes,
>>> - ) -> Result<RangeInclusive<IrqVector<'_>>> {
>>> - IrqVectorRegistration::register(self, min_vecs, max_vecs, irq_types)
>>> + ) -> Result<IrqVectorRegistration<'_>> {
>>> + // SAFETY:
>>> + // - `self.as_raw()` is guaranteed to be a valid pointer to a `struct pci_dev`
>>> + // by the type invariant of `Device`.
>>> + // - `pci_alloc_irq_vectors` internally validates all other parameters
>>> + // and returns error codes.
>>> + let ret = unsafe {
>>> + bindings::pci_alloc_irq_vectors(self.as_raw(), min_vecs, max_vecs, irq_types.as_raw())
>>> + };
>>> +
>>> + to_result(ret)?;
>>> +
>>> + let count = NonZero::new(ret as usize).ok_or(EINVAL)?;
>>
>> I don't think `ret` can ever be zero. `expect` or `new_unchecked()` perhaps?
>
> Correct, but I don't see a reason to BUG_ON() for this. A WARN_ON() makes sense,
> but I see this to be the job of the C API making the promise.
>
> We could use new_unchecked(), but since this method is fallible already and not
> a hot path, I don't think it's worth.
next prev parent reply other threads:[~2026-08-12 18:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 23:39 [PATCH v2 0/5] Rework PCI IRQ vector code Danilo Krummrich
2026-08-11 23:39 ` [PATCH v2 1/5] rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type Danilo Krummrich
2026-08-12 16:26 ` Gary Guo
2026-08-12 17:37 ` Danilo Krummrich
2026-08-12 18:11 ` Gary Guo [this message]
2026-08-12 18:47 ` Danilo Krummrich
2026-08-12 19:01 ` Gary Guo
2026-08-12 19:57 ` Danilo Krummrich
2026-08-11 23:39 ` [PATCH v2 2/5] rust: pci: resolve IRQ in vector() and embed IrqRequest in IrqVector Danilo Krummrich
2026-08-12 16:38 ` Gary Guo
2026-08-12 17:44 ` Danilo Krummrich
2026-08-12 18:09 ` Gary Guo
2026-08-12 19:31 ` Danilo Krummrich
2026-08-11 23:39 ` [PATCH v2 3/5] rust: pci: remove request_irq() and request_threaded_irq() from Device Danilo Krummrich
2026-08-11 23:39 ` [PATCH v2 4/5] PCI: Add pci_irq_type() to query the allocated interrupt type Danilo Krummrich
2026-08-11 23:39 ` [PATCH v2 5/5] rust: pci: expose " Danilo Krummrich
2026-08-12 16:44 ` Gary Guo
2026-08-12 17:57 ` Danilo Krummrich
2026-08-12 18:16 ` Gary Guo
2026-08-12 20:48 ` Danilo Krummrich
2026-08-13 1:20 ` [PATCH v2 0/5] Rework PCI IRQ vector code John Hubbard
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=DKN6203R3WD1.1NLN19VVBZJO9@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=jhubbard@nvidia.com \
--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=rust-for-linux@vger.kernel.org \
--cc=shashanks@nvidia.com \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=work@onurozkan.dev \
--cc=zhiw@nvidia.com \
/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