From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 333661EB36; Sat, 28 Jun 2025 17:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; cv=none; b=ARaytfP8aWwDa4OMaYADnwvbTFTLge7py34bhLEWzM2OjFlqgzinkw+r9WRQOeUAkkIL+ax2TqJH9yL0o0P9W3QMWVuhg/l9C8U21nxWhBhdLrSHNCHjeQOa4un7wGVON4P7wEkBCPAF5EOm21iY9IE5uiN1u1xadQG7HSlRYQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; c=relaxed/simple; bh=LTJgQeXifMFvhewXq1QziXQmUhfSC8Gh4RQFCzcAmcc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F5h6b0zFAjO0w1OGu5xPnUdFF+MsFLiGyOIcqOyUFsYGbbbcErtPpCLKYlyCr9ok2NZvi0Arsw0IS5sINcnV68kKppXNl2EnAx02LNx1HMKb4vYk8PwrTgSoFZmHdnsZjrIJL7TKE2FW4wD7Llj2fXf/AEy+uPRgeLy1NwimOCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pyAcDTzC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pyAcDTzC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3888C4CEEA; Sat, 28 Jun 2025 17:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131827; bh=LTJgQeXifMFvhewXq1QziXQmUhfSC8Gh4RQFCzcAmcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pyAcDTzCLnxhbBnq6ie4dvRqywD9yApCSndQJcRyr2M7f7vU64foxquEIZGNmvRFY 1iM8GgjF9k14Vf5nl6LvqUU2/LrjArPqX9l+9lB8f82/jtZSHno//oO6dbeE0hBPzZ euMhMhzxyJXndom80z1ca+tr8u0yAjbfVb4aoS/9nJVKhKT0ekyH79ByX12SujhmE1 3akMbafBNQesEg4lSiEvdbPneLk3PlckhCyj5zItEKSnxh+O7uB7FHrL9kdh88fFH1 +Qf5rUnathXrF6IBi4+0oywzE1ecG59FMv9UASYUipWSE9wMZv6MqxNmssN6Vcqocn cwK8FaMbbLtMw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNh-00AqZC-Pf; Sat, 28 Jun 2025 18:30:25 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 01/12] genirq: Teach handle_simple_irq() to resend an in-progress interrupt Date: Sat, 28 Jun 2025 18:29:54 +0100 Message-Id: <20250628173005.445013-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" It appears that the defect outlined in 9c15eeb5362c4 ("genirq: Allow fasteoi handler to resend interrupts on concurrent handling") also affects some other less stellar MSI controllers, this time using the handle_simple_irq() flow. Teach this flow about irqd_needs_resend_when_in_progress(). Given the invasive nature of this workaround, only this flow is updated. Signed-off-by: Marc Zyngier Reviewed-by: Thomas Gleixner --- kernel/irq/chip.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 2b274007e8bab..6e789035919f7 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -559,7 +559,13 @@ void handle_simple_irq(struct irq_desc *desc) { guard(raw_spinlock)(&desc->lock); =20 - if (!irq_can_handle(desc)) + if (!irq_can_handle_pm(desc)) { + if (irqd_needs_resend_when_in_progress(&desc->irq_data)) + desc->istate |=3D IRQS_PENDING; + return; + } + + if (!irq_can_handle_actions(desc)) return; =20 kstat_incr_irqs_this_cpu(desc); --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0910264FB1; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; cv=none; b=LE3ra0rh6ox6IjdzEjDC8XEdYZAW2PooCiTeLLCFmQ64r0IRPc+P5No9k9KmycI0W4n3xn/H418ZJtAqv5GU+V4u/zV9/gOjeSgyuNDOo4dTLk+hebDMhH+2H3r4OoD1v5k/Izb9Xlfm6cGsDbMIwEwpU4l2qfboGUYdQhgvlZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; c=relaxed/simple; bh=9TTQFkyY0M8aTj6Iv8cpYI5ilm3sw2M2ZI3G1K0Exkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rkJvulbNAnLbSxQLf7RBLEhvmtxiO9w9cMXeqJFlQCpX8Xt4xKe/eTKZ56/dE6NE5uYVgYSRPYcMoYVRexjntvnROW1wg/QrY9R70ILI5scdT6Cj7QiPeKj9dCTXD957xW1RA2klhlclgWfgdzcmzcT1Gw6K218Ys2MARbs1DWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cFR9aOOr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cFR9aOOr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45383C4CEED; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131828; bh=9TTQFkyY0M8aTj6Iv8cpYI5ilm3sw2M2ZI3G1K0Exkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFR9aOOrkWMwCpnFCv0RgIjSMofAj1v6SNEV0R8UXHUPufnSFsyiPoF2aI5AIJIgL +vEFn4DUaHD/d87N8hzkxecozlxl2UnWDlpjiJL4jYnSYw1Kq8v7Eyb4h100jEYXdC +53idaD1n9dxEMF8VDTLKUcxccEqE3fccC7oPSadlMFDZtmr3yGp3fHZ0xGSrCxFFR CYweTG4X3QncSk/0PUXtC6kT9FjslaQbIODfMtPVd+fYoNgFclyIBeJzJvnTEAY+7L zikQTLcoQdMhzzqbiJwSdXpAtzRUUDM7AQNg1NW09i3pLMv3ipWUr4Cr1vjzYK4Rxx XQIpwzuJJDhkg== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNi-00AqZC-13; Sat, 28 Jun 2025 18:30:26 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 02/12] PCI: xgene: Defer probing if the MSI widget driver hasn't probed yet Date: Sat, 28 Jun 2025 18:29:55 +0100 Message-Id: <20250628173005.445013-3-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" As a preparatory work to make the XGene MSI driver probe less of a sorry hack, make the PCI driver check for the availability of the MSI parent domain, and defer the probing otherwise. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pc= i-xgene.c index 1e2ebbfa36d19..f26cb58f814ec 100644 --- a/drivers/pci/controller/pci-xgene.c +++ b/drivers/pci/controller/pci-xgene.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -594,6 +595,24 @@ static struct pci_ops xgene_pcie_ops =3D { .write =3D pci_generic_config_write32, }; =20 +static bool xgene_check_pcie_msi_ready(void) +{ + struct device_node *np; + struct irq_domain *d; + + if (!IS_ENABLED(CONFIG_PCI_XGENE_MSI)) + return true; + + np =3D of_find_compatible_node(NULL, NULL, "apm,xgene1-msi"); + if (!np) + return true; + + d =3D irq_find_matching_host(np, DOMAIN_BUS_PCI_MSI); + of_node_put(np); + + return d && irq_domain_is_msi_parent(d); +} + static int xgene_pcie_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -602,6 +621,10 @@ static int xgene_pcie_probe(struct platform_device *pd= ev) struct pci_host_bridge *bridge; int ret; =20 + if (!xgene_check_pcie_msi_ready()) + return dev_err_probe(&pdev->dev, -EPROBE_DEFER, + "MSI driver not ready\n"); + bridge =3D devm_pci_alloc_host_bridge(dev, sizeof(*port)); if (!bridge) return -ENOMEM; --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0080527FB0D; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; cv=none; b=ivh0E8K3ySrZbVC8iYuP7aerNjw2ZA4LrUc+uBJRtpmtxPKFuwAEHCMDoi4y4Auhc1uop6qgapJL6F4Ij/xC0Y1qW5wmPbbzq2pOcqKbYnMRVHb5+IozKB/vHHKGr68BH2DcgPZ83PM4WLZHK10AareGux8Bb82HkPP3HqQs/O4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; c=relaxed/simple; bh=XyHVZgTEEU9jeG0R0aHxp6hZU2S5LzzIaxTXL9QhFBI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AF1TlwVA8Ya2UhgRWnabskVlsf+JKfo/h8bUUBGO90U98ckOjZrPCr80A99sCbJdhZVG/9arnmEASVeCv5DoaKE62BYXXg/o0iaPwXI8mRFBDr95m7vGEhSh3d0f93YYFFE5NMmMWoYOnL3v1Ow7Ek3Ha82mQsM0vLb5yJdNO0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lo7vjY6h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lo7vjY6h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E8DDC4CEF2; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131828; bh=XyHVZgTEEU9jeG0R0aHxp6hZU2S5LzzIaxTXL9QhFBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lo7vjY6he4xWIMh1pX/S8sSy8sa2VSOPIMc9V5Ayn8nWMgHmsFhuJ7XMXSxjJ52Ri g1u7MJqMzIS5gAbrvtsirGBRVzU+J+tQDrOtmrWX+FeoveZEOg51x/E2EqwwhX+ToQ vh8AoAK8zs8raM2LEI0Q7yXxgLkG4qXp9OZ0hhdZZDXz38OgGB0bufrYuR5+3ho5Iu L0y0IIkVBue7vuZrkOS7kYJps0fNDG04KEvIlnwF3LMQ4eebPbaMdDqhHHcI6xh8tE 1AKc1Qn9Akab5x7+8aEuRWHTRmh7NQxKpFXfFvSPoxMBdeux4CfGwBKaZ6ucUCgH97 I1WYQBAnKIa/g== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNi-00AqZC-8D; Sat, 28 Jun 2025 18:30:26 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 03/12] PCI: xgene: Drop useless conditional compilation Date: Sat, 28 Jun 2025 18:29:56 +0100 Message-Id: <20250628173005.445013-4-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" pci-xgene.c only gets compiled if CONFIG_PCI_XGENE is selected. It is therefore pointless to check for CONFIG_PCI_XGENE inside the driver. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pc= i-xgene.c index f26cb58f814ec..a848f98203ae4 100644 --- a/drivers/pci/controller/pci-xgene.c +++ b/drivers/pci/controller/pci-xgene.c @@ -58,7 +58,6 @@ #define XGENE_PCIE_IP_VER_1 1 #define XGENE_PCIE_IP_VER_2 2 =20 -#if defined(CONFIG_PCI_XGENE) || (defined(CONFIG_ACPI) && defined(CONFIG_P= CI_QUIRKS)) struct xgene_pcie { struct device_node *node; struct device *dev; @@ -189,7 +188,6 @@ static int xgene_pcie_config_read32(struct pci_bus *bus= , unsigned int devfn, =20 return PCIBIOS_SUCCESSFUL; } -#endif =20 #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) static int xgene_get_csr_resource(struct acpi_device *adev, @@ -280,7 +278,6 @@ const struct pci_ecam_ops xgene_v2_pcie_ecam_ops =3D { }; #endif =20 -#if defined(CONFIG_PCI_XGENE) static u64 xgene_pcie_set_ib_mask(struct xgene_pcie *port, u32 addr, u32 flags, u64 size) { @@ -670,4 +667,3 @@ static struct platform_driver xgene_pcie_driver =3D { .probe =3D xgene_pcie_probe, }; builtin_platform_driver(xgene_pcie_driver); -#endif --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB6CF2BCFB; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; cv=none; b=SAkhAyRYSBPcvbGKysXKP/acQIsD3g1cfGLRTscnCLsU9xqVJS+kvqahsacYL+yoj1z2lR7y1FvMybB90RoihW2c3tf2R17abwOiFM9B3dqAMMHdm0TPVYFYD5goqUIuYZkzmUHT9ZUQSiV1c0MFwrmx5Qs6GWCc04tY1gtBmks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131828; c=relaxed/simple; bh=zWAmwKnV6f1cwbtaUPgrJ1lIE+Rc2XJQ33KR+f1+GBg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GaGXza3prxWZk7EdYm9ynyo5M9BvXE6YoZ4bQ4JViGB0MnVDVxXpziJPWRX5DVRLas2QEBtX68KYZPvi+0VfdzBHKW2staG7MU6B+6UoUv/Zlvn2cKAH6AnHx/YMltMiCRP9XfkUT7q6K3nrMiJ36/C1ibPUfpcH1z1yMTGCaeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l/5rNor2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l/5rNor2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CA90C4CEEA; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131828; bh=zWAmwKnV6f1cwbtaUPgrJ1lIE+Rc2XJQ33KR+f1+GBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/5rNor2Px+Cl03/jN1HOWynCV9eo9DeSLJ6bO8UiztHyxYNqMuyqqhnzMpSnt9TH 3kRNDIs83QmyR1QPNeG7WCWI59VZYaYbtT3Z4uHHSfsVP357KbSIMqAzl2Q/nRTYEx oL63w2UYzn9/d/mr3Ns+0EL9e7sCXCVWM6oQj0pJKOGAuPh/9Gu2jB2bVawB7D5qxe 2pwPMr0neIm6Fv06BYVWNU26Frt54kD1MzdyyUugfZvBPxEkIGqf5NkJL9DUg0P1rS ZZIFOxvccdpe4/0TJL6k94CwGN+DGQFO6jwdMb1sn6kDdRXlaVjJusfA+20YePCd3L BJM2bK8IJ+3/w== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNi-00AqZC-Fv; Sat, 28 Jun 2025 18:30:26 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 04/12] PCI: xgene: Drop XGENE_PCIE_IP_VER_UNKN Date: Sat, 28 Jun 2025 18:29:57 +0100 Message-Id: <20250628173005.445013-5-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" XGENE_PCIE_IP_VER_UNKN is only refered to when probing for the original XGene PCIe implementation, and get immediately overridden if the device has the "apm,xgene-pcie" compatible string. Given that the only way to get there is by finding this very string in the DT, it is obvious that we will always ovwrite the version with XGENE_PCIE_IP_VER_1. Drop the whole thing. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/pci/controller/pci-xgene.c b/drivers/pci/controller/pc= i-xgene.c index a848f98203ae4..b95afa35201d0 100644 --- a/drivers/pci/controller/pci-xgene.c +++ b/drivers/pci/controller/pci-xgene.c @@ -54,7 +54,6 @@ #define XGENE_V1_PCI_EXP_CAP 0x40 =20 /* PCIe IP version */ -#define XGENE_PCIE_IP_VER_UNKN 0 #define XGENE_PCIE_IP_VER_1 1 #define XGENE_PCIE_IP_VER_2 2 =20 @@ -630,10 +629,7 @@ static int xgene_pcie_probe(struct platform_device *pd= ev) =20 port->node =3D of_node_get(dn); port->dev =3D dev; - - port->version =3D XGENE_PCIE_IP_VER_UNKN; - if (of_device_is_compatible(port->node, "apm,xgene-pcie")) - port->version =3D XGENE_PCIE_IP_VER_1; + port->version =3D XGENE_PCIE_IP_VER_1; =20 ret =3D xgene_pcie_map_reg(port, pdev); if (ret) --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00793278741; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; cv=none; b=Lm9+0C52h0dSTIlyMgouzMj6xYKm4whV3P52KCk4AD7c2Z/C8EifH4n70p0bGNf6jLKPx1VNKqd8Wn//RFEWwtqMpK2NS2pb/C+G73uQGTdgdfLUUaIU2fHv7OWAfJ/ThrX8tViMWOK+wRwFiL2zVMM+36oLa6qUfWViRvBXNak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; c=relaxed/simple; bh=sLHbDjMOHIJK5FmjK2GBYLynXvuhrJcJu9u/Pnuu0t4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZiiYQL8whEdFEjoA3XiZzFTpCs8Q5IGyTEkS2uYvIRJ3f3AOvu9oMOK3BprEogf6JQj9H7lFPNjjfvACL66FGnydUTM+myT9xLC8t1zskGx1zWOLdEKoPuNuDsdlF45ohl/AbhpNev+BEMD84bpop9tbh6o0bAm+0n51xLI8FgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UBUd/rwb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UBUd/rwb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2A4BC4AF0B; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131828; bh=sLHbDjMOHIJK5FmjK2GBYLynXvuhrJcJu9u/Pnuu0t4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UBUd/rwbkcwGj5oOKCjOnDc9IgcnMsAY4+78S/j83PoJA0drmiifTAZmie46L9sve TVtvum5fmrJBq2JukTpUK2Nxs2PaoE4gb4rVig4COzT4niYnlb5VUw8Nv3bCgmGWtW wJFe1AkOBpGnxUYXdphSzijlgXK8AUlFoxU8QPDExqscFE7mvIjvpr5hM5jwHwi2Dj FxXPi3DhI4ngIf5UQxJRAbfRFJabxae+5pCjVfUdkXdQoEFOH0VMtFYbavb2MUbBor FKanDCFZDNnDdGS6yfN2zx8TecQOEKCLP1HFniAxUsHGLQQEUIIReg/Xb6px5dxMl2 wd4udbWxBy5Aw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNi-00AqZC-OS; Sat, 28 Jun 2025 18:30:26 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 05/12] PCI: xgene-msi: Make per-CPU interrupt setup robust Date: Sat, 28 Jun 2025 18:29:58 +0100 Message-Id: <20250628173005.445013-6-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" The way the per-CPU interrupts are dealt with in the XGene MSI driver isn't great: - the affinity is set after the interrupt is enabled - nothing prevents userspace from moving the interrupt around - the affinity setting code pointlessly allocates memory - the driver checks for conditions that cannot possibly happen Address all of this in one go, resulting in slightly simpler setup code. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index b05ec8b0bb93f..25cb4119bab07 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -355,40 +355,26 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) { struct xgene_msi *msi =3D &xgene_msi_ctrl; struct xgene_msi_group *msi_group; - cpumask_var_t mask; int i; int err; =20 for (i =3D cpu; i < NR_HW_IRQS; i +=3D msi->num_cpus) { msi_group =3D &msi->msi_groups[i]; - if (!msi_group->gic_irq) - continue; - - irq_set_chained_handler_and_data(msi_group->gic_irq, - xgene_msi_isr, msi_group); =20 /* * Statically allocate MSI GIC IRQs to each CPU core. * With 8-core X-Gene v1, 2 MSI GIC IRQs are allocated * to each core. */ - if (alloc_cpumask_var(&mask, GFP_KERNEL)) { - cpumask_clear(mask); - cpumask_set_cpu(cpu, mask); - err =3D irq_set_affinity(msi_group->gic_irq, mask); - if (err) - pr_err("failed to set affinity for GIC IRQ"); - free_cpumask_var(mask); - } else { - pr_err("failed to alloc CPU mask for affinity\n"); - err =3D -EINVAL; - } - + irq_set_status_flags(msi_group->gic_irq, IRQ_NO_BALANCING); + err =3D irq_set_affinity(msi_group->gic_irq, cpumask_of(cpu)); if (err) { - irq_set_chained_handler_and_data(msi_group->gic_irq, - NULL, NULL); + pr_err("failed to set affinity for GIC IRQ"); return err; } + + irq_set_chained_handler_and_data(msi_group->gic_irq, + xgene_msi_isr, msi_group); } =20 return 0; --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D4FE2868A9; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; cv=none; b=hdUjKgQ+yLFa2ouUhmXGVLYYlUx4adqAHU+klmSSYmuKXVJKz/ZxtAa+5/ZGLEBkD9cCAUxsy2PsOmsYgbeiQhZoZi74l/dY56IirIGk5e7Xy6s6sInNgFpILxX6DCiTJGSDprIhaI3G5W9o4ouYk2FSM/6bdWlGqwO+WXk2e+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; c=relaxed/simple; bh=4Gg5A1LyFjdZmUgJo3m479Qqj8iK0uKlUkKwvsIYG08=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Aq9ijG553T8Z1fZJ7yvTxrYZbtqO8KWoiuJwKLPJWtJIWuPNSrUXc/PZUWH/acq4iQsoZWQZHXyE/m08iIjvj362TJXhnDkK71LEg/yqs6HSsd8yVUmXuctk0M2YmkvsIRMGvsrASR2CFo7KiOs+2yqxPKW5n+i4TIAbO0KqRGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CFCsT+rL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CFCsT+rL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFD76C4CEED; Sat, 28 Jun 2025 17:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131828; bh=4Gg5A1LyFjdZmUgJo3m479Qqj8iK0uKlUkKwvsIYG08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CFCsT+rLkcqq4jOmXDTLFYZVnXozPG6tq3LqY/qFbK7zn00/y0gSMDg5/P+gT5c8x FII2gsx2fui7qRAYLNnDw2owytPhv5s8uRX0cZp4uCDAhWvcv86La3J3RBZOCZZiSN 3Dm5ItjnrQSwyuUzJ6ZXMwB86kDWyjyf+jyacsdZQhTc4RSWXneEU5Q0faowlDPEtH zpMOhBFllKZ99SbP/f6E4iENVsIkiuCRfLNZU+davFELsKyXGsUh5feWZ48CZOpKvn Y5IIjylzWJoYfy6GopTBucTluQEY2lOBFgnTrH+aB0C0k6rpPtiUcn+8V45M/YOcxj n1vvwYNup/wqQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNj-00AqZC-09; Sat, 28 Jun 2025 18:30:27 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 06/12] PCI: xgene-msi: Drop superfluous fields from xgene_msi structure Date: Sat, 28 Jun 2025 18:29:59 +0100 Message-Id: <20250628173005.445013-7-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" The xgene_msi structure remembers both the of_node of the device and the number of CPUs. All of which are perfectly useless. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index 25cb4119bab07..3ca9a13cf38d3 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -31,14 +31,12 @@ struct xgene_msi_group { }; =20 struct xgene_msi { - struct device_node *node; struct irq_domain *inner_domain; u64 msi_addr; void __iomem *msi_regs; unsigned long *bitmap; struct mutex bitmap_lock; struct xgene_msi_group *msi_groups; - int num_cpus; }; =20 /* Global data */ @@ -147,7 +145,7 @@ static void xgene_compose_msi_msg(struct irq_data *data= , struct msi_msg *msg) */ static int hwirq_to_cpu(unsigned long hwirq) { - return (hwirq % xgene_msi_ctrl.num_cpus); + return (hwirq % num_possible_cpus()); } =20 static unsigned long hwirq_to_canonical_hwirq(unsigned long hwirq) @@ -186,9 +184,9 @@ static int xgene_irq_domain_alloc(struct irq_domain *do= main, unsigned int virq, mutex_lock(&msi->bitmap_lock); =20 msi_irq =3D bitmap_find_next_zero_area(msi->bitmap, NR_MSI_VEC, 0, - msi->num_cpus, 0); + num_possible_cpus(), 0); if (msi_irq < NR_MSI_VEC) - bitmap_set(msi->bitmap, msi_irq, msi->num_cpus); + bitmap_set(msi->bitmap, msi_irq, num_possible_cpus()); else msi_irq =3D -ENOSPC; =20 @@ -214,7 +212,7 @@ static void xgene_irq_domain_free(struct irq_domain *do= main, mutex_lock(&msi->bitmap_lock); =20 hwirq =3D hwirq_to_canonical_hwirq(d->hwirq); - bitmap_clear(msi->bitmap, hwirq, msi->num_cpus); + bitmap_clear(msi->bitmap, hwirq, num_possible_cpus()); =20 mutex_unlock(&msi->bitmap_lock); =20 @@ -235,10 +233,11 @@ static const struct msi_parent_ops xgene_msi_parent_o= ps =3D { .init_dev_msi_info =3D msi_lib_init_dev_msi_info, }; =20 -static int xgene_allocate_domains(struct xgene_msi *msi) +static int xgene_allocate_domains(struct device_node *node, + struct xgene_msi *msi) { struct irq_domain_info info =3D { - .fwnode =3D of_fwnode_handle(msi->node), + .fwnode =3D of_fwnode_handle(node), .ops =3D &xgene_msi_domain_ops, .size =3D NR_MSI_VEC, .host_data =3D msi, @@ -358,7 +357,7 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) int i; int err; =20 - for (i =3D cpu; i < NR_HW_IRQS; i +=3D msi->num_cpus) { + for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { msi_group =3D &msi->msi_groups[i]; =20 /* @@ -386,11 +385,10 @@ static int xgene_msi_hwirq_free(unsigned int cpu) struct xgene_msi_group *msi_group; int i; =20 - for (i =3D cpu; i < NR_HW_IRQS; i +=3D msi->num_cpus) { + for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { msi_group =3D &msi->msi_groups[i]; if (!msi_group->gic_irq) continue; - irq_set_chained_handler_and_data(msi_group->gic_irq, NULL, NULL); } @@ -420,8 +418,6 @@ static int xgene_msi_probe(struct platform_device *pdev) goto error; } xgene_msi->msi_addr =3D res->start; - xgene_msi->node =3D pdev->dev.of_node; - xgene_msi->num_cpus =3D num_possible_cpus(); =20 rc =3D xgene_msi_init_allocator(xgene_msi); if (rc) { @@ -429,7 +425,7 @@ static int xgene_msi_probe(struct platform_device *pdev) goto error; } =20 - rc =3D xgene_allocate_domains(xgene_msi); + rc =3D xgene_allocate_domains(dev_of_node(&pdev->dev), xgene_msi); if (rc) { dev_err(&pdev->dev, "Failed to allocate MSI domain\n"); goto error; --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3511E287270; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; cv=none; b=c/lVoPkmCj51ajU9w+ANqm1L8Jh2Gvf+dsAX6xBNIgTsoL32lAhwe2Vm35wN1XTgDd2ab7ML0cm3SPpUjM2G1y0/W3pO3+IGytQmmgCKnFympXw7cGQfzASjdXlNEtCkw2qK0iM+GbW0AekXVagBd8+7Wa0jIk9N5v0mZ4F3/fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131829; c=relaxed/simple; bh=JZyJGXIu/4I+riiflFUcQzbvQss2UZj5eTHZTtcmb0U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hxBC47+MVft4h7vqDX648VdprI4y+6rMzHpSELbO9s18CUEMMno34D3Q7oDdbKUFAull2RYZs3yIsFOEaO4xilWh8rwQfwNztgpV0YRblLk0/u+VVWceRXQ+OMOokrl2787QYUFzzX2pgJHlLcFmFzn4G0nilbY+Lr1cZiANLLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LO9h/GJi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LO9h/GJi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1060AC4CEEA; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131829; bh=JZyJGXIu/4I+riiflFUcQzbvQss2UZj5eTHZTtcmb0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LO9h/GJi2Ir33taGZccJ/ya3WyPfw3E0QPo2kAy/N58uMiARZCXYxj+35Jsu0zvOV 8ReuFVXfP3eQxrBmNvIxe0PwjwCx/OFjjNN1Gc0/n7pyXP+Cd5COgAJzJFDd7fWOGl vA/FVG/OytThgFLMC9LqWitbUTkbWRYCbm4tv7pci7FlCrX+3grl8vhygo6nhCdvo/ eOE0Tz5JHJCrvCLFGY5U11ZEqEi2YBNclLmINOZY4n6JQT111b4c66JMTQmZC14pTb qENINSVmIEI9zJI+ptMIMzrqJNx8L/VSXu0sE8+X4uHMUH+8jxdFwxpAyps7FtycTK 7exj2AVFw0vJw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNj-00AqZC-8P; Sat, 28 Jun 2025 18:30:27 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 07/12] PCI: xgene-msi: Use device-managed memory allocations Date: Sat, 28 Jun 2025 18:30:00 +0100 Message-Id: <20250628173005.445013-8-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Since the MSI driver is probed as a platform device, there is no reason to not use device-managed allocations. That's including the top-level bookkeeping structure, which is better dynamically alocated than being static. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index 3ca9a13cf38d3..b3ac0125b3b40 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -40,7 +40,7 @@ struct xgene_msi { }; =20 /* Global data */ -static struct xgene_msi xgene_msi_ctrl; +static struct xgene_msi *xgene_msi_ctrl; =20 /* * X-Gene v1 has 16 groups of MSI termination registers MSInIRx, where @@ -253,18 +253,18 @@ static void xgene_free_domains(struct xgene_msi *msi) irq_domain_remove(msi->inner_domain); } =20 -static int xgene_msi_init_allocator(struct xgene_msi *xgene_msi) +static int xgene_msi_init_allocator(struct device *dev) { - xgene_msi->bitmap =3D bitmap_zalloc(NR_MSI_VEC, GFP_KERNEL); - if (!xgene_msi->bitmap) + xgene_msi_ctrl->bitmap =3D devm_bitmap_zalloc(dev, NR_MSI_VEC, GFP_KERNEL= ); + if (!xgene_msi_ctrl->bitmap) return -ENOMEM; =20 - mutex_init(&xgene_msi->bitmap_lock); + mutex_init(&xgene_msi_ctrl->bitmap_lock); =20 - xgene_msi->msi_groups =3D kcalloc(NR_HW_IRQS, - sizeof(struct xgene_msi_group), - GFP_KERNEL); - if (!xgene_msi->msi_groups) + xgene_msi_ctrl->msi_groups =3D devm_kcalloc(dev, NR_HW_IRQS, + sizeof(struct xgene_msi_group), + GFP_KERNEL); + if (!xgene_msi_ctrl->msi_groups) return -ENOMEM; =20 return 0; @@ -273,15 +273,14 @@ static int xgene_msi_init_allocator(struct xgene_msi = *xgene_msi) static void xgene_msi_isr(struct irq_desc *desc) { struct irq_chip *chip =3D irq_desc_get_chip(desc); + struct xgene_msi *xgene_msi =3D xgene_msi_ctrl; struct xgene_msi_group *msi_groups; - struct xgene_msi *xgene_msi; int msir_index, msir_val, hw_irq, ret; u32 intr_index, grp_select, msi_grp; =20 chained_irq_enter(chip, desc); =20 msi_groups =3D irq_desc_get_handler_data(desc); - xgene_msi =3D msi_groups->msi; msi_grp =3D msi_groups->msi_grp; =20 /* @@ -344,15 +343,12 @@ static void xgene_msi_remove(struct platform_device *= pdev) =20 kfree(msi->msi_groups); =20 - bitmap_free(msi->bitmap); - msi->bitmap =3D NULL; - xgene_free_domains(msi); } =20 static int xgene_msi_hwirq_alloc(unsigned int cpu) { - struct xgene_msi *msi =3D &xgene_msi_ctrl; + struct xgene_msi *msi =3D xgene_msi_ctrl; struct xgene_msi_group *msi_group; int i; int err; @@ -381,7 +377,7 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) =20 static int xgene_msi_hwirq_free(unsigned int cpu) { - struct xgene_msi *msi =3D &xgene_msi_ctrl; + struct xgene_msi *msi =3D xgene_msi_ctrl; struct xgene_msi_group *msi_group; int i; =20 @@ -408,7 +404,12 @@ static int xgene_msi_probe(struct platform_device *pde= v) int virt_msir; u32 msi_val, msi_idx; =20 - xgene_msi =3D &xgene_msi_ctrl; + xgene_msi_ctrl =3D devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl), + GFP_KERNEL); + if (!xgene_msi_ctrl) + return -ENOMEM; + + xgene_msi =3D xgene_msi_ctrl; =20 platform_set_drvdata(pdev, xgene_msi); =20 @@ -419,7 +420,7 @@ static int xgene_msi_probe(struct platform_device *pdev) } xgene_msi->msi_addr =3D res->start; =20 - rc =3D xgene_msi_init_allocator(xgene_msi); + rc =3D xgene_msi_init_allocator(&pdev->dev); if (rc) { dev_err(&pdev->dev, "Error allocating MSI bitmap\n"); goto error; --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF2602877DB; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; cv=none; b=N7gPL3cc25lJ8ocCoOqFAQkjIL0fSjwNDLeTLzNWPS8QoCp9hk5pKxiz6uVVkkXqhHSPeyEFQWMFRKnji3OIKNo6e3rwyQNuwKNX9xnQGT3KPySyct7JwDD3HPHhZOLOsa3E1pZ7OGIFN6FrtyEJj1D7SzVXikNrGCVsGM84L+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; c=relaxed/simple; bh=DHDYX8cxljeI3rHGGcqR3uEzr7HycmJ924nJhLeqQ78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GZDk4Mce+9jQTGs9/ZscjGA9o+rmK7G9nQ+b1pDRY+pZQ+U2RGZ5QNEnR8PFO6zlv23FJPuRUy5bpyicFtlIbj951z8fv/F/CbXgrT2IZm/1Us1vwi1OFmJ8+my7P9djMtyNySx/8IshUUXp3B1/b69d1GnUAVE6OAh5IyPmlk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rMziUJ9p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rMziUJ9p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C09CC4CEEA; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131829; bh=DHDYX8cxljeI3rHGGcqR3uEzr7HycmJ924nJhLeqQ78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMziUJ9pucVOVHytvHBKwI1DHX9Hn6L2H2Kvhrn1AcG77Ur4XuHhLaN7LwT0i4EfK xscWXWjSYh6/xEjPo1WONO2OJWS3+h8V1sF9wgRctg1HbFSydTF5hZyqtbexCY7DgW j6WB/Rjp6QtJgl8kPR0k4ZT9za3gdZkdUum7bXdfBs0PgOlPz3GE3RIZENl/Jx//Cc LmLLDZxyP4bLnaHhrt2e/GUbRs/0WaCjYT7+wEPMzohjasfxvUCeOIv9zxFyYX94sF AeX4Nd4thFOsMZCXlnUg+j/h+PSIBWF5FLi8DgoSd1Rn8usPm/L2JNprE/bFN1bPHY rHfD8yo3fFIPQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNj-00AqZC-GE; Sat, 28 Jun 2025 18:30:27 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 08/12] PCI: xgene-msi: Get rid of intermediate tracking structure Date: Sat, 28 Jun 2025 18:30:01 +0100 Message-Id: <20250628173005.445013-9-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" The xgene-msi driver uses an odd construct in the form of an intermediate tracking structure, evidently designed to deal with multiple instances of the MSI widget. However, the existing HW only has one set, and it is obvious that there won't be new HW coming down that particular line. Simplify the driver by using a bit of pointer arithmetic instead, directly tracking the interrupt and avoiding extra memory allocation. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 58 ++++++++------------------ 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index b3ac0125b3b40..4be79b9ff80df 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -24,19 +24,13 @@ #define NR_HW_IRQS 16 #define NR_MSI_VEC (IDX_PER_GROUP * IRQS_PER_IDX * NR_HW_IRQS) =20 -struct xgene_msi_group { - struct xgene_msi *msi; - int gic_irq; - u32 msi_grp; -}; - struct xgene_msi { struct irq_domain *inner_domain; u64 msi_addr; void __iomem *msi_regs; unsigned long *bitmap; struct mutex bitmap_lock; - struct xgene_msi_group *msi_groups; + unsigned int gic_irq[NR_HW_IRQS]; }; =20 /* Global data */ @@ -261,27 +255,20 @@ static int xgene_msi_init_allocator(struct device *de= v) =20 mutex_init(&xgene_msi_ctrl->bitmap_lock); =20 - xgene_msi_ctrl->msi_groups =3D devm_kcalloc(dev, NR_HW_IRQS, - sizeof(struct xgene_msi_group), - GFP_KERNEL); - if (!xgene_msi_ctrl->msi_groups) - return -ENOMEM; - return 0; } =20 static void xgene_msi_isr(struct irq_desc *desc) { + unsigned int *irqp =3D irq_desc_get_handler_data(desc); struct irq_chip *chip =3D irq_desc_get_chip(desc); struct xgene_msi *xgene_msi =3D xgene_msi_ctrl; - struct xgene_msi_group *msi_groups; int msir_index, msir_val, hw_irq, ret; u32 intr_index, grp_select, msi_grp; =20 chained_irq_enter(chip, desc); =20 - msi_groups =3D irq_desc_get_handler_data(desc); - msi_grp =3D msi_groups->msi_grp; + msi_grp =3D irqp - xgene_msi->gic_irq; =20 /* * MSIINTn (n is 0..F) indicates if there is a pending MSI interrupt @@ -341,35 +328,31 @@ static void xgene_msi_remove(struct platform_device *= pdev) cpuhp_remove_state(pci_xgene_online); cpuhp_remove_state(CPUHP_PCI_XGENE_DEAD); =20 - kfree(msi->msi_groups); - xgene_free_domains(msi); } =20 static int xgene_msi_hwirq_alloc(unsigned int cpu) { - struct xgene_msi *msi =3D xgene_msi_ctrl; - struct xgene_msi_group *msi_group; int i; int err; =20 for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { - msi_group =3D &msi->msi_groups[i]; + unsigned int irq =3D xgene_msi_ctrl->gic_irq[i]; =20 /* * Statically allocate MSI GIC IRQs to each CPU core. * With 8-core X-Gene v1, 2 MSI GIC IRQs are allocated * to each core. */ - irq_set_status_flags(msi_group->gic_irq, IRQ_NO_BALANCING); - err =3D irq_set_affinity(msi_group->gic_irq, cpumask_of(cpu)); + irq_set_status_flags(irq, IRQ_NO_BALANCING); + err =3D irq_set_affinity(irq, cpumask_of(cpu)); if (err) { pr_err("failed to set affinity for GIC IRQ"); return err; } =20 - irq_set_chained_handler_and_data(msi_group->gic_irq, - xgene_msi_isr, msi_group); + irq_set_chained_handler_and_data(irq, xgene_msi_isr, + &xgene_msi_ctrl->gic_irq[i]); } =20 return 0; @@ -378,15 +361,12 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) static int xgene_msi_hwirq_free(unsigned int cpu) { struct xgene_msi *msi =3D xgene_msi_ctrl; - struct xgene_msi_group *msi_group; int i; =20 for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { - msi_group =3D &msi->msi_groups[i]; - if (!msi_group->gic_irq) + if (!msi->gic_irq[i]) continue; - irq_set_chained_handler_and_data(msi_group->gic_irq, NULL, - NULL); + irq_set_chained_handler_and_data(msi->gic_irq[i], NULL, NULL); } return 0; } @@ -399,10 +379,9 @@ static const struct of_device_id xgene_msi_match_table= [] =3D { static int xgene_msi_probe(struct platform_device *pdev) { struct resource *res; - int rc, irq_index; struct xgene_msi *xgene_msi; - int virt_msir; u32 msi_val, msi_idx; + int rc; =20 xgene_msi_ctrl =3D devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl), GFP_KERNEL); @@ -432,15 +411,12 @@ static int xgene_msi_probe(struct platform_device *pd= ev) goto error; } =20 - for (irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { - virt_msir =3D platform_get_irq(pdev, irq_index); - if (virt_msir < 0) { - rc =3D virt_msir; + for (int irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { + rc =3D platform_get_irq(pdev, irq_index); + if (rc < 0) goto error; - } - xgene_msi->msi_groups[irq_index].gic_irq =3D virt_msir; - xgene_msi->msi_groups[irq_index].msi_grp =3D irq_index; - xgene_msi->msi_groups[irq_index].msi =3D xgene_msi; + + xgene_msi->gic_irq[irq_index] =3D rc; } =20 /* @@ -448,7 +424,7 @@ static int xgene_msi_probe(struct platform_device *pdev) * interrupt handlers, read all of them to clear spurious * interrupts that may occur before the driver is probed. */ - for (irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { + for (int irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { for (msi_idx =3D 0; msi_idx < IDX_PER_GROUP; msi_idx++) xgene_msi_ir_read(xgene_msi, irq_index, msi_idx); =20 --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C32D2882A2; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; cv=none; b=qIyg9UJSQI+jgvqqiD3TDT8eZx6M/LPOuEGWAWyFf4eckUhKihCFBrF180Z+2H1FzFJCCoQTfkmkTRcpqCJh2hEZliuf+1eQw8qJjfdh55F7m+4c0tsxL99S57va75eyA5hUcvayYNalNwaNfXbEDdOoHkX6wbOVcYJJMJ9wFow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; c=relaxed/simple; bh=rYCQKGb1ZqPdvdaV2zXhlkoVVymsw18Qy4NODhcH3ZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uGa0Bzhy322nahqlTwDOcMJ4nX6vjlgu1SwbczYbljd4OykTiDCT7+GVjYk4aLPx3BCTSwOfXkKiLeg0O2OwfIDI6pbiEyVMOQG7jAYzxEIpBpg3ZHYRj9+jJIl0HZdyqRXq1hKhZcsJtBGgqhPjMS8QSWU07oAl95LdRys6apE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mmOUmfTm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mmOUmfTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6415C4CEED; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131829; bh=rYCQKGb1ZqPdvdaV2zXhlkoVVymsw18Qy4NODhcH3ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmOUmfTmwFZLwjKLAY8QqNR38lRHuU+tfuzbWXK3c1BNS/Ugp/VATFdJ2i+jLWwrT IT5DffEw1nS4I2uhqSJQ9YTM99JT7Hl7Gl4iWFu4tKQZGLM3gQfI2inG/l6NwC4HuK 14s+fFxCGERkuDlAOZ6rBJ+LcsdRVN7cTnAAuE2wVOnNTb/L6BozTRb+mMagow/V10 CGXgHAduH0nByQ9JVG4M5sWbfw/WbJK+XzkP18Hb7cZk7XHGO29nERKo/zzkSSNjIO 42qwKZ/C08KhJ0/yWMHRmtw8t+4kaFKdC/sZRKBFpHd2bMsx983RBnDcBB3BOp1Nsb T8GxZx/ogMi+w== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNj-00AqZC-Sf; Sat, 28 Jun 2025 18:30:28 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 09/12] PCI: xgene-msi: Sanitise MSI allocation and affinity setting Date: Sat, 28 Jun 2025 18:30:02 +0100 Message-Id: <20250628173005.445013-10-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Plugging a device that doesn't use managed affinity on an XGene-1 machine results in messages such as: genirq: irq_chip PCI-MSIX-0000:01:00.0 did not update eff. affinity mask of= irq 39 As it turns out, the driver was never updated to populate the effective affinity on irq_set_affinity() call, and the core code is prickly about that. But upon further investigation, it appears that the driver keeps repainting the hwirq field of the irq_data structure as a way to track the affinity of the MSI, something that is very much frowned upon as it breaks the fundamentals of an IRQ domain (an array indexed by hwirq). Fixing this results more or less in a rewrite of the driver: - Define how a hwirq and a cpu affinity map onto the MSI termination registers - Allocate a single entry in the bitmap per MSI instead of *8* - Correctly track CPU affinity - Fix the documentation so that it actually means something (to me) - Use standard bitmap iterators - and plenty of other cleanups With this, the driver behaves correctly on my vintage Mustang board. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 212 ++++++++++--------------- 1 file changed, 82 insertions(+), 130 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index 4be79b9ff80df..fbfdc80942596 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -6,6 +6,7 @@ * Author: Tanmay Inamdar * Duc Dang */ +#include #include #include #include @@ -22,7 +23,12 @@ #define IDX_PER_GROUP 8 #define IRQS_PER_IDX 16 #define NR_HW_IRQS 16 -#define NR_MSI_VEC (IDX_PER_GROUP * IRQS_PER_IDX * NR_HW_IRQS) +#define NR_MSI_BITS (IDX_PER_GROUP * IRQS_PER_IDX * NR_HW_IRQS) +#define NR_MSI_VEC (NR_MSI_BITS / num_possible_cpus()) + +#define MSI_GROUP_MASK GENMASK(22, 19) +#define MSI_INDEX_MASK GENMASK(18, 16) +#define MSI_INTR_MASK GENMASK(19, 16) =20 struct xgene_msi { struct irq_domain *inner_domain; @@ -37,8 +43,21 @@ struct xgene_msi { static struct xgene_msi *xgene_msi_ctrl; =20 /* - * X-Gene v1 has 16 groups of MSI termination registers MSInIRx, where - * n is group number (0..F), x is index of registers in each group (0..7) + * X-Gene v1 has 16 frames of MSI termination registers MSInIRx, where n is + * frame number (0..15), x is index of registers in each frame (0..7). Ea= ch + * 32b register is at the beginning of a 64kB region, each frame occupying + * 512kB (and the whole thing 8MB of PA space). + * + * Each register supports 16 MSI vectors (0..15) to generate interrupts. + * + * Additionally, each MSI termination frame has 1 MSIINTn register (n is + * 0..15) to indicate the MSI pending status caused by 1 of its 8 index + * registers. Each 32b register is at the beginning of a 64kB region (and + * overall occupying an extra 1MB). + * + * There is one GIC IRQ assigned for each MSI termination frame, 16 in + * total. + * * The register layout is as follows: * MSI0IR0 base_addr * MSI0IR1 base_addr + 0x10000 @@ -59,13 +78,6 @@ static struct xgene_msi *xgene_msi_ctrl; * MSIINT1 base_addr + 0x810000 * ... ... * MSIINTF base_addr + 0x8F0000 - * - * Each index register supports 16 MSI vectors (0..15) to generate interru= pt. - * There are total 16 GIC IRQs assigned for these 16 groups of MSI termina= tion - * registers. - * - * Each MSI termination group has 1 MSIINTn register (n is 0..15) to indic= ate - * the MSI pending status caused by 1 of its 8 index registers. */ =20 /* MSInIRx read helper */ @@ -73,93 +85,60 @@ static u32 xgene_msi_ir_read(struct xgene_msi *msi, u32 msi_grp, u32 msir_idx) { return readl_relaxed(msi->msi_regs + MSI_IR0 + - (msi_grp << 19) + (msir_idx << 16)); + (FIELD_PREP(MSI_GROUP_MASK, msi_grp) | + FIELD_PREP(MSI_INDEX_MASK, msir_idx))); } =20 /* MSIINTn read helper */ static u32 xgene_msi_int_read(struct xgene_msi *msi, u32 msi_grp) { - return readl_relaxed(msi->msi_regs + MSI_INT0 + (msi_grp << 16)); + return readl_relaxed(msi->msi_regs + MSI_INT0 + + FIELD_PREP(MSI_INTR_MASK, msi_grp)); } =20 /* - * With 2048 MSI vectors supported, the MSI message can be constructed usi= ng - * following scheme: - * - Divide into 8 256-vector groups - * Group 0: 0-255 - * Group 1: 256-511 - * Group 2: 512-767 - * ... - * Group 7: 1792-2047 - * - Each 256-vector group is divided into 16 16-vector groups - * As an example: 16 16-vector groups for 256-vector group 0-255 is - * Group 0: 0-15 - * Group 1: 16-32 - * ... - * Group 15: 240-255 - * - The termination address of MSI vector in 256-vector group n and 16-ve= ctor - * group x is the address of MSIxIRn - * - The data for MSI vector in 16-vector group x is x + * In order to allow an MSI to be moved from one CPU to another without + * having to repaint both the address and the data (which cannot be done + * atomically), we statically partitions the MSI frames between CPUs. Given + * that XGene-1 has 8 CPUs, each CPU gets two frames assigned to it + * + * We adopt the convention that when an MSI is moved, it is configured to + * target the same register number in the new frame. This reserves a given + * MSI across all CPUs, and reduces the MSI capacity from 2048 to 256. + * + * Effectively, this amounts to: + * - hwirq[7]::cpu[2:0] is the target frame number + * - hwirq[6:4] is the register index in any given frame + * - hwirq[3:0] is the MSI data */ -static u32 hwirq_to_reg_set(unsigned long hwirq) -{ - return (hwirq / (NR_HW_IRQS * IRQS_PER_IDX)); -} - -static u32 hwirq_to_group(unsigned long hwirq) -{ - return (hwirq % NR_HW_IRQS); -} - -static u32 hwirq_to_msi_data(unsigned long hwirq) -{ - return ((hwirq / NR_HW_IRQS) % IRQS_PER_IDX); -} - static void xgene_compose_msi_msg(struct irq_data *data, struct msi_msg *m= sg) { struct xgene_msi *msi =3D irq_data_get_irq_chip_data(data); - u32 reg_set =3D hwirq_to_reg_set(data->hwirq); - u32 group =3D hwirq_to_group(data->hwirq); - u64 target_addr =3D msi->msi_addr + (((8 * group) + reg_set) << 16); + u64 target_addr; + u32 frame, msir; + int cpu; =20 - msg->address_hi =3D upper_32_bits(target_addr); - msg->address_lo =3D lower_32_bits(target_addr); - msg->data =3D hwirq_to_msi_data(data->hwirq); -} + cpu =3D cpumask_first(irq_data_get_effective_affinity_mask(data)); + msir =3D FIELD_GET(GENMASK(6, 4), data->hwirq); + frame =3D FIELD_GET(BIT(7), data->hwirq) << 3 | cpu; =20 -/* - * X-Gene v1 only has 16 MSI GIC IRQs for 2048 MSI vectors. To maintain - * the expected behaviour of .set_affinity for each MSI interrupt, the 16 - * MSI GIC IRQs are statically allocated to 8 X-Gene v1 cores (2 GIC IRQs - * for each core). The MSI vector is moved from 1 MSI GIC IRQ to another - * MSI GIC IRQ to steer its MSI interrupt to correct X-Gene v1 core. As a - * consequence, the total MSI vectors that X-Gene v1 supports will be - * reduced to 256 (2048/8) vectors. - */ -static int hwirq_to_cpu(unsigned long hwirq) -{ - return (hwirq % num_possible_cpus()); -} + target_addr =3D msi->msi_addr; + target_addr +=3D (FIELD_PREP(MSI_GROUP_MASK, frame) | + FIELD_PREP(MSI_INTR_MASK, msir)); =20 -static unsigned long hwirq_to_canonical_hwirq(unsigned long hwirq) -{ - return (hwirq - hwirq_to_cpu(hwirq)); + msg->address_hi =3D upper_32_bits(target_addr); + msg->address_lo =3D lower_32_bits(target_addr); + msg->data =3D data->hwirq & GENMASK(3, 0); } =20 static int xgene_msi_set_affinity(struct irq_data *irqdata, const struct cpumask *mask, bool force) { int target_cpu =3D cpumask_first(mask); - int curr_cpu; =20 - curr_cpu =3D hwirq_to_cpu(irqdata->hwirq); - if (curr_cpu =3D=3D target_cpu) - return IRQ_SET_MASK_OK_DONE; - - /* Update MSI number to target the new CPU */ - irqdata->hwirq =3D hwirq_to_canonical_hwirq(irqdata->hwirq) + target_cpu; + irq_data_update_effective_affinity(irqdata, cpumask_of(target_cpu)); =20 + /* Force the core code to regenerate the message */ return IRQ_SET_MASK_OK; } =20 @@ -173,23 +152,20 @@ static int xgene_irq_domain_alloc(struct irq_domain *= domain, unsigned int virq, unsigned int nr_irqs, void *args) { struct xgene_msi *msi =3D domain->host_data; - int msi_irq; + irq_hw_number_t hwirq; =20 mutex_lock(&msi->bitmap_lock); =20 - msi_irq =3D bitmap_find_next_zero_area(msi->bitmap, NR_MSI_VEC, 0, - num_possible_cpus(), 0); - if (msi_irq < NR_MSI_VEC) - bitmap_set(msi->bitmap, msi_irq, num_possible_cpus()); - else - msi_irq =3D -ENOSPC; + hwirq =3D find_first_zero_bit(msi->bitmap, NR_MSI_VEC); + if (hwirq < NR_MSI_VEC) + set_bit(hwirq, msi->bitmap); =20 mutex_unlock(&msi->bitmap_lock); =20 - if (msi_irq < 0) - return msi_irq; + if (hwirq >=3D NR_MSI_VEC) + return -ENOSPC; =20 - irq_domain_set_info(domain, virq, msi_irq, + irq_domain_set_info(domain, virq, hwirq, &xgene_msi_bottom_irq_chip, domain->host_data, handle_simple_irq, NULL, NULL); =20 @@ -201,12 +177,10 @@ static void xgene_irq_domain_free(struct irq_domain *= domain, { struct irq_data *d =3D irq_domain_get_irq_data(domain, virq); struct xgene_msi *msi =3D irq_data_get_irq_chip_data(d); - u32 hwirq; =20 mutex_lock(&msi->bitmap_lock); =20 - hwirq =3D hwirq_to_canonical_hwirq(d->hwirq); - bitmap_clear(msi->bitmap, hwirq, num_possible_cpus()); + clear_bit(d->hwirq, msi->bitmap); =20 mutex_unlock(&msi->bitmap_lock); =20 @@ -263,55 +237,33 @@ static void xgene_msi_isr(struct irq_desc *desc) unsigned int *irqp =3D irq_desc_get_handler_data(desc); struct irq_chip *chip =3D irq_desc_get_chip(desc); struct xgene_msi *xgene_msi =3D xgene_msi_ctrl; - int msir_index, msir_val, hw_irq, ret; - u32 intr_index, grp_select, msi_grp; + unsigned long grp_pending; + int msir_idx; + u32 msi_grp; =20 chained_irq_enter(chip, desc); =20 msi_grp =3D irqp - xgene_msi->gic_irq; =20 - /* - * MSIINTn (n is 0..F) indicates if there is a pending MSI interrupt - * If bit x of this register is set (x is 0..7), one or more interrupts - * corresponding to MSInIRx is set. - */ - grp_select =3D xgene_msi_int_read(xgene_msi, msi_grp); - while (grp_select) { - msir_index =3D ffs(grp_select) - 1; - /* - * Calculate MSInIRx address to read to check for interrupts - * (refer to termination address and data assignment - * described in xgene_compose_msi_msg() ) - */ - msir_val =3D xgene_msi_ir_read(xgene_msi, msi_grp, msir_index); - while (msir_val) { - intr_index =3D ffs(msir_val) - 1; - /* - * Calculate MSI vector number (refer to the termination - * address and data assignment described in - * xgene_compose_msi_msg function) - */ - hw_irq =3D (((msir_index * IRQS_PER_IDX) + intr_index) * - NR_HW_IRQS) + msi_grp; - /* - * As we have multiple hw_irq that maps to single MSI, - * always look up the virq using the hw_irq as seen from - * CPU0 - */ - hw_irq =3D hwirq_to_canonical_hwirq(hw_irq); - ret =3D generic_handle_domain_irq(xgene_msi->inner_domain, hw_irq); + grp_pending =3D xgene_msi_int_read(xgene_msi, msi_grp); + + for_each_set_bit(msir_idx, &grp_pending, IDX_PER_GROUP) { + unsigned long msir; + int intr_idx; + + msir =3D xgene_msi_ir_read(xgene_msi, msi_grp, msir_idx); + + for_each_set_bit(intr_idx, &msir, IRQS_PER_IDX) { + irq_hw_number_t hwirq; + int ret; + + hwirq =3D ((FIELD_GET(BIT(3), msi_grp) << 7) | + (msir_idx << 4) | + intr_idx); + + ret =3D generic_handle_domain_irq(xgene_msi->inner_domain, + hwirq); WARN_ON_ONCE(ret); - msir_val &=3D ~(1 << intr_index); - } - grp_select &=3D ~(1 << msir_index); - - if (!grp_select) { - /* - * We handled all interrupts happened in this group, - * resample this group MSI_INTx register in case - * something else has been made pending in the meantime - */ - grp_select =3D xgene_msi_int_read(xgene_msi, msi_grp); } } =20 --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 707B52882B6; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; cv=none; b=RHGUb+ssnaeCLL6uClv6F+AqTCm2h+oCbR3GPDE4zOQ4OBWFyW14Ts7mR1Efd3ELoiEEUdrqFnaOvcmtLU24MuT/UqGdPE7Gc8Pq5rrQN8aCgvwhyr7CZXXS9DJBkxJ29wY6+WU8RA9enMc1ImFivGRCjLw5i0ykBtc9RzSYtn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; c=relaxed/simple; bh=7TKWmvcmwH8EPAgGzhd5SaoCtxIYJA2s5UD/FxVMb24=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d5tV5J4NxqCcCXX7UqvrqtVVoFKB4ZPcK+6QJhkRLsJ2B6NaAnRs8y1vTvWKCiEm9wEbAmiQ2xnFUkDHhqd3cSPvyzQI8PJamtV0ur3qNL7NtrZeedLWiEnolMZYTKGE/W+oOIVPnJQEhWqUu/p5Ia8JlG3XtMUA5IoOHJXccDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IbK2Lldp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IbK2Lldp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2DF0C4CEF7; Sat, 28 Jun 2025 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131830; bh=7TKWmvcmwH8EPAgGzhd5SaoCtxIYJA2s5UD/FxVMb24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbK2Lldpk+5feq9A359lTu/tVzT5DORZ+3NRgDVCNNuSAQOXg3by+CADp1by1l1LY nkb8nIyXxVy8iNAnXXCd95XqIPAsbeUohcI9bKtkNKixH/K+y2QglmjPNI6a8fBvZF zy15F684XQ75nuWhIQoZdvgFGcBaBIJ/VjLthGvCMWkTBaqJHUKibOrbwAvvehju9S blmBcaf6TbKYa8HG+tzoyDg3YXi0bHHEjwwzzGAjiUIYIYMQoP0+hUqx6Ef8cTRUrC R0k1ZUxkMhCEjaQhtvM/qHefylBFIRNmNT+H6c1siqyNY2Onq/VF1Ws56C9nEq6lfb WLuYJooE9+3Iw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNk-00AqZC-62; Sat, 28 Jun 2025 18:30:28 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 10/12] PCI: xgene-msi: Resend an MSI racing with itself on a different CPU Date: Sat, 28 Jun 2025 18:30:03 +0100 Message-Id: <20250628173005.445013-11-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Since changing the affinity of an MSI really is about changing the target address and that it isn't possible to mask an individual MSI, it is completely possible for an interrupt to race with itself, usually resulting in a lost interrupt. Paper over the design blunder by informing the core code of this sad state of affair. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index fbfdc80942596..f797ba0524783 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -168,6 +168,7 @@ static int xgene_irq_domain_alloc(struct irq_domain *do= main, unsigned int virq, irq_domain_set_info(domain, virq, hwirq, &xgene_msi_bottom_irq_chip, domain->host_data, handle_simple_irq, NULL, NULL); + irqd_set_resend_when_in_progress(irq_get_irq_data(virq)); =20 return 0; } --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FA5D2882BB; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; cv=none; b=NGCueiEWYKkYYgSaUD0IMrwV2i3Mnnf5wXIr6l/fZ2Z9ptH/CNL+ojXcAX2OyftCGIsVeehh+2DLp3Rz33aBi9OkMjuw0k1JWIG+NfcGvaXfKfFhK6UoZmI3qU7/h1zt5YQMlgJpAx8zy8hFGzi7MUcEqF/8nK3pdKaB57rxyfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; c=relaxed/simple; bh=+GYSKd8aIM8xo28+bC9TFYEOVhobRPsyzp0tu6Fgk3o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gzmI4xSmfxVmpEB0Yvd3MnutEZtcThJj89Wng0YhZYBXWcHuU9+yQTPrbqjrYWGggcbQt1Cxsz5xXHFSrVcNs3ml8g6kp/kjDkEqn7YX2xj35cotdUDhRU2g93RzJZLh6j/H/TZIfEHX41CmttWtFVUyJThn5jw48Xsturyfs10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bjRiiX2y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bjRiiX2y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 610A2C4CEF4; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131830; bh=+GYSKd8aIM8xo28+bC9TFYEOVhobRPsyzp0tu6Fgk3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjRiiX2ytUjhCedtYc9Qd1lJMVXPsynbsX2z5LJR+xNHvTUh0thKE5RKQRMp3jbSN UkZKBJBsVKPWnTJlfEObly4mf5qol55dPg+NUaCeUiKLspMA1oaJfLyJ9YK0qds+sT Ka86SdsZMimLOzbYkiB0LnngAzY21dAGFSYQmveNP1FdEkAzN7hpb9fW0EuuIlACrg 0VB6sQFN7iAy3V8mHby0jnQnTqmZv2IRzar/dG3U/+t8C77Gs88bMO8U/Fl5224+P6 15RkI7XBhPP1m5b2Js8DbTBgFT1+JuOaqIU3mt/omJsP02/BMa+eUoiY4pZegWVEMM 4O6ZSZK2eLV5Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNk-00AqZC-DX; Sat, 28 Jun 2025 18:30:28 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 11/12] PCI: xgene-msi: Probe as a standard platform driver Date: Sat, 28 Jun 2025 18:30:04 +0100 Message-Id: <20250628173005.445013-12-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Now that we have made the dependedncy between the PCI driver and the MSI driver explicit, there is no need to use subsys_initcall() as a probing hook, and we can rely on builtin_platform_driver() instead. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index f797ba0524783..a22a6df7808c7 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -419,9 +419,4 @@ static struct platform_driver xgene_msi_driver =3D { .probe =3D xgene_msi_probe, .remove =3D xgene_msi_remove, }; - -static int __init xgene_pcie_msi_init(void) -{ - return platform_driver_register(&xgene_msi_driver); -} -subsys_initcall(xgene_pcie_msi_init); +builtin_platform_driver(xgene_msi_driver); --=20 2.39.2 From nobody Wed Oct 8 10:56:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A333D2882D3; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; cv=none; b=nkAaolRmq65/QrQL6Xqdb1U1EAgRua73ux49zdcCEA0tKyWWtiIC9lzDpalW6/8aZ5nAimfPr51ZsQf/mVEEe1TdgGcIdaZs7Kj7fQKvcYobzKlaalMKMkZyj5a1dfCqeX1x7g67tBzoLR9cG03eMBcDQmyG3uJ3kphnf6knf1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751131830; c=relaxed/simple; bh=jcOz3x1eGlNJpjfPJye0zmL0BeEqCXJWFfQN+XE02XU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JxqJUbQ4Gky4seKkqwVEYa08YnSh5q34itKYGaiDplmdSrT+4Yqhy8pRmDpt0wyhScOB74owvFG+pGON34gXhDd2H8bFibbECFQ2mhUtFSOzl0UxZGk0TEsONt9g4+aB0lFwTX6IQxaOJ+P1Con8C+Fbn3Pe1RN6Z1+TK1dNX9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mnKHCbCw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mnKHCbCw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84042C4CEEF; Sat, 28 Jun 2025 17:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751131830; bh=jcOz3x1eGlNJpjfPJye0zmL0BeEqCXJWFfQN+XE02XU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mnKHCbCwtx3uTyrPjXJq80QwKbtrL4UBVIwHDOlOzCEalNs2fcMN/zjKeGHyukzkH 6GK/UycXynXKtjBy9cGYk/woCl3twg+6q0kGXyY+2eQ9K2tDKmBdG5ZE3oNZhDmdJ4 cYWKYL5QJwryutN3CoKVFWBMxGWFBD2tW3oFr0P8MCcoNIJbeZ8k2FTXnQgUtvmEKK OTd6QOKcNQ0X5vyH4lDEHTNN4iCexOemRzuFjEe34x/Uy9/Jx1Wpgk+Pi74FG9uT9d 7H6HImnXD7Ub+c7XjwRQIlr/NHXl5LCPaLs0BpeZWdvAqyz3gwyJJRr8zJJVJmcedU O9asPCiBVxPiA== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uVZNk-00AqZC-Lh; Sat, 28 Jun 2025 18:30:28 +0100 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Toan Le , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Thomas Gleixner Subject: [PATCH 12/12] PCI: xgene-msi: Restructure handler setup/teardown Date: Sat, 28 Jun 2025 18:30:05 +0100 Message-Id: <20250628173005.445013-13-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628173005.445013-1-maz@kernel.org> References: <20250628173005.445013-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, toan@os.amperecomputing.com, lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, tglx@linutronix.de X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Another utterly pointless aspect of the xgene-msi driver is that it is built around CPU hotplug. Which is quite amusing since this is one of the few arm64 platforms that, by construction, cannot do CPU hotplug in a supported way (no EL3, no PSCI, no luck). Drop the CPU hotplug nonsense and just setup the IRQs and handlers in a less overdesigned way, grouping things more logically in the process. Signed-off-by: Marc Zyngier --- drivers/pci/controller/pci-xgene-msi.c | 109 +++++++++---------------- 1 file changed, 37 insertions(+), 72 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controlle= r/pci-xgene-msi.c index a22a6df7808c7..9f05c2a12da94 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -216,12 +216,6 @@ static int xgene_allocate_domains(struct device_node *= node, return msi->inner_domain ? 0 : -ENOMEM; } =20 -static void xgene_free_domains(struct xgene_msi *msi) -{ - if (msi->inner_domain) - irq_domain_remove(msi->inner_domain); -} - static int xgene_msi_init_allocator(struct device *dev) { xgene_msi_ctrl->bitmap =3D devm_bitmap_zalloc(dev, NR_MSI_VEC, GFP_KERNEL= ); @@ -271,26 +265,48 @@ static void xgene_msi_isr(struct irq_desc *desc) chained_irq_exit(chip, desc); } =20 -static enum cpuhp_state pci_xgene_online; - static void xgene_msi_remove(struct platform_device *pdev) { - struct xgene_msi *msi =3D platform_get_drvdata(pdev); - - if (pci_xgene_online) - cpuhp_remove_state(pci_xgene_online); - cpuhp_remove_state(CPUHP_PCI_XGENE_DEAD); + for (int i =3D 0; i < NR_HW_IRQS; i++) { + unsigned int irq =3D xgene_msi_ctrl->gic_irq[i]; + if (!irq) + continue; + irq_set_chained_handler_and_data(irq, NULL, NULL); + } =20 - xgene_free_domains(msi); + if (xgene_msi_ctrl->inner_domain) + irq_domain_remove(xgene_msi_ctrl->inner_domain); } =20 -static int xgene_msi_hwirq_alloc(unsigned int cpu) +static int xgene_msi_handler_setup(struct platform_device *pdev) { + struct xgene_msi *xgene_msi =3D xgene_msi_ctrl; int i; - int err; =20 - for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { - unsigned int irq =3D xgene_msi_ctrl->gic_irq[i]; + for (i =3D 0; i < NR_HW_IRQS; i++) { + u32 msi_val; + int irq, err; + + /* + * MSInIRx registers are read-to-clear; before registering + * interrupt handlers, read all of them to clear spurious + * interrupts that may occur before the driver is probed. + */ + for (int msi_idx =3D 0; msi_idx < IDX_PER_GROUP; msi_idx++) + xgene_msi_ir_read(xgene_msi, i, msi_idx); + + /* Read MSIINTn to confirm */ + msi_val =3D xgene_msi_int_read(xgene_msi, i); + if (msi_val) { + dev_err(&pdev->dev, "Failed to clear spurious IRQ\n"); + return EINVAL; + } + + irq =3D platform_get_irq(pdev, i); + if (irq < 0) + return irq; + + xgene_msi->gic_irq[i] =3D irq; =20 /* * Statically allocate MSI GIC IRQs to each CPU core. @@ -298,7 +314,7 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) * to each core. */ irq_set_status_flags(irq, IRQ_NO_BALANCING); - err =3D irq_set_affinity(irq, cpumask_of(cpu)); + err =3D irq_set_affinity(irq, cpumask_of(i % num_possible_cpus())); if (err) { pr_err("failed to set affinity for GIC IRQ"); return err; @@ -311,19 +327,6 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu) return 0; } =20 -static int xgene_msi_hwirq_free(unsigned int cpu) -{ - struct xgene_msi *msi =3D xgene_msi_ctrl; - int i; - - for (i =3D cpu; i < NR_HW_IRQS; i +=3D num_possible_cpus()) { - if (!msi->gic_irq[i]) - continue; - irq_set_chained_handler_and_data(msi->gic_irq[i], NULL, NULL); - } - return 0; -} - static const struct of_device_id xgene_msi_match_table[] =3D { {.compatible =3D "apm,xgene1-msi"}, {}, @@ -333,7 +336,6 @@ static int xgene_msi_probe(struct platform_device *pdev) { struct resource *res; struct xgene_msi *xgene_msi; - u32 msi_val, msi_idx; int rc; =20 xgene_msi_ctrl =3D devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl), @@ -343,8 +345,6 @@ static int xgene_msi_probe(struct platform_device *pdev) =20 xgene_msi =3D xgene_msi_ctrl; =20 - platform_set_drvdata(pdev, xgene_msi); - xgene_msi->msi_regs =3D devm_platform_get_and_ioremap_resource(pdev, 0, &= res); if (IS_ERR(xgene_msi->msi_regs)) { rc =3D PTR_ERR(xgene_msi->msi_regs); @@ -364,48 +364,13 @@ static int xgene_msi_probe(struct platform_device *pd= ev) goto error; } =20 - for (int irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { - rc =3D platform_get_irq(pdev, irq_index); - if (rc < 0) - goto error; - - xgene_msi->gic_irq[irq_index] =3D rc; - } - - /* - * MSInIRx registers are read-to-clear; before registering - * interrupt handlers, read all of them to clear spurious - * interrupts that may occur before the driver is probed. - */ - for (int irq_index =3D 0; irq_index < NR_HW_IRQS; irq_index++) { - for (msi_idx =3D 0; msi_idx < IDX_PER_GROUP; msi_idx++) - xgene_msi_ir_read(xgene_msi, irq_index, msi_idx); - - /* Read MSIINTn to confirm */ - msi_val =3D xgene_msi_int_read(xgene_msi, irq_index); - if (msi_val) { - dev_err(&pdev->dev, "Failed to clear spurious IRQ\n"); - rc =3D -EINVAL; - goto error; - } - } - - rc =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "pci/xgene:online", - xgene_msi_hwirq_alloc, NULL); - if (rc < 0) - goto err_cpuhp; - pci_xgene_online =3D rc; - rc =3D cpuhp_setup_state(CPUHP_PCI_XGENE_DEAD, "pci/xgene:dead", NULL, - xgene_msi_hwirq_free); + rc =3D xgene_msi_handler_setup(pdev); if (rc) - goto err_cpuhp; + goto error; =20 dev_info(&pdev->dev, "APM X-Gene PCIe MSI driver loaded\n"); =20 return 0; - -err_cpuhp: - dev_err(&pdev->dev, "failed to add CPU MSI notifier\n"); error: xgene_msi_remove(pdev); return rc; --=20 2.39.2