[PATCH] Documentation: PCI: Amend error recovery doc with pci_save_state() rules

Farhan Ali alifm at linux.ibm.com
Sat Nov 22 05:57:24 AEDT 2025


Hi Lukas,

Thanks for the update to documentation.

On 11/21/2025 9:31 AM, Lukas Wunner wrote:
> After recovering from a PCI error through reset, affected devices are in
> D0_uninitialized state and need to be brought into D0_active state by
> re-initializing their Config Space registers (PCIe r7.0 sec 5.3.1.1).
>
> To facilitate that, the PCI core provides pci_restore_state() and
> pci_save_state() helpers.  Document rules governing their usage.
>
> As Bjorn notes, so far no file in "Documentation/ includes anything about
> the idea of a driver using pci_save_state() to capture the state it wants
> to restore after an error", even though it is a common pattern in drivers.
> So that's obviously a gap that should be closed.
>
> Reported-by: Bjorn Helgaas <helgaas at kernel.org>
> Closes: https://lore.kernel.org/r/20251113161556.GA2284238@bhelgaas/
> Signed-off-by: Lukas Wunner <lukas at wunner.de>
> ---
>   Documentation/PCI/pci-error-recovery.rst | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
>
> diff --git a/Documentation/PCI/pci-error-recovery.rst b/Documentation/PCI/pci-error-recovery.rst
> index 5df481a..43bc4e3 100644
> --- a/Documentation/PCI/pci-error-recovery.rst
> +++ b/Documentation/PCI/pci-error-recovery.rst
> @@ -326,6 +326,21 @@ be recovered, there is nothing more that can be done;  the platform
>   will typically report a "permanent failure" in such a case.  The
>   device will be considered "dead" in this case.
>   
> +Drivers typically need to call pci_restore_state() after reset to
> +re-initialize the device's config space registers and thereby
> +bring it from D0\ :sub:`uninitialized` into D0\ :sub:`active` state
> +(PCIe r7.0 sec 5.3.1.1).  The PCI core invokes pci_save_state()
> +on enumeration after initializing config space to ensure that a
> +saved state is available for subsequent error recovery.
> +Drivers which modify config space on probe may need to invoke
> +pci_save_state() afterwards to record those changes for later
> +error recovery.  When going into system suspend, pci_save_state()
> +is called for every PCI device and that state will be restored
> +not only on resume, but also on any subsequent error recovery.

Nit: Should we clarify in the above sentence on what calls the 
pci_save_state() when going into suspend? My assumption is the 
pci_save_state() is called by the PCI core and not the drivers?

> +In the unlikely event that the saved state recorded on suspend
> +is unsuitable for error recovery, drivers should call
> +pci_save_state() on resume.
> +

What should the PCI core do if the saved state recorded is bad? should 
we continue to restore the device with the recorded bad state? On s390 
restoring the device with the bad state can break the device put into 
error again.

Thanks

Farhan




More information about the Linuxppc-dev mailing list