ufs: core: fix lockdep warning of clk_scaling_lock
Subsystems (3)
PATCH 1/1 ufs: core: fix lockdep warning of clk_scaling_lock
From: Peter Wang <[email protected]>
There have a lockdep warning like below in current flow. kworker/u16:0: Possible unsafe locking scenario:
kworker/u16:0: CPU0 CPU1 kworker/u16:0: ---- ----
kworker/u16:0: lock(&hba->clk_scaling_lock);
kworker/u16:0: lock(&hba->dev_cmd.lock);
kworker/u16:0: lock(&hba->clk_scaling_lock);
kworker/u16:0: lock(&hba->dev_cmd.lock);
kworker/u16:0:
Because ufshcd_wb_toggle -> ufshcd_query_flag -> ufshcd_exec_dev_cmd will get read lock of clk_scaling_lock, so ufshcd_devfreq_scale can release read lock before call ufshcd_wb_toggle.
This patch only release write lock of clk_scaling_lock before ufshcd_wb_toggle.
--- drivers/ufs/core/ufshcd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/ufs/core/ufshcd.c +11 -11
@@ -1249,12 +1249,10 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba)return ret; } -static void ufshcd_clock_scaling_unprepare (struct ufs_hba *hba,bool writelock) +static void ufshcd_clock_scaling_unprepare (struct ufs_hba *hba) { -if (writelock) -up_write (&hba->clk_scaling_lock); -else -up_read (&hba->clk_scaling_lock); +up_write (&hba->clk_scaling_lock); +ufshcd_scsi_unblock_requests (hba);ufshcd_release (hba); }
@@ -1271,7 +1269,7 @@ static void ufshcd_clock_scaling_unprepare(struct ufs_hba *hba, bool writelock)static int ufshcd_devfreq_scale (struct ufs_hba *hba,bool scale_up) {int ret =0 ; -bool is_writelock = true; +bool wb_toggle = false; ret =ufshcd_clock_scaling_prepare (hba);if (ret)
@@ -1300,13 +1298,15 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) } } -/* Enable Write Booster if we have scaled up else disable it */ -downgrade_write (&hba->clk_scaling_lock); - is_writelock = false; -ufshcd_wb_toggle (hba, scale_up); + wb_toggle = true; out_unprepare: -ufshcd_clock_scaling_unprepare (hba, is_writelock); +ufshcd_clock_scaling_unprepare (hba); + +/* Enable Write Booster if we have scaled up else disable it */ +if (wb_toggle) +ufshcd_wb_toggle (hba, scale_up); +return ret; }
Signature · 1 line
2.18.0
Bart Van Assche
reviewerQuoted 2 lines · On 7/22/22 02:53, [email protected] wrote:
This patch only release write lock of
clk_scaling_lockbeforeufshcd_wb_toggle.
The above is not clear to me. Please make the above more clear.
Additionally, patches must be signed before these can be merged upstream. Where is your Signed-off-by?
Quoted 6 lines
drivers/ufs/core/ufshcd.c +1
-4-/* Enable Write Booster if we have scaled up else disable it */ -downgrade_write (&hba->clk_scaling_lock); - is_writelock = false; -ufshcd_wb_toggle (hba, scale_up); + wb_toggle = true;
drivers/ufs/core/ufshcd.c static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) · line 1311
Quoted 10 lines
drivers/ufs/core/ufshcd.c +6
-1out_unprepare: -ufshcd_clock_scaling_unprepare (hba, is_writelock); +ufshcd_clock_scaling_unprepare (hba); + +/* Enable Write Booster if we have scaled up else disable it */ +if (wb_toggle) +ufshcd_wb_toggle (hba, scale_up); +return ret; }
The patch description should mention that this patch changes the ufshcd_wb_toggle() call: before this patch clk_scaling_lock was held in reader mode during the ufshcd_wb_toggle() call and with this patch applied clk_scaling_lock is not held while ufshcd_wb_toggle() is called. I'm missing an explanation of why this change is safe.
Thanks,
Bart.
Quoted 26 lines · Bart Van Assche
Quoted 2 lines · On 7/22/22 02:53, [email protected] wrote:
This patch only release write lock of
clk_scaling_lockbeforeufshcd_wb_toggle.The above is not clear to me. Please make the above more clear.
Additionally, patches must be signed before these can be merged upstream. Where is your Signed-off-by?
Quoted 13 lines
- /* Enable Write Booster if we have scaled up else disable it */ -
downgrade_write(&hba->clk_scaling_lock);
-is_writelock= false;
-ufshcd_wb_toggle(hba, scale_up);
+wb_toggle= true;
out_unprepare:
-ufshcd_clock_scaling_unprepare(hba, is_writelock);
+ufshcd_clock_scaling_unprepare(hba);drivers/ufs/core/ufshcd.c +5
-0+ + /* Enable Write Booster if we have scaled up else disable it */ + if (wb_toggle) + ufshcd_wb_toggle(hba, scale_up); +Quoted 2 lines
return ret;
}The patch description should mention that this patch changes the
ufshcd_wb_toggle()call: before this patchclk_scaling_lockwas held in reader mode during theufshcd_wb_toggle()call and with this patch appliedclk_scaling_lockis not held whileufshcd_wb_toggle()is called. I'm missing an explanation of why this change is safe.
Quoted 4 lines
Thanks,
Bart.
Hi Bart,
okay, I will make this path more clear and add Signed-off-by Thanks for review.
Peter