Fix the error path in ufshcd_async_scan()
Subsystems (3)
Bart Van Assche
reviewercover Fix the error path in ufshcd_async_scan()
Hi Martin,
This patch series fixes a kernel crash triggered by the error path of ufshcd_async_scan(). Please consider this patch series for the next merge window.
Thanks,
Bart.
Bart Van Assche (2):
scsi: ufs: Simplify power management during async scan
scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
drivers/ufs/core/ufshcd.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
Bart Van Assche
reviewerPATCH 1/2 scsi: ufs: Simplify power management during async scan
ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().
--- drivers/ufs/core/ufshcd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +3 -4
@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)ufs_bsg_probe (hba);scsi_scan_host (hba->host); -pm_runtime_put_sync (hba->dev); out:return ret;
@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)/* Probe and add UFS logical units */ ret =ufshcd_add_lus (hba); + out: +pm_runtime_put_sync (hba->dev);/* * If we failed to initialize the device or the device is not * present, turn off the power/clocks etc. */ -if (ret) { -pm_runtime_put_sync (hba->dev); +if (ret)ufshcd_hba_exit (hba); - } }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan
Quoted 33 lines · Bart Van Assche
ufshcd_init()callspm_runtime_get_sync()before it callsasync_schedule().ufshcd_async_scan()callspm_runtime_put_sync()directly or indirectly fromufshcd_add_lus(). Simplifyufshcd_async_scan()by always callingpm_runtime_put_sync()fromufshcd_async_scan().Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/ufs/core/ufshcd.c +2
-1@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)ufs_bsg_probe (hba);scsi_scan_host (hba->host); -pm_runtime_put_sync (hba->dev); out:return ret;@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)/* Probe and add UFS logical units */ ret =ufshcd_add_lus (hba); + out: +pm_runtime_put_sync (hba->dev);/* * If we failed to initialize the device or the device is not
drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, async_cookie_t cookie) · line 8993
Quoted 10 lines
drivers/ufs/core/ufshcd.c +1
-3* present, turn off the power/clocks etc. */ -if (ret) { -pm_runtime_put_sync (hba->dev); +if (ret)ufshcd_hba_exit (hba); - } }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan
In reply to Bart Van AsscheQuoted 7 lines · Bart Van Assche
ufshcd_init()callspm_runtime_get_sync()before it callsasync_schedule().ufshcd_async_scan()callspm_runtime_put_sync()directly or indirectly fromufshcd_add_lus(). Simplifyufshcd_async_scan()by always callingpm_runtime_put_sync()fromufshcd_async_scan().
No fixes tag?
Quoted 1 line
Signed-off-by Bart Van Assche <[email protected]>
- Mani
Quoted 35 lines
--- drivers/ufs/core/ufshcd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/ufs/core/ufshcd.c +3
-4@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)ufs_bsg_probe (hba);scsi_scan_host (hba->host); -pm_runtime_put_sync (hba->dev); out:return ret;@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)/* Probe and add UFS logical units */ ret =ufshcd_add_lus (hba); + out: +pm_runtime_put_sync (hba->dev);/* * If we failed to initialize the device or the device is not * present, turn off the power/clocks etc. */ -if (ret) { -pm_runtime_put_sync (hba->dev); +if (ret)ufshcd_hba_exit (hba); - } }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Bart Van Assche
reviewerRe: [PATCH 1/2] scsi: ufs: Simplify power management during async scan
Quoted 10 lines · Manivannan Sadhasivam
Quoted 7 lines · Bart Van Assche
ufshcd_init()callspm_runtime_get_sync()before it callsasync_schedule().ufshcd_async_scan()callspm_runtime_put_sync()directly or indirectly fromufshcd_add_lus(). Simplifyufshcd_async_scan()by always callingpm_runtime_put_sync()fromufshcd_async_scan().No fixes tag?
There is no Fixes: tag because this patch does not change the behavior of the UFS driver. The Cc: stable tag is present because the next patch in this series has a Fixes: tag and depends on this patch.
Thanks,
Bart.
Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 6 lines · Bart Van Assche
ufshcd_init()callspm_runtime_get_sync()before it callsasync_schedule().ufshcd_async_scan()callspm_runtime_put_sync()directly or indirectly fromufshcd_add_lus(). Simplifyufshcd_async_scan()by always callingpm_runtime_put_sync()fromufshcd_async_scan().
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
No fixes tag?
There is no Fixes: tag because this patch does not change the behavior of the UFS driver. The Cc: stable tag is present because the next patch in this series has a Fixes: tag and depends on this patch.
Ok.
- Mani
Quoted 3 lines
Thanks,
Bart.
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Bart Van Assche
reviewerPATCH 2/2 scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
In reply to Bart Van AsscheCalling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.
--- drivers/ufs/core/ufshcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +2 -5
@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) out:pm_runtime_put_sync (hba->dev); -/* -* If we failed to initialize the device or the device is not -* present, turn off the power/clocks etc. -*/ +if (ret) -ufshcd_hba_exit (hba); +dev_err (hba->dev,"%s failed: %d\n" , __func__, ret); }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
Quoted 20 lines · Bart Van Assche
Calling
ufshcd_hba_exit()from a function that is called asynchronously fromufshcd_init()is wrong because this triggers multiple race conditions. Instead of callingufshcd_hba_exit(), log an error message.Reported-by Daniel Mentz <[email protected]>Fixes 1d337ec2f35e ("ufs: improve init sequence")Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/ufs/core/ufshcd.c +0
-1@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) out:pm_runtime_put_sync (hba->dev); -/*
drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, async_cookie_t cookie) · line 8990
Quoted 10 lines
drivers/ufs/core/ufshcd.c +2
-4-* If we failed to initialize the device or the device is not -* present, turn off the power/clocks etc. -*/ +if (ret) -ufshcd_hba_exit (hba); +dev_err (hba->dev,"%s failed: %d\n" , __func__, ret); }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
In reply to Bart Van AsscheQuoted 4 lines · Bart Van Assche
Calling
ufshcd_hba_exit()from a function that is called asynchronously fromufshcd_init()is wrong because this triggers multiple race conditions. Instead of callingufshcd_hba_exit(), log an error message.
This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.
Quoted 2 lines
Reported-by Daniel Mentz <[email protected]>Fixes 1d337ec2f35e ("ufs: improve init sequence")
No need to backport this patch?
Quoted 1 line
Signed-off-by Bart Van Assche <[email protected]>
- Mani
Quoted 23 lines
--- drivers/ufs/core/ufshcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/ufs/core/ufshcd.c +2
-5@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) out:pm_runtime_put_sync (hba->dev); -/* -* If we failed to initialize the device or the device is not -* present, turn off the power/clocks etc. -*/ +if (ret) -ufshcd_hba_exit (hba); +dev_err (hba->dev,"%s failed: %d\n" , __func__, ret); }static enum scsi_timeout_action ufshcd_eh_timed_out (struct scsi_cmnd *scmd)
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Bart Van Assche
reviewerRe: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
Quoted 7 lines · Manivannan Sadhasivam
Quoted 3 lines · Bart Van Assche
Calling
ufshcd_hba_exit()from a function that is called asynchronously fromufshcd_init()is wrong because this triggers multiple race conditions. Instead of callingufshcd_hba_exit(), log an error message.This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.
I have never seen ufshcd_async_scan() fail other than during hardware bringup. Has anyone else ever observed a ufshcd_async_scan() failure?
Quoted 4 lines
Quoted 2 lines
Reported-by Daniel Mentz <[email protected]>Fixes 1d337ec2f35e ("ufs: improve init sequence")No need to backport this patch?
Isn't the "Fixes:" tag sufficient? I don't think that it it necessary to add a "Cc: stable" tag if a "Fixes:" tag is present.
Thanks,
Bart.
Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()
Quoted 12 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 3 lines · Bart Van Assche
Calling
ufshcd_hba_exit()from a function that is called asynchronously fromufshcd_init()is wrong because this triggers multiple race conditions. Instead of callingufshcd_hba_exit(), log an error message.This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.
I have never seen
ufshcd_async_scan()fail other than during hardware bringup. Has anyone else ever observed aufshcd_async_scan()failure?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Reported-by Daniel Mentz <[email protected]>Fixes 1d337ec2f35e ("ufs: improve init sequence")No need to backport this patch?
Isn't the "Fixes:" tag sufficient? I don't think that it it necessary to add a "Cc: stable" tag if a "Fixes:" tag is present.
No. You need to explicitly CC stable list, if you want the commit to be backported to stable releases. Even though the stable maintainers backport the commits with Fixes tag, it is always strongly advised to explictly CC stable list.
Here is an excerpt from Documentation/process/stable-kernel-rules.rst:
"There are three options to submit a change to -stable trees:
1. Add a 'stable tag' to the description of a patch you then submit for mainline inclusion.
2. Ask the stable team to pick up a patch already mainlined.
3. Submit a patch to the stable team that is equivalent to a change already mainlined.
The sections below describe each of the options in more detail.
:ref:option_1 is **strongly** preferred, it is the easiest and most common."
- Mani
Quoted 3 lines
Thanks,
Bart.
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Martin K. Petersen
AppliedBart,
Quoted 3 lines
This patch series fixes a kernel crash triggered by the error path of
ufshcd_async_scan(). Please consider this patch series for the next merge window.
Applied to 6.8/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering