Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3610675pxb; Mon, 24 Jan 2022 13:29:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxygMtlSa1gUOzVBl4lfADvnGItG9qDsMLsudixrbMLW/LLmE9Apm1CS0O6WQx5zPPDYO5B X-Received: by 2002:a17:90b:1bd1:: with SMTP id oa17mr222584pjb.160.1643059754019; Mon, 24 Jan 2022 13:29:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059754; cv=none; d=google.com; s=arc-20160816; b=NTkGXPwi+FMxiedg/uD5ulU+0QXDRjBOVfesSicOyapL5DhtdGYEGHHReUsJ6W9sy8 qb2zKfIaYhfIU5dJaERBigkLimk8989PcOCfKZ5GMsA0gBG6YmNzA+JA2GA5pR+bDSHP 1/6yz1ygp/QqT2FY8ntalTVsadcY6P4Jx/cQGQGHqIXOMWc0DaKR6KJBorohBEdwweiV kYcAn65KAqqOzn7EiyQ9HjdvH9NEYP9igORs7D0pq54gLL/930NcHyTM6mlTKLVMumBk J5UUpOGnFVIqvrFRJIIiBaSLWSwJb/9tP2LBCnjczjnFt55o61g4S5e+TNU1e4SjWn2b 6OHA== 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=7QtyCxVo99RpX+HwVcRftSsTnAHgHwC9CxZIUgxr+Ps=; b=PKBgFd/Mn/PDwKZy923wLdYPwFD6OrW65QXi/z+A3h6/ANlSwnigImNTvgcyUexjDc ZtTcPpIVMEIP+AtPx8rZylOFBBjQ/Fzk266bXcKL1UE4IPS041t3UEMZ4DZB7bY6D9Zj 0li19Ubw+EQtcKqP1va2UZUSLQNWDhi+tug0XZ8YnagYuebiCzjOiRtbXwvsnuXSR0N+ TAlgSVjuZwdObZll1vBxyxCUkYJs5nBx5+optuOes/gYhOZDYxeZqwEGx9O7zp6hxitC YwXOnD2wojJ4rQ9wOPEgiAwa1y8+NLtuYjCFn+zIdl3/oQxb0SfTrY+j+Jd1d4Vm/jfV sX1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VtHgAQgj; 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 q73si370216pjq.184.2022.01.24.13.29.01; Mon, 24 Jan 2022 13:29:14 -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=VtHgAQgj; 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 S1446335AbiAXVH5 (ORCPT + 99 others); Mon, 24 Jan 2022 16:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390169AbiAXUpD (ORCPT ); Mon, 24 Jan 2022 15:45:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C16CC0424C9; Mon, 24 Jan 2022 11:54:23 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 243316090A; Mon, 24 Jan 2022 19:54:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 092B1C340E5; Mon, 24 Jan 2022 19:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054062; bh=3/xGQscgkM8CssT8T+AIB1T7dP+Y+M/pd+KZ9tVxfUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VtHgAQgjvZdj2zGvRzb3yyknKnTDVIfVzVoj/RzouHwm1w6SblXUDiEPWOhzA1a0u O4Xh8XN4xkVr2YHJ8uACwDWs0jQeBYSYKNDmJEQe3+eqp2kfEHZFVe0btGpdNdi58Z gKQgZLwUORbxjuhK4nhWQlVIZ43mQN5dHG1Hse0Y= 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.10 266/563] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Date: Mon, 24 Jan 2022 19:40:31 +0100 Message-Id: <20220124184033.640624882@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 57314fec2261b..3da69b26e6743 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -1291,19 +1291,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; @@ -1327,17 +1332,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