Merge branch 'pci/msi'

- Update documentation of pci_free_irq_vectors() and pcim_enable_device()
  (Shawn Lin)

* pci/msi:
  PCI/MSI: Add TODO comment about legacy pcim_enable_device() side-effect
  PCI/MSI: Clarify pci_free_irq_vectors() usage for managed devices
This commit is contained in:
Bjorn Helgaas 2026-04-13 12:50:03 -05:00
commit 3ebccb123d
3 changed files with 20 additions and 2 deletions

View File

@ -113,8 +113,11 @@ vectors, use the following function::
int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
Any allocated resources should be freed before removing the device using
the following function::
If the driver enables the device using pcim_enable_device(), the driver
shouldn't call pci_free_irq_vectors() because pcim_enable_device()
activates automatic management for IRQ vectors. Otherwise, the driver should
free any allocated IRQ vectors before removing the device using the following
function::
void pci_free_irq_vectors(struct pci_dev *dev);

View File

@ -370,6 +370,11 @@ EXPORT_SYMBOL(pci_irq_get_affinity);
* Undo the interrupt vector allocations and possible device MSI/MSI-X
* enablement earlier done through pci_alloc_irq_vectors_affinity() or
* pci_alloc_irq_vectors().
*
* WARNING: Do not call this function if the device has been enabled
* with pcim_enable_device(). In that case, IRQ vectors are automatically
* managed via pcim_msi_release() and calling pci_free_irq_vectors() can
* lead to double-free issues.
*/
void pci_free_irq_vectors(struct pci_dev *dev)
{

View File

@ -77,6 +77,16 @@ static void pcim_msi_release(void *pcidev)
/*
* Needs to be separate from pcim_release to prevent an ordering problem
* vs. msi_device_data_release() in the MSI core code.
*
* TODO: Remove the legacy side-effect of pcim_enable_device() that
* activates automatic IRQ vector management. This design is dangerous
* and confusing because it switches normally un-managed functions
* into managed mode. Drivers should explicitly manage their IRQ vectors
* without this implicit behavior.
*
* The current implementation uses both pdev->is_managed and
* pdev->is_msi_managed flags, which adds unnecessary complexity.
* This should be simplified in a future kernel version.
*/
static int pcim_setup_msi_release(struct pci_dev *dev)
{