All of lore.kernel.org
 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>, Xiang Chen <chenxiang66@hisilicon.com>
Subject: [PATCH v2 14/15] scsi: libsas: Keep host active while processing events
Date: Mon, 20 Dec 2021 19:21:37 +0800	[thread overview]
Message-ID: <1639999298-244569-15-git-send-email-chenxiang66@hisilicon.com> (raw)
In-Reply-To: <1639999298-244569-1-git-send-email-chenxiang66@hisilicon.com>

From: Xiang Chen <chenxiang66@hisilicon.com>

Processing events such as PORTE_BROADCAST_RCVD may cause dependency issues
for runtime power management support.
Such a problem would be that handling a PORTE_BROADCAST_RCVD event requires
that the host is resumed to send SMP commands. However, in resuming the
host, the phyup events generated from re-enabling the phys are processed in
the same workqueue as the original PORTE_BROADCAST_RCVD event. As such, the
host will never finish resuming (as it waits for the phyup event 
processing), and then the PORTE_BROADCAST_RCVD event can't be processed 
as the SMP commands are blocked, and so we have a deadlock.
Solve this problem by ensuring that libsas keeps the host active until
completely finished phy or port events, such as PORTE_BYTES_DMAED. As such,
we don't have to worry about resuming the host for processing individual
SMP commands in this example.

Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Reviewed-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/libsas/sas_event.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/libsas/sas_event.c b/drivers/scsi/libsas/sas_event.c
index 626ef96b9348..3613b9b315bc 100644
--- a/drivers/scsi/libsas/sas_event.c
+++ b/drivers/scsi/libsas/sas_event.c
@@ -50,8 +50,10 @@ void sas_queue_deferred_work(struct sas_ha_struct *ha)
 	list_for_each_entry_safe(sw, _sw, &ha->defer_q, drain_node) {
 		list_del_init(&sw->drain_node);
 		ret = sas_queue_work(ha, sw);
-		if (ret != 1)
+		if (ret != 1) {
+			pm_runtime_put(ha->dev);
 			sas_free_event(to_asd_sas_event(&sw->work));
+		}
 	}
 	spin_unlock_irq(&ha->lock);
 }
@@ -126,16 +128,22 @@ void sas_enable_revalidation(struct sas_ha_struct *ha)
 static void sas_port_event_worker(struct work_struct *work)
 {
 	struct asd_sas_event *ev = to_asd_sas_event(work);
+	struct asd_sas_phy *phy = ev->phy;
+	struct sas_ha_struct *ha = phy->ha;
 
 	sas_port_event_fns[ev->event](work);
+	pm_runtime_put(ha->dev);
 	sas_free_event(ev);
 }
 
 static void sas_phy_event_worker(struct work_struct *work)
 {
 	struct asd_sas_event *ev = to_asd_sas_event(work);
+	struct asd_sas_phy *phy = ev->phy;
+	struct sas_ha_struct *ha = phy->ha;
 
 	sas_phy_event_fns[ev->event](work);
+	pm_runtime_put(ha->dev);
 	sas_free_event(ev);
 }
 
@@ -170,14 +178,19 @@ int sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event,
 	if (!ev)
 		return -ENOMEM;
 
+	/* Call pm_runtime_put() with pairs in sas_port_event_worker() */
+	pm_runtime_get_noresume(ha->dev);
+
 	INIT_SAS_EVENT(ev, sas_port_event_worker, phy, event);
 
 	if (sas_defer_event(phy, ev))
 		return 0;
 
 	ret = sas_queue_event(event, &ev->work, ha);
-	if (ret != 1)
+	if (ret != 1) {
+		pm_runtime_put(ha->dev);
 		sas_free_event(ev);
+	}
 
 	return ret;
 }
@@ -196,14 +209,19 @@ int sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event,
 	if (!ev)
 		return -ENOMEM;
 
+	/* Call pm_runtime_put() with pairs in sas_phy_event_worker() */
+	pm_runtime_get_noresume(ha->dev);
+
 	INIT_SAS_EVENT(ev, sas_phy_event_worker, phy, event);
 
 	if (sas_defer_event(phy, ev))
 		return 0;
 
 	ret = sas_queue_event(event, &ev->work, ha);
-	if (ret != 1)
+	if (ret != 1) {
+		pm_runtime_put(ha->dev);
 		sas_free_event(ev);
+	}
 
 	return ret;
 }
-- 
2.33.0


  parent reply	other threads:[~2021-12-20 11:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 11:21 [PATCH v2 00/15] Add runtime PM support for libsas chenxiang
2021-12-20 11:21 ` [PATCH v2 01/15] libsas: Don't always drain event workqueue for HA resume chenxiang
2021-12-20 11:21 ` [PATCH v2 02/15] Revert "scsi: hisi_sas: Filter out new PHY up events during suspend" chenxiang
2021-12-20 11:21 ` [PATCH v2 03/15] scsi/block PM: Always set request queue runtime active in blk_post_runtime_resume() chenxiang
2021-12-20 11:21 ` [PATCH v2 04/15] scsi: libsas: Add spin_lock/unlock() to protect asd_sas_port->phy_list chenxiang
2021-12-20 11:21 ` [PATCH v2 05/15] scsi: hisi_sas: Fix some issues related to asd_sas_port->phy_list chenxiang
2021-12-27 17:25   ` Nathan Chancellor
2021-12-28  2:03     ` chenxiang (M)
2022-01-04 10:02       ` John Garry
2022-01-04 11:38         ` chenxiang (M)
2021-12-20 11:21 ` [PATCH v2 06/15] scsi: mvsas: Add spin_lock/unlock() to protect asd_sas_port->phy_list chenxiang
2021-12-20 11:21 ` [PATCH v2 07/15] scsi: libsas: Insert PORTE_BROADCAST_RCVD event for resuming host chenxiang
2021-12-20 11:21 ` [PATCH v2 08/15] scsi: hisi_sas: Add more logs for runtime suspend/resume chenxiang
2021-12-20 11:21 ` [PATCH v2 09/15] scsi: libsas: Resume host while sending SMP IOs chenxiang
2021-12-20 11:21 ` [PATCH v2 10/15] scsi: libsas: Add flag SAS_HA_RESUMING chenxiang
2021-12-20 11:21 ` [PATCH v2 11/15] scsi: libsas: Refactor sas_queue_deferred_work() chenxiang
2021-12-20 11:21 ` [PATCH v2 12/15] scsi: libsas: Defer works of new phys during suspend chenxiang
2021-12-20 11:21 ` [PATCH v2 13/15] scsi: hisi_sas: Keep controller active between ISR of phyup and the event being processed chenxiang
2021-12-20 11:21 ` chenxiang [this message]
2021-12-20 11:21 ` [PATCH v2 15/15] scsi: hisi_sas: Use autosuspend for the host controller chenxiang
2021-12-23  4:39 ` [PATCH v2 00/15] Add runtime PM support for libsas Martin K. Petersen

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=1639999298-244569-15-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 \
    /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.