scsi: ufs: Bug fixes for ufs core and platform drivers
Subsystems (12)
cover scsi: ufs: Bug fixes for ufs core and platform drivers
Hi,
This series has several bug fixes that I encountered when the ufs-qcom driver was removed and inserted back. But the fixes are applicable to other platform glue drivers as well.
This series is tested on Qcom RB5 development board based on SM8250 SoC.
---
Manivannan Sadhasivam (5):
scsi: ufs: core: Cancel RTC work during ufshcd_remove()
scsi: ufs: qcom: Only free platform MSIs when ESI is enabled
scsi: ufs: pltfrm: Disable runtime PM during removal of glue drivers
scsi: ufs: pltfrm: Drop PM runtime reference count after ufshcd_remove()
scsi: ufs: pltfrm: Dellocate HBA during ufshcd_pltfrm_remove()
drivers/ufs/core/ufshcd.c | 1 + drivers/ufs/host/cdns-pltfrm.c | 4 +--- drivers/ufs/host/tc-dwc-g210-pltfrm.c | 5 +---- drivers/ufs/host/ufs-exynos.c | 3 +-- drivers/ufs/host/ufs-hisi.c | 4 +--- drivers/ufs/host/ufs-mediatek.c | 5 +---- drivers/ufs/host/ufs-qcom.c | 7 ++++--- drivers/ufs/host/ufs-renesas.c | 4 +--- drivers/ufs/host/ufs-sprd.c | 5 +---- drivers/ufs/host/ufshcd-pltfrm.c | 16 ++++++++++++++++ drivers/ufs/host/ufshcd-pltfrm.h | 1 + 11 files changed, 29 insertions(+), 26 deletions(-)
---
base-commit: 59b723cd2adbac2a34fc8e12c74ae26ae45bf230
change-id: 20241111-ufs_bug_fix-6d17f39afaa4
Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>
PATCH 1/5 scsi: ufs: core: Cancel RTC work during ufshcd_remove()
Currently, RTC work is only cancelled during __ufshcd_wl_suspend(). When ufshcd is removed in ufshcd_remove(), RTC work is not cancelled. Due to this, any further trigger of the RTC work after ufshcd_remove() would result in a NULL pointer dereference as below:
Unable to handle kernel NULL pointer dereference at virtual address 00000000000002a4 Workqueue: events ufshcd_rtc_work Call trace: _raw_spin_lock_irqsave+0x34/0x8c pm_runtime_get_if_active+0x24/0xb4 ufshcd_rtc_work+0x124/0x19c process_scheduled_works+0x18c/0x2d8 worker_thread+0x144/0x280 kthread+0x11c/0x128 ret_from_fork+0x10/0x20
Since RTC work accesses the ufshcd internal structures, it should be cancelled when ufshcd is removed. So do that in ufshcd_remove(), as per the order in ufshcd_init().
--- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +1 -0
@@ -10225,6 +10225,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_hwmon_remove (hba);ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev); +cancel_delayed_work_sync (&hba->ufs_rtc_update_work);blk_mq_destroy_queue (hba->tmf_queue);blk_put_queue (hba->tmf_queue);blk_mq_free_tag_set (&hba->tmf_tag_set);
Signature · 1 line
2.25.1
Re: [PATCH 1/5] scsi: ufs: core: Cancel RTC work during ufshcd_remove()
Quoted 31 lines · On Mon, 2024-11-11 at 23:18 +0530, Manivannan Sadhasivam via B4 Relay wrote:
External email : Please do not click links or open attachments until you have verified the sender or the content.
From: Manivannan Sadhasivam <[email protected]>
Currently, RTC work is only cancelled during
__ufshcd_wl_suspend(). When
ufshcd is removed inufshcd_remove(), RTC work is not cancelled. Due to
this, any further trigger of the RTC work afterufshcd_remove()would result in a NULL pointer dereference as below:Unable to handle kernel NULL pointer dereference at virtual address 00000000000002a4 Workqueue: events ufshcd_rtc_work Call trace: _raw_spin_lock_irqsave+0x34/0x8c pm_runtime_get_if_active+0x24/0xb4 ufshcd_rtc_work+0x124/0x19c process_scheduled_works+0x18c/0x2d8 worker_thread+0x144/0x280 kthread+0x11c/0x128 ret_from_fork+0x10/0x20Since RTC work accesses the ufshcd internal structures, it should be cancelled
when ufshcd is removed. So do that inufshcd_remove(), as per the order inufshcd_init().
Quoted 9 lines
Cc [email protected] # 6.8Fixes 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")Signed-off-by Manivannan Sadhasivam <--- drivers/ufs/core/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
Re: [PATCH 1/5] scsi: ufs: core: Cancel RTC work during ufshcd_remove()
In reply to Manivannan SadhasivamPATCH 2/5 scsi: ufs: qcom: Only free platform MSIs when ESI is enabled
In reply to Manivannan SadhasivamOtherwise, it will result in a NULL pointer dereference as below:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 Call trace: mutex_lock+0xc/0x54 platform_device_msi_free_irqs_all+0x14/0x20 ufs_qcom_remove+0x34/0x48 [ufs_qcom] platform_remove+0x28/0x44 device_remove+0x4c/0x80 device_release_driver_internal+0xd8/0x178 driver_detach+0x50/0x9c bus_remove_driver+0x6c/0xbc driver_unregister+0x30/0x60 platform_driver_unregister+0x14/0x20 ufs_qcom_pltform_exit+0x18/0xb94 [ufs_qcom] __arm64_sys_delete_module+0x180/0x260 invoke_syscall+0x44/0x100 el0_svc_common.constprop.0+0xc0/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x34/0xdc el0t_64_sync_handler+0xc0/0xc4 el0t_64_sync+0x190/0x194
--- drivers/ufs/host/ufs-qcom.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ufs/host/ufs-qcom.c +3 -1
@@ -1843,10 +1843,12 @@ static int ufs_qcom_probe(struct platform_device *pdev)static void ufs_qcom_remove (struct platform_device *pdev) {struct ufs_hba *hba =platform_get_drvdata (pdev); +struct ufs_qcom_host *host =ufshcd_get_variant (hba);pm_runtime_get_sync (&(pdev)->dev);ufshcd_remove (hba); -platform_device_msi_free_irqs_all (hba->dev); +if (host->esi_enabled) +platform_device_msi_free_irqs_all (hba->dev); }static const struct of_device_id ufs_qcom_of_match[]__maybe_unused = {
Signature · 1 line
2.25.1
Re: [PATCH 2/5] scsi: ufs: qcom: Only free platform MSIs when ESI is enabled
Quoted 24 lines · On Mon, 2024-11-11 at 23:18 +0530, Manivannan Sadhasivam via B4 Relay wrote:
Otherwise, it will result in a NULL pointer dereference as below:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 Call trace: mutex_lock+0xc/0x54 platform_device_msi_free_irqs_all+0x14/0x20 ufs_qcom_remove+0x34/0x48 [ufs_qcom] platform_remove+0x28/0x44 device_remove+0x4c/0x80 device_release_driver_internal+0xd8/0x178 driver_detach+0x50/0x9c bus_remove_driver+0x6c/0xbc driver_unregister+0x30/0x60 platform_driver_unregister+0x14/0x20 ufs_qcom_pltform_exit+0x18/0xb94 [ufs_qcom] __arm64_sys_delete_module+0x180/0x260 invoke_syscall+0x44/0x100 el0_svc_common.constprop.0+0xc0/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x34/0xdc el0t_64_sync_handler+0xc0/0xc4 el0t_64_sync+0x190/0x194
Quoted 5 lines
Cc [email protected] # 6.3Fixes 519b6274a777 ("scsi: ufs: qcom: Add MCQ ESI config vendorspecific ops")
Signed-off-by: Manivannan Sadhasivam
<[email protected]>
PATCH 3/5 scsi: ufs: pltfrm: Disable runtime PM during removal of glue drivers
In reply to Manivannan SadhasivamWhen the UFSHCD platform glue drivers are removed, runtime PM should be disabled using pm_runtime_disable() to balance the enablement done in ufshcd_pltfrm_init(). This is also reported by PM core when the glue driver is removed and inserted again:
ufshcd-qcom 1d84000.ufshc: Unbalanced pm_runtime_enable!
So disable runtime PM using a new helper API ufshcd_pltfrm_remove(), that also takes care of removing ufshcd. This helper should be called during the remove() stage of glue drivers.
--- drivers/ufs/host/cdns-pltfrm.c | 4 +--- drivers/ufs/host/tc-dwc-g210-pltfrm.c | 4 +--- drivers/ufs/host/ufs-exynos.c | 2 +- drivers/ufs/host/ufs-hisi.c | 4 +--- drivers/ufs/host/ufs-mediatek.c | 4 +--- drivers/ufs/host/ufs-qcom.c | 2 +- drivers/ufs/host/ufs-renesas.c | 4 +--- drivers/ufs/host/ufs-sprd.c | 4 +--- drivers/ufs/host/ufshcd-pltfrm.c | 13 +++++++++++++ drivers/ufs/host/ufshcd-pltfrm.h | 1 + 10 files changed, 22 insertions(+), 20 deletions(-)
drivers/ufs/host/cdns-pltfrm.c +1 -3
@@ -307,9 +307,7 @@ static int cdns_ufs_pltfrm_probe(struct platform_device *pdev)*/ static void cdns_ufs_pltfrm_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); - -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }static const struct dev_pm_ops cdns_ufs_dev_pm_ops = {
drivers/ufs/host/tc-dwc-g210-pltfrm.c +1 -3
@@ -76,10 +76,8 @@ static int tc_dwc_g210_pltfm_probe(struct platform_device *pdev)*/ static void tc_dwc_g210_pltfm_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); -pm_runtime_get_sync (&(pdev)->dev); -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }static const struct dev_pm_ops tc_dwc_g210_pltfm_pm_ops = {
drivers/ufs/host/ufs-exynos.c +1 -1
@@ -1961,7 +1961,7 @@ static void exynos_ufs_remove(struct platform_device *pdev)struct exynos_ufs *ufs =ufshcd_get_variant (hba);pm_runtime_get_sync (&(pdev)->dev); -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev);phy_power_off (ufs->phy);phy_exit (ufs->phy);
drivers/ufs/host/ufs-hisi.c +1 -3
@@ -576,9 +576,7 @@ static int ufs_hisi_probe(struct platform_device *pdev)static void ufs_hisi_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); - -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }static const struct dev_pm_ops ufs_hisi_pm_ops = {
drivers/ufs/host/ufs-mediatek.c +1 -3
@@ -1869,10 +1869,8 @@ static int ufs_mtk_probe(struct platform_device *pdev)*/ static void ufs_mtk_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); -pm_runtime_get_sync (&(pdev)->dev); -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }#ifdef CONFIG_PM_SLEEP
drivers/ufs/host/ufs-qcom.c +1 -1
@@ -1846,7 +1846,7 @@ static void ufs_qcom_remove(struct platform_device *pdev)struct ufs_qcom_host *host =ufshcd_get_variant (hba);pm_runtime_get_sync (&(pdev)->dev); -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev);if (host->esi_enabled)platform_device_msi_free_irqs_all (hba->dev); }
drivers/ufs/host/ufs-renesas.c +1 -3
@@ -390,9 +390,7 @@ static int ufs_renesas_probe(struct platform_device *pdev)static void ufs_renesas_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); - -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }static struct platform_driver ufs_renesas_platform = {
drivers/ufs/host/ufs-sprd.c +1 -3
@@ -427,10 +427,8 @@ static int ufs_sprd_probe(struct platform_device *pdev)static void ufs_sprd_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); -pm_runtime_get_sync (&(pdev)->dev); -ufshcd_remove (hba); +ufshcd_pltfrm_remove (pdev); }static const struct dev_pm_ops ufs_sprd_pm_ops = {
drivers/ufs/host/ufshcd-pltfrm.c +13 -0
@@ -524,6 +524,19 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, }EXPORT_SYMBOL_GPL (ufshcd_pltfrm_init); +/** +* ufshcd_pltfrm_remove - Remove ufshcd platform +* @pdev: pointer to Platform device handle +*/ +void ufshcd_pltfrm_remove (struct platform_device *pdev) +{ +struct ufs_hba *hba =platform_get_drvdata (pdev); + +ufshcd_remove (hba); +pm_runtime_disable (&pdev->dev); +} +EXPORT_SYMBOL_GPL (ufshcd_pltfrm_remove); +MODULE_AUTHOR ("Santosh Yaragnavi <[email protected]>" );MODULE_AUTHOR ("Vinayak Holikatti <[email protected]>" );MODULE_DESCRIPTION ("UFS host controller Platform bus based glue driver" );
drivers/ufs/host/ufshcd-pltfrm.h +1 -0
@@ -31,6 +31,7 @@ int ufshcd_negotiate_pwr_params(const struct ufs_host_params *host_params,void ufshcd_init_host_params (struct ufs_host_params *host_params);int ufshcd_pltfrm_init (struct platform_device *pdev,const struct ufs_hba_variant_ops *vops); +void ufshcd_pltfrm_remove (struct platform_device *pdev);int ufshcd_populate_vreg (struct device *dev,const char *name,struct ufs_vreg **out_vreg,bool skip_current);
Signature · 1 line
2.25.1
Re: [PATCH 3/5] scsi: ufs: pltfrm: Disable runtime PM during removal of glue drivers
Quoted 26 lines · On Mon, 2024-11-11 at 23:18 +0530, Manivannan Sadhasivam via B4 Relay wrote:
External email : Please do not click links or open attachments until you have verified the sender or the content.
From: Manivannan Sadhasivam <[email protected]>
When the UFSHCD platform glue drivers are removed, runtime PM should be
disabled usingpm_runtime_disable()to balance the enablement done inufshcd_pltfrm_init(). This is also reported by PM core when the glue driver
is removed and inserted again:ufshcd-qcom 1d84000.ufshc: Unbalanced
pm_runtime_enable!So disable runtime PM using a new helper API
ufshcd_pltfrm_remove(), that
also takes care of removing ufshcd. This helper should be called during theremove()stage of glue drivers.Cc [email protected] # 3.12Fixes 62694735ca95 ("[SCSI] ufs: Add runtime PM support for UFS hostcontroller driver")
Signed-off-by: Manivannan Sadhasivam <
[email protected]>
Quoted 14 lines
--- drivers/ufs/host/cdns-pltfrm.c | 4 +--- drivers/ufs/host/tc-dwc-g210-pltfrm.c | 4 +--- drivers/ufs/host/ufs-exynos.c | 2 +- drivers/ufs/host/ufs-hisi.c | 4 +--- drivers/ufs/host/ufs-mediatek.c | 4 +--- drivers/ufs/host/ufs-qcom.c | 2 +- drivers/ufs/host/ufs-renesas.c | 4 +--- drivers/ufs/host/ufs-sprd.c | 4 +--- drivers/ufs/host/ufshcd-pltfrm.c | 13 +++++++++++++ drivers/ufs/host/ufshcd-pltfrm.h | 1 + 10 files changed, 22 insertions(+), 20 deletions(-)
Re: [PATCH 3/5] scsi: ufs: pltfrm: Disable runtime PM during removal of glue drivers
In reply to Manivannan SadhasivamPATCH 4/5 scsi: ufs: pltfrm: Drop PM runtime reference count after ufshcd_remove()
In reply to Manivannan SadhasivamDuring the remove stage of glue drivers, some of them are incrementing the reference count using pm_runtime_get_sync(), before removing the ufshcd using ufshcd_remove(). But they are not dropping that reference count after ufshcd_remove() to balance the refcount.
So drop the reference count by calling pm_runtime_put_noidle() after ufshcd_remove(). Since the behavior is applicable to all glue drivers, move the PM handling to ufshcd_pltfrm_remove().
--- drivers/ufs/host/tc-dwc-g210-pltfrm.c | 1 - drivers/ufs/host/ufs-exynos.c | 1 - drivers/ufs/host/ufs-mediatek.c | 1 - drivers/ufs/host/ufs-qcom.c | 1 - drivers/ufs/host/ufs-sprd.c | 1 - drivers/ufs/host/ufshcd-pltfrm.c | 2 ++ 6 files changed, 2 insertions(+), 5 deletions(-)
drivers/ufs/host/tc-dwc-g210-pltfrm.c +0 -1
@@ -76,7 +76,6 @@ static int tc_dwc_g210_pltfm_probe(struct platform_device *pdev)*/ static void tc_dwc_g210_pltfm_remove (struct platform_device *pdev) { -pm_runtime_get_sync (&(pdev)->dev);ufshcd_pltfrm_remove (pdev); }
drivers/ufs/host/ufs-exynos.c +0 -1
@@ -1960,7 +1960,6 @@ static void exynos_ufs_remove(struct platform_device *pdev)struct ufs_hba *hba =platform_get_drvdata (pdev);struct exynos_ufs *ufs =ufshcd_get_variant (hba); -pm_runtime_get_sync (&(pdev)->dev);ufshcd_pltfrm_remove (pdev);phy_power_off (ufs->phy);
drivers/ufs/host/ufs-mediatek.c +0 -1
@@ -1869,7 +1869,6 @@ static int ufs_mtk_probe(struct platform_device *pdev)*/ static void ufs_mtk_remove (struct platform_device *pdev) { -pm_runtime_get_sync (&(pdev)->dev);ufshcd_pltfrm_remove (pdev); }
drivers/ufs/host/ufs-qcom.c +0 -1
@@ -1845,7 +1845,6 @@ static void ufs_qcom_remove(struct platform_device *pdev)struct ufs_hba *hba =platform_get_drvdata (pdev);struct ufs_qcom_host *host =ufshcd_get_variant (hba); -pm_runtime_get_sync (&(pdev)->dev);ufshcd_pltfrm_remove (pdev);if (host->esi_enabled)platform_device_msi_free_irqs_all (hba->dev);
drivers/ufs/host/ufs-sprd.c +0 -1
@@ -427,7 +427,6 @@ static int ufs_sprd_probe(struct platform_device *pdev)static void ufs_sprd_remove (struct platform_device *pdev) { -pm_runtime_get_sync (&(pdev)->dev);ufshcd_pltfrm_remove (pdev); }
drivers/ufs/host/ufshcd-pltfrm.c +2 -0
@@ -532,8 +532,10 @@ void ufshcd_pltfrm_remove(struct platform_device *pdev) {struct ufs_hba *hba =platform_get_drvdata (pdev); +pm_runtime_get_sync (&pdev->dev);ufshcd_remove (hba);pm_runtime_disable (&pdev->dev); +pm_runtime_put_noidle (&pdev->dev); }EXPORT_SYMBOL_GPL (ufshcd_pltfrm_remove);
Signature · 1 line
2.25.1
Re: [PATCH 4/5] scsi: ufs: pltfrm: Drop PM runtime reference count after ufshcd_remove()
Quoted 24 lines · On Mon, 2024-11-11 at 23:18 +0530, Manivannan Sadhasivam via B4 Relay wrote:
External email : Please do not click links or open attachments until you have verified the sender or the content.
From: Manivannan Sadhasivam <[email protected]>
During the remove stage of glue drivers, some of them are incrementing the
reference count usingpm_runtime_get_sync(), before removing the ufshcd
usingufshcd_remove(). But they are not dropping that reference count afterufshcd_remove()to balance the refcount.So drop the reference count by calling
pm_runtime_put_noidle()afterufshcd_remove(). Since the behavior is applicable to all glue drivers, move
the PM handling toufshcd_pltfrm_remove().Cc [email protected] # 3.12Fixes 62694735ca95 ("[SCSI] ufs: Add runtime PM support for UFS hostcontroller driver")
Signed-off-by: Manivannan Sadhasivam <
[email protected]>
Quoted 10 lines
--- drivers/ufs/host/tc-dwc-g210-pltfrm.c | 1 - drivers/ufs/host/ufs-exynos.c | 1 - drivers/ufs/host/ufs-mediatek.c | 1 - drivers/ufs/host/ufs-qcom.c | 1 - drivers/ufs/host/ufs-sprd.c | 1 - drivers/ufs/host/ufshcd-pltfrm.c | 2 ++ 6 files changed, 2 insertions(+), 5 deletions(-)
Re: [PATCH 4/5] scsi: ufs: pltfrm: Drop PM runtime reference count after ufshcd_remove()
In reply to Manivannan SadhasivamPATCH 5/5 scsi: ufs: pltfrm: Dellocate HBA during ufshcd_pltfrm_remove()
In reply to Manivannan SadhasivamThis will ensure that the scsi host is cleaned up properly using scsi_host_dev_release(). Otherwise, it may lead to memory leaks.
--- drivers/ufs/host/ufshcd-pltfrm.c | 1 + 1 file changed, 1 insertion(+)
drivers/ufs/host/ufshcd-pltfrm.c +1 -0
@@ -534,6 +534,7 @@ void ufshcd_pltfrm_remove(struct platform_device *pdev)pm_runtime_get_sync (&pdev->dev);ufshcd_remove (hba); +ufshcd_dealloc_host (hba);pm_runtime_disable (&pdev->dev);pm_runtime_put_noidle (&pdev->dev); }
Signature · 1 line
2.25.1
Re: [PATCH 5/5] scsi: ufs: pltfrm: Dellocate HBA during ufshcd_pltfrm_remove()
Quoted 9 lines · On Mon, 2024-11-11 at 23:18 +0530, Manivannan Sadhasivam via B4 Relay wrote:
External email : Please do not click links or open attachments until you have verified the sender or the content.
From: Manivannan Sadhasivam <[email protected]>
This will ensure that the scsi host is cleaned up properly using
scsi_host_dev_release(). Otherwise, it may lead to memory leaks.
Quoted 10 lines
Cc [email protected] # 4.4Fixes 03b1781aa978 ("[SCSI] ufs: Add Platform glue driver forufshcd")
Signed-off-by: Manivannan Sadhasivam <
[email protected]>--- drivers/ufs/host/ufshcd-pltfrm.c | 1 + 1 file changed, 1 insertion(+)
Re: [PATCH 5/5] scsi: ufs: pltfrm: Dellocate HBA during ufshcd_pltfrm_remove()
In reply to Manivannan SadhasivamQuoted 3 lines · On 11/11/24 9:48 AM, Manivannan Sadhasivam via B4 Relay wrote:
This series has several bug fixes that I encountered when the ufs-qcom driver was removed and inserted back. But the fixes are applicable to other platform glue drivers as well.
For the entire series:
Martin K. Petersen
AppliedManivannan,
Quoted 6 lines
This series has several bug fixes that I encountered when the ufs-qcom driver was removed and inserted back. But the fixes are applicable to other platform glue drivers as well.
This series is tested on Qcom RB5 development board based on SM8250 SoC.
Applied to 6.13/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering