summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2026-04-13 12:50:03 -0500
committerBjorn Helgaas <bhelgaas@google.com>2026-04-13 12:50:03 -0500
commit3ebccb123dfa8b475ee77b9c49bc775152e70205 (patch)
treed3e178f6879d57ad2d65306cb6b84aa81a0d8382
parentc9aad5598046f884d5164b5e5000fd0b32a90dd7 (diff)
parent874b07eb0875729b9a47441e03b125d9fa735645 (diff)
downloadlwn-3ebccb123dfa8b475ee77b9c49bc775152e70205.tar.gz
lwn-3ebccb123dfa8b475ee77b9c49bc775152e70205.zip
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
-rw-r--r--Documentation/PCI/msi-howto.rst7
-rw-r--r--drivers/pci/msi/api.c5
-rw-r--r--drivers/pci/msi/msi.c10
3 files changed, 20 insertions, 2 deletions
diff --git a/Documentation/PCI/msi-howto.rst b/Documentation/PCI/msi-howto.rst
index 667ebe2156b4..844c1d3c395d 100644
--- a/Documentation/PCI/msi-howto.rst
+++ b/Documentation/PCI/msi-howto.rst
@@ -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);
diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c
index 818d55fbad0d..c18559b6272c 100644
--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -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)
{
diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index e2412175d7af..81d24a270a79 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -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)
{