Patch "PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()" has been added to the 5.16-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()

to the 5.16-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     pci-msi-fix-pci_irq_vector-pci_irq_get_affinity.patch
and it can be found in the queue-5.16 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 191eef20b774a6d29fd9fd79e296c148842dff54
Author: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Date:   Mon Dec 6 23:27:26 2021 +0100

    PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
    
    [ Upstream commit 29bbc35e29d9b6347780dcacde2deb4b39344167 ]
    
    pci_irq_vector() and pci_irq_get_affinity() use the list position to find the
    MSI-X descriptor at a given index. That's correct for the normal case where
    the entry number is the same as the list position.
    
    But it's wrong for cases where MSI-X was allocated with an entries array
    describing sparse entry numbers into the hardware message descriptor
    table. That's inconsistent at best.
    
    Make it always check the entry number because that's what the zero base
    index really means. This change won't break existing users which use a
    sparse entries array for allocation because these users retrieve the Linux
    interrupt number from the entries array after allocation and none of them
    uses pci_irq_vector() or pci_irq_get_affinity().
    
    Fixes: aff171641d18 ("PCI: Provide sensible IRQ vector alloc/free routines")
    Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
    Tested-by: Juergen Gross <jgross@xxxxxxxx>
    Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
    Acked-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20211206210223.929792157@xxxxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index d84cf30bb2790..8465221be6d21 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -1194,19 +1194,24 @@ EXPORT_SYMBOL(pci_free_irq_vectors);
 
 /**
  * pci_irq_vector - return Linux IRQ number of a device vector
- * @dev: PCI device to operate on
- * @nr: device-relative interrupt vector index (0-based).
+ * @dev:	PCI device to operate on
+ * @nr:		Interrupt vector index (0-based)
+ *
+ * @nr has the following meanings depending on the interrupt mode:
+ *   MSI-X:	The index in the MSI-X vector table
+ *   MSI:	The index of the enabled MSI vectors
+ *   INTx:	Must be 0
+ *
+ * Return: The Linux interrupt number or -EINVAl if @nr is out of range.
  */
 int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
 {
 	if (dev->msix_enabled) {
 		struct msi_desc *entry;
-		int i = 0;
 
 		for_each_pci_msi_entry(entry, dev) {
-			if (i == nr)
+			if (entry->msi_attrib.entry_nr == nr)
 				return entry->irq;
-			i++;
 		}
 		WARN_ON_ONCE(1);
 		return -EINVAL;
@@ -1230,17 +1235,22 @@ EXPORT_SYMBOL(pci_irq_vector);
  * pci_irq_get_affinity - return the affinity of a particular MSI vector
  * @dev:	PCI device to operate on
  * @nr:		device-relative interrupt vector index (0-based).
+ *
+ * @nr has the following meanings depending on the interrupt mode:
+ *   MSI-X:	The index in the MSI-X vector table
+ *   MSI:	The index of the enabled MSI vectors
+ *   INTx:	Must be 0
+ *
+ * Return: A cpumask pointer or NULL if @nr is out of range
  */
 const struct cpumask *pci_irq_get_affinity(struct pci_dev *dev, int nr)
 {
 	if (dev->msix_enabled) {
 		struct msi_desc *entry;
-		int i = 0;
 
 		for_each_pci_msi_entry(entry, dev) {
-			if (i == nr)
+			if (entry->msi_attrib.entry_nr == nr)
 				return &entry->affinity->mask;
-			i++;
 		}
 		WARN_ON_ONCE(1);
 		return NULL;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux