public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: "Petr Tesařík" <petr@tesarici.cz>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-ide@vger.kernel.org
Subject: Re: Thinkpad E595 system deadlock on resume from S3
Date: Wed, 4 Oct 2023 10:25:47 +0900	[thread overview]
Message-ID: <539ec93d-b4f4-1c36-632b-48b89537c9dd@kernel.org> (raw)
In-Reply-To: <20231003220744.07c4fa0a@meshulam.tesarici.cz>

On 10/4/23 05:07, Petr Tesařík wrote:
> I just want to confirm that my understanding of the issue is correct
> now. After applying the patch below, my laptop has just survived half a
> dozen suspend/resume cycles with autosuspend enabled for the SATA SSD
> disk. Without the patch, it usually freezes on first attempt.
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index a371b497035e..87000f89319e 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -4768,6 +4768,14 @@ void ata_scsi_dev_rescan(struct work_struct *work)
>  		ata_for_each_dev(dev, link, ENABLED) {
>  			struct scsi_device *sdev = dev->sdev;
>  
> +			/*
> +			 * If the queue accepts only PM, bail out.
> +			 */
> +			if (blk_queue_pm_only(sdev->request_queue)) {
> +				ret = -EAGAIN;
> +				goto unlock;
> +			}
> +
>  			/*
>  			 * If the port was suspended before this was scheduled,
>  			 * bail out.

This seems sensible to me: scsi_rescan_device() only checks that the device is
running, without checking that the device queue is also resumed. So the right
place for this check is scsi_rescan_device():

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 3db4d31a03a1..b05a55f498a2 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1627,12 +1627,13 @@ int scsi_rescan_device(struct scsi_device *sdev)
        device_lock(dev);

        /*
-        * Bail out if the device is not running. Otherwise, the rescan may
-        * block waiting for commands to be executed, with us holding the
-        * device lock. This can result in a potential deadlock in the power
-        * management core code when system resume is on-going.
+        * Bail out if the device or its queue are not running. Otherwise,
+        * the rescan may block waiting for commands to be executed, with us
+        * holding the device lock. This can result in a potential deadlock
+        * in the power management core code when system resume is on-going.
         */
-       if (sdev->sdev_state != SDEV_RUNNING) {
+       if (sdev->sdev_state != SDEV_RUNNING ||
+           blk_queue_pm_only(sdev->request_queue)) {
                ret = -EWOULDBLOCK;
                goto unlock;
        }

Can you try the above to confirm it works for you ? It should, as that is
essentially the same as you did.

-- 
Damien Le Moal
Western Digital Research


  reply	other threads:[~2023-10-04  1:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30 10:20 Thinkpad E595 system deadlock on resume from S3 Petr Tesařík
2023-10-03  9:31 ` Petr Tesařík
2023-10-03 10:15   ` Rafael J. Wysocki
2023-10-03 11:02     ` Petr Tesařík
2023-10-03 12:34       ` Rafael J. Wysocki
2023-10-03 12:40         ` Petr Tesařík
2023-10-03 12:48           ` Rafael J. Wysocki
2023-10-03 12:51             ` Petr Tesařík
2023-10-03 12:57               ` Rafael J. Wysocki
2023-10-03 15:18                 ` Petr Tesařík
2023-10-03 16:16                   ` Petr Tesařík
2023-10-03 16:48                   ` Rafael J. Wysocki
2023-10-03 17:19                     ` Petr Tesařík
2023-10-03 20:07                     ` Petr Tesařík
2023-10-04  1:25                       ` Damien Le Moal [this message]
2023-10-04  6:43                         ` Petr Tesařík
2023-10-04  7:38                           ` Damien Le Moal
2023-10-04  6:13                   ` Hannes Reinecke
2023-10-04  6:18                     ` Damien Le Moal
2023-10-04  6:42                       ` Petr Tesařík
2023-10-03 12:35       ` Petr Tesařík

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=539ec93d-b4f4-1c36-632b-48b89537c9dd@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=petr@tesarici.cz \
    --cc=rafael@kernel.org \
    /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