Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Pali Rohár" <pali@kernel.org>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Frank Li" <Frank.Li@nxp.com>
Cc: Rob Herring <robh@kernel.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port()
Date: Sun,  6 Dec 2026 01:40:31 -0800	[thread overview]
Message-ID: <20261206094043.971494-2-rosenp@gmail.com> (raw)
In-Reply-To: <20261206094043.971494-1-rosenp@gmail.com>

pcibios_reset_secondary_bus() restores the Root Port's config space after
host->reset_root_port(), but doesn't save it first, so it restores
whatever was saved last. For a Root Port that is the state saved when
portdrv probed it, before a device below it was enabled, which turns
memory decoding and bus mastering of the port off again: a function
reset of the device through its parent bus (e.g. pci_reset_function()
on a device whose only reset method is "bus") leaves the device
unreachable.

Save the Root Port's state right before resetting it. If a reset fails,
don't save again on the next attempt: the port may be left with reset
defaults (e.g. cleared bridge windows) that a successful retry would then
restore, or with its clocks off, where reading its config space can abort.
Keep the state saved before the failed reset instead.

Fixes: 3fc686d550f6 ("PCI/ERR: Add support for resetting the Root Ports in a platform-specific way")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/pci/pci.c | 16 ++++++++++++++--
 drivers/pci/pci.h |  1 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e2607cc84ff1..66ed89142a65 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5100,11 +5100,23 @@ void __weak pcibios_reset_secondary_bus(struct pci_dev *dev)
 	int ret;
 
 	if (pci_is_root_bus(dev->bus) && host->reset_root_port) {
+		/*
+		 * The state saved when the port was enumerated or probed may
+		 * predate changes made since, e.g. memory decoding enabled
+		 * once a device below the port was enabled.  After a failed
+		 * reset, keep the state saved before it instead: the port may
+		 * be left with reset defaults or with its clocks off.
+		 */
+		if (!test_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags))
+			pci_save_state(dev);
 		ret = host->reset_root_port(host, dev);
-		if (ret)
+		if (ret) {
+			set_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags);
 			pci_err(dev, "Failed to reset Root Port: %d\n", ret);
-		else
+		} else {
+			clear_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags);
 			pci_restore_state(dev);
+		}
 
 		return;
 	}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 202c52c0a83b..972ca609458b 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -825,6 +825,7 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
 #define PCI_LINK_CHANGING 5
 #define PCI_LINK_LBMS_SEEN	6
 #define PCI_DEV_ALLOW_BINDING 7
+#define PCI_ROOT_PORT_RESET_FAILED 8
 
 static inline void pci_dev_assign_added(struct pci_dev *dev)
 {
-- 
2.56.1



  reply	other threads:[~2026-12-06  9:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  9:40 [PATCH v2 0/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
2026-12-06  9:40 ` Rosen Penev [this message]
2026-12-06  9:40 ` [PATCH v2 2/3] PCI: Export pci_reset_secondary_bus() Rosen Penev
2026-12-06  9:40 ` [PATCH v2 3/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206094043.971494-2-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    --cc=pali@kernel.org \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox