All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand()
@ 2021-10-08  8:40 Adrian Hunter
  2021-10-08 16:40 ` Asutosh Das (asd)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Adrian Hunter @ 2021-10-08  8:40 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Asutosh Das, Bart Van Assche, linux-scsi

The SCSI error handler calls scsi_unjam_host() which can call the queue
function ufshcd_queuecommand() indirectly. The error handler changes the
state to UFSHCD_STATE_RESET while running, but error interrupts that
happen while the error handler is running could change the state to
UFSHCD_STATE_EH_SCHEDULED_NON_FATAL which would allow requests to go
through ufshcd_queuecommand() even though the error handler is running.
Block that hole by checking whether the error handler is in progress.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Add comment

 drivers/scsi/ufs/ufshcd.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index f34227add27d..29d202207b18 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2688,7 +2688,19 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 
 	switch (hba->ufshcd_state) {
 	case UFSHCD_STATE_OPERATIONAL:
+		break;
 	case UFSHCD_STATE_EH_SCHEDULED_NON_FATAL:
+		/*
+		 * SCSI error handler can call ->queuecommand() while UFS error
+		 * handler is in progress. Error interrupts could change the
+		 * state from UFSHCD_STATE_RESET to
+		 * UFSHCD_STATE_EH_SCHEDULED_NON_FATAL. Prevent requests
+		 * being issued in that case.
+		 */
+		if (ufshcd_eh_in_progress(hba)) {
+			err = SCSI_MLQUEUE_HOST_BUSY;
+			goto out;
+		}
 		break;
 	case UFSHCD_STATE_EH_SCHEDULED_FATAL:
 		/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand()
  2021-10-08  8:40 [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand() Adrian Hunter
@ 2021-10-08 16:40 ` Asutosh Das (asd)
  2021-10-12 17:53 ` Martin K. Petersen
  2021-10-21  3:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Asutosh Das (asd) @ 2021-10-08 16:40 UTC (permalink / raw)
  To: Adrian Hunter, Martin K . Petersen
  Cc: James E . J . Bottomley, Bean Huo, Avri Altman, Alim Akhtar,
	Can Guo, Bart Van Assche, linux-scsi

On 10/8/2021 1:40 AM, Adrian Hunter wrote:
> The SCSI error handler calls scsi_unjam_host() which can call the queue
> function ufshcd_queuecommand() indirectly. The error handler changes the
> state to UFSHCD_STATE_RESET while running, but error interrupts that
> happen while the error handler is running could change the state to
> UFSHCD_STATE_EH_SCHEDULED_NON_FATAL which would allow requests to go
> through ufshcd_queuecommand() even though the error handler is running.
> Block that hole by checking whether the error handler is in progress.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---

LGTM.
Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

> 
> Changes in V2:
> 
> 	Add comment
> 
>   drivers/scsi/ufs/ufshcd.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index f34227add27d..29d202207b18 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -2688,7 +2688,19 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
>   
>   	switch (hba->ufshcd_state) {
>   	case UFSHCD_STATE_OPERATIONAL:
> +		break;
>   	case UFSHCD_STATE_EH_SCHEDULED_NON_FATAL:
> +		/*
> +		 * SCSI error handler can call ->queuecommand() while UFS error
> +		 * handler is in progress. Error interrupts could change the
> +		 * state from UFSHCD_STATE_RESET to
> +		 * UFSHCD_STATE_EH_SCHEDULED_NON_FATAL. Prevent requests
> +		 * being issued in that case.
> +		 */
> +		if (ufshcd_eh_in_progress(hba)) {
> +			err = SCSI_MLQUEUE_HOST_BUSY;
> +			goto out;
> +		}
>   		break;
>   	case UFSHCD_STATE_EH_SCHEDULED_FATAL:
>   		/*
> 


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand()
  2021-10-08  8:40 [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand() Adrian Hunter
  2021-10-08 16:40 ` Asutosh Das (asd)
@ 2021-10-12 17:53 ` Martin K. Petersen
  2021-10-21  3:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-10-12 17:53 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, James E . J . Bottomley, Bean Huo,
	Avri Altman, Alim Akhtar, Can Guo, Asutosh Das, Bart Van Assche,
	linux-scsi


Adrian,

> The SCSI error handler calls scsi_unjam_host() which can call the queue
> function ufshcd_queuecommand() indirectly. The error handler changes the
> state to UFSHCD_STATE_RESET while running, but error interrupts that
> happen while the error handler is running could change the state to
> UFSHCD_STATE_EH_SCHEDULED_NON_FATAL which would allow requests to go
> through ufshcd_queuecommand() even though the error handler is running.
> Block that hole by checking whether the error handler is in progress.

Applied to 5.16/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand()
  2021-10-08  8:40 [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand() Adrian Hunter
  2021-10-08 16:40 ` Asutosh Das (asd)
  2021-10-12 17:53 ` Martin K. Petersen
@ 2021-10-21  3:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-10-21  3:42 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, Avri Altman, Alim Akhtar, Bart Van Assche,
	Can Guo, James E . J . Bottomley, Bean Huo, linux-scsi,
	Asutosh Das

On Fri, 8 Oct 2021 11:40:48 +0300, Adrian Hunter wrote:

> The SCSI error handler calls scsi_unjam_host() which can call the queue
> function ufshcd_queuecommand() indirectly. The error handler changes the
> state to UFSHCD_STATE_RESET while running, but error interrupts that
> happen while the error handler is running could change the state to
> UFSHCD_STATE_EH_SCHEDULED_NON_FATAL which would allow requests to go
> through ufshcd_queuecommand() even though the error handler is running.
> Block that hole by checking whether the error handler is in progress.
> 
> [...]

Applied to 5.16/scsi-queue, thanks!

[1/1] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand()
      https://git.kernel.org/mkp/scsi/c/d489f18ad1fc

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-21  3:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08  8:40 [PATCH V2] scsi: ufs: core: Fix synchronization between scsi_unjam_host() and ufshcd_queuecommand() Adrian Hunter
2021-10-08 16:40 ` Asutosh Das (asd)
2021-10-12 17:53 ` Martin K. Petersen
2021-10-21  3:42 ` Martin K. Petersen

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.