From nobody Thu Apr 9 13:37:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 000B6274B39; Mon, 9 Mar 2026 06:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773039521; cv=none; b=RtkkIlM+d/Ugu9YBd7p0BDoamgopub3/r7qrqfEI334nRUxF21APrSlwTvAGW1qZh04z8aZZV3Pro0a4xLrAyoauE5hE81aRnGYx6E0vg4uezasNdBS+4gjUmAjZPVILiX+g+uh31p6ztdemAQG6TTjXOg1xJxKgXein0TISUA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773039521; c=relaxed/simple; bh=9ifWUGUuqbMEA3nM68bJhc8gfZIk88yslqLcdB+vYiY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wu87tv8CJXIsAMfY2gipg1V0Z8ahBTKVHQhs/rWB7bEPu2vrg7noTwGpu+ZNeJHPnZtKGetiUbQ9qXgauh1iMbeauvwYSFbk27G3iH/j3dajWf+5UUkfTBstzNDoZhr2JaaWQ1ivpplvV4N9zEaKQPIJdKOTbI3MM1UEu83qKNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DAKpMcmc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DAKpMcmc" Received: by smtp.kernel.org (Postfix) with ESMTPS id A4D58C2BC87; Mon, 9 Mar 2026 06:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773039520; bh=9ifWUGUuqbMEA3nM68bJhc8gfZIk88yslqLcdB+vYiY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DAKpMcmcA9TLNb/vBZq7oZbl6TzD+0cNcN98DcLgXlRSQE+tFTsmJKIBtvSvfIxPL oj85iW4GApmE31pu+CaQWQ4llUU3dXOYxNWmTKObkiDpeos6Ho2MB3IQjp5j2Z+tu/ VSxxaQcyBKOX8xeH2cwPtFmIwuY7NZK/IjIvqsNevSitSk4RndDU3QXK2xz/OHVGme poeHg8Jz/Fo4YYCVzauCdNf+aP4pM08PQCi6DyTfJef5EEc9IJSkaCSmZXvzFcGflO NAGOQlzlvxhzt/Za5K8qgVDh6ejnuTzdqWRN8NBo0oqlRWEd/GBiiLcAROSss/1+9H h7V8jHPiKIIrQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90E05EF36EB; Mon, 9 Mar 2026 06:58:40 +0000 (UTC) From: Manivannan Sadhasivam via B4 Relay Date: Mon, 09 Mar 2026 12:28:31 +0530 Subject: [PATCH v6 1/5] soc: qcom: ice: Fix race between qcom_ice_probe() and of_qcom_ice_get() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260309-qcom-ice-fix-v6-1-4dd3347df530@oss.qualcomm.com> References: <20260309-qcom-ice-fix-v6-0-4dd3347df530@oss.qualcomm.com> In-Reply-To: <20260309-qcom-ice-fix-v6-0-4dd3347df530@oss.qualcomm.com> To: Bjorn Andersson , Konrad Dybcio , Adrian Hunter , Ulf Hansson , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , Abel Vesa , Abel Vesa Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, Sumit Garg , mani@kernel.org, Neeraj Soni , Manivannan Sadhasivam , stable@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4921; i=manivannan.sadhasivam@oss.qualcomm.com; h=from:subject:message-id; bh=UmeyW+kNpWioyVDzVXqFfX4+r2Km4VFRq/bAVfTsmFo=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBprm+c6h0RSxkKmqMZ35CXym+leOD1teE3J69SW +sRVzluyX2JATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCaa5vnAAKCRBVnxHm/pHO 9YT+B/9ogjaHpyGpq0790JuBkYXU8G0pMbq/Ve1BH/aOc+RCwAK+5A4jrNYwxyIXNi8janl+9GE qXxLRg82md4IyNrK4roY3v2yWmr2TQ2rLlxMREiMrukyMNoIErdPdrm5d7q/U1vvp8oHfKyzkFR 5JIuCoVJw46Ycm9JAyINBONfPSMmK83tuwyxFaOBcG4G/naA2C2zCQusAVBvOpS1twySdC1VfdB 3nbnOw/9x6IOOHoc7ZzBiphhSfIbsj5zdV13WnVg/y1GjdHDGeMR3bpdMZIkUIktNF01Lm2qXTi etr8sw+N7iw91eo83oxjlMCd+8XZlu0dWRtxPbFfDxUfSf81 X-Developer-Key: i=manivannan.sadhasivam@oss.qualcomm.com; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-Endpoint-Received: by B4 Relay for manivannan.sadhasivam@oss.qualcomm.com/default with auth_id=461 X-Original-From: Manivannan Sadhasivam Reply-To: manivannan.sadhasivam@oss.qualcomm.com From: Manivannan Sadhasivam 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 a global xarray with ice node phandle as a key 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 xarray entry 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. Otherwise, add the devlink as usual and return the valid pointer to the consumer. Xarray is used instead of platform drvdata, since driver core frees the drvdata during probe failure. So it cannot be used to pass the error pointer to the consumers. 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. Cc: # 6.4 Fixes: 2afbf43a4aec ("soc: qcom: Make the Qualcomm UFS/SDCC ICE a dedicated= driver") Reported-by: Sumit Garg Signed-off-by: Manivannan Sadhasivam --- drivers/soc/qcom/ice.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c index b203bc685cad..91991864b4a3 100644 --- a/drivers/soc/qcom/ice.c +++ b/drivers/soc/qcom/ice.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include =20 @@ -113,6 +114,9 @@ struct qcom_ice { u8 hwkm_version; }; =20 +static DEFINE_XARRAY(ice_handles); +static DEFINE_MUTEX(ice_mutex); + static bool qcom_ice_check_supported(struct qcom_ice *ice) { u32 regval =3D qcom_ice_readl(ice, QCOM_ICE_REG_VERSION); @@ -631,6 +635,8 @@ static struct qcom_ice *of_qcom_ice_get(struct device *= dev) return qcom_ice_create(&pdev->dev, base); } =20 + 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 @@ -647,12 +653,13 @@ static struct qcom_ice *of_qcom_ice_get(struct device= *dev) return ERR_PTR(-EPROBE_DEFER); } =20 - ice =3D platform_get_drvdata(pdev); - if (!ice) { - dev_err(dev, "Cannot get ice instance from %s\n", - dev_name(&pdev->dev)); + ice =3D xa_load(&ice_handles, pdev->dev.of_node->phandle); + 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; } =20 link =3D device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); @@ -716,24 +723,40 @@ EXPORT_SYMBOL_GPL(devm_of_qcom_ice_get); =20 static int qcom_ice_probe(struct platform_device *pdev) { + unsigned long phandle =3D pdev->dev.of_node->phandle; struct qcom_ice *engine; void __iomem *base; =20 + guard(mutex)(&ice_mutex); + base =3D 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() */ + xa_store(&ice_handles, phandle, (__force void *)base, GFP_KERNEL); return PTR_ERR(base); } =20 engine =3D qcom_ice_create(&pdev->dev, base); - if (IS_ERR(engine)) + if (IS_ERR(engine)) { + /* Store the error pointer for devm_of_qcom_ice_get() */ + xa_store(&ice_handles, phandle, engine, GFP_KERNEL); return PTR_ERR(engine); + } =20 - platform_set_drvdata(pdev, engine); + xa_store(&ice_handles, phandle, engine, GFP_KERNEL); =20 return 0; } =20 +static void qcom_ice_remove(struct platform_device *pdev) +{ + unsigned long phandle =3D pdev->dev.of_node->phandle; + + guard(mutex)(&ice_mutex); + xa_store(&ice_handles, phandle, NULL, GFP_KERNEL); +} + static const struct of_device_id qcom_ice_of_match_table[] =3D { { .compatible =3D "qcom,inline-crypto-engine" }, { }, @@ -742,6 +765,7 @@ MODULE_DEVICE_TABLE(of, qcom_ice_of_match_table); =20 static struct platform_driver qcom_ice_driver =3D { .probe =3D qcom_ice_probe, + .remove =3D qcom_ice_remove, .driver =3D { .name =3D "qcom-ice", .of_match_table =3D qcom_ice_of_match_table, --=20 2.51.0