Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port()
Date: Sun, 06 Dec 2026 10:16:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-252345@kernel.org> (raw)
In-Reply-To: <20261206094043.971494-2-rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] PCI: pcibios_reset_secondary_bus() saves disabled AER IRQs in
  aer_root_reset()
- [Medium] PCI: PCI_ROOT_PORT_RESET_FAILED not coordinated with PCI PM
  suspend/resume
--

commit 3776a7bbc2b39db00bec4a17b5f8dc535b61e321
Author: Rosen Penev <rosenp@gmail.com>

PCI: Save Root Port state before resetting it with reset_root_port()

This commit saves the Root Port's config space before calling
host->reset_root_port() in pcibios_reset_secondary_bus(), and tracks
failed resets with PCI_ROOT_PORT_RESET_FAILED so a retry does not
overwrite the previously saved state.

> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index e2607cc84ff1c..66ed89142a655 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);

[Severity: Medium]
Can pci_save_state() here capture disabled AER interrupts when called from
aer_root_reset()?

aer_root_reset() calls aer_disable_irq() to clear ROOT_PORT_INTR_ON_MESG_MASK
in PCI_ERR_ROOT_COMMAND before calling pci_bus_error_reset(), and only
re-enables it afterward.  pci_save_state() -> pci_save_aer_state() saves
that cleared register value.

If host->reset_root_port() fails, PCI_ROOT_PORT_RESET_FAILED keeps that
saved state while aer_root_reset() re-enables AER interrupts in hardware.
A later successful non-AER reset (such as pci_reset_function()) then skips
pci_save_state() and restores it, leaving AER interrupts disabled.

>  		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);
> +		}

[Severity: Medium]
Should PCI_ROOT_PORT_RESET_FAILED also be coordinated with PCI PM
suspend and resume paths?

pci_pm_runtime_suspend() and pci_pm_suspend() clear state_saved and call
pci_save_state() without checking this flag.  If host->reset_root_port()
left the port with clocks off, those config-space reads can abort; if it
left reset defaults, they overwrite the saved state a retry will restore.

Conversely, this flag is only cleared when a later reset succeeds.  If
reset_root_port() fails before touching hardware (such as
qcom_pcie_reset_root_port() timing out on flush completion) or the port
recovers via system suspend/resume, the flag stays set.

The next reset then skips pci_save_state() and restores stale config
space, clobbering newer bridge settings such as memory decoding and bus
mastering for downstream devices.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206094043.971494-1-rosenp@gmail.com?part=1

  reply	other threads:[~2026-12-06 10:16 UTC|newest]

Thread overview: 7+ 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 ` [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port() Rosen Penev
2026-12-06 10:16   ` sashiko-bot [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
2026-12-06  9:58   ` sashiko-bot
2026-12-06 10:16 ` [PATCH v2 0/3] " sashiko-bot

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=sashiko-outbox-252345@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rosenp@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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