Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3573809pxb; Mon, 24 Jan 2022 12:33:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJydAHVRazhGguY2jpM8Z/WwiL2bCAo133YENdyTgIBPPrqKkFyeJX5tp3Ph4RSsSrt1gPSB X-Received: by 2002:a17:902:aa03:b0:14a:c626:2317 with SMTP id be3-20020a170902aa0300b0014ac6262317mr15687351plb.7.1643056413902; Mon, 24 Jan 2022 12:33:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056413; cv=none; d=google.com; s=arc-20160816; b=vhBrN7eJfhEZPCdwFy7lhLY24DlDz6lQF0/t6sQJOYs+GgBvFls01wkPDZan7+Ak6L MknVbzvSAVxFgEtK7udQxEgBkwStLOhTBXRxMFTB4WjI3hpNJiP9n3Lxi5wd5Xu9t+Co h55zUv7D2IyqvJwovJEE+73Kc7Y23jjEgG2BKxkXSZPxKWeTQfLF4WdCbT7cHArh5esJ d3f/2DYe8H0w24Mlxif6XVC9tqCIxE2B5a3waPxq7kzLl1J/XI0P5G4WI2WaVuVML5Z+ sD/z6g/tR8EO+U0wPuN3+NsuBDRWWrfKuOdvj9+w1kng8wsYROC33iKAeYtg1rk9ABYW sgXw== 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=UPXmM7m/83LM/+fBNpsgnK9C19p3djjAhcWEio0eOHQ=; b=FazEDAlJ2xQR7Tz/MMo1chhu6wMOTlrv9CozYexWJ4x/8V/IoOPSrRF9H6WWEMt22a QZsAnGaBT305wCfsvAL1PG0UChugtGRCkM7TX6MZ7LJdYR7h3ydTksBTKEl+N/SWJWf7 wXhAGXMw2CV99U3qsUzr/HKOUM5zKaTpH+z8UD/geUbil2hcccGnBo/leWL+4NBtL63u nrAmeSAtcbkTpY93wNrehYm6zPA92GFGA90Qp7P5CVLtLUJ2xBkT5peunL5dh5RJt0Mz Hs1KzQd5dPjGxAUNNt+KnKAfWfQovn915lsX8bbiNlXH1eSTMUbAAMglZr9kX6R6DVAq gbEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EBO4XBby; 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 y6si12273095pgy.692.2022.01.24.12.33.15; Mon, 24 Jan 2022 12:33:33 -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=EBO4XBby; 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 S1344648AbiAXTly (ORCPT + 99 others); Mon, 24 Jan 2022 14:41:54 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60258 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353129AbiAXTcx (ORCPT ); Mon, 24 Jan 2022 14:32:53 -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 180136151B; Mon, 24 Jan 2022 19:32:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECF9AC340E5; Mon, 24 Jan 2022 19:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052772; bh=1k00qKxoOl45JtrC5qwUDU82EQxxTUOYt/FuVoHXc9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBO4XBby+WP+3fQ0cw/97mF13/PPVW50vbxJYKXi4Tgx8gtxOAnZAkBBAkIRD/ZMd VNU01rKMo4JIwHb3MCNsM3iSZcmXgLZirlM7HKPCdZ1aJuVz9bVK+UlBY4OFp+3MBP tIRcgCyrIpy1T4+uZgYFQ3GEWHmklvvdQcA/s8pw= 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.4 136/320] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity() Date: Mon, 24 Jan 2022 19:42:00 +0100 Message-Id: <20220124183958.285126187@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 7dc10c2b4785d..715c85d4e688d 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -1294,19 +1294,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; @@ -1330,17 +1335,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