liveupdate: luo_file: remember retrieve() status
Subsystems (2)
Pratyush Yadav
maintainerPATCH v2 1/1 liveupdate: luo_file: remember retrieve() status
From: "Pratyush Yadav (Google)" <[email protected]>
LUO keeps track of successful retrieve attempts on a LUO file. It does so to avoid multiple retrievals of the same file. Multiple retrievals cause problems because once the file is retrieved, the serialized data structures are likely freed and the file is likely in a very different state from what the code expects.
The retrieve boolean in struct luo_file keeps track of this, and is passed to the finish callback so it knows what work was already done and what it has left to do.
All this works well when retrieve succeeds. When it fails, luo_retrieve_file() returns the error immediately, without ever storing anywhere that a retrieve was attempted or what its error code was. This results in an errored LIVEUPDATE_SESSION_RETRIEVE_FD ioctl to userspace, but nothing prevents it from trying this again.
The retry is problematic for much of the same reasons listed above. The file is likely in a very different state than what the retrieve logic normally expects, and it might even have freed some serialization data structures. Attempting to access them or free them again is going to break things.
For example, if memfd managed to restore 8 of its 10 folios, but fails on the 9th, a subsequent retrieve attempt will try to call kho_restore_folio() on the first folio again, and that will fail with a warning since it is an invalid operation.
Apart from the retry, finish() also breaks. Since on failure the retrieved bool in luo_file is never touched, the finish() call on session close will tell the file handler that retrieve was never attempted, and it will try to access or free the data structures that might not exist, much in the same way as the retry attempt.
There is no sane way of attempting the retrieve again. Remember the error retrieve returned and directly return it on a retry. Also pass this status code to finish() so it can make the right decision on the work it needs to do.
This is done by changing the bool to an integer. A value of 0 means retrieve was never attempted, a positive value means it succeeded, and a negative value means it failed and the error code is the value.
---
Notes:
Changes in v2:
- s/retrieve_sts/retrieve_status/g
- Update name in liveupdate_file_op_args docstring.
- Re-order retrieve_status checks in luo_retrieve_file().
- Do not explicitly initialize retrieve_status since we kzalloc() both luo_file and liveupdate_file_op_args.
- Apply commit message fixups suggested by Mike.
include/linux/liveupdate.h | 9 +++++--- kernel/liveupdate/luo_file.c | 41 ++++++++++++++++++++++-------------- mm/memfd_luo.c | 7 +++++- 3 files changed, 37 insertions(+), 20 deletions(-)
include/linux/liveupdate.h +6 -3
@@ -23,8 +23,11 @@ struct file;/** * struct liveupdate_file_op_args - Arguments for file operation callbacks. * @handler: The file handler being called. -* @retrieved: The retrieve status for the 'can_finish / finish' -* operation. +* @retrieve_status: The retrieve status for the 'can_finish / finish' +* operation. A value of 0 means the retrieve has not been +* attempted, a positive value means the retrieve was +* successful, and a negative value means the retrieve failed, +* and the value is the error code of the call. * @file: The file object. For retrieve: [OUT] The callback sets * this to the new file. For other ops: [IN] The caller sets * this to the file being operated on.
@@ -40,7 +43,7 @@ struct file;*/ struct liveupdate_file_op_args {struct liveupdate_file_handler *handler; -bool retrieved; +int retrieve_status;struct file *file;u64 serialized_data;void *private_data;
kernel/liveupdate/luo_file.c +25 -16
92 lines not on this page · raw message
mm/memfd_luo.c +6 -1
@@ -326,7 +326,12 @@ static void memfd_luo_finish(struct liveupdate_file_op_args *args)struct memfd_luo_folio_ser *folios_ser;struct memfd_luo_ser *ser; -if (args->retrieved) +/* +* If retrieve was successful, nothing to do. If it failed, retrieve() +* already cleaned up everything it could. So nothing to do there +* either. Only need to clean up when retrieve was not called. +*/ +if (args->retrieve_status)return ; ser =phys_to_virt (args->serialized_data);
base-commit: 6c8dd4f02805de481c200636e567a871f25399a2
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
Andrew Morton
maintainerQuoted 40 lines · On Mon, 16 Feb 2026 14:22:19 +0100 Pratyush Yadav <[email protected]> wrote:
From: "Pratyush Yadav (Google)" <[email protected]>
LUO keeps track of successful retrieve attempts on a LUO file. It does so to avoid multiple retrievals of the same file. Multiple retrievals cause problems because once the file is retrieved, the serialized data structures are likely freed and the file is likely in a very different state from what the code expects.
The retrieve boolean in struct
luo_filekeeps track of this, and is passed to the finish callback so it knows what work was already done and what it has left to do.All this works well when retrieve succeeds. When it fails,
luo_retrieve_file()returns the error immediately, without ever storing anywhere that a retrieve was attempted or what its error code was. This results in an erroredLIVEUPDATE_SESSION_RETRIEVE_FDioctl to userspace, but nothing prevents it from trying this again.The retry is problematic for much of the same reasons listed above. The file is likely in a very different state than what the retrieve logic normally expects, and it might even have freed some serialization data structures. Attempting to access them or free them again is going to break things.
For example, if memfd managed to restore 8 of its 10 folios, but fails on the 9th, a subsequent retrieve attempt will try to call
kho_restore_folio()on the first folio again, and that will fail with a warning since it is an invalid operation.Apart from the retry,
finish()also breaks. Since on failure the retrieved bool inluo_fileis never touched, thefinish()call on session close will tell the file handler that retrieve was never attempted, and it will try to access or free the data structures that might not exist, much in the same way as the retry attempt.There is no sane way of attempting the retrieve again. Remember the error retrieve returned and directly return it on a retry. Also pass this status code to
finish()so it can make the right decision on the work it needs to do.
Quoted 5 lines
This is done by changing the bool to an integer. A value of 0 means retrieve was never attempted, a positive value means it succeeded, and a negative value means it failed and the error code is the value.
Fixes 7c722a7f44e0 ("liveupdate: luo_file: implement file systems callbacks")
Should we backport this into 6.19.1?
Pratyush Yadav
maintainerQuoted 42 lines · Andrew Morton
Quoted 40 lines · On Mon, 16 Feb 2026 14:22:19 +0100 Pratyush Yadav <[email protected]> wrote:
From: "Pratyush Yadav (Google)" <[email protected]>
LUO keeps track of successful retrieve attempts on a LUO file. It does so to avoid multiple retrievals of the same file. Multiple retrievals cause problems because once the file is retrieved, the serialized data structures are likely freed and the file is likely in a very different state from what the code expects.
The retrieve boolean in struct
luo_filekeeps track of this, and is passed to the finish callback so it knows what work was already done and what it has left to do.All this works well when retrieve succeeds. When it fails,
luo_retrieve_file()returns the error immediately, without ever storing anywhere that a retrieve was attempted or what its error code was. This results in an erroredLIVEUPDATE_SESSION_RETRIEVE_FDioctl to userspace, but nothing prevents it from trying this again.The retry is problematic for much of the same reasons listed above. The file is likely in a very different state than what the retrieve logic normally expects, and it might even have freed some serialization data structures. Attempting to access them or free them again is going to break things.
For example, if memfd managed to restore 8 of its 10 folios, but fails on the 9th, a subsequent retrieve attempt will try to call
kho_restore_folio()on the first folio again, and that will fail with a warning since it is an invalid operation.Apart from the retry,
finish()also breaks. Since on failure the retrieved bool inluo_fileis never touched, thefinish()call on session close will tell the file handler that retrieve was never attempted, and it will try to access or free the data structures that might not exist, much in the same way as the retry attempt.There is no sane way of attempting the retrieve again. Remember the error retrieve returned and directly return it on a retry. Also pass this status code to
finish()so it can make the right decision on the work it needs to do.
Quoted 7 lines
Quoted 5 lines
This is done by changing the bool to an integer. A value of 0 means retrieve was never attempted, a positive value means it succeeded, and a negative value means it failed and the error code is the value.
Fixes 7c722a7f44e0 ("liveupdate: luo_file: implement file systems callbacks")Should we backport this into 6.19.1?
Yes.
I keep forgetting that a Fixes tag alone isn't enough for stable backports and I should add Cc: [email protected] too.
Please add it to the patch.
Signature · 2 lines
Regards, Pratyush Yadav
Quoted 40 lines · Pratyush Yadav
From: "Pratyush Yadav (Google)" <[email protected]>
LUO keeps track of successful retrieve attempts on a LUO file. It does so to avoid multiple retrievals of the same file. Multiple retrievals cause problems because once the file is retrieved, the serialized data structures are likely freed and the file is likely in a very different state from what the code expects.
The retrieve boolean in struct
luo_filekeeps track of this, and is passed to the finish callback so it knows what work was already done and what it has left to do.All this works well when retrieve succeeds. When it fails,
luo_retrieve_file()returns the error immediately, without ever storing anywhere that a retrieve was attempted or what its error code was. This results in an erroredLIVEUPDATE_SESSION_RETRIEVE_FDioctl to userspace, but nothing prevents it from trying this again.The retry is problematic for much of the same reasons listed above. The file is likely in a very different state than what the retrieve logic normally expects, and it might even have freed some serialization data structures. Attempting to access them or free them again is going to break things.
For example, if memfd managed to restore 8 of its 10 folios, but fails on the 9th, a subsequent retrieve attempt will try to call
kho_restore_folio()on the first folio again, and that will fail with a warning since it is an invalid operation.Apart from the retry,
finish()also breaks. Since on failure the retrieved bool inluo_fileis never touched, thefinish()call on session close will tell the file handler that retrieve was never attempted, and it will try to access or free the data structures that might not exist, much in the same way as the retry attempt.There is no sane way of attempting the retrieve again. Remember the error retrieve returned and directly return it on a retry. Also pass this status code to
finish()so it can make the right decision on the work it needs to do.
Quoted 6 lines
This is done by changing the bool to an integer. A value of 0 means retrieve was never attempted, a positive value means it succeeded, and a negative value means it failed and the error code is the value.
Fixes 7c722a7f44e0 ("liveupdate: luo_file: implement file systems callbacks")Signed-off-by Pratyush Yadav (Google) <[email protected]>
Signature · 2 lines
Sincerely yours, Mike.