Skip to content

Commit 0153094

Browse files
soleenakpm00
authored andcommitted
liveupdate: luo_session: add sessions support
Introduce concept of "Live Update Sessions" within the LUO framework. LUO sessions provide a mechanism to group and manage `struct file *` instances (representing file descriptors) that need to be preserved across a kexec-based live update. Each session is identified by a unique name and acts as a container for file objects whose state is critical to a userspace workload, such as a virtual machine or a high-performance database, aiming to maintain their functionality across a kernel transition. This groundwork establishes the framework for preserving file-backed state across kernel updates, with the actual file data preservation mechanisms to be implemented in subsequent patches. [dan.carpenter@linaro.org: fix use after free in luo_session_deserialize()] Link: https://lkml.kernel.org/r/c5dd637d7eed3a3be48c5e9fedb881596a3b1f5a.1764163896.git.dan.carpenter@linaro.org Link: https://lkml.kernel.org/r/20251125165850.3389713-5-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Tested-by: David Matlack <dmatlack@google.com> Cc: Aleksander Lobakin <aleksander.lobakin@intel.com> Cc: Alexander Graf <graf@amazon.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andriy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: anish kumar <yesanishhere@gmail.com> Cc: Anna Schumaker <anna.schumaker@oracle.com> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Borislav Betkov <bp@alien8.de> Cc: Chanwoo Choi <cw00.choi@samsung.com> Cc: Chen Ridong <chenridong@huawei.com> Cc: Chris Li <chrisl@kernel.org> Cc: Christian Brauner <brauner@kernel.org> Cc: Daniel Wagner <wagi@kernel.org> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Hildenbrand <david@redhat.com> Cc: David Jeffery <djeffery@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Guixin Liu <kanie@linux.alibaba.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Hugh Dickins <hughd@google.com> Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Ira Weiny <ira.weiny@intel.com> Cc: Jann Horn <jannh@google.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Joanthan Cameron <Jonathan.Cameron@huawei.com> Cc: Joel Granados <joel.granados@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Lennart Poettering <lennart@poettering.net> Cc: Leon Romanovsky <leon@kernel.org> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Marc Rutland <mark.rutland@arm.com> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Matthew Maurer <mmaurer@google.com> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Myugnjoo Ham <myungjoo.ham@samsung.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Pratyush Yadav <ptyadav@amazon.de> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Song Liu <song@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Stuart Hayes <stuart.w.hayes@gmail.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleinxer <tglx@linutronix.de> Cc: Thomas Weißschuh <linux@weissschuh.net> Cc: Vincent Guittot <vincent.guittot@linaro.org> Cc: William Tu <witu@nvidia.com> Cc: Yoann Congal <yoann.congal@smile.fr> Cc: Zhu Yanjun <yanjun.zhu@linux.dev> Cc: Zijun Hu <quic_zijuhu@quicinc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent db8bed8 commit 0153094

6 files changed

Lines changed: 577 additions & 1 deletion

File tree

include/linux/kho/abi/luo.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
* / {
3333
* compatible = "luo-v1";
3434
* liveupdate-number = <...>;
35+
*
36+
* luo-session {
37+
* compatible = "luo-session-v1";
38+
* luo-session-header = <phys_addr_of_session_header_ser>;
39+
* };
3540
* };
3641
*
3742
* Main LUO Node (/):
@@ -40,11 +45,37 @@
4045
* Identifies the overall LUO ABI version.
4146
* - liveupdate-number: u64
4247
* A counter tracking the number of successful live updates performed.
48+
*
49+
* Session Node (luo-session):
50+
* This node describes all preserved user-space sessions.
51+
*
52+
* - compatible: "luo-session-v1"
53+
* Identifies the session ABI version.
54+
* - luo-session-header: u64
55+
* The physical address of a `struct luo_session_header_ser`. This structure
56+
* is the header for a contiguous block of memory containing an array of
57+
* `struct luo_session_ser`, one for each preserved session.
58+
*
59+
* Serialization Structures:
60+
* The FDT properties point to memory regions containing arrays of simple,
61+
* `__packed` structures. These structures contain the actual preserved state.
62+
*
63+
* - struct luo_session_header_ser:
64+
* Header for the session array. Contains the total page count of the
65+
* preserved memory block and the number of `struct luo_session_ser`
66+
* entries that follow.
67+
*
68+
* - struct luo_session_ser:
69+
* Metadata for a single session, including its name and a physical pointer
70+
* to another preserved memory block containing an array of
71+
* `struct luo_file_ser` for all files in that session.
4372
*/
4473

4574
#ifndef _LINUX_KHO_ABI_LUO_H
4675
#define _LINUX_KHO_ABI_LUO_H
4776

77+
#include <uapi/linux/liveupdate.h>
78+
4879
/*
4980
* The LUO FDT hooks all LUO state for sessions, fds, etc.
5081
* In the root it also carries "liveupdate-number" 64-bit property that
@@ -55,4 +86,44 @@
5586
#define LUO_FDT_COMPATIBLE "luo-v1"
5687
#define LUO_FDT_LIVEUPDATE_NUM "liveupdate-number"
5788

89+
/*
90+
* LUO FDT session node
91+
* LUO_FDT_SESSION_HEADER: is a u64 physical address of struct
92+
* luo_session_header_ser
93+
*/
94+
#define LUO_FDT_SESSION_NODE_NAME "luo-session"
95+
#define LUO_FDT_SESSION_COMPATIBLE "luo-session-v1"
96+
#define LUO_FDT_SESSION_HEADER "luo-session-header"
97+
98+
/**
99+
* struct luo_session_header_ser - Header for the serialized session data block.
100+
* @count: The number of `struct luo_session_ser` entries that immediately
101+
* follow this header in the memory block.
102+
*
103+
* This structure is located at the beginning of a contiguous block of
104+
* physical memory preserved across the kexec. It provides the necessary
105+
* metadata to interpret the array of session entries that follow.
106+
*
107+
* If this structure is modified, `LUO_FDT_SESSION_COMPATIBLE` must be updated.
108+
*/
109+
struct luo_session_header_ser {
110+
u64 count;
111+
} __packed;
112+
113+
/**
114+
* struct luo_session_ser - Represents the serialized metadata for a LUO session.
115+
* @name: The unique name of the session, provided by the userspace at
116+
* the time of session creation.
117+
*
118+
* This structure is used to package session-specific metadata for transfer
119+
* between kernels via Kexec Handover. An array of these structures (one per
120+
* session) is created and passed to the new kernel, allowing it to reconstruct
121+
* the session context.
122+
*
123+
* If this structure is modified, `LUO_FDT_SESSION_COMPATIBLE` must be updated.
124+
*/
125+
struct luo_session_ser {
126+
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
127+
} __packed;
128+
58129
#endif /* _LINUX_KHO_ABI_LUO_H */

include/uapi/linux/liveupdate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@
4343
/* The ioctl type, documented in ioctl-number.rst */
4444
#define LIVEUPDATE_IOCTL_TYPE 0xBA
4545

46+
/* The maximum length of session name including null termination */
47+
#define LIVEUPDATE_SESSION_NAME_LENGTH 64
48+
4649
#endif /* _UAPI_LIVEUPDATE_H */

kernel/liveupdate/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
luo-y := \
4-
luo_core.o
4+
luo_core.o \
5+
luo_session.o
56

67
obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o
78
obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) += kexec_handover_debug.o

kernel/liveupdate/luo_core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ static int __init luo_early_startup(void)
118118
pr_info("Retrieved live update data, liveupdate number: %lld\n",
119119
luo_global.liveupdate_num);
120120

121+
err = luo_session_setup_incoming(luo_global.fdt_in);
122+
if (err)
123+
return err;
124+
121125
return 0;
122126
}
123127

@@ -154,6 +158,7 @@ static int __init luo_fdt_setup(void)
154158
err |= fdt_begin_node(fdt_out, "");
155159
err |= fdt_property_string(fdt_out, "compatible", LUO_FDT_COMPATIBLE);
156160
err |= fdt_property(fdt_out, LUO_FDT_LIVEUPDATE_NUM, &ln, sizeof(ln));
161+
err |= luo_session_setup_outgoing(fdt_out);
157162
err |= fdt_end_node(fdt_out);
158163
err |= fdt_finish(fdt_out);
159164
if (err)
@@ -211,6 +216,10 @@ int liveupdate_reboot(void)
211216
if (!liveupdate_enabled())
212217
return 0;
213218

219+
err = luo_session_serialize();
220+
if (err)
221+
return err;
222+
214223
err = kho_finalize();
215224
if (err) {
216225
pr_err("kho_finalize failed %d\n", err);

kernel/liveupdate/luo_internal.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,33 @@
1919
*/
2020
#define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__)
2121

22+
/**
23+
* struct luo_session - Represents an active or incoming Live Update session.
24+
* @name: A unique name for this session, used for identification and
25+
* retrieval.
26+
* @ser: Pointer to the serialized data for this session.
27+
* @list: A list_head member used to link this session into a global list
28+
* of either outgoing (to be preserved) or incoming (restored from
29+
* previous kernel) sessions.
30+
* @retrieved: A boolean flag indicating whether this session has been
31+
* retrieved by a consumer in the new kernel.
32+
* @mutex: protects fields in the luo_session.
33+
*/
34+
struct luo_session {
35+
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
36+
struct luo_session_ser *ser;
37+
struct list_head list;
38+
bool retrieved;
39+
struct mutex mutex;
40+
};
41+
42+
int luo_session_create(const char *name, struct file **filep);
43+
int luo_session_retrieve(const char *name, struct file **filep);
44+
int __init luo_session_setup_outgoing(void *fdt);
45+
int __init luo_session_setup_incoming(void *fdt);
46+
int luo_session_serialize(void);
47+
int luo_session_deserialize(void);
48+
bool luo_session_quiesce(void);
49+
void luo_session_resume(void);
50+
2251
#endif /* _LINUX_LUO_INTERNAL_H */

0 commit comments

Comments
 (0)