On Mon, Oct 28, 2024 at 7:58 PM Marek Vasut <marex@xxxxxxx> wrote: > > On 10/28/24 6:52 PM, Wysocki, Rafael J wrote: > > On 10/26/2024 2:19 AM, Marek Vasut wrote: > >> On 10/13/24 1:03 PM, Lukas Wunner wrote: > >>> On Sat, Oct 12, 2024 at 02:48:48AM +0200, Marek Vasut wrote: > >>>> The pci_host_probe() does reallocate BARs for devices which start up > >>>> with > >>>> uninitialized BAR addresses set to 0 by calling > >>>> pci_bus_assign_resources(), > >>>> which updates the device config space content. > >>>> > >>>> At the same time, pci_pm_runtime_suspend() triggers pci_save_state() > >>>> for > >>>> all devices which do not have drivers assigned to them to store current > >>>> content of their config space registers. > > > > What exactly do you mean by "at the same time"? > I mean these two blocks of code run in parallel and likely race each other. Which two blocks of code? I'm guessing one of them is pci_host_probe() and what's the other? Unbound PCI devices have their PM-runtime usage counters incremented at init time; see pci_pm_init(). This can be undone by user space if it changes their /sys/devices/.../power/control attributes to "auto", but in that case the device will be suspended immediately from control_store(). If pci_host_probe() can race against this (and it looks like it can from your problem description), it needs to call pm_runtime_get_sync() on each PCI device before accessing its registers.