From patchwork Thu Feb 7 13:36:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 157756 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp656312jaa; Thu, 7 Feb 2019 05:36:20 -0800 (PST) X-Google-Smtp-Source: AHgI3IYEA1PQF1/T1yApilJwf+6rmYrs66F6qI8Ceg5VKTRIGZWUVVoQtY2sTeaF6k8YQjG8gLQ8 X-Received: by 2002:a62:61c3:: with SMTP id v186mr16292163pfb.55.1549546580147; Thu, 07 Feb 2019 05:36:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549546580; cv=none; d=google.com; s=arc-20160816; b=j5VCfCiCyDMWtYh9jwZhbvWiughWH5cQkab9dbmPcoFTbSIby2R2RV8WroxUVxQFBQ BfQ6kJWJdWZqG4MPv/EaGLRkdCdaI4M7GfX9iggXCHe5xkZ9oKD3RzL5Kv1R3/5Nx5Si PJtgLCpa8DhNCEmk0NO8qzvMdgYOTKvdEFeoG/7RUOMSAASTpDzRHOOeqPwYnJjU6J+X aKTGdMOr3WO+C/H7ORS62QpZrbhRKMGH3ceH+6OckbYA4p3Gnw3C+tB2kmb4rWP7wPoV nFkDqwelLiiJoqiHDwYfK7/+y0nP99rtbhVR1gt3kq3+rC8TpZ7VJdA2gvReA2vLQthT kzSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=t1QBbXDE+Ldt15qF63IvfQJSWQroO6tQiiPmqTlUGQ0=; b=iFniIVVIt9S4vjCaTFbJft0SqFah5pqDkjKGVhpW12/LwIDCcOQfHDn130BXl1H6RZ sIKi1R87fecLeWPRIPkT5ELuzsWs8PnJy6srODtorUV4Brhv+Yful8+IcDXwgAA8b+f2 +MfWcl8N5wYAZ3jEnqjBc1J6ysqoIxVnq4vAhHvX5OtAYUFOVwDwqBAg4P8V2ZaTQOEE sr7MVh0w/sP/v1bqlcXUdC98F3agPcoNY0IWdh/sLE/FZjDhGOpxSQfd86ouqh+MwXMA SGeXdZLv10g7BaMUyTf7GCvZVmOHgJu0VWUEyc/jrkxoYQ+vaollWXO4myLaQsZOMi2q IN6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si5078255pgg.120.2019.02.07.05.36.19; Thu, 07 Feb 2019 05:36:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfBGNgR (ORCPT + 3 others); Thu, 7 Feb 2019 08:36:17 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:37254 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726750AbfBGNgR (ORCPT ); Thu, 7 Feb 2019 08:36:17 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 655E5EBD; Thu, 7 Feb 2019 05:36:16 -0800 (PST) Received: from e110176-lin.kfn.arm.com (e110176-lin.kfn.arm.com [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7BC7F3F675; Thu, 7 Feb 2019 05:36:14 -0800 (PST) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drag , Vincent Guittot , stable@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [BUGFIX PATCH] crypto: ccree: fix resume race condition on init Date: Thu, 7 Feb 2019 15:36:11 +0200 Message-Id: <20190207133612.31836-1-gilad@benyossef.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 Cc: Vincent Guittot 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(-) -- 2.20.1 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)