Skip to contentSkip to conversation

nvmet: protect discovery change log event list iteration

PATCH New Sagi Grimberg 3 participants 3 messages Apr 29, 2019 – Apr 30, 2019

Subsystems (2)
lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

PATCH 1/1 nvmet: protect discovery change log event list iteration

When we iterate on the discovery subsystem controllers we need to protect against concurrent mutations to it.

Signed-off-by Sagi Grimberg <sagi at grimberg.me>

---
Changes from v1:
- don't protect nvmet_genctr with subsys lock but throw a lockdep_assert_held on nvmet_config_sem

 drivers/nvme/target/discovery.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/target/discovery.c +5 -0
index e8e09266bfa5..5baf269f3f8a 100644
@@ -30,14 +30,17 @@ void nvmet_port_disc_changed(struct nvmet_port *port,
 {
 	struct nvmet_ctrl *ctrl;
 
+	lockdep_assert_held(&nvmet_config_sem);
 	nvmet_genctr++;
 
+	mutex_lock(&nvmet_disc_subsys->lock);
 	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
 		if (subsys && !nvmet_host_allowed(subsys, ctrl->hostnqn))
 			continue;
 
 		__nvmet_disc_changed(port, ctrl);
 	}
+	mutex_unlock(&nvmet_disc_subsys->lock);
 }
 
 static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
@@ -46,12 +49,14 @@ static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
 {
 	struct nvmet_ctrl *ctrl;
 
+	mutex_lock(&nvmet_disc_subsys->lock);
 	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
 		if (host && strcmp(nvmet_host_name(host), ctrl->hostnqn))
 			continue;
 
 		__nvmet_disc_changed(port, ctrl);
 	}
+	mutex_unlock(&nvmet_disc_subsys->lock);
 }
 
 void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 nvmet: protect discovery change log event list iteration

Quoted 8 lines

-----Original Message-----
From: Linux-nvme [mailto:linux-nvme-bounces at lists.infradead.org] On Behalf Of Sagi Grimberg
Sent: Tuesday, April 30, 2019 8:28 AM
To: linux-nvme at lists.infradead.org
Cc: Keith Busch; Christoph Hellwig
Subject: [PATCH] nvmet: protect discovery change log event list iteration

Quoted 4 lines

When we iterate on the discovery subsystem controllers we need to protect against concurrent mutations to it.

Signed-off-by Sagi Grimberg <sagi at grimberg.me>

This looks good to me.

Reviewed-by Minwoo Im <minwoo.im at samsung.com>