Re: [PATCH v4 07/19] liveupdate: Add helpers to track the files that LUO manages

From: Pratyush Yadav

Date: Fri Nov 20 2026 - 06:15:45 EST


On Wed, Nov 11 2026, David Matlack wrote:

> Add luo_track_file() and luo_untrack_file(), which add a file to and
> remove it from luo_preserved_files, and use them instead of open-coding
> xa_insert() and xa_erase() with luo_get_id() for preserved and retrieved
> files.
>
> The next commit lets file handlers make LUO track the file they retrieve
> into, which adds more users. The helpers keep the key and the -EBUSY
> behavior in one place.
>
> No functional change intended.
>
> Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
> ---
[...]
> @@ -395,8 +407,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
> luo_file->fh->ops->unpreserve(&args);
> luo_flb_file_unpreserve(luo_file->fh);
>
> - xa_erase(&luo_preserved_files,
> - luo_get_id(luo_file->fh, luo_file->file));
> + luo_untrack_file(luo_file->fh, luo_file->file);
> module_put(luo_file->fh->ops->owner);
>
> list_del(&luo_file->list);
> @@ -668,9 +679,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
> return err;
> }
>
> - err = xa_insert(&luo_preserved_files,
> - luo_get_id(luo_file->fh, args.file), args.file,
> - GFP_KERNEL);
> + err = luo_track_file(luo_file->fh, args.file);
> if (err) {
> /* A retrieved file is new, so it can't be tracked already. */
> WARN_ON_ONCE(err == -EBUSY);
> @@ -788,8 +797,7 @@ int luo_file_finish(struct luo_file_set *file_set)
> luo_file_finish_one(file_set, luo_file);
>
> if (luo_file->file) {
> - xa_erase(&luo_preserved_files,
> - luo_get_id(luo_file->fh, luo_file->file));
> + luo_untrack_file(luo_file->fh, luo_file->file);

This looks dangerous.

Since the previous patch set luo_file->file when xa_insert() failed,
this will trigger in a failed retrieve. Except, the file was never
tracked to begin with.

While I don't see anything that actually breaks because of this today,
I think it is a bug in the making.

I think the below is a bit better. Although this change probably makes
more sense in the previous patch, since that introduced the problem.
This patch should just replace the xa_erase() with luo_untrack_file().

if (luo_file->file)
fput(luo_file->file);

if (luo_file->retrieve_status > 0)
luo_untrack_file(luo_file->fh, luo_file->file);

> fput(luo_file->file);
> }
> module_put(luo_file->fh->ops->owner);

--
Regards,
Pratyush Yadav