Re: [PATCH 1/2] liveupdate: Reference count outgoing FLB data

From: David Matlack

Date: Tue Jun 02 2026 - 13:38:50 EST


On 2026-06-02 07:15 PM, Pratyush Yadav wrote:
> Hi David,
>
> On Thu, May 28 2026, David Matlack wrote:
>
> > Increment the outgoing FLB refcount in liveupdate_flb_get_outgoing() so
> > that the FLB structure cannot be freed while the caller is actively
> > using it. Add an additional liveupdate_flb_put_outgoing() function so
> > the caller can explicitly indicate when it is done using the outgoing
> > FLB.
> >
> > During a Live Update, the kernel may need to fetch the outgoing FLB
> > outside of the scope of a file handler's preserve() and unpreserve()
> > callbacks. In that situation there is no way for the caller to protect
> > itself against the outgoing FLB from being freed while it is using it.
> > Incrementing the reference count in liveupdate_flb_get_outgoing()
> > ensures it cannot be freed.
>
> We grab a reference to the FLB's module when the first file using the
> FLB is preserved. So the FLB should never go away while preserved files
> exist. Once all preserved files go away, you normally shouldn't be doing
> anything with the FLB anyway.
>
> Can you please elaborate on the use case and why this is a problem?
> Using the FLB outside of the standard LUO file callbacks sounds
> problematic.

The scenario I had in mind was to remove a PCI device from the outgoing
FLB if the device is forcibly removed while the file is still preserved,
for example someone writes 1 to /sys/bus/pci/devices/.../remove or a
device is physically hot-unplugged.

Specifically this call here from the patch below:

+void pci_liveupdate_cleanup_device(struct pci_dev *dev)
+{
+ /*
+ * It should be safe to READ_ONCE() outside of the rwsem during cleanup
+ * since there should no longer be any references to @dev on the system.
+ */
+ if (READ_ONCE(dev->liveupdate.outgoing)) {
+ pci_WARN(dev, 1, "Destroying outgoing-preserved device!\n");
+ pci_liveupdate_unpreserve(dev);
+ }
+}

https://lore.kernel.org/linux-pci/20260522202410.3104264-3-dmatlack@xxxxxxxxxx/

I can do this without adding reference counting to
liveupdate_flb_get_outgoing(), but the reference counting makes it
obvious that the outgoing FLB will not be freed while I am using it
here, and also aligns with liveupdate_flb_get_incoming().

> >
> > This change also aligns the outgoing FLB lifecycle management with the
> > incoming FLB, since the latter uses the same get/put semantics.
> >
> > Fixes: cab056f2aae7 ("liveupdate: luo_flb: introduce File-Lifecycle-Bound global state")
> > Assisted-by: Gemini:gemini-3-pro-preview
> > Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
> [...]
>
> --
> Regards,
> Pratyush Yadav