Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: scameron@beardog.cce.hp.com
Cc: linux-scsi@vger.kernel.org, elliott@hp.com
Subject: Re: Question about scsi error handling and LLD
Date: Tue, 19 Aug 2014 12:16:12 -0500	[thread overview]
Message-ID: <1408468572.7095.11.camel@jarvis> (raw)
In-Reply-To: <20140819153051.GG19666@beardog.cce.hp.com>

On Tue, 2014-08-19 at 10:30 -0500, scameron@beardog.cce.hp.com wrote:
> 
> Is it permitted for a LLD to call scsi_done() for a command which
> has been or is attempting to be aborted via the LLD abort error handler
> function?
> 
> I am looking at the scsi mid layer code, and I'm a bit confused.

Hannes asked a similar question; does this help:

http://marc.info/?l=linux-scsi&m=140267838320488

James


> There seem to be a few ways the LLD abort handler function can
> get called.
> 
> One path:
> 
> scsi_times_out() calls scsi_abort_command() which queues
> cmd->abort_work in 10ms.  This will cause scmd_eh_abort_handler()
> to be called, which can call scsi_try_to_abort_cmd() which
> calls the LLD abort error handler function.  If the LLD abort
> error handler function returns SUCCESS, then scmd_eh_abort_handler()
> may requeue the command via scsi_queue_insert() re-using the same
> scsi_cmnd pointer.  Or, it may call scsi_finish_cmnd() on that
> scsi_cmnd.
> 
> Both of those actions, requeueing the same scsi command, or calling
> scsi_finish_cmnd(), seem incompatible with the LLD also having
> called scsi_done() on the command.
> 
> I think, scsi_done eventually frees the scsi_cmnd...
> 
> scsi_done() -> blk_complete_request -> __blk_complete_request ->
> 	-> raise_softirq_irqoff	-> ??? -> scsi_softirq_done() ->
> 	-> scsi_finish_cmnd() -> scsi_io_completion -> scsi_end_request()
> 	-> scsi_mq_uninit_cmd() ... etc.
> 
> It seems like either calling scsi_finish_cmnd() too many times (once via
> LLD calling scsi_done, and once via scmd_eh_abort_handler calling
> scsi_finish_cmnd()), or calling scsi_done() via LLD concurrently with
> re-using that same scsi command (via scmd_eh_abort_handler calling
> scsi_queue_insert()) would both be bad things.  Correct?
> 
> So, without completely understanding it, it seems like if the LLD
> abort handler is going to return SUCCESS, it must be sure that it
> hasn't already called scsi_done() on the command.  Or to put it
> another way, the LLD must make sure there is not a race between
> the abort handler and the interrupt handler, and the instant
> the LLD abort handler is called for a command, calling scsi_done()
> for that command is no longer an option for the LLD.  But, I do
> not see how to synchronize that.
> 
> I hope I'm missing something here, because I am having a hard time
> seeing how to eliminate the race between the LLD abort handler and
> command completion in the LLD, esp. since now (due to my hardware's
> specific weirdness) I may in the interrupt handler requeue the command
> internally in a workqueue within the LLD for submission to HW a 2nd
> time before completion back to the mid layer under some circumstances
> (e.g. fast path failed, try slower but more robust RAID stack path.)
> 
> But, then there is this comment attached to scsi_times_out() which
> makes me feel better:
> 
>  * Notes:
>  *     We do not need to lock this.  There is the potential for a race
>  *     only in that the normal completion handling might run, but if the
>  *     normal completion function determines that the timer has already
>  *     fired, then it mustn't do anything.
>  */
> 
> So, perhaps that is the answer I'm looking for.  If the comment is
> correct and my understanding of it is correct, then the LLD *is* free
> to call scsi_done() even though it races with the LLD abort handler?
> 
> I'm not finding the code that implements what that comment claims though.
> Is it in the block layer code?
> 
> -- steve
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



  reply	other threads:[~2014-08-19 17:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19 15:30 Question about scsi error handling and LLD scameron
2014-08-19 17:16 ` James Bottomley [this message]
2014-08-19 17:59   ` scameron

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=1408468572.7095.11.camel@jarvis \
    --to=james.bottomley@hansenpartnership.com \
    --cc=elliott@hp.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=scameron@beardog.cce.hp.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