Skip to content

Commit 1aece82

Browse files
soleenakpm00
authored andcommitted
liveupdate: luo_core: integrate with KHO
Integrate the LUO with the KHO framework to enable passing LUO state across a kexec reboot. This patch implements the lifecycle integration with KHO: 1. Incoming State: During early boot (`early_initcall`), LUO checks if KHO is active. If so, it retrieves the "LUO" subtree, verifies the "luo-v1" compatibility string, and reads the `liveupdate-number` to track the update count. 2. Outgoing State: During late initialization (`late_initcall`), LUO allocates a new FDT for the next kernel, populates it with the basic header (compatible string and incremented update number), and registers it with KHO (`kho_add_subtree`). 3. Finalization: The `liveupdate_reboot()` notifier is updated to invoke `kho_finalize()`. This ensures that all memory segments marked for preservation are properly serialized before the kexec jump. Link: https://lkml.kernel.org/r/20251125165850.3389713-3-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Tested-by: David Matlack <dmatlack@google.com> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> 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 9e2fd06 commit 1aece82

3 files changed

Lines changed: 233 additions & 1 deletion

File tree

include/linux/kho/abi/luo.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/*
4+
* Copyright (c) 2025, Google LLC.
5+
* Pasha Tatashin <pasha.tatashin@soleen.com>
6+
*/
7+
8+
/**
9+
* DOC: Live Update Orchestrator ABI
10+
*
11+
* This header defines the stable Application Binary Interface used by the
12+
* Live Update Orchestrator to pass state from a pre-update kernel to a
13+
* post-update kernel. The ABI is built upon the Kexec HandOver framework
14+
* and uses a Flattened Device Tree to describe the preserved data.
15+
*
16+
* This interface is a contract. Any modification to the FDT structure, node
17+
* properties, compatible strings, or the layout of the `__packed` serialization
18+
* structures defined here constitutes a breaking change. Such changes require
19+
* incrementing the version number in the relevant `_COMPATIBLE` string to
20+
* prevent a new kernel from misinterpreting data from an old kernel.
21+
*
22+
* Changes are allowed provided the compatibility version is incremented;
23+
* however, backward/forward compatibility is only guaranteed for kernels
24+
* supporting the same ABI version.
25+
*
26+
* FDT Structure Overview:
27+
* The entire LUO state is encapsulated within a single KHO entry named "LUO".
28+
* This entry contains an FDT with the following layout:
29+
*
30+
* .. code-block:: none
31+
*
32+
* / {
33+
* compatible = "luo-v1";
34+
* liveupdate-number = <...>;
35+
* };
36+
*
37+
* Main LUO Node (/):
38+
*
39+
* - compatible: "luo-v1"
40+
* Identifies the overall LUO ABI version.
41+
* - liveupdate-number: u64
42+
* A counter tracking the number of successful live updates performed.
43+
*/
44+
45+
#ifndef _LINUX_KHO_ABI_LUO_H
46+
#define _LINUX_KHO_ABI_LUO_H
47+
48+
/*
49+
* The LUO FDT hooks all LUO state for sessions, fds, etc.
50+
* In the root it also carries "liveupdate-number" 64-bit property that
51+
* corresponds to the number of live-updates performed on this machine.
52+
*/
53+
#define LUO_FDT_SIZE PAGE_SIZE
54+
#define LUO_FDT_KHO_ENTRY_NAME "LUO"
55+
#define LUO_FDT_COMPATIBLE "luo-v1"
56+
#define LUO_FDT_LIVEUPDATE_NUM "liveupdate-number"
57+
58+
#endif /* _LINUX_KHO_ABI_LUO_H */

kernel/liveupdate/luo_core.c

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,26 @@
4141

4242
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
4343

44+
#include <linux/io.h>
45+
#include <linux/kexec_handover.h>
46+
#include <linux/kho/abi/luo.h>
4447
#include <linux/kobject.h>
48+
#include <linux/libfdt.h>
4549
#include <linux/liveupdate.h>
4650
#include <linux/miscdevice.h>
51+
#include <linux/mm.h>
52+
#include <linux/sizes.h>
53+
#include <linux/string.h>
54+
#include <linux/unaligned.h>
55+
56+
#include "kexec_handover_internal.h"
57+
#include "luo_internal.h"
4758

4859
static struct {
4960
bool enabled;
61+
void *fdt_out;
62+
void *fdt_in;
63+
u64 liveupdate_num;
5064
} luo_global;
5165

5266
static int __init early_liveupdate_param(char *buf)
@@ -55,6 +69,129 @@ static int __init early_liveupdate_param(char *buf)
5569
}
5670
early_param("liveupdate", early_liveupdate_param);
5771

72+
static int __init luo_early_startup(void)
73+
{
74+
phys_addr_t fdt_phys;
75+
int err, ln_size;
76+
const void *ptr;
77+
78+
if (!kho_is_enabled()) {
79+
if (liveupdate_enabled())
80+
pr_warn("Disabling liveupdate because KHO is disabled\n");
81+
luo_global.enabled = false;
82+
return 0;
83+
}
84+
85+
/* Retrieve LUO subtree, and verify its format. */
86+
err = kho_retrieve_subtree(LUO_FDT_KHO_ENTRY_NAME, &fdt_phys);
87+
if (err) {
88+
if (err != -ENOENT) {
89+
pr_err("failed to retrieve FDT '%s' from KHO: %pe\n",
90+
LUO_FDT_KHO_ENTRY_NAME, ERR_PTR(err));
91+
return err;
92+
}
93+
94+
return 0;
95+
}
96+
97+
luo_global.fdt_in = phys_to_virt(fdt_phys);
98+
err = fdt_node_check_compatible(luo_global.fdt_in, 0,
99+
LUO_FDT_COMPATIBLE);
100+
if (err) {
101+
pr_err("FDT '%s' is incompatible with '%s' [%d]\n",
102+
LUO_FDT_KHO_ENTRY_NAME, LUO_FDT_COMPATIBLE, err);
103+
104+
return -EINVAL;
105+
}
106+
107+
ln_size = 0;
108+
ptr = fdt_getprop(luo_global.fdt_in, 0, LUO_FDT_LIVEUPDATE_NUM,
109+
&ln_size);
110+
if (!ptr || ln_size != sizeof(luo_global.liveupdate_num)) {
111+
pr_err("Unable to get live update number '%s' [%d]\n",
112+
LUO_FDT_LIVEUPDATE_NUM, ln_size);
113+
114+
return -EINVAL;
115+
}
116+
117+
luo_global.liveupdate_num = get_unaligned((u64 *)ptr);
118+
pr_info("Retrieved live update data, liveupdate number: %lld\n",
119+
luo_global.liveupdate_num);
120+
121+
return 0;
122+
}
123+
124+
static int __init liveupdate_early_init(void)
125+
{
126+
int err;
127+
128+
err = luo_early_startup();
129+
if (err) {
130+
luo_global.enabled = false;
131+
luo_restore_fail("The incoming tree failed to initialize properly [%pe], disabling live update\n",
132+
ERR_PTR(err));
133+
}
134+
135+
return err;
136+
}
137+
early_initcall(liveupdate_early_init);
138+
139+
/* Called during boot to create outgoing LUO fdt tree */
140+
static int __init luo_fdt_setup(void)
141+
{
142+
const u64 ln = luo_global.liveupdate_num + 1;
143+
void *fdt_out;
144+
int err;
145+
146+
fdt_out = kho_alloc_preserve(LUO_FDT_SIZE);
147+
if (IS_ERR(fdt_out)) {
148+
pr_err("failed to allocate/preserve FDT memory\n");
149+
return PTR_ERR(fdt_out);
150+
}
151+
152+
err = fdt_create(fdt_out, LUO_FDT_SIZE);
153+
err |= fdt_finish_reservemap(fdt_out);
154+
err |= fdt_begin_node(fdt_out, "");
155+
err |= fdt_property_string(fdt_out, "compatible", LUO_FDT_COMPATIBLE);
156+
err |= fdt_property(fdt_out, LUO_FDT_LIVEUPDATE_NUM, &ln, sizeof(ln));
157+
err |= fdt_end_node(fdt_out);
158+
err |= fdt_finish(fdt_out);
159+
if (err)
160+
goto exit_free;
161+
162+
err = kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out);
163+
if (err)
164+
goto exit_free;
165+
luo_global.fdt_out = fdt_out;
166+
167+
return 0;
168+
169+
exit_free:
170+
kho_unpreserve_free(fdt_out);
171+
pr_err("failed to prepare LUO FDT: %d\n", err);
172+
173+
return err;
174+
}
175+
176+
/*
177+
* late initcall because it initializes the outgoing tree that is needed only
178+
* once userspace starts using /dev/liveupdate.
179+
*/
180+
static int __init luo_late_startup(void)
181+
{
182+
int err;
183+
184+
if (!liveupdate_enabled())
185+
return 0;
186+
187+
err = luo_fdt_setup();
188+
if (err)
189+
luo_global.enabled = false;
190+
191+
return err;
192+
}
193+
late_initcall(luo_late_startup);
194+
58195
/* Public Functions */
59196

60197
/**
@@ -69,7 +206,22 @@ early_param("liveupdate", early_liveupdate_param);
69206
*/
70207
int liveupdate_reboot(void)
71208
{
72-
return 0;
209+
int err;
210+
211+
if (!liveupdate_enabled())
212+
return 0;
213+
214+
err = kho_finalize();
215+
if (err) {
216+
pr_err("kho_finalize failed %d\n", err);
217+
/*
218+
* kho_finalize() may return libfdt errors, to aboid passing to
219+
* userspace unknown errors, change this to EAGAIN.
220+
*/
221+
err = -EAGAIN;
222+
}
223+
224+
return err;
73225
}
74226

75227
/**

kernel/liveupdate/luo_internal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/*
4+
* Copyright (c) 2025, Google LLC.
5+
* Pasha Tatashin <pasha.tatashin@soleen.com>
6+
*/
7+
8+
#ifndef _LINUX_LUO_INTERNAL_H
9+
#define _LINUX_LUO_INTERNAL_H
10+
11+
#include <linux/liveupdate.h>
12+
13+
/*
14+
* Handles a deserialization failure: devices and memory is in unpredictable
15+
* state.
16+
*
17+
* Continuing the boot process after a failure is dangerous because it could
18+
* lead to leaks of private data.
19+
*/
20+
#define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__)
21+
22+
#endif /* _LINUX_LUO_INTERNAL_H */

0 commit comments

Comments
 (0)