From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E4C6367B97 for ; Fri, 29 May 2026 03:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024872; cv=none; b=QgKGwqD/Yc3x0d9O6tfsl3po+qeyOmVyVnJ1WotiOGgVb4zd7XARWXg8cLhNXyG6H4aRlu+LLb4/JoaHyG9f7wF0skijjV1EYXPzjlDpWf2jwo4uQGDjONtPwuCM/gYaURaFJtI14CJWiqfiYI/oiXoD0ckz36K9WQPCfIal6/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024872; c=relaxed/simple; bh=W9TrcKq6asgV8XeViYf/hgyOFuerJ5Zq1eR2TKusa+k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XMbCuS6Mnaw4G6omisjA8YhctVZVEUf29miX1Os1Np1CCvmbKrg/Zp0Qfrd6C+qCxLUWWDV+IqdCdLrf/ZxyC6XZb0/BLV41x4wKnGygYKf/njPzYXPRiVrM1lUGe6C9YQCxR2P6HpLmkBABbo6HGc9aLD2p8ypR7TSdwfLjvKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=CiOMABaD; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="CiOMABaD" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-8cbe69b122bso81733366d6.2 for ; Thu, 28 May 2026 20:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024869; x=1780629669; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=CUrKJoDYrQkjTLkL3MuZp6oC7EFU1kzzmwsnuISmv5A=; b=CiOMABaD1bOikQ5KEJ3ar8D8NheVVeXe5duo2o9UA8rHof7mGoZiF8b62v5qLiWfJ0 +jtYypkjCB0ByWvCsOCYr9Q1dmXqIo9e1YvfV3OHkzdQRpgeQXgM+oUC/IYflCQHHH+D Jvft0YCg+FipMAB2xT9yE+vfaAgcE7cKlTxzuB6GJ7bl1mpV+eKBpp9/U5QfjQH22BoE 2DB4yLSXdQhrwaajHY+KAICwTuWZoLy+pilqCQEdowmKckWdsMJY1yfUIE0A4If5As+Y gofYwjTyozS/qNXiyQPqLF9gF3zrgupUie5z6Q605KeJvyYiRYpws/wUssMQEHQRMk9U 8sQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024869; x=1780629669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=CUrKJoDYrQkjTLkL3MuZp6oC7EFU1kzzmwsnuISmv5A=; b=hlLlC6VLj6s0/YtmKBKuXveOg6LeUwQWhAuhnGh7vsg0F+tHdIWvXdLnlbLFs8zreZ +9t5VjkPq1CH37O4/ppPRel7K82t2F9k6HqAqnL+1+FXE0jWLQoMAEtOA8BeT/o6TGaL hWrMEPQuwWUOeakuVJR+NPXze4PTgVqAkoNTs6B9DZjBR5+YVNM2nSa98bZGs/k210fn m7Y3kS8bq9Bby94uQK/aP9mCBFdrPJ4izMe5kaswTJMKAR0ECo8/+hRo9toaZeiRk+SJ UxTE7NLvNKPrycRqXYvx2l4dFhmhISOnWtE+xUPNAkNhmBQei3GQ8VPp3fCWIwbYL6Ch QaaQ== X-Forwarded-Encrypted: i=1; AFNElJ9UBcFfCbIx34G4D+jdg/FsF2NI3kVX8HHJn9diTJFBUibiqmBUIc7ZiTf7Xtr/vKsW+H+zcl1xRrjmhDk=@vger.kernel.org X-Gm-Message-State: AOJu0YyfLocsc4f2lN4YyB0BymbtF8mgpvTsgG5UV1y0O774C+IgQIHv C56e+I/iG0nHJJPWkZvx0lUJEMtbLxHaWjzGurGW+I+P0fTMFLdVw5W+pnEFCWZU5Tc= X-Gm-Gg: Acq92OEW+IO7/dQ4xbfJ9pQvqY1mURZw50kJ8Fm9BK5Y7U6dUYjxmjn/7puatzWdA0/ sZyv+Rxj81A2+156osisXAu0D8ZEWNZKRj5wOKfI7scsxHkGx+xomcqFj8JASr9BvQJWr5+P3Fw aoWTW6TrvdPWS1fX/PKEm9TlWh3jmi4ZUqHGgoxixiCZhXIqbP01pGTnE3Tpa0atUhPwp1Qu7eB GMLW6sHKyc4lZ+YxT3kVJOynnxzOMtZEbMqhiQXo7aQPDpuf2vSsCH2pBDE+DMshY0MtSvoMgDI 0l8r2hwlyk4ToU4WKEzNK2/g4/SgJRLUW5NkJd/L0FOF9NUvJ5o1OMLWKbTJHwpDpT/8Xn+TPIm sZPA85a5mH0yJs4FWkibk1uFPK6Au+cSp8K4THTAmwBN0fiKT9ucPlZq54lmK5JdIGPKDOW5dhy FWQ+o7hQkDYEZChjrHqdeBrINFrBcW3/GbzhcQylA7cUVB72PjNLAEmGOxjhFzKg== X-Received: by 2002:a05:6214:3d97:b0:8ba:3fc9:88ca with SMTP id 6a1803df08f44-8cce82758d4mr12346736d6.39.1780024869500; Thu, 28 May 2026 20:21:09 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:09 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 01/11] liveupdate: centralize state management into struct luo_ser Date: Fri, 29 May 2026 03:20:56 +0000 Message-ID: <20260529032106.1505796-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Transition the LUO to ABI v2, which centralizes state management into a single struct luo_ser header. Previously, LUO state was spread across multiple FDT properties and subnodes. ABI v2 simplifies this by placing all core state, including the liveupdate number and physical addresses for sessions and FLB headers into a centralized struct luo_ser. Note that this change introduces a semantic difference: the sessions and FLB serialization formats are no longer completely independent of the core LUO. Their metadata (such as physical addresses for sessions and FLB headers) is now coupled to and managed via the centralized struct luo_ser. Signed-off-by: Pasha Tatashin --- include/linux/kho/abi/luo.h | 91 +++++++++++--------------------- kernel/liveupdate/luo_core.c | 60 ++++++++++++++------- kernel/liveupdate/luo_flb.c | 65 +++-------------------- kernel/liveupdate/luo_internal.h | 8 +-- kernel/liveupdate/luo_session.c | 64 ++++------------------ 5 files changed, 94 insertions(+), 194 deletions(-) diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h index 46750a0ddf88..1b2f865a771a 100644 --- a/include/linux/kho/abi/luo.h +++ b/include/linux/kho/abi/luo.h @@ -30,52 +30,25 @@ * .. code-block:: none * * / { - * compatible =3D "luo-v1"; - * liveupdate-number =3D <...>; - * - * luo-session { - * compatible =3D "luo-session-v1"; - * luo-session-header =3D ; - * }; - * - * luo-flb { - * compatible =3D "luo-flb-v1"; - * luo-flb-header =3D ; - * }; + * compatible =3D "luo-v2"; + * luo-abi-header =3D ; * }; * * Main LUO Node (/): * - * - compatible: "luo-v1" + * - compatible: "luo-v2" * Identifies the overall LUO ABI version. - * - liveupdate-number: u64 - * A counter tracking the number of successful live updates performed. - * - * Session Node (luo-session): - * This node describes all preserved user-space sessions. - * - * - compatible: "luo-session-v1" - * Identifies the session ABI version. - * - luo-session-header: u64 - * The physical address of a `struct luo_session_header_ser`. This str= ucture - * is the header for a contiguous block of memory containing an array = of - * `struct luo_session_ser`, one for each preserved session. - * - * File-Lifecycle-Bound Node (luo-flb): - * This node describes all preserved global objects whose lifecycle is b= ound - * to that of the preserved files (e.g., shared IOMMU state). - * - * - compatible: "luo-flb-v1" - * Identifies the FLB ABI version. - * - luo-flb-header: u64 - * The physical address of a `struct luo_flb_header_ser`. This structu= re is - * the header for a contiguous block of memory containing an array of - * `struct luo_flb_ser`, one for each preserved global object. + * - luo-abi-header: u64 + * The physical address of `struct luo_ser`. * * Serialization Structures: * The FDT properties point to memory regions containing arrays of simpl= e, * `__packed` structures. These structures contain the actual preserved = state. * + * - struct luo_ser: + * The central ABI structure that contains the overall state of the LU= O. + * It includes the liveupdate-number and pointers to sessions and FLBs. + * * - struct luo_session_header_ser: * Header for the session array. Contains the total page count of the * preserved memory block and the number of `struct luo_session_ser` @@ -109,13 +82,26 @@ =20 /* * The LUO FDT hooks all LUO state for sessions, fds, etc. - * In the root it also carries "liveupdate-number" 64-bit property that - * corresponds to the number of live-updates performed on this machine. */ #define LUO_FDT_SIZE PAGE_SIZE #define LUO_FDT_KHO_ENTRY_NAME "LUO" -#define LUO_FDT_COMPATIBLE "luo-v1" -#define LUO_FDT_LIVEUPDATE_NUM "liveupdate-number" +#define LUO_FDT_COMPATIBLE "luo-v2" +#define LUO_FDT_ABI_HEADER "luo-abi-header" + +/** + * struct luo_ser - Centralized LUO ABI header. + * @liveupdate_num: A counter tracking the number of successful live updat= es. + * @sessions_pa: Physical address of the first session block header. + * @flbs_pa: Physical address of the FLB header. + * + * This structure is the root of all preserved LUO state. It is pointed to= by + * the "luo-abi-header" property in the LUO FDT. + */ +struct luo_ser { + u64 liveupdate_num; + u64 sessions_pa; + u64 flbs_pa; +} __packed; =20 #define LIVEUPDATE_HNDL_COMPAT_LENGTH 48 =20 @@ -147,15 +133,6 @@ struct luo_file_set_ser { u64 count; } __packed; =20 -/* - * LUO FDT session node - * LUO_FDT_SESSION_HEADER: is a u64 physical address of struct - * luo_session_header_ser - */ -#define LUO_FDT_SESSION_NODE_NAME "luo-session" -#define LUO_FDT_SESSION_COMPATIBLE "luo-session-v2" -#define LUO_FDT_SESSION_HEADER "luo-session-header" - /** * struct luo_session_header_ser - Header for the serialized session data = block. * @count: The number of `struct luo_session_ser` entries that immediately @@ -165,7 +142,7 @@ struct luo_file_set_ser { * physical memory preserved across the kexec. It provides the necessary * metadata to interpret the array of session entries that follow. * - * If this structure is modified, `LUO_FDT_SESSION_COMPATIBLE` must be upd= ated. + * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. */ struct luo_session_header_ser { u64 count; @@ -182,7 +159,7 @@ struct luo_session_header_ser { * session) is created and passed to the new kernel, allowing it to recons= truct * the session context. * - * If this structure is modified, `LUO_FDT_SESSION_COMPATIBLE` must be upd= ated. + * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. */ struct luo_session_ser { char name[LIVEUPDATE_SESSION_NAME_LENGTH]; @@ -192,10 +169,6 @@ struct luo_session_ser { /* The max size is set so it can be reliably used during in serialization = */ #define LIVEUPDATE_FLB_COMPAT_LENGTH 48 =20 -#define LUO_FDT_FLB_NODE_NAME "luo-flb" -#define LUO_FDT_FLB_COMPATIBLE "luo-flb-v1" -#define LUO_FDT_FLB_HEADER "luo-flb-header" - /** * struct luo_flb_header_ser - Header for the serialized FLB data block. * @pgcnt: The total number of pages occupied by the entire preserved memo= ry @@ -205,11 +178,9 @@ struct luo_session_ser { * in the memory block. * * This structure is located at the physical address specified by the - * `LUO_FDT_FLB_HEADER` FDT property. It provides the new kernel with the - * necessary information to find and iterate over the array of preserved - * File-Lifecycle-Bound objects and to manage the underlying memory. + * flbs_pa in luo_ser. * - * If this structure is modified, LUO_FDT_FLB_COMPATIBLE must be updated. + * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. */ struct luo_flb_header_ser { u64 pgcnt; @@ -231,7 +202,7 @@ struct luo_flb_header_ser { * passed to the new kernel. Each entry allows the LUO core to restore one * global, shared object. * - * If this structure is modified, LUO_FDT_FLB_COMPATIBLE must be updated. + * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. */ struct luo_flb_ser { char name[LIVEUPDATE_FLB_COMPAT_LENGTH]; diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 803f51c84275..c1c290aefc76 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -57,7 +57,6 @@ #include #include #include -#include =20 #include "kexec_handover_internal.h" #include "luo_internal.h" @@ -82,9 +81,11 @@ early_param("liveupdate", early_liveupdate_param); =20 static int __init luo_early_startup(void) { + struct luo_ser *luo_ser; + int err, header_size; phys_addr_t fdt_phys; - int err, ln_size; const void *ptr; + u64 luo_ser_pa; =20 if (!kho_is_enabled()) { if (liveupdate_enabled()) @@ -115,27 +116,29 @@ static int __init luo_early_startup(void) return -EINVAL; } =20 - ln_size =3D 0; - ptr =3D fdt_getprop(luo_global.fdt_in, 0, LUO_FDT_LIVEUPDATE_NUM, - &ln_size); - if (!ptr || ln_size !=3D sizeof(luo_global.liveupdate_num)) { - pr_err("Unable to get live update number '%s' [%d]\n", - LUO_FDT_LIVEUPDATE_NUM, ln_size); + header_size =3D 0; + ptr =3D fdt_getprop(luo_global.fdt_in, 0, LUO_FDT_ABI_HEADER, &header_siz= e); + if (!ptr || header_size !=3D sizeof(u64)) { + pr_err("Unable to get ABI header '%s' [%d]\n", + LUO_FDT_ABI_HEADER, header_size); =20 return -EINVAL; } =20 - luo_global.liveupdate_num =3D get_unaligned((u64 *)ptr); + luo_ser_pa =3D get_unaligned((u64 *)ptr); + luo_ser =3D phys_to_virt(luo_ser_pa); + + luo_global.liveupdate_num =3D luo_ser->liveupdate_num; pr_info("Retrieved live update data, liveupdate number: %lld\n", luo_global.liveupdate_num); =20 - err =3D luo_session_setup_incoming(luo_global.fdt_in); + err =3D luo_session_setup_incoming(luo_ser->sessions_pa); if (err) return err; =20 - err =3D luo_flb_setup_incoming(luo_global.fdt_in); + luo_flb_setup_incoming(luo_ser->flbs_pa); =20 - return err; + return 0; } =20 static int __init liveupdate_early_init(void) @@ -156,7 +159,8 @@ early_initcall(liveupdate_early_init); /* Called during boot to create outgoing LUO fdt tree */ static int __init luo_fdt_setup(void) { - const u64 ln =3D luo_global.liveupdate_num + 1; + struct luo_ser *luo_ser; + u64 luo_ser_pa; void *fdt_out; int err; =20 @@ -166,27 +170,45 @@ static int __init luo_fdt_setup(void) return PTR_ERR(fdt_out); } =20 + luo_ser =3D kho_alloc_preserve(sizeof(*luo_ser)); + if (IS_ERR(luo_ser)) { + err =3D PTR_ERR(luo_ser); + goto exit_free_fdt; + } + luo_ser_pa =3D virt_to_phys(luo_ser); + err =3D fdt_create(fdt_out, LUO_FDT_SIZE); err |=3D fdt_finish_reservemap(fdt_out); err |=3D fdt_begin_node(fdt_out, ""); err |=3D fdt_property_string(fdt_out, "compatible", LUO_FDT_COMPATIBLE); - err |=3D fdt_property(fdt_out, LUO_FDT_LIVEUPDATE_NUM, &ln, sizeof(ln)); - err |=3D luo_session_setup_outgoing(fdt_out); - err |=3D luo_flb_setup_outgoing(fdt_out); + err |=3D fdt_property(fdt_out, LUO_FDT_ABI_HEADER, &luo_ser_pa, + sizeof(luo_ser_pa)); err |=3D fdt_end_node(fdt_out); err |=3D fdt_finish(fdt_out); if (err) - goto exit_free; + goto exit_free_luo_ser; + + err =3D luo_session_setup_outgoing(&luo_ser->sessions_pa); + if (err) + goto exit_free_luo_ser; + + err =3D luo_flb_setup_outgoing(&luo_ser->flbs_pa); + if (err) + goto exit_free_luo_ser; + + luo_ser->liveupdate_num =3D luo_global.liveupdate_num + 1; =20 err =3D kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out, fdt_totalsize(fdt_out)); if (err) - goto exit_free; + goto exit_free_luo_ser; luo_global.fdt_out =3D fdt_out; =20 return 0; =20 -exit_free: +exit_free_luo_ser: + kho_unpreserve_free(luo_ser); +exit_free_fdt: kho_unpreserve_free(fdt_out); pr_err("failed to prepare LUO FDT: %d\n", err); =20 diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c index 8f5c5dd01cd0..c8dd30b41238 100644 --- a/kernel/liveupdate/luo_flb.c +++ b/kernel/liveupdate/luo_flb.c @@ -44,13 +44,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include "luo_internal.h" =20 #define LUO_FLB_PGCNT 1ul @@ -551,27 +549,15 @@ int liveupdate_flb_get_outgoing(struct liveupdate_flb= *flb, void **objp) return 0; } =20 -int __init luo_flb_setup_outgoing(void *fdt_out) +int __init luo_flb_setup_outgoing(u64 *flbs_pa) { struct luo_flb_header_ser *header_ser; - u64 header_ser_pa; - int err; =20 header_ser =3D kho_alloc_preserve(LUO_FLB_PGCNT << PAGE_SHIFT); if (IS_ERR(header_ser)) return PTR_ERR(header_ser); =20 - header_ser_pa =3D virt_to_phys(header_ser); - - err =3D fdt_begin_node(fdt_out, LUO_FDT_FLB_NODE_NAME); - err |=3D fdt_property_string(fdt_out, "compatible", - LUO_FDT_FLB_COMPATIBLE); - err |=3D fdt_property(fdt_out, LUO_FDT_FLB_HEADER, &header_ser_pa, - sizeof(header_ser_pa)); - err |=3D fdt_end_node(fdt_out); - - if (err) - goto err_unpreserve; + *flbs_pa =3D virt_to_phys(header_ser); =20 header_ser->pgcnt =3D LUO_FLB_PGCNT; luo_flb_global.outgoing.header_ser =3D header_ser; @@ -579,53 +565,18 @@ int __init luo_flb_setup_outgoing(void *fdt_out) luo_flb_global.outgoing.active =3D true; =20 return 0; - -err_unpreserve: - kho_unpreserve_free(header_ser); - - return err; } =20 -int __init luo_flb_setup_incoming(void *fdt_in) +void __init luo_flb_setup_incoming(u64 flbs_pa) { struct luo_flb_header_ser *header_ser; - int err, header_size, offset; - const void *ptr; - u64 header_ser_pa; =20 - offset =3D fdt_subnode_offset(fdt_in, 0, LUO_FDT_FLB_NODE_NAME); - if (offset < 0) { - pr_err("Unable to get FLB node [%s]\n", LUO_FDT_FLB_NODE_NAME); - - return -ENOENT; + if (flbs_pa) { + header_ser =3D phys_to_virt(flbs_pa); + luo_flb_global.incoming.header_ser =3D header_ser; + luo_flb_global.incoming.ser =3D (void *)(header_ser + 1); + luo_flb_global.incoming.active =3D true; } - - err =3D fdt_node_check_compatible(fdt_in, offset, - LUO_FDT_FLB_COMPATIBLE); - if (err) { - pr_err("FLB node is incompatible with '%s' [%d]\n", - LUO_FDT_FLB_COMPATIBLE, err); - - return -EINVAL; - } - - header_size =3D 0; - ptr =3D fdt_getprop(fdt_in, offset, LUO_FDT_FLB_HEADER, &header_size); - if (!ptr || header_size !=3D sizeof(u64)) { - pr_err("Unable to get FLB header property '%s' [%d]\n", - LUO_FDT_FLB_HEADER, header_size); - - return -EINVAL; - } - - header_ser_pa =3D get_unaligned((u64 *)ptr); - header_ser =3D phys_to_virt(header_ser_pa); - - luo_flb_global.incoming.header_ser =3D header_ser; - luo_flb_global.incoming.ser =3D (void *)(header_ser + 1); - luo_flb_global.incoming.active =3D true; - - return 0; } =20 /** diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index dd53d4a7277e..9bf26c5b1495 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -79,8 +79,8 @@ extern struct rw_semaphore luo_register_rwlock; =20 int luo_session_create(const char *name, struct file **filep); int luo_session_retrieve(const char *name, struct file **filep); -int __init luo_session_setup_outgoing(void *fdt); -int __init luo_session_setup_incoming(void *fdt); +int __init luo_session_setup_outgoing(u64 *sessions_pa); +int __init luo_session_setup_incoming(u64 sessions_pa); int luo_session_serialize(void); int luo_session_deserialize(void); =20 @@ -102,8 +102,8 @@ int luo_flb_file_preserve(struct liveupdate_file_handle= r *fh); void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh); void luo_flb_file_finish(struct liveupdate_file_handler *fh); void luo_flb_unregister_all(struct liveupdate_file_handler *fh); -int __init luo_flb_setup_outgoing(void *fdt); -int __init luo_flb_setup_incoming(void *fdt); +int __init luo_flb_setup_outgoing(u64 *flbs_pa); +void __init luo_flb_setup_incoming(u64 flbs_pa); void luo_flb_serialize(void); =20 #ifdef CONFIG_LIVEUPDATE_TEST diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_sessio= n.c index 146414933977..1cad54ea8209 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -25,9 +25,8 @@ * * - Serialization: Session metadata is preserved using the KHO framework.= When * a live update is triggered via kexec, an array of `struct luo_session= _ser` - * is populated and placed in a preserved memory region. An FDT node is = also - * created, containing the count of sessions and the physical address of= this - * array. + * is populated and placed in a preserved memory region. The physical ad= dress + * of this array is stored in the centralized `struct luo_ser` structure. * * Session Lifecycle: * @@ -91,13 +90,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include "luo_internal.h" =20 @@ -498,75 +495,34 @@ int luo_session_retrieve(const char *name, struct fil= e **filep) return err; } =20 -int __init luo_session_setup_outgoing(void *fdt_out) +int __init luo_session_setup_outgoing(u64 *sessions_pa) { struct luo_session_header_ser *header_ser; - u64 header_ser_pa; - int err; =20 header_ser =3D kho_alloc_preserve(LUO_SESSION_PGCNT << PAGE_SHIFT); if (IS_ERR(header_ser)) return PTR_ERR(header_ser); - header_ser_pa =3D virt_to_phys(header_ser); - - err =3D fdt_begin_node(fdt_out, LUO_FDT_SESSION_NODE_NAME); - err |=3D fdt_property_string(fdt_out, "compatible", - LUO_FDT_SESSION_COMPATIBLE); - err |=3D fdt_property(fdt_out, LUO_FDT_SESSION_HEADER, &header_ser_pa, - sizeof(header_ser_pa)); - err |=3D fdt_end_node(fdt_out); =20 - if (err) - goto err_unpreserve; + *sessions_pa =3D virt_to_phys(header_ser); =20 luo_session_global.outgoing.header_ser =3D header_ser; luo_session_global.outgoing.ser =3D (void *)(header_ser + 1); luo_session_global.outgoing.active =3D true; =20 return 0; - -err_unpreserve: - kho_unpreserve_free(header_ser); - return err; } =20 -int __init luo_session_setup_incoming(void *fdt_in) +int __init luo_session_setup_incoming(u64 sessions_pa) { struct luo_session_header_ser *header_ser; - int err, header_size, offset; - u64 header_ser_pa; - const void *ptr; - - offset =3D fdt_subnode_offset(fdt_in, 0, LUO_FDT_SESSION_NODE_NAME); - if (offset < 0) { - pr_err("Unable to get session node: [%s]\n", - LUO_FDT_SESSION_NODE_NAME); - return -EINVAL; - } =20 - err =3D fdt_node_check_compatible(fdt_in, offset, - LUO_FDT_SESSION_COMPATIBLE); - if (err) { - pr_err("Session node incompatible [%s]\n", - LUO_FDT_SESSION_COMPATIBLE); - return -EINVAL; - } - - header_size =3D 0; - ptr =3D fdt_getprop(fdt_in, offset, LUO_FDT_SESSION_HEADER, &header_size); - if (!ptr || header_size !=3D sizeof(u64)) { - pr_err("Unable to get session header '%s' [%d]\n", - LUO_FDT_SESSION_HEADER, header_size); - return -EINVAL; + if (sessions_pa) { + header_ser =3D phys_to_virt(sessions_pa); + luo_session_global.incoming.header_ser =3D header_ser; + luo_session_global.incoming.ser =3D (void *)(header_ser + 1); + luo_session_global.incoming.active =3D true; } =20 - header_ser_pa =3D get_unaligned((u64 *)ptr); - header_ser =3D phys_to_virt(header_ser_pa); - - luo_session_global.incoming.header_ser =3D header_ser; - luo_session_global.incoming.ser =3D (void *)(header_ser + 1); - luo_session_global.incoming.active =3D true; - return 0; } =20 --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B155A3546C6 for ; Fri, 29 May 2026 03:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024873; cv=none; b=OkM0WkxoTsawzwlJcesSELGkMRpCJuAc7MOCKgNfi5p8XW0+Lt+wZAN/U++4zUZwGR+jgpQF95LQnteawDye6AKkT5nDwrwiaICmxqq9sUMcK+ICDDviY9V7/4EUbQIEvRXswQBR+MAzwTz7D4gSNrlyIBeC85qBEPpHwwKFof0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024873; c=relaxed/simple; bh=gWZQJd1/xNgDKtqgIHtIzktrfzhYfSqK3tgEwLJieLg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sDbFDwZgIw1/dEJF/ZuW1HJmOV7w5GMnMpT1Y31Doxcp5nwYBPEDEvdq0hB7feYDKB2P9L6q+saaSWAcbt1gNpx9xHcH9fH6uZyvcEw5R3rGOdqhbjjtt1zOb/EMFpV3tDjlBUpS9xr/L8y3PhqdG4y+T3s/h4DR9Kmxn6kXU1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=DezSDcZP; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="DezSDcZP" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-8ccd1f57b32so16988186d6.2 for ; Thu, 28 May 2026 20:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024871; x=1780629671; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XlF+4nIJqGhSWvyi1zvFIxVHRsseY6Zy+d1V9eOuO1Y=; b=DezSDcZP+fWx+Cla8grw+/hmQXd4Msr9iKuKD1YBdhvmPyV0+5wdqar3WPOBa5gb22 Tl6Dy3JM5L8sEZySq7qIXsz64DOb4G5M0QdBDgm1wJk4f6b4fH71WS6kukgQaEvbKHcF Nb1PDZJV0qlszvRwIuidRqluqNozdL9xnzrCbeF/4y69WhkyS7fTUzSXGZWi8t0TWMmC 7ZuR048tcMAIW8gAMNsNcBxOR77XCQ6rXrAHoHTe5U4JaYWk2lGoOwW8IYpE7L8/M0N9 6suTdsqMa1k3EHB0R2BRhUAeCgRF2WnXaHlY2uhaFXcCs8X0pcctw8ps+MuvdZsBt6T3 QS6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024871; x=1780629671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=XlF+4nIJqGhSWvyi1zvFIxVHRsseY6Zy+d1V9eOuO1Y=; b=YZadyp3aqZO5J4p1nuZXbrT2cPwhOL5wN+dSjHaTNs2q5wbuGx8omlX9jDzID3FY+d qnc+AhM2X3cGffReaH1yw6m3U/FPTJfH8SAWCKsi5pY9x7WCOWvbNak7isPy5ju6EIVP Lzp4o6dt4wLE8VJq6x0dN6aaIPRnVwTvPazeknHo3TwVhTFt0+5vziFf+zsnfwAB+Ddt OKuWGipXFggY6IhB3H18cHLYvp/q85fvGTG1/UceNBW+8Gpl8PRArFc1pKpBGuWzPMeS 0vMhvI1tg533byZtU2SnuXKU/ik7R3rlvbLHXYzuFFCwsdDxQuR56UB9QUydc1DFq9Sp CRxw== X-Forwarded-Encrypted: i=1; AFNElJ/GOJeyyHAQyZFZPrG4v8ag8CW9zmCYJo4fXT7tyR7bWfkRUYgIrrfAzN/g26WQfagPvdltWjH1+8RFBUE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzjp0U02GOtoGs3LMicU069JPSPFWw/jGTz4u+h/zcoZvAF2c6i A2EsG1Kc/Vog6exXMUICeOaG35TeCLZLHeqZG01kkvz34UjolFZ0L+qphILUq2HUbU0= X-Gm-Gg: Acq92OGHuKHXLsDy5tM6IjTPfwEmR2GYmyOK0HksHQtcY12eYqepGi+Ra693Kv6lacI XtiJ1Oi7i6E9b2Ri/YC6UA3Lba6EVLJ0/p56DyIqHzhGB3/6Clf7n2YCrOQrnthoiu1fJELsyVI y/0inhjTNbfmScuMfxX1V2I9jRdzeeP2ynB8TWiZ01+zO4Si2ElxLahTRvnd+lo4YkMUvgrUTxW /d+jorwBLubJ0HW3heZ1mHf6Pg3Je6etfRA4QPb2D6FUNqlVP5OcbDW8MLPVnGUWAmNgluZogtT 7lmMx2AIRg4zP/CBK+Diq9jpZpPQcH7hHZnrSX5WzVeTl6HVoNa3rT+O1udtEi/IUGmcq7v/6cj 8sBuXH98oj0WY1FPiA0qqzcKc/cJyDEJlqoREvBUEpbkq2nnsmDc4aUUqhG1i5wL+DUsd6wCvjx Dj0xxzjhGDX3U2sCNkWAqstIrG0ZreISQITbMwxFg6yrwuR6isEFGXTOQfqviXVw== X-Received: by 2002:a05:6214:528d:b0:8cc:6c08:552f with SMTP id 6a1803df08f44-8cce7b6873fmr12860586d6.9.1780024870731; Thu, 28 May 2026 20:21:10 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:10 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 02/11] liveupdate: register luo_ser as KHO subtree Date: Fri, 29 May 2026 03:20:57 +0000 Message-ID: <20260529032106.1505796-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Entirely remove the LUO FDT wrapper since the FDT only carries the compatible string and the pointer to the centralized struct luo_ser. Instead, register the struct luo_ser via the KHO raw subtree API, placing the compatibility string inside the structure itself. Signed-off-by: Pasha Tatashin --- include/linux/kho/abi/luo.h | 57 +++++++++--------------- kernel/liveupdate/luo_core.c | 85 +++++++++++------------------------- 2 files changed, 46 insertions(+), 96 deletions(-) diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h index 1b2f865a771a..9a4fe491812b 100644 --- a/include/linux/kho/abi/luo.h +++ b/include/linux/kho/abi/luo.h @@ -10,11 +10,11 @@ * * Live Update Orchestrator uses the stable Application Binary Interface * defined below to pass state from a pre-update kernel to a post-update - * kernel. The ABI is built upon the Kexec HandOver framework and uses a - * Flattened Device Tree to describe the preserved data. + * kernel. The ABI is built upon the Kexec HandOver framework and registers + * the central `struct luo_ser` via the KHO raw subtree API. * - * This interface is a contract. Any modification to the FDT structure, no= de - * properties, compatible strings, or the layout of the `__packed` seriali= zation + * This interface is a contract. Any modification to the structure fields, + * compatible strings, or the layout of the `__packed` serialization * structures defined here constitutes a breaking change. Such changes req= uire * incrementing the version number in the relevant `_COMPATIBLE` string to * prevent a new kernel from misinterpreting data from an old kernel. @@ -23,31 +23,15 @@ * however, backward/forward compatibility is only guaranteed for kernels * supporting the same ABI version. * - * FDT Structure Overview: + * KHO Structure Overview: * The entire LUO state is encapsulated within a single KHO entry named = "LUO". - * This entry contains an FDT with the following layout: - * - * .. code-block:: none - * - * / { - * compatible =3D "luo-v2"; - * luo-abi-header =3D ; - * }; - * - * Main LUO Node (/): - * - * - compatible: "luo-v2" - * Identifies the overall LUO ABI version. - * - luo-abi-header: u64 - * The physical address of `struct luo_ser`. + * This entry contains the `struct luo_ser` structure. * * Serialization Structures: - * The FDT properties point to memory regions containing arrays of simpl= e, - * `__packed` structures. These structures contain the actual preserved = state. - * * - struct luo_ser: * The central ABI structure that contains the overall state of the LU= O. - * It includes the liveupdate-number and pointers to sessions and FLBs. + * It includes the compatibility string, the liveupdate-number, and po= inters + * to sessions and FLBs. * * - struct luo_session_header_ser: * Header for the session array. Contains the total page count of the @@ -78,26 +62,27 @@ #ifndef _LINUX_KHO_ABI_LUO_H #define _LINUX_KHO_ABI_LUO_H =20 +#include #include =20 /* - * The LUO FDT hooks all LUO state for sessions, fds, etc. + * The LUO state is registered under this KHO entry name. */ -#define LUO_FDT_SIZE PAGE_SIZE -#define LUO_FDT_KHO_ENTRY_NAME "LUO" -#define LUO_FDT_COMPATIBLE "luo-v2" -#define LUO_FDT_ABI_HEADER "luo-abi-header" +#define LUO_KHO_ENTRY_NAME "LUO" +#define LUO_ABI_COMPATIBLE "luo-v3" +#define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) =20 /** * struct luo_ser - Centralized LUO ABI header. + * @compatible: Compatibility string identifying the LUO ABI version. * @liveupdate_num: A counter tracking the number of successful live updat= es. * @sessions_pa: Physical address of the first session block header. * @flbs_pa: Physical address of the FLB header. * - * This structure is the root of all preserved LUO state. It is pointed to= by - * the "luo-abi-header" property in the LUO FDT. + * This structure is the root of all preserved LUO state. */ struct luo_ser { + char compatible[LUO_ABI_COMPAT_LEN]; u64 liveupdate_num; u64 sessions_pa; u64 flbs_pa; @@ -111,7 +96,7 @@ struct luo_ser { * @data: Private data * @token: User provided token for this file * - * If this structure is modified, LUO_SESSION_COMPATIBLE must be updated. + * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_file_ser { char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH]; @@ -142,7 +127,7 @@ struct luo_file_set_ser { * physical memory preserved across the kexec. It provides the necessary * metadata to interpret the array of session entries that follow. * - * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. + * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_session_header_ser { u64 count; @@ -159,7 +144,7 @@ struct luo_session_header_ser { * session) is created and passed to the new kernel, allowing it to recons= truct * the session context. * - * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. + * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_session_ser { char name[LIVEUPDATE_SESSION_NAME_LENGTH]; @@ -180,7 +165,7 @@ struct luo_session_ser { * This structure is located at the physical address specified by the * flbs_pa in luo_ser. * - * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. + * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_flb_header_ser { u64 pgcnt; @@ -202,7 +187,7 @@ struct luo_flb_header_ser { * passed to the new kernel. Each entry allows the LUO core to restore one * global, shared object. * - * If this structure is modified, `LUO_FDT_COMPATIBLE` must be updated. + * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_flb_ser { char name[LIVEUPDATE_FLB_COMPAT_LENGTH]; diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index c1c290aefc76..5e12c8f8669b 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -63,8 +62,7 @@ =20 static struct { bool enabled; - void *fdt_out; - void *fdt_in; + struct luo_ser *luo_ser_out; u64 liveupdate_num; } luo_global; =20 @@ -81,11 +79,10 @@ early_param("liveupdate", early_liveupdate_param); =20 static int __init luo_early_startup(void) { + phys_addr_t luo_ser_phys; struct luo_ser *luo_ser; - int err, header_size; - phys_addr_t fdt_phys; - const void *ptr; - u64 luo_ser_pa; + size_t len; + int err; =20 if (!kho_is_enabled()) { if (liveupdate_enabled()) @@ -94,40 +91,29 @@ static int __init luo_early_startup(void) return 0; } =20 - /* Retrieve LUO subtree, and verify its format. */ - err =3D kho_retrieve_subtree(LUO_FDT_KHO_ENTRY_NAME, &fdt_phys, NULL); + /* Retrieve LUO state from KHO. */ + err =3D kho_retrieve_subtree(LUO_KHO_ENTRY_NAME, &luo_ser_phys, &len); if (err) { if (err !=3D -ENOENT) { - pr_err("failed to retrieve FDT '%s' from KHO: %pe\n", - LUO_FDT_KHO_ENTRY_NAME, ERR_PTR(err)); + pr_err("failed to retrieve LUO state '%s' from KHO: %pe\n", + LUO_KHO_ENTRY_NAME, ERR_PTR(err)); return err; } =20 return 0; } =20 - luo_global.fdt_in =3D phys_to_virt(fdt_phys); - err =3D fdt_node_check_compatible(luo_global.fdt_in, 0, - LUO_FDT_COMPATIBLE); - if (err) { - pr_err("FDT '%s' is incompatible with '%s' [%d]\n", - LUO_FDT_KHO_ENTRY_NAME, LUO_FDT_COMPATIBLE, err); - + if (len < sizeof(*luo_ser)) { + pr_err("LUO state is too small (%zu < %zu)\n", len, sizeof(*luo_ser)); return -EINVAL; } =20 - header_size =3D 0; - ptr =3D fdt_getprop(luo_global.fdt_in, 0, LUO_FDT_ABI_HEADER, &header_siz= e); - if (!ptr || header_size !=3D sizeof(u64)) { - pr_err("Unable to get ABI header '%s' [%d]\n", - LUO_FDT_ABI_HEADER, header_size); - + luo_ser =3D phys_to_virt(luo_ser_phys); + if (strncmp(luo_ser->compatible, LUO_ABI_COMPATIBLE, LUO_ABI_COMPAT_LEN))= { + pr_err("LUO state is incompatible with '%s'\n", LUO_ABI_COMPATIBLE); return -EINVAL; } =20 - luo_ser_pa =3D get_unaligned((u64 *)ptr); - luo_ser =3D phys_to_virt(luo_ser_pa); - luo_global.liveupdate_num =3D luo_ser->liveupdate_num; pr_info("Retrieved live update data, liveupdate number: %lld\n", luo_global.liveupdate_num); @@ -156,37 +142,20 @@ static int __init liveupdate_early_init(void) } early_initcall(liveupdate_early_init); =20 -/* Called during boot to create outgoing LUO fdt tree */ -static int __init luo_fdt_setup(void) +/* Called during boot to create outgoing LUO state */ +static int __init luo_state_setup(void) { struct luo_ser *luo_ser; - u64 luo_ser_pa; - void *fdt_out; int err; =20 - fdt_out =3D kho_alloc_preserve(LUO_FDT_SIZE); - if (IS_ERR(fdt_out)) { - pr_err("failed to allocate/preserve FDT memory\n"); - return PTR_ERR(fdt_out); - } - luo_ser =3D kho_alloc_preserve(sizeof(*luo_ser)); if (IS_ERR(luo_ser)) { - err =3D PTR_ERR(luo_ser); - goto exit_free_fdt; + pr_err("failed to allocate/preserve LUO state memory\n"); + return PTR_ERR(luo_ser); } - luo_ser_pa =3D virt_to_phys(luo_ser); - - err =3D fdt_create(fdt_out, LUO_FDT_SIZE); - err |=3D fdt_finish_reservemap(fdt_out); - err |=3D fdt_begin_node(fdt_out, ""); - err |=3D fdt_property_string(fdt_out, "compatible", LUO_FDT_COMPATIBLE); - err |=3D fdt_property(fdt_out, LUO_FDT_ABI_HEADER, &luo_ser_pa, - sizeof(luo_ser_pa)); - err |=3D fdt_end_node(fdt_out); - err |=3D fdt_finish(fdt_out); - if (err) - goto exit_free_luo_ser; + + strscpy(luo_ser->compatible, LUO_ABI_COMPATIBLE, sizeof(luo_ser->compatib= le)); + luo_ser->liveupdate_num =3D luo_global.liveupdate_num + 1; =20 err =3D luo_session_setup_outgoing(&luo_ser->sessions_pa); if (err) @@ -196,21 +165,17 @@ static int __init luo_fdt_setup(void) if (err) goto exit_free_luo_ser; =20 - luo_ser->liveupdate_num =3D luo_global.liveupdate_num + 1; - - err =3D kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out, - fdt_totalsize(fdt_out)); + err =3D kho_add_subtree(LUO_KHO_ENTRY_NAME, luo_ser, sizeof(*luo_ser)); if (err) goto exit_free_luo_ser; - luo_global.fdt_out =3D fdt_out; + + luo_global.luo_ser_out =3D luo_ser; =20 return 0; =20 exit_free_luo_ser: kho_unpreserve_free(luo_ser); -exit_free_fdt: - kho_unpreserve_free(fdt_out); - pr_err("failed to prepare LUO FDT: %d\n", err); + pr_err("failed to prepare LUO state: %d\n", err); =20 return err; } @@ -226,7 +191,7 @@ static int __init luo_late_startup(void) if (!liveupdate_enabled()) return 0; =20 - err =3D luo_fdt_setup(); + err =3D luo_state_setup(); if (err) luo_global.enabled =3D false; =20 --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF28E36AB44 for ; Fri, 29 May 2026 03:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024874; cv=none; b=afvrbP0Gw6LUYHKMHDIDPUfL+NygxSGzwP1dozDnlevqX2W2mF2pRVNI9AIjY58sJyuyRIH7yF2g/ioqQl6DvoIWqZ2GkxjMdN5pQ3KA5cBfHGstF7ymNqdkigH1hwbzgLuIK7Wh9IUYH/t+o12Nw5bxE6R+kqxwrudSaaLtCik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024874; c=relaxed/simple; bh=bhQWLj7PPI9UClPVVfb3CJJP1nHiv+tJKCbUyOi+1+A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtTWaAgcaVoisebzvXIOzZtk8kY2/0gRf5gMlUSrvfqbt8TjF142F6OdU1pabR/HYyP9WbzE/jVsMztb6S8egyfFgQq4rkMIbhr9u2BqupUffhMMX3i19KA0dpMMu3ky6OiFc5TllXeZ5LyZ6R/xieHlkQmDhLGlFKfBgiYXKgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=RSUdtj1i; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="RSUdtj1i" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-516d15ed2bcso69454061cf.0 for ; Thu, 28 May 2026 20:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024872; x=1780629672; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M0UeBGKKNpBDiXtsHx+XK9ecjuYaKOuvdeJHksP7ylQ=; b=RSUdtj1iv4ikZk0d6urv7HtstgD6B8wERnFfiYZdQj+MW1MUqPbhlN60CyKycnMKuQ 3DYkcwQFoLw33eD8Cm5w7PMQkM0FvarG4eaht7ZOrD1sDLavojIDMUvYHe3ovvgH/CS+ +R1WpGBLOCujcJ3iEv3QFy3anm7ggl2G4V26yQ+gs36S+z6nyigN5PZG35+jNFfRbfor C6jYT4IMaxNvy0kD0Ayur4QSy06Ujq8mfBRwp02M6oBG2+zcRdKezBIBUoy2jEmMxBgv oVm6Xm3ndYcsGllHUhhrPQ55bqzep9mBHSTorDQVlg4MW0F4JSIlUM+fZcZZI266fb0t VOkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024872; x=1780629672; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=M0UeBGKKNpBDiXtsHx+XK9ecjuYaKOuvdeJHksP7ylQ=; b=qtJdGO+gHukai8SgTnFamCLcw3BZjiNfC9rfM8b1JfJWBAn7GfXnsBVLo+00cf0UuN W3owCmmuQmX1Ep4lCQcrED9uhK5wLp7Oy2kvHCikqu1YoLeqC39pqmx6jnW3oMD+Asjy epPU8ObkBnSzzRj8evv/ag8DEUPYR+XvTK1VR4hZjMNPH4JDnizjqMJlLD6ntRDgcdZT b0LOIzmZRNp4+cDZ39T0olLRBDKtkXgHGrk87uAo8wL/SJKcOppLwX2qSu/Y2ceBHE8N kedPqrKh/axekzaIagpGkCWba3visitXxkLGMJjj+G2VMD4aJIE5kdEk8Yai1J/XJ0kC kjVw== X-Forwarded-Encrypted: i=1; AFNElJ+dKtV/mzuWpG8LNDUTNvmocIqXDlHHOlrryASmpMzbDng2rql/KJO/oSm+2LDocAk2F9achvS2uOMEqlA=@vger.kernel.org X-Gm-Message-State: AOJu0YzDwhdVXY9dPnjy1DK8bchPwCBpuKi6TLzYMCTj1NZP7dwpC+x8 YS6BQF0kH0maMugmHTKX51DvEZfUlEpPJ50nOXHAJvk0tPX5zld7oC1t3Qw5vH1Yb9I= X-Gm-Gg: Acq92OGEZu1vtcRlghqpGqa50CY3ChAOxNqhImA/1ue13JLlCeYX9vW1xmoJPXxI2eV e2jDR8sqlLusidyyUnPqttMwxQFeYWJ6/p9gwqdPdNCdRf6OOgWSKTL16lWr6v5xFSYMeavdkb7 SRJQPlM5/Q8+dEaMZA3hj7GcOCjR3RlTuq4jsf+rxwFVNK0+E1iKxz+Sq3XMMknRaHYea+Sa2Ia +e/qXfibzYj80rqTiPLk0/JKZdsh46YKD+H4rYnqxuVPpfQZwaU7UYxoQ1B2Mo26wk3Dfh9r1EF TpoGrAnCw5oE6gv9l+3d8AmD9RX/bDm4m26FZ17BiMFQWTXm/nB4RRvTJ0fZLuR7cdXI9pXrOWZ w4yHbHmv1DPaGSiMZOwWVx1Iviqd5EwAS+eFzYhpcAqn6VmbuhK3iDpzrT7HnBslYA3WTaAbqdk 3+7F5Yb66Xm6hN1xab1DemdKUiHchoZCYVKBaNJP0mm/fzrb8cUn7ezrDSFNwuN/U6KKLj/StF X-Received: by 2002:a05:622a:1b9f:b0:516:9b30:f025 with SMTP id d75a77b69052e-5172dbbc5e5mr13902181cf.15.1780024871947; Thu, 28 May 2026 20:21:11 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:11 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 03/11] liveupdate: Extract luo_file_deserialize_one helper Date: Fri, 29 May 2026 03:20:58 +0000 Message-ID: <20260529032106.1505796-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract the logic for deserializing single entries for files into separate helper functions. In preparation to a linked-block serialization for files. This is a pure code movement, no other changes intended. Acked-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav (Google) Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_file.c | 77 ++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 208987502f73..9eec07a9e9fc 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -753,6 +753,46 @@ int luo_file_finish(struct luo_file_set *file_set) return 0; } =20 +static int luo_file_deserialize_one(struct luo_file_set *file_set, + struct luo_file_ser *ser) +{ + struct liveupdate_file_handler *fh; + bool handler_found =3D false; + struct luo_file *luo_file; + + down_read(&luo_register_rwlock); + list_private_for_each_entry(fh, &luo_file_handler_list, list) { + if (!strcmp(fh->compatible, ser->compatible)) { + if (try_module_get(fh->ops->owner)) + handler_found =3D true; + break; + } + } + up_read(&luo_register_rwlock); + + if (!handler_found) { + pr_warn("No registered handler for compatible '%.*s'\n", + (int)sizeof(ser->compatible), + ser->compatible); + return -ENOENT; + } + + luo_file =3D kzalloc_obj(*luo_file); + if (!luo_file) { + module_put(fh->ops->owner); + return -ENOMEM; + } + + luo_file->fh =3D fh; + luo_file->file =3D NULL; + luo_file->serialized_data =3D ser->data; + luo_file->token =3D ser->token; + mutex_init(&luo_file->mutex); + list_add_tail(&luo_file->list, &file_set->files_list); + + return 0; +} + /** * luo_file_deserialize - Reconstructs the list of preserved files in the = new kernel. * @file_set: The incoming file_set to fill with deserialized data. @@ -782,6 +822,7 @@ int luo_file_deserialize(struct luo_file_set *file_set, struct luo_file_set_ser *file_set_ser) { struct luo_file_ser *file_ser; + int err; u64 i; =20 if (!file_set_ser->files) { @@ -809,39 +850,9 @@ int luo_file_deserialize(struct luo_file_set *file_set, */ file_ser =3D file_set->files; for (i =3D 0; i < file_set->count; i++) { - struct liveupdate_file_handler *fh; - bool handler_found =3D false; - struct luo_file *luo_file; - - down_read(&luo_register_rwlock); - list_private_for_each_entry(fh, &luo_file_handler_list, list) { - if (!strcmp(fh->compatible, file_ser[i].compatible)) { - if (try_module_get(fh->ops->owner)) - handler_found =3D true; - break; - } - } - up_read(&luo_register_rwlock); - - if (!handler_found) { - pr_warn("No registered handler for compatible '%.*s'\n", - (int)sizeof(file_ser[i].compatible), - file_ser[i].compatible); - return -ENOENT; - } - - luo_file =3D kzalloc_obj(*luo_file); - if (!luo_file) { - module_put(fh->ops->owner); - return -ENOMEM; - } - - luo_file->fh =3D fh; - luo_file->file =3D NULL; - luo_file->serialized_data =3D file_ser[i].data; - luo_file->token =3D file_ser[i].token; - mutex_init(&luo_file->mutex); - list_add_tail(&luo_file->list, &file_set->files_list); + err =3D luo_file_deserialize_one(file_set, &file_ser[i]); + if (err) + return err; } =20 return 0; --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F29D7369D74 for ; Fri, 29 May 2026 03:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024877; cv=none; b=aVO/zwVJBznJ7DK+C29BnwS72CUVktoy2bJ7yWbwSkMfs5jn1MHipURb2phjfG8FYeKTwmtgILkP4Rvo3dXZ27EYOK76yaIaEUVGMRGV8ih8sGWJZXie1y/5wDkgwucYkFDmXkwlOezNOp1VoNLcQLPtyyJcIiytArpZ+lcfF44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024877; c=relaxed/simple; bh=xCG7g8cTS3rmmUschcRtrqLp0HBhvgU8+TA0v+hFl3c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NWOhM8LBXS7ruiZaL9gJrITmkM4J8kH/aIOvQdQpuiHLggDu4VPOdpmWxiCsVASAJAGEpWKZ9JN3TUFHxgOuYY9J4Sd/TLWxLix3yunn04JxHAqT89e179xW8pWcUji0wwQG2LTi2wRnGtdmMUCSYEc+Y+F12LTF7etK76vX5wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=R6xKxLoi; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="R6xKxLoi" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-516d78df76aso73839151cf.3 for ; Thu, 28 May 2026 20:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024873; x=1780629673; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NpCsC6C+qH6VW/iV99P+6fjIK3KTX0m1gB7hOlYbVxk=; b=R6xKxLoiNylJGGSWvr9N87evrpNXQpaMRkdWjXxiAPcbuhpMaLnRHkTA4aKwPhAbPS +v4VPUSNr4qDKI7EmBVsi0BmZqWeSlcqzaabvROpDNYvdAcKZFdLODJ39FoB80n22Qku lxlk8TMMzB92c2QMmHIgnjIBt7+MZEbdnrdAlpkmp2tUD75r53LOlCbnKa/x8eKr3hBY QFefoKOwij2xQ1WUdk0PSWtXN3cQ+9+WhnuaQ6Y8w4tRkDrvJbxW8t2vkuhsoa58DO7y m3ya93a86XerfTxspWebyeW2hwD20DDftBy8ePmHtiVWgHUsh1iIcRcfOmTRmiqDeU+a 5LuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024873; x=1780629673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NpCsC6C+qH6VW/iV99P+6fjIK3KTX0m1gB7hOlYbVxk=; b=hH0hXGOGANbYq91ELKVgAjCnJtu6OsCyVKAQJjfd+Z3YUmcQhRZDIXpCXHNOLlA/d9 gyYh3+kUo0we86tUQStAllwVMKYUFBKPNkz7cqJLk/J3IjYGsKrbg7XXkwTCt/76q3WI hLBMV3gMf0EkoqQUFoA0I/+Waalkmoeem0x+42CJx/xI5OxZPELJWc+2yCJbqxQxXN1v XfvRFMPH00xNwtDEf8JcQN7U6BSsQVefDzOLOWKWYqMVSTC+/CXR3PTkJlCQ0sTUip+d OpBTPnKwzx+DeTZw0ATx/O/xLZ6J8Zu7DMxVcOQjUzNThPCZKJ3xZyvzaJmHByO9b6GZ D5gA== X-Forwarded-Encrypted: i=1; AFNElJ+GVMDBcCNxke/WQWB/uo//1SnwIv7JN0+IBLGTfyHAfopazciUDgnli5zF2GiPo5u2WA5+QiZ+f459g5o=@vger.kernel.org X-Gm-Message-State: AOJu0YxgFAo9WIPFmESy02gSKtpPdW9DxC8bh+a8u95ra3q783QLujzj MnP05cRCioK6Zzv09LurzAvxUiztCbzPMJmT0Jb7t5dxu2RIohLln6Of6sypv4mm/Ic= X-Gm-Gg: Acq92OEIC96lL75f8MabV13WyqR7PjZha65GngSIRC1FSFC2WBRBOQMQw76WhV0eOpv O+fY9QS6Gs2NRgT8KmKUeGkWqRWiLt0/HuwYP9u2BtGDzEC2h8pHjVa3CRVA9e8k8DfYcABxdCX h01PzXRfkpAF9IUqBj0pjHSbTv24hVa30oyjXiBKQF+7/BUC1NRdLSrZZ22N9Qfa9L//kAkGh42 3liEOJ6mH4TM3MMQ9XsoQmlFfLonpm/Si8NM+0aUTqKg8ScEGDxmJlvgbU4tgggshyt3QN0FU3j Gi9i5kW9OU36RhCywirNcPZTADx00QC5FICcyn7SricFXLnF+qXsk6jZOoOpCXv7gRSoHGHhrfj YNG+y9MTmu7d0hiyZ35ImrAIglB5LaVIqXZWsAZqlXlIk0XtwudeMXZ9qq6dqbaOZ1HUxl61160 5ykvsi8W78lARz1sMKyml+kEi9gcY90A3RGvNhivxJ8DUTTqq6DaZ6VoQnF/tw0Q== X-Received: by 2002:a05:622a:4c1b:b0:516:d955:ea2 with SMTP id d75a77b69052e-5172daa1350mr16395121cf.0.1780024873082; Thu, 28 May 2026 20:21:13 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:12 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 04/11] liveupdate: Extract luo_session_deserialize_one helper Date: Fri, 29 May 2026 03:20:59 +0000 Message-ID: <20260529032106.1505796-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract the logic for deserializing single entries for sessions into separate helper functions. In preparation to a linked-block serialization for sessions. This is a pure code movement, no other changes intended. Acked-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav (Google) Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_session.c | 62 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_sessio= n.c index 1cad54ea8209..5c092c71797e 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -526,6 +526,40 @@ int __init luo_session_setup_incoming(u64 sessions_pa) return 0; } =20 +static int luo_session_deserialize_one(struct luo_session_header *sh, + struct luo_session_ser *ser) +{ + struct luo_session *session; + int err; + + session =3D luo_session_alloc(ser->name); + if (IS_ERR(session)) { + pr_warn("Failed to allocate session [%.*s] during deserialization %pe\n", + (int)sizeof(ser->name), ser->name, session); + return PTR_ERR(session); + } + + err =3D luo_session_insert(sh, session); + if (err) { + pr_warn("Failed to insert session [%s] %pe\n", + session->name, ERR_PTR(err)); + luo_session_free(session); + return err; + } + + scoped_guard(mutex, &session->mutex) { + err =3D luo_file_deserialize(&session->file_set, + &ser->file_set_ser); + } + if (err) { + pr_warn("Failed to deserialize files for session [%s] %pe\n", + session->name, ERR_PTR(err)); + return err; + } + + return 0; +} + int luo_session_deserialize(void) { struct luo_session_header *sh =3D &luo_session_global.incoming; @@ -556,33 +590,9 @@ int luo_session_deserialize(void) * reliably reset devices and reclaim memory. */ for (int i =3D 0; i < sh->header_ser->count; i++) { - struct luo_session *session; - - session =3D luo_session_alloc(sh->ser[i].name); - if (IS_ERR(session)) { - pr_warn("Failed to allocate session [%.*s] during deserialization %pe\n= ", - (int)sizeof(sh->ser[i].name), - sh->ser[i].name, session); - return PTR_ERR(session); - } - - err =3D luo_session_insert(sh, session); - if (err) { - pr_warn("Failed to insert session [%s] %pe\n", - session->name, ERR_PTR(err)); - luo_session_free(session); - return err; - } - - scoped_guard(mutex, &session->mutex) { - err =3D luo_file_deserialize(&session->file_set, - &sh->ser[i].file_set_ser); - } - if (err) { - pr_warn("Failed to deserialize files for session [%s] %pe\n", - session->name, ERR_PTR(err)); + err =3D luo_session_deserialize_one(sh, &sh->ser[i]); + if (err) return err; - } } =20 kho_restore_free(sh->header_ser); --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84FE336A351 for ; Fri, 29 May 2026 03:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024877; cv=none; b=Bb8wZe4OKQB9HWRaocy/T730VS0t8wExCHxRUVMxopmqGtaWVop55XZKvo5eluNG2S8L05W7qLHynnFoiJR/xp1kCkT51EAs347caL5PoJN8FgwgL+j1yhHDWEiek8/M2c5mg/7MWhwOAcqJHSr78w+xo+f8VKzFXuqI8oA2hSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024877; c=relaxed/simple; bh=5jL0a8MXVIph/vKzNDTSGTFp4zQ0RDqIMhCkTt+Y0tI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O048oZ+yXwI7lndG7eLfADMiA6m7a8l4OWh1/dS5zCPSFt0r1Jj3ep71emkBnBcyTHUv2AssdAL5pcrHMh15wn20VHEHA0Q85/TIsDbAmrUcTJThu1GZePByxa8Lpk5QkHWIyWLO7ybSoJ4nhSb0le6uPtZ7OAv6sAQLoaPlG5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=VOGopAgs; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="VOGopAgs" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-8b7105dfb35so171355566d6.3 for ; Thu, 28 May 2026 20:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024874; x=1780629674; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=IVSXk0/56skBmRqrLRSaTWUlJtVH0b3/3ym1O9cV9BM=; b=VOGopAgsWk1OpFPh5vZojspTPN9hjkmP4vyPXRakYh3EpA2B0FjegInLD5Gm2ZL+c6 ZUCtKZxd4njGczrDazG+ebnqSrYfOFiJRFwAH9m+iDwhpmZj3FiNxDj1JE9d0PgdedWk TA4uUt+CapD8yXxq9gAEV7T2J50182Nyi1ENlxM1FoT4Le01MgMwsGOdXdujOZ4OCFK9 1/onZJokomsdCn/3zhLyz2x4jjLAhOJBjqVIBM/rLwWGl/em7njqVKOeVyZj0Rg8/ihn +9ifqq+UkHBL2uyH/4pHOovbfg4/flb3m7rquIlbccxiKBMAygULkmmLv5JyU0BkWfI9 CQzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024874; x=1780629674; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IVSXk0/56skBmRqrLRSaTWUlJtVH0b3/3ym1O9cV9BM=; b=CgZI/vt377jPdhnXMyTbgfyHjVnNyvb6DBcxR1q7PlC28e0lmWM4TGaV/yL3a6aiOK coW7Tzk19M4WRVBzY6YkNGsmSV3KhulqV2lk1yHAzlFgrFYI7MBl9lXAIqtiUx9CfGPR JzMYbJ/i3SWFbxrAGce3wahktNebflp8o+q7cBP2qWOgVBNSSs06tyzytggCCr+kXB1/ Fi3qMkXcuFO26jEr3raEmlHJDzCRVubQYwd7IGhWY+i/bjA8oL5eXhmyBLUitG/95CDq mJhCdDHBbzjXFVJx9rPi41gbPZbylLc3IKJSZBm1Mus1cVdJUb24LoMmO6fPFO44Bkpk SGHg== X-Forwarded-Encrypted: i=1; AFNElJ9EQo4wfHkHF8c8aM3c8Rk9yGc8MqVnzxAHiHXr/iIdJEqj+U47DxeTQIDCjgTSYEHB+iMSaRx8izhk4Iw=@vger.kernel.org X-Gm-Message-State: AOJu0YwlckOmNVjKIIkyYb3HxHQlzJeVUGGskRcAj8PTwVLN+uAQRIGv fRnU7+fIi1pJ7isVpf93PB9y4DH/BrJGm7el10iMG3Nf1azXitvE+ZJ2bfGoFQHf2S8= X-Gm-Gg: Acq92OFMupO/MUvVwyRpnMTN2zGATwgrO+/1rNovENuGhpRKCQ2AzhrhrKRqDoerRo9 9XdMNdkVa6cv1QbS+XDoK/3AXnpzTEm+tLVhFQ7QPwJop00VcH4/en+pD2b+p/UZ1JouIAcco/w MtDx/g1KfSdtRPinACQ4AqkdTeTTpD6YFxBADlMuqF4jRPDKaT4w3hR5IqfAfshkLnJidPt7wTd x0s0GasvwvuCJB0hWRyqRAgvuTR0G0Lo7F7kfd1r4VfXUGfbQ1JJwHm4nuPt8OQ6m+941ad36Wc mTsexziR68kLGt8ozk+z3TRiYIX207Bpf/azNBV+T/63GCo/wA6EcBzVnW8EcLhdonCATCGrOBz SG8N/LXVb+kdcLlsh8shq6W5YElmlqDrZ/GZleH4J3VeM9AiwDOENHz3YBMYiWT34jPMECYuDoj 3L4ADdhp5Flo0XtmhPubsM7QY+xtx3pMMQpjF6zDGQb9dpHKIwlXVD/R5++2MO3GanuLcgOPrT X-Received: by 2002:a05:6214:4347:b0:8c3:f47f:50f8 with SMTP id 6a1803df08f44-8cce7a1f616mr15839496d6.0.1780024874311; Thu, 28 May 2026 20:21:14 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:13 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 05/11] kho: add support for linked-block serialization Date: Fri, 29 May 2026 03:21:00 +0000 Message-ID: <20260529032106.1505796-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a linked-block serialization mechanism for state handover. Previously, LUO used contiguous memory blocks for serializing sessions and files, which imposed limits on the total number of items that could be preserved across a live update. This commit adds the infrastructure for a more flexible, block-based approach where serialized data is stored in a chain of linked blocks. This is a generic KHO serialization block infrastructure that can be used by multiple subsystems. Signed-off-by: Pasha Tatashin --- Documentation/core-api/kho/abi.rst | 5 + Documentation/core-api/kho/index.rst | 11 + MAINTAINERS | 1 + include/linux/kho/abi/block.h | 56 ++++ include/linux/kho_block.h | 79 ++++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/kho_block.c | 382 +++++++++++++++++++++++++++ 7 files changed, 535 insertions(+) create mode 100644 include/linux/kho/abi/block.h create mode 100644 include/linux/kho_block.h create mode 100644 kernel/liveupdate/kho_block.c diff --git a/Documentation/core-api/kho/abi.rst b/Documentation/core-api/kh= o/abi.rst index 799d743105a6..edeb5b311963 100644 --- a/Documentation/core-api/kho/abi.rst +++ b/Documentation/core-api/kho/abi.rst @@ -28,6 +28,11 @@ KHO persistent memory tracker ABI .. kernel-doc:: include/linux/kho/abi/kexec_handover.h :doc: KHO persistent memory tracker =20 +KHO serialization block ABI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +.. kernel-doc:: include/linux/kho/abi/block.h + See Also =3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/Documentation/core-api/kho/index.rst b/Documentation/core-api/= kho/index.rst index 0a2dee4f8e7d..320914a42178 100644 --- a/Documentation/core-api/kho/index.rst +++ b/Documentation/core-api/kho/index.rst @@ -83,6 +83,17 @@ Public API .. kernel-doc:: kernel/liveupdate/kexec_handover.c :export: =20 +KHO Serialization Blocks API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +.. kernel-doc:: kernel/liveupdate/kho_block.c + :doc: KHO Serialization Blocks + +.. kernel-doc:: include/linux/kho_block.h + +.. kernel-doc:: kernel/liveupdate/kho_block.c + :internal: + See Also =3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/MAINTAINERS b/MAINTAINERS index 2fb1c75afd16..fd119b343e99 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14194,6 +14194,7 @@ F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h F: include/linux/kho/ +F: include/linux/kho_block.h F: kernel/liveupdate/kexec_handover* F: lib/test_kho.c F: tools/testing/selftests/kho/ diff --git a/include/linux/kho/abi/block.h b/include/linux/kho/abi/block.h new file mode 100644 index 000000000000..8641c20b379b --- /dev/null +++ b/include/linux/kho/abi/block.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: KHO Serialization Blocks ABI + * + * Subsystems using the KHO Serialization Blocks framework rely on the sta= ble + * Application Binary Interface defined below to pass serialized state fro= m a + * pre-update kernel to a post-update kernel. + * + * This interface is a contract. Any modification to the structure fields, + * compatible strings, or the layout of the `__packed` serialization + * structures defined here constitutes a breaking change. Such changes req= uire + * incrementing the version number in the `KHO_BLOCK_ABI_COMPATIBLE` strin= g to + * prevent a new kernel from misinterpreting data from an old kernel. + * + * Changes are allowed provided the compatibility version is incremented; + * however, backward/forward compatibility is only guaranteed for kernels + * supporting the same ABI version. + */ + +#ifndef _LINUX_KHO_ABI_BLOCK_H +#define _LINUX_KHO_ABI_BLOCK_H + +#include +#include + +#define KHO_BLOCK_ABI_COMPATIBLE "kho-block-v1" + +/** + * KHO_BLOCK_SIZE - The size of each serialization block. + * + * This is defined as PAGE_SIZE. PAGE_SIZE is ABI compliant because live + * update between kernels with different page sizes is not supported by KH= O. + */ +#define KHO_BLOCK_SIZE PAGE_SIZE + +/** + * struct kho_block_header_ser - Header for the serialized data block. + * @next: Physical address of the next struct kho_block_header_ser. + * @count: The number of entries that immediately follow this header in the + * memory block. + * + * This structure is located at the beginning of a block of physical memory + * preserved across a kexec. It provides the necessary metadata to interpr= et + * the array of entries that follow. + */ +struct kho_block_header_ser { + u64 next; + u64 count; +} __packed; + +#endif /* _LINUX_KHO_ABI_BLOCK_H */ diff --git a/include/linux/kho_block.h b/include/linux/kho_block.h new file mode 100644 index 000000000000..5e6b87b1befa --- /dev/null +++ b/include/linux/kho_block.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026, Google LLC. + * Pasha Tatashin + */ + +#ifndef _LINUX_KHO_BLOCK_H +#define _LINUX_KHO_BLOCK_H + +#include +#include +#include + +/** + * struct kho_block - Internal representation of a serialization block. + * @list: List head for linking blocks in memory. + * @ser: Pointer to the serialized header in preserved memory. + */ +struct kho_block { + struct list_head list; + struct kho_block_header_ser *ser; +}; + +/** + * struct kho_block_set - A set of blocks that belong to the same object. + * @blocks: The list of serialization blocks (struct kho_block). + * @nblocks: The number of allocated serialization blocks. + * @head_pa: Physical address of the first block header. + * @entry_size: The size of each entry in the blocks. + * @count_per_block: The maximum number of entries each block can hold. + * @incoming: True if this block set was restored from the previous= kernel. + */ +struct kho_block_set { + struct list_head blocks; + long nblocks; + u64 head_pa; + size_t entry_size; + u64 count_per_block; + bool incoming; +}; + +/** + * struct kho_block_it - Iterator for serializing entries into blocks. + * @bs: The block set being iterated. + * @block: The current block. + * @i: The current entry index within @block. + */ +struct kho_block_it { + struct kho_block_set *bs; + struct kho_block *block; + u64 i; +}; + +/** + * KHO_BLOCK_SET_INIT - Initialize a static kho_block_set. + * @_name: Name of the kho_block_set variable. + * @_entry_size: The size of each entry in the block set. + */ +#define KHO_BLOCK_SET_INIT(_name, _entry_size) { \ + .blocks =3D LIST_HEAD_INIT((_name).blocks), \ + .entry_size =3D _entry_size, \ +} + +void kho_block_set_init(struct kho_block_set *bs, size_t entry_size); + +int kho_block_grow(struct kho_block_set *bs, u64 count); +void kho_block_shrink(struct kho_block_set *bs, u64 count); + +int kho_block_restore(struct kho_block_set *bs, u64 head_pa); +void kho_block_destroy(struct kho_block_set *bs); +void kho_block_set_clear(struct kho_block_set *bs); + +void kho_block_it_init(struct kho_block_it *it, struct kho_block_set *bs); +void *kho_block_it_next(struct kho_block_it *it); +void *kho_block_it_read(struct kho_block_it *it); +void *kho_block_it_prev(struct kho_block_it *it); +void kho_block_it_finalize(struct kho_block_it *it); + +#endif /* _LINUX_KHO_BLOCK_H */ diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index d2f779cbe279..eec9d3ae07eb 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 =20 luo-y :=3D \ + kho_block.o \ luo_core.o \ luo_file.o \ luo_flb.o \ diff --git a/kernel/liveupdate/kho_block.c b/kernel/liveupdate/kho_block.c new file mode 100644 index 000000000000..c781c1e36056 --- /dev/null +++ b/kernel/liveupdate/kho_block.c @@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2026, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: KHO Serialization Blocks + * + * KHO provides a mechanism to preserve stateful data across a kexec hando= ver + * by serializing it into memory blocks. This file provides the common + * infrastructure for managing these blocks. + * + * Each block consists of a header (struct kho_block_header_ser) followed = by an + * array of serialized entries. Multiple blocks are linked together via a + * physical pointer in the header, forming a linked list that can be easily + * traversed in both the current and the next kernel. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include + +/* + * Safeguard limit for the number of serialization blocks. This is used to + * prevent infinite loops and excessive memory allocation in case of memory + * corruption in the preserved state. + */ +#define KHO_MAX_BLOCKS 10000 + +/** + * kho_block_set_init - Initialize a block set. + * @bs: The block set to initialize. + * @entry_size: The size of each entry in the blocks. + */ +void kho_block_set_init(struct kho_block_set *bs, size_t entry_size) +{ + *bs =3D (struct kho_block_set)KHO_BLOCK_SET_INIT(*bs, entry_size); +} + +static inline u64 kho_block_count_per_block(struct kho_block_set *bs) +{ + if (unlikely(!bs->count_per_block)) { + bs->count_per_block =3D (KHO_BLOCK_SIZE - + sizeof(struct kho_block_header_ser)) / + bs->entry_size; + WARN_ON(!bs->count_per_block); + } + return bs->count_per_block; +} + +/* Free serialized data */ +static void kho_block_free_ser(struct kho_block_set *bs, + struct kho_block_header_ser *ser) +{ + if (bs->incoming) + kho_restore_free(ser); + else + kho_unpreserve_free(ser); +} + +static struct kho_block_header_ser *kho_block_alloc_ser(struct kho_block_s= et *bs) +{ + WARN_ON(bs->incoming); + return kho_alloc_preserve(KHO_BLOCK_SIZE); +} + +static int kho_block_add(struct kho_block_set *bs, + struct kho_block_header_ser *ser) +{ + struct kho_block *block, *last; + + if (bs->nblocks >=3D KHO_MAX_BLOCKS) + return -ENOSPC; + + block =3D kzalloc_obj(*block); + if (!block) + return -ENOMEM; + + block->ser =3D ser; + last =3D list_last_entry_or_null(&bs->blocks, struct kho_block, list); + list_add_tail(&block->list, &bs->blocks); + bs->nblocks++; + + if (last) + last->ser->next =3D virt_to_phys(ser); + else + bs->head_pa =3D virt_to_phys(ser); + + return 0; +} + +/** + * kho_block_grow - Create a new block if the current capacity is reached. + * @bs: The block set. + * @count: The current number of entries. + * + * This function handles the dynamic expansion of a block set. It allocates + * and links a new serialization block if the provided entry count matches + * the current total capacity of the set. + * + * Return: 0 on success, or a negative errno on failure. + */ +int kho_block_grow(struct kho_block_set *bs, u64 count) +{ + struct kho_block_header_ser *ser; + int err; + + if (WARN_ON(bs->incoming)) + return -EINVAL; + + if (count !=3D bs->nblocks * kho_block_count_per_block(bs)) + return 0; + + ser =3D kho_block_alloc_ser(bs); + if (IS_ERR(ser)) + return PTR_ERR(ser); + + err =3D kho_block_add(bs, ser); + if (err) { + kho_block_free_ser(bs, ser); + return err; + } + + return 0; +} + +/** + * kho_block_shrink - Conditionally destroy the last block in a block set. + * @bs: The block set. + * @count: The current number of entries across all blocks. + * + * This function checks if the last block in the set is redundant based on= the + * total entry count and the capacity of the preceding blocks. If the entry + * count can be accommodated by the blocks that come before the last one, = the + * last block is destroyed and removed from the set. + */ +void kho_block_shrink(struct kho_block_set *bs, u64 count) +{ + struct kho_block *last, *new_last; + + if (count > (bs->nblocks - 1) * kho_block_count_per_block(bs)) + return; + + if (list_empty(&bs->blocks)) + return; + + last =3D list_last_entry(&bs->blocks, struct kho_block, list); + list_del(&last->list); + bs->nblocks--; + kho_block_free_ser(bs, last->ser); + kfree(last); + + new_last =3D list_last_entry_or_null(&bs->blocks, struct kho_block, list); + if (new_last) + new_last->ser->next =3D 0; + else + bs->head_pa =3D 0; +} + +/* + * kho_cyclic_blocks_check - Check for cycles in a linked list of blocks. + * Uses Floyd's cycle-finding algorithm to ensure sanity of the incoming l= ist. + */ +static bool kho_cyclic_blocks_check(struct kho_block_set *bs) +{ + struct kho_block_header_ser *fast; + struct kho_block_header_ser *slow; + int count =3D 0; + + fast =3D phys_to_virt(bs->head_pa); + slow =3D fast; + + while (fast) { + if (count++ >=3D KHO_MAX_BLOCKS) { + pr_err("Linked list too long\n"); + return false; + } + + if (!fast->next) + break; + + fast =3D phys_to_virt(fast->next); + if (!fast->next) + break; + + fast =3D phys_to_virt(fast->next); + slow =3D phys_to_virt(slow->next); + + if (slow =3D=3D fast) { + pr_err("Cyclic list detected\n"); + return false; + } + } + + return true; +} + +/** + * kho_block_restore - Restore a block set from a physical address. + * @bs: The block set to restore. + * @head_pa: Physical address of the first block header. + * + * Return: 0 on success, or a negative errno on failure. + */ +int kho_block_restore(struct kho_block_set *bs, u64 head_pa) +{ + struct kho_block_header_ser *ser; + u64 next_pa =3D head_pa; + int err; + + /* Restored block sets use size from the previous kernel */ + bs->incoming =3D true; + if (!head_pa) + return 0; + + bs->head_pa =3D head_pa; + if (!kho_cyclic_blocks_check(bs)) + return -EINVAL; + + while (next_pa) { + ser =3D phys_to_virt(next_pa); + if (ser->count > kho_block_count_per_block(bs)) { + pr_warn("Block contains too many entries: %llu\n", + ser->count); + err =3D -EINVAL; + goto err_destroy; + } + err =3D kho_block_add(bs, ser); + if (err) + goto err_destroy; + next_pa =3D ser->next; + } + + return 0; + +err_destroy: + kho_block_destroy(bs); + return err; +} + +/** + * kho_block_destroy - Destroy all blocks in a block set. + * @bs: The block set. + */ +void kho_block_destroy(struct kho_block_set *bs) +{ + u64 head_pa =3D bs->head_pa; + struct kho_block *block; + + while (!list_empty(&bs->blocks)) { + block =3D list_first_entry(&bs->blocks, struct kho_block, list); + list_del(&block->list); + kfree(block); + } + bs->nblocks =3D 0; + bs->head_pa =3D 0; + + while (head_pa) { + struct kho_block_header_ser *ser =3D phys_to_virt(head_pa); + + head_pa =3D ser->next; + kho_block_free_ser(bs, ser); + } +} + +/** + * kho_block_set_clear - Clear all serialized data in a block set. + * @bs: The block set to clear. + */ +void kho_block_set_clear(struct kho_block_set *bs) +{ + struct kho_block *block; + + list_for_each_entry(block, &bs->blocks, list) { + block->ser->count =3D 0; + memset(block->ser + 1, 0, KHO_BLOCK_SIZE - sizeof(*block->ser)); + } +} + +/** + * kho_block_it_init - Initialize a block set iterator. + * @it: The iterator to initialize. + * @bs: The block set to iterate over. + */ +void kho_block_it_init(struct kho_block_it *it, struct kho_block_set *bs) +{ + it->bs =3D bs; + it->block =3D list_first_entry_or_null(&bs->blocks, struct kho_block, lis= t); + it->i =3D 0; +} + +/** + * kho_block_it_next - Return the next entry slot in the block set. + * @it: The block iterator. + * + * If the current block is full, it automatically advances to the next blo= ck + * in the set. + * + * Return: A pointer to the next entry slot, or NULL if no more slots are + * available. + */ +void *kho_block_it_next(struct kho_block_it *it) +{ + if (!it->block) + return NULL; + + if (it->i =3D=3D kho_block_count_per_block(it->bs)) { + it->block->ser->count =3D it->i; + if (list_is_last(&it->block->list, &it->bs->blocks)) + return NULL; + it->block =3D list_next_entry(it->block, list); + it->i =3D 0; + } + + return (void *)(it->block->ser + 1) + (it->i++ * it->bs->entry_size); +} + +/** + * kho_block_it_read - Return the next entry slot for reading. + * @it: The block iterator. + * + * This function iterates through entries that were previously serialized, + * respecting the count stored in each block's header. + * + * Return: A pointer to the next entry slot, or NULL if no more entries are + * available. + */ +void *kho_block_it_read(struct kho_block_it *it) +{ + if (!it->block) + return NULL; + + while (it->i =3D=3D it->block->ser->count) { + if (list_is_last(&it->block->list, &it->bs->blocks)) + return NULL; + it->block =3D list_next_entry(it->block, list); + it->i =3D 0; + } + + return (void *)(it->block->ser + 1) + (it->i++ * it->bs->entry_size); +} + +/** + * kho_block_it_prev - Return the previous entry slot in the block set. + * @it: The block iterator. + * + * If the current index is at the start of a block, it automatically moves= to + * the end of the previous block. + * + * Return: A pointer to the previous entry slot, or NULL if at the very + * beginning of the block set. + */ +void *kho_block_it_prev(struct kho_block_it *it) +{ + if (!it->block) + return NULL; + + if (it->i =3D=3D 0) { + if (list_is_first(&it->block->list, &it->bs->blocks)) + return NULL; + it->block =3D list_prev_entry(it->block, list); + it->i =3D kho_block_count_per_block(it->bs); + } + + return (void *)(it->block->ser + 1) + (--it->i * it->bs->entry_size); +} + +/** + * kho_block_it_finalize - Finalize the current block by setting its entry= count. + * @it: The block iterator. + */ +void kho_block_it_finalize(struct kho_block_it *it) +{ + if (it->block) + it->block->ser->count =3D it->i; +} --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D964836D9EE for ; Fri, 29 May 2026 03:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024878; cv=none; b=maqEAB3w62+bpYAHDU++T/BH1UdH7AEhBKhw8mLY+5Mrf43yfL7+Z8s4fld6MsEg/l47E3654QUzvnA0Gz3hO/n8jHuyWJPyteTZQny+iNPFpFdyHlzt3CgpkmMFFqUTuPBOU+TJxnufsk6Do9gIU3n3w2AxWv9ZnjUfd5teP10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024878; c=relaxed/simple; bh=9LSRU3a1usVDXKHUxY4h/d/bYsPe3I+mUssTk71ltV4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PnCTV2RuqMR8f9NpUlEt1PUKiCTj1U9yKCLhRKKXnnXXmH/+TPi8AgZG/YvB6IG8D2gC6DgvqVTWcGw97usgJTDoOejtw6X97josIJw2XSKaUtOxWWFdMs1DECAtkSg8RrYFBT8N6Iz5t4Gc1RfdILCnCUkDk9JO7F2zj5iJ9lY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=giZ7dXUh; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="giZ7dXUh" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-8cccdea2fbdso16071256d6.1 for ; Thu, 28 May 2026 20:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024876; x=1780629676; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/lzT/uKNjiuJAcCs6ljq32s6d+IXBzBHeWWiRI2fHMI=; b=giZ7dXUhJCR+iFOptRT/THIdWf3e1MY7fkTXSXFrgpSV2teF9K5vZN90kZvJxfRtQp NvdEXGNCIwZiTbMV8lAk6E1SeaO2ytGzKy9pIU2qUw+Q7puTARw9+ZaPYM7QB1FzfUjB 0CbolnvQgBwuJeSrhiPAH4VAh7TqBND60OjSqmmjbBGN2itkxsW1dcK5fZ3kCjMYFjG5 cR6lsKWvK6La50SXvwEk3XPs+RoNgZJbRp5hnubRbHh8zqbQoFzuhmd3R/DQ7euBhqch PiWdGG15Wf9/xlvmFb634BYtjV7ITSQVGzezwsutE9JaY1vIXZ6JxiDHTPuHRFzewncn l20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024876; x=1780629676; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/lzT/uKNjiuJAcCs6ljq32s6d+IXBzBHeWWiRI2fHMI=; b=kyVMPKukHGbZLPGyIOnmoSlhKffz+b+v46CiswzWq8pzuTv8ssRQ1vkS2Wq9PklSMk GgqDO40p2UZIjf5rr4qpluw31vSlNLwy+izkJoIszvRDDzA7Lkbg+6/TWJgfIBo2WVuM M3SWZ5Zm0C/U9VRZjvZB3KbqrRY8ZvMbbWcrffEDWZ1hce5XhJTN+9PBi2+6mAUWp1EF LjP9JJf9kg6cOxyqIof5kUMFLhq23rB1etEPavGbEuSWLPFvBv3mBLF6yjs4zQeCN5Ct o/gHBt3r7GU+YKIjUMtDlw5fNzhDhIHA1MRicMDILZ7kIodEY0R/XvEMxRtgE3S/EXar fOHg== X-Forwarded-Encrypted: i=1; AFNElJ+ljtU2cFhZ5eFllI0wSYpjcvKtfIbfXRdct60yZLzxjFG26b4eB/JGtyktVOC0OSpovLkr1iYZuzaUF3o=@vger.kernel.org X-Gm-Message-State: AOJu0YwnT1t+nSbDYYkCqZsi+i7aLk8nqyKRzbDWwwl20kb1sYoh1jMS urNEhmAAoSgEV6lN8Ms7BpcNSrhMuYVitMRnMvfXK7ECgNLFbWwsBxausPoaw04RDM8= X-Gm-Gg: Acq92OH6ce4RaO8X6yafRto+CXntb1/5nm3XX6OqiyyD4elXxP6/Iai40TGRwGLbbmz gbA4MFQO6kwFJk1OYQFjzMjbCF/0rfOtKoXFtI082Jy1tC5E5sb+33/WTQW+bjfS+wSK8ERLY9K LdkimlRH7htvI4Dw9w2Edq5Sj3qQ1x8mFG6eHeHMcHCO+v/L4yCRK9jOvYiNAlppZEtmDXmafoc Mdvr68BjJd5eagYMSxjatoBmztLH9OXSfwlUbJqXKeT9nQ6BG+kqLFr68zJN7u3UbL4anYnAz0G NLUnk9hOIHvbrG+AjJtVl2h8DRFhUzPNOpDO7DiCK2c7naRH/GTM1fNiRUileJUkdVEK3Luipvs TPTaRxRm1JeDdBY1JDKGiP0rgmHEbYX0mnrliCHPqpl0FwQT937YtqWjbR3QK+DsmWctfrd07YT u0/7TVkH7puJXkpWgvWDwJQcLCUPjvHPIVQ6CNBZq2WvbjBJ0U5jqYy9XO4F3nhA== X-Received: by 2002:a05:6214:33c2:b0:8cb:d479:a103 with SMTP id 6a1803df08f44-8cce621c869mr14316046d6.20.1780024875958; Thu, 28 May 2026 20:21:15 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:15 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 06/11] liveupdate: defer session block allocation and PA setting Date: Fri, 29 May 2026 03:21:01 +0000 Message-ID: <20260529032106.1505796-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, luo_session_setup_outgoing() allocates the session block and sets its physical address in the header immediately. With upcoming dynamic block-based session management, this makes the first block different from the rest. Move the allocation to where it is first needed. Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_core.c | 4 +- kernel/liveupdate/luo_internal.h | 2 +- kernel/liveupdate/luo_session.c | 68 ++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 5e12c8f8669b..92f8c53c7a73 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -157,9 +157,7 @@ static int __init luo_state_setup(void) strscpy(luo_ser->compatible, LUO_ABI_COMPATIBLE, sizeof(luo_ser->compatib= le)); luo_ser->liveupdate_num =3D luo_global.liveupdate_num + 1; =20 - err =3D luo_session_setup_outgoing(&luo_ser->sessions_pa); - if (err) - goto exit_free_luo_ser; + luo_session_setup_outgoing(&luo_ser->sessions_pa); =20 err =3D luo_flb_setup_outgoing(&luo_ser->flbs_pa); if (err) diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 9bf26c5b1495..28ebb4f3000b 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -79,7 +79,7 @@ extern struct rw_semaphore luo_register_rwlock; =20 int luo_session_create(const char *name, struct file **filep); int luo_session_retrieve(const char *name, struct file **filep); -int __init luo_session_setup_outgoing(u64 *sessions_pa); +void __init luo_session_setup_outgoing(u64 *sessions_pa); int __init luo_session_setup_incoming(u64 sessions_pa); int luo_session_serialize(void); int luo_session_deserialize(void); diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_sessio= n.c index 5c092c71797e..ec72f16185f3 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -108,15 +108,16 @@ static DECLARE_RWSEM(luo_session_serialize_rwsem); =20 /** * struct luo_session_header - Header struct for managing LUO sessions. - * @count: The number of sessions currently tracked in the @list. - * @list: The head of the linked list of `struct luo_session` instan= ces. - * @rwsem: A read-write semaphore providing synchronized access to the - * session list and other fields in this structure. - * @header_ser: The header data of serialization array. - * @ser: The serialized session data (an array of - * `struct luo_session_ser`). - * @active: Set to true when first initialized. If previous kernel did= not - * send session data, active stays false for incoming. + * @count: The number of sessions currently tracked in the @list. + * @list: The head of the linked list of `struct luo_session` insta= nces. + * @rwsem: A read-write semaphore providing synchronized access to t= he + * session list and other fields in this structure. + * @header_ser: The header data of serialization array. + * @ser: The serialized session data (an array of + * `struct luo_session_ser`). + * @sessions_pa: Points to the location of sessions_pa within struct luo_s= er. + * @active: Set to true when first initialized. If previous kernel di= d not + * send session data, active stays false for incoming. */ struct luo_session_header { long count; @@ -124,6 +125,7 @@ struct luo_session_header { struct rw_semaphore rwsem; struct luo_session_header_ser *header_ser; struct luo_session_ser *ser; + u64 *sessions_pa; bool active; }; =20 @@ -171,10 +173,30 @@ static void luo_session_free(struct luo_session *sess= ion) kfree(session); } =20 +static int luo_session_grow_ser(struct luo_session_header *sh) +{ + struct luo_session_header_ser *header_ser; + + if (sh->count =3D=3D LUO_SESSION_MAX) + return -ENOMEM; + + if (sh->header_ser) + return 0; + + header_ser =3D kho_alloc_preserve(LUO_SESSION_PGCNT << PAGE_SHIFT); + if (IS_ERR(header_ser)) + return PTR_ERR(header_ser); + + sh->header_ser =3D header_ser; + sh->ser =3D (void *)(header_ser + 1); + return 0; +} + static int luo_session_insert(struct luo_session_header *sh, struct luo_session *session) { struct luo_session *it; + int err; =20 guard(rwsem_write)(&sh->rwsem); =20 @@ -183,8 +205,9 @@ static int luo_session_insert(struct luo_session_header= *sh, * for new session. */ if (sh =3D=3D &luo_session_global.outgoing) { - if (sh->count =3D=3D LUO_SESSION_MAX) - return -ENOMEM; + err =3D luo_session_grow_ser(sh); + if (err) + return err; } =20 /* @@ -495,21 +518,10 @@ int luo_session_retrieve(const char *name, struct fil= e **filep) return err; } =20 -int __init luo_session_setup_outgoing(u64 *sessions_pa) +void __init luo_session_setup_outgoing(u64 *sessions_pa) { - struct luo_session_header_ser *header_ser; - - header_ser =3D kho_alloc_preserve(LUO_SESSION_PGCNT << PAGE_SHIFT); - if (IS_ERR(header_ser)) - return PTR_ERR(header_ser); - - *sessions_pa =3D virt_to_phys(header_ser); - - luo_session_global.outgoing.header_ser =3D header_ser; - luo_session_global.outgoing.ser =3D (void *)(header_ser + 1); + luo_session_global.outgoing.sessions_pa =3D sessions_pa; luo_session_global.outgoing.active =3D true; - - return 0; } =20 int __init luo_session_setup_incoming(u64 sessions_pa) @@ -611,6 +623,8 @@ int luo_session_serialize(void) =20 down_write(&luo_session_serialize_rwsem); down_write(&sh->rwsem); + *sh->sessions_pa =3D 0; + list_for_each_entry(session, &sh->list, list) { err =3D luo_session_freeze_one(session, &sh->ser[i]); if (err) @@ -620,7 +634,11 @@ int luo_session_serialize(void) sizeof(sh->ser[i].name)); i++; } - sh->header_ser->count =3D sh->count; + + if (sh->header_ser && sh->count > 0) { + sh->header_ser->count =3D sh->count; + *sh->sessions_pa =3D virt_to_phys(sh->header_ser); + } up_write(&sh->rwsem); =20 return 0; --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB5F636F430 for ; Fri, 29 May 2026 03:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024880; cv=none; b=eDNnLZO8FBE1s1dEA0OXdwLAU6FkVyr8wlcjFmJv4W3FORluE6bL5usJVGRFdB7DtKdpYggUguoq8Wo3rg6H2gqRvYscdynUahD7jM/uZPfWMHq78oBYy7/hmcI1msDGz15ioZawIace9KTwI6nKJM+PrRWWQB9e3BOVvYifbEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024880; c=relaxed/simple; bh=lI9O4QlWa29m1gAOidbZ7ftnaJeUa0UFB+lkjwhczVA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KbJ5PeZs6IT6+qcgLOM+nwThe/IVVYqtI/pWr5YQDcjr9O0VpnXHCpGspGNJHPr2yIndCljH4DL8rtYxWH5ZGNHfSszOcZZLxggNQtobLVRRRWx8wzoWCuRQvsTFGS1dCQ+vW4r+AAyooVEdiGiojIReThYoxaAMjVQ080QmQuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=ZPUDPQkx; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="ZPUDPQkx" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-8b6ea7716bfso153721896d6.0 for ; Thu, 28 May 2026 20:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024878; x=1780629678; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=N+twxrCgMPmxRUfCoAO2rR744nXbCirg1fWRSm/fo6E=; b=ZPUDPQkxs4tCk3EVSsE0zCRqg+ejNjTlLNna27kj/9hmLOCoaqloJ2kf2l0PVGrlZt jXcWiyGKsUo0mo22dZwJNvQPhy0EQaLrObLWutgOed0WlmmJkhA2nFkN0aB3nMZ9uD1B 3oB9kLFKW1feBvO84L8dkD7+LIApYtcf1wX+pNXjBTQOwks3hnHMgZfw2UGJC9AvKJqT +XS2j1RsA/Si0iUwkA80ed3E827khDjoZ2eEdsvv/YN1aLWU9EXT4GeFRewC/S1t2WCP x2RT5IbpCV39yoDHgliMDuCjF1gIolqyc6oBS2ODnR0Ajo4wxaOvLhsqBmTc8AaIYcWV Oc0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024878; x=1780629678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=N+twxrCgMPmxRUfCoAO2rR744nXbCirg1fWRSm/fo6E=; b=jk91jcEqYjn2cjJWiEIJbW2EJWF7SMRaYUD53zibpCJRCvYznUFv13XEwKdbzPy7dc Fa0uBN8u1WmsFs20qcghmR05ndQWhoytLEmazXw8Skts+hDHzJdsKk1ayHZH1Z+uYzlo odNHmwJXryxTAQMLNKYxFZncBQ3wLd2KjwwBwc57AVeUdGhmAYz5VPtagk+vFE0S/SQw lJ5T1NbmEU8G4ieZB4TFxJr3Vr4AhnMZN030I7Mqa+0UwN/IUQ83J7Gs7FXqD3bQS6SU FZT4kODZ35WJFGSwnLe8bgoAMu0/xmo1gMg0/PcwYmH7Iep6dfIO5RPrwts+jTlPdgig Za8Q== X-Forwarded-Encrypted: i=1; AFNElJ8z50h8RC5ikSRrQ7HERBRrIXn5gxiF6YVHs9eAWN67+jyCbDr3SSmTN8lQCj7cF1zSV1yb5ImXelYyB4k=@vger.kernel.org X-Gm-Message-State: AOJu0YxElDd8DlItNvMavcScNPHUmSrwBdvakBZmsF/EbazKmTPcan5Q N/2u9MVzCXfMHNFX8mlK93Jd/nIgpRGEuB0c2Yq+qb/jjUJAtR7HwAaU2xB7TNtSDc0= X-Gm-Gg: Acq92OHNLRvYPGUTEez+PLoM3caL1+mB2kX5y/+aIbAbArS98uACKIsgRaN9SpQuKMy PS+ZYrrF6Qg0giFUVslfzQHyoHDYt/tW2uuRux0BmwJ74N41Sk//a8DF8eutt5MuAiJYa/a3QaL I4mPqkUqbbwW262q1m2VAR6ONtCDNsgMJ92r0Rrlu2qIqmK63m+FY4o3LC4BCeCqVXehxQb6Ply yC/wrJPsLdRN+Tz/P6wo429Oxpm8Txz1BW8pHp2GaxwjHoQ0PAFOyc0gq2WB6e6L9Nnx1RvwqQF iPfQ0JaOXWf6UHz7hGYzrgM+FY0/nOyfaeZSzFP6vEyUeKJGcFRgJbHamdIoODaHj5Bw1usBcmK pKOAqoq28mFt/rKnFLV1qafHoVs8/PsE+aK6Ctq96IrhZ7WbSbiz4PQbJCCna3BdO+NhngNm29a SGlBiHRMa6iK+7VptQMrm5dxqDXFT/RKpdooFRFzFfnRyRoekIlobxgC+ITHFCo/Wm9JWjr3tv X-Received: by 2002:a05:6214:238f:b0:8cc:3546:2630 with SMTP id 6a1803df08f44-8cce7fd38d8mr11874636d6.9.1780024878004; Thu, 28 May 2026 20:21:18 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:17 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 07/11] liveupdate: Remove limit on the number of sessions Date: Fri, 29 May 2026 03:21:02 +0000 Message-ID: <20260529032106.1505796-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the number of LUO sessions is limited by a fixed number of pre-allocated pages for serialization (16 pages, allowing for ~819 sessions). This limitation is problematic if LUO is used to support things such as systemd file descriptor store, and would be used not just as VM memory but to save other states on the machine. Remove this limit by transitioning to a linked-block approach for session metadata serialization. Instead of a single contiguous block, session metadata is now stored in a chain of 16-page blocks. Each block starts with a header containing the physical address of the next block and the number of session entries in the current block. Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- include/linux/kho/abi/luo.h | 24 +------ kernel/liveupdate/luo_session.c | 114 +++++++++++++++----------------- 2 files changed, 56 insertions(+), 82 deletions(-) diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h index 9a4fe491812b..79758d92ed5f 100644 --- a/include/linux/kho/abi/luo.h +++ b/include/linux/kho/abi/luo.h @@ -33,11 +33,6 @@ * It includes the compatibility string, the liveupdate-number, and po= inters * to sessions and FLBs. * - * - struct luo_session_header_ser: - * Header for the session array. Contains the total page count of the - * preserved memory block and the number of `struct luo_session_ser` - * entries that follow. - * * - struct luo_session_ser: * Metadata for a single session, including its name and a physical po= inter * to another preserved memory block containing an array of @@ -63,13 +58,15 @@ #define _LINUX_KHO_ABI_LUO_H =20 #include +#include #include =20 /* * The LUO state is registered under this KHO entry name. */ #define LUO_KHO_ENTRY_NAME "LUO" -#define LUO_ABI_COMPATIBLE "luo-v3" +#define LUO_COMPAT_BASE "luo-v3" +#define LUO_ABI_COMPATIBLE LUO_COMPAT_BASE "-" KHO_BLOCK_ABI_COMPATIBLE #define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) =20 /** @@ -118,21 +115,6 @@ struct luo_file_set_ser { u64 count; } __packed; =20 -/** - * struct luo_session_header_ser - Header for the serialized session data = block. - * @count: The number of `struct luo_session_ser` entries that immediately - * follow this header in the memory block. - * - * This structure is located at the beginning of a contiguous block of - * physical memory preserved across the kexec. It provides the necessary - * metadata to interpret the array of session entries that follow. - * - * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. - */ -struct luo_session_header_ser { - u64 count; -} __packed; - /** * struct luo_session_ser - Represents the serialized metadata for a LUO s= ession. * @name: The unique name of the session, provided by the userspac= e at diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_sessio= n.c index ec72f16185f3..c340ae4bf743 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -24,9 +24,10 @@ * ioctls on /dev/liveupdate. * * - Serialization: Session metadata is preserved using the KHO framework.= When - * a live update is triggered via kexec, an array of `struct luo_session= _ser` - * is populated and placed in a preserved memory region. The physical ad= dress - * of this array is stored in the centralized `struct luo_ser` structure. + * a live update is triggered via kexec, session metadata is serialized = into + * a chain of linked-blocks and placed in a preserved memory region. The + * physical address of the first block header is stored in the centraliz= ed + * `struct luo_ser` structure. * * Session Lifecycle: * @@ -89,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -98,23 +100,14 @@ #include #include "luo_internal.h" =20 -/* 16 4K pages, give space for 744 sessions */ -#define LUO_SESSION_PGCNT 16ul -#define LUO_SESSION_MAX (((LUO_SESSION_PGCNT << PAGE_SHIFT) - \ - sizeof(struct luo_session_header_ser)) / \ - sizeof(struct luo_session_ser)) - static DECLARE_RWSEM(luo_session_serialize_rwsem); - /** * struct luo_session_header - Header struct for managing LUO sessions. * @count: The number of sessions currently tracked in the @list. * @list: The head of the linked list of `struct luo_session` insta= nces. * @rwsem: A read-write semaphore providing synchronized access to t= he * session list and other fields in this structure. - * @header_ser: The header data of serialization array. - * @ser: The serialized session data (an array of - * `struct luo_session_ser`). + * @block_set: The set of serialization blocks. * @sessions_pa: Points to the location of sessions_pa within struct luo_s= er. * @active: Set to true when first initialized. If previous kernel di= d not * send session data, active stays false for incoming. @@ -123,8 +116,7 @@ struct luo_session_header { long count; struct list_head list; struct rw_semaphore rwsem; - struct luo_session_header_ser *header_ser; - struct luo_session_ser *ser; + struct kho_block_set block_set; u64 *sessions_pa; bool active; }; @@ -143,10 +135,14 @@ static struct luo_session_global luo_session_global = =3D { .incoming =3D { .list =3D LIST_HEAD_INIT(luo_session_global.incoming.list), .rwsem =3D __RWSEM_INITIALIZER(luo_session_global.incoming.rwsem), + .block_set =3D KHO_BLOCK_SET_INIT(luo_session_global.incoming.block_set, + sizeof(struct luo_session_ser)), }, .outgoing =3D { .list =3D LIST_HEAD_INIT(luo_session_global.outgoing.list), .rwsem =3D __RWSEM_INITIALIZER(luo_session_global.outgoing.rwsem), + .block_set =3D KHO_BLOCK_SET_INIT(luo_session_global.outgoing.block_set, + sizeof(struct luo_session_ser)), }, }; =20 @@ -173,25 +169,6 @@ static void luo_session_free(struct luo_session *sessi= on) kfree(session); } =20 -static int luo_session_grow_ser(struct luo_session_header *sh) -{ - struct luo_session_header_ser *header_ser; - - if (sh->count =3D=3D LUO_SESSION_MAX) - return -ENOMEM; - - if (sh->header_ser) - return 0; - - header_ser =3D kho_alloc_preserve(LUO_SESSION_PGCNT << PAGE_SHIFT); - if (IS_ERR(header_ser)) - return PTR_ERR(header_ser); - - sh->header_ser =3D header_ser; - sh->ser =3D (void *)(header_ser + 1); - return 0; -} - static int luo_session_insert(struct luo_session_header *sh, struct luo_session *session) { @@ -205,7 +182,7 @@ static int luo_session_insert(struct luo_session_header= *sh, * for new session. */ if (sh =3D=3D &luo_session_global.outgoing) { - err =3D luo_session_grow_ser(sh); + err =3D kho_block_grow(&sh->block_set, sh->count); if (err) return err; } @@ -232,6 +209,8 @@ static void luo_session_remove(struct luo_session_heade= r *sh, guard(rwsem_write)(&sh->rwsem); list_del(&session->list); sh->count--; + if (sh =3D=3D &luo_session_global.outgoing) + kho_block_shrink(&sh->block_set, sh->count); } =20 static int luo_session_finish_one(struct luo_session *session) @@ -526,15 +505,17 @@ void __init luo_session_setup_outgoing(u64 *sessions_= pa) =20 int __init luo_session_setup_incoming(u64 sessions_pa) { - struct luo_session_header_ser *header_ser; + struct luo_session_header *sh =3D &luo_session_global.incoming; + int err; =20 - if (sessions_pa) { - header_ser =3D phys_to_virt(sessions_pa); - luo_session_global.incoming.header_ser =3D header_ser; - luo_session_global.incoming.ser =3D (void *)(header_ser + 1); - luo_session_global.incoming.active =3D true; - } + if (!sessions_pa) + return 0; =20 + err =3D kho_block_restore(&sh->block_set, sessions_pa); + if (err) + return err; + + sh->active =3D true; return 0; } =20 @@ -576,6 +557,8 @@ int luo_session_deserialize(void) { struct luo_session_header *sh =3D &luo_session_global.incoming; static bool is_deserialized; + struct luo_session_ser *ser; + struct kho_block_it it; static int err; =20 /* If has been deserialized, always return the same error code */ @@ -601,53 +584,62 @@ int luo_session_deserialize(void) * userspace to detect the failure and trigger a reboot, which will * reliably reset devices and reclaim memory. */ - for (int i =3D 0; i < sh->header_ser->count; i++) { - err =3D luo_session_deserialize_one(sh, &sh->ser[i]); + kho_block_it_init(&it, &sh->block_set); + while ((ser =3D kho_block_it_read(&it))) { + err =3D luo_session_deserialize_one(sh, ser); if (err) - return err; + goto err_destroy_blocks; } =20 - kho_restore_free(sh->header_ser); - sh->header_ser =3D NULL; - sh->ser =3D NULL; +err_destroy_blocks: + kho_block_destroy(&sh->block_set); =20 - return 0; + return err; } =20 int luo_session_serialize(void) { struct luo_session_header *sh =3D &luo_session_global.outgoing; struct luo_session *session; - int i =3D 0; + struct kho_block_it it; int err; =20 down_write(&luo_session_serialize_rwsem); down_write(&sh->rwsem); *sh->sessions_pa =3D 0; =20 + kho_block_it_init(&it, &sh->block_set); + list_for_each_entry(session, &sh->list, list) { - err =3D luo_session_freeze_one(session, &sh->ser[i]); + struct luo_session_ser *ser =3D kho_block_it_next(&it); + + if (!ser) { + err =3D -ENOSPC; + goto err_undo; + } + + err =3D luo_session_freeze_one(session, ser); if (err) goto err_undo; =20 - strscpy(sh->ser[i].name, session->name, - sizeof(sh->ser[i].name)); - i++; + strscpy(ser->name, session->name, sizeof(ser->name)); } =20 - if (sh->header_ser && sh->count > 0) { - sh->header_ser->count =3D sh->count; - *sh->sessions_pa =3D virt_to_phys(sh->header_ser); - } + kho_block_it_finalize(&it); + + if (sh->sessions_pa && sh->count > 0) + *sh->sessions_pa =3D sh->block_set.head_pa; up_write(&sh->rwsem); =20 return 0; =20 err_undo: + kho_block_it_prev(&it); list_for_each_entry_continue_reverse(session, &sh->list, list) { - i--; - luo_session_unfreeze_one(session, &sh->ser[i]); - memset(sh->ser[i].name, 0, sizeof(sh->ser[i].name)); + struct luo_session_ser *ser =3D kho_block_it_prev(&it); + + luo_session_unfreeze_one(session, ser); + memset(ser->name, 0, sizeof(ser->name)); } up_write(&sh->rwsem); up_write(&luo_session_serialize_rwsem); --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47BFA36F8F5 for ; Fri, 29 May 2026 03:21:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024882; cv=none; b=r56U8RHtclbcSShvig5rwQz6iUR/RPQETKou6m7R6pwHA8hnfAKUE8g3TVMa+kIRk10YMnt/cjwSdKj/lPF88/SWGCmJ44ULT7K8EvNDuLeMoPSvGFA9y+FB+FRfOEjIkE+AFgOQcXH7ssLEzRgqfJonDlbvrEcH0HfhtpkwGJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024882; c=relaxed/simple; bh=iUiaIHiiv3PYpRKmon4R643EpIlIHD0Kp6A2AR5aqKo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bM6fjBGaQerDi4ghvosiwnjMYqIOmJuN+M6Mq5ZcV9VrwSmShjclASs1z7PlYnQawMcOrDvErFDUeu1e9I+ZwBX35EVqC+MqXygBZ4G19W1BzaAXRLo/2rBsxBXzw8cSgF1ctGkXJlAPAW3cn2nuZjPGGqla1Ekhohjlwpb1QH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=jrXI/4fl; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="jrXI/4fl" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-8b98482b253so217224086d6.1 for ; Thu, 28 May 2026 20:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024879; x=1780629679; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=oZd8mWvo7gp73ILBBgVaF/bc9fDtru0D8V/2+ZV2cFk=; b=jrXI/4flVVz/IYvtiW3xvLVSWzbXPcxu73CAmm8nRWTsfY6fwJhDjxWBRqriMpaQx4 BLrlaqMZ252UK7LjhytKoRKcUiB7SmYvDxPXYkqFp3lZnM7+OJZFSy3WhASDr4K9eEoU lg8ISzzaQW9R9TtAcYFs0kynexzUL8us6LnzgFEcV1je+QPLb3exg26lJncH5tjSBqMg N8QMEto7FBMx49OGZiorZX0xlxlFX2MYwR6FA5exWkes/Z/FJ9TEL87p/PtP3s+BEjaw Pb4FVz5gU8GMMatr7CRu7OGfMycCK15Xy8LPunmmquHCXPIGfpF8yKDdRWwDZw0j/vMo WZhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024879; x=1780629679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=oZd8mWvo7gp73ILBBgVaF/bc9fDtru0D8V/2+ZV2cFk=; b=AHPJb7UG0Zj8KQw6I1yFvUpx0yrTbZwEslaaL8NJiG3O1KqbH5V3VZVS+u+HKA0nAA Edq8cHpwwbxdSjsG6NRze9AnyjkVs8IHP99Bn2EUb8P1/p2WbPV70FnWHwZIxTS9LezS 9218f5uQtn1k0J84N+WCHX1KuFHpyLr6FIkbMfG7RGQZvtoZ8aGGjtw0c6rs89FwL5Oc d4aANSobzG/AyhNrsXFp+aU6Rj33zJmRiPY+DJvSQbIJDYwQHhm+HmsSdAMDJPUIhVsF sl5Sm4Kid4PeXjhqogw+IwNYJ/aYGbnH9l0epF/PsspYVmQANdL+fh6pU2zOWC3q+pv6 gtmA== X-Forwarded-Encrypted: i=1; AFNElJ/wHoJRyOUBU9leNF354acBSDKsA7AfiKCrjkA857JL2QoX1ldphpC4dBye9ogXvGGQ4dEiwY14OK2Xcts=@vger.kernel.org X-Gm-Message-State: AOJu0YxXObcyX077VQxIkd59XjSdrvzWt8sqRemXBDKDF3p2d39KbOI4 F9v8G4uar0hpCRXaNGJmbloxHxY/0Nu6tXugpPTqaGPiF+ZB0yHMco6sOp9qEpN9gPI= X-Gm-Gg: Acq92OHUEB7dwUt0U98cl8SJCjzBbI2Rw71c8vOlSBrFbOjZ0hD2Vm1bbz0EcYTNtNk OxwLRnb6dF2I2n3uhXUmEtjeRpuuUE3o/EeSI1GotoWOPmjZoBUibyvJnX4gQM+uh2lL5mLcTnv ZoW3/pE6mtf3qbCmkIuBOlPDt8Wxcm9HmBpjbeSleTzvOtXo5/8lDBwb+da4V715BpuwQWon1lg lcbbdtHzr0wZiie009IyDaVCql6JKa5RQXjiPNZMI2Ur5VB8Vf3eujikwfBYBcxLAa8b6G0KdeM L8aAcwTnweESExlGRLn3RXpo1S31AtG9hlynR3erCGWzug0sIf/hIMrlrBCX3S4xQXiKEPr9Lt3 F4+JfzhqaJuFE3posHG/j4apChuMQ/F04WW+Emsazq165K5bW6NxSeWTnkiWQkbwTQZerUtF0qW goR2lrIUy6ThiqnzrZUGnuuwTGP3SPyIBGhWGzABUPdEJ1ztnXvsZmG/YYNMsJeA== X-Received: by 2002:a05:6214:1d0e:b0:8ca:2a4f:7364 with SMTP id 6a1803df08f44-8cce801ecd8mr12833796d6.29.1780024879286; Thu, 28 May 2026 20:21:19 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:18 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 08/11] liveupdate: Remove limit on the number of files per session Date: Fri, 29 May 2026 03:21:03 +0000 Message-ID: <20260529032106.1505796-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To remove the fixed limit on the number of preserved files per session, transition the file metadata serialization from a single contiguous memory block to a chain of linked blocks. Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- include/linux/kho/abi/luo.h | 13 +-- kernel/liveupdate/luo_file.c | 142 +++++++++++++++---------------- kernel/liveupdate/luo_internal.h | 6 +- 3 files changed, 78 insertions(+), 83 deletions(-) diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h index 79758d92ed5f..16df550ef143 100644 --- a/include/linux/kho/abi/luo.h +++ b/include/linux/kho/abi/luo.h @@ -35,8 +35,8 @@ * * - struct luo_session_ser: * Metadata for a single session, including its name and a physical po= inter - * to another preserved memory block containing an array of - * `struct luo_file_ser` for all files in that session. + * to the first `struct kho_block_header_ser` for all files in that se= ssion. + * Multiple blocks are linked via the `next` field in the header. * * - struct luo_file_ser: * Metadata for a single preserved file. Contains the `compatible` str= ing to @@ -65,7 +65,7 @@ * The LUO state is registered under this KHO entry name. */ #define LUO_KHO_ENTRY_NAME "LUO" -#define LUO_COMPAT_BASE "luo-v3" +#define LUO_COMPAT_BASE "luo-v4" #define LUO_ABI_COMPATIBLE LUO_COMPAT_BASE "-" KHO_BLOCK_ABI_COMPATIBLE #define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) =20 @@ -103,9 +103,10 @@ struct luo_file_ser { =20 /** * struct luo_file_set_ser - Represents the serialized metadata for file s= et - * @files: The physical address of a contiguous memory block that holds - * the serialized state of files (array of luo_file_ser) in this= file - * set. + * @files: The physical address of the first `struct kho_block_header_se= r`. + * This structure is the header for a block of memory containing + * an array of `struct luo_file_ser` entries. Multiple blocks are + * linked via the `next` field in the header. * @count: The total number of files that were part of this session duri= ng * serialization. Used for iteration and validation during * restoration. diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 9eec07a9e9fc..06eb083cc759 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -118,11 +118,6 @@ static LIST_HEAD(luo_file_handler_list); /* Keep track of files being preserved by LUO */ static DEFINE_XARRAY(luo_preserved_files); =20 -/* 2 4K pages, give space for 128 files per file_set */ -#define LUO_FILE_PGCNT 2ul -#define LUO_FILE_MAX \ - ((LUO_FILE_PGCNT << PAGE_SHIFT) / sizeof(struct luo_file_ser)) - /** * struct luo_file - Represents a single preserved file instance. * @fh: Pointer to the &struct liveupdate_file_handler that man= ages @@ -174,39 +169,6 @@ struct luo_file { u64 token; }; =20 -static int luo_alloc_files_mem(struct luo_file_set *file_set) -{ - size_t size; - void *mem; - - if (file_set->files) - return 0; - - WARN_ON_ONCE(file_set->count); - - size =3D LUO_FILE_PGCNT << PAGE_SHIFT; - mem =3D kho_alloc_preserve(size); - if (IS_ERR(mem)) - return PTR_ERR(mem); - - file_set->files =3D mem; - - return 0; -} - -static void luo_free_files_mem(struct luo_file_set *file_set) -{ - /* If file_set has files, no need to free preservation memory */ - if (file_set->count) - return; - - if (!file_set->files) - return; - - kho_unpreserve_free(file_set->files); - file_set->files =3D NULL; -} - static unsigned long luo_get_id(struct liveupdate_file_handler *fh, struct file *file) { @@ -276,16 +238,15 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) if (luo_token_is_used(file_set, token)) return -EEXIST; =20 - if (file_set->count =3D=3D LUO_FILE_MAX) - return -ENOSPC; + err =3D kho_block_grow(&file_set->block_set, file_set->count); + if (err) + return err; =20 file =3D fget(fd); - if (!file) - return -EBADF; - - err =3D luo_alloc_files_mem(file_set); - if (err) - goto err_fput; + if (!file) { + err =3D -EBADF; + goto err_shrink; + } =20 err =3D -ENOENT; down_read(&luo_register_rwlock); @@ -300,7 +261,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u6= 4 token, int fd) =20 /* err is still -ENOENT if no handler was found */ if (err) - goto err_free_files_mem; + goto err_fput; =20 err =3D xa_insert(&luo_preserved_files, luo_get_id(fh, file), file, GFP_KERNEL); @@ -343,10 +304,10 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) xa_erase(&luo_preserved_files, luo_get_id(fh, file)); err_module_put: module_put(fh->ops->owner); -err_free_files_mem: - luo_free_files_mem(file_set); err_fput: fput(file); +err_shrink: + kho_block_shrink(&file_set->block_set, file_set->count); =20 return err; } @@ -392,13 +353,14 @@ void luo_file_unpreserve_files(struct luo_file_set *f= ile_set) =20 list_del(&luo_file->list); file_set->count--; + kho_block_shrink(&file_set->block_set, file_set->count); =20 fput(luo_file->file); mutex_destroy(&luo_file->mutex); kfree(luo_file); } =20 - luo_free_files_mem(file_set); + kho_block_destroy(&file_set->block_set); } =20 static int luo_file_freeze_one(struct luo_file_set *file_set, @@ -454,7 +416,7 @@ static void __luo_file_unfreeze(struct luo_file_set *fi= le_set, luo_file_unfreeze_one(file_set, luo_file); } =20 - memset(file_set->files, 0, LUO_FILE_PGCNT << PAGE_SHIFT); + kho_block_set_clear(&file_set->block_set); } =20 /** @@ -493,19 +455,23 @@ static void __luo_file_unfreeze(struct luo_file_set *= file_set, int luo_file_freeze(struct luo_file_set *file_set, struct luo_file_set_ser *file_set_ser) { - struct luo_file_ser *file_ser =3D file_set->files; struct luo_file *luo_file; + struct kho_block_it it; int err; - int i; =20 if (!file_set->count) return 0; =20 - if (WARN_ON(!file_ser)) - return -EINVAL; + kho_block_it_init(&it, &file_set->block_set); =20 - i =3D 0; list_for_each_entry(luo_file, &file_set->files_list, list) { + struct luo_file_ser *file_ser =3D kho_block_it_next(&it); + + if (!file_ser) { + err =3D -ENOSPC; + goto err_unfreeze; + } + err =3D luo_file_freeze_one(file_set, luo_file); if (err < 0) { pr_warn("Freeze failed for token[%#0llx] handler[%s] err[%pe]\n", @@ -514,16 +480,21 @@ int luo_file_freeze(struct luo_file_set *file_set, goto err_unfreeze; } =20 - strscpy(file_ser[i].compatible, luo_file->fh->compatible, - sizeof(file_ser[i].compatible)); - file_ser[i].data =3D luo_file->serialized_data; - file_ser[i].token =3D luo_file->token; - i++; + strscpy(file_ser->compatible, luo_file->fh->compatible, + sizeof(file_ser->compatible)); + file_ser->data =3D luo_file->serialized_data; + file_ser->token =3D luo_file->token; } + kho_block_it_finalize(&it); =20 file_set_ser->count =3D file_set->count; - if (file_set->files) - file_set_ser->files =3D virt_to_phys(file_set->files); + if (!list_empty(&file_set->block_set.blocks)) { + struct kho_block *block; + + block =3D list_first_entry(&file_set->block_set.blocks, + struct kho_block, list); + file_set_ser->files =3D virt_to_phys(block->ser); + } =20 return 0; =20 @@ -741,14 +712,12 @@ int luo_file_finish(struct luo_file_set *file_set) module_put(luo_file->fh->ops->owner); list_del(&luo_file->list); file_set->count--; + kho_block_shrink(&file_set->block_set, file_set->count); mutex_destroy(&luo_file->mutex); kfree(luo_file); } =20 - if (file_set->files) { - kho_restore_free(file_set->files); - file_set->files =3D NULL; - } + kho_block_destroy(&file_set->block_set); =20 return 0; } @@ -822,16 +791,18 @@ int luo_file_deserialize(struct luo_file_set *file_se= t, struct luo_file_set_ser *file_set_ser) { struct luo_file_ser *file_ser; + struct kho_block_it it; int err; - u64 i; =20 if (!file_set_ser->files) { WARN_ON(file_set_ser->count); return 0; } =20 - file_set->count =3D file_set_ser->count; - file_set->files =3D phys_to_virt(file_set_ser->files); + file_set->count =3D 0; + err =3D kho_block_restore(&file_set->block_set, file_set_ser->files); + if (err) + return err; =20 /* * Note on error handling: @@ -848,25 +819,48 @@ int luo_file_deserialize(struct luo_file_set *file_se= t, * userspace to detect the failure and trigger a reboot, which will * reliably reset devices and reclaim memory. */ - file_ser =3D file_set->files; - for (i =3D 0; i < file_set->count; i++) { - err =3D luo_file_deserialize_one(file_set, &file_ser[i]); + kho_block_it_init(&it, &file_set->block_set); + while ((file_ser =3D kho_block_it_read(&it))) { + err =3D luo_file_deserialize_one(file_set, file_ser); if (err) - return err; + goto err_destroy_blocks; + file_set->count++; + } + + if (file_set->count !=3D file_set_ser->count) { + pr_warn("File count mismatch: expected %llu, found %ld\n", + file_set_ser->count, file_set->count); } =20 return 0; + +err_destroy_blocks: + while (!list_empty(&file_set->files_list)) { + struct luo_file *luo_file; + + luo_file =3D list_first_entry(&file_set->files_list, + struct luo_file, list); + list_del(&luo_file->list); + module_put(luo_file->fh->ops->owner); + mutex_destroy(&luo_file->mutex); + kfree(luo_file); + } + file_set->count =3D 0; + kho_block_destroy(&file_set->block_set); + return err; } =20 void luo_file_set_init(struct luo_file_set *file_set) { INIT_LIST_HEAD(&file_set->files_list); + kho_block_set_init(&file_set->block_set, sizeof(struct luo_file_ser)); } =20 void luo_file_set_destroy(struct luo_file_set *file_set) { WARN_ON(file_set->count); WARN_ON(!list_empty(&file_set->files_list)); + WARN_ON(!list_empty(&file_set->block_set.blocks)); } =20 /** diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 28ebb4f3000b..2c5e8bcb219c 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -10,6 +10,7 @@ =20 #include #include +#include =20 struct luo_ucmd { void __user *ubuffer; @@ -44,14 +45,13 @@ static inline int luo_ucmd_respond(struct luo_ucmd *ucm= d, * struct luo_file_set - A set of files that belong to the same sessions. * @files_list: An ordered list of files associated with this session, it = is * ordered by preservation time. - * @files: The physically contiguous memory block that holds the seri= alized - * state of files. + * @block_set: The set of serialization blocks. * @count: A counter tracking the number of files currently stored in= the * @files_list for this session. */ struct luo_file_set { struct list_head files_list; - struct luo_file_ser *files; + struct kho_block_set block_set; long count; }; =20 --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75BB936D9EB for ; Fri, 29 May 2026 03:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024883; cv=none; b=eoXZfcef4/MBXXnHWg0oCVNQPnNA6ykEvlHKLDIlEu7TcoCzF0IfU/cKXTo/qki1OiTt2G4FE2bNx1LNejJFvITQlk9ScWEJATnZucw3Qa5TNKkOi0Eob26Nlj+c/hGipgJikdtvatSC9nkrZqZJoc1Zwp3AwYbAy5kozb7j0Zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024883; c=relaxed/simple; bh=l5sCPInN24558zDa0DI5TQ1DcCXBUgAOZ3PiWzJQJoI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p1ctCQqOP7al83WY/jOkEeEWjhuJc/0JvqtGOGpAEtkyVVkXke2LDqWqf37PaJaVp0ofZKCp/ZI5F4jP0DgyDtKTWp2PN+lz/g/90C5EpYtRT7AJC1mDceLaFnTp9fPp83fpX41AmdDBajNtroxUhiNrAI+29t3YWEArUh3FlOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=GDsGEhr7; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="GDsGEhr7" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-516d634956fso81577611cf.2 for ; Thu, 28 May 2026 20:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024880; x=1780629680; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=l/PRPWvWF9f7qW0XjjBpwGc/NadY8LWCtXHDn2RYoSI=; b=GDsGEhr7SUn9cHIzAHtJ+z7aKPPj7z7LFgjgMomXYOwqW+oPrYdoi2iCrwfOqLb46O 3qbKq1r9mvabkhHr1eQ24xuEAVfu10tG1jznBVrsfFT6phslbQITj+SWCKiiGBNvshBM bZoLQQDEVBVFJYMs7zC3W9e6vtAean03kvr6oeJLpV68aJjuW/x8eFNpls22UIUeX+aY WVj7XFZ3aEoh3cGfGtlNKa1BlSyQr8d9uE3GLluOypOD4I0v6caV++WoTvxT/A3uve2q C/J9e69a17B/XZ1mZ9VRx/0AB3bA5CuSZ4IH65oWYfxCNouWdkThhXJtpXjjYSXH+obF QODw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024880; x=1780629680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=l/PRPWvWF9f7qW0XjjBpwGc/NadY8LWCtXHDn2RYoSI=; b=mIjD7qNaypX9Zi5Sb9M9xSM+5MB8LWZWV5qUwdjEquDEFA4cGfnbMUUZNBpW3cmLV4 AqcJmus07NrB+YTGy8De0QcyNViqrbvzXF8qxQRmXpuJyFI5NOuhPAa2nhP/IbqGAYxz +ay0YPInmwIuy2pWVk5rhMqPHA+SLSCYCIhphhKGh/PqXKto2ljyJZP/4c2lwNVjX58j HjOqmziAXeQ1ah3SWYn3xBMDgIjsBsT8acWX7K16v8ojrn533FwR/ZBZWBEeVuqIAQk4 MZOciOfevdY1MQMzikQZtxhH/Y5bC6Jhe9KxNAAc6Y66Hr5+u/PXu9/4qmG9p/XnXrWF 19/A== X-Forwarded-Encrypted: i=1; AFNElJ9bfWk+DssvKTceag2Hoquc+q9iNzkNeJidYp42sZQ3jRkHKpjZhbfLZmKwEUqwzIJ9/po6woxtWYk20ec=@vger.kernel.org X-Gm-Message-State: AOJu0YzeqA2ZVmwz1EbqGzqIEHHgICTJlGwc5SH81Bsf5YEFKJwe6bkf CL0v4w7qaetG7/4j+Xd/S7QAFMVo29EAdQtd4MHzLc3iP6XFnmVLtDgnNw5og05qoHM= X-Gm-Gg: Acq92OHnPZ/W6URmFlK/5YbDlOf2ls3bgwSQCpqz4U6Ik93yFOH2TjUdsdEjONsJCxl xsi3XEB5C44qC+ZL/zaKvwTdoHsl2vgbsJsnHLw8vk7/3RNMT59ObsEWG2zdAJYPvmigOiqqN2v UN4HV3Fyc93rZHpEf+1T9lnUm43Ypdrix6i9pKiCRcFxYHIfGxfSvphfRTS41nW6vG1kB5RIul9 /dZKxM7D+rldtE+By+Ny5Pq8Xp89ajIFmjolLWxP8az4KNKW75nxXfHCIA/jLx+G9jlba/2QjHe x9c963pkJS/vkaiS/+zfmh9i/kZVt6K61Z4GmTSTVNZTTQetrTeBzdnd6BPTiBCvYEHEnnX5B80 RKaUGutgVot6cMrITRr8tI3Xt67sdfYfF3C/dIwViZMps/sO+fEyPXYzDa3YdxVmF7/1HGQXU40 +TsM7oYUPGCsN4wUB/+ZfikfAP6BwU7mhddeY8j7t6FhSvNIok+BIPgAhhpfDT9hwkCh73MDv7 X-Received: by 2002:a05:622a:5805:b0:516:e722:5ed1 with SMTP id d75a77b69052e-5172dd1e2a1mr15106211cf.29.1780024880588; Thu, 28 May 2026 20:21:20 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:20 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 09/11] selftests/liveupdate: Test session and file limit removal Date: Fri, 29 May 2026 03:21:04 +0000 Message-ID: <20260529032106.1505796-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With the removal of static limits on the number of sessions and files per session, the orchestrator now uses dynamic allocation. Add new test cases to verify that the system can handle a large number of sessions and files. These tests ensure that the dynamic block allocation and reuse logic for session metadata and outgoing files work correctly beyond the previous static limits. Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- .../testing/selftests/liveupdate/liveupdate.c | 75 +++++++++++++++++++ .../selftests/liveupdate/luo_test_utils.c | 24 ++++++ .../selftests/liveupdate/luo_test_utils.h | 2 + 3 files changed, 101 insertions(+) diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c index c7d94b9181e1..502fb3567e38 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -26,6 +26,7 @@ =20 #include =20 +#include "luo_test_utils.h" #include "../kselftest.h" #include "../kselftest_harness.h" =20 @@ -499,4 +500,78 @@ TEST_F(liveupdate_device, get_session_name_max_length) ASSERT_EQ(close(session_fd), 0); } =20 +/* + * Test Case: Manage Many Sessions + * + * Verifies that a large number of sessions can be created and then + * destroyed during normal system operation. This specifically tests the + * dynamic block allocation and reuse logic for session metadata management + * without preserving any files. + */ +TEST_F(liveupdate_device, preserve_many_sessions) +{ +#define MANY_SESSIONS 2000 + int session_fds[MANY_SESSIONS]; + int ret, i; + + self->fd1 =3D open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno =3D=3D ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + ret =3D luo_ensure_nofile_limit(MANY_SESSIONS); + if (ret =3D=3D -EPERM) + SKIP(return, "Insufficient privileges to set RLIMIT_NOFILE"); + ASSERT_EQ(ret, 0); + + for (i =3D 0; i < MANY_SESSIONS; i++) { + char name[64]; + + snprintf(name, sizeof(name), "many-session-%d", i); + session_fds[i] =3D create_session(self->fd1, name); + ASSERT_GE(session_fds[i], 0); + } + + for (i =3D 0; i < MANY_SESSIONS; i++) + ASSERT_EQ(close(session_fds[i]), 0); +} + +/* + * Test Case: Preserve Many Files + * + * Verifies that a large number of files can be preserved in a single sess= ion + * and then destroyed during normal system operation. This tests the dynam= ic + * block allocation and management for outgoing files. + */ +TEST_F(liveupdate_device, preserve_many_files) +{ +#define MANY_FILES 500 + int mem_fds[MANY_FILES]; + int session_fd, ret, i; + + self->fd1 =3D open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno =3D=3D ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + session_fd =3D create_session(self->fd1, "many-files-test"); + ASSERT_GE(session_fd, 0); + + ret =3D luo_ensure_nofile_limit(MANY_FILES + 10); + if (ret =3D=3D -EPERM) + SKIP(return, "Insufficient privileges to set RLIMIT_NOFILE"); + ASSERT_EQ(ret, 0); + + for (i =3D 0; i < MANY_FILES; i++) { + mem_fds[i] =3D memfd_create("test-memfd", 0); + ASSERT_GE(mem_fds[i], 0); + ASSERT_EQ(preserve_fd(session_fd, mem_fds[i], i), 0); + } + + for (i =3D 0; i < MANY_FILES; i++) + ASSERT_EQ(close(mem_fds[i]), 0); + + ASSERT_EQ(close(session_fd), 0); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/te= sting/selftests/liveupdate/luo_test_utils.c index 3c8721c505df..333a3530051b 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/luo_test_utils.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,29 @@ int luo_open_device(void) return open(LUO_DEVICE, O_RDWR); } =20 +int luo_ensure_nofile_limit(long min_limit) +{ + struct rlimit hl; + + /* Allow to extra files to be used by test itself */ + min_limit +=3D 32; + + if (getrlimit(RLIMIT_NOFILE, &hl) < 0) + return -errno; + + if (hl.rlim_cur >=3D min_limit) + return 0; + + hl.rlim_cur =3D min_limit; + if (hl.rlim_cur > hl.rlim_max) + hl.rlim_max =3D hl.rlim_cur; + + if (setrlimit(RLIMIT_NOFILE, &hl) < 0) + return -errno; + + return 0; +} + int luo_create_session(int luo_fd, const char *name) { struct liveupdate_ioctl_create_session arg =3D { .size =3D sizeof(arg) }; diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/te= sting/selftests/liveupdate/luo_test_utils.h index 90099bf49577..6a0d85386613 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.h +++ b/tools/testing/selftests/liveupdate/luo_test_utils.h @@ -26,6 +26,8 @@ int luo_create_session(int luo_fd, const char *name); int luo_retrieve_session(int luo_fd, const char *name); int luo_session_finish(int session_fd); =20 +int luo_ensure_nofile_limit(long min_limit); + int create_and_preserve_memfd(int session_fd, int token, const char *data); int restore_and_verify_memfd(int session_fd, int token, const char *expect= ed_data); =20 --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 983EB370AE7 for ; Fri, 29 May 2026 03:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024884; cv=none; b=Lw0x5BacCHLU+fMan3BXbwtz4sbIG1rwx6utM13zB8I+e5fPvql4WclzmDJnzEmz86d9aZgmgBVLLeI8B+OWoSc3hIBwPVg5mxUVUDBA1w3Khc+7NJFyjh/Tn26LghEjy9dLR/hoz0MExP4DkMQ1cTU1WtxWtCLg/kFXi6BKJnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024884; c=relaxed/simple; bh=PwW6M86VtpCYbVanCRu9RC9XepQoEWHm1vY/6gS4fT8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a0FpTOvIxl5ZhtwjQ0bEteq3cRa4WNsXKOaFAKXzV/sUsBtVuC5QZghmLsQ1u0zZkVTUuhRhqXLS/9wZm1JVuZCpSsQH1pvsMGAwwiLst0KLznh0Jznz/Bf8ggVZ7QZRfqNtwekvTcYm08WS4KKeNA8irqJqUjlc5U40Y4CcJ10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=b+4kwRa8; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="b+4kwRa8" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-8bb4e8a5240so168601316d6.1 for ; Thu, 28 May 2026 20:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024882; x=1780629682; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zMNVhv3SnOTuZ3xqpMfMs2g7riJHPagItEAHtnUEWTI=; b=b+4kwRa8f7qrkyNsbDVjH0o6FjozCDeb8hD4uzPe2/f34l0/Kpab6HKSKhDZlwcFA5 v9Y+mm0dEzdSOhwAsGrTI1eQCNAJuFop/qtwur22W0cYDPJTB/cjx83EKznqE+X5iYD3 n6R32cHt4+9XnqW+zwEBPTQnm9bO1OLPsT1NlLIm+vM5uQZCqFSIUG5EFkXlqf0C9xO3 0pYh16JHzgVyXOu91BYTtaDcXt+6iY2Qgn7CjcPbAWKYiE0HJtvoevzCzCM30V6ncexg NAcx5SllZtIBQr9lNhJPREvjtRZIcmgQJooyFkXS4HOCK6tU/8jDPqWxlPTg23GrokJy XkxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024882; x=1780629682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=zMNVhv3SnOTuZ3xqpMfMs2g7riJHPagItEAHtnUEWTI=; b=G3oMmhZosJzOAgQDySwIJs8MQbCXtpkrMa16YqYty5g97lGil6D697FnvL/XBd7dzI YIbP7ZDoquoRsOxErGodbaTf195X3j0FACZSvqwKkWU0QyXaqmoJ2WG5x1YzIBKEBSNg qv50dlZoRUH1GgAmZ/GP3zRDDsZbMspJNg1hSFdshugOBoHZcIp8Idgd6jp91sXpU57b 62j6Rt52BWNyVIdRDUYtIKEsbtsX2YitnsUl5IA9EaQXE1a1m+1DRAlrv+Qd/VnkqFfO 2BQ/mZg510OPoWbW4aU0M0XAd1s2pkD/Q1b6CnwM424UN1u4n1TqgQUWsIsdcM55EqRR HeMQ== X-Forwarded-Encrypted: i=1; AFNElJ8Xb7n5nZPAfP8qBrpysfrAhw9uoLXIm8PH67HWOU5F9GMKM8nKBni2qWOamNMqoAnu30+EzwYH3KNYwls=@vger.kernel.org X-Gm-Message-State: AOJu0YyK4RavGYofSUPsqmacUwQL0VJIlTMgxgapvxYrdF1pbcm6BW89 4GiPfpxKaq7L4GphwuXGU34t8rAi4yXyR7GSQ74xSEv2Ws+E5PFWCbqAW4vUfp0u8Tw= X-Gm-Gg: Acq92OEe6cJbXESqoDA8kwSe7qNKl01PkoczubYxP10HdrA4CXg0ar8tCS65qRhudpc a+EVPxcP423Xxd32LhrOOJJhPKPiEQY/aOXN0YWdk0meJXihGeyPZpEyEfZkESPRaMb5xFy3Ozk wolnhHBG+J91ZJHatIbEnUtzc9uM0g5qNXTUBp3W5wQ0SGw1st2mqbUDEVvqWRpcEWkXoT3Qd7X eEM+RF+nGhk6apvPWaWf0BikR9Db7WoYJkyVg8kH+ks2qLbWr8pua1585/EhizSc4EGtB4qD8ge Rd12tObFY9GQ2aikfEOcm2VMqoGkb2FSO/mhg8Ni7sT5nKxR19YozMlR7eSUD2NipVSJq8A97E8 k+O3r2c/lX3SwpPgj4rfEqAwyRlLs4ZwEuuHyd72IVb1fHMkKcs2ark917xuNVzvgyRBkU0O9tQ Krn5HhxqHkubpf6ZV2xM2iyXCtBucvoYoFLa6Pyf/VKEcKiEeXR3TgMV7cfW4b9A== X-Received: by 2002:a05:6214:518b:b0:8ca:deb:3f9f with SMTP id 6a1803df08f44-8cce82412d1mr11698806d6.34.1780024881756; Thu, 28 May 2026 20:21:21 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:21 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 10/11] selftests/liveupdate: Add stress-sessions kexec test Date: Fri, 29 May 2026 03:21:05 +0000 Message-ID: <20260529032106.1505796-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new test that creates 2000 LUO sessions before a kexec reboot and verifies their presence after the reboot. This ensures that the linked-block serialization mechanism works correctly for a large number of sessions. Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- tools/testing/selftests/liveupdate/Makefile | 1 + .../liveupdate/luo_stress_sessions.c | 102 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/luo_stress_sessions.c diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile index 080754787ede..ed7534468386 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -6,6 +6,7 @@ TEST_GEN_PROGS +=3D liveupdate =20 TEST_GEN_PROGS_EXTENDED +=3D luo_kexec_simple TEST_GEN_PROGS_EXTENDED +=3D luo_multi_session +TEST_GEN_PROGS_EXTENDED +=3D luo_stress_sessions =20 TEST_FILES +=3D do_kexec.sh =20 diff --git a/tools/testing/selftests/liveupdate/luo_stress_sessions.c b/too= ls/testing/selftests/liveupdate/luo_stress_sessions.c new file mode 100644 index 000000000000..f201b1839d1d --- /dev/null +++ b/tools/testing/selftests/liveupdate/luo_stress_sessions.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2026, Google LLC. + * Pasha Tatashin + * + * Validate that LUO can handle a large number of sessions across a kexec + * reboot. + */ + +#include +#include +#include "luo_test_utils.h" + +#define NUM_SESSIONS 2000 +#define STATE_SESSION_NAME "kexec_many_state" +#define STATE_MEMFD_TOKEN 999 + +/* Stage 1: Executed before the kexec reboot. */ +static void run_stage_1(int luo_fd) +{ + int ret, i; + + ksft_print_msg("[STAGE 1] Increasing ulimit for open files...\n"); + ret =3D luo_ensure_nofile_limit(NUM_SESSIONS); + if (ret =3D=3D -EPERM) + ksft_exit_skip("Insufficient privileges to set RLIMIT_NOFILE\n"); + if (ret < 0) + ksft_exit_fail_msg("luo_ensure_nofile_limit failed: %s\n", strerror(-ret= )); + + ksft_print_msg("[STAGE 1] Creating state file for next stage (2)...\n"); + create_state_file(luo_fd, STATE_SESSION_NAME, STATE_MEMFD_TOKEN, 2); + + ksft_print_msg("[STAGE 1] Creating %d sessions...\n", NUM_SESSIONS); + + for (i =3D 0; i < NUM_SESSIONS; i++) { + char name[LIVEUPDATE_SESSION_NAME_LENGTH]; + int s_fd; + + snprintf(name, sizeof(name), "many-test-%d", i); + s_fd =3D luo_create_session(luo_fd, name); + if (s_fd < 0) { + fail_exit("luo_create_session for '%s' at index %d", + name, i); + } + } + + ksft_print_msg("[STAGE 1] Successfully created %d sessions.\n", + NUM_SESSIONS); + + close(luo_fd); + daemonize_and_wait(); +} + +/* Stage 2: Executed after the kexec reboot. */ +static void run_stage_2(int luo_fd, int state_session_fd) +{ + int i, stage; + + ksft_print_msg("[STAGE 2] Starting post-kexec verification...\n"); + + restore_and_read_stage(state_session_fd, STATE_MEMFD_TOKEN, &stage); + if (stage !=3D 2) { + fail_exit("Expected stage 2, but state file contains %d", + stage); + } + + ksft_print_msg("[STAGE 2] Retrieving and finishing %d sessions...\n", + NUM_SESSIONS); + + for (i =3D 0; i < NUM_SESSIONS; i++) { + char name[LIVEUPDATE_SESSION_NAME_LENGTH]; + int s_fd; + + snprintf(name, sizeof(name), "many-test-%d", i); + s_fd =3D luo_retrieve_session(luo_fd, name); + if (s_fd < 0) { + fail_exit("luo_retrieve_session for '%s' at index %d", + name, i); + } + + if (luo_session_finish(s_fd) < 0) { + fail_exit("luo_session_finish for '%s' at index %d", + name, i); + } + close(s_fd); + } + + ksft_print_msg("[STAGE 2] Finalizing state session...\n"); + if (luo_session_finish(state_session_fd) < 0) + fail_exit("luo_session_finish for state session"); + close(state_session_fd); + + ksft_print_msg("\n--- MANY-SESSIONS KEXEC TEST PASSED (%d sessions) ---\n= ", + NUM_SESSIONS); +} + +int main(int argc, char *argv[]) +{ + return luo_test(argc, argv, STATE_SESSION_NAME, + run_stage_1, run_stage_2); +} --=20 2.53.0 From nobody Mon Jun 8 13:31:22 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE3FC371046 for ; Fri, 29 May 2026 03:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024886; cv=none; b=JR98C+97uG2clBFP7tVMgJIvPDHyPTIXxIihtxjavfD9GUWrb6CWnUaKHPp1ifiHzH0r7MZ8BRY9+cuA4Jak53+jsvLctSUV1aHPoLtubO+8gf4hvciClLNnVFKqX4HYqdowc5OQv7SARV2WYa0hapTwq0y8mHdmLlHcFoWIg3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780024886; c=relaxed/simple; bh=5h2GF0XbFDjqAMNI62aGoAqPGag11ae9hGWbCLa3/ew=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MUDDqi0CD4y+RRJqkpXjrQBIaUNK4GL60hjMwpX6YZjmT0yeUKBVUHRFkdMK5U/THNcTAS+wkVSF10rGYV3qz6MFOLJsjXN3t4XJSxuh+dD7J23kpaNhajMMAURnuRu6nT2WmiEO5kyf9+MscPrt47AXQ+P6/GbxvCTdJdXxLCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=YCqbSG4c; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="YCqbSG4c" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-914ae4101b4so957973085a.2 for ; Thu, 28 May 2026 20:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1780024884; x=1780629684; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DD7mpkHwGkKw+XnhrMPNwFwDdntpab6EeONlinrdH5M=; b=YCqbSG4cVmUbbUcN7NfC6z+TlNTNEo1/SoiG5DVgJgJgo3ycs0JYd/9P6j1TOmosfY xdzoJ6G7YUp5aL9uZLWRDpSFhNxvdiU0sVDqspADONwWkvLbBSs8GBsbnQER4ZCH000m tylGDIikhAy0gNVFewNG/VastMPk4/TJUsRW98fhSoBQwNgjOuR3guMSAYOq4MV4PkvY 97+De62PaaSn2xluaz6DWQO0NXAr6B/7XDLCGqS/cajTwGXOws9wN//8NGPpvwcyR53P Nxa4ldcwP/BkypI07ldV79dOUfJ/tagKXdg0xlSnLHPeY4ymugSSVPR0Ria+2Cg11E4O 5M4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780024884; x=1780629684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=DD7mpkHwGkKw+XnhrMPNwFwDdntpab6EeONlinrdH5M=; b=oymKzRnaGuRMoCpx76dfAX/972RsJoVb+vQOX1jRbJdUP8TLwHvAeLhTHatPkC7mfJ SGMjyj7yXAfPkxq0GyDbRElvgoHq8GIpiVbAFGkKWWqwE9Eg+mG4iw7tiZTzGzMCfvAc PQrlurv/6iIdPNIGCWpCs/ja0ekQrhw/dtHkh0EAW3knWM5gH0+/K5xRtpWPUNHpZt6T L4drWJg1BovD2Eb6tpkWucLTneiL0muEXVjiJfR5oHT+e0b4ngs5ZfumzE/MG4NilrJe VlQMgGqAwN1IHxx9ezeBrcH01aESDX7ZzS3M4fMoRWb87ms5uZF5lXib+h1o4nv+8wjm LviA== X-Forwarded-Encrypted: i=1; AFNElJ/CVxrYDmqP4vwDVikyMgEegYsbDMnbXce9mvNI1S8SbkFeNLaMujKTVrmRSYGPNQlnA9jVHcbsrpQipe8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4oKS0i5SdFDP9ZXQMlUBWqn0KznY3l5AjY1jQMaac1L1ZiJ1I v//ZYGRBM37+vPXSt59nes4QyO/JFa3ljIm3rbhN2W+cmeSrlf0PgglZAbbwfedubEk= X-Gm-Gg: Acq92OENcHLEGEliEL9QuxtQ2nHqBXuxCdYOFi/+ck+6MyfR/zEQwebsoZypn1rMDog sg3YoWTuDzY7Tr1jSA5uiWnSOODvWY697VHMp7i2E4d+SqLsEQdJKt/pghYAYTwJ79ESIiibs/S vrHwFVnsUVi7FJcW/c28wuJqtt8gWFqLktRZEv3+S2CpyDZnFXF4PV535aQY8W3UTBKX5EEvPch Mc3OC0mZFtpY8p4DKcmPraUpmSP1TzThlQFeFGIXrrKXOuL+agb63Mlczpsl4CAYTqahdS8fPM9 s7uIOyVd30dEDh7/lGc+Yt4L+bhFX2fyP6/f3ushJLfCVrqfKC9DxkdvLY4jnpYzPJ/j+cXXLWq jB6B6kzoEmxibnJ+4X2j92GsRR47oHCOQ7q+OpeYvHHTGMbEQV38zyVhNj8eTup3KdNSEaQoyhp MStxATDBOcUJ84iorc3CIaSbyhNiTXbmSkcrFbkc2LxgqtkgwccNVmczvniXAQ/A== X-Received: by 2002:a05:620a:4709:b0:914:bb8e:915b with SMTP id af79cd13be357-9152fd2fc49mr147943985a.21.1780024883867; Thu, 28 May 2026 20:21:23 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea26d286sm1179476d6.48.2026.05.28.20.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 20:21:22 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, skhan@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, corbet@lwn.net, pasha.tatashin@soleen.com, dmatlack@google.com, kexec@lists.infradead.org, pratyush@kernel.org, skhawaja@google.com, graf@amazon.com Subject: [PATCH v3 11/11] selftests/liveupdate: Add stress-files kexec test Date: Fri, 29 May 2026 03:21:06 +0000 Message-ID: <20260529032106.1505796-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260529032106.1505796-1-pasha.tatashin@soleen.com> References: <20260529032106.1505796-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new luo_stress_files kexec test that verifies preserving and retrieving 500 files across a kexec reboot. Reviewed-by: Pratyush Yadav (Google) Acked-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- tools/testing/selftests/liveupdate/Makefile | 1 + .../selftests/liveupdate/luo_stress_files.c | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/luo_stress_files.c diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile index ed7534468386..30689d22cb02 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -7,6 +7,7 @@ TEST_GEN_PROGS +=3D liveupdate TEST_GEN_PROGS_EXTENDED +=3D luo_kexec_simple TEST_GEN_PROGS_EXTENDED +=3D luo_multi_session TEST_GEN_PROGS_EXTENDED +=3D luo_stress_sessions +TEST_GEN_PROGS_EXTENDED +=3D luo_stress_files =20 TEST_FILES +=3D do_kexec.sh =20 diff --git a/tools/testing/selftests/liveupdate/luo_stress_files.c b/tools/= testing/selftests/liveupdate/luo_stress_files.c new file mode 100644 index 000000000000..b6a0c3899890 --- /dev/null +++ b/tools/testing/selftests/liveupdate/luo_stress_files.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2026, Google LLC. + * Pasha Tatashin + * + * Validate that LUO can handle a large number of files per session across + * a kexec reboot. + */ + +#include +#include +#include "luo_test_utils.h" + +#define NUM_FILES 500 +#define STATE_SESSION_NAME "kexec_many_files_state" +#define STATE_MEMFD_TOKEN 9999 +#define TEST_SESSION_NAME "many_files_session" + +/* Stage 1: Executed before the kexec reboot. */ +static void run_stage_1(int luo_fd) +{ + int session_fd, ret, i; + + ksft_print_msg("[STAGE 1] Increasing ulimit for open files...\n"); + ret =3D luo_ensure_nofile_limit(NUM_FILES); + if (ret =3D=3D -EPERM) + ksft_exit_skip("Insufficient privileges to set RLIMIT_NOFILE\n"); + if (ret < 0) + ksft_exit_fail_msg("luo_ensure_nofile_limit failed: %s\n", strerror(-ret= )); + + ksft_print_msg("[STAGE 1] Creating state file for next stage (2)...\n"); + create_state_file(luo_fd, STATE_SESSION_NAME, STATE_MEMFD_TOKEN, 2); + + ksft_print_msg("[STAGE 1] Creating test session '%s'...\n", TEST_SESSION_= NAME); + session_fd =3D luo_create_session(luo_fd, TEST_SESSION_NAME); + if (session_fd < 0) + fail_exit("luo_create_session"); + + ksft_print_msg("[STAGE 1] Preserving %d files...\n", NUM_FILES); + for (i =3D 0; i < NUM_FILES; i++) { + char data[64]; + + snprintf(data, sizeof(data), "file-data-%d", i); + if (create_and_preserve_memfd(session_fd, i, data) < 0) + fail_exit("create_and_preserve_memfd for index %d", i); + } + + ksft_print_msg("[STAGE 1] Successfully preserved %d files.\n", NUM_FILES); + + close(luo_fd); + daemonize_and_wait(); +} + +/* Stage 2: Executed after the kexec reboot. */ +static void run_stage_2(int luo_fd, int state_session_fd) +{ + int session_fd; + int i, stage; + + ksft_print_msg("[STAGE 2] Starting post-kexec verification...\n"); + + restore_and_read_stage(state_session_fd, STATE_MEMFD_TOKEN, &stage); + if (stage !=3D 2) { + fail_exit("Expected stage 2, but state file contains %d", + stage); + } + + ksft_print_msg("[STAGE 2] Retrieving test session '%s'...\n", TEST_SESSIO= N_NAME); + session_fd =3D luo_retrieve_session(luo_fd, TEST_SESSION_NAME); + if (session_fd < 0) + fail_exit("luo_retrieve_session"); + + ksft_print_msg("[STAGE 2] Verifying %d files...\n", NUM_FILES); + for (i =3D 0; i < NUM_FILES; i++) { + char data[64]; + + snprintf(data, sizeof(data), "file-data-%d", i); + if (restore_and_verify_memfd(session_fd, i, data) < 0) + fail_exit("restore_and_verify_memfd for index %d", i); + } + + ksft_print_msg("[STAGE 2] Finishing test session...\n"); + if (luo_session_finish(session_fd) < 0) + fail_exit("luo_session_finish for test session"); + close(session_fd); + + ksft_print_msg("[STAGE 2] Finalizing state session...\n"); + if (luo_session_finish(state_session_fd) < 0) + fail_exit("luo_session_finish for state session"); + close(state_session_fd); + + ksft_print_msg("\n--- MANY-FILES KEXEC TEST PASSED (%d files) ---\n", + NUM_FILES); +} + +int main(int argc, char *argv[]) +{ + return luo_test(argc, argv, STATE_SESSION_NAME, + run_stage_1, run_stage_2); +} --=20 2.53.0