soc: qcom: ice: Fix race between qcom_ice_probe() and of_qcom_ice_get()
Subsystems (8)
v4 cover soc: qcom: ice: Fix race between qcom_ice_probe() and of_qcom_ice_get()
Hi,
This series fixes the race betwen qcom_ice_probe() and of_qcom_ice_get() but synchronizing the two APIs and properly propagating the error codes to clients.
Merge Strategy
==============
Due to dependency, all patches should go through Qcom SoC tree.
---
Changes in v4:
- For supporting multi-ice instances in a SoC, stored the err ptr in platform drvdata instead of in a global pointer.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Dropped the platform driver removal patch and used the ice_handle to pass error codes. This was done as I learned that we need to have the platform driver design going forward and also removing it introduces other issues.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added MODULE_* macros back
- Removed spurious platform_device_put()
- Added patches to remove NULL return
---
Manivannan Sadhasivam (5):
soc: qcom: ice: Fix race between qcom_ice_probe() and of_qcom_ice_get()
soc: qcom: ice: Return -ENODEV if the ICE platform device is not found
soc: qcom: ice: Return proper error codes from devm_of_qcom_ice_get() instead of NULL
mmc: sdhci-msm: Remove NULL check from devm_of_qcom_ice_get()
scsi: ufs: ufs-qcom: Remove NULL check from devm_of_qcom_ice_get()
drivers/mmc/host/sdhci-msm.c | 10 +++++----- drivers/soc/qcom/ice.c | 33 ++++++++++++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 10 +++++----- 3 files changed, 32 insertions(+), 21 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260210-qcom-ice-fix-d2a3a045b32d
Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>
PATCH v4 1/5 soc: qcom: ice: Fix race between qcom_ice_probe() and of_qcom_ice_get()
The current platform driver design causes probe ordering races with consumers (UFS, eMMC) due to ICE's dependency on SCM firmware calls. If ICE probe fails (missing ICE SCM or DT registers), devm_of_qcom_ice_get() loops with -EPROBE_DEFER, leaving consumers non-functional even when ICE should be gracefully disabled. devm_of_qcom_ice_get() doesn't know if the ICE driver probe has failed due to above reasons or it is waiting for the SCM driver.
Moreover, there is no devlink dependency between ICE and consumer drivers as 'qcom,ice' is not considered as a DT 'supplier'. So the consumer drivers have no idea of when the ICE driver is going to probe.
To address these issues, store the error pointer in the platform drvdata during probe in addition to the valid ice pointer and synchronize both qcom_ice_probe() and of_qcom_ice_get() using a mutex.
If the platform drvdata is NULL, then it implies that the driver is not probed yet, so return -EPROBE_DEFER. If it has any error pointer, return that error pointer directly.
Note that this change only fixes the standalone ICE DT node bindings and not the ones with 'ice' range embedded in the consumer nodes, where there is no issue.
--- drivers/soc/qcom/ice.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/soc/qcom/ice.c +17 -5
@@ -113,6 +113,8 @@ struct qcom_ice {u8 hwkm_version; }; +static DEFINE_MUTEX (ice_mutex); +static bool qcom_ice_check_supported (struct qcom_ice *ice) {u32 regval =qcom_ice_readl (ice,QCOM_ICE_REG_VERSION );
@@ -631,6 +633,8 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev)return qcom_ice_create (&pdev->dev, base); } +guard (mutex)(&ice_mutex); +/* * If the consumer node does not provider an 'ice' reg range * (legacy DT binding), then it must at least provide a phandle
@@ -648,11 +652,12 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev) } ice =platform_get_drvdata (pdev); -if (!ice) { -dev_err (dev,"Cannot get ice instance from %s\n" , -dev_name (&pdev->dev)); +if (IS_ERR_OR_NULL (ice)) {platform_device_put (pdev); -return ERR_PTR (-EPROBE_DEFER ); +if (!ice) +return ERR_PTR (-EPROBE_DEFER ); +else +return ice; } link =device_link_add (dev, &pdev->dev,DL_FLAG_AUTOREMOVE_SUPPLIER );
@@ -719,15 +724,22 @@ static int qcom_ice_probe(struct platform_device *pdev)struct qcom_ice *engine;void __iomem *base; +guard (mutex)(&ice_mutex); + base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (base)) {dev_warn (&pdev->dev,"ICE registers not found\n" ); +/* Store the error pointer for devm_of_qcom_ice_get() */ +platform_set_drvdata (pdev, base);return PTR_ERR (base); } engine =qcom_ice_create (&pdev->dev, base); -if (IS_ERR (engine)) +if (IS_ERR (engine)) { +/* Store the error pointer for devm_of_qcom_ice_get() */ +platform_set_drvdata (pdev, engine);return PTR_ERR (engine); + }platform_set_drvdata (pdev, engine);
Signature · 1 line
2.51.0
PATCH v4 2/5 soc: qcom: ice: Return -ENODEV if the ICE platform device is not found
In reply to Manivannan SadhasivamBy the time the consumer driver calls devm_of_qcom_ice_get(), all the platform devices for ICE nodes would've been created by of_platform_default_populate().
So for the absence of any platform device, -ENODEV should not returned, not -EPROBE_DEFER.
--- drivers/soc/qcom/ice.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/ice.c +1 -1
@@ -648,7 +648,7 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev) pdev =of_find_device_by_node (node);if (!pdev) {dev_err (dev,"Cannot find device node %s\n" , node->name); -return ERR_PTR (-EPROBE_DEFER ); +return ERR_PTR (-ENODEV ); } ice =platform_get_drvdata (pdev);
Signature · 1 line
2.51.0
PATCH v4 3/5 soc: qcom: ice: Return proper error codes from devm_of_qcom_ice_get() instead of NULL
In reply to Manivannan Sadhasivamdevm_of_qcom_ice_get() currently returns NULL if ICE SCM is not available or "qcom,ice" property is not found in DT. But this confuses the clients since NULL doesn't convey the reason for failure. So return proper error codes instead of NULL.
--- drivers/soc/qcom/ice.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/soc/qcom/ice.c +4 -5
@@ -561,7 +561,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,if (!qcom_scm_ice_available ()) {dev_warn (dev,"ICE SCM interface not found\n" ); -return NULL ; +return ERR_PTR (-EOPNOTSUPP ); } engine =devm_kzalloc (dev,sizeof (*engine),GFP_KERNEL );
@@ -643,7 +643,7 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev) struct device_node *node __free(device_node) = of_parse_phandle(dev->of_node,"qcom,ice" ,0 );if (!node) -return NULL ; +return ERR_PTR (-ENODEV ); pdev =of_find_device_by_node (node);if (!pdev) {
@@ -696,8 +696,7 @@ static void devm_of_qcom_ice_put(struct device *dev, void *res)* phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already * be created and so this function will return that instead. * -* Return: ICE pointer on success, NULL if there is no ICE data provided by the -* consumer or ERR_PTR() on error. +* Return: ICE pointer on success, ERR_PTR() on error. */ struct qcom_ice *devm_of_qcom_ice_get (struct device *dev) {
@@ -708,7 +707,7 @@ struct qcom_ice *devm_of_qcom_ice_get(struct device *dev)return ERR_PTR (-ENOMEM ); ice =of_qcom_ice_get (dev); -if (!IS_ERR_OR_NULL (ice)) { +if (!IS_ERR (ice)) { *dr = ice;devres_add (dev, dr); }else {
Signature · 1 line
2.51.0
Re: [PATCH v4 3/5] soc: qcom: ice: Return proper error codes from devm_of_qcom_ice_get() instead of NULL
Hey Mani,
Quoted 20 lines · On Mon, Mar 2, 2026 at 6:30 PM Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
devm_of_qcom_ice_get()currently returns NULL if ICE SCM is not available or "qcom,ice" property is not found in DT. But this confuses the clients since NULL doesn't convey the reason for failure. So return proper error codes instead of NULL.Reported-by Sumit Garg <[email protected]>Reviewed-by Konrad Dybcio <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>--- drivers/soc/qcom/ice.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/soc/qcom/ice.c +0
-0
drivers/soc/qcom/ice.c static struct qcom_ice *qcom_ice_create(struct device *dev, · line 565
Quoted 6 lines
drivers/soc/qcom/ice.c +1
-1@@ -561,7 +561,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,if (!qcom_scm_ice_available ()) {dev_warn (dev,"ICE SCM interface not found\n" ); -return NULL ; +return ERR_PTR (-EOPNOTSUPP ); }
With this patch-set on top of v7.0-rc2, I still see UFS probe failing when ICE isn't supported with OP-TEE as follows:
[ 5.401558] qcom-ice 1d88000.crypto: ICE SCM interface not found [ 5.419482] qcom-ice 1d88000.crypto: probe with driver qcom-ice failed with error -95 <snip> [ 18.662977] ufshcd-qcom 1d84000.ufshc: freq-table-hz property not specified [ 18.670193] ufshcd-qcom 1d84000.ufshc: ufshcd_populate_vreg: Unable to find vdd-hba-supply regulator, assuming enabled [ 18.737665] platform 1d84000.ufshc: deferred probe pending: ufshcd-qcom: ufshcd_pltfrm_init() failed [ 18.747141] platform 3370000.codec: deferred probe pending:
platform: wait for supplier /soc@0/pinctrl@33c0000/dmic23-data-state
Maybe it's the "qcom-ice" driver failure leading to this deferred probe problem again.
-Sumit
Quoted 35 lines
drivers/soc/qcom/ice.c +3
-5engine =devm_kzalloc (dev,sizeof (*engine),GFP_KERNEL );@@ -643,7 +643,7 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev) struct device_node *node __free(device_node) = of_parse_phandle(dev->of_node,"qcom,ice" ,0 );if (!node) -return NULL ; +return ERR_PTR (-ENODEV ); pdev =of_find_device_by_node (node);if (!pdev) {@@ -696,8 +696,7 @@ static void devm_of_qcom_ice_put(struct device *dev, void *res)* phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already * be created and so this function will return that instead. * -* Return: ICE pointer on success, NULL if there is no ICE data provided by the -* consumer or ERR_PTR() on error. +* Return: ICE pointer on success, ERR_PTR() on error. */ struct qcom_ice *devm_of_qcom_ice_get (struct device *dev) {@@ -708,7 +707,7 @@ struct qcom_ice *devm_of_qcom_ice_get(struct device *dev)return ERR_PTR (-ENOMEM ); ice =of_qcom_ice_get (dev); -if (!IS_ERR_OR_NULL (ice)) { +if (!IS_ERR (ice)) { *dr = ice;devres_add (dev, dr); }else { --2.51.0
Re: [PATCH v4 3/5] soc: qcom: ice: Return proper error codes from devm_of_qcom_ice_get() instead of NULL
Quoted 45 lines · Sumit Garg
Hey Mani,
Quoted 20 lines · On Mon, Mar 2, 2026 at 6:30 PM Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
devm_of_qcom_ice_get()currently returns NULL if ICE SCM is not available or "qcom,ice" property is not found in DT. But this confuses the clients since NULL doesn't convey the reason for failure. So return proper error codes instead of NULL.Reported-by Sumit Garg <[email protected]>Reviewed-by Konrad Dybcio <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>--- drivers/soc/qcom/ice.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/soc/qcom/ice.c +0
-0drivers/soc/qcom/ice.c static struct qcom_ice *qcom_ice_create(struct device *dev, · line 565
Quoted 6 lines
drivers/soc/qcom/ice.c +1
-1@@ -561,7 +561,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,if (!qcom_scm_ice_available ()) {dev_warn (dev,"ICE SCM interface not found\n" ); -return NULL ; +return ERR_PTR (-EOPNOTSUPP ); }With this patch-set on top of v7.0-rc2, I still see UFS probe failing when ICE isn't supported with OP-TEE as follows:
[ 5.401558] qcom-ice 1d88000.crypto: ICE SCM interface not found [ 5.419482] qcom-ice 1d88000.crypto: probe with driver qcom-ice failed with error -95 <snip> [ 18.662977] ufshcd-qcom 1d84000.ufshc: freq-table-hz property not specified [ 18.670193] ufshcd-qcom 1d84000.ufshc: ufshcd_populate_vreg: Unable to find vdd-hba-supply regulator, assuming enabled [ 18.737665] platform 1d84000.ufshc: deferred probe pending: ufshcd-qcom: ufshcd_pltfrm_init() failed [ 18.747141] platform 3370000.codec: deferred probe pending:
Quoted 5 lines
platform: wait for supplier /soc@0/pinctrl@33c0000/dmic23-data-state
Maybe it's the "qcom-ice" driver failure leading to this deferred probe problem again.
Following diff on top of your patchset allows the UFS driver to probe successfully without ICE support. I suppose just setting the drvdata should be sufficient.
drivers/soc/qcom/ice.c +0 -7
@@ -734,12 +734,6 @@ static int qcom_ice_probe(struct platform_device *pdev) } engine =qcom_ice_create (&pdev->dev, base); -if (IS_ERR (engine)) { -/* Store the error pointer for devm_of_qcom_ice_get() */ -platform_set_drvdata (pdev, engine); -return PTR_ERR (engine); - } -platform_set_drvdata (pdev, engine); -Sumit
Quoted 36 lines
Quoted 36 lines
drivers/soc/qcom/ice.c +3
-5engine =devm_kzalloc (dev,sizeof (*engine),GFP_KERNEL );@@ -643,7 +643,7 @@ static struct qcom_ice *of_qcom_ice_get(struct device *dev) struct device_node *node __free(device_node) = of_parse_phandle(dev->of_node,"qcom,ice" ,0 );if (!node) -return NULL ; +return ERR_PTR (-ENODEV ); pdev =of_find_device_by_node (node);if (!pdev) {@@ -696,8 +696,7 @@ static void devm_of_qcom_ice_put(struct device *dev, void *res)* phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already * be created and so this function will return that instead. * -* Return: ICE pointer on success, NULL if there is no ICE data provided by the -* consumer or ERR_PTR() on error. +* Return: ICE pointer on success, ERR_PTR() on error. */ struct qcom_ice *devm_of_qcom_ice_get (struct device *dev) {@@ -708,7 +707,7 @@ struct qcom_ice *devm_of_qcom_ice_get(struct device *dev)return ERR_PTR (-ENOMEM ); ice =of_qcom_ice_get (dev); -if (!IS_ERR_OR_NULL (ice)) { +if (!IS_ERR (ice)) { *dr = ice;devres_add (dev, dr); }else { --2.51.0
Manivannan Sadhasivam
maintainerRe: [PATCH v4 3/5] soc: qcom: ice: Return proper error codes from devm_of_qcom_ice_get() instead of NULL
Quoted 48 lines · Sumit Garg
Quoted 47 lines · Sumit Garg
Hey Mani,
Quoted 20 lines · On Mon, Mar 2, 2026 at 6:30 PM Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
devm_of_qcom_ice_get()currently returns NULL if ICE SCM is not available or "qcom,ice" property is not found in DT. But this confuses the clients since NULL doesn't convey the reason for failure. So return proper error codes instead of NULL.Reported-by Sumit Garg <[email protected]>Reviewed-by Konrad Dybcio <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>--- drivers/soc/qcom/ice.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/soc/qcom/ice.c +0
-0drivers/soc/qcom/ice.c static struct qcom_ice *qcom_ice_create(struct device *dev, · line 565
Quoted 6 lines
drivers/soc/qcom/ice.c +1
-1@@ -561,7 +561,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,if (!qcom_scm_ice_available ()) {dev_warn (dev,"ICE SCM interface not found\n" ); -return NULL ; +return ERR_PTR (-EOPNOTSUPP ); }With this patch-set on top of v7.0-rc2, I still see UFS probe failing when ICE isn't supported with OP-TEE as follows:
[ 5.401558] qcom-ice 1d88000.crypto: ICE SCM interface not found [ 5.419482] qcom-ice 1d88000.crypto: probe with driver qcom-ice failed with error -95 <snip> [ 18.662977] ufshcd-qcom 1d84000.ufshc: freq-table-hz property not specified [ 18.670193] ufshcd-qcom 1d84000.ufshc: ufshcd_populate_vreg: Unable to find vdd-hba-supply regulator, assuming enabled [ 18.737665] platform 1d84000.ufshc: deferred probe pending: ufshcd-qcom: ufshcd_pltfrm_init() failed [ 18.747141] platform 3370000.codec: deferred probe pending:platform: wait for supplier /soc@0/pinctrl@33c0000/dmic23-data-state
Quoted 3 lines
Quoted 3 lines
Maybe it's the "qcom-ice" driver failure leading to this deferred probe problem again.
Urgh... I completely forgot that the driver core removes the drvdata during probe error >.<
Quoted 10 lines
Following diff on top of your patchset allows the UFS driver to probe successfully without ICE support. I suppose just setting the drvdata should be sufficient.
drivers/soc/qcom/ice.c +0
-0
drivers/soc/qcom/ice.c static int qcom_ice_probe(struct platform_device *pdev) · line 742
Quoted 9 lines
drivers/soc/qcom/ice.c +0
-6@@ -734,12 +734,6 @@ static int qcom_ice_probe(struct platform_device *pdev) } engine =qcom_ice_create (&pdev->dev, base); -if (IS_ERR (engine)) { -/* Store the error pointer for devm_of_qcom_ice_get() */ -platform_set_drvdata (pdev, engine); -return PTR_ERR (engine); - } -
No, this will indicate probe success which we do not want and is not safe all the time. Like what if qcom_ice_create() returned -EPROBE_DEFER.
Let me just store the ice_handle in a global xarray with key based on node phandle instead of drvdata. This will ensure that the pointer stays till the driver is loaded.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
PATCH v4 4/5 mmc: sdhci-msm: Remove NULL check from devm_of_qcom_ice_get()
In reply to Manivannan SadhasivamNow since the devm_of_qcom_ice_get() API never returns NULL, remove the NULL check and also simplify the error handling.
--- drivers/mmc/host/sdhci-msm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mmc/host/sdhci-msm.c +5 -5
@@ -1906,14 +1906,14 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,return 0 ; ice =devm_of_qcom_ice_get (dev); -if (ice ==ERR_PTR (-EOPNOTSUPP )) { +if (IS_ERR (ice)) { +if (ice !=ERR_PTR (-EOPNOTSUPP )) +return PTR_ERR (ice); +dev_warn (dev,"Disabling inline encryption support\n" ); - ice =NULL ; +return 0 ; } -if (IS_ERR_OR_NULL (ice)) -return PTR_ERR_OR_ZERO (ice); -if (qcom_ice_get_supported_key_type (ice) !=BLK_CRYPTO_KEY_TYPE_RAW ) {dev_warn (dev,"Wrapped keys not supported. Disabling inline encryption support.\n" );return 0 ;
Signature · 1 line
2.51.0
PATCH v4 5/5 scsi: ufs: ufs-qcom: Remove NULL check from devm_of_qcom_ice_get()
In reply to Manivannan SadhasivamNow since the devm_of_qcom_ice_get() API never returns NULL, remove the NULL check and also simplify the error handling.
--- drivers/ufs/host/ufs-qcom.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/ufs/host/ufs-qcom.c +5 -5
@@ -177,14 +177,14 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)int i; ice =devm_of_qcom_ice_get (dev); -if (ice ==ERR_PTR (-EOPNOTSUPP )) { +if (IS_ERR (ice)) { +if (ice !=ERR_PTR (-EOPNOTSUPP )) +return PTR_ERR (ice); +dev_warn (dev,"Disabling inline encryption support\n" ); - ice =NULL ; +return 0 ; } -if (IS_ERR_OR_NULL (ice)) -return PTR_ERR_OR_ZERO (ice); - host->ice = ice;/* Initialize the blk_crypto_profile */
Signature · 1 line
2.51.0