mirror of
https://github.com/torvalds/linux.git
synced 2026-12-02 11:34:58 +00:00
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/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Reviewed-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Pratyush Yadav <[email protected]> Tested-by: David Matlack <[email protected]> Cc: Aleksander Lobakin <[email protected]> Cc: Alexander Graf <[email protected]> Cc: Alice Ryhl <[email protected]> Cc: Andriy Shevchenko <[email protected]> Cc: anish kumar <[email protected]> Cc: Anna Schumaker <[email protected]> Cc: Bartosz Golaszewski <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Borislav Betkov <[email protected]> Cc: Chanwoo Choi <[email protected]> Cc: Chen Ridong <[email protected]> Cc: Chris Li <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Daniel Wagner <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Dan Williams <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Jeffery <[email protected]> Cc: David Rientjes <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Guixin Liu <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ilpo Järvinen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ira Weiny <[email protected]> Cc: Jann Horn <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Joanthan Cameron <[email protected]> Cc: Joel Granados <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Lennart Poettering <[email protected]> Cc: Leon Romanovsky <[email protected]> Cc: Leon Romanovsky <[email protected]> Cc: Lukas Wunner <[email protected]> Cc: Marc Rutland <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Matthew Maurer <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Myugnjoo Ham <[email protected]> Cc: Parav Pandit <[email protected]> Cc: Pratyush Yadav <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Saeed Mahameed <[email protected]> Cc: Samiullah Khawaja <[email protected]> Cc: Song Liu <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Stuart Hayes <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Thomas Gleinxer <[email protected]> Cc: Thomas Weißschuh <[email protected]> Cc: Vincent Guittot <[email protected]> Cc: William Tu <[email protected]> Cc: Yoann Congal <[email protected]> Cc: Zhu Yanjun <[email protected]> Cc: Zijun Hu <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
111 lines
3.7 KiB
C
111 lines
3.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
* Copyright (c) 2025, Google LLC.
|
|
* Pasha Tatashin <[email protected]>
|
|
*/
|
|
|
|
#ifndef _LINUX_LUO_INTERNAL_H
|
|
#define _LINUX_LUO_INTERNAL_H
|
|
|
|
#include <linux/liveupdate.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
struct luo_ucmd {
|
|
void __user *ubuffer;
|
|
u32 user_size;
|
|
void *cmd;
|
|
};
|
|
|
|
static inline int luo_ucmd_respond(struct luo_ucmd *ucmd,
|
|
size_t kernel_cmd_size)
|
|
{
|
|
/*
|
|
* Copy the minimum of what the user provided and what we actually
|
|
* have.
|
|
*/
|
|
if (copy_to_user(ucmd->ubuffer, ucmd->cmd,
|
|
min_t(size_t, ucmd->user_size, kernel_cmd_size))) {
|
|
return -EFAULT;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Handles a deserialization failure: devices and memory is in unpredictable
|
|
* state.
|
|
*
|
|
* Continuing the boot process after a failure is dangerous because it could
|
|
* lead to leaks of private data.
|
|
*/
|
|
#define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__)
|
|
|
|
/* Mimics list_for_each_entry() but for private list head entries */
|
|
#define luo_list_for_each_private(pos, head, member) \
|
|
for (struct list_head *__iter = (head)->next; \
|
|
__iter != (head) && \
|
|
({ pos = container_of(__iter, typeof(*(pos)), member); 1; }); \
|
|
__iter = __iter->next)
|
|
|
|
/**
|
|
* 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 serialized
|
|
* state of files.
|
|
* @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;
|
|
long count;
|
|
};
|
|
|
|
/**
|
|
* struct luo_session - Represents an active or incoming Live Update session.
|
|
* @name: A unique name for this session, used for identification and
|
|
* retrieval.
|
|
* @ser: Pointer to the serialized data for this session.
|
|
* @list: A list_head member used to link this session into a global list
|
|
* of either outgoing (to be preserved) or incoming (restored from
|
|
* previous kernel) sessions.
|
|
* @retrieved: A boolean flag indicating whether this session has been
|
|
* retrieved by a consumer in the new kernel.
|
|
* @file_set: A set of files that belong to this session.
|
|
* @mutex: protects fields in the luo_session.
|
|
*/
|
|
struct luo_session {
|
|
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
|
|
struct luo_session_ser *ser;
|
|
struct list_head list;
|
|
bool retrieved;
|
|
struct luo_file_set file_set;
|
|
struct mutex mutex;
|
|
};
|
|
|
|
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 luo_session_serialize(void);
|
|
int luo_session_deserialize(void);
|
|
bool luo_session_quiesce(void);
|
|
void luo_session_resume(void);
|
|
|
|
int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd);
|
|
void luo_file_unpreserve_files(struct luo_file_set *file_set);
|
|
int luo_file_freeze(struct luo_file_set *file_set,
|
|
struct luo_file_set_ser *file_set_ser);
|
|
void luo_file_unfreeze(struct luo_file_set *file_set,
|
|
struct luo_file_set_ser *file_set_ser);
|
|
int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
|
|
struct file **filep);
|
|
int luo_file_finish(struct luo_file_set *file_set);
|
|
int luo_file_deserialize(struct luo_file_set *file_set,
|
|
struct luo_file_set_ser *file_set_ser);
|
|
void luo_file_set_init(struct luo_file_set *file_set);
|
|
void luo_file_set_destroy(struct luo_file_set *file_set);
|
|
|
|
#endif /* _LINUX_LUO_INTERNAL_H */
|