From: sashiko-bot@kernel.org
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: linux-pci@vger.kernel.org, ojeda@kernel.org
Subject: Re: [PATCH v2 1/5] rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type
Date: Tue, 11 Aug 2026 23:52:53 +0000 [thread overview]
Message-ID: <20260811235254.36BF61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260811233952.3000968-2-dakr@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The lifetime bounds introduced on `IrqVectorRegistration` and `IrqVector` force an impossible self-referential struct, rendering the API unusable in safe Rust.
Pre-existing issues:
- [High] Concurrent calls to `alloc_irq_vectors` allow unsynchronized mutation of PCI device state, leading to data races and kernel memory corruption.
--
--- Patch [1]: [PATCH v2 1/5] rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type ---
commit c70c8b630ade05d17f2339a929d25258bdd64514
Author: Danilo Krummrich <dakr@kernel.org>
rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type
This commit converts IrqVectorRegistration to a lifetime-annotated type that
owns the PCI interrupt vector allocation. Dropping it frees the vectors, and
alloc_irq_vectors() is updated to return IrqVectorRegistration directly.
> diff --git a/rust/kernel/pci/irq.rs b/rust/kernel/pci/irq.rs
> index fea484dcf9cf2..8e06515878290 100644
> --- a/rust/kernel/pci/irq.rs
> +++ b/rust/kernel/pci/irq.rs
> @@ -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>,
> index: u32,
> }
[Severity: High]
Will this lifetime bound prevent drivers from storing their PCI interrupts in a
device data structure?
If a driver calls alloc_irq_vectors() to get an IrqVectorRegistration, borrows
it via vector() to create an irq::Registration, and then tries to store both in
its driver data struct, the compiler will reject it. Safe Rust does not allow
the registration and the IRQ handler to be stored in the same struct due to
these self-referential lifetime constraints.
This seems to force drivers to either leak memory or drop the registration
prematurely, which would instantly free the interrupts via
pci_free_irq_vectors().
[ ... ]
> @@ -256,7 +249,21 @@ pub fn alloc_irq_vectors(
> &self,
> min_vecs: u32,
> max_vecs: u32,
> irq_types: IrqTypes,
> - ) -> Result<RangeInclusive<IrqVector<'_>>> {
> - IrqVectorRegistration::register(self, min_vecs, max_vecs, irq_types)
> + ) -> Result<IrqVectorRegistration<'_>> {
[Severity: High]
This is a pre-existing issue, but is it safe for alloc_irq_vectors to take an
immutable reference when it mutates PCI device state?
Because alloc_irq_vectors takes &self (which is Sync), a driver could expose
concurrent sysfs or ioctl endpoints that trigger reallocation on the same
Device.
The underlying C function pci_alloc_irq_vectors checks and modifies
dev->msix_enabled without locking. This can cause a data race, leading to
double-allocation of MSI-X descriptors, leaking of ioremap mappings, and
corruption of internal PCI device state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260811233952.3000968-1-dakr@kernel.org?part=1
next prev parent reply other threads:[~2026-08-11 23:52 UTC|newest]
Thread overview: 19+ 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-11 23:52 ` sashiko-bot [this message]
2026-08-12 16:26 ` Gary Guo
2026-08-12 17:37 ` Danilo Krummrich
2026-08-12 18:11 ` Gary Guo
2026-08-11 23:39 ` [PATCH v2 2/5] rust: pci: resolve IRQ in vector() and embed IrqRequest in IrqVector Danilo Krummrich
2026-08-11 23:48 ` sashiko-bot
2026-08-12 16:38 ` Gary Guo
2026-08-12 17:44 ` Danilo Krummrich
2026-08-12 18:09 ` Gary Guo
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:47 ` sashiko-bot
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:44 ` sashiko-bot
2026-08-11 23:39 ` [PATCH v2 5/5] rust: pci: expose " Danilo Krummrich
2026-08-11 23:46 ` sashiko-bot
2026-08-12 16:44 ` Gary Guo
2026-08-12 17:57 ` Danilo Krummrich
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=20260811235254.36BF61F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dakr@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.