Re: [PATCH v2 5/5] rust: pci: expose the allocated interrupt type

From: Gary Guo

Date: Wed Aug 12 2026 - 12:51:36 EST


On Wed Aug 12, 2026 at 12:39 AM BST, Danilo Krummrich wrote:
> Add irq_type() on IrqVectorRegistration and IrqVector, wrapping the new
> pci_irq_type() C function. A driver whose interrupt acknowledgment
> depends on the type (MSI-X vs MSI vs INTx) queries it here rather than
> assuming which type the PCI core selected.
>
> Suggested-by: John Hubbard <jhubbard@xxxxxxxxxx>
> Link: https://lore.kernel.org/all/20260808031120.363869-4-jhubbard@xxxxxxxxxx/
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> rust/helpers/pci.c | 5 +++++
> rust/kernel/pci/irq.rs | 22 ++++++++++++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/rust/helpers/pci.c b/rust/helpers/pci.c
> index e44905317d75..23b06becb448 100644
> --- a/rust/helpers/pci.c
> +++ b/rust/helpers/pci.c
> @@ -24,6 +24,11 @@ __rust_helper bool rust_helper_dev_is_pci(const struct device *dev)
> return dev_is_pci(dev);
> }
>
> +__rust_helper unsigned int rust_helper_pci_irq_type(struct pci_dev *pdev)
> +{
> + return pci_irq_type(pdev);
> +}
> +
> #ifndef CONFIG_PCI_MSI
> __rust_helper int rust_helper_pci_alloc_irq_vectors(struct pci_dev *dev,
> unsigned int min_vecs,
> diff --git a/rust/kernel/pci/irq.rs b/rust/kernel/pci/irq.rs
> index b3dce5b49d57..41059b922492 100644
> --- a/rust/kernel/pci/irq.rs
> +++ b/rust/kernel/pci/irq.rs
> @@ -33,6 +33,16 @@ const fn as_raw(self) -> u32 {
> IrqType::MsiX => bindings::PCI_IRQ_MSIX,
> }
> }
> +
> + /// Construct from raw value.
> + #[inline]
> + const fn from_raw(raw: u32) -> Self {
> + match raw {
> + bindings::PCI_IRQ_MSIX => IrqType::MsiX,
> + bindings::PCI_IRQ_MSI => IrqType::Msi,
> + _ => IrqType::Intx,
> + }
> + }
> }
>
> /// Set of IRQ types that can be used for PCI interrupt allocation.
> @@ -106,6 +116,11 @@ pub fn index(&self) -> usize {
> pub fn vectors(&self) -> &'a IrqVectorRegistration<'a> {
> self.reg
> }
> +
> + /// Returns the interrupt type the PCI core selected for this vector's allocation.

#[inline]

> + pub fn irq_type(&self) -> IrqType {
> + self.reg.irq_type()

Do you expect people to call this on the `IrqVetor` (or even
`IrqVectorRegistration`)? This is really a property of the device, and not on a
specific IRQ vector/allocation.

Asking this because I think we can avoid keeping reference to `reg` if we don't
need this and `vectors` (just keep `&'a Device<Bound>`; the mere signature of
`IrqVectorRegistration::vector` will ensure the correct lifetime)

Best,
Gary

> + }
> }
>
> impl<'a> From<IrqVector<'a>> for IrqRequest<'a> {
> @@ -137,6 +152,13 @@ pub fn vector_count(&self) -> usize {
> self.count.get()
> }
>
> + /// Returns the interrupt type the PCI core selected for this allocation.
> + #[inline]
> + pub fn irq_type(&self) -> IrqType {
> + // SAFETY: `self.dev.as_raw()` is a valid pointer to a `struct pci_dev`.
> + IrqType::from_raw(unsafe { bindings::pci_irq_type(self.dev.as_raw()) })
> + }
> +
> /// Returns the [`IrqVector`] at `index`.
> ///
> /// The returned [`IrqVector`] borrows from this registration, ensuring the vector allocation