nvmet: protect discovery change log event
Subsystems (2)
Sagi Grimberg
maintainerPATCH 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
@@ -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
Christoph Hellwig
maintainerPATCH 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
-1struct 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)