Skip to content

Commit 7c722a7

Browse files
soleenakpm00
authored andcommitted
liveupdate: luo_file: implement file systems callbacks
This patch implements the core mechanism for managing preserved files throughout the live update lifecycle. It provides the logic to invoke the file handler callbacks (preserve, unpreserve, freeze, unfreeze, retrieve, and finish) at the appropriate stages. During the reboot phase, luo_file_freeze() serializes the final metadata for each file (handler compatible string, token, and data handle) into a memory region preserved by KHO. In the new kernel, luo_file_deserialize() reconstructs the in-memory file list from this data, preparing the session for retrieval. Link: https://lkml.kernel.org/r/20251125165850.3389713-7-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> 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 81cd25d commit 7c722a7

5 files changed

Lines changed: 1055 additions & 1 deletion

File tree

include/linux/kho/abi/luo.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
* Metadata for a single session, including its name and a physical pointer
7070
* to another preserved memory block containing an array of
7171
* `struct luo_file_ser` for all files in that session.
72+
*
73+
* - struct luo_file_ser:
74+
* Metadata for a single preserved file. Contains the `compatible` string to
75+
* find the correct handler in the new kernel, a user-provided `token` for
76+
* identification, and an opaque `data` handle for the handler to use.
7277
*/
7378

7479
#ifndef _LINUX_KHO_ABI_LUO_H
@@ -86,13 +91,43 @@
8691
#define LUO_FDT_COMPATIBLE "luo-v1"
8792
#define LUO_FDT_LIVEUPDATE_NUM "liveupdate-number"
8893

94+
#define LIVEUPDATE_HNDL_COMPAT_LENGTH 48
95+
96+
/**
97+
* struct luo_file_ser - Represents the serialized preserves files.
98+
* @compatible: File handler compatible string.
99+
* @data: Private data
100+
* @token: User provided token for this file
101+
*
102+
* If this structure is modified, LUO_SESSION_COMPATIBLE must be updated.
103+
*/
104+
struct luo_file_ser {
105+
char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH];
106+
u64 data;
107+
u64 token;
108+
} __packed;
109+
110+
/**
111+
* struct luo_file_set_ser - Represents the serialized metadata for file set
112+
* @files: The physical address of a contiguous memory block that holds
113+
* the serialized state of files (array of luo_file_ser) in this file
114+
* set.
115+
* @count: The total number of files that were part of this session during
116+
* serialization. Used for iteration and validation during
117+
* restoration.
118+
*/
119+
struct luo_file_set_ser {
120+
u64 files;
121+
u64 count;
122+
} __packed;
123+
89124
/*
90125
* LUO FDT session node
91126
* LUO_FDT_SESSION_HEADER: is a u64 physical address of struct
92127
* luo_session_header_ser
93128
*/
94129
#define LUO_FDT_SESSION_NODE_NAME "luo-session"
95-
#define LUO_FDT_SESSION_COMPATIBLE "luo-session-v1"
130+
#define LUO_FDT_SESSION_COMPATIBLE "luo-session-v2"
96131
#define LUO_FDT_SESSION_HEADER "luo-session-header"
97132

98133
/**
@@ -114,6 +149,7 @@ struct luo_session_header_ser {
114149
* struct luo_session_ser - Represents the serialized metadata for a LUO session.
115150
* @name: The unique name of the session, provided by the userspace at
116151
* the time of session creation.
152+
* @file_set_ser: Serialized files belonging to this session,
117153
*
118154
* This structure is used to package session-specific metadata for transfer
119155
* between kernels via Kexec Handover. An array of these structures (one per
@@ -124,6 +160,7 @@ struct luo_session_header_ser {
124160
*/
125161
struct luo_session_ser {
126162
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
163+
struct luo_file_set_ser file_set_ser;
127164
} __packed;
128165

129166
#endif /* _LINUX_KHO_ABI_LUO_H */

include/linux/liveupdate.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,93 @@
88
#define _LINUX_LIVEUPDATE_H
99

1010
#include <linux/bug.h>
11+
#include <linux/compiler.h>
12+
#include <linux/kho/abi/luo.h>
1113
#include <linux/list.h>
1214
#include <linux/types.h>
15+
#include <uapi/linux/liveupdate.h>
16+
17+
struct liveupdate_file_handler;
18+
struct file;
19+
20+
/**
21+
* struct liveupdate_file_op_args - Arguments for file operation callbacks.
22+
* @handler: The file handler being called.
23+
* @retrieved: The retrieve status for the 'can_finish / finish'
24+
* operation.
25+
* @file: The file object. For retrieve: [OUT] The callback sets
26+
* this to the new file. For other ops: [IN] The caller sets
27+
* this to the file being operated on.
28+
* @serialized_data: The opaque u64 handle, preserve/prepare/freeze may update
29+
* this field.
30+
*
31+
* This structure bundles all parameters for the file operation callbacks.
32+
* The 'data' and 'file' fields are used for both input and output.
33+
*/
34+
struct liveupdate_file_op_args {
35+
struct liveupdate_file_handler *handler;
36+
bool retrieved;
37+
struct file *file;
38+
u64 serialized_data;
39+
};
40+
41+
/**
42+
* struct liveupdate_file_ops - Callbacks for live-updatable files.
43+
* @can_preserve: Required. Lightweight check to see if this handler is
44+
* compatible with the given file.
45+
* @preserve: Required. Performs state-saving for the file.
46+
* @unpreserve: Required. Cleans up any resources allocated by @preserve.
47+
* @freeze: Optional. Final actions just before kernel transition.
48+
* @unfreeze: Optional. Undo freeze operations.
49+
* @retrieve: Required. Restores the file in the new kernel.
50+
* @can_finish: Optional. Check if this FD can finish, i.e. all restoration
51+
* pre-requirements for this FD are satisfied. Called prior to
52+
* finish, in order to do successful finish calls for all
53+
* resources in the session.
54+
* @finish: Required. Final cleanup in the new kernel.
55+
* @owner: Module reference
56+
*
57+
* All operations (except can_preserve) receive a pointer to a
58+
* 'struct liveupdate_file_op_args' containing the necessary context.
59+
*/
60+
struct liveupdate_file_ops {
61+
bool (*can_preserve)(struct liveupdate_file_handler *handler,
62+
struct file *file);
63+
int (*preserve)(struct liveupdate_file_op_args *args);
64+
void (*unpreserve)(struct liveupdate_file_op_args *args);
65+
int (*freeze)(struct liveupdate_file_op_args *args);
66+
void (*unfreeze)(struct liveupdate_file_op_args *args);
67+
int (*retrieve)(struct liveupdate_file_op_args *args);
68+
bool (*can_finish)(struct liveupdate_file_op_args *args);
69+
void (*finish)(struct liveupdate_file_op_args *args);
70+
struct module *owner;
71+
};
72+
73+
/**
74+
* struct liveupdate_file_handler - Represents a handler for a live-updatable file type.
75+
* @ops: Callback functions
76+
* @compatible: The compatibility string (e.g., "memfd-v1", "vfiofd-v1")
77+
* that uniquely identifies the file type this handler
78+
* supports. This is matched against the compatible string
79+
* associated with individual &struct file instances.
80+
*
81+
* Modules that want to support live update for specific file types should
82+
* register an instance of this structure. LUO uses this registration to
83+
* determine if a given file can be preserved and to find the appropriate
84+
* operations to manage its state across the update.
85+
*/
86+
struct liveupdate_file_handler {
87+
const struct liveupdate_file_ops *ops;
88+
const char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH];
89+
90+
/* private: */
91+
92+
/*
93+
* Used for linking this handler instance into a global list of
94+
* registered file handlers.
95+
*/
96+
struct list_head __private list;
97+
};
1398

1499
#ifdef CONFIG_LIVEUPDATE
15100

@@ -19,6 +104,9 @@ bool liveupdate_enabled(void);
19104
/* Called during kexec to tell LUO that entered into reboot */
20105
int liveupdate_reboot(void);
21106

107+
int liveupdate_register_file_handler(struct liveupdate_file_handler *fh);
108+
int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh);
109+
22110
#else /* CONFIG_LIVEUPDATE */
23111

24112
static inline bool liveupdate_enabled(void)
@@ -31,5 +119,15 @@ static inline int liveupdate_reboot(void)
31119
return 0;
32120
}
33121

122+
static inline int liveupdate_register_file_handler(struct liveupdate_file_handler *fh)
123+
{
124+
return -EOPNOTSUPP;
125+
}
126+
127+
static inline int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh)
128+
{
129+
return -EOPNOTSUPP;
130+
}
131+
34132
#endif /* CONFIG_LIVEUPDATE */
35133
#endif /* _LINUX_LIVEUPDATE_H */

kernel/liveupdate/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
luo-y := \
44
luo_core.o \
5+
luo_file.o \
56
luo_session.o
67

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

0 commit comments

Comments
 (0)