Re: [PATCH v7 03/12] PCI: liveupdate: Track incoming preserved PCI devices
David Matlack <[email protected]> Mon, 20 Jul 2026 14:54:51 -0700
| Newsgroups | org.infradead.lists.kexec,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci,org.kvack.linux-mm |
|---|---|
| Message-ID | <CALzav=e1Gcu-9TD7F--41cYqKBrStKOE4VqQ4K3PKdNuYnNmcQ@mail.gmail.com> |
On Fri, Jul 17, 2026 at 2:47 PM Pasha Tatashin <[email protected]> wrote: > > On Fri, 10 Jul 2026 21:26:06 +0000, David Matlack <[email protected]> wrote: > > diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c > > index 03075ce06ac9..df6a02240aa4 100644 > > --- a/drivers/pci/liveupdate.c > > +++ b/drivers/pci/liveupdate.c > > @@ -298,6 +377,87 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev) > > [ ... skip 76 lines ... ] > > + /* > > + * Hold the ref on the incoming FLB until pci_liveupdate_finish() so > > + * that dev->liveupdate.incoming cannot get freed while the PCI core > > + * has a pointer to it. It's better to leak the incoming FLB than do a > > + * use-after-free if driver does not call pci_liveupdate_finish(). > > + */ > > I am confused by this. Each preserved PCI device must have an associated > FD preserved with it via LUO. I.e., vfiofd would need to be preserved. If > the vfiofd was not reclaimed, and finish is not possible, that vfiofd > would still be owned by LUO, and therefore PCI FLB refcount would stay > positive. > > However, if finish is possible, and this is the last vfiofd that is > finished, FLB will be freed as soon as the reference count reaches zero, > which I would think is the expected behavior. > > What is the point of holding a reference here, instead of only for the > duration of FLB access, i.e. to make sure we are accessing a valid data? The duration of the access is from here until pci_liveupdate_finish() because that it when the pointer (dev->liveupdate.incoming) is cleared. So that is why the PCI core holds the reference from here until pci_liveupdate_finish(). We could avoid this by deleteing dev->liveupdate.incoming and, instead, fetching the incoming FLB and doing the xarray lookup every atime the PCI core needs to access the device's incoming ser struct, but that would be inefficient.