From: Bean Huo <huobean@gmail.com>
To: Bart Van Assche <bvanassche@acm.org>,
peter.wang@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,
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,
tun-yu.yu@mediatek.com, eddie.huang@mediatek.com,
naomi.chu@mediatek.com, chu.stanley@gmail.com,
beanhuo@micron.com, stable@vger.kernel.org
Subject: Re: [PATCH v1] ufs: core: fix deadlock when rtc update
Date: Mon, 15 Jul 2024 00:37:45 +0200 [thread overview]
Message-ID: <de8b34e3a4055a545de4f6ee4321f968ccbfa0aa.camel@gmail.com> (raw)
In-Reply-To: <d1d20f65-faa9-414f-b7fb-4b53794c0acb@acm.org>
On Fri, 2024-07-12 at 10:34 -0700, Bart Van Assche wrote:
> > - /* Update RTC only when there are no requests in progress
> > and UFSHCI is operational */
> > - if (!ufshcd_is_ufs_dev_busy(hba) && hba->ufshcd_state ==
> > UFSHCD_STATE_OPERATIONAL)
> > + /*
> > + * Update RTC only when
> > + * 1. there are no requests in progress
> > + * 2. UFSHCI is operational
> > + * 3. pm operation is not in progress
> > + */
> > + if (!ufshcd_is_ufs_dev_busy(hba) &&
> > + hba->ufshcd_state == UFSHCD_STATE_OPERATIONAL &&
> > + !hba->pm_op_in_progress)
> > ufshcd_update_rtc(hba);
> >
> > if (ufshcd_is_ufs_dev_active(hba) && hba-
> > >dev_info.rtc_update_period)
>
> The above seems racy to me. I don't think there is any mechanism that
> prevents that hba->pm_op_in_progress is set after it has been checked
> and before ufshcd_update_rtc() is called. Has it been considered to
> add
> an ufshcd_rpm_get_sync_nowait() call before the hba-
> >pm_op_in_progress
> check and a ufshcd_rpm_put_sync() call after the ufshcd_update_rtc()
> call?
>
> Thanks,
>
> Bart.
Bart,
do you want this:
diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-
priv.h
index ce36154ce963..2b74d6329b9d 100644
--- a/drivers/ufs/core/ufshcd-priv.h
+++ b/drivers/ufs/core/ufshcd-priv.h
@@ -311,6 +311,25 @@ static inline int ufshcd_update_ee_usr_mask(struct
ufs_hba *hba,
&hba->ee_drv_mask, set, clr);
}
+static inline int ufshcd_rpm_get_sync_nowait(struct ufs_hba *hba)
+{
+ int ret = 0;
+ struct device *dev = &hba->ufs_device_wlun->sdev_gendev;
+
+ pm_runtime_get_noresume(dev);
+
+ /* Check if the device is already active */
+ if (pm_runtime_active(dev))
+ return 0;
+
+ /* Attempt to resume the device without blocking */
+ ret = pm_request_resume(dev);
+ if (ret < 0)
+ pm_runtime_put_noidle(dev);
+
+ return ret;
+}
+
static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
{
return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev);
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index bea00e069e9a..1b7fc4ce9e5c 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8209,10 +8209,8 @@ static void ufshcd_update_rtc(struct ufs_hba
*hba)
*/
val = ts64.tv_sec - hba->dev_info.rtc_time_baseline;
- ufshcd_rpm_get_sync(hba);
err = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
QUERY_ATTR_IDN_SECONDS_PASSED,
0, 0, &val);
- ufshcd_rpm_put_sync(hba);
if (err)
dev_err(hba->dev, "%s: Failed to update rtc %d\n",
__func__, err);
@@ -8226,10 +8224,14 @@ static void ufshcd_rtc_work(struct work_struct
*work)
hba = container_of(to_delayed_work(work), struct ufs_hba,
ufs_rtc_update_work);
+ if (ufshcd_rpm_get_sync_nowait(hba))
+ goto out;
+
/* Update RTC only when there are no requests in progress and
UFSHCI is operational */
if (!ufshcd_is_ufs_dev_busy(hba) && hba->ufshcd_state ==
UFSHCD_STATE_OPERATIONAL)
ufshcd_update_rtc(hba);
-
+ ufshcd_rpm_put_sync(hba);
+out:
if (ufshcd_is_ufs_dev_active(hba) && hba-
>dev_info.rtc_update_period)
schedule_delayed_work(&hba->ufs_rtc_update_work,
msecs_to_jiffies(hba-
>dev_info.rtc_update_period));
(END)
or can we change cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
to cancel_delayed_work(&hba->ufs_rtc_update_work); ??
kind regards,
Bean
next prev parent reply other threads:[~2024-07-14 22:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 9:43 [PATCH v1] ufs: core: fix deadlock when rtc update peter.wang
2024-07-12 9:51 ` Bean Huo
2024-07-12 10:33 ` Avri Altman
2024-07-12 10:49 ` Bean Huo
2024-07-12 12:31 ` Avri Altman
2024-07-13 20:17 ` Bean Huo
2024-07-15 6:27 ` Peter Wang (王信友)
2024-07-12 17:34 ` Bart Van Assche
2024-07-14 22:37 ` Bean Huo [this message]
2024-07-15 6:31 ` Peter Wang (王信友)
2024-07-15 6:29 ` 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=de8b34e3a4055a545de4f6ee4321f968ccbfa0aa.camel@gmail.com \
--to=huobean@gmail.com \
--cc=alice.chao@mediatek.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=cc.chou@mediatek.com \
--cc=chaotian.jing@mediatek.com \
--cc=chu.stanley@gmail.com \
--cc=chun-hung.wu@mediatek.com \
--cc=eddie.huang@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=naomi.chu@mediatek.com \
--cc=peter.wang@mediatek.com \
--cc=powen.kao@mediatek.com \
--cc=qilin.tan@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=tun-yu.yu@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox