Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: target: core: annotate LUN hlist traversals
@ 2026-06-25 11:38 Runyu Xiao
  2026-06-25 11:50 ` Runyu Xiao
  2026-06-25 11:55 ` [PATCH] " sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Runyu Xiao @ 2026-06-25 11:38 UTC (permalink / raw)
  To: martin.petersen
  Cc: linux-scsi, target-devel, linux-kernel, runyu.xiao, jianhao.xu

Some target-core writer-side helpers walk RCU hlist state while already
holding the mutex that serializes the operation:

core_free_device_list_for_node() holds nacl->lun_entry_mutex
core_clear_lun_from_tpg() holds nacl->lun_entry_mutex
core_tpg_add_node_to_devs() holds tpg->tpg_lun_mutex

The code already uses the same lockdep condition for the
rcu_dereference_check() of lun->lun_se_dev in
core_tpg_add_node_to_devs(). Pass the corresponding mutex condition to
the RCU hlist iterators as well so CONFIG_PROVE_RCU_LIST can see the
non-RCU protection.

This was found by our static analysis tool and then manually reviewed
against the current tree. In the reviewed CONFIG_PROVE_RCU_LIST triage
runs, the LUN hlist walkers produced the expected "RCU-list traversed
in non-reader section!!" warning with stacks matching
core_free_device_list_for_node(), core_clear_lun_from_tpg(), and
core_tpg_add_node_to_devs(). The change is limited to documenting the
existing protection contract.

This is a lockdep annotation cleanup. It does not change LUN list
lifetime or serialization.

Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
 drivers/target/target_core_device.c | 6 ++++--
 drivers/target/target_core_tpg.c    | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 9db2201aa553..82aa831c69c9 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -237,7 +237,8 @@ void core_free_device_list_for_node(
 	struct se_dev_entry *deve;
 
 	mutex_lock(&nacl->lun_entry_mutex);
-	hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link)
+	hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link,
+				 lockdep_is_held(&nacl->lun_entry_mutex))
 		core_disable_device_list_for_node(deve->se_lun, deve, nacl, tpg);
 	mutex_unlock(&nacl->lun_entry_mutex);
 }
@@ -483,7 +484,8 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
 	list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) {
 
 		mutex_lock(&nacl->lun_entry_mutex);
-		hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
+		hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link,
+					 lockdep_is_held(&nacl->lun_entry_mutex)) {
 			if (lun != deve->se_lun)
 				continue;
 
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index ccff9f6e4826..74bfcaa11188 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -111,7 +111,8 @@ void core_tpg_add_node_to_devs(
 	struct se_device *dev;
 
 	mutex_lock(&tpg->tpg_lun_mutex);
-	hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link) {
+	hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link,
+				 lockdep_is_held(&tpg->tpg_lun_mutex)) {
 		if (lun_orig && lun != lun_orig)
 			continue;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-25 12:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 11:38 [PATCH] scsi: target: core: annotate LUN hlist traversals Runyu Xiao
2026-06-25 11:50 ` Runyu Xiao
2026-06-25 11:55 ` [PATCH] " sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox