public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Lin Ming <ming.m.lin@intel.com>
To: linux-kernel@vger.kernel.org
Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-pm@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
	Jeff Garzik <jgarzik@pobox.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	James Bottomley <JBottomley@Parallels.com>,
	Tejun Heo <tj@kernel.org>, Huang Ying <ying.huang@intel.com>,
	Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH 1/3] scsi: fix potential dead lock for host runtime pm
Date: Wed,  2 Nov 2011 14:21:38 +0800	[thread overview]
Message-ID: <1320214900-2112-2-git-send-email-ming.m.lin@intel.com> (raw)
In-Reply-To: <1320214900-2112-1-git-send-email-ming.m.lin@intel.com>

In later patch hooks will be added to do ata port runtime pm through scsi layer.
libata schedules scsi EH to handle suspend, then dead lock happens
because scsi EH in turn waits for the ongoing suspend, as below.

<scsi host runtime suspend>
 scsi_autopm_put_host
   pm_runtime_put_sync
     <scsi_host runtime pm status updated to RPM_SUSPENDING>
     ......
       <call libata hook to do suspend>
         <wake up scsi EH to handle suspend>
         <wait for scsi EH ...>

<scsi EH wake up>
 scsi_error_handler
   <resume scsi host>
   scsi_autopm_get_host
     pm_runtime_get_sync
     .....
       <sleep to wait for the ongoing scsi host suspend>

This patch fixes the dead lock by checking if there is ongoing runtime PM request.
If there is ongoing runtime PM request, scsi_autopm_get_host_noresume is called to
increase the usage count, but don't resume the host.

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
 drivers/scsi/scsi_error.c |    4 +++-
 drivers/scsi/scsi_pm.c    |   11 +++++++++++
 drivers/scsi/scsi_priv.h  |    2 ++
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index a4b9cdb..d35d8f7 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -1804,7 +1804,9 @@ int scsi_error_handler(void *data)
 		 * what we need to do to get it up and online again (if we can).
 		 * If we fail, we end up taking the thing offline.
 		 */
-		if (scsi_autopm_get_host(shost) != 0) {
+		if (scsi_autopm_host_busy(shost))
+			scsi_autopm_get_host_noresume(shost);
+		else if (scsi_autopm_get_host(shost) != 0) {
 			SCSI_LOG_ERROR_RECOVERY(1,
 				printk(KERN_ERR "Error handler scsi_eh_%d "
 						"unable to autoresume\n",
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index d82a023a..1be6c5a 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -185,6 +185,17 @@ void scsi_autopm_put_host(struct Scsi_Host *shost)
 	pm_runtime_put_sync(&shost->shost_gendev);
 }
 
+bool scsi_autopm_host_busy(struct Scsi_Host *shost)
+{
+	return (shost->shost_gendev.power.runtime_status == RPM_RESUMING
+		|| shost->shost_gendev.power.runtime_status == RPM_SUSPENDING);
+}
+
+void scsi_autopm_get_host_noresume(struct Scsi_Host *shost)
+{
+	pm_runtime_get_noresume(&shost->shost_gendev);
+}
+
 #else
 
 #define scsi_runtime_suspend	NULL
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 2a58895..1750651 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -156,6 +156,8 @@ extern void scsi_autopm_get_target(struct scsi_target *);
 extern void scsi_autopm_put_target(struct scsi_target *);
 extern int scsi_autopm_get_host(struct Scsi_Host *);
 extern void scsi_autopm_put_host(struct Scsi_Host *);
+extern bool scsi_autopm_host_busy(struct Scsi_Host *shost);
+extern void scsi_autopm_get_host_noresume(struct Scsi_Host *);
 #else
 static inline void scsi_autopm_get_target(struct scsi_target *t) {}
 static inline void scsi_autopm_put_target(struct scsi_target *t) {}
-- 
1.7.2.5

  reply	other threads:[~2011-11-02  6:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02  6:21 [PATCH 0/3] ata port runtime power management support Lin Ming
2011-11-02  6:21 ` Lin Ming [this message]
2011-11-02 14:41   ` [PATCH 1/3] scsi: fix potential dead lock for host runtime pm Alan Stern
2011-11-02  6:21 ` [PATCH 2/3] scsi: add hooks for host runtime power management Lin Ming
2011-11-02 14:53   ` Alan Stern
2011-11-03 13:08     ` Lin Ming
2011-11-03 14:22       ` Alan Stern
2011-11-03 14:37         ` Lin Ming
2011-11-03 14:41           ` Tejun Heo
2011-11-03 15:39             ` Alan Stern
2011-11-03 15:51               ` Tejun Heo
2011-11-03 16:08                 ` Alan Stern
2011-11-02  6:21 ` [PATCH 3/3] ata: implement ata port runtime pm hooks Lin Ming
2011-11-02 15:17 ` [PATCH 0/3] ata port runtime power management support Tejun Heo
2011-11-03 14:21   ` Lin Ming
2011-11-03 14:30     ` Tejun Heo
2011-11-03 14:47       ` Lin Ming
2011-11-03 14:59         ` Tejun Heo

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=1320214900-2112-2-git-send-email-ming.m.lin@intel.com \
    --to=ming.m.lin@intel.com \
    --cc=JBottomley@Parallels.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=rui.zhang@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tj@kernel.org \
    --cc=ying.huang@intel.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