Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71DAFC433FE for ; Thu, 9 Dec 2021 16:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241199AbhLIQLa (ORCPT ); Thu, 9 Dec 2021 11:11:30 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:40094 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240954AbhLIQKs (ORCPT ); Thu, 9 Dec 2021 11:10:48 -0500 Date: Thu, 09 Dec 2021 16:07:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1639066033; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=peLjpNoKAwd94/C3ClAuFT0nbJQVorzfikMopJTcTnE=; b=nqVd5svR3F5L8Yty47ATQma6cBSLFxjIN0hWqRInBGF9dl0H2/cWEnwkjkLhSkQasRFBO9 GtAjeYbnNgijkstKqB77gPuRf7hCF8rU5kA8EhxumVLiftOt41PJEfmORVG78VT9lamhAI YafJNpJU/7DeEAHtCRhhi8R9wr6YIQUJoaFB8Q1Y8ROdDMusuzf5oxhykjlHLaJ7+tQJya xLQIWdRqbcaf4C5ze34ZeSr4w+C9GrdyCxY/e/Rqfrg5J4G3hMzi/yB2l5ZpyP9xe7gN6c XVb/4I5y7YpkB8JvO9v8ur2P4CmQkQlkFBjyHbFOrfs9KQoQxFvISVax33HU6A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1639066033; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=peLjpNoKAwd94/C3ClAuFT0nbJQVorzfikMopJTcTnE=; b=zlK7ZkVPIAYaX5bnlTNsRbVLkufb4yPO9kOA3JYU/bKF0+QJiPRnAoRXExDpZeXb+wyYGu Ep4Tp5Ca4pjybXDA== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/msi] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Cc: Thomas Gleixner , Juergen Gross , Jason Gunthorpe , Bjorn Helgaas , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20211206210223.929792157@linutronix.de> References: <20211206210223.929792157@linutronix.de> MIME-Version: 1.0 Message-ID: <163906603293.11128.11068406777835111377.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/msi branch of tip: Commit-ID: 29bbc35e29d9b6347780dcacde2deb4b39344167 Gitweb: https://git.kernel.org/tip/29bbc35e29d9b6347780dcacde2deb4b39344167 Author: Thomas Gleixner AuthorDate: Mon, 06 Dec 2021 23:27:26 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00 PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() 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 Tested-by: Juergen Gross Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas Link: https://lore.kernel.org/r/20211206210223.929792157@linutronix.de --- drivers/pci/msi.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 48e3f4e..00ed45f 100644 --- 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;