Re: [PATCH v6 4/7] liveupdate: luo_flb: serialize outgoing FLBs incrementally
From: Mike Rapoport
Date: Thu Nov 19 2026 - 06:04:18 EST
Hi,
> Currently, outgoing FLB metadata is written in a single pass by
> luo_flb_serialize() during liveupdate_reboot(). When sessions are
> serialized ahead of reboot, any FLBs their files depend on must also
> be serialized at that time so the outgoing KHO state stays consistent.
>
> Serialize each file's FLB dependencies from luo_session_serialize_one(),
> appending new FLB entries or incrementing the serialized file count in
> place. Since every serialized session now updates its FLBs as it is
> serialized, drop the separate luo_flb_serialize() pass from
> liveupdate_reboot().
>
> Because serialized sessions never unpreserve their files, FLB
> serialization is one-way: once an FLB is serialized, its .unpreserve()
> callback will not run and its root handle from .preserve() remains
> fixed for the rest of the boot.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>
> ---
> kernel/liveupdate/luo_core.c | 10 +--
> kernel/liveupdate/luo_file.c | 15 +++++
> kernel/liveupdate/luo_flb.c | 102 ++++++++++++++++++++-----------
> kernel/liveupdate/luo_internal.h | 3 +-
> kernel/liveupdate/luo_session.c | 2 +
> 5 files changed, 85 insertions(+), 47 deletions(-)
>
> diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c
> index 1b2bda22902d2..9fef5161a1f3d 100644
> --- a/kernel/liveupdate/luo_core.c
> +++ b/kernel/liveupdate/luo_core.c
> @@ -219,18 +219,10 @@ late_initcall(luo_late_startup);
> */
> int liveupdate_reboot(void)
> {
> - int err;
> -
> if (!liveupdate_enabled())
> return 0;
>
> - err = luo_session_serialize();
> - if (err)
> - return err;
> -
> - luo_flb_serialize();
> -
> - return 0;
> + return luo_session_serialize();
> }
>
> /**
> diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
> index 988eb313a135f..cdd3c466e5ac3 100644
> --- a/kernel/liveupdate/luo_file.c
> +++ b/kernel/liveupdate/luo_file.c
> @@ -380,6 +380,21 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
> kho_block_set_destroy(&file_set->block_set);
> }
>
> +/**
> + * luo_file_serialize_flbs - Serialize FLBs for all preserved files in a file_set.
> + * @file_set: The file_set being serialized.
> + *
> + * Iterates through all preserved files in @file_set and serializes their
> + * associated FLB metadata into the outgoing KHO FLB array.
> + */
> +void luo_file_serialize_flbs(struct luo_file_set *file_set)
> +{
> + struct luo_file *luo_file;
> +
> + list_for_each_entry(luo_file, &file_set->files_list, list)
> + luo_flb_file_serialize(luo_file->fh);
> +}
> +
> static int luo_file_freeze_one(struct luo_file_set *file_set,
> struct luo_file *luo_file)
> {
> diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c
> index cd715a7c1d992..4ac534171d423 100644
> --- a/kernel/liveupdate/luo_flb.c
> +++ b/kernel/liveupdate/luo_flb.c
> @@ -34,6 +34,12 @@
> * This reference-counted approach ensures that shared state is saved exactly
> * once and restored exactly once, regardless of how many files depend on it,
> * and that its lifecycle is correctly managed across the kexec transition.
> + *
> + * Serialization: Outgoing FLB metadata is serialized into the KHO FLB array
> + * incrementally as sessions are serialized. Once serialized, the FLB's
> + * .unpreserve() callback is never invoked and its root KHO handle from
> + * .preserve() remains fixed, while later sessions may still update per-FD
> + * state in the shared live object under the FLB handler's own locking.
> */
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> @@ -72,6 +78,13 @@ static struct luo_flb_global luo_flb_global = {
> .list = LIST_HEAD_INIT(luo_flb_global.list),
> };
>
> +/*
> + * Serializes updates to luo_flb_global.outgoing.header_ser and .ser[].
> + * Lock hierarchy:
> + * luo_register_rwlock -> private->outgoing.lock -> luo_flb_ser_lock
> + */
> +static DEFINE_MUTEX(luo_flb_ser_lock);
Why is this needed? luo_flb_file_serialize() is called only from
luo_session_serialize_one() and that runs with sh->rwsem held for write, so
all the writers to the outgoing FLB block set are already serialized.
I'd drop the mutex and add lockdep_assert_held_write() for the outer lock,
or at least mention sh->rwsem in the lock hierarchy comment above.
Currently it lists only the inner part of the hierarchy, which is confusing.
--
Sincerely yours,
Mike.