mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
nvmet: protect nvmet_ports_list with nvmet_config_sem
Readers of nvmet_ports_list (e.g. nvmet_subsys_disc_changed()) hold
nvmet_config_sem and assert it via lockdep. The writers --
nvmet_ports_make() and nvmet_port_release() -- do not take the lock;
they rely on the parent directory's VFS inode lock for serialization,
which is an implementation detail of configfs and not a guaranteed
contract. Align the writers with the lock the readers already require.
Also move list_add() in nvmet_ports_make() to after the port is fully
initialized: the old position published the port on the global list
before INIT_LIST_HEAD(&port->subsystems), so a concurrent reader
could traverse uninitialized list heads.
flush_workqueue() in nvmet_port_release() stays outside the semaphore
to avoid a lock dependency on nvmet_wq.
Fixes: b662a07857 ("nvmet: enable Discovery Controller AENs")
Reviewed-by: Maurizio Lombardi <mlombard@redhat.com>
Signed-off-by: Qing Zhang <diasyzhang@tencent.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
parent
a563f13a54
commit
cead6beb89
|
|
@ -2103,7 +2103,9 @@ static void nvmet_port_release(struct config_item *item)
|
|||
|
||||
/* Let inflight controllers teardown complete */
|
||||
flush_workqueue(nvmet_wq);
|
||||
down_write(&nvmet_config_sem);
|
||||
list_del(&port->global_entry);
|
||||
up_write(&nvmet_config_sem);
|
||||
|
||||
key_put(port->keyring);
|
||||
kfree(port);
|
||||
|
|
@ -2164,8 +2166,6 @@ static struct config_group *nvmet_ports_make(struct config_group *group,
|
|||
port->ana_state[i] = NVME_ANA_INACCESSIBLE;
|
||||
}
|
||||
|
||||
list_add(&port->global_entry, &nvmet_ports_list);
|
||||
|
||||
INIT_LIST_HEAD(&port->entry);
|
||||
INIT_LIST_HEAD(&port->subsystems);
|
||||
INIT_LIST_HEAD(&port->referrals);
|
||||
|
|
@ -2199,6 +2199,10 @@ static struct config_group *nvmet_ports_make(struct config_group *group,
|
|||
configfs_add_default_group(&port->ana_default_group.group,
|
||||
&port->ana_groups_group);
|
||||
|
||||
down_write(&nvmet_config_sem);
|
||||
list_add(&port->global_entry, &nvmet_ports_list);
|
||||
up_write(&nvmet_config_sem);
|
||||
|
||||
return &port->group;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user