All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Adrian Hunter <adrian.hunter@intel.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: "James E . J . Bottomley" <jejb@linux.ibm.com>,
	Bean Huo <huobean@gmail.com>, Avri Altman <avri.altman@wdc.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Can Guo <cang@codeaurora.org>,
	Asutosh Das <asutoshd@codeaurora.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	Wei Li <liwei213@huawei.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH V3 1/3] scsi: ufs: Fix error handler clear ua deadlock
Date: Tue, 7 Sep 2021 15:36:11 -0700	[thread overview]
Message-ID: <e5307bbe-1cda-fdd2-a666-ae57cd90de07@acm.org> (raw)
In-Reply-To: <d9656961-4abb-aff0-e34d-d8082a1f4eaa@acm.org>

On 9/7/21 9:56 AM, Bart Van Assche wrote:
> On 9/7/21 8:43 AM, Adrian Hunter wrote:
>> No.  Requests cannot make progress when ufshcd_state is
>> UFSHCD_STATE_EH_SCHEDULED_FATAL, and only the error handler can change 
>> that,
>> so if the error handler is waiting to enter the queue and 
>> blk_mq_freeze_queue()
>> is waiting for outstanding requests, they will deadlock.
> 
> How about adding the above text as a comment above 
> ufshcd_clear_ua_wluns() such
> that this information becomes available to those who have not followed this
> conversation?

After having given patch 1/3 some further thought: an unfortunate
effect of this patch is that unit attention clearing is skipped for
the states UFSHCD_STATE_EH_SCHEDULED_FATAL and UFSHCD_STATE_RESET.
How about replacing patch 1/3 with the untested patch below since that
patch does not have the disadvantage of sometimes skipping clearing UA?

Thanks,

Bart.

[PATCH] scsi: ufs: Fix a recently introduced deadlock

Completing pending commands with DID_IMM_RETRY triggers the following
code paths:

   scsi_complete()
   -> scsi_queue_insert()
     -> __scsi_queue_insert()
       -> scsi_device_unbusy()
         -> scsi_dec_host_busy()
	  -> scsi_eh_wakeup()
       -> blk_mq_requeue_request()

   scsi_queue_rq()
   -> scsi_host_queue_ready()
     -> scsi_host_in_recovery()

Fixes: a113eaaf8637 ("scsi: ufs: Synchronize SCSI and UFS error handling")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
  drivers/scsi/ufs/ufshcd.c | 8 ++++++++
  1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index c2c614da1fb8..9560f34f3d27 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2707,6 +2707,14 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  		}
  		fallthrough;
  	case UFSHCD_STATE_RESET:
+		/*
+		 * The SCSI error handler only starts after all pending commands
+		 * have failed or timed out. Complete commands with
+		 * DID_IMM_RETRY to allow the error handler to start
+		 * if it has been scheduled.
+		 */
+		set_host_byte(cmd, DID_IMM_RETRY);
+		cmd->scsi_done(cmd);
  		err = SCSI_MLQUEUE_HOST_BUSY;
  		goto out;
  	case UFSHCD_STATE_ERROR:

  reply	other threads:[~2021-09-07 22:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-05  9:51 [PATCH V3 0/3] scsi: ufs: Let devices remain runtime suspended during system suspend Adrian Hunter
2021-09-05  9:51 ` [PATCH V3 1/3] scsi: ufs: Fix error handler clear ua deadlock Adrian Hunter
2021-09-07 14:42   ` Bart Van Assche
2021-09-07 15:43     ` Adrian Hunter
2021-09-07 16:56       ` Bart Van Assche
2021-09-07 22:36         ` Bart Van Assche [this message]
2021-09-11 16:47           ` Adrian Hunter
2021-09-13  3:17             ` Bart Van Assche
2021-09-13  8:53               ` Adrian Hunter
2021-09-13 16:33                 ` Bart Van Assche
2021-09-13 17:13                   ` Adrian Hunter
2021-09-13 20:11                     ` Bart Van Assche
2021-09-14  4:55                       ` Adrian Hunter
2021-09-14 22:28                         ` Bart Van Assche
2021-09-15 15:35                           ` Adrian Hunter
2021-09-15 22:41                             ` Bart Van Assche
2021-09-16 17:01                               ` Adrian Hunter
2021-09-05  9:51 ` [PATCH V3 2/3] scsi: ufs: Fix runtime PM dependencies getting broken Adrian Hunter
2021-09-05  9:51 ` [PATCH V3 3/3] scsi: ufs: Let devices remain runtime suspended during system suspend Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e5307bbe-1cda-fdd2-a666-ae57cd90de07@acm.org \
    --to=bvanassche@acm.org \
    --cc=adrian.hunter@intel.com \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avri.altman@wdc.com \
    --cc=cang@codeaurora.org \
    --cc=huobean@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=liwei213@huawei.com \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.