mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: HOYOUNG SEO <hy50.seo@samsung.com>
To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	bvanassche@acm.org, mkp@kernel.org, martin.petersen@oracle.com,
	stanleyjhu@google.com, peter.wang@mediatek.com,
	alim.akhtar@samsung.com, kwangwon.min@samsung.com,
	kwmad.kim@samsung.com, cpgsproxy1@samsung.com,
	h10.kim@samsung.com
Cc: HOYOUNG SEO <hy50.seo@samsung.com>
Subject: [PATCH v10 3/4] scsi: ufs: core: Make ufshcd_wl_poweroff() behave like ufshcd_wl_suspend()
Date: Wed, 11 Nov 2026 17:18:33 +0900	[thread overview]
Message-ID: <603443293.161794387787869.JavaMail.epsvc@epcpadp2new> (raw)
In-Reply-To: <cover.1794384665.git.hy50.seo@samsung.com>

ufshcd_wl_poweroff(), the hibernation poweroff callback, calls
__ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM) directly and ignores the
result. Unlike ufshcd_wl_suspend() it:

 - does not take hba->host_sem. An error handler that runs in the
   meantime can reset the link concurrently with __ufshcd_wl_suspend().
   It also leaves host_sem unbalanced: if hibernation is aborted after
   ufshcd_wl_poweroff() has been called, ufshcd_wl_resume() is called as
   the .restore callback and releases host_sem, which was not acquired;
 - does not check pm_runtime_suspended(dev). __ufshcd_suspend_prepare()
   leaves the WLUN runtime suspended if ufshcd_rpm_ok_for_spm() is true,
   which is the case if rpm_lvl and spm_lvl are equal. Then
   __ufshcd_wl_suspend() triggers error recovery and returns -EBUSY;
 - does not set hba->is_sys_suspended, so ufshcd_err_handling_prepare()
   does not restore the clocks and regulators if the .restore callback
   fails;
 - ignores errors.

Call ufshcd_wl_system_suspend() with UFS_SHUTDOWN_PM from
ufshcd_wl_poweroff() to fix all of these, as suggested by Bart Van
Assche. host_sem is held until ufshcd_wl_resume() releases it if
hibernation is aborted, and released if the suspend fails. For
UFS_SHUTDOWN_PM, __ufshcd_wl_suspend() does not convert failures into
-EBUSY, so a positive SCSI or UIC status can be returned. A dev_pm_ops
callback has to return a negative error code, so convert it.

This changes the behavior of ufshcd_wl_poweroff(): an error is now
returned from the .poweroff callback, which aborts hibernation, instead
of being ignored, and a runtime suspended WLUN is left as it is like in
ufshcd_wl_suspend().

Do not use hba->shutting_down to stop the error handler: it makes
ufs_mtk_system_suspend(), which is also the .poweroff callback of the
MediaTek host controller, fail with -EBUSY, and nothing clears it when
hibernation is aborted.

Fixes: b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun")
Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: HOYOUNG SEO <hy50.seo@samsung.com>
---
 drivers/ufs/core/ufshcd.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 4825349e87fd..8aea99f5c364 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10729,6 +10729,9 @@ static int ufshcd_wl_system_suspend(struct device *dev, enum ufs_pm_op pm_op)
 	if (ret) {
 		dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__,  ret);
 		up(&hba->host_sem);
+		/* __ufshcd_wl_suspend() can return a positive status for UFS_SHUTDOWN_PM. */
+		if (ret > 0)
+			ret = -EBUSY;
 	}
 
 out:
@@ -11576,11 +11579,7 @@ EXPORT_SYMBOL_GPL(ufshcd_suspend_prepare);
 #ifdef CONFIG_PM_SLEEP
 static int ufshcd_wl_poweroff(struct device *dev)
 {
-	struct scsi_device *sdev = to_scsi_device(dev);
-	struct ufs_hba *hba = shost_priv(sdev->host);
-
-	__ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM);
-	return 0;
+	return ufshcd_wl_system_suspend(dev, UFS_SHUTDOWN_PM);
 }
 #endif
 
-- 
2.34.1



  parent reply	other threads:[~2026-11-11  9:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1794384665.git.hy50.seo@samsung.com>
     [not found] ` <CGME20261111082304epcas2p4887d72756d51a72b94729439d25dd3e8@epcas2p4.samsung.com>
2026-11-11  8:18   ` [PATCH v10 1/4] scsi: ufs: core: Clear saved errors in ufshcd_link_recovery() HOYOUNG SEO
     [not found] ` <CGME20261111082305epcas2p28dd4b104523c10c82457a29e7e89c56c@epcas2p2.samsung.com>
2026-11-11  8:18   ` [PATCH v10 2/4] scsi: ufs: core: Add a helper for the system suspend callbacks HOYOUNG SEO
     [not found] ` <CGME20261111082306epcas2p21456a0a7d81ed5328ec01f022b87ee32@epcas2p2.samsung.com>
2026-11-11  8:18   ` HOYOUNG SEO [this message]
     [not found] ` <CGME20261111082307epcas2p3b1376d94048de0aa228515860e892641@epcas2p3.samsung.com>
2026-11-11  8:18   ` [PATCH v10 4/4] scsi: ufs: core: Limit early link recovery in the error handler to runtime PM HOYOUNG SEO

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=603443293.161794387787869.JavaMail.epsvc@epcpadp2new \
    --to=hy50.seo@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=bvanassche@acm.org \
    --cc=cpgsproxy1@samsung.com \
    --cc=h10.kim@samsung.com \
    --cc=kwangwon.min@samsung.com \
    --cc=kwmad.kim@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mkp@kernel.org \
    --cc=peter.wang@mediatek.com \
    --cc=stanleyjhu@google.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

all inboxes | Powered by JetHome®