From nobody Thu Apr 2 18:49:12 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 40FC3371CF7 for ; Fri, 27 Mar 2026 03:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774582426; cv=none; b=ryiGUCUI3ZclaDfKBgF2qVSfsMP8sTVMReUy67jFxe8RfudD2tr2QVfT5kYoZabtqerZn6mlsp0egunkvVxol55eOdyser3dCG1JmAZ6nkn3USHV/7s3RlO5dmMTDYlO47OcurXpWVOpJ0Bk2PV+YphGZkAMGb6YtdAsPAPM/r0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774582426; c=relaxed/simple; bh=9il8OaDcAvon2AOA+eJCw8pVlaLGkkhR/Q6e2Bz/FSI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QgvoZ4rY9sPM7434HJWwUkDkITgUybpS3/lllxchMtqawhrbB+Tmp/iuhhGMgErOoifuXZuzmRb5qgyDh67QxKEidMoKICLOJIS7xd1C+iJ4BZ1vLfazpegK4F3R+xKdUrMe3pf3hr8HttP/insuNeDEYkc26HBtovAlsV1/o6c= 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=FeeUJAU+; arc=none smtp.client-ip=209.85.219.54 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="FeeUJAU+" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-89cab686a9bso12275996d6.2 for ; Thu, 26 Mar 2026 20:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774582424; x=1775187224; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3hDiA51qt4kdhGsAF/wtP6SU35I33186MYzANJAE0/8=; b=FeeUJAU+p5eW5VfD1e4pw5MuCIwDfpquL5jbOxUUEe1aGzRLogOHLxdqkvF0Fh+Tqc yYr7VO6w0AL35Vjw/eu7lmp6uWz1cD/akDr6ehdCAFE07TCZeuehQ0LhB9iTNXcMe5LV PVEO1R7BeHKOWjELltVt4mmRFWKSV51Hoz6gtaU7TxmlY+RglsFSPYTo5CERsjJ2eXdh MbUV4yO91ILocIDGgs8uQ6U4npcnkw+Ats4jIuJaL4uzuGeADsZ8+ZXLwycOXX+gtfzW Fjo8C8VCbpZY7+vy609MWquzAnHvpJcSB2eKH6qdR1/ciOQQQicAMvxQNgVpleOOUgqu UH2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774582424; x=1775187224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=3hDiA51qt4kdhGsAF/wtP6SU35I33186MYzANJAE0/8=; b=T1QuOVxORxHcqSWX2SI3PeMq7JKrS+V3YD2eS3c9dGEmsrIdz6Mqh6wSXvE8/p06/L 4AZf7BEqTChnlRMZ5b6Bqop+HLkftCKXSRgyKFdUg03ESe5leutcyJljX+wEGbRb1J0g B+KRjc1JblWndpLSYUujpAF8oQTgMXsUX0dB5rLCcVU/Sex14sbQmgeqLO45HCdLwHc2 R2U8P4Z0tLDwaH6XFJjunE5DEljRzRcgKA6nDs7RLpRv8eX1P7Y/o3g37VR0qvuA47IV zhXliYslT7W/brifeI7+Y6Y0tx9Oti3yXFoHLjT1/6PhgkOHaT4S8NP1IAP20kiHHZ2P ti9g== X-Forwarded-Encrypted: i=1; AJvYcCVB6Np+VqX+p9ucKLRbdxPlUZRRTgHv86hNFzgbP78aw+gRmx7bhpfb6FxqdvW+SuHHF4MDqLFgqVJVg10=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3S2o74cEVnuKO66lQhVgre8143fffgzf4RhRrbthCc52zoCre eX3FmbX4c+94bwwVl90F54Rat3YL+URWWzLPJQlP1EF3p1T18P7pnOZlSkg7TmgsoKU= X-Gm-Gg: ATEYQzwdO9DaU+zIyxcYgBLmt7sNQFn54ybVwU1M9ZDKI3/v+5Or/rqhffLoS6Ekb4E Zf7Ee2BAQCH4CXOn4y1/72mG5V/hrPL3VeiNoNj2PafKOGF/1Js3+fWe1SIr9DvDfDDKM6yzFwF 2OaKfVTvnXfA13RwBH3xaDo/93Nnx2PXwpVUN1IvHPKHjNq/lyuf/HkrIkfL8UP9bB5k+j33+cG p+PjqHVvwkeaMTldqW5rM/P8YRfvrQkS6txO4hpFF4jTdSubDQ5pA8a4uQTaiw31ll6EXjRUk3A uZwix6VMFeuxM1xIroRJM6c/WXKaVwXChBldYVYE8QQbaB3GhFKTfsQ7r4JhQssDbVv2gxwmlyX au5tjxS6v3cgG4tNSLFDSszgPXvSGjdsolXR5vaNC5reRl27a9GcRsUe9jQ+Qs9fIy228AM+OtE slhqA96zP3g2pGTXW6JbTEEDollKzatQGYzzahMP7udWmXVBxfgtY6aaRI3B2RTp5PIw== X-Received: by 2002:a05:6214:d4e:b0:899:ea9e:31c4 with SMTP id 6a1803df08f44-89ce8f6abe6mr11258026d6.51.1774582424185; Thu, 26 Mar 2026 20:33:44 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89cd5a22711sm46519186d6.27.2026.03.26.20.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 20:33:43 -0700 (PDT) From: Pasha Tatashin To: rppt@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v3 07/10] liveupdate: Auto unregister FLBs on file handler unregistration Date: Fri, 27 Mar 2026 03:33:31 +0000 Message-ID: <20260327033335.696621-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327033335.696621-1-pasha.tatashin@soleen.com> References: <20260327033335.696621-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To ensure that unregistration is always successful and doesn't leave dangling resources, introduce auto-unregistration of FLBs: when a file handler is unregistered, all FLBs associated with it are automatically unregistered. Introduce a new helper luo_flb_unregister_all() which unregisters all FLBs linked to the given file handler. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_file.c | 14 +----- kernel/liveupdate/luo_flb.c | 84 ++++++++++++++++++++++---------- kernel/liveupdate/luo_internal.h | 1 + 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 439177c10723..80f4e3b796a6 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -895,26 +895,16 @@ int liveupdate_register_file_handler(struct liveupdat= e_file_handler *fh) */ int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) { - int err =3D -EBUSY; - if (!liveupdate_enabled()) return -EOPNOTSUPP; =20 liveupdate_test_unregister(fh); =20 - down_write(&luo_register_rwlock); - if (!list_empty(&ACCESS_PRIVATE(fh, flb_list))) - goto err_unlock; - + guard(rwsem_write)(&luo_register_rwlock); + luo_flb_unregister_all(fh); list_del(&ACCESS_PRIVATE(fh, list)); - up_write(&luo_register_rwlock); =20 module_put(fh->ops->owner); =20 return 0; - -err_unlock: - up_write(&luo_register_rwlock); - liveupdate_test_register(fh); - return err; } diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c index ac6fa5b34b43..f8348138de70 100644 --- a/kernel/liveupdate/luo_flb.c +++ b/kernel/liveupdate/luo_flb.c @@ -335,6 +335,62 @@ void luo_flb_file_finish(struct liveupdate_file_handle= r *fh) luo_flb_file_finish_one(iter->flb); } =20 +static void luo_flb_unregister_one(struct liveupdate_file_handler *fh, + struct liveupdate_flb *flb) +{ + struct luo_flb_private *private =3D luo_flb_get_private(flb); + struct list_head *flb_list =3D &ACCESS_PRIVATE(fh, flb_list); + struct luo_flb_link *iter; + bool found =3D false; + + /* Find and remove the link from the file handler's list */ + list_for_each_entry(iter, flb_list, list) { + if (iter->flb =3D=3D flb) { + list_del(&iter->list); + kfree(iter); + found =3D true; + break; + } + } + + if (!found) { + pr_warn("Failed to unregister FLB '%s': not found in file handler '%s'\n= ", + flb->compatible, fh->compatible); + return; + } + + private->users--; + + /* + * If this is the last file-handler with which we are registred, remove + * from the global list. + */ + if (!private->users) { + list_del_init(&private->list); + luo_flb_global.count--; + } +} + +/** + * luo_flb_unregister_all - Unregister all FLBs associated with a file han= dler. + * @fh: The file handler whose FLBs should be unregistered. + * + * This function iterates through the list of FLBs associated with the giv= en + * file handler and unregisters them all one by one. + */ +void luo_flb_unregister_all(struct liveupdate_file_handler *fh) +{ + struct list_head *flb_list =3D &ACCESS_PRIVATE(fh, flb_list); + struct luo_flb_link *iter, *tmp; + + if (!liveupdate_enabled()) + return; + + lockdep_assert_held_write(&luo_register_rwlock); + list_for_each_entry_safe(iter, tmp, flb_list, list) + luo_flb_unregister_one(fh, iter->flb); +} + /** * liveupdate_register_flb - Associate an FLB with a file handler and regi= ster it globally. * @fh: The file handler that will now depend on the FLB. @@ -443,38 +499,12 @@ int liveupdate_register_flb(struct liveupdate_file_ha= ndler *fh, int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, struct liveupdate_flb *flb) { - struct luo_flb_private *private =3D luo_flb_get_private(flb); - struct list_head *flb_list =3D &ACCESS_PRIVATE(fh, flb_list); - struct luo_flb_link *iter; - int err =3D -ENOENT; - if (!liveupdate_enabled()) return -EOPNOTSUPP; =20 guard(rwsem_write)(&luo_register_rwlock); =20 - /* Find and remove the link from the file handler's list */ - list_for_each_entry(iter, flb_list, list) { - if (iter->flb =3D=3D flb) { - list_del(&iter->list); - kfree(iter); - err =3D 0; - break; - } - } - - if (err) - return err; - - private->users--; - /* - * If this is the last file-handler with which we are registred, remove - * from the global list. - */ - if (!private->users) { - list_del_init(&private->list); - luo_flb_global.count--; - } + luo_flb_unregister_one(fh, flb); =20 return 0; } diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 40a011bdfa55..22f6901f89ed 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -103,6 +103,7 @@ void luo_file_set_destroy(struct luo_file_set *file_set= ); int luo_flb_file_preserve(struct liveupdate_file_handler *fh); void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh); void luo_flb_file_finish(struct liveupdate_file_handler *fh); +void luo_flb_unregister_all(struct liveupdate_file_handler *fh); int __init luo_flb_setup_outgoing(void *fdt); int __init luo_flb_setup_incoming(void *fdt); void luo_flb_serialize(void); --=20 2.43.0