From mboxrd@z Thu Jan 1 00:00:00 1970 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 CD683C982FD for ; Tue, 22 Sep 2026 02:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=cH0gCTdhbVMkhBFKmWQxKWj82iKCdJrEMLo+8O+B+jg=; b=DIbaRqh6/fvD+q Kdk+SKG02IYOor/pbxroRpVHSthd6upIN25oULv9Tod6sxGvsnDzF4nli92fv1JpU9bG9k8LUtZ5x uB//h1dtHX52hQEm25YEXzSpa8sJ6Pti+iStUzcJhsac6KCePm96hz5/yU1U0yHiXZZsBnlHf+WoE KtubCU25ax2fZnVHb8BRfy7AjWGKO6SaTOL70lJ8iwr9LKwrdu05MwAkY4Ml7Fqd8B9fVJpdDjaB9 7sLLkSpk4LseQVBvGEsubpGIEDTp1qyrtxXKX+YA2KMgAfE+7p9YS2c7NqEGMUD2HWQAe5s+OW6OI D2QocrCV6SQLOAo314uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8qNp-000000040St-2Iep; Tue, 22 Sep 2026 02:37:25 +0000 Received: from mail-m10195.netease.com ([154.81.10.195]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8qNl-000000040RP-13h6 for linux-rockchip@lists.infradead.org; Tue, 22 Sep 2026 02:37:24 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTP id 4ea70feac; Tue, 22 Sep 2026 10:37:17 +0800 (GMT+08:00) From: Shawn Lin To: Manivannan Sadhasivam , Bjorn Helgaas Cc: linux-rockchip@lists.infradead.org, linux-pci@vger.kernel.org, Niklas Cassel , Shawn Lin Subject: [PATCH v3 1/3] PCI: dw-rockchip: Move the INTx irq setup to probe Date: Tue, 22 Sep 2026 10:37:00 +0800 Message-Id: <1790044622-164744-2-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1790044622-164744-1-git-send-email-shawn.lin@rock-chips.com> References: <1790044622-164744-1-git-send-email-shawn.lin@rock-chips.com> X-HM-Tid: 0aa0c6f988a103a4kunm27853d20398d42 X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1kYFggdWUFKV1ktWUFJV1kPCRoVCBIfWUFZGRhKT1YZSx1JTxpCH0 MfSExWFRQJFhoXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0 tIVUpLSU9PT0hVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=FMn7tWTRdfgPQSSGSZuXQRHruNnb0qRgExH513sG/+O6Y8pS119SGLE2ZjeMu6/iI0mftG/wf7rg8lIrJu6QtFgPKGSihE+8TIhJFuM9M2dXvM3al0bTYI6fDvGGrwlYs0HjtxNWEAKVdO5AS2zrNHtriLYUXRfiVYNCgXgIJJA=; s=default; c=relaxed/relaxed; d=rock-chips.com; v=1; bh=n00Z4Jr5yae9rvhO7FKpm87YcHpUZxS8llu8J3/udT8=; h=date:mime-version:subject:message-id:from; X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260921_193721_522847_A062F3B7 X-CRM114-Status: GOOD ( 19.04 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Since commit b376b3ff9cb0 ("PCI: dw-rockchip: Implement .reset_root_port() and use for link down"), .reset_root_port() re-runs the host ops .init() callback to reprogram the Root Complex after a controller reset. That works for the register programming, but .init() is not re-entrant: it also creates the INTx irq domain and installs the chained INTx handler. Every root port reset therefore ends up with a second irq domain registered for the same fwnode: the previous one is leaked, as it is never removed, and worse, the INTx virqs of the downstream PCI devices were allocated in the previous irq domain and are never re-mapped, while the chained handler now looks up virqs in the new, empty domain. After a link down recovery, INTx interrupts are silently lost. Fix it by moving the of_irq_get_byname() lookup, the INTx irq domain creation and the chained handler installation out of .init() and into rockchip_pcie_configure_rc(), right after dw_pcie_host_init(). This mirrors how the qcom driver requests its global IRQ, and leaves .init() with nothing but idempotent register programming, so both .reset_root_port() and dw_pcie_resume_noirq() can safely re-run it. Re-running of_irq_get_byname() on every resume is also gone. rockchip_pcie_configure_rc() can abort probe, so propagate the irq domain creation error instead of only logging it as .init() used to do. Fixes: b376b3ff9cb0 ("PCI: dw-rockchip: Implement .reset_root_port() and use for link down") Suggested-by: Niklas Cassel Signed-off-by: Shawn Lin --- Changes in v3: - split devm-managed part into a seperate patch Changes in v2: - Moved the of_irq_get_byname() lookup, the INTx irq domain creation and the chained handler installation out of the host ops .init() callback into rockchip_pcie_configure_rc(), right after dw_pcie_host_init(), as suggested by Niklas Cassel. This supersedes v1 patch 1/2, as .init() no longer creates the irq domain, and removes the rockchip_pcie_host_hw_init() helper from v1. - Made the INTx irq domain devm-managed with devm_irq_domain_instantiate() and uninstall the chained handler through a devres action, addressing the probe failure leak and use-after-free flagged by the Sashiko review. drivers/pci/controller/dwc/pcie-dw-rockchip.c | 32 +++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c index 1497686..8788a10 100644 --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c @@ -422,23 +422,9 @@ static void rockchip_pcie_stop_link(struct dw_pcie *pci) static int rockchip_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); - struct rockchip_pcie *rockchip = to_rockchip_pcie(pci); - struct device *dev = rockchip->pci.dev; - int irq, ret; - - irq = of_irq_get_byname(dev->of_node, "legacy"); - if (irq < 0) - return irq; pci->dbi_base2 = pci->dbi_base + PCIE_TYPE0_HDR_DBI2_OFFSET; - ret = rockchip_pcie_init_irq_domain(rockchip); - if (ret < 0) - dev_err(dev, "failed to init irq domain\n"); - - irq_set_chained_handler_and_data(irq, rockchip_pcie_intx_handler, - rockchip); - rockchip_pcie_configure_l1ss(pci); rockchip_pcie_enable_l0s(pci); pp->bridge->reset_root_port = rockchip_pcie_rc_reset_root_port; @@ -740,6 +726,24 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev, return ret; } + /* + * This is done here instead of in the host ops .init() callback, + * which is also re-run by .reset_root_port(), so that the INTx irq + * domain is only created once, at probe time. + */ + irq = of_irq_get_byname(dev->of_node, "legacy"); + if (irq < 0) + return irq; + + ret = rockchip_pcie_init_irq_domain(rockchip); + if (ret < 0) { + dev_err(dev, "failed to init irq domain\n"); + return ret; + } + + irq_set_chained_handler_and_data(irq, rockchip_pcie_intx_handler, + rockchip); + /* unmask hot reset/link-down reset */ val = FIELD_PREP_WM16(PCIE_LINK_REQ_RST_NOT_INT, 0); rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_INTR_MASK_MISC); -- 2.7.4 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip