| 1 |
|
| 2 |
|
| 3 | |
| 4 | * Copyright (c) 2025, Google LLC.
|
| 5 | * Pasha Tatashin <[email protected]>
|
| 6 |
|
| 7 |
|
| 8 | #ifndef _LINUX_LUO_INTERNAL_H
|
| 9 | #define _LINUX_LUO_INTERNAL_H
|
| 10 |
|
| 11 | #include <linux/liveupdate.h>
|
| 12 | #include <linux/uaccess.h>
|
| 13 | #include <linux/kho_block.h>
|
| 14 |
|
| 15 | struct luo_ucmd {
|
| 16 | void __user *ubuffer;
|
| 17 | u32 user_size;
|
| 18 | void *cmd;
|
| 19 | };
|
| 20 |
|
| 21 | static inline int luo_ucmd_respond(struct luo_ucmd *ucmd,
|
| 22 | size_t kernel_cmd_size)
|
| 23 | {
|
| 24 | |
| 25 | * Copy the minimum of what the user provided and what we actually
|
| 26 | * have.
|
| 27 |
|
| 28 | if (copy_to_user(ucmd->ubuffer, ucmd->cmd,
|
| 29 | min_t(size_t, ucmd->user_size, kernel_cmd_size))) {
|
| 30 | return -EFAULT;
|
| 31 | }
|
| 32 | return 0;
|
| 33 | }
|
| 34 |
|
| 35 | |
| 36 | * Handles a deserialization failure: devices and memory is in unpredictable
|
| 37 | * state.
|
| 38 | *
|
| 39 | * Continuing the boot process after a failure is dangerous because it could
|
| 40 | * lead to leaks of private data.
|
| 41 |
|
| 42 | #define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__)
|
| 43 |
|
| 44 | |
| 45 | * struct luo_file_set - A set of files that belong to the same sessions.
|
| 46 | * @files_list: An ordered list of files associated with this session, it is
|
| 47 | * ordered by preservation time.
|
| 48 | * @block_set: The set of serialization blocks.
|
| 49 | * @count: A counter tracking the number of files currently stored in the
|
| 50 | * @files_list for this session.
|
| 51 |
|
| 52 | struct luo_file_set {
|
| 53 | struct list_head files_list;
|
| 54 | struct kho_block_set block_set;
|
| 55 | u64 count;
|
| 56 | };
|
| 57 |
|
| 58 | |
| 59 | * struct luo_session - Represents an active or incoming Live Update session.
|
| 60 | * @name: A unique name for this session, used for identification and
|
| 61 | * retrieval.
|
| 62 | * @list: A list_head member used to link this session into a global list
|
| 63 | * of either outgoing (to be preserved) or incoming (restored from
|
| 64 | * previous kernel) sessions.
|
| 65 | * @retrieved: A boolean flag indicating whether this session has been
|
| 66 | * retrieved by a consumer in the new kernel.
|
| 67 | * @file_set: A set of files that belong to this session.
|
| 68 | * @mutex: protects fields in the luo_session.
|
| 69 |
|
| 70 | struct luo_session {
|
| 71 | char name[LIVEUPDATE_SESSION_NAME_LENGTH];
|
| 72 | struct list_head list;
|
| 73 | bool retrieved;
|
| 74 | struct luo_file_set file_set;
|
| 75 | struct mutex mutex;
|
| 76 | };
|
| 77 |
|
| 78 | extern struct rw_semaphore luo_register_rwlock;
|
| 79 |
|
| 80 | int luo_session_create(const char *name, struct file **filep);
|
| 81 | int luo_session_retrieve(const char *name, struct file **filep);
|
| 82 | void __init luo_session_setup_outgoing(u64 *sessions_pa);
|
| 83 | int __init luo_session_setup_incoming(u64 sessions_pa);
|
| 84 | int luo_session_serialize(void);
|
| 85 | int luo_session_deserialize(void);
|
| 86 |
|
| 87 | int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd);
|
| 88 | void luo_file_unpreserve_files(struct luo_file_set *file_set);
|
| 89 | int luo_file_freeze(struct luo_file_set *file_set,
|
| 90 | struct luo_file_set_ser *file_set_ser);
|
| 91 | void luo_file_unfreeze(struct luo_file_set *file_set,
|
| 92 | struct luo_file_set_ser *file_set_ser);
|
| 93 | int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
|
| 94 | struct file **filep);
|
| 95 | int luo_file_finish(struct luo_file_set *file_set);
|
| 96 | int luo_file_deserialize(struct luo_file_set *file_set,
|
| 97 | struct luo_file_set_ser *file_set_ser);
|
| 98 | void luo_file_set_init(struct luo_file_set *file_set);
|
| 99 | void luo_file_set_destroy(struct luo_file_set *file_set);
|
| 100 |
|
| 101 | int luo_flb_file_preserve(struct liveupdate_file_handler *fh);
|
| 102 | void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh);
|
| 103 | void luo_flb_file_finish(struct liveupdate_file_handler *fh);
|
| 104 | void luo_flb_unregister_all(struct liveupdate_file_handler *fh);
|
| 105 | int __init luo_flb_setup_outgoing(u64 *flbs_pa);
|
| 106 | void __init luo_flb_setup_incoming(u64 flbs_pa);
|
| 107 | void luo_flb_serialize(void);
|
| 108 |
|
| 109 | #ifdef CONFIG_LIVEUPDATE_TEST
|
| 110 | void liveupdate_test_register(struct liveupdate_file_handler *fh);
|
| 111 | #else
|
| 112 | static inline void liveupdate_test_register(struct liveupdate_file_handler *fh) { }
|
| 113 | #endif
|
| 114 |
|
| 115 | #endif
|