From nobody Mon Apr 6 19:59:50 2026 Received: from mail-yx1-f47.google.com (mail-yx1-f47.google.com [74.125.224.47]) (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 2DC603DB626 for ; Wed, 18 Mar 2026 14:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773843420; cv=none; b=ZkRNK4G7jQZ9o3p8DqiaJXAzN6U0L+Dze8Dp8eoZKIyTX3oCyaJUDVfseAC34+1DxzhkGDb7swUFt7MKfuM7b7uCugwHZhaj0+k8up/dKr+3qetmzRBLi5t3dLggzgLKjncfCjIQ5VXXqmEsAINwN2mWOpC7gL3xcNYdhMoU7wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773843420; c=relaxed/simple; bh=dkjsJaF9zS233/cIv2JZuqCsRBtr9t9nThiFjC9QTdU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PO0UfYaySHs522OFORyl62OyETbEzQD6oy/tLxbSdfRgynvlj1/Gx6wfWKInQni7bg3EyaOdKOVsNjGmxn27GtVMb8NO5tThvppo/6wXeO9TBY/b99lrzxdHdV8HCBJYCk8o+IA+tQGLmV0Oj9JhR/cau6i1qU6cizjvya6rGio= 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=c7f7JMoe; arc=none smtp.client-ip=74.125.224.47 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="c7f7JMoe" Received: by mail-yx1-f47.google.com with SMTP id 956f58d0204a3-64ad9fabd08so7932045d50.2 for ; Wed, 18 Mar 2026 07:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1773843418; x=1774448218; 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=iae6YsWSZF4NEuA9NS1+GhS3bfxbm2onYFzq2DhQW14=; b=c7f7JMoeSF4gMOpDsZkwZvkfC3K1rxgrEoMyNgpu+TMHwO69XFkrfEIhl/dSpA0cJx 344BpZrfTLk9eUXTDQlHO/his+HWqh82sKwvhZvNujt+uGQgYN8pQ5y5fyn3Bu6quyzQ 5FAKTalgPpybAs1ag/7w5g1x0rpfCIQ8bT1X2DVtt584MvwL2B0q4YP6y6fzEUTyPgLL QUnDbLxjGKaHixc3fe5AwzQR1HifOr1xXSg7c/U9Ipw0d9r3SGjxwgmx/LYw+n2Xc/YR +z/qSOMTEw7CLodgvENwAMDwO/BfFae8mjb57sTBEQVRQwA0szBhbOcrgjMCjAKJLIir bbqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773843418; x=1774448218; 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=iae6YsWSZF4NEuA9NS1+GhS3bfxbm2onYFzq2DhQW14=; b=mwoo65L/4Nc7ExhOYPLSy0CLUJ90svQDgBu+cIPbCyLAA8lQzTe8BrER97OojshndC y9Mb11GmSKMtVodMBv5Lvwh0ek+cey+TWh2RjF7w52patRQnkClMa7P/Lquwh39UvOKK eD7lR9sMRtSsJz3rqaE6l9CtEhfesQCaGPBLaHVm3fy5Q4MF/X5eBZetI6QTwqF4Hajt PXaPW0hQa0IKIO1FpRrJV0BIjv85xBxq0RwAktmHh85gFkaI8Sl2GcIr94Me3L3wAdmA Ml4LmcdNNwNE4YnTN+l3FlA5ONqUdCBRX9vncAmzSVI6hp6xTv85Xj7IO/Y6DnrrxZQM VE4Q== X-Forwarded-Encrypted: i=1; AJvYcCXBw+ixLepVv37kuZu7YIA+ooh3CcYzDEv4JVayP3qUWre3zkhtosCUN4VKU0s/MdeEls9ZEIbfh7IDiLU=@vger.kernel.org X-Gm-Message-State: AOJu0YxjavoPd5G4jDuUlU/ZcudFk9a6ZsS21cUGuGdTCdX0Xwy9nCz4 jRyWmnJ0eaYnci/xLPw/W/TcmeEpiGB5LU/JgziTThkOyoOf6IrH/MPzW9qBXrZ3EUj1zXiQ4w/ vZkm6 X-Gm-Gg: ATEYQzzZsS7JQvaN7I5nOtrUkcIP+V5FQjCRSw68CBR8yIL0X5jJEahaDNs08XbLe4v O63Rr+N/8kDkw8KCb+/MgdVvGEyQ+eI4xJnGRRMowUelGyth/CcsJjHn1AmevzGzI3P45hM/IV+ LRQroIQPPkMNMiwbtA+DJTZq55j6qJa/DkMWm92BzdN2eq+3rDaaMecdtHOMaUXb7KuRrrQPskh /TVs++aSeq9cjFATpwrKoMX6fZ3Wlo5/wyTyJMyB83zo6/Ow9704IfVR7C3tl7aNq3nh9DdzYM/ 96wYBfnWxwYHogpD+xKKBHnCLtvO63wlPsa6aaE50r50aut7qG2yvSikTICmi4p09xCGHGtmsQx xKsECJQq6bEGZj/Q063kTryLTuiWBnsarEajgsghK/E4eguV97AV/TuNPI0zJl5HDtJOt868H8+ 1Z5b/Mu0kW1rjK5nfZ0xK5hEhnFKAWjGIW4zQtZlkS7WORFFL/anqE8i7ISH6M2rqsQX6hFFGf8 tLDyrk28IAydDhUcrTiFOOyG4OKhxND2mQ3XvvB/HnkCSE3C2r65eQj1gbk X-Received: by 2002:a05:690e:1a03:b0:649:f272:4e71 with SMTP id 956f58d0204a3-64e915e9af0mr2899384d50.61.1773843417840; Wed, 18 Mar 2026 07:16:57 -0700 (PDT) Received: from soleen.c.googlers.com.com (57.233.150.34.bc.googleusercontent.com. [34.150.233.57]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64e91be0e91sm1672028d50.15.2026.03.18.07.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 07:16:57 -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 Subject: [PATCH v2 2/8] liveupdate: Protect FLB lists with rwsem Date: Wed, 18 Mar 2026 10:16:40 -0400 Message-ID: <20260318141637.1870220-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog In-Reply-To: <20260318141637.1870220-10-pasha.tatashin@soleen.com> References: <20260318141637.1870220-10-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4697; i=pasha.tatashin@soleen.com; h=from:subject; bh=dkjsJaF9zS233/cIv2JZuqCsRBtr9t9nThiFjC9QTdU=; b=owEBbQKS/ZANAwAKAbt3KEzbc3reAcsmYgBpurPIEf2Hd/j/HyvzxGhdP66f5gdQf18OjzKVY 0RUvUJ6F6uJAjMEAAEKAB0WIQRBMaqT7LRvGvB/NmK7dyhM23N63gUCabqzyAAKCRC7dyhM23N6 3gGLD/44VIJY2e4gFWjXLJ68WeFLVVKrzyz58iPZAdSWRcT/aWoEVdIF4BQIzow+V+IIcH4NY/w Nn/LuiuTU89YdpPeiXb2E5HdyAbL+lDx26BgrQVWW6/mCe4iarCbKAd3OW5Xf7587w7g7+flKYQ zWYVKFpwv/yejr4B7xe+RSc6bpTOM7OM/4Fu2c8uGHW5UqJMiqMq6XYWBFyeg2Pi8Jizr9/5Bbb fOm1BU3MC1nFb352hGrjCfbWinbaSsVqEjRoGKqE3YyZAhSftlXlZkkf0Br82sasckGzKlH8dXt +lYELDGrBrAkBJs7t+3ufEkg+e5ZY8ZSZyeGcDO1oYbOv+N8J98uvHW5wBPxDeeVLOKNqBjiTY9 pCGmfrAIesk6kLVQxW2NeSBHLkfDL5NBSjVWLSjVpMhyDJ1zbt3xycDw0EHKaNrNjsHxZm0asdO kJgdWoIVRxPqYwY1zOEJpTrRMqDCjkGV17YHvVEBoFjG7uFHjCn8HCoVbjcLSDT91WCIsjpQOin WERJJtUiOISYNRkuhQPOYSxvVQvlcbPlGUqjHIKkwranZ/A/Jma3IBdHAIn+3kFoWKhYHcbx3M7 dDxIRtf7lFyjqve2kkaHJn7iNBsoQSu6VG2awJW+fLnAVTKgPbPB/ox3FZOz2A+sWuHt42Mq+Uy /rOdRqhXaQhTBCw== X-Developer-Key: i=pasha.tatashin@soleen.com; a=openpgp; fpr=CAAAB722DD22A081F0D49F35633A6A993D43B569 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 @@ -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; }; =20 /** 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) } =20 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; }; =20 +static DECLARE_RWSEM(luo_flb_lock); static struct luo_flb_global luo_flb_global =3D { .list =3D LIST_HEAD_INIT(luo_flb_global.list), }; @@ -240,6 +242,8 @@ int luo_flb_file_preserve(struct liveupdate_file_handle= r *fh) struct luo_flb_link *iter; int err =3D 0; =20 + guard(rwsem_read)(&ACCESS_PRIVATE(fh, flb_lock)); + list_for_each_entry(iter, flb_list, list) { err =3D luo_flb_file_preserve_one(iter->flb); if (err) @@ -272,6 +276,8 @@ void luo_flb_file_unpreserve(struct liveupdate_file_han= dler *fh) struct list_head *flb_list =3D &ACCESS_PRIVATE(fh, flb_list); struct luo_flb_link *iter; =20 + 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 =3D &ACCESS_PRIVATE(fh, flb_list); struct luo_flb_link *iter; =20 + 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_hand= ler *fh, if (!luo_session_quiesce()) return -EBUSY; =20 + guard(rwsem_write)(&luo_flb_lock); + guard(rwsem_write)(&ACCESS_PRIVATE(fh, flb_lock)); + /* Check that this FLB is not already linked to this file handler */ err =3D -EEXIST; list_for_each_entry(iter, flb_list, list) { @@ -444,6 +455,9 @@ int liveupdate_unregister_flb(struct liveupdate_file_ha= ndler *fh, if (!luo_session_quiesce()) return -EBUSY; =20 + 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 =3D=3D flb) { @@ -638,6 +652,8 @@ void luo_flb_serialize(void) struct liveupdate_flb *gflb; int i =3D 0; =20 + guard(rwsem_read)(&luo_flb_lock); + list_private_for_each_entry(gflb, &luo_flb_global.list, private.list) { struct luo_flb_private *private =3D luo_flb_get_private(gflb); =20 --=20 2.53.0.851.ga537e3e6e9-goog