From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 A2AC2387371 for ; Thu, 23 Apr 2026 18:11:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776967879; cv=none; b=kjNFgZJ/PNS9iZjCjM6bf+h8J2ei+sKLud871Bh6aINiDzuuelFceqZ3fnlrmxPQ3+xSph32FwDachEZAUc7Gu6dvpak4DjTd6Yj9/T208kh1ZjPQ0UG+JF5aOrCvEOMMwyMbxVPBPcdVdMXfsm4GlxqIHcamji3/Ks9D8HiRWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776967879; c=relaxed/simple; bh=eibtJCrmQ5ZRubRoblpOwU2VaT2sWBfN31FxNyAEMw8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UbnIcTvosjHEbLqlKdOEG83z5OnycDU6VGlVIW7kzYJkwnkVzynua/TD86GwN9vjbplWTyL1gQgzqMjTyu9ybXk1/lxffwxbs03WLaXBEOVpj/B9cKHH5uL0ISLfMD+bWzN6Iq6rAqg16bPS+m5hFO18ytZi4D79fBx7sd0Ej8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=gXpixaIO; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="gXpixaIO" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-8d6d5e45c43so796006085a.3 for ; Thu, 23 Apr 2026 11:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1776967876; x=1777572676; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wXanv71aYlZAhfS9WbBd7RIN8H4hpKpjMc82q1X9rqA=; b=gXpixaIOwVETomciUxZ6K2UuzCfMKiJLD+tlzK3qGyeFrYeKTwUCU7J5lD3sq5mlDZ t2qzGpNh0YOkC86wXxKqnaxGQ4zxL5gVJ/TQ5rdOdoiZ51+e6TSOUjii8ATGVr+YuIpp r2U3BswzyWQH1R31IKzkeU3ftW1IzxyBuCbFll+zbjYw1DiHy3Prmj9uNir/G+8iLOFb +L/t7u1P2VlsWQ4sU2OECLd09pJj3KhIITHzy6FZL1IWA+/YsQ1QWUPGafUmM7bjLcg5 dnB66JUUYd1l0hjw6kivmYsaE5ln9JsyofpheyYni5tWsSLjJkjVhNO30wJu+HeNtheJ 7Diw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776967876; x=1777572676; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXanv71aYlZAhfS9WbBd7RIN8H4hpKpjMc82q1X9rqA=; b=rw0yg4MaOAV0B7Z70hav8eAQnXC781y3S+yHOnI4E9Kl9PSVATv4GRzZ/z5SE5dl82 7kwgyEOp5oXcLOGYxSf7tJBTYMm6lLWqljZNE4muZVkJdBr3SM6b2zkNmX3xxm2McOBM N/vmB44uGXFM7XcZaHP+/ov+qz7szvNIgwrJOxb7vRjXe6wF+XHJShXHZS2jIWHFeFeS zvjMevIeAs9dnug1wEZ1ZV2/QtzHRfq3g6C8Yq9pQgnFPuosx8Otp3u5/tSauvpaufLH GN4ju0b9smCYPuU8RiiTvBYrJ4vACOI0d6Bg5hVipLWUB4UWSTrDt+f1W/ryAN0d9e09 5g6g== X-Gm-Message-State: AOJu0YyrhE7+Yh1fjSP+uuBM4KKmZbSjjiLBSFqVhrjgCx0NA80QKI0u 53B8I6irmAChf95TCiy50PSmduqVUhjuLJRFoqHSUewIdCI7J2gqqYd1vk3fknLLgbYHLR4IHgR /6va5MQ8= X-Gm-Gg: AeBDieslmvMZh56Q9SUtJ9Oc0QG3DD2zifRhXN0RuYe7BeQmcXtk5NGQLVRixnMa17N HVue2GEFQR7p1wmj84n98oMoFF1D2zQbc87m5R7vep8iZe/BpiodBimHDFq0Hs24MGe7DGct4Wk /8MD9gImpvr0zedehV5yv5xAiz4mfEMErq34lR5YqjVpv6mBKTLcmGql2qqVUJmfPSML9hW7ZX4 F5xggrJWeUhOdoUTR7hhXGbwGSekeOQE+DfMjbMStx1oLjChzF0NYWflXRv/Nb5BO21Ozvnd5sV 3IExdlXNKpRjvFqdM8R5mIAzTccNCLQ2Ao67jsNFxa3QtlR9xcbwmGbTXfX7YEYBbv8FM/GAHrC 7SkmWgdP2pkzdLhYwVYBe/6ncn5C+LKxX99mrKm3t86c/GBgj7Rp2OYUKCnCsmay5aeN0OQWkFI tR5HgOyhDHwQweNciByzTAD15HUGiJFpgkD2IkhbBMBWjgimXfPtopoBCDhLzkUQ== X-Received: by 2002:a05:620a:2903:b0:8d0:891:34d0 with SMTP id af79cd13be357-8e792f4ac59mr3823929785a.60.1776967876393; Thu, 23 Apr 2026 11:11:16 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8e7d69ad48asm1594062885a.19.2026.04.23.11.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 11:11:15 -0700 (PDT) Date: Thu, 23 Apr 2026 18:11:15 +0000 From: Pasha Tatashin To: David Matlack Cc: linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja Subject: Re: [PATCH 1/2] liveupdate: Use refcount_t for FLB reference counts Message-ID: References: <20260423174032.3140399-1-dmatlack@google.com> <20260423174032.3140399-2-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260423174032.3140399-2-dmatlack@google.com> On 04-23 17:40, David Matlack wrote: > Use refcount_t instead of a raw integer to keep track of references on > incoming and outgoing FLBs. Using refcount_t provides protection from > overflow, underflow, and other issues. > > Fixes: cab056f2aae7 ("liveupdate: luo_flb: introduce File-Lifecycle-Bound global state") > Signed-off-by: David Matlack > --- > include/linux/liveupdate.h | 3 ++- > kernel/liveupdate/luo_flb.c | 22 ++++++++++------------ > 2 files changed, 12 insertions(+), 13 deletions(-) > > diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h > index 30c5a39ff9e9..8d3bbc35c828 100644 > --- a/include/linux/liveupdate.h > +++ b/include/linux/liveupdate.h > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -175,7 +176,7 @@ struct liveupdate_flb_ops { > * @retrieved: True once the FLB's retrieve() callback has run. > */ > struct luo_flb_private_state { > - long count; > + refcount_t count; > u64 data; > void *obj; > struct mutex lock; > diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c > index 00f5494812c4..59c5f31ab767 100644 > --- a/kernel/liveupdate/luo_flb.c > +++ b/kernel/liveupdate/luo_flb.c > @@ -111,7 +111,7 @@ static int luo_flb_file_preserve_one(struct liveupdate_flb *flb) > struct luo_flb_private *private = luo_flb_get_private(flb); > > scoped_guard(mutex, &private->outgoing.lock) { > - if (!private->outgoing.count) { > + if (!refcount_read(&private->outgoing.count)) { > struct liveupdate_flb_op_args args = {0}; > int err; > > @@ -126,8 +126,10 @@ static int luo_flb_file_preserve_one(struct liveupdate_flb *flb) > } > private->outgoing.data = args.data; > private->outgoing.obj = args.obj; > + refcount_set(&private->outgoing.count, 1); > + } else { > + refcount_inc(&private->outgoing.count); > } > - private->outgoing.count++; It should be: refcount_inc(&private->outgoing.count); for both cases, as it was before. Additionally, please add refcount_set(&private->outgoing.count, 0) to luo_flb_get_private, where the rest of the private fields are initialized. In general, I prefer to avoid refcount_set() because it breaks continuity and makes debugging hard. It should only be used only during initialization, so moving it to where the other fields are initialized is the correct approach. > } > > return 0; > @@ -138,8 +140,7 @@ static void luo_flb_file_unpreserve_one(struct liveupdate_flb *flb) > struct luo_flb_private *private = luo_flb_get_private(flb); > > scoped_guard(mutex, &private->outgoing.lock) { > - private->outgoing.count--; > - if (!private->outgoing.count) { > + if (refcount_dec_and_test(&private->outgoing.count)) { > struct liveupdate_flb_op_args args = {0}; > > args.flb = flb; > @@ -178,7 +179,7 @@ static int luo_flb_retrieve_one(struct liveupdate_flb *flb) > for (int i = 0; i < fh->header_ser->count; i++) { > if (!strcmp(fh->ser[i].name, flb->compatible)) { > private->incoming.data = fh->ser[i].data; > - private->incoming.count = fh->ser[i].count; > + refcount_set(&private->incoming.count, fh->ser[i].count); > found = true; > break; > } > @@ -208,12 +209,8 @@ 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); > - u64 count; > > - scoped_guard(mutex, &private->incoming.lock) > - count = --private->incoming.count; > - > - if (!count) { > + if (refcount_dec_and_test(&private->incoming.count)) { > struct liveupdate_flb_op_args args = {0}; > > if (!private->incoming.retrieved) { > @@ -652,12 +649,13 @@ void luo_flb_serialize(void) > guard(rwsem_read)(&luo_register_rwlock); > list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) { > struct luo_flb_private *private = luo_flb_get_private(gflb); > + long count = refcount_read(&private->outgoing.count); > > - if (private->outgoing.count > 0) { > + if (count > 0) { > strscpy(fh->ser[i].name, gflb->compatible, > sizeof(fh->ser[i].name)); > fh->ser[i].data = private->outgoing.data; > - fh->ser[i].count = private->outgoing.count; > + fh->ser[i].count = count; > i++; > } > } > -- > 2.54.0.rc2.544.gc7ae2d5bb8-goog >