All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Alan Stern <stern@rowland.harvard.edu>,
	John Garry <john.garry@huawei.com>
Cc: Christoph Hellwig <hch@lst.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	Hannes Reinecke <hare@suse.com>,
	chenxiang <chenxiang66@hisilicon.com>,
	Xiejianqin <xiejianqin@hisilicon.com>
Subject: Re: SCSI layer RPM deadlock debug suggestion
Date: Sun, 4 Jul 2021 16:45:44 -0700	[thread overview]
Message-ID: <ec4a3038-34b0-084f-a1bd-039827465dd1@acm.org> (raw)
In-Reply-To: <20210702203142.GA49307@rowland.harvard.edu>

On 7/2/21 1:31 PM, Alan Stern wrote:
> On Fri, Jul 02, 2021 at 06:03:20PM +0100, John Garry wrote:
>> Hi guys,
>>
>> We're experiencing a deadlock between trying to remove a SATA device and
>> doing a rescan in scsi_rescan_device().
>>
>> I'm just looking for a suggestion on how to solve.
>>
>> The background is that the host (hisi sas v3 hw) uses SAS SCSI transport and
>> supports RPM. In the testcase, the host and disks are put to suspend. Then
>> we run fio on the disk to make them active and then immediately hard reset
>> the disk link, which causes the disk to be disconnected (please don't ask
>> why ...).
>>
>> We find that there is a conflict between the rescan and the device removal
>> code, resulting in a deadlock:
> 
>> The rescan holds the sdev_gendev.device lock in scsi_rescan_device(), while
>> the removal code in __scsi_remove_device() wants to grab it.
>>
>> However the rescan will not release (the lock) until the blk_queue_enter()
>> succeeds, above. That can happen 2x ways:
>>
>> - the queue is dying, which would not happen until after the device_del() in
>> __scsi_remove_device(), so not going to happen
>>
>> - q->pm_only falls to 0. This would be when scsi_runtime_resume() ->
>> sdev_runtime_resume() -> blk_post_runtime_resume(err = 0) ->
>> blk_set_runtime_active() is called. However, I find that the err argument
>> for me is -5, which comes from sdev_runtime_resume() -> pm->runtime_resume
>> (=sd_resume()), which fails. That sd_resume() -> sd_start_stop_device()
>> fails as the disk is not attached. So we go into error state:
>>
>> $:more /sys/devices/pci0000:b4/0000:b4:04.0/host3/port-3:0/end_device-3:0/target3:0:0/3:0:0:0/power/runtime_status
>> error
>>
>> Removing commit e27829dc92e5 ("scsi: serialize ->rescan against ->remove")
>> solves this issue for me, but that is there for a reason.
>>
>> Any suggestion on how to fix this deadlock?
> 
> This is indeed a tricky question.  It seems like we should allow a 
> runtime resume to succeed if the only reason it failed was that the 
> device has been removed.
> 
> More generally, perhaps we should always consider that a runtime 
> resume succeeds.  Any remaining problems will be dealt with by the 
> device's driver and subsystem once the device is marked as 
> runtime-active again.
> 
> Suppose you try changing blk_post_runtime_resume() so that it always 
> calls blk_set_runtime_active() regardless of the value of err.  Does 
> that fix the problem?
> 
> And more importantly, will it cause any other problems...?

That would cause trouble for the UFS driver and other drivers for which
runtime resume can fail due to e.g. the link between host and device
being in a bad state.

How about checking the SCSI device state inside scsi_rescan_device() and
skipping the rescan if the SCSI device state is SDEV_CANCEL or SDEV_DEL?

Adding such a check inside __scsi_execute() would break sd_remove() and
sd_shutdown() since both use __scsi_execute() to submit a SYNCHRONIZE
CACHE command to the device.

Bart.

  reply	other threads:[~2021-07-04 23:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02 17:03 SCSI layer RPM deadlock debug suggestion John Garry
2021-07-02 20:31 ` Alan Stern
2021-07-04 23:45   ` Bart Van Assche [this message]
2021-07-05 12:00     ` John Garry
2021-07-05 13:17       ` Alan Stern
2021-07-05 13:20         ` Hannes Reinecke
2021-07-07 15:08           ` John Garry
2021-07-14 16:10             ` Alan Stern
2021-07-14 16:48               ` John Garry
2021-07-14 17:10                 ` Alan Stern
2021-07-14 17:41                   ` John Garry
2021-09-28 14:05                 ` Alan Stern
2021-09-28 14:13                   ` John Garry

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=ec4a3038-34b0-084f-a1bd-039827465dd1@acm.org \
    --to=bvanassche@acm.org \
    --cc=chenxiang66@hisilicon.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=jejb@linux.ibm.com \
    --cc=john.garry@huawei.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    --cc=xiejianqin@hisilicon.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.