Re: [PATCH v11 3/9] PCI: Avoid saving config space state if inaccessible

Bjorn Helgaas
2026-03-24T22:52:33Z

On Tue, Mar 24, 2026 at 03:38:33PM -0700, Farhan Ali wrote:
> On 3/24/2026 2:40 PM, Bjorn Helgaas wrote:
> > On Mon, Mar 16, 2026 at 12:15:38PM -0700, Farhan Ali wrote:
> > > The current reset process saves the device's config space state before
> > > reset and restores it afterward. However errors may occur unexpectedly and
> > > it may then be impossible to save config space because the device may be
> > > inaccessible (e.g. DPC) or config space may be corrupted. This results in
> > > saving corrupted values that get written back to the device during state
> > > restoration.

> > > + * If device's config space is inaccessible it can return ~0 for
> > > + * any reads. Since VFs can also return ~0 for Device and Vendor ID
> > > + * check Command and Status registers. At the very least we should
> > > + * avoid restoring config space for device with error bits set in
> > > + * Status register.
> > > + */
> > > + pci_read_config_dword(dev, PCI_COMMAND, &val);
> > > + if (PCI_POSSIBLE_ERROR(val)) {
> >
> > Obviously this is still racy because the device may become
> > inaccessible partway through saving the state, and it might be worth
> > acknowledging that in the comment. But I think this is an improvement
> > over what we do now.
>
> Yeah, makes sense. Will update the comment. How about something like:
>
> If device's config space is inaccessible it can return ~0 for
> any reads. Since VFs can also return ~0 for Device and Vendor ID
> check Command and Status registers. This can still be racy as a device
> can become inaccessible partway through saving the state, even after this
> check.

How about:

Note that this is racy because the device may become inaccessible
partway through saving the state.

It's not just "can still be racy"; it's *always* racy unless we detect
PCI errors on every access and recover from them.