All of lore.kernel.org
 help / color / mirror / Atom feed
From: <peter.wang@mediatek.com>
To: <stanley.chu@mediatek.com>, <linux-scsi@vger.kernel.org>,
	<martin.petersen@oracle.com>, <avri.altman@wdc.com>,
	<alim.akhtar@samsung.com>, <jejb@linux.ibm.com>
Cc: <wsd_upstream@mediatek.com>, <linux-mediatek@lists.infradead.org>,
	<peter.wang@mediatek.com>, <chun-hung.wu@mediatek.com>,
	<alice.chao@mediatek.com>, <cc.chou@mediatek.com>,
	<chaotian.jing@mediatek.com>, <jiajie.hao@mediatek.com>,
	<powen.kao@mediatek.com>, <qilin.tan@mediatek.com>,
	<lin.gui@mediatek.com>, <mikebi@micron.com>, <beanhuo@micron.com>
Subject: [PATCH v1] scsi: ufs: fix rpm racing issue
Date: Thu, 21 Apr 2022 22:41:52 +0800	[thread overview]
Message-ID: <20220421144152.23888-1-peter.wang@mediatek.com> (raw)

From: Peter Wang <peter.wang@mediatek.com>

Device WLun may enter RPM_SUSPENDED and the consumer is RPM_ACTIVE.

The error state is
Device Wlun RPM: status:2, usage_count:0
Consumer: 0:0:0:49476 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:49456 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:0 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:1 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:2 Link: rpm_active:1, RPM: status:0, usage_count:0

Because rpm enable before rpm delay set, scsi_autopm_put_device
invoke by scsi_sysfs_add_sdev may cause consumer enter suspend immediately.
Thas will always set rpm_active to 1.
If driver_probe_device invoke pm_runtime_get_suppliers just befor
previous scsi_autopm_put_device, the rpm_active will change to 1
after pm_runtime_put_suppliers.
Set this delay to avoid scsi_autopm_put_device enter suspend immediately.

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3f9caafa91bf..1250792d16be 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -5024,10 +5024,14 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)
 	 * Block runtime-pm until all consumers are added.
 	 * Refer ufshcd_setup_links().
 	 */
-	if (is_device_wlun(sdev))
+	if (is_device_wlun(sdev)) {
 		pm_runtime_get_noresume(&sdev->sdev_gendev);
-	else if (ufshcd_is_rpm_autosuspend_allowed(hba))
+	} else if (ufshcd_is_rpm_autosuspend_allowed(hba)) {
 		sdev->rpm_autosuspend = 1;
+		pm_runtime_set_autosuspend_delay(&sdev->sdev_gendev,
+			RPM_AUTOSUSPEND_DELAY_MS);
+	}
+
 	/*
 	 * Do not print messages during runtime PM to avoid never-ending cycles
 	 * of messages written back to storage by user space causing runtime
-- 
2.18.0


WARNING: multiple messages have this Message-ID (diff)
From: <peter.wang@mediatek.com>
To: <stanley.chu@mediatek.com>, <linux-scsi@vger.kernel.org>,
	<martin.petersen@oracle.com>, <avri.altman@wdc.com>,
	<alim.akhtar@samsung.com>, <jejb@linux.ibm.com>
Cc: <wsd_upstream@mediatek.com>, <linux-mediatek@lists.infradead.org>,
	<peter.wang@mediatek.com>, <chun-hung.wu@mediatek.com>,
	<alice.chao@mediatek.com>, <cc.chou@mediatek.com>,
	<chaotian.jing@mediatek.com>, <jiajie.hao@mediatek.com>,
	<powen.kao@mediatek.com>, <qilin.tan@mediatek.com>,
	<lin.gui@mediatek.com>, <mikebi@micron.com>, <beanhuo@micron.com>
Subject: [PATCH v1] scsi: ufs: fix rpm racing issue
Date: Thu, 21 Apr 2022 22:41:52 +0800	[thread overview]
Message-ID: <20220421144152.23888-1-peter.wang@mediatek.com> (raw)

From: Peter Wang <peter.wang@mediatek.com>

Device WLun may enter RPM_SUSPENDED and the consumer is RPM_ACTIVE.

The error state is
Device Wlun RPM: status:2, usage_count:0
Consumer: 0:0:0:49476 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:49456 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:0 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:1 Link: rpm_active:1, RPM: status:2, usage_count:0
Consumer: 0:0:0:2 Link: rpm_active:1, RPM: status:0, usage_count:0

Because rpm enable before rpm delay set, scsi_autopm_put_device
invoke by scsi_sysfs_add_sdev may cause consumer enter suspend immediately.
Thas will always set rpm_active to 1.
If driver_probe_device invoke pm_runtime_get_suppliers just befor
previous scsi_autopm_put_device, the rpm_active will change to 1
after pm_runtime_put_suppliers.
Set this delay to avoid scsi_autopm_put_device enter suspend immediately.

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 drivers/scsi/ufs/ufshcd.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3f9caafa91bf..1250792d16be 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -5024,10 +5024,14 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)
 	 * Block runtime-pm until all consumers are added.
 	 * Refer ufshcd_setup_links().
 	 */
-	if (is_device_wlun(sdev))
+	if (is_device_wlun(sdev)) {
 		pm_runtime_get_noresume(&sdev->sdev_gendev);
-	else if (ufshcd_is_rpm_autosuspend_allowed(hba))
+	} else if (ufshcd_is_rpm_autosuspend_allowed(hba)) {
 		sdev->rpm_autosuspend = 1;
+		pm_runtime_set_autosuspend_delay(&sdev->sdev_gendev,
+			RPM_AUTOSUSPEND_DELAY_MS);
+	}
+
 	/*
 	 * Do not print messages during runtime PM to avoid never-ending cycles
 	 * of messages written back to storage by user space causing runtime
-- 
2.18.0


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

             reply	other threads:[~2022-04-21 14:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21 14:41 peter.wang [this message]
2022-04-21 14:41 ` [PATCH v1] scsi: ufs: fix rpm racing issue peter.wang
2022-04-25  8:35 ` Avri Altman
2022-04-25  8:35   ` Avri Altman
2022-04-26 12:16   ` Peter Wang

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=20220421144152.23888-1-peter.wang@mediatek.com \
    --to=peter.wang@mediatek.com \
    --cc=alice.chao@mediatek.com \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=cc.chou@mediatek.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=chun-hung.wu@mediatek.com \
    --cc=jejb@linux.ibm.com \
    --cc=jiajie.hao@mediatek.com \
    --cc=lin.gui@mediatek.com \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mikebi@micron.com \
    --cc=powen.kao@mediatek.com \
    --cc=qilin.tan@mediatek.com \
    --cc=stanley.chu@mediatek.com \
    --cc=wsd_upstream@mediatek.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.