From: "Pratyush Yadav (Google)" The private_data field of struct liveupdate_file_op_args lets file handlers keep runtime state that is not preserved. It is set by .preserve() and passed to the later outgoing callbacks, up to .unpreserve(). But in the new kernel, nothing set by .retrieve() is kept, and .can_finish() and .finish() always get a NULL private_data. Handlers might need to keep runtime state from retrieve until finish. For example, memfd will need to remember the folios it holds on to until finish so it can release them there. Save the private_data set by a successful .retrieve() in the luo_file, and pass it to .can_finish() and .finish(). The handler must free it in .finish(). Signed-off-by: Pratyush Yadav (Google) --- include/linux/liveupdate.h | 8 +++++--- kernel/liveupdate/luo_file.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 63ea5417de849..21caff8a98a7e 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -36,9 +36,11 @@ struct file; * @serialized_data: The opaque u64 handle, preserve/prepare/freeze may update * this field. * @private_data: Private data for the file used to hold runtime state that - * is not preserved. Set by the handler's .preserve() - * callback, and must be freed in the handler's - * .unpreserve() callback. + * is not preserved. For outgoing, set by the handler's + * .preserve() callback, and must be freed in the handler's + * .unpreserve() callback. For incoming, set by the handler's + * .retrieve() callback on success, and must be freed in the + * handler's .finish() callback. * * This structure bundles all parameters for the file operation callbacks. * The 'data' and 'file' fields are used for both input and output. diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index c39f96961a85b..ca4b685d6e1ce 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -130,9 +130,11 @@ static DEFINE_XARRAY(luo_preserved_files); * .retrieve(), and .finish() callbacks, allowing it to track * and update its serialized state across phases. * @private_data: Pointer to the private data for the file used to hold runtime - * state that is not preserved. Set by the handler's .preserve() - * callback, and must be freed in the handler's .unpreserve() - * callback. + * state that is not preserved. For outgoing, set by the + * handler's .preserve() callback, and must be freed in the + * handler's .unpreserve() callback. For incoming, set by the + * handler's .retrieve() callback, and must be freed in the + * handler's .finish() callback. * @retrieve_status: Status code indicating whether a user/kernel in the new kernel has * successfully called retrieve() on this file. This prevents * multiple retrieval attempts. A value of 0 means a retrieve() @@ -596,6 +598,7 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, } luo_file->file = args.file; + luo_file->private_data = args.private_data; /* Get reference so we can keep this file in LUO until finish */ get_file(luo_file->file); @@ -622,6 +625,7 @@ static int luo_file_can_finish_one(struct luo_file_set *file_set, args.handler = luo_file->fh; args.file = luo_file->file; args.serialized_data = luo_file->serialized_data; + args.private_data = luo_file->private_data; args.retrieve_status = luo_file->retrieve_status; can_finish = luo_file->fh->ops->can_finish(&args); } @@ -639,6 +643,7 @@ static void luo_file_finish_one(struct luo_file_set *file_set, args.handler = luo_file->fh; args.file = luo_file->file; args.serialized_data = luo_file->serialized_data; + args.private_data = luo_file->private_data; args.retrieve_status = luo_file->retrieve_status; luo_file->fh->ops->finish(&args); -- 2.56.0.385.gac671c819a-goog