From nobody Mon Jun 8 14:35:25 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C8F73AC0D7 for ; Thu, 28 May 2026 17:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779990110; cv=none; b=bWFCduqeLwEj0gHjlr0neRfZeOyhOC9dXPPleBcle7x6osi3kyNiITb3TzPMouVgcS6w8gwuJ8R3z1n0I1wBh8QHBvZK82wiAq3R73GNvYmeuEK1sQAoKZwa0ZJ0xo0kL/YDX139rU52WZWzIm8Hjsx0JK/aPsTdKVlAwI1uHvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779990110; c=relaxed/simple; bh=QBhXuBBdQPBnfjmLP7bmvCQIK0Vud7gW3z0f/PHyerg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=REtS2HbrWj3FCtE+VFxeiHT5fGi6Ob8OVKAl3TljCDY2G7W6XivVRyjoSj8NJzMwmOW8nhqHU2fl73Q55a0X6LYbOZwcMp/RwVhuOA2U8so2Y0X75S/UsXMCkYDuWzhRbIvtaBDWMcD9FUTPsrNO+U9TEzufsWXpe3axifltJg0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QcXfirr+; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QcXfirr+" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-365ff2ab7beso13783474a91.1 for ; Thu, 28 May 2026 10:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779990108; x=1780594908; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0poEg6dzE32DnYuKI7VywdtZZms3dhY1RszrIEICmMM=; b=QcXfirr+U2LcHT+TBmwiLlCM/AhyK9Tqq2+HdhtbmMZL6fCBwyvqIzI2JJYd3RgITk dPuD1q+rSbSDlM37JzWhQXApP8YMrFK13GH1cCVb8AQoYzkKeTh7Awdw5aUYAJhr7vcD cLw2H6MhHp5lFarj4KCbVRQfNhdvLrX72CL0VJbp/kyRvm1qLgb9OK/27GDgK/oRFcdW Rt52gxocTGabmgvQ4s45oWJDAywVj5a44Lj65jbTVBk6BI5NI9ho2pocrLl1I+YLjd/T GVnNSgugdiY4bECOCupKQgtymlOhV3mWDbSm1o1uWosKjt4bAFtjUNRd7HmMSCvhk6a6 lUsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779990108; x=1780594908; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0poEg6dzE32DnYuKI7VywdtZZms3dhY1RszrIEICmMM=; b=tHmKysJyYQ//JcIh4STohGD/eAduy9CZbqtBArVAwRGfA99YgZtDZi1iIxilXTPjkm XIFPiLV+mf73EI+ib5tK5dNupuYvXqWZlfDW2a6+9OKrTi77pwShsGK++KIkI3G58SP+ RSc4OtaubyGmRngN2qo1Oh9mlZLPLtLVk6Zq25SsNEjY6D1R1Uvzs8Tcocb9l8Om++Tf thU+83I23muMXUL6kEJy0RCVlbqPahNHNshF+5NAgQmOYXGHKShDCVY/H8pTSc3Lzejg gEwpb0Bh9vCB9fuZuj6rQz2licWi0CyDa2VcdvZMyzY4npxRC501yB8/WL5A+OOrb/9W QNtA== X-Forwarded-Encrypted: i=1; AFNElJ+YHmyF0c5FcOpy5XWg84xubm3AG3XlV7GFCc/Nomffw1gH+OWOaTUQby9cPrGpA7Oui20sI3bsVzKD9yI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5MqCBDLLOOwElJ4vA7Ne3FvxFFhtHya8D388nEC0KE3H4ljp7 Ok3vaXy3dYixiBIgcagCUteCSr34951iMCY7YKvnGs+iUZcJUtqNtupq2+8Qiwn8bxMMDC1KFjX +rr7t9VH2t9+wog== X-Received: from pjbei7.prod.google.com ([2002:a17:90a:e547:b0:36a:7f0b:e285]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:544b:b0:36b:9798:4f68 with SMTP id 98e67ed59e1d1-36b9c9717d1mr2611746a91.9.1779990108327; Thu, 28 May 2026 10:41:48 -0700 (PDT) Date: Thu, 28 May 2026 17:41:39 +0000 In-Reply-To: <20260528174140.1921129-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260528174140.1921129-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260528174140.1921129-2-dmatlack@google.com> Subject: [PATCH 1/2] liveupdate: Reference count outgoing FLB data From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Increment the outgoing FLB refcount in liveupdate_flb_get_outgoing() so that the FLB structure cannot be freed while the caller is actively using it. Add an additional liveupdate_flb_put_outgoing() function so the caller can explicitly indicate when it is done using the outgoing FLB. During a Live Update, the kernel may need to fetch the outgoing FLB outside of the scope of a file handler's preserve() and unpreserve() callbacks. In that situation there is no way for the caller to protect itself against the outgoing FLB from being freed while it is using it. Incrementing the reference count in liveupdate_flb_get_outgoing() ensures it cannot be freed. This change also aligns the outgoing FLB lifecycle management with the incoming FLB, since the latter uses the same get/put semantics. Fixes: cab056f2aae7 ("liveupdate: luo_flb: introduce File-Lifecycle-Bound g= lobal state") Assisted-by: Gemini:gemini-3-pro-preview Signed-off-by: David Matlack Reviewed-by: Pasha Tatashin =20 --- include/linux/liveupdate.h | 5 +++++ kernel/liveupdate/luo_flb.c | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 88722e5caf02..c344bf987b63 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -243,6 +243,7 @@ int liveupdate_flb_get_incoming(struct liveupdate_flb *= flb, void **objp); void liveupdate_flb_put_incoming(struct liveupdate_flb *flb); =20 int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, void **objp); +void liveupdate_flb_put_outgoing(struct liveupdate_flb *flb); =20 #else /* CONFIG_LIVEUPDATE */ =20 @@ -292,5 +293,9 @@ static inline int liveupdate_flb_get_outgoing(struct li= veupdate_flb *flb, return -EOPNOTSUPP; } =20 +static inline void liveupdate_flb_put_outgoing(struct liveupdate_flb *flb) +{ +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c index 8f5c5dd01cd0..7ddef552ff6b 100644 --- a/kernel/liveupdate/luo_flb.c +++ b/kernel/liveupdate/luo_flb.c @@ -135,7 +135,7 @@ static int luo_flb_file_preserve_one(struct liveupdate_= flb *flb) return 0; } =20 -static void luo_flb_file_unpreserve_one(struct liveupdate_flb *flb) +void liveupdate_flb_put_outgoing(struct liveupdate_flb *flb) { struct luo_flb_private *private =3D luo_flb_get_private(flb); =20 @@ -266,7 +266,7 @@ int luo_flb_file_preserve(struct liveupdate_file_handle= r *fh) =20 exit_err: list_for_each_entry_continue_reverse(iter, flb_list, list) - luo_flb_file_unpreserve_one(iter->flb); + liveupdate_flb_put_outgoing(iter->flb); up_read(&luo_register_rwlock); =20 return err; @@ -291,7 +291,7 @@ void luo_flb_file_unpreserve(struct liveupdate_file_han= dler *fh) =20 guard(rwsem_read)(&luo_register_rwlock); list_for_each_entry_reverse(iter, flb_list, list) - luo_flb_file_unpreserve_one(iter->flb); + liveupdate_flb_put_outgoing(iter->flb); } =20 /** @@ -546,6 +546,10 @@ int liveupdate_flb_get_outgoing(struct liveupdate_flb = *flb, void **objp) return -EOPNOTSUPP; =20 guard(mutex)(&private->outgoing.lock); + if (!private->outgoing.obj) + return -ENOENT; + + refcount_inc(&private->outgoing.count); *objp =3D private->outgoing.obj; =20 return 0; --=20 2.54.0.823.g6e5bcc1fc9-goog From nobody Mon Jun 8 14:35:25 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0399D3F8EB5 for ; Thu, 28 May 2026 17:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779990111; cv=none; b=gbXUwdQLhqIxe5mLClTSoJpWXrDrs36GBvggwuZSHwLgNJ9WsSVswdefDdZUUdDtWDM/XNUFV6h3fLq6CfoLvhVPdOGmknnEY70gNAQcyqixaVTQp9PZvA8734OjtPFLBZiNC5tv//CABRiReTnRmx1805JXRLNRHb4XmELSJZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779990111; c=relaxed/simple; bh=KAMdx8s2C1zMEwaN5gNaaXfmuRTW1H6Sy6SYcyTzxI4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rVmuDwqogPyc3FQTO7SJ62xYAebqix2V9eQ/xyiOP70JpEPPpNf7vYos6Li3aq1JGfZ3eBVW6KJWMYGLZ3YIWiR5c3Vp7mM2sVp6gyCkjjdA6qDDJaYJ6NlUIiCwY8c4JynYUaWUAEar/UcSsq8VBuLk+0D2L0I9tJw7kU923qY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZeOzaDSq; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZeOzaDSq" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-bce224720d8so6626021a12.1 for ; Thu, 28 May 2026 10:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779990109; x=1780594909; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zI6/R1kae2LnDj1mKhlFVbr6Z6bSt4LSCoOlMnq3wXg=; b=ZeOzaDSqRX1y5YzTW4R7Y1T99rTFReXuQzNvAE3A5wZ2NYWBN8mPBzxLRaXKjNje4/ 3voULJaBBYUfePI+ae6HfP3buM0TDradoGAcS6YUqnLrwTct73RCjopmH0kOT/dsdYRB BQj/5zSxzSiL37KNNAvR8OmgZXDS+P1KVED1c2UeBapjvdcq1779aI66ir6XlaBcYr8h wmAZiqqww1fMJthck/8viPtlFMWElWfD7CyAIUgsUX73sG8hAKVGD+m0ACWxL+pgs+I6 Dl99biTYbZgAgsFhIPkPMSB34SmAFUTyREbd4HNNvf4RiP4+3gYnKhDawSRv4vL03GN6 VI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779990109; x=1780594909; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zI6/R1kae2LnDj1mKhlFVbr6Z6bSt4LSCoOlMnq3wXg=; b=nnkYkhcs2udDzeKH0D2N9/MhlZ8gV2bCFilYqNmtT4o8g6zUD0rj33gAiK16exdrH4 riHN0MQYQSiUcCGFVsu+Dg4deOGyCLUujaXKVJl0/ixAwaW9ppUUb/2H+v2u59cX6uyD 8eabs4VPCfO5rdcWZeGKNjnINF45AVM9mfF0QtztGG96TrlHth6uUwd5f5lGWwZOlCDv QObkxqjx3uDH/Kw3EFZPN6FHB7KqtplZRfmutE+MGtvw9WahGtb4E7tjGUDkn3CTei91 OSAMYVQPArMFMS0kFmWZz43EejEvkbGGBLi7t77mVydjfhqS41WJ5PIzR3xCosFs5l7g 3siQ== X-Forwarded-Encrypted: i=1; AFNElJ96af7+AtlQOh89EfKMyIqGN3fLd6KzXB2CyStK5LSkQGekJEtvz26xHsaA0NnckZ5v7mrGRq8KFsvSWqI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9mOsdWpbXYC0qNGZqUM2r8Y32SUezTJW1FxoL9OynB1aep2S1 N/jxfQfsiyq7yvLcrpb97LCIGKx6bYnGUuL1JYuqTcUYUP0k+/FAnvFTKt94jo++hJPSwkLMAM6 xGmmhVUmBawHvsw== X-Received: from pgli34.prod.google.com ([2002:a63:1322:0:b0:c82:3bf0:91df]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:394c:b0:3a3:33bd:319b with SMTP id adf61e73a8af0-3b328f3b012mr30313814637.39.1779990109127; Thu, 28 May 2026 10:41:49 -0700 (PDT) Date: Thu, 28 May 2026 17:41:40 +0000 In-Reply-To: <20260528174140.1921129-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260528174140.1921129-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260528174140.1921129-3-dmatlack@google.com> Subject: [PATCH 2/2] liveupdate: Remember FLB retrieve() status From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" LUO keeps track of successful retrieve attempts on an FLB. It does so to avoid multiple retrievals of the same FLB. Multiple retrievals cause problems because once the FLB is retrieved, the serialized data structures are likely freed and the FLB is likely in a very different state from what the code expects. All this works well when retrieve succeeds. When it fails, luo_flb_retrieve_one() returns the error immediately, without ever storing anywhere that a retrieve was attempted or what its error code was. If the user attempts to retrieve another file registered with the same FLB, LUO will attempt to call the FLB's retrieve() callback again. The retry is problematic for much of the same reasons listed above. The FLB is likely in a very different state than what the retrieve logic normally expects (e.g. some KHO pages may have already been restored and freed). There is no sane way of attempting the retrieve again. Remember the error retrieve returned and directly return it on a retry. This is done by changing the retrieved bool to a retrieve_status 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. This is similar to commit f85b1c6af5bc ("liveupdate: luo_file: remember retrieve() status") which did the same for LUO files. Fixes: cab056f2aae7 ("liveupdate: luo_flb: introduce File-Lifecycle-Bound g= lobal state") Assisted-by: Gemini:gemini-3-pro-preview Signed-off-by: David Matlack Reviewed-by: Pasha Tatashin =20 Reviewed-by: Pratyush Yadav (Google) --- include/linux/liveupdate.h | 6 ++++-- kernel/liveupdate/luo_flb.c | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index c344bf987b63..63ea5417de84 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -173,7 +173,9 @@ struct liveupdate_flb_ops { * @lock: A mutex that protects all fields within this structure, pro= viding * the synchronization service for the FLB's ops. * @finished: True once the FLB's finish() callback has run. - * @retrieved: True once the FLB's retrieve() callback has run. + * @retrieve_status: Status code indicating whether retrieve() has been + * attempted. 0 means not attempted, 1 means successful, + * and negative value means it failed with that error co= de. */ struct luo_flb_private_state { refcount_t count; @@ -181,7 +183,7 @@ struct luo_flb_private_state { void *obj; struct mutex lock; bool finished; - bool retrieved; + int retrieve_status; }; =20 /* diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c index 7ddef552ff6b..f8852f7e62e5 100644 --- a/kernel/liveupdate/luo_flb.c +++ b/kernel/liveupdate/luo_flb.c @@ -170,7 +170,10 @@ static int luo_flb_retrieve_one(struct liveupdate_flb = *flb) if (private->incoming.finished) return -ENODATA; =20 - if (private->incoming.retrieved) + if (private->incoming.retrieve_status < 0) + return private->incoming.retrieve_status; + + if (private->incoming.retrieve_status > 0) return 0; =20 if (!fh->active) @@ -196,12 +199,13 @@ static int luo_flb_retrieve_one(struct liveupdate_flb= *flb) =20 err =3D flb->ops->retrieve(&args); if (err) { + private->incoming.retrieve_status =3D err; module_put(flb->ops->owner); return err; } =20 private->incoming.obj =3D args.obj; - private->incoming.retrieved =3D true; + private->incoming.retrieve_status =3D 1; =20 return 0; } @@ -215,7 +219,7 @@ void liveupdate_flb_put_incoming(struct liveupdate_flb = *flb) if (!refcount_dec_and_test(&private->incoming.count)) return; =20 - if (!private->incoming.retrieved) { + if (private->incoming.retrieve_status <=3D 0) { int err =3D luo_flb_retrieve_one(flb); =20 if (WARN_ON(err)) --=20 2.54.0.823.g6e5bcc1fc9-goog