From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F0393DA7FF for ; Wed, 15 Apr 2026 15:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776267114; cv=none; b=YE4zfGTeqRnlnS1JYws4HTzbE1VMHYnkNs4N9i3zo62t+KkO6Tc3tpxOoB7TR56OGuLsPLfjoG+llSM5wgGqppo5iH7QNQaK2m6UmacWck+GUwY0qOhKn4MMvBduiWqY3uTHlxx9/+AFjs2TU16q5QNy5NHUEYYfzl5da81aGfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776267114; c=relaxed/simple; bh=1tDsvv1sxI2uTzxIZN8RvOiouBDKtDIgWijD4C3lV5U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h36tSB3CpP8USS+kfqZhFmvTY20XZlrtxH3cloowoJQFsF9mU2fdo0VeXnz3E0gGK6kl5cXhZ7GNIwlGU9Fvui4R2QpEwDkeTiNhooT51Z+g8URu+GGmbduMKw8iQWVgPr9wUeJQWa2TMkkNpdwtocgnndUnQHNcxAtQ8ELyFe8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=huV9nTg8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="huV9nTg8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DC74C19424; Wed, 15 Apr 2026 15:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776267114; bh=1tDsvv1sxI2uTzxIZN8RvOiouBDKtDIgWijD4C3lV5U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=huV9nTg8aekK7d5lOkB+9C75grBxCIiAGjuPQki4kGPMcbpWKN6eAOk639zsOyUm/ uQ44R85keGmZjXXnmsTRhfyRRcXfdSYn505dt/iqmwrosDohP8TYOINpWMFx0P8Gf2 O1COgJ/wLLjg4c2GXsbnSc6NAayAawm9tzHvth3yMN49a7NDhKziqa4FY1T93KMvn8 RwRVJb8GNXc8m6w7yMYkd840P98m45dHjWQTTG9aHol0nrtBRt7JFN1ZPd6gnV358W cQoi5CEk6dkYmzWlrsXmPYpLEd2NWq4aNUZDtuuUskmaKnH4qTOAppK5TwKTwX1AZp EwFYn8QrBXvMw== Date: Wed, 15 Apr 2026 18:31:49 +0300 From: Mike Rapoport To: Pasha Tatashin Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: Re: [PATCH v4 07/11] liveupdate: Auto unregister FLBs on file handler unregistration Message-ID: References: <20260413185127.128180-1-pasha.tatashin@soleen.com> <20260413185127.128180-8-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260413185127.128180-8-pasha.tatashin@soleen.com> On Mon, Apr 13, 2026 at 06:51:23PM +0000, Pasha Tatashin wrote: > 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 > Reviewed-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) > --- > kernel/liveupdate/luo_file.c | 14 +----- > kernel/liveupdate/luo_flb.c | 85 ++++++++++++++++++++++---------- > kernel/liveupdate/luo_internal.h | 1 + > 3 files changed, 61 insertions(+), 39 deletions(-) > > diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c > index 63ddcf6dcddb..b37bd79974ce 100644 > --- a/kernel/liveupdate/luo_file.c > +++ b/kernel/liveupdate/luo_file.c > @@ -926,26 +926,16 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) > */ > int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) > { > - int err = -EBUSY; > - > if (!liveupdate_enabled()) > return -EOPNOTSUPP; > > liveupdate_test_unregister(fh); > > - 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); > > module_put(fh->ops->owner); > > 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 13f96d11ecc9..b9f5d452a998 100644 > --- a/kernel/liveupdate/luo_flb.c > +++ b/kernel/liveupdate/luo_flb.c > @@ -318,6 +318,63 @@ void luo_flb_file_finish(struct liveupdate_file_handler *fh) > luo_flb_file_finish_one(iter->flb); > } > > +static void luo_flb_unregister_one(struct liveupdate_file_handler *fh, > + struct liveupdate_flb *flb) > +{ > + struct luo_flb_private *private = luo_flb_get_private(flb); > + struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); > + struct luo_flb_link *iter; > + bool found = false; > + > + /* Find and remove the link from the file handler's list */ > + lockdep_assert_held_write(&luo_register_rwlock); > + list_for_each_entry(iter, flb_list, list) { > + if (iter->flb == flb) { > + list_del(&iter->list); > + kfree(iter); > + found = 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 handler. > + * @fh: The file handler whose FLBs should be unregistered. > + * > + * This function iterates through the list of FLBs associated with the given > + * file handler and unregisters them all one by one. > + */ > +void luo_flb_unregister_all(struct liveupdate_file_handler *fh) > +{ > + struct list_head *flb_list = &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 register it globally. > * @fh: The file handler that will now depend on the FLB. > @@ -426,38 +483,12 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, > int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > struct liveupdate_flb *flb) > { > - struct luo_flb_private *private = luo_flb_get_private(flb); > - struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); > - struct luo_flb_link *iter; > - int err = -ENOENT; > - > if (!liveupdate_enabled()) > return -EOPNOTSUPP; > > guard(rwsem_write)(&luo_register_rwlock); > > - /* Find and remove the link from the file handler's list */ > - list_for_each_entry(iter, flb_list, list) { > - if (iter->flb == flb) { > - list_del(&iter->list); > - kfree(iter); > - err = 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); > > return 0; > } > diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.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); > -- > 2.43.0 > -- Sincerely yours, Mike.