diff mbox

[1/1] scsi/libfc: fix a deadlock in fc_rport_work

Message ID 1507246881-20508-1-git-send-email-satishkh@cisco.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Satish Kharat Oct. 5, 2017, 11:41 p.m. UTC
From: Satish Kharat <satishkh@cisco.com>

In places like fc_rport_recv_plogi_req and fcoe_ctlr_vn_add we
always take the lport disc_mutex lock before the rports mutex
(rp_mutex) lock. Gaurding list_del_rcu(&rdata->peers) with
disc.disc_mutex in fc_rport_work is correct but the rp_mutex lock
can and should to be dropped before taking that lock else results
in a deadlock.

Signed-off-by: Satish Kharat <satishkh@cisco.com>
---
 drivers/scsi/libfc/fc_rport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Johannes Thumshirn Oct. 6, 2017, 7:45 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Martin K. Petersen Oct. 6, 2017, 6:58 p.m. UTC | #2
Satish,

> In places like fc_rport_recv_plogi_req and fcoe_ctlr_vn_add we
> always take the lport disc_mutex lock before the rports mutex
> (rp_mutex) lock. Gaurding list_del_rcu(&rdata->peers) with
> disc.disc_mutex in fc_rport_work is correct but the rp_mutex lock
> can and should to be dropped before taking that lock else results
> in a deadlock.

Applied to 4.14/scsi-fixes. Thank you!
diff mbox

Patch

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 5203258..31d31aa 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -383,11 +383,11 @@  static void fc_rport_work(struct work_struct *work)
 				fc_rport_enter_flogi(rdata);
 				mutex_unlock(&rdata->rp_mutex);
 			} else {
+				mutex_unlock(&rdata->rp_mutex);
 				FC_RPORT_DBG(rdata, "work delete\n");
 				mutex_lock(&lport->disc.disc_mutex);
 				list_del_rcu(&rdata->peers);
 				mutex_unlock(&lport->disc.disc_mutex);
-				mutex_unlock(&rdata->rp_mutex);
 				kref_put(&rdata->kref, fc_rport_destroy);
 			}
 		} else {