at master 4.9 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2 3/* 4 * Copyright (c) 2025, Google LLC. 5 * Pasha Tatashin <pasha.tatashin@soleen.com> 6 */ 7#ifndef _LINUX_LIVEUPDATE_H 8#define _LINUX_LIVEUPDATE_H 9 10#include <linux/bug.h> 11#include <linux/compiler.h> 12#include <linux/kho/abi/luo.h> 13#include <linux/list.h> 14#include <linux/types.h> 15#include <uapi/linux/liveupdate.h> 16 17struct liveupdate_file_handler; 18struct 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 * @private_data: Private data for the file used to hold runtime state that 31 * is not preserved. Set by the handler's .preserve() 32 * callback, and must be freed in the handler's 33 * .unpreserve() callback. 34 * 35 * This structure bundles all parameters for the file operation callbacks. 36 * The 'data' and 'file' fields are used for both input and output. 37 */ 38struct liveupdate_file_op_args { 39 struct liveupdate_file_handler *handler; 40 bool retrieved; 41 struct file *file; 42 u64 serialized_data; 43 void *private_data; 44}; 45 46/** 47 * struct liveupdate_file_ops - Callbacks for live-updatable files. 48 * @can_preserve: Required. Lightweight check to see if this handler is 49 * compatible with the given file. 50 * @preserve: Required. Performs state-saving for the file. 51 * @unpreserve: Required. Cleans up any resources allocated by @preserve. 52 * @freeze: Optional. Final actions just before kernel transition. 53 * @unfreeze: Optional. Undo freeze operations. 54 * @retrieve: Required. Restores the file in the new kernel. 55 * @can_finish: Optional. Check if this FD can finish, i.e. all restoration 56 * pre-requirements for this FD are satisfied. Called prior to 57 * finish, in order to do successful finish calls for all 58 * resources in the session. 59 * @finish: Required. Final cleanup in the new kernel. 60 * @owner: Module reference 61 * 62 * All operations (except can_preserve) receive a pointer to a 63 * 'struct liveupdate_file_op_args' containing the necessary context. 64 */ 65struct liveupdate_file_ops { 66 bool (*can_preserve)(struct liveupdate_file_handler *handler, 67 struct file *file); 68 int (*preserve)(struct liveupdate_file_op_args *args); 69 void (*unpreserve)(struct liveupdate_file_op_args *args); 70 int (*freeze)(struct liveupdate_file_op_args *args); 71 void (*unfreeze)(struct liveupdate_file_op_args *args); 72 int (*retrieve)(struct liveupdate_file_op_args *args); 73 bool (*can_finish)(struct liveupdate_file_op_args *args); 74 void (*finish)(struct liveupdate_file_op_args *args); 75 struct module *owner; 76}; 77 78/** 79 * struct liveupdate_file_handler - Represents a handler for a live-updatable file type. 80 * @ops: Callback functions 81 * @compatible: The compatibility string (e.g., "memfd-v1", "vfiofd-v1") 82 * that uniquely identifies the file type this handler 83 * supports. This is matched against the compatible string 84 * associated with individual &struct file instances. 85 * 86 * Modules that want to support live update for specific file types should 87 * register an instance of this structure. LUO uses this registration to 88 * determine if a given file can be preserved and to find the appropriate 89 * operations to manage its state across the update. 90 */ 91struct liveupdate_file_handler { 92 const struct liveupdate_file_ops *ops; 93 const char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH]; 94 95 /* private: */ 96 97 /* 98 * Used for linking this handler instance into a global list of 99 * registered file handlers. 100 */ 101 struct list_head __private list; 102}; 103 104#ifdef CONFIG_LIVEUPDATE 105 106/* Return true if live update orchestrator is enabled */ 107bool liveupdate_enabled(void); 108 109/* Called during kexec to tell LUO that entered into reboot */ 110int liveupdate_reboot(void); 111 112int liveupdate_register_file_handler(struct liveupdate_file_handler *fh); 113int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh); 114 115#else /* CONFIG_LIVEUPDATE */ 116 117static inline bool liveupdate_enabled(void) 118{ 119 return false; 120} 121 122static inline int liveupdate_reboot(void) 123{ 124 return 0; 125} 126 127static inline int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) 128{ 129 return -EOPNOTSUPP; 130} 131 132static inline int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) 133{ 134 return -EOPNOTSUPP; 135} 136 137#endif /* CONFIG_LIVEUPDATE */ 138#endif /* _LINUX_LIVEUPDATE_H */