Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707647pxb; Mon, 24 Jan 2022 15:58:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/+L/NhbsMZMCjxu8De3R84MYhtYB3J/MM03S1r99MsXXhq4c+HqoVaYqKUZEqquIA6WmE X-Received: by 2002:a17:903:245:b0:149:d2a3:ddbf with SMTP id j5-20020a170903024500b00149d2a3ddbfmr16462434plh.3.1643068693201; Mon, 24 Jan 2022 15:58:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068693; cv=none; d=google.com; s=arc-20160816; b=bJjcKhW2RsvmjqwKjIXqTOjSqzc3LaQYCJLDC0B66L/VIH5MvNfNjbpvGTPlsnnN7Z h4zOxNAPqfxQyoSBQaLef4d7xjECPE3c4mTaJrLBj7k75U5ppPZo5Rp7+PaVaLaEcbKR lqudYNhw84zJBFhgMeaACBZk2A+0Yh99zwRJxWMgpk5Z4UOJ2+sEwGMJuFObgbV1NhR6 sH6n9ba5Ex+jUeJh5yNHFlXIEF7zw4fYa8fDasVJgGzE3rPXML29NyvFAAkLYNRHm1NO M/QK3vbNLAtHkDrusKI8DT2+D9JDic1ozvGRpKHp9u2gmTattyR8pg+5WWXVxvt6VI82 LH9Q== 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=uGv6suZ6HiXXGBrq8bohrPYxEOX244hkDtK5CDwHARo=; b=UfvxKFCspd0DbraOPeN2mB8Tlaoj5MRHJa2ldsoYGiP9RncDKfwilBv+x2ESdWwE8v WSVBSRLGLs/MUyRhMr0AJO8ks1U0CktoSy35CO9bMKfHl0i5bzD8xY5vsxuP3aNysBBk e/Vu7aJ15a+ref4jqVX7ucc/uV8Jl2E2GkN1R6ZbAF4eaUvzCFd/+jYE0QCRRAaZlqq4 vJQ5k4rnZjBx6uBnWEHf9/vVit40eOluHC5XyFTyqikBXr3yNRYjqd8PHrl6bkyWp7Fu mNxniKSjFUwq/i1odo0cHePj+5KBHU+vLedbyC6Kkia9AQ0oDg+2CaPSMyRQYNEW/itY Ff1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nop0maVa; 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 w24si15284618pgj.52.2022.01.24.15.58.01; Mon, 24 Jan 2022 15:58:13 -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=Nop0maVa; 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 S2365930AbiAXXwA (ORCPT + 99 others); Mon, 24 Jan 2022 18:52:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1845261AbiAXXLz (ORCPT ); Mon, 24 Jan 2022 18:11:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 636FCC0A02B2; Mon, 24 Jan 2022 13:18:54 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 2C5BDB8123A; Mon, 24 Jan 2022 21:18:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DA99C340E4; Mon, 24 Jan 2022 21:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059131; bh=5bUKsrqF9mbHtV4XlYG05/ugAg6Jo+Sb90uYqTfChFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nop0maVa6lVucsRkAhc4uy2PU9je0gp9SaGJ3jPPcUZ41rZWiFUeScC18O+RUsKLq H2HNZOCSgOtuSoc2U8VMCVb5OygtO88SbrIHq79CQUb2u5+lawc0SdbJMtpdPorfWg HZGq0gR8Ep+ChLIsUIi+aG8l7sLSZauY280bnnHM= 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.16 0481/1039] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Date: Mon, 24 Jan 2022 19:37:50 +0100 Message-Id: <20220124184141.435262990@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 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; -- 2.34.1