Skip to content

Commit 891cdbb

Browse files
igawkeithbusch
authored andcommitted
nvme-fc: use lock accessing port_state and rport state
nvme_fc_unregister_remote removes the remote port on a lport object at any point in time when there is no active association. This races with with the reconnect logic, because nvme_fc_create_association is not taking a lock to check the port_state and atomically increase the active count on the rport. Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Closes: https://lore.kernel.org/all/u4ttvhnn7lark5w3sgrbuy2rxupcvosp4qmvj46nwzgeo5ausc@uyrkdls2muwx Signed-off-by: Daniel Wagner <wagi@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 10c165a commit 891cdbb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • drivers/nvme/host

drivers/nvme/host/fc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,11 +3032,17 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
30323032

30333033
++ctrl->ctrl.nr_reconnects;
30343034

3035-
if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE)
3035+
spin_lock_irqsave(&ctrl->rport->lock, flags);
3036+
if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE) {
3037+
spin_unlock_irqrestore(&ctrl->rport->lock, flags);
30363038
return -ENODEV;
3039+
}
30373040

3038-
if (nvme_fc_ctlr_active_on_rport(ctrl))
3041+
if (nvme_fc_ctlr_active_on_rport(ctrl)) {
3042+
spin_unlock_irqrestore(&ctrl->rport->lock, flags);
30393043
return -ENOTUNIQ;
3044+
}
3045+
spin_unlock_irqrestore(&ctrl->rport->lock, flags);
30403046

30413047
dev_info(ctrl->ctrl.device,
30423048
"NVME-FC{%d}: create association : host wwpn 0x%016llx "

0 commit comments

Comments
 (0)