From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 236C31DA60D for ; Fri, 20 Mar 2026 00:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773966068; cv=none; b=Y45xIX/EdXbc6of3r+ehJbBaD+yRIWeYemQZUpXGt8cnDt0R8GvW9SYiiLASS7PGn/n1NI7sJAF9kj8Fj7rC2NRrxmTw8ENF6iTxf9+zBE/kFuz6NiW3xNyHmM98lHoO2hntQfm+pOd6nhGbbZ8kq6/KM60B2z7nVwdyCoXgelE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773966068; c=relaxed/simple; bh=foEuyi+repZLtvUk5LbAesgI0DAocVY7AgUICWB/Gmc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WyBH9R+rR8nk/eo+Tvt4gQONGu08KypJABDl61ZZdz6Ei5+4+hmnxzwzEf4do1ZcNiQ/A8KOew5qbVHuZgopzj0/OpGuHKGBqHcDxGdzowNUD4voEx09KCWxsjl7IJ1RfVUPuvHeo46/svpBRLcq2iYcZhWtE6rhRmaC66b7Hvo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gUCSOzA8; arc=none smtp.client-ip=209.85.214.179 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gUCSOzA8" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2b052562254so43145ad.0 for ; Thu, 19 Mar 2026 17:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773966066; x=1774570866; 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=bSWC2c+6ov5jVqWIkd0yhypYy89vs1IKdCrAW1Ebqvc=; b=gUCSOzA8EVi7zykEoo/XZG82iDbE8km/xWZgEmSpffJjcxv7YIk8w1mfPr+LjJVb6D b/+MUnHRxgTfLgxdMoBTMbtIONj3kVIAooo3mcQlNMF2r/VYRPidzQlIM6HiElISgUSA DiPiFBg0sENR2VCaY3hwL1Da9WlctfqW8j875Q43C+59gWtJmlqWvfPpEH0Pb9daxQ6M X8YwcOy36ol4sOKu89Mjfm+dq5HWqZWGr4uhgv9XVVTnFNRiM0ahLBcoMvtmRkGwmv15 EOttkrpRGHtnPqz1jG1vV7vOZ/G28csAYbJ/k7JnOYy+EhWJdwCkHshYP6Osaz+pDmfK /Rkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773966066; x=1774570866; 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=bSWC2c+6ov5jVqWIkd0yhypYy89vs1IKdCrAW1Ebqvc=; b=Bk/oP/pUkOUYlM9g3lnCjI+1XM3majyI/opGV0eBDKQuWXiBlbaNrhJqMlGRQtjMqx Ahjaf5YStat+W6Dd0Bte+U5W9aeRXAzOQzZRktuOqENj5zI+9pnMt6zt+d+Y7nIvtSKc pqPm5tm8IZR0dDHnA4fByu/sCtj5gwe1ZHFnT2Sws2o+RtVdTwI706dNTv4feB0ycyUv TaRVE9gapbyw4HcBMwBqEqgBuUa0dB7LS7xXdGdGgwJFbqcJqWoIBk0apzFBZvtGcfeM zt8qLHilTsJqff2j5EZtSA8HagNN6oas+xGsEYZK+re9MXN3O+Y0d2NBz2OT+/uDc0mq sotg== X-Forwarded-Encrypted: i=1; AJvYcCUWTw4RYG8Ay8faK/6MmtZn3tkVh2/WxbrAOBE0dNYq5NO8k6HwmdW7i3+z8/QoVaC724BDOBdarizppAw=@vger.kernel.org X-Gm-Message-State: AOJu0YxliBaaiIvoOdkH7UyG3kpkfJmIv59D+LOIIUvG5Q5gZi/pR/m1 bCvbQ8aGvB3rzoTYwwJZDmk3hl6kCtywJ2Vu6hCcK0c1FHMjRotL5klWcHlyRLwiR7F5ArLVJ+p QyHh+pkW+ X-Gm-Gg: ATEYQzydqiozsuVx/nz34azP5Jb+8YoAA/R7XQV+uNI0shG18U8tZWDdUbH0b9A8JER A2+2OVvBc0GJZWy7gKMFS1M0M3HFqOgGt3YWJt3UJSTdSrmJqgW47yN4lAX9T9o2+yM0hFSnCVV mqWG4/AUligZfzHHL5CRrsnorRRH7aHM3OfjZY00ZUhRgjwFc2ORGlXbs7kwe0ykFYCBNnQ2y7h vxeG/pthKBMRk7lih9rMdP+cubrDuf9qQHkVhuzT5y1sIRNcI5Hxfu+Btjb3iAYwmoet4svYVj0 at16d6Lq3BmmVw9JbfXYuNNesgPrY8zYPTvGUeFSNo2bATd7FTF/L9gIfhoo3Lil8IAC7dW2w5n 9IVmqcJejd0gpoqYW1KcFOCZwzmHTivyRm8P+AwnJTDrBZ8q0FxpBUgrDFfX/ZIP5gIeD3fQ6w2 zLm7wSoImkK6aFhz9SHq7uHHDFdw1gcgkaEdEb6nRt0fOTlLZRCBO6nz1LZof65A== X-Received: by 2002:a17:902:cccc:b0:2b0:4d40:ce18 with SMTP id d9443c01a7336-2b0828a92e1mr1264855ad.14.1773966065751; Thu, 19 Mar 2026 17:21:05 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b040da3easm319482b3a.41.2026.03.19.17.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 17:21:05 -0700 (PDT) Date: Fri, 20 Mar 2026 00:21:01 +0000 From: Samiullah Khawaja To: Pasha Tatashin Cc: rppt@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dmatlack@google.com, pratyush@kernel.org Subject: Re: [PATCH v2 2/8] liveupdate: Protect FLB lists with rwsem Message-ID: References: <20260318141637.1870220-10-pasha.tatashin@soleen.com> <20260318141637.1870220-12-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; format=flowed Content-Disposition: inline In-Reply-To: <20260318141637.1870220-12-pasha.tatashin@soleen.com> On Wed, Mar 18, 2026 at 10:16:40AM -0400, Pasha Tatashin wrote: >Because liveupdate FLB objects will soon drop their persistent module >references when registered, list traversals must be protected against >concurrent module unloading. > >Introduce two read-write semaphores to provide this protection: >1. A global luo_flb_lock protects the global registry of FLBs. >2. A per-handler flb_lock protects the handler's specific list of FLB > dependencies. > >Read locks are used during concurrent list traversals (e.g., during >preservation and serialization). Write locks are taken during registration >and unregistration. When both locks are required, the global luo_flb_lock >is strictly acquired before the per-handler flb_lock to prevent deadlocks. > >Signed-off-by: Pasha Tatashin >--- > include/linux/liveupdate.h | 3 +++ > kernel/liveupdate/luo_file.c | 1 + > kernel/liveupdate/luo_flb.c | 16 ++++++++++++++++ > 3 files changed, 20 insertions(+) > >diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h >index dd11fdc76a5f..8394fb2d8774 100644 >--- a/include/linux/liveupdate.h >+++ b/include/linux/liveupdate.h >@@ -12,6 +12,7 @@ > #include > #include > #include >+#include > #include > #include > >@@ -107,6 +108,8 @@ struct liveupdate_file_handler { > struct list_head __private list; > /* A list of FLB dependencies. */ > struct list_head __private flb_list; >+ /* Protects flb_list */ >+ struct rw_semaphore __private flb_lock; > }; > > /** >diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c >index 6a0ae29c6a24..96fdd5790dcc 100644 >--- a/kernel/liveupdate/luo_file.c >+++ b/kernel/liveupdate/luo_file.c >@@ -873,6 +873,7 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) > } > > INIT_LIST_HEAD(&ACCESS_PRIVATE(fh, flb_list)); >+ init_rwsem(&ACCESS_PRIVATE(fh, flb_lock)); > INIT_LIST_HEAD(&ACCESS_PRIVATE(fh, list)); > list_add_tail(&ACCESS_PRIVATE(fh, list), &luo_file_handler_list); > } >diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c >index f52e8114837e..91910d806d1d 100644 >--- a/kernel/liveupdate/luo_flb.c >+++ b/kernel/liveupdate/luo_flb.c >@@ -49,6 +49,7 @@ > #include > #include > #include >+#include > #include > #include > #include "luo_internal.h" >@@ -70,6 +71,7 @@ struct luo_flb_global { > long count; > }; > >+static DECLARE_RWSEM(luo_flb_lock); > static struct luo_flb_global luo_flb_global = { > .list = LIST_HEAD_INIT(luo_flb_global.list), > }; >@@ -240,6 +242,8 @@ int luo_flb_file_preserve(struct liveupdate_file_handler *fh) > struct luo_flb_link *iter; > int err = 0; > >+ guard(rwsem_read)(&ACCESS_PRIVATE(fh, flb_lock)); >+ > list_for_each_entry(iter, flb_list, list) { > err = luo_flb_file_preserve_one(iter->flb); > if (err) >@@ -272,6 +276,8 @@ void luo_flb_file_unpreserve(struct liveupdate_file_handler *fh) > struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); > struct luo_flb_link *iter; > >+ guard(rwsem_read)(&ACCESS_PRIVATE(fh, flb_lock)); >+ > list_for_each_entry_reverse(iter, flb_list, list) > luo_flb_file_unpreserve_one(iter->flb); > } >@@ -292,6 +298,8 @@ void luo_flb_file_finish(struct liveupdate_file_handler *fh) > struct list_head *flb_list = &ACCESS_PRIVATE(fh, flb_list); > struct luo_flb_link *iter; > >+ guard(rwsem_read)(&ACCESS_PRIVATE(fh, flb_lock)); >+ > list_for_each_entry_reverse(iter, flb_list, list) > luo_flb_file_finish_one(iter->flb); > } >@@ -355,6 +363,9 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, > if (!luo_session_quiesce()) > return -EBUSY; > >+ guard(rwsem_write)(&luo_flb_lock); >+ guard(rwsem_write)(&ACCESS_PRIVATE(fh, flb_lock)); Since FLBs are linked with file handlers and the file_handler can be unregistered/registered while this is running, should the luo_file_lock write be taken here? I think maybe we don't need a separate luo_flb_lock and the luo_file_lock should provide enough protection if we acquire it here, as a file_handler is supposed to be registered first and then flb needs to be registered against it? Maybe we can have one luo_register_lock? >+ > /* Check that this FLB is not already linked to this file handler */ > err = -EEXIST; > list_for_each_entry(iter, flb_list, list) { >@@ -444,6 +455,9 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, > if (!luo_session_quiesce()) > return -EBUSY; > >+ guard(rwsem_write)(&luo_flb_lock); >+ guard(rwsem_write)(&ACCESS_PRIVATE(fh, flb_lock)); >+ > /* Find and remove the link from the file handler's list */ > list_for_each_entry(iter, flb_list, list) { > if (iter->flb == flb) { >@@ -638,6 +652,8 @@ void luo_flb_serialize(void) > struct liveupdate_flb *gflb; > int i = 0; > >+ guard(rwsem_read)(&luo_flb_lock); >+ > list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) { > struct luo_flb_private *private = luo_flb_get_private(gflb); > >-- >2.53.0.851.ga537e3e6e9-goog > >