On Tue, Jul 28, 2026 at 10:10:00PM +0000, David Matlack wrote:
> When a PCI device is preserved across a Live Update, all of its upstream
> bridges up to the root port must also be preserved. This enables the PCI
> core and any drivers bound to the bridges to manage bridges correctly
> across a Live Update.
> 
> Notably, this will be used in subsequent commits to ensure that
> preserved devices can continue performing memory transactions without a
> disruption or change in routing.
> 
> To preserve bridges, the PCI core tracks the number of downstream
> devices preserved under each bridge using a reference count in struct
> pci_dev_ser. This allows a bridge to remain preserved until all its
> downstream preserved devices are unpreserved or finish their
> participation in the Live Update.
> ...

> +static int pci_liveupdate_unpreserve_device(struct pci_flb_outgoing 
> *outgoing,
> +                                         struct pci_dev *dev)
>  {
>       struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing;
>  
>       if (!dev_ser) {
>               pci_warn(dev, "Cannot unpreserve device that is not 
> preserved\n");
> -             return;
> +             return -EINVAL;
> +     }
> +
> +     if (!dev_ser->refcount) {
> +             pci_WARN(dev, 1, "Preserved device has a 0 refcount!\n");
> +             return -EINVAL;
>       }
>  
> +     if (--dev_ser->refcount)
> +             return 0;

I guess this is a nit: I was looking for a dev_ser->refcount++ in this
patch to correspond with this decrement.  I *guess* the
"dev_ser->refcount = 1" in pci_liveupdate_preserve_device() starts
that, and the "dev->liveupdate.outgoing->refcount++" there is an
increment of the same refcount?  The connections there don't seem
quite obvious to me.

But I guess "dev_ser->refcount = 1" was added by a different patch, so
probably *not* the same?

>       pci_info(dev, "Device will no longer be preserved across next Live 
> Update\n");
>       outgoing->ser->nr_devices--;
>       memset(dev_ser, 0, sizeof(*dev_ser));
>       dev->liveupdate.outgoing = NULL;
> +     return 0;
> +}

> @@ -385,13 +418,23 @@ static int pci_liveupdate_preserve_device(struct 
> pci_flb_outgoing *outgoing,
>       }
>  
>       if (dev->liveupdate.outgoing) {
> -             pci_warn(dev, "Device is already preserved\n");
> -             return -EBUSY;
> -     }
> +             if (!dev->liveupdate.outgoing->refcount) {
> +                     pci_WARN(dev, 1, "Preserved device with 0 refcount!\n");
> +                     return -EINVAL;
> +             }
>  
> -     if (!pci_is_root_bus(dev->bus)) {
> -             pci_warn(dev, "Cannot preserve devices behind bridges\n");
> -             return -EINVAL;
> +             /*
> +              * Endpoint devices should not be preserved more than once.
> +              * Bridges are preserved once for every downstream device that
> +              * is preserved.
> +              */
> +             if (!dev->subordinate) {
> +                     pci_warn(dev, "Device is already preserved\n");
> +                     return -EBUSY;
> +             }
> +
> +             dev->liveupdate.outgoing->refcount++;
> +             return 0;
>       }
>  
>       dev_ser = pci_flb_alloc_dev_ser(outgoing);

Reply via email to