Skip to content

Commit 8def186

Browse files
prati0100akpm00
authored andcommitted
liveupdate: luo_file: add private argument to store runtime state
Currently file handlers only get the serialized_data field to store their state. This field has a pointer to the serialized state of the file, and it becomes a part of LUO file's serialized state. File handlers can also need some runtime state to track information that shouldn't make it in the serialized data. One such example is a vmalloc pointer. While kho_preserve_vmalloc() preserves the memory backing a vmalloc allocation, it does not store the original vmap pointer, since that has no use being passed to the next kernel. The pointer is needed to free the memory in case the file is unpreserved. Provide a private field in struct luo_file and pass it to all the callbacks. The field's can be set by preserve, and must be freed by unpreserve. Link: https://lkml.kernel.org/r/20251125165850.3389713-14-pasha.tatashin@soleen.com Signed-off-by: Pratyush Yadav <ptyadav@amazon.de> Co-developed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Mike Rapoport (Microsoft) <rppt@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 <pratyush@kernel.org> 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 ed6f45f commit 8def186

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

include/linux/liveupdate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ struct file;
2727
* this to the file being operated on.
2828
* @serialized_data: The opaque u64 handle, preserve/prepare/freeze may update
2929
* 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.
3034
*
3135
* This structure bundles all parameters for the file operation callbacks.
3236
* The 'data' and 'file' fields are used for both input and output.
@@ -36,6 +40,7 @@ struct liveupdate_file_op_args {
3640
bool retrieved;
3741
struct file *file;
3842
u64 serialized_data;
43+
void *private_data;
3944
};
4045

4146
/**

kernel/liveupdate/luo_file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ static LIST_HEAD(luo_file_handler_list);
129129
* This handle is passed back to the handler's .freeze(),
130130
* .retrieve(), and .finish() callbacks, allowing it to track
131131
* and update its serialized state across phases.
132+
* @private_data: Pointer to the private data for the file used to hold runtime
133+
* state that is not preserved. Set by the handler's .preserve()
134+
* callback, and must be freed in the handler's .unpreserve()
135+
* callback.
132136
* @retrieved: A flag indicating whether a user/kernel in the new kernel has
133137
* successfully called retrieve() on this file. This prevents
134138
* multiple retrieval attempts.
@@ -155,6 +159,7 @@ struct luo_file {
155159
struct liveupdate_file_handler *fh;
156160
struct file *file;
157161
u64 serialized_data;
162+
void *private_data;
158163
bool retrieved;
159164
struct mutex mutex;
160165
struct list_head list;
@@ -298,6 +303,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
298303
goto err_kfree;
299304

300305
luo_file->serialized_data = args.serialized_data;
306+
luo_file->private_data = args.private_data;
301307
list_add_tail(&luo_file->list, &file_set->files_list);
302308
file_set->count++;
303309

@@ -344,6 +350,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set)
344350
args.handler = luo_file->fh;
345351
args.file = luo_file->file;
346352
args.serialized_data = luo_file->serialized_data;
353+
args.private_data = luo_file->private_data;
347354
luo_file->fh->ops->unpreserve(&args);
348355

349356
list_del(&luo_file->list);
@@ -370,6 +377,7 @@ static int luo_file_freeze_one(struct luo_file_set *file_set,
370377
args.handler = luo_file->fh;
371378
args.file = luo_file->file;
372379
args.serialized_data = luo_file->serialized_data;
380+
args.private_data = luo_file->private_data;
373381

374382
err = luo_file->fh->ops->freeze(&args);
375383
if (!err)
@@ -390,6 +398,7 @@ static void luo_file_unfreeze_one(struct luo_file_set *file_set,
390398
args.handler = luo_file->fh;
391399
args.file = luo_file->file;
392400
args.serialized_data = luo_file->serialized_data;
401+
args.private_data = luo_file->private_data;
393402

394403
luo_file->fh->ops->unfreeze(&args);
395404
}

0 commit comments

Comments
 (0)