Message ID | 20211213230045.492994-1-huobean@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v1] scsi: ufs: Fix deadlock issue in ufshcd_wait_for_doorbell_clr() | expand |
On 12/13/21 3:00 PM, Bean Huo wrote: > Call shost_for_each_device() with host->host_lock is held will cause > a deadlock situation, which will cause the system to stall (the log > as follow). Fix this issue by narrowing the scope of the lock. Hi Bean, As you probably know I do not have access to a test setup that supports clock scaling. Has the following patch been considered? diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6d692aae67ce..244eddf0caf8 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1084,7 +1084,9 @@ static u32 ufshcd_pending_cmds(struct ufs_hba *hba) struct scsi_device *sdev; u32 pending = 0; - shost_for_each_device(sdev, hba->host) + lockdep_assert_held(hba->host->host_lock); + + __shost_for_each_device(sdev, hba->host) pending += sbitmap_weight(&sdev->budget_map); return pending; Thanks, Bart.
On Mon, Dec 13, 2021 at 8:15 PM Bart Van Assche <bvanassche@acm.org> wrote: > > On 12/13/21 3:00 PM, Bean Huo wrote: > > Call shost_for_each_device() with host->host_lock is held will cause > > a deadlock situation, which will cause the system to stall (the log > > as follow). Fix this issue by narrowing the scope of the lock. > > Hi Bean, > > As you probably know I do not have access to a test setup that supports clock > scaling. Has the following patch been considered? > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > index 6d692aae67ce..244eddf0caf8 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -1084,7 +1084,9 @@ static u32 ufshcd_pending_cmds(struct ufs_hba *hba) > struct scsi_device *sdev; > u32 pending = 0; > > - shost_for_each_device(sdev, hba->host) > + lockdep_assert_held(hba->host->host_lock); > + > + __shost_for_each_device(sdev, hba->host) > pending += sbitmap_weight(&sdev->budget_map); We hit the same issue today as well, and this solution works on db845c. Reported-by: YongQin Liu <yongqin.liu@linaro.org> Reported-by: Amit Pundir <amit.pundir@linaro.org> Tested-by: John Stultz <john.stultz@linaro.org> thanks -john
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6dd517267f1b..15333a327b93 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1099,19 +1099,21 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, ktime_t start; ufshcd_hold(hba, false); - spin_lock_irqsave(hba->host->host_lock, flags); /* * Wait for all the outstanding tasks/transfer requests. * Verify by checking the doorbell registers are clear. */ start = ktime_get(); do { + spin_lock_irqsave(hba->host->host_lock, flags); if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { ret = -EBUSY; + spin_unlock_irqrestore(hba->host->host_lock, flags); goto out; } - tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL); + spin_unlock_irqrestore(hba->host->host_lock, flags); + tr_pending = ufshcd_pending_cmds(hba); if (!tm_doorbell && !tr_pending) { timeout = false; @@ -1120,7 +1122,6 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, break; } - spin_unlock_irqrestore(hba->host->host_lock, flags); schedule(); if (ktime_to_us(ktime_sub(ktime_get(), start)) > wait_timeout_us) { @@ -1132,7 +1133,6 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, */ do_last_check = true; } - spin_lock_irqsave(hba->host->host_lock, flags); } while (tm_doorbell || tr_pending); if (timeout) { @@ -1142,7 +1142,6 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, ret = -EBUSY; } out: - spin_unlock_irqrestore(hba->host->host_lock, flags); ufshcd_release(hba); return ret; }