public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <Niklas.Cassel@wdc.com>
To: Hannes Reinecke <hare@suse.de>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	John Garry <john.g.garry@oracle.com>
Subject: Re: [PATCH] scsi_error: do not queue pointless abort workqueue functions
Date: Thu, 10 Nov 2022 10:38:07 +0000	[thread overview]
Message-ID: <Y2zUjhGZoyzADUsC@x1-carbon> (raw)
In-Reply-To: <20221109074754.24075-1-hare@suse.de>

On Wed, Nov 09, 2022 at 08:47:54AM +0100, Hannes Reinecke wrote:
> If a host template doesn't implement the .eh_abort_handler()
> there is no point in queueing the abort workqueue function;
> all it does is invoking SCSI EH anyway.
> So return 'FAILED' from scsi_abort_command() if the .eh_abort_handler()
> is not implemented and save us from having to wait for the
> abort workqueue function to complete.
>
> Cc: Niklas Cassel <Niklas.Cassel@wdc.com>
> Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Cc: John Garry <john.garry@oracle.com>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/scsi/scsi_error.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
> index be2a70c5ac6d..e9f9c8f52c59 100644
> --- a/drivers/scsi/scsi_error.c
> +++ b/drivers/scsi/scsi_error.c
> @@ -242,6 +242,11 @@ scsi_abort_command(struct scsi_cmnd *scmd)
>		return FAILED;
>	}
>
> +	if (!shost->hostt->eh_abort_handler) {
> +		/* No abort handler, fail command directly */
> +		return FAILED;
> +	}
> +

Hello Hannes,

is there any reason why you didn't put this before the preceding
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
if statement?

>	spin_lock_irqsave(shost->host_lock, flags);
>	if (shost->eh_deadline != -1 && !shost->last_reset)
>		shost->last_reset = jiffies;
> --
> 2.35.3
>

After some additional testing with this patch, I did notice that it does
introduce a behavioural change from libata perspective:

Before this patch, for libata, scmd_eh_abort_handler() would get called,
and we would come into this statement:

	rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
	if (rtn != SUCCESS) {
		SCSI_LOG_ERROR_RECOVERY(3,
			scmd_printk(KERN_INFO, scmd,
				    "cmd abort %s\n",
				    (rtn == FAST_IO_FAIL) ?
				    "not send" : "failed"));
		goto out;
	}

Which jumps to:

out:
	spin_lock_irqsave(shost->host_lock, flags);
	list_del_init(&scmd->eh_entry);
	spin_unlock_irqrestore(shost->host_lock, flags);

	scsi_eh_scmd_add(scmd);


So scsi_eh_scmd_add() would be called.



After this patch, scsi_abort_command() will return FAILED instead
of SUCCESS, which means that scsi_timeout() instead enters this
if statement:

	if (scsi_abort_command(scmd) != SUCCESS) {
		set_host_byte(scmd, DID_TIME_OUT);
		scsi_eh_scmd_add(scmd);
	}

Which means that scmds reaching libata .eh_strategy_handler()
now has host_byte DID_TIME_OUT set, while before this patch,
that was not the case.


I guess we could simply clear the host_byte in libata's
.eh_strategy_handler() (and that is actually what we do).



I just want to understand how it is meant to work.

Looking back at the code to when libata first started to use
blk_abort_request()/scsi_req_abort_cmd(), DID_TIME_OUT was only set
if scsi_eh_scmd_add() failed:
https://github.com/torvalds/linux/blob/7b70fc039824bc7303e4007a5f758f832de56611/drivers/scsi/scsi_error.c#L181

Martin then moved the set_host_byte(scmd, DID_TIME_OUT)
to be done regardless if scsi_eh_scmd_add() failed or not in:
18a4d0a22ed6 ("[SCSI] Handle disk devices which can not process medium access commands")
without really explaining why.

Then in your commit:
2171b6d08bf8 ("scsi: make scsi_eh_scmd_add() always succeed")

you changed scsi_times_out() to:
+               if (host->hostt->no_async_abort ||
+                   scsi_abort_command(scmd) != SUCCESS) {
+                       set_host_byte(scmd, DID_TIME_OUT);
+                       scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD);
+               }

And it also changed scmd_eh_abort_handler():

-       if (!scsi_eh_scmd_add(scmd, 0)) {
-               SCSI_LOG_ERROR_RECOVERY(3,
-                       scmd_printk(KERN_WARNING, scmd,
-                                   "terminate aborted command\n"));
-               set_host_byte(scmd, DID_TIME_OUT);
-               scsi_finish_command(scmd);
-       }
+       scsi_eh_scmd_add(scmd, 0);


So for libata, which did not set host->hostt->no_async_abort,
scsi_abort_command() would return SUCCESS, so we would not go
into that if statement. Instead we would have the current behavior
where scmd_eh_abort_handler() fails, and does a goto out;
to add the scsi_eh_scmd_add() (without setting DID_TIME_OUT).

Should perhaps scmd_eh_abort_handler() perhaps set DID_TIME_OUT
unconditionally, to match the code before the change?

To me, it is not really clear how the SCSI code is meant to behave.


I think if the timeout has actually triggered, because the timer expired,
it makes sense that scsi_timeout() sets DID_TIME_OUT.

But if e.g. libata called blk_abort_request() to abort the command before
the timer actually expired, I'm not sure.


For ata part, it does not really matter, because currently, libata always
overwrites the scmd->result anyway. However, there might be other LLDD
where this change actually do matter.





(For the curious, libata's own way of detecting if the command actually
was a timeout from scsi_timeout() or if it was an aborted command works
like this:

If QCFLAG_FAILED is not set in .eh_strategy_handler, then libata EH does
not own the QC, so it was scsi_timeout() that won the race, without libata
ever aborting the command. It then sets qc->err_mask = AC_ERR_TIMEOUT).

So libata currently never looks at host_byte(), it always overwrites it,
and it instead uses its own way of detecting that a timeout occured, if so,
it freezes the port (disables IRQs) and resets the controller, and increases
smcd->allowed, such that the command is retried.)


Kind regards,
Niklas

      parent reply	other threads:[~2022-11-10 10:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  7:47 [PATCH] scsi_error: do not queue pointless abort workqueue functions Hannes Reinecke
2022-11-09  8:28 ` [External] : " John Garry
2022-11-09 12:48   ` Hannes Reinecke
2022-11-09  9:29 ` Niklas Cassel
2022-11-10 10:38 ` Niklas Cassel [this message]

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=Y2zUjhGZoyzADUsC@x1-carbon \
    --to=niklas.cassel@wdc.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=john.g.garry@oracle.com \
    --cc=linux-scsi@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox