public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add Devres managed IRQ vectors allocation
@ 2026-04-17  2:26 Shawn Lin
  2026-04-17  2:26 ` [PATCH v2 1/3] PCI/MSI: " Shawn Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Shawn Lin @ 2026-04-17  2:26 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Nirmal Patel, Jonathan Derrick, Kurt Schwemmer, Logan Gunthorpe,
	Philipp Stanner, linux-pci, Shawn Lin

There is a long-standing design issue in the PCI/MSI subsystem where the
implicit, automatic management of IRQ vectors by the devres framework
conflicts with explicit driver cleanup, creating ambiguity and potential
resource management bugs.

Historically, `pcim_enable_device()` not only manages standard PCI resources
(BARs) via devres but also implicitly triggers automatic IRQ vector management
by setting a flag that registers `pcim_msi_release()` as a cleanup action.

This creates an ambiguous ownership model. Many drivers follow a pattern of:
1. Calling `pci_alloc_irq_vectors()` to allocate interrupts.
2. Also calling `pci_free_irq_vectors()` in their error paths or remove routines.

When such a driver also uses `pcim_enable_device()`, the devres framework may
attempt to free the IRQ vectors a second time upon device release, leading to
a double-free. Analysis of the tree shows this hazardous pattern exists widely,
while 35 other drivers correctly rely solely on the implicit cleanup.

This series introduces new managed APIs: pcim_alloc_irq_vectors()and
pcim_alloc_irq_vectors_affinity(). Drivers that wish to have devres-managed IRQ
vectors should use these functions. They appropriately set the is_msi_managed
flag and ensure proper automatic cleanup.

In the short term, the series converts two drivers within the PCI subsystem to
use the new APIs. The long-term goal is to convert all other drivers to use these
managed functions, and finally to remove the problematic hybrid management pattern
from pcim_enable_device() entirely.


Changes in v2:
- Rebase
- Introduce patches only for PCI subsystem to convert the API

Shawn Lin (3):
  PCI/MSI: Add Devres managed IRQ vectors allocation
  PCI: switchtec: Replace pci_alloc_irq_vectors() with
    pcim_alloc_irq_vectors()
  PCI: vmd: Replace pci_alloc_irq_vectors() with
    pcim_alloc_irq_vectors()

 drivers/pci/controller/vmd.c   |  4 ++--
 drivers/pci/msi/api.c          | 26 ++++++++++++++++++++++++++
 drivers/pci/switch/switchtec.c |  6 +++---
 include/linux/pci.h            | 22 ++++++++++++++++++++++
 4 files changed, 53 insertions(+), 5 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-04-20 10:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17  2:26 [PATCH v2 0/3] Add Devres managed IRQ vectors allocation Shawn Lin
2026-04-17  2:26 ` [PATCH v2 1/3] PCI/MSI: " Shawn Lin
2026-04-17  6:10   ` Frank Li
2026-04-17  6:32     ` Shawn Lin
2026-04-17  8:44   ` Philipp Stanner
2026-04-17  9:33     ` Shawn Lin
2026-04-20  9:28       ` Philipp Stanner
2026-04-20  9:52         ` Shawn Lin
2026-04-17  2:26 ` [PATCH v2 2/3] PCI: switchtec: Replace pci_alloc_irq_vectors() with pcim_alloc_irq_vectors() Shawn Lin
2026-04-17 15:16   ` Logan Gunthorpe
2026-04-17  2:26 ` [PATCH v2 3/3] PCI: vmd: " Shawn Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox