Skip to content

Commit 87be3e7

Browse files
Bartosz Golaszewskiandersson
authored andcommitted
firmware: qcom: scm: initialize tzmem before marking SCM as available
Now that qcom_scm_shm_bridge_enable() uses the struct device passed to it as argument to make the QCOM_SCM_MP_SHM_BRIDGE_ENABLE SCM call, we can move the TZMem initialization before the assignment of the __scm pointer in the SCM driver (which marks SCM as ready to users) thus fixing the potential race between consumer calls and the memory pool initialization. Reported-by: Johan Hovold <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Bartosz Golaszewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent dc3f4e7 commit 87be3e7

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

drivers/firmware/qcom/qcom_scm.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,32 @@ static int qcom_scm_probe(struct platform_device *pdev)
22562256
if (ret)
22572257
return ret;
22582258

2259-
/* Paired with smp_load_acquire() in qcom_scm_is_available(). */
2259+
ret = of_reserved_mem_device_init(scm->dev);
2260+
if (ret && ret != -ENODEV)
2261+
return dev_err_probe(scm->dev, ret,
2262+
"Failed to setup the reserved memory region for TZ mem\n");
2263+
2264+
ret = qcom_tzmem_enable(scm->dev);
2265+
if (ret)
2266+
return dev_err_probe(scm->dev, ret,
2267+
"Failed to enable the TrustZone memory allocator\n");
2268+
2269+
memset(&pool_config, 0, sizeof(pool_config));
2270+
pool_config.initial_size = 0;
2271+
pool_config.policy = QCOM_TZMEM_POLICY_ON_DEMAND;
2272+
pool_config.max_size = SZ_256K;
2273+
2274+
scm->mempool = devm_qcom_tzmem_pool_new(scm->dev, &pool_config);
2275+
if (IS_ERR(scm->mempool))
2276+
return dev_err_probe(scm->dev, PTR_ERR(scm->mempool),
2277+
"Failed to create the SCM memory pool\n");
2278+
2279+
/*
2280+
* Paired with smp_load_acquire() in qcom_scm_is_available().
2281+
*
2282+
* This marks the SCM API as ready to accept user calls and can only
2283+
* be called after the TrustZone memory pool is initialized.
2284+
*/
22602285
smp_store_release(&__scm, scm);
22612286

22622287
irq = platform_get_irq_optional(pdev, 0);
@@ -2289,32 +2314,6 @@ static int qcom_scm_probe(struct platform_device *pdev)
22892314
if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled") || !download_mode)
22902315
qcom_scm_disable_sdi();
22912316

2292-
ret = of_reserved_mem_device_init(__scm->dev);
2293-
if (ret && ret != -ENODEV) {
2294-
dev_err_probe(__scm->dev, ret,
2295-
"Failed to setup the reserved memory region for TZ mem\n");
2296-
goto err;
2297-
}
2298-
2299-
ret = qcom_tzmem_enable(__scm->dev);
2300-
if (ret) {
2301-
dev_err_probe(__scm->dev, ret,
2302-
"Failed to enable the TrustZone memory allocator\n");
2303-
goto err;
2304-
}
2305-
2306-
memset(&pool_config, 0, sizeof(pool_config));
2307-
pool_config.initial_size = 0;
2308-
pool_config.policy = QCOM_TZMEM_POLICY_ON_DEMAND;
2309-
pool_config.max_size = SZ_256K;
2310-
2311-
__scm->mempool = devm_qcom_tzmem_pool_new(__scm->dev, &pool_config);
2312-
if (IS_ERR(__scm->mempool)) {
2313-
ret = dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool),
2314-
"Failed to create the SCM memory pool\n");
2315-
goto err;
2316-
}
2317-
23182317
/*
23192318
* Initialize the QSEECOM interface.
23202319
*

0 commit comments

Comments
 (0)