From patchwork Mon Jul 15 11:48:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13733360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EEEA1C3DA5D for ; Mon, 15 Jul 2024 11:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NXlhT+Pi1N/fknm4uXso0HjXFqpauI65jJVaFQcptgA=; b=ZqEAWPOHiANBp+bONTrUJ+s2Tf qlq1D/ZuogT/cUfBiML27FmyJoDo8R3+jSSUpAIf9SuX4kByzZrNqrTKUDxyzobDGzoz7jIoxy4Wn HhALuDqKQIDkmYZY3MY24/8+rcG4LvMaP/vbvPeKetK2o7MM7E9lKViTsBfGaQw0XpjMocpgDKN71 LdjFRK8IHfBRSVeCvZICUihUUnrppRBhi7YjYxCJ45TFoT/cRd5KA9NSEIHouC+UhcE5hHmqJwAN5 Gvufrj5htxBiYw3F8eaZLwtnxNlcwXlWQP9kkpRRmjybpPJYJJYWCeNFO+ITwAAPEmqvMcbn+qztW 6rw/n93A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTKD6-00000006v1P-0lXz; Mon, 15 Jul 2024 11:49:40 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTKCX-00000006um5-0tCf for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 11:49:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 73324CE0F8F; Mon, 15 Jul 2024 11:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26A51C4AF0E; Mon, 15 Jul 2024 11:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721044142; bh=r2ieMZY0t9B54SYvvKjLt4MeM8xUd6cfPZGUgzxbNn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bc5dQVNhD3YtuJRdD+xaqpyW8lWRStRcA/oL0c9wYaFW3LP2R3/VwS85r9TV7yy0L Bwi2DBGZ1N5ZaE0gCOy3EmHlNxJuZbrr3Gvbr1PctkJhTgEQHL5502j0UmJOdHpwFm FtLdHR8YvgKMZzFtKvokGod1erK+Acmxf7rgUDFa0qrhv/bzKkxiJjvWfiIgegVU3C z1slCbIMS3jp3miSPg5l9o3MGvdd8azxOFcP/FHvQ85nvHJwp57hUZg9ImDTkF80Z2 8QWhR7TyvPLcG9Xi82nGOTk+vAMxFAk73ZXrknAyDrYvyVgvZI8KgrrYvzeN7ltE03 YKDKesuVhNEAw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Thomas Gleixner , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Bjorn Helgaas , Andrew Lunn , Gregory Clement Cc: Thomas Petazzoni , Rob Herring , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Manivannan Sadhasivam , =?utf-8?q?Marek_B?= =?utf-8?q?eh=C3=BAn?= Subject: [PATCH v3 1/2] PCI: Add pci_remove_irq_domain() helper Date: Mon, 15 Jul 2024 13:48:53 +0200 Message-ID: <20240715114854.4792-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715114854.4792-1-kabel@kernel.org> References: <20240715114854.4792-1-kabel@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240715_044905_829347_D8D7AAA8 X-CRM114-Status: GOOD ( 15.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a helper function pci_remove_irq_domain() for disposing all interrupt mappings of an IRQ domain and then removing said IRQ domain. As explained in the attached link, the PCI INTX interrupt may be shared, and so the PCI device drivers do not dispose mapped interrupts when they are unbound from a device, since other devices may be still using those mapped interrupts. Thus the interrupts must be disposed by the PCI controller driver when the IRQ domain is being removed. This function may be used by PCI controller drivers that wish to be removable / modular. Link: https://lore.kernel.org/linux-pci/878qy5rrq7.ffs@tglx/ Signed-off-by: Marek Behún Reviewed-by: Manivannan Sadhasivam --- drivers/pci/irq.c | 21 +++++++++++++++++++++ drivers/pci/pci.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c index 4555630be9ec..30c8d930016a 100644 --- a/drivers/pci/irq.c +++ b/drivers/pci/irq.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "pci.h" @@ -259,6 +260,26 @@ bool pci_check_and_unmask_intx(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_check_and_unmask_intx); +#ifdef CONFIG_IRQ_DOMAIN +/** + * pci_remove_irq_domain - dispose all IRQ mappings and remove IRQ domain + * @domain: the IRQ domain to be removed + * + * Disposes all IRQ mappings of a given IRQ domain before removing the domain. + */ +void pci_remove_irq_domain(struct irq_domain *domain) +{ + for (irq_hw_number_t i = 0; i < domain->hwirq_max; i++) { + unsigned int virq = irq_find_mapping(domain, i); + + if (virq) + irq_dispose_mapping(virq); + } + + irq_domain_remove(domain); +} +#endif + /** * pcibios_penalize_isa_irq - penalize an ISA IRQ * @irq: ISA IRQ to penalize diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fd44565c4756..1ba6a6f418ac 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -170,6 +170,13 @@ void pci_no_msi(void); static inline void pci_no_msi(void) { } #endif +struct irq_domain; +#ifdef CONFIG_IRQ_DOMAIN +void pci_remove_irq_domain(struct irq_domain *domain); +#else +static inline void pci_remove_irq_domain(struct irq_domain *domain) { } +#endif + void pci_realloc_get_opt(char *); static inline int pci_no_d1d2(struct pci_dev *dev) From patchwork Mon Jul 15 11:48:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13733361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2FE0DC3DA5D for ; Mon, 15 Jul 2024 11:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qFB60JuoUpWfQd++e659onwDWqNLZDHWnNExsiEMQdM=; b=K6eylMu2ERu2YHtAdb6WD0358d 1WFYChKZ5VglvuPADYidoic2mncq3+yhWrMNUFdDeP/9UbJBVlPhNQRl1mVJPagyEqqeP/hNylric +H2hQtfy1fWlGzkSL/QkhKvbu/iwQt/pZrY/7xn37147Wc5zGEpjy42T/Ld6qF7QHVjZBs2OPg5rQ KnanclLpmukFNHVuJsuYW2kFHKnRZROqfzouFzjxo6SyIlP0P/cIJnY1jr7B3+he9VDFw9HO8xVm+ 2VOZ8qvZsLaye3QZvwpeqeF4N1WP/4DBSEobI+cWnklFyTBBVkpUQS4J2FFFejaGMB6jTydQ5Js/p zN8NneAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTKDN-00000006vAE-2zYL; Mon, 15 Jul 2024 11:49:57 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTKCY-00000006unX-3NAA for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 11:49:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 228A160DFD; Mon, 15 Jul 2024 11:49:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B0D2C4AF10; Mon, 15 Jul 2024 11:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721044145; bh=GBWvRjJ6Uyft1k+kSz5hldpNuIiPrjwuJYXhdOBdovA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EhS6XZKXwXzsjtqjy/rJaeb44sU681IzCcpp0DwpeVIAEGtX2j1axs8+3kGfSqN8C GEVA7dcOlqc/DzC8FL9g/VrntK6pP6S+6IjgZypPlgoRke6TOJQnFxfh6zLLlFpr0f hsnoUgXfT0mVw6e7biUQxB4ZJtxsii0LX0it9W9txkZtsUxHyXN4LryI35wcW30uv8 XxvWSgds8nxXfzwBgb/fPzh9Zjlm+AIaMhJAMPGEysPQ8A5HgMcxjBX0IdO4/T4HOY 0Q0lR2hCea/E7YVgCrm2eryS84RlnsUsxg9Fx/wLnlxHJu5hLdmh4lWJAZR3ly5hPs YvfAVtVJtRBOg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Thomas Gleixner , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Bjorn Helgaas , Andrew Lunn , Gregory Clement Cc: Thomas Petazzoni , Rob Herring , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Manivannan Sadhasivam , =?utf-8?q?Marek_B?= =?utf-8?q?eh=C3=BAn?= Subject: [PATCH v3 2/2] PCI: mvebu: Dispose INTx IRQs before to removing INTx domain Date: Mon, 15 Jul 2024 13:48:54 +0200 Message-ID: <20240715114854.4792-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715114854.4792-1-kabel@kernel.org> References: <20240715114854.4792-1-kabel@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240715_044906_937531_5FEA8ED5 X-CRM114-Status: GOOD ( 15.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Pali Rohár The documentation for the irq_domain_remove() function says that all mappings within the IRQ domain must be disposed before the domain is removed. Use the new helper function pci_remove_irq_domain() that also disposes all IRQ mappings of a IRQ domain before removing sait domain. Currently, the INTx IRQs are not disposed in pci-mvebu driver .remove() method, which causes the kernel to crash when unloading the driver and then reading /sys/kernel/debug/irq/irqs/ or /proc/interrupts. Unmapping of the IRQs at this point of the .remove() method is safe, since the PCIe bus is already unregistered, and all its devices are unbound from their drivers and removed. If there was indeed any remaining use of PCIe resources, then it would mean that PCIe hotplug code is broken, and we have bigger problems. Fixes: ec075262648f ("PCI: mvebu: Implement support for legacy INTx interrupts") Reported-by: Hajo Noerenberg Signed-off-by: Pali Rohár Reviewed-by: Marek Behún [ Marek: refactored a little, added more explanation to commit message ] Signed-off-by: Marek Behún Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/pci-mvebu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 29fe09c99e7d..590f121bd91a 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -1684,7 +1684,7 @@ static void mvebu_pcie_remove(struct platform_device *pdev) /* Remove IRQ domains. */ if (port->intx_irq_domain) - irq_domain_remove(port->intx_irq_domain); + pci_remove_irq_domain(port->intx_irq_domain); /* Free config space for emulated root bridge. */ pci_bridge_emul_cleanup(&port->bridge);