Skip to contentSkip to conversation

nvmet: protect discovery change log event

PATCH New Sagi Grimberg 2 participants 2 messages Mar 11, 2019 – Mar 12, 2019

Subsystems (2)
lore
Share & tools
lore

Sagi Grimberg

author maintainer
#0 lore raw

PATCH 1/1 nvmet: protect discovery change log event

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>
---
 drivers/nvme/target/discovery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/target/discovery.c +4 -1
index a34cf4986a49..dd6e8248e643 100644
@@ -38,14 +38,15 @@ void nvmet_port_disc_changed(struct nvmet_port *port,
 {
 	struct nvmet_ctrl *ctrl;
 
+	mutex_lock(&nvmet_disc_subsys->lock);
 	nvmet_genctr++;
-
 	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,
@@ -54,12 +55,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

drivers/nvme/target/discovery.c void nvmet_port_disc_changed(struct nvmet_port *port, · line 42

Quoted 5 lines
drivers/nvme/target/discovery.c +1 -1
 	struct nvmet_ctrl *ctrl;
 
+	mutex_lock(&nvmet_disc_subsys->lock);
 	nvmet_genctr++;
-

But there should be no need to takes this over the nvmet_genctr increment, that is supposed to be protected using nvmet_config_sem. That being said a lockdep_assert_held for that would be nice.

Also I think the subject line could use a tweak - we are not really protecting the event, but the list iteration (as explained in the commit log)