linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: chenxiang <chenxiang66@hisilicon.com>
To: <jejb@linux.ibm.com>, <martin.petersen@oracle.com>
Cc: <linux-scsi@vger.kernel.org>, <linuxarm@huawei.com>,
	<john.garry@huawei.com>, Alan Stern <stern@rowland.harvard.edu>,
	Xiang Chen <chenxiang66@hisilicon.com>
Subject: [PATCH 03/15] scsi/block PM: Always set request queue runtime active in blk_post_runtime_resume()
Date: Wed, 17 Nov 2021 10:44:56 +0800	[thread overview]
Message-ID: <1637117108-230103-4-git-send-email-chenxiang66@hisilicon.com> (raw)
In-Reply-To: <1637117108-230103-1-git-send-email-chenxiang66@hisilicon.com>

From: Alan Stern <stern@rowland.harvard.edu>

John Garry reported a deadlock that occurs when trying to access a
runtime-suspended SATA device.  For obscure reasons, the rescan
procedure causes the link to be hard-reset, which disconnects the
device.

The rescan tries to carry out a runtime resume when accessing the
device.  scsi_rescan_device() holds the SCSI device lock and won't
release it until it can put commands onto the device's block queue.
This can't happen until the queue is successfully runtime-resumed or
the device is unregistered.  But the runtime resume fails because the
device is disconnected, and __scsi_remove_device() can't do the
unregistration because it can't get the device lock.

The best way to resolve this deadlock appears to be to allow the block
queue to start running again even after an unsuccessful runtime
resume.  The idea is that the driver or the SCSI error handler will
need to be able to use the queue to resolve the runtime resume
failure.

This patch removes the err argument to blk_post_runtime_resume() and
makes the routine act as though the resume was successful always.
This fixes the deadlock.

Reported-and-tested-by: John Garry <john.garry@huawei.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Fixes: e27829dc92e5 ("scsi: serialize ->rescan against ->remove")
---
 block/blk-pm.c         | 22 +++++++---------------
 drivers/scsi/scsi_pm.c |  2 +-
 include/linux/blk-pm.h |  2 +-
 3 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/block/blk-pm.c b/block/blk-pm.c
index 17bd020268d4..2dad62cc1572 100644
--- a/block/blk-pm.c
+++ b/block/blk-pm.c
@@ -163,27 +163,19 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
 /**
  * blk_post_runtime_resume - Post runtime resume processing
  * @q: the queue of the device
- * @err: return value of the device's runtime_resume function
  *
  * Description:
- *    Update the queue's runtime status according to the return value of the
- *    device's runtime_resume function. If the resume was successful, call
- *    blk_set_runtime_active() to do the real work of restarting the queue.
+ *    For historical reasons, this routine merely calls blk_set_runtime_active()
+ *    to do the real work of restarting the queue.  It does this regardless of
+ *    whether the device's runtime-resume succeeded; even if it failed the
+ *    driver or error handler will need to communicate with the device.
  *
  *    This function should be called near the end of the device's
  *    runtime_resume callback.
  */
-void blk_post_runtime_resume(struct request_queue *q, int err)
+void blk_post_runtime_resume(struct request_queue *q)
 {
-	if (!q->dev)
-		return;
-	if (!err) {
-		blk_set_runtime_active(q);
-	} else {
-		spin_lock_irq(&q->queue_lock);
-		q->rpm_status = RPM_SUSPENDED;
-		spin_unlock_irq(&q->queue_lock);
-	}
+	blk_set_runtime_active(q);
 }
 EXPORT_SYMBOL(blk_post_runtime_resume);
 
@@ -201,7 +193,7 @@ EXPORT_SYMBOL(blk_post_runtime_resume);
  * runtime PM status and re-enable peeking requests from the queue. It
  * should be called before first request is added to the queue.
  *
- * This function is also called by blk_post_runtime_resume() for successful
+ * This function is also called by blk_post_runtime_resume() for
  * runtime resumes.  It does everything necessary to restart the queue.
  */
 void blk_set_runtime_active(struct request_queue *q)
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index b5a858c29488..f06ca9d2a597 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -181,7 +181,7 @@ static int sdev_runtime_resume(struct device *dev)
 	blk_pre_runtime_resume(sdev->request_queue);
 	if (pm && pm->runtime_resume)
 		err = pm->runtime_resume(dev);
-	blk_post_runtime_resume(sdev->request_queue, err);
+	blk_post_runtime_resume(sdev->request_queue);
 
 	return err;
 }
diff --git a/include/linux/blk-pm.h b/include/linux/blk-pm.h
index b80c65aba249..2580e05a8ab6 100644
--- a/include/linux/blk-pm.h
+++ b/include/linux/blk-pm.h
@@ -14,7 +14,7 @@ extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev);
 extern int blk_pre_runtime_suspend(struct request_queue *q);
 extern void blk_post_runtime_suspend(struct request_queue *q, int err);
 extern void blk_pre_runtime_resume(struct request_queue *q);
-extern void blk_post_runtime_resume(struct request_queue *q, int err);
+extern void blk_post_runtime_resume(struct request_queue *q);
 extern void blk_set_runtime_active(struct request_queue *q);
 #else
 static inline void blk_pm_runtime_init(struct request_queue *q,
-- 
2.33.0


  parent reply	other threads:[~2021-11-17  2:50 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17  2:44 [PATCH 00/15] Add runtime PM support for libsas chenxiang
2021-11-17  2:44 ` [PATCH 01/15] libsas: Don't always drain event workqueue for HA resume chenxiang
2021-11-17  4:14   ` Bart Van Assche
2021-11-17  5:06     ` Bart Van Assche
2021-11-17  2:44 ` [PATCH 02/15] Revert "scsi: hisi_sas: Filter out new PHY up events during suspend" chenxiang
2021-12-13 10:31   ` John Garry
2021-12-15  7:20     ` chenxiang (M)
2021-11-17  2:44 ` chenxiang [this message]
2021-11-17  4:58   ` [PATCH 03/15] scsi/block PM: Always set request queue runtime active in blk_post_runtime_resume() Bart Van Assche
2021-11-17  2:44 ` [PATCH 04/15] scsi: libsas: Add spin_lock/unlock() to protect asd_sas_port->phy_list chenxiang
2021-11-17  2:44 ` [PATCH 05/15] scsi: hisi_sas: Fix some issues related to asd_sas_port->phy_list chenxiang
2021-11-17  2:44 ` [PATCH 06/15] scsi: mvsas: Add spin_lock/unlock() to protect asd_sas_port->phy_list chenxiang
2021-11-17  2:45 ` [PATCH 07/15] scsi: libsas: Send event PORTE_BROADCAST_RCVD for valid ports chenxiang
2021-12-13 11:02   ` John Garry
2021-12-15  7:25     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 08/15] scsi: hisi_sas: Add more prink for runtime suspend/resume chenxiang
2021-12-13 10:34   ` John Garry
2021-12-15  7:26     ` chenxiang (M)
2021-12-13 10:35   ` John Garry
2021-12-15  7:26     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 09/15] scsi: libsas: Resume sas host before sending SMP IOs chenxiang
2021-12-13 11:12   ` John Garry
2021-12-15  8:00     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 10/15] scsi: libsas: Add a flag SAS_HA_RESUMING of sas_ha chenxiang
2021-12-13 11:17   ` John Garry
2021-12-15  7:34     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 11/15] scsi: libsas: Refactor out sas_queue_deferred_work() chenxiang
2021-12-13 11:20   ` John Garry
2021-12-15  7:59     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 12/15] scsi: libsas: Defer works of new phys during suspend chenxiang
2021-11-17  2:45 ` [PATCH 13/15] scsi: hisi_sas: Keep controller active between ISR of phyup and the event being processed chenxiang
2021-12-13 10:44   ` John Garry
2021-12-15  7:57     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 14/15] scsi: libsas: Keep sas host active until finished some work chenxiang
2021-12-14 12:34   ` John Garry
2021-12-15  7:46     ` chenxiang (M)
2021-11-17  2:45 ` [PATCH 15/15] scsi: hisi_sas: Use autosuspend for SAS controller chenxiang
2021-12-13 10:50   ` John Garry
2021-12-15  7:52     ` chenxiang (M)
2021-11-19  4:04 ` [PATCH 00/15] Add runtime PM support for libsas Martin K. Petersen
2021-11-23  6:01   ` chenxiang (M)
2021-12-14 11:52 ` John Garry
2021-12-15  7:56   ` chenxiang (M)

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=1637117108-230103-4-git-send-email-chenxiang66@hisilicon.com \
    --to=chenxiang66@hisilicon.com \
    --cc=jejb@linux.ibm.com \
    --cc=john.garry@huawei.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).