[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211207205337.GA76377@bhelgaas>
Date: Tue, 7 Dec 2021 14:53:37 -0600
From: Bjorn Helgaas <helgaas@...nel.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>, Marc Zygnier <maz@...nel.org>,
Alex Williamson <alex.williamson@...hat.com>,
Kevin Tian <kevin.tian@...el.com>,
Jason Gunthorpe <jgg@...dia.com>,
Megha Dey <megha.dey@...el.com>,
Ashok Raj <ashok.raj@...el.com>, linux-pci@...r.kernel.org,
Cedric Le Goater <clg@...d.org>,
Juergen Gross <jgross@...e.com>,
Michael Ellerman <mpe@...erman.id.au>,
Paul Mackerras <paulus@...ba.org>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
linuxppc-dev@...ts.ozlabs.org,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
linux-mips@...r.kernel.org, Kalle Valo <kvalo@...eaurora.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
sparclinux@...r.kernel.org, x86@...nel.org,
xen-devel@...ts.xenproject.org, ath11k@...ts.infradead.org,
Wei Liu <wei.liu@...nel.org>, linux-hyperv@...r.kernel.org,
Christian Borntraeger <borntraeger@...ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>
Subject: Re: [patch V2 02/23] PCI/MSI: Fix
pci_irq_vector()/pci_irq_get_affinity()
On Mon, Dec 06, 2021 at 11:27:26PM +0100, Thomas Gleixner wrote:
> 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@...utronix.de>
> Tested-by: Juergen Gross <jgross@...e.com>
> Reviewed-by: Jason Gunthorpe <jgg@...dia.com>
Acked-by: Bjorn Helgaas <bhelgaas@...gle.com>
> ---
> V2: Fix typo in subject - Jason
> ---
> drivers/pci/msi.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -1187,19 +1187,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;
> @@ -1223,17 +1228,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;
>
Powered by blists - more mailing lists