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 3A5DD2EAB72 for ; Sun, 22 Mar 2026 13:13:45 +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=1774185225; cv=none; b=VoXuTy/qsFx56lLhGX6UYHfzJ01qq0WnYpxDSYcu+uIEULGP5Ekr6PG7a1auHHGDL9axs9O0LzEEmXjk9zRO2JTs7IH39XD9ooW/HF5l4TzPaCJiAEbsCxDcP4dsWT/zVni5Y7USLTLmJs7E6ALI58QKb30dXnyP4lQ5oV/7aCk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774185225; c=relaxed/simple; bh=5taCrRbCiZRabK14Jhz8fQtqNTWry3OlVCQeaw+8hs4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q6JkH1o4gv9vjYWXetA3TQHUJBSYkoJSFQDHczJRP1Q/z/93LpEkYwSIQfQoaCo4YspK2fttMhk7Tjn+SLpWICIcGQMhvchheWncrWYHtOXsSj3Gk/thNEiAk9MQLcZgqDlMn4mKYEWsVTN+KrIv115reE1tq1QpnYTuGR3QmaU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RCoipx0U; 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="RCoipx0U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78903C19424; Sun, 22 Mar 2026 13:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774185224; bh=5taCrRbCiZRabK14Jhz8fQtqNTWry3OlVCQeaw+8hs4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RCoipx0UMevyhY4HjT8WikkfX13R/rbDAklImxeVQt9zLguwFXcjdg+lp87L4nh3+ W8Abb74RvPmAd5rU1xO+1PByqlxxI3LMl0L+AmaDfzRxQF37zZuIardfHqWRPY60HX hfpFupf6MZ5TELHsjPGT8ah1LgOeSylEVcrqgMOohADc7Zso8Y6sjjrK9u/59NwTVh IEv4pP6Q4t+ub3663Ohu0CcwGnQzjWR+IN3zHULUj8LupvT31xw55JuLs4XMY3bFiT gC61TzuGoEH5bdJXPty98AbX1KbkOlIu6Vckf68nE8FgdmPwcAzpnknY9PQ2vgOBLf Vf4G74ucogEEQ== Date: Sun, 22 Mar 2026 15:13:38 +0200 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 Subject: Re: [PATCH v2 1/8] liveupdate: Protect file handler list with rwsem Message-ID: References: <20260318141637.1870220-10-pasha.tatashin@soleen.com> <20260318141637.1870220-11-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: <20260318141637.1870220-11-pasha.tatashin@soleen.com> Hi Pasha, On Wed, Mar 18, 2026 at 10:16:39AM -0400, Pasha Tatashin wrote: > Because liveupdate file handlers will no longer hold a > module reference when registered, we must ensure that the access to > the handler list is protected against concurrent module unloading. > > Signed-off-by: Pasha Tatashin > --- > kernel/liveupdate/luo_file.c | 61 +++++++++++++++++++++--------------- > 1 file changed, 35 insertions(+), 26 deletions(-) > > diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c > index 5acee4174bf0..6a0ae29c6a24 100644 > --- a/kernel/liveupdate/luo_file.c > +++ b/kernel/liveupdate/luo_file.c > @@ -112,6 +112,7 @@ > #include > #include "luo_internal.h" > > +static DECLARE_RWSEM(luo_file_handler_lock); > static LIST_HEAD(luo_file_handler_list); > > /* 2 4K pages, give space for 128 files per file_set */ > @@ -277,10 +278,12 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd) > goto err_fput; > > err = -ENOENT; > - list_private_for_each_entry(fh, &luo_file_handler_list, list) { > - if (fh->ops->can_preserve(fh, file)) { > - err = 0; > - break; > + scoped_guard(rwsem_read, &luo_file_handler_lock) { I'm not sure scoped_guard() here is better that lock before the loop and unlock after. scoped_guard() would be useful if we were returning from the guarded scope. > + list_private_for_each_entry(fh, &luo_file_handler_list, list) { > + if (fh->ops->can_preserve(fh, file)) { > + err = 0; > + break; > + } > } > } > > @@ -777,10 +780,12 @@ int luo_file_deserialize(struct luo_file_set *file_set, > bool handler_found = false; > struct luo_file *luo_file; > > - list_private_for_each_entry(fh, &luo_file_handler_list, list) { > - if (!strcmp(fh->compatible, file_ser[i].compatible)) { > - handler_found = true; > - break; > + scoped_guard(rwsem_read, &luo_file_handler_lock) { > + list_private_for_each_entry(fh, &luo_file_handler_list, list) { > + if (!strcmp(fh->compatible, file_ser[i].compatible)) { > + handler_found = true; > + break; > + } Ditto. > } > } > > @@ -850,25 +855,27 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) > if (!luo_session_quiesce()) > return -EBUSY; > > - /* Check for duplicate compatible strings */ > - list_private_for_each_entry(fh_iter, &luo_file_handler_list, list) { > - if (!strcmp(fh_iter->compatible, fh->compatible)) { > - pr_err("File handler registration failed: Compatible string '%s' already registered.\n", > - fh->compatible); > - err = -EEXIST; > + scoped_guard(rwsem_write, &luo_file_handler_lock) { > + /* Check for duplicate compatible strings */ > + list_private_for_each_entry(fh_iter, &luo_file_handler_list, list) { > + if (!strcmp(fh_iter->compatible, fh->compatible)) { > + pr_err("File handler registration failed: Compatible string '%s' already registered.\n", > + fh->compatible); > + err = -EEXIST; > + goto err_resume; PeterZ advised against mixing guards() with goto, but unfortunately I can't find lore link right now. > + } > + } > + -- Sincerely yours, Mike.