From mboxrd@z Thu Jan 1 00:00:00 1970 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-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 global state") Assisted-by: Gemini:gemini-3-pro-preview Signed-off-by: David Matlack --- 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); int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, void **objp); +void liveupdate_flb_put_outgoing(struct liveupdate_flb *flb); #else /* CONFIG_LIVEUPDATE */ @@ -292,5 +293,9 @@ static inline int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, return -EOPNOTSUPP; } +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; } -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 = luo_flb_get_private(flb); @@ -266,7 +266,7 @@ int luo_flb_file_preserve(struct liveupdate_file_handler *fh) 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); return err; @@ -291,7 +291,7 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh) 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); } /** @@ -546,6 +546,10 @@ int liveupdate_flb_get_outgoing(struct liveupdate_flb *flb, void **objp) return -EOPNOTSUPP; guard(mutex)(&private->outgoing.lock); + if (!private->outgoing.obj) + return -ENOENT; + + refcount_inc(&private->outgoing.count); *objp = private->outgoing.obj; return 0; -- 2.54.0.823.g6e5bcc1fc9-goog