linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Marc Zygnier <maz@kernel.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Jason Gunthorpe <jgg@nvidia.com>, Megha Dey <megha.dey@intel.com>,
	Ashok Raj <ashok.raj@intel.com>,
	linux-pci@vger.kernel.org, Cedric Le Goater <clg@kaod.org>,
	Juergen Gross <jgross@suse.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Paul Mackerras <paulus@samba.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	linuxppc-dev@lists.ozlabs.org,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	linux-mips@vger.kernel.org, Kalle Valo <kvalo@codeaurora.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	sparclinux@vger.kernel.org, x86@kernel.org,
	xen-devel@lists.xenproject.org, ath11k@lists.infradead.org,
	Wei Liu <wei.liu@kernel.org>,
	linux-hyperv@vger.kernel.org,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>
Subject: Re: [patch V2 02/23] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
Date: Tue, 7 Dec 2021 14:53:37 -0600	[thread overview]
Message-ID: <20211207205337.GA76377@bhelgaas> (raw)
In-Reply-To: <20211206210223.929792157@linutronix.de>

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@linutronix.de>
> Tested-by: Juergen Gross <jgross@suse.com>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.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;
> 

  reply	other threads:[~2021-12-07 20:53 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 22:27 [patch V2 00/23] genirq/msi, PCI/MSI: Spring cleaning - Part 1 Thomas Gleixner
2021-12-06 22:27 ` [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked Thomas Gleixner
2021-12-07  7:21   ` Cédric Le Goater
2021-12-07 11:36     ` Michael Ellerman
2021-12-07 15:50       ` Cédric Le Goater
2021-12-07 20:42         ` Thomas Gleixner
2021-12-08 10:44           ` Cédric Le Goater
2021-12-06 22:27 ` [patch V2 02/23] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Thomas Gleixner
2021-12-07 20:53   ` Bjorn Helgaas [this message]
2021-12-06 22:27 ` [patch V2 03/23] genirq/msi: Guard sysfs code Thomas Gleixner
2021-12-07  7:42   ` Greg Kroah-Hartman
2021-12-06 22:27 ` [patch V2 04/23] genirq/msi: Remove unused domain callbacks Thomas Gleixner
2021-12-06 22:27 ` [patch V2 05/23] genirq/msi: Fixup includes Thomas Gleixner
2021-12-07  7:43   ` Greg Kroah-Hartman
2021-12-06 22:27 ` [patch V2 06/23] PCI/MSI: Make pci_msi_domain_write_msg() static Thomas Gleixner
2021-12-07 20:54   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 07/23] PCI/MSI: Remove msi_desc_to_pci_sysdata() Thomas Gleixner
2021-12-07 20:55   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 08/23] PCI/sysfs: Use pci_irq_vector() Thomas Gleixner
2021-12-07  7:43   ` Greg Kroah-Hartman
2021-12-07 20:56   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 09/23] MIPS: Octeon: Use arch_setup_msi_irq() Thomas Gleixner
2021-12-06 22:27 ` [patch V2 10/23] genirq/msi, treewide: Use a named struct for PCI/MSI attributes Thomas Gleixner
2021-12-07  7:44   ` Greg Kroah-Hartman
2021-12-06 22:27 ` [patch V2 11/23] x86/hyperv: Refactor hv_msi_domain_free_irqs() Thomas Gleixner
2021-12-06 22:27 ` [patch V2 12/23] PCI/MSI: Make arch_restore_msi_irqs() less horrible Thomas Gleixner
2021-12-07 20:56   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 13/23] PCI/MSI: Cleanup include zoo Thomas Gleixner
2021-12-07 20:57   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 14/23] PCI/MSI: Make msix_update_entries() smarter Thomas Gleixner
2021-12-07  7:44   ` Greg Kroah-Hartman
2021-12-07 20:57   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 15/23] PCI/MSI: Move code into a separate directory Thomas Gleixner
2021-12-07 20:57   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 16/23] PCI/MSI: Split out CONFIG_PCI_MSI independent part Thomas Gleixner
2021-12-07  7:45   ` Greg Kroah-Hartman
2021-12-07 20:58   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 17/23] PCI/MSI: Split out !IRQDOMAIN code Thomas Gleixner
2021-12-07  7:45   ` Greg Kroah-Hartman
2021-12-07 20:59   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 18/23] PCI/MSI: Split out irqdomain code Thomas Gleixner
2021-12-07  7:46   ` Greg Kroah-Hartman
2021-12-07 21:00   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 19/23] PCI/MSI: Sanitize MSIX table map handling Thomas Gleixner
2021-12-07 21:01   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 20/23] PCI/MSI: Move msi_lock to struct pci_dev Thomas Gleixner
2021-12-07  7:47   ` Greg Kroah-Hartman
2021-12-07 21:01   ` Bjorn Helgaas
2021-12-08 15:29   ` Jason Gunthorpe
2021-12-08 20:56     ` Thomas Gleixner
2021-12-06 22:27 ` [patch V2 21/23] PCI/MSI: Make pci_msi_domain_check_cap() static Thomas Gleixner
2021-12-07  7:47   ` Greg Kroah-Hartman
2021-12-07 21:01   ` Bjorn Helgaas
2021-12-06 22:27 ` [patch V2 22/23] genirq/msi: Handle PCI/MSI allocation fail in core code Thomas Gleixner
2021-12-07  7:48   ` Greg Kroah-Hartman
2021-12-07 21:02   ` Bjorn Helgaas
2021-12-06 22:28 ` [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code Thomas Gleixner
2021-12-07  7:48   ` Greg Kroah-Hartman
2021-12-07 21:02   ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211207205337.GA76377@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=ath11k@lists.infradead.org \
    --cc=benh@kernel.crashing.org \
    --cc=borntraeger@de.ibm.com \
    --cc=clg@kaod.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hca@linux.ibm.com \
    --cc=jgg@nvidia.com \
    --cc=jgross@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maz@kernel.org \
    --cc=megha.dey@intel.com \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).