liveupdate: fix incoming error handling and teardown paths
cover liveupdate: fix incoming error handling and teardown paths
Hi,
This series fixes three small issues in LUO's incoming-side error handling and teardown paths.
The first patch makes session deserialization fail when file deserialization fails, instead of silently continuing with a partially restored session.
The second patch keeps an incoming session retrievable if automatic finish-on-release fails. The VFS ignores ->release() return values during __fput(), so preserving recoverability is more useful than returning an error that userspace will never see.
The third patch initializes incoming FLB state before the finish path decrements its refcount, so the last-user cleanup path does not run from an uninitialized count.
Leo Timmins (3):
liveupdate: propagate file deserialization failures
liveupdate: keep sessions retrievable after release failures
liveupdate: initialize incoming FLB state before finish
kernel/liveupdate/luo_flb.c | 16 +++++++++++++++- kernel/liveupdate/luo_session.c | 13 ++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/3 liveupdate: propagate file deserialization failures
luo_session_deserialize() ignored the return value from luo_file_deserialize(). As a result, a session could be left partially restored even though the /dev/liveupdate open path treats deserialization failures as fatal.
Propagate the error so a failed file deserialization aborts session deserialization instead of silently continuing.
--- kernel/liveupdate/luo_session.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/liveupdate/luo_session.c +7 -2
@@ -558,8 +558,13 @@ int luo_session_deserialize(void) } scoped_guard(mutex, &session->mutex) { -luo_file_deserialize (&session->file_set, - &sh->ser[i].file_set_ser); + err =luo_file_deserialize (&session->file_set, + &sh->ser[i].file_set_ser); + } +if (err) { +pr_warn ("Failed to deserialize files for session [%s] %pe\n" , + session->name,ERR_PTR (err)); +return err; } }
Signature · 1 line
2.53.0
PATCH 2/3 liveupdate: keep sessions retrievable after release failures
In reply to Leo TimminsWhen automatic finish-on-release fails for an incoming session, luo_session_release() cannot report that error back through close(). The VFS ignores ->release() return values during __fput().
Returning with session->retrieved still set leaves the session on the incoming list but impossible to retrieve again after the file descriptor is gone. Clear the retrieved flag so userspace can reopen the session and retry finishing it later.
--- kernel/liveupdate/luo_session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/liveupdate/luo_session.c +3 -1
@@ -210,9 +210,11 @@ static int luo_session_release(struct inode *inodep, struct file *filep)int err =luo_session_finish_one (session);if (err) { +scoped_guard (mutex, &session->mutex) + session->retrieved = false;pr_warn ("Unable to finish session [%s] on release\n" , session->name); -return err; +return 0 ; } sh = &luo_session_global.incoming; }else {
Signature · 1 line
2.53.0
Pasha Tatashin
maintainerRe: [PATCH 2/3] liveupdate: keep sessions retrievable after release failures
Hi Leo,
Sorry for dup, accidentally switched to HTML mode in previous reply, and therefore it was rejected from the mailing lists.
Quoted 4 lines · Leo Timmins
When automatic finish-on-release fails for an incoming session,
luo_session_release()cannot report that error back throughclose(). The VFS ignores ->release() return values during__fput().
Exactly. Since userspace can't detect a close() failure without parsing dmesg, we shouldn't design around it. The API gives explicit ioctl(LIVEUPDATE_SESSION_FINISH) that user should use before closing the session, and if needed repeate finish again.
If userspace closes the session fd before finishing, we have to treat it as a userspace bug. While it does mean the resource leaks until the next live update or reboot, trying to work around this by allowing session retrieval after a close() doesn't make sense. There is no clean way for userspace to know the session is even still there; perhaps blindly firing ioctl(LIVEUPDATE_SESSION_RETRIEVE_FD) would allow querying that.
Quoted 6 lines
Returning with
session->retrievedstill set leaves the session on the incoming list but impossible to retrieve again after the file descriptor is gone. Clear the retrieved flag so userspace can reopen the session and retry finishing it later.Fixes 16cec0d26521 ("liveupdate: luo_session: add ioctls for file preservation")
It changes functionality, not really sure that Fixes applies.
Quoted 10 lines
Signed-off-by Leo Timmins <[email protected]>--- kernel/liveupdate/luo_session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/liveupdate/luo_session.c +0
-0
kernel/liveupdate/luo_session.c static int luo_session_release(struct inode *inodep, struct file *filep) · line 217
Quoted 9 lines
kernel/liveupdate/luo_session.c +3
-1@@ -210,9 +210,11 @@ static int luo_session_release(struct inode *inodep, struct file *filep)int err =luo_session_finish_one (session);if (err) { +scoped_guard (mutex, &session->mutex) + session->retrieved = false;pr_warn ("Unable to finish session [%s] on release\n" , session->name); -return err; +return 0 ;
close() do not return failure to userspace, but is there a disadvantage in propagating this up?
Thanks,
Pasha
Quoted 5 lines
kernel/liveupdate/luo_session.c +0
-1} sh = &luo_session_global.incoming; }else { --2.53.0
PATCH 3/3 liveupdate: initialize incoming FLB state before finish
In reply to Leo Timminsluo_flb_file_finish_one() decremented incoming.count before making sure that the incoming FLB state had been materialized. If no earlier incoming retrieval had populated that state, the first decrement ran from zero and skipped the last-user finish path.
Initialize the incoming FLB state before the first decrement so finish uses the serialized refcount instead of an uninitialized value.
--- kernel/liveupdate/luo_flb.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
kernel/liveupdate/luo_flb.c +15 -1
@@ -192,10 +192,24 @@ static int luo_flb_retrieve_one(struct liveupdate_flb *flb)static void luo_flb_file_finish_one (struct liveupdate_flb *flb) {struct luo_flb_private *private =luo_flb_get_private (flb); +bool needs_retrieve = false;u64 count; -scoped_guard (mutex, &private->incoming.lock) + scoped_guard(mutex, &private->incoming.lock) { +if (!private->incoming.count && !private->incoming.finished) + needs_retrieve = true; + } + +if (needs_retrieve) { +int err =luo_flb_retrieve_one (flb); + +if (WARN_ON (err)) +return ; + } + + scoped_guard(mutex, &private->incoming.lock) { count = --private->incoming.count; + }if (!count) {struct liveupdate_flb_op_args args = {0 };
Signature · 1 line
2.53.0
Pasha Tatashin
maintainerRe: [PATCH 3/3] liveupdate: initialize incoming FLB state before finish
kernel/liveupdate/luo_flb.c static int luo_flb_retrieve_one(struct liveupdate_flb *flb) · line 207
Quoted 5 lines
kernel/liveupdate/luo_flb.c +5
-0+if (needs_retrieve) { +int err =luo_flb_retrieve_one (flb); + +if (WARN_ON (err)) +return ;
Let's use pr_warn() here. Otherwise LGTM.
Thanks,
Pasha