From: Farhan Ali <alifm@linux.ibm.com>
To: lirongqing <lirongqing@baidu.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Niklas Schnelle <schnelle@linux.ibm.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
Frank Li <Frank.Li@nxp.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: Only restore state that was successfully saved around a reset
Date: Tue, 10 Nov 2026 10:09:48 -0800 [thread overview]
Message-ID: <04e0b460-da19-458b-a042-753608e67c68@linux.ibm.com> (raw)
In-Reply-To: <20261110053348.2419-1-lirongqing@baidu.com>
Hi Li,
On 11/9/2026 9:33 PM, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> pci_dev_save_and_disable() returns early when config space is inaccessible,
> without saving anything, but pci_dev_restore() calls pci_restore_state()
> unconditionally and pci_restore_state() does not look at state_saved. After
> the reset makes config space accessible again, the all-zero or stale
> saved_config_space[] array is written back to the device, clearing Command,
> BARs and, for bridges, the bus number registers.
>
> Clear state_saved when the save is skipped and only restore when a state
> was saved.
We should always have a valid state of the device saved at enumeration
due to commit a2f1e22390ac ("PCI/ERR: Ensure error recoverability at all
times"). In pci_dev_save_disable(), if the device is inaccessible then
we want to avoid storing a state that can corrupt the device on restore.
Since we always have a valid state, we would restore to the last good state.
May I ask what device or driver do you hit this issue?
Thanks
Farhan
>
> Fixes: e18d1abc3bff ("PCI: Avoid saving config space state if inaccessible")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/pci/pci.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 67fe565..ddb86dd 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5156,8 +5156,10 @@ static void pci_dev_save_and_disable(struct pci_dev *dev)
> */
> pci_set_power_state(dev, PCI_D0);
>
> - if (!pci_dev_config_accessible(dev, "save state"))
> + if (!pci_dev_config_accessible(dev, "save state")) {
> + dev->state_saved = false;
> return;
> + }
>
> pci_save_state(dev);
> /*
> @@ -5175,7 +5177,8 @@ static void pci_dev_restore(struct pci_dev *dev)
> const struct pci_error_handlers *err_handler =
> dev->driver ? dev->driver->err_handler : NULL;
>
> - pci_restore_state(dev);
> + if (dev->state_saved)
> + pci_restore_state(dev);
>
> /*
> * dev->driver->err_handler->reset_done() is protected against
prev parent reply other threads:[~2026-11-10 18:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 5:33 lirongqing
2026-11-10 5:33 ` [PATCH] PCI: Save the Root Port state before a platform-specific reset lirongqing
2026-11-10 10:16 ` Lukas Wunner
2026-11-10 10:13 ` [PATCH] PCI: Only restore state that was successfully saved around a reset Lukas Wunner
2026-11-10 18:09 ` Farhan Ali [this message]
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=04e0b460-da19-458b-a042-753608e67c68@linux.ibm.com \
--to=alifm@linux.ibm.com \
--cc=Frank.Li@nxp.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=manivannan.sadhasivam@oss.qualcomm.com \
--cc=schnelle@linux.ibm.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
all inboxes | Powered by JetHome®