Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Pratyush Yadav and committed by
Andrew Morton
8def1863 ed6f45f8

+14
+5
include/linux/liveupdate.h
··· 27 27 * this to the file being operated on. 28 28 * @serialized_data: The opaque u64 handle, preserve/prepare/freeze may update 29 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. 30 34 * 31 35 * This structure bundles all parameters for the file operation callbacks. 32 36 * The 'data' and 'file' fields are used for both input and output. ··· 40 36 bool retrieved; 41 37 struct file *file; 42 38 u64 serialized_data; 39 + void *private_data; 43 40 }; 44 41 45 42 /**
+9
kernel/liveupdate/luo_file.c
··· 129 129 * This handle is passed back to the handler's .freeze(), 130 130 * .retrieve(), and .finish() callbacks, allowing it to track 131 131 * 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. 132 136 * @retrieved: A flag indicating whether a user/kernel in the new kernel has 133 137 * successfully called retrieve() on this file. This prevents 134 138 * multiple retrieval attempts. ··· 159 155 struct liveupdate_file_handler *fh; 160 156 struct file *file; 161 157 u64 serialized_data; 158 + void *private_data; 162 159 bool retrieved; 163 160 struct mutex mutex; 164 161 struct list_head list; ··· 303 298 goto err_kfree; 304 299 305 300 luo_file->serialized_data = args.serialized_data; 301 + luo_file->private_data = args.private_data; 306 302 list_add_tail(&luo_file->list, &file_set->files_list); 307 303 file_set->count++; 308 304 ··· 350 344 args.handler = luo_file->fh; 351 345 args.file = luo_file->file; 352 346 args.serialized_data = luo_file->serialized_data; 347 + args.private_data = luo_file->private_data; 353 348 luo_file->fh->ops->unpreserve(&args); 354 349 355 350 list_del(&luo_file->list); ··· 377 370 args.handler = luo_file->fh; 378 371 args.file = luo_file->file; 379 372 args.serialized_data = luo_file->serialized_data; 373 + args.private_data = luo_file->private_data; 380 374 381 375 err = luo_file->fh->ops->freeze(&args); 382 376 if (!err) ··· 398 390 args.handler = luo_file->fh; 399 391 args.file = luo_file->file; 400 392 args.serialized_data = luo_file->serialized_data; 393 + args.private_data = luo_file->private_data; 401 394 402 395 luo_file->fh->ops->unfreeze(&args); 403 396 }