Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3603392pxb; Mon, 24 Jan 2022 13:17:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3y/4Sh3C+5729RY/t2K5LzAxwf1qyA2tOz0EcWtgbOYpvl6EBUjwxtNu3CfIJMqRizZU2 X-Received: by 2002:a63:c6:: with SMTP id 189mr12825227pga.85.1643059055655; Mon, 24 Jan 2022 13:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059055; cv=none; d=google.com; s=arc-20160816; b=Fnbh8RNZBhNFDNOiZLzUStuzM5AzH22z6ob1SS6Bqfx4wWU+WwKw8rbM/bvAI7nyz3 470bAEK/TmHql89e1xaOSw8P98lZIpuv43O6uWZzK/D+FgOahn+7DXD0rDZXNVRbC2Ea 0HqC22tSbdwpUWvOprfO8ueSpnjJHnvRh1Yqbl5xlcHHr6M/0dMInbjNkTW9TyWhX/jG rp0BWR9fUlhe1JFf2Z8fF+4lo9zlZluusbHLc0vGcJW5mAZjrnE9h5LohC2KpJreluqd isf/QbdlCgmYwaFspy2Iw8DFY35wZCeftZSmlrgahkDvmzPyLVLLtKsIehzKBmfVk2jk QZog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UIC7JOq0E29NVsnd7Byoyvu2OkeKy7ZT0ouba4HbP6A=; b=mJ4HoBdA9WV3+99wPzFJQZbZfQCYekp/An/zmkiOkwJyza3ThCtgKDQ4OTSiuy5cJY Z/QjyPA7NYNa445Ytzx7GGs14b5KoIk+L21Xi6w9/NvjRiWvEqVs4GYeVfOVaFihJQwJ fihKlvmrCZLjQICZyyi4yu1A7eXup1qdVS8RdicLimv9Wk4z6+Y+JB1xrzHT23ecPY0M V8Yye97DFyhNvNAz8Hes/3ZEwJRjkWb3rARIGKfko4NskuZhAPBBubZr8dVD1+zIvt1T HxMWgfmrF8NwRno/UGF4UB38r5QoN+k3WjUwafcHyy4jxpIhwYDmA5YPhBXC4hkHXlJv 3ylQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rQi48VY/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si3673104pgb.12.2022.01.24.13.17.20; Mon, 24 Jan 2022 13:17:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rQi48VY/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384307AbiAXUwr (ORCPT + 99 others); Mon, 24 Jan 2022 15:52:47 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:51730 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384574AbiAXUaH (ORCPT ); Mon, 24 Jan 2022 15:30:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6F1D6152D; Mon, 24 Jan 2022 20:30:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CB77C340E5; Mon, 24 Jan 2022 20:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056206; bh=mrzrnxbmD+5U4WQgviGOnIsr+fY8KnoUK66V9RP2bRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rQi48VY/Qhi30Tr0cQFinZZJ3csMaEeuytMRvQzayWoWcO/b45cwoYnVqUxosuInN 0IEIHm69Y5kJg4qQTdpltAjLmiMEQDH1cbJB3OuHNJ51CRpSdiZZ3NVzDiKtp4i4TH XCd4ilWe7LhH4d0U8dJg35onavsTlb8U5mfECtPQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Juergen Gross , Jason Gunthorpe , Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.15 407/846] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Date: Mon, 24 Jan 2022 19:38:44 +0100 Message-Id: <20220124184114.998619758@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner [ 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 Tested-by: Juergen Gross Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas Link: https://lore.kernel.org/r/20211206210223.929792157@linutronix.de Signed-off-by: Sasha Levin --- 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 e11530cb05699..cc4c2b8a5efd7 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -1193,19 +1193,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; @@ -1229,17 +1234,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; -- 2.34.1