PCI: imx6: install the fault handler only if we are really running on a compatible device
Message ID | aa1c18c70bea1d6f99c88027dc72c700e8c309a2.1677573834.git.hns@goldelico.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2898133wrd; Tue, 28 Feb 2023 00:56:32 -0800 (PST) X-Google-Smtp-Source: AK7set+sraX2GTzI3zfXEzy2Zb0963AJ9P78+TZIu7za5wXSRH3BACTs4gXybfs8/DPH06TQxaSN X-Received: by 2002:a05:6a20:ba9f:b0:cc:7c25:2e1c with SMTP id fb31-20020a056a20ba9f00b000cc7c252e1cmr2227406pzb.13.1677574592686; Tue, 28 Feb 2023 00:56:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677574592; cv=pass; d=google.com; s=arc-20160816; b=iTM8evGqmH9npQK+fXDnzcDWLznPIBkyNhGOtDFAwUVBNbeOR8Um0eW4JkuxrCpFa8 pCaiqUxMjl7SD8Mto0mENtT6ZZL8zJYTwElQIbJHs8wO/owIcGnwn5gP7Atre64N9Pw7 ty/+6tHk5bSa9IZ3HtgangAtR+JQWJyFWupjJeUmyWRMhfyyXBfOXL+ff6Rw268LuZsi pR6jefS63dN26/nGAM6xgSBI0CY9vNi6AOczd/+Pf5ZdHBN6TOFXOITiwEgcQdyJIIhP QB3Ob2UoJNHxN4G6F8YcfHMJw/218+UcZCOfrVW5dYQbDUJaVi5ppLVlgWVJDIjgICvh ZCKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+UOfEgqD4oRECTcBuUsff3LMCbW6CRcg0WZi4nlmdjY=; b=OzKtsw47JwmC7HXZ4pqlw12TG/4kXUnWLaJNrju5ZbUd9bsN8Q3idKEEA3AA5uBgyY EX+Q7U9hWWbxN0IToke7mIu4gZMi3+yT4cxN0+Q4ts/3LfVwlp6KbmnJ74UZWY6+Wqj/ bXOEcBaaGDS14j1VyPiPiawzhEJLCnSlzKfiPrd74ZFlRab2pcP6fSV2ME3ptK9yFcI5 C+d9uXfJGOJYJO51uatMk6aK9SGnBjLo9lui3pkhQF1fm8kpHhWXr9w90kMQ4u/JDYVT 6fJxHmJ94fETILRvFWLlUDfWK5UH2Zjk14/WtC+5LTbtEWNAL7Ghb1BFc85yl3OJIiJ3 lMNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@goldelico.com header.s=strato-dkim-0002 header.b=ZMvzHtkk; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a056a00194d00b005a8e948561fsi10110542pfk.2.2023.02.28.00.56.19; Tue, 28 Feb 2023 00:56:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@goldelico.com header.s=strato-dkim-0002 header.b=ZMvzHtkk; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231249AbjB1IsR (ORCPT <rfc822;brysonjbanks@gmail.com> + 99 others); Tue, 28 Feb 2023 03:48:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjB1Irq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Feb 2023 03:47:46 -0500 X-Greylist: delayed 84 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 28 Feb 2023 00:46:57 PST Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208BAE384; Tue, 28 Feb 2023 00:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677573839; cv=none; d=strato.com; s=strato-dkim-0002; b=rOKZ7uBdwo9kpAIdNPYWTbYHefAzEZqlUWZRLguaN7uns1UccaGIoj3GplAnjp/74p Pf62+PlxRaCbPyM+fFispC5cxJqVpdfKLQ7a43+LEQW4i9L+2p9uglhZ/XH4ckQA9Ks9 /ACVaupsE2+Hc0UlqFeABliH6yCJvjgnVmC2ZXnTIdB/hLCupxVDjmKIEeEjNqPOczuz b2bwgl+x2ZRM1D30nBR07iF85BZOfcDaMQTgPcshtaweL/39hIhcAFjEl8E0CmDzscG/ we83p9ajoXHDKTgmQkODmTZ3Zo/vwsjr1qm1mKma8uiHpcdh7JcZ/LrUTQAsawVAxeBX Sleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1677573839; s=strato-dkim-0002; d=strato.com; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=+UOfEgqD4oRECTcBuUsff3LMCbW6CRcg0WZi4nlmdjY=; b=hVF4rS/JTgW6RdRiLEt9JLl84hg3WvsRe8OENPW0oVwovL5qYDzu16Pqds0ibMdFfY OmKHIKhB28cKXl/lnYZtr5SzN7jWiIbqQdGAJlhBqxVqoIna15ipAHrFKOCtyy8TSNLa 22u5zRggv1xrQyXmBJ8BRK02EkoiDC/hdSyLqiFns1NEPNWAgVxFdw5x55iydt2c6VdF PNDcPi8DJbX36xuVS9WIdnG8pYr0HuKhe1Rs6iaVYKN8xRTOp9+RYu+3NMrrdjX7fxHG A8/v/aySHyMmEc8BE/w8v4LCC6sehSEXaknMaGmwHYGPuhQ81pBEKFsDTWWx6xW7dCQ7 kpuQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1677573839; s=strato-dkim-0002; d=goldelico.com; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=+UOfEgqD4oRECTcBuUsff3LMCbW6CRcg0WZi4nlmdjY=; b=ZMvzHtkkoGoX5RBqQb3PCk8sE3XFgErKKNaK0Euk60E8jBJASOrSO3SwrO8icbpZ1q Rn7KOTq3ui9U/EgvRDQsP5dwkFWp3QOY+RoAIQGdfQMpJ+A44qERdxGifM6Pd5o5yDVD gaKj1jUMoIRsXgrCbpEzD7xmSKyM4ltAPbXHPAVtLRF0LxUDsHCLRwPykTM+Pn+2yQ5Y l83Pp9IAu5LsyC9kQS0GXW0eUDXdtpdj5r7ngLuv2VQAHPKewBmVzeSJdYnfxtf7Cra5 qjjrfaijARwvVb1Uk2uXS8hWBoY68RfNANcD1hN5Km5jRNpl+Oe9MygRxNjEKOdx8Sit pgWA== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o1iTDUhfN4hi3qVZrW/J" Received: from iMac.fritz.box by smtp.strato.de (RZmta 49.3.0 DYNA|AUTH) with ESMTPSA id 326d57z1S8htRev (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 28 Feb 2023 09:43:55 +0100 (CET) From: "H. Nikolaus Schaller" <hns@goldelico.com> To: Richard Zhu <hongxing.zhu@nxp.com>, Lucas Stach <l.stach@pengutronix.de>, Lorenzo Pieralisi <lpieralisi@kernel.org>, =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= <kw@linux.com>, Bjorn Helgaas <bhelgaas@google.com>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de> Cc: Rob Herring <robh@kernel.org>, Pengutronix Kernel Team <kernel@pengutronix.de>, Fabio Estevam <festevam@gmail.com>, NXP Linux Team <linux-imx@nxp.com>, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, letux-kernel@openphoenux.org, kernel@pyra-handheld.com, "H. Nikolaus Schaller" <hns@goldelico.com> Subject: [PATCH] PCI: imx6: install the fault handler only if we are really running on a compatible device Date: Tue, 28 Feb 2023 09:43:54 +0100 Message-Id: <aa1c18c70bea1d6f99c88027dc72c700e8c309a2.1677573834.git.hns@goldelico.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759064456273388810?= X-GMAIL-MSGID: =?utf-8?q?1759064456273388810?= |
Series |
PCI: imx6: install the fault handler only if we are really running on a compatible device
|
|
Commit Message
H. Nikolaus Schaller
Feb. 28, 2023, 8:43 a.m. UTC
commit bb38919ec56e ("PCI: imx6: Add support for i.MX6 PCIe controller")
added a fault hook to this driver in the probe function. So it was only
installed if needed.
commit bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO")
moved it from probe to driver init which installs the hook unconditionally
as soon as the driver is compiled into a kernel.
When this driver is compiled as a module, the hook is not registered
until after the driver has been matched with a .compatible and
loaded.
commit 415b6185c541 ("PCI: imx6: Fix config read timeout handling")
extended the fault handling code.
commit 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ")
added some protection for non-ARM architectures, but this does not
protect non-i.MX ARM architectures.
Since fault handlers can be triggered on any architecture for different
reasons, there is no guarantee that they will be triggered only for the
assumed situation, leading to improper error handling (i.MX6-specific
imx6q_pcie_abort_handler) on foreign systems.
I had seen strange L3 imprecise external abort messages several times on
OMAP4 and OMAP5 devices and couldn't make sense of them until I realized
they were related to this unused imx6q driver because I had
CONFIG_PCI_IMX6=y.
Note that CONFIG_PCI_IMX6=y is useful for kernel binaries that are designed
to run on different ARM SoC and be differentiated only by device tree
binaries. So turning off CONFIG_PCI_IMX6 is not a solution.
Therefore we check the compatible in the init function before registering
the fault handler.
Fixes: bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO")
Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling")
Fixes: 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ")
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/pci/controller/dwc/pci-imx6.c | 9 +++++++++
1 file changed, 9 insertions(+)
Comments
On Tue, Feb 28, 2023 at 09:43:54AM +0100, H. Nikolaus Schaller wrote: > commit bb38919ec56e ("PCI: imx6: Add support for i.MX6 PCIe controller") > added a fault hook to this driver in the probe function. So it was only > installed if needed. > > commit bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO") > moved it from probe to driver init which installs the hook unconditionally > as soon as the driver is compiled into a kernel. > > When this driver is compiled as a module, the hook is not registered > until after the driver has been matched with a .compatible and > loaded. > > commit 415b6185c541 ("PCI: imx6: Fix config read timeout handling") > extended the fault handling code. > > commit 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ") > added some protection for non-ARM architectures, but this does not > protect non-i.MX ARM architectures. Are *all* these commits relevant? Question also applies to Fixes: below. > Since fault handlers can be triggered on any architecture for different > reasons, there is no guarantee that they will be triggered only for the > assumed situation, leading to improper error handling (i.MX6-specific > imx6q_pcie_abort_handler) on foreign systems. > > I had seen strange L3 imprecise external abort messages several times on > OMAP4 and OMAP5 devices and couldn't make sense of them until I realized > they were related to this unused imx6q driver because I had > CONFIG_PCI_IMX6=y. Apparently imx6q_pcie_abort_handler() assumes it is always called because of a PCI abort? If so, that sounds problematic. If non-PCI imprecise aborts happen on OMAP4 and OMAP5 where imx6q is unused and imx6q_pcie_abort_handler() is not appropriate, I assume similar non-PCI aborts can also happen on systems where imx6q *is* used. So imx6q_pcie_abort_handler() may be trying to fixup non-PCI aborts when it shouldn't? > Note that CONFIG_PCI_IMX6=y is useful for kernel binaries that are designed > to run on different ARM SoC and be differentiated only by device tree > binaries. So turning off CONFIG_PCI_IMX6 is not a solution. > > Therefore we check the compatible in the init function before registering > the fault handler. > > Fixes: bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO") > Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling") > Fixes: 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ") > > Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> > --- > drivers/pci/controller/dwc/pci-imx6.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 1dde5c579edc8..89774aa187ae8 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -1402,6 +1402,15 @@ DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, > static int __init imx6_pcie_init(void) > { > #ifdef CONFIG_ARM > + const struct of_device_id *reboot_id; > + struct device_node *np; > + > + np = of_find_matching_node_and_match(NULL, imx6_pcie_of_match, > + &reboot_id); Since you don't need reboot_id, I think you should use of_find_matching_node() instead. > + if (!np) > + return -ENODEV; > + of_node_put(np); > + > /* > * Since probe() can be deferred we need to make sure that > * hook_fault_code is not called after __init memory is freed > -- > 2.38.1 >
Hi Bjorn, > Am 08.03.2023 um 19:49 schrieb Bjorn Helgaas <helgaas@kernel.org>: > > On Tue, Feb 28, 2023 at 09:43:54AM +0100, H. Nikolaus Schaller wrote: >> commit bb38919ec56e ("PCI: imx6: Add support for i.MX6 PCIe controller") >> added a fault hook to this driver in the probe function. So it was only >> installed if needed. >> >> commit bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO") >> moved it from probe to driver init which installs the hook unconditionally >> as soon as the driver is compiled into a kernel. >> >> When this driver is compiled as a module, the hook is not registered >> until after the driver has been matched with a .compatible and >> loaded. >> >> commit 415b6185c541 ("PCI: imx6: Fix config read timeout handling") >> extended the fault handling code. >> >> commit 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ") >> added some protection for non-ARM architectures, but this does not >> protect non-i.MX ARM architectures. > > Are *all* these commits relevant? Yes, it was correct when introduced by commit bb38919ec56e for a goo reason. And it was broken by bde4a5a00e76 an all attempts later made it worse. > Question also applies to Fixes: > below. It fixes all between bde4a5a00e76 and HEAD. Well, one can argue that commit bde4a5a00e76 could be sufficient for Fixes: I don't know if it is a problem because I have no overview over side-effects. > >> Since fault handlers can be triggered on any architecture for different >> reasons, there is no guarantee that they will be triggered only for the >> assumed situation, leading to improper error handling (i.MX6-specific >> imx6q_pcie_abort_handler) on foreign systems. >> >> I had seen strange L3 imprecise external abort messages several times on >> OMAP4 and OMAP5 devices and couldn't make sense of them until I realized >> they were related to this unused imx6q driver because I had >> CONFIG_PCI_IMX6=y. > > Apparently imx6q_pcie_abort_handler() assumes it is always called > because of a PCI abort? If so, that sounds problematic. > > If non-PCI imprecise aborts happen on OMAP4 and OMAP5 where imx6q is > unused and imx6q_pcie_abort_handler() is not appropriate, I assume > similar non-PCI aborts can also happen on systems where imx6q *is* > used. As far as I know the reasons why imprecise aborts occur may be SoC specific. So I have no experience with i.MX6 to judge this. My goal is to shield other architectures from this fault handler may it be correct or wrong. > So imx6q_pcie_abort_handler() may be trying to fixup non-PCI aborts > when it shouldn't? Yes, at least if it is triggered on OMAP4/OMAP5 by accessing non-existing registers in some subsystems (e.g. through devmem2). > >> Note that CONFIG_PCI_IMX6=y is useful for kernel binaries that are designed >> to run on different ARM SoC and be differentiated only by device tree >> binaries. So turning off CONFIG_PCI_IMX6 is not a solution. >> >> Therefore we check the compatible in the init function before registering >> the fault handler. >> >> Fixes: bde4a5a00e76 ("PCI: imx6: Allow probe deferral by reset GPIO") >> Fixes: 415b6185c541 ("PCI: imx6: Fix config read timeout handling") >> Fixes: 2d8ed461dbc9 ("PCI: imx6: Add support for i.MX8MQ") >> >> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> >> --- >> drivers/pci/controller/dwc/pci-imx6.c | 9 +++++++++ >> 1 file changed, 9 insertions(+) >> >> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c >> index 1dde5c579edc8..89774aa187ae8 100644 >> --- a/drivers/pci/controller/dwc/pci-imx6.c >> +++ b/drivers/pci/controller/dwc/pci-imx6.c >> @@ -1402,6 +1402,15 @@ DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, >> static int __init imx6_pcie_init(void) >> { >> #ifdef CONFIG_ARM >> + const struct of_device_id *reboot_id; >> + struct device_node *np; >> + >> + np = of_find_matching_node_and_match(NULL, imx6_pcie_of_match, >> + &reboot_id); > > Since you don't need reboot_id, I think you should use > of_find_matching_node() instead. Well, I used it for debugging, but for production code it has indeed no benefit. of_find_matching_node it is just a static inline wrapper for of_find_matching_node_and_match with NULL parameter, but we can save one stack position. I'll send a v2 soon. > >> + if (!np) >> + return -ENODEV; >> + of_node_put(np); >> + >> /* >> * Since probe() can be deferred we need to make sure that >> * hook_fault_code is not called after __init memory is freed >> -- >> 2.38.1 >> BR and thanks, Nikolaus
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 1dde5c579edc8..89774aa187ae8 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1402,6 +1402,15 @@ DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, static int __init imx6_pcie_init(void) { #ifdef CONFIG_ARM + const struct of_device_id *reboot_id; + struct device_node *np; + + np = of_find_matching_node_and_match(NULL, imx6_pcie_of_match, + &reboot_id); + if (!np) + return -ENODEV; + of_node_put(np); + /* * Since probe() can be deferred we need to make sure that * hook_fault_code is not called after __init memory is freed