* [BUGFIX PATCH] crypto: ccree: fix resume race condition on init
@ 2019-02-07 13:36 Gilad Ben-Yossef
2019-02-08 7:48 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Gilad Ben-Yossef @ 2019-02-07 13:36 UTC (permalink / raw)
To: Herbert Xu, David S. Miller
Cc: Ofir Drag, Vincent Guittot, stable, linux-crypto, linux-kernel
We were enabling autosuspend, which is using data set by the
hash module, prior to the hash module being inited, casuing
a crash on resume as part of the startup sequence if the race
was lost.
This was never a real problem because the PM infra was using low
res timers so we were always winning the race, until commit 8234f6734c5d
("PM-runtime: Switch autosuspend over to using hrtimers") changed that :-)
Fix this by seperating the PM setup and enablement and doing the
latter only at the end of the init sequence.
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: stable@kernel.org # v4.20
---
Herbert, could you please take this for 5.0-rc6 ? thanks.
drivers/crypto/ccree/cc_driver.c | 7 ++++---
drivers/crypto/ccree/cc_pm.c | 13 ++++++-------
drivers/crypto/ccree/cc_pm.h | 3 +++
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c
index 210cc86605e9..3bcc6c76e090 100644
--- a/drivers/crypto/ccree/cc_driver.c
+++ b/drivers/crypto/ccree/cc_driver.c
@@ -380,7 +380,7 @@ static int init_cc_resources(struct platform_device *plat_dev)
rc = cc_ivgen_init(new_drvdata);
if (rc) {
dev_err(dev, "cc_ivgen_init failed\n");
- goto post_power_mgr_err;
+ goto post_buf_mgr_err;
}
/* Allocate crypto algs */
@@ -403,6 +403,9 @@ static int init_cc_resources(struct platform_device *plat_dev)
goto post_hash_err;
}
+ /* All set, we can allow autosuspend */
+ cc_pm_go(new_drvdata);
+
/* If we got here and FIPS mode is enabled
* it means all FIPS test passed, so let TEE
* know we're good.
@@ -417,8 +420,6 @@ static int init_cc_resources(struct platform_device *plat_dev)
cc_cipher_free(new_drvdata);
post_ivgen_err:
cc_ivgen_fini(new_drvdata);
-post_power_mgr_err:
- cc_pm_fini(new_drvdata);
post_buf_mgr_err:
cc_buffer_mgr_fini(new_drvdata);
post_req_mgr_err:
diff --git a/drivers/crypto/ccree/cc_pm.c b/drivers/crypto/ccree/cc_pm.c
index d990f472e89f..6ff7e75ad90e 100644
--- a/drivers/crypto/ccree/cc_pm.c
+++ b/drivers/crypto/ccree/cc_pm.c
@@ -100,20 +100,19 @@ int cc_pm_put_suspend(struct device *dev)
int cc_pm_init(struct cc_drvdata *drvdata)
{
- int rc = 0;
struct device *dev = drvdata_to_dev(drvdata);
/* must be before the enabling to avoid resdundent suspending */
pm_runtime_set_autosuspend_delay(dev, CC_SUSPEND_TIMEOUT);
pm_runtime_use_autosuspend(dev);
/* activate the PM module */
- rc = pm_runtime_set_active(dev);
- if (rc)
- return rc;
- /* enable the PM module*/
- pm_runtime_enable(dev);
+ return pm_runtime_set_active(dev);
+}
- return rc;
+/* enable the PM module*/
+void cc_pm_go(struct cc_drvdata *drvdata)
+{
+ pm_runtime_enable(drvdata_to_dev(drvdata));
}
void cc_pm_fini(struct cc_drvdata *drvdata)
diff --git a/drivers/crypto/ccree/cc_pm.h b/drivers/crypto/ccree/cc_pm.h
index 020a5403c58b..f62624357020 100644
--- a/drivers/crypto/ccree/cc_pm.h
+++ b/drivers/crypto/ccree/cc_pm.h
@@ -16,6 +16,7 @@
extern const struct dev_pm_ops ccree_pm;
int cc_pm_init(struct cc_drvdata *drvdata);
+void cc_pm_go(struct cc_drvdata *drvdata);
void cc_pm_fini(struct cc_drvdata *drvdata);
int cc_pm_suspend(struct device *dev);
int cc_pm_resume(struct device *dev);
@@ -29,6 +30,8 @@ static inline int cc_pm_init(struct cc_drvdata *drvdata)
return 0;
}
+static void cc_pm_go(struct cc_drvdata *drvdata) {}
+
static inline void cc_pm_fini(struct cc_drvdata *drvdata) {}
static inline int cc_pm_suspend(struct device *dev)
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [BUGFIX PATCH] crypto: ccree: fix resume race condition on init
2019-02-07 13:36 [BUGFIX PATCH] crypto: ccree: fix resume race condition on init Gilad Ben-Yossef
@ 2019-02-08 7:48 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2019-02-08 7:48 UTC (permalink / raw)
To: Gilad Ben-Yossef
Cc: David S. Miller, Ofir Drag, Vincent Guittot, stable,
linux-crypto, linux-kernel
On Thu, Feb 07, 2019 at 03:36:11PM +0200, Gilad Ben-Yossef wrote:
> We were enabling autosuspend, which is using data set by the
> hash module, prior to the hash module being inited, casuing
> a crash on resume as part of the startup sequence if the race
> was lost.
>
> This was never a real problem because the PM infra was using low
> res timers so we were always winning the race, until commit 8234f6734c5d
> ("PM-runtime: Switch autosuspend over to using hrtimers") changed that :-)
>
> Fix this by seperating the PM setup and enablement and doing the
> latter only at the end of the init sequence.
>
> Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: stable@kernel.org # v4.20
> ---
> Herbert, could you please take this for 5.0-rc6 ? thanks.
>
> drivers/crypto/ccree/cc_driver.c | 7 ++++---
> drivers/crypto/ccree/cc_pm.c | 13 ++++++-------
> drivers/crypto/ccree/cc_pm.h | 3 +++
> 3 files changed, 13 insertions(+), 10 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-08 7:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 13:36 [BUGFIX PATCH] crypto: ccree: fix resume race condition on init Gilad Ben-Yossef
2019-02-08 7:48 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.