Skip to contentSkip to conversation

i2c: designware: amdisp: Fix resume-probe race condition issue

PATCH Applied Pratap Nirujogi 6 participants 6 messages Mar 20 – Mar 25

Subsystems (4)
lore
Share & tools
lore

Pratap Nirujogi

author maintainer
#0 lore raw

PATCH v2 1/1 i2c: designware: amdisp: Fix resume-probe race condition issue

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

Fixes d6263c468a761 ("i2c: amd-isp: Add ISP i2c-designware driver")

---
Changes v1 -> v2:

* Fixed resume-probe race condition issue
* Removed NULL check in runtime_resume
* Updated Fixes tag with appropriate commit
* Added Signed-off-by for Co-developed-by tag

 drivers/i2c/busses/i2c-designware-amdisp.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-amdisp.c +5 -6
index c48728ad9f6f2..9f0ec0fae6f23 100644
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/soc/amd/isp4_misc.h>
 
@@ -76,22 +77,20 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev)
 
 	device_enable_async_suspend(&pdev->dev);
 
-	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(&pdev->dev);
-
+	dev_pm_genpd_resume(&pdev->dev);
 	ret = i2c_dw_probe(isp_i2c_dev);
 	if (ret) {
 		dev_err_probe(&pdev->dev, ret, "i2c_dw_probe failed\n");
 		goto error_release_rpm;
 	}
-
-	pm_runtime_put_sync(&pdev->dev);
+	dev_pm_genpd_suspend(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
 
 	return 0;
 
 error_release_rpm:
 	amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev);
-	pm_runtime_put_sync(&pdev->dev);
 	return ret;
 }
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Pratap Nirujogi

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Quoted 5 lines

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

LGTM, assuming that genpd calls are okay,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Pratap Nirujogi
Quoted 17 lines · Pratap Nirujogi

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

Quoted 4 lines
Fixes d6263c468a761 ("i2c: amd-isp: Add ISP i2c-designware driver")
Quoted 50 lines

---
Changes v1 -> v2:

* Fixed resume-probe race condition issue
* Removed NULL check in runtime_resume
* Updated Fixes tag with appropriate commit
* Added Signed-off-by for Co-developed-by tag

  drivers/i2c/busses/i2c-designware-amdisp.c | 11 +++++------
  1 file changed, 5 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-amdisp.c +5 -6
index c48728ad9f6f2..9f0ec0fae6f23 100644
@@ -7,6 +7,7 @@
 
  #include <linux/module.h>
  #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
  #include <linux/pm_runtime.h>
  #include <linux/soc/amd/isp4_misc.h>
 
@@ -76,22 +77,20 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev)
 
  	device_enable_async_suspend(&pdev->dev);
 
-	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(&pdev->dev);
-
+	dev_pm_genpd_resume(&pdev->dev);
  	ret = i2c_dw_probe(isp_i2c_dev);
  	if (ret) {
  		dev_err_probe(&pdev->dev, ret, "i2c_dw_probe failed\n");
  		goto error_release_rpm;
  	}
-
-	pm_runtime_put_sync(&pdev->dev);
+	dev_pm_genpd_suspend(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
 
  	return 0;
 
  error_release_rpm:
  	amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev);
-	pm_runtime_put_sync(&pdev->dev);
  	return ret;
  }
 
maintainer Acked-by on v2 1/1
#3 lore raw
In reply to Pratap Nirujogi
Quoted 17 lines · Pratap Nirujogi

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

Quoted 4 lines
Fixes d6263c468a761 ("i2c: amd-isp: Add ISP i2c-designware driver")
maintainer Applied
#4 lore raw
In reply to Pratap Nirujogi

Hi Pratap,

Quoted 17 lines · Pratap Nirujogi

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

Quoted 4 lines
Fixes d6263c468a761 ("i2c: amd-isp: Add ISP i2c-designware driver")

merged to i2c/i2c-host-fixes.

Thanks,
Andi

#5 lore raw
Quoted 23 lines · Andi Shyti

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Hi Pratap,

Quoted 17 lines · Pratap Nirujogi

Identified resume-probe race condition in kernel v7.0 with the commit 38fa29b01a6a ("i2c: designware: Combine the init functions"),but this issue existed from the beginning though not detected.

The amdisp i2c device requires ISP to be in power-on state for probe to succeed. To meet this requirement, this device is added to genpd to control ISP power using runtime PM. The pm_runtime_get_sync() called before i2c_dw_probe() triggers PM resume, which powers on ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition and a NULL dereferencing issue in v7.0

Fix this race condition by using the genpd APIs directly during probe:
- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Set the device to suspended state with pm_runtime_set_suspended()
- Enable runtime PM only after the device is fully initialized

Quoted 7 lines
Quoted 4 lines
Fixes d6263c468a761 ("i2c: amd-isp: Add ISP i2c-designware driver")

merged to i2c/i2c-host-fixes.

Thanks Andi.

Quoted 2 lines

Thanks,
Andi