04c14ca92786c19231c916f02cfb0b59ba7a4900
[openwrt/openwrt.git] / target / linux / layerscape / patches-5.4 / 804-crypto-0034-LF-63-1-crypto-caam-fix-SM-test-init.patch
1 From 79aa6ebf9d0b982c859a0c1bec1d879ff3d9ad29 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Horia=20Geant=C4=83?= <horia.geanta@nxp.com>
3 Date: Wed, 27 Nov 2019 12:30:41 +0200
4 Subject: [PATCH] LF-63-1 crypto: caam - fix SM test init
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Commit 77debf316c44 ("LFV-26 crypto: caam - fix Secure Memory driver init")
10 addressed SM driver initialization and also update SM test.
11
12 However, the fix for SM test is insufficient.
13 There are cases when SM test runs before SM driver, causing a crash
14 due to uninitialized "priv" pointer being dereferenced.
15
16 The fix consists in the following:
17
18 1. Since SM test is a "bare" device driver (doesn't sit on any bus),
19 there is no deferred probing support.
20 Thus we have no choice (*) but to abort SM tests with a notification.
21
22 (*) We don't want to force SM driver running first by means of
23 init levels etc. Just KISS.
24
25 2. SM test driver forced to being built only as a module
26 Since SM test driver's only goal is to run SM tests, it doesn't make
27 any sense to be built-in.
28 Building the driver as a module allows for running the tests
29 several times if needed (multiple modprobe & rmmod cycles).
30
31 Note: from the perspective of wanting to test repetitively, it would
32 make sense to force module unloading by returning an error code
33 in the module_init function.
34 However, this might affect test scripts (due to error code and/or
35 message output by unsuccessful module loading), so we postpone
36 this change for now.
37
38 Fixes: d02fe599d7d5 ("MLKU-25-3 crypto: caam - add Secure Memory support")
39 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
40 Acked-by: Leonard Crestez <leonard.crestez@nxp.com>
41 ---
42 drivers/crypto/caam/Kconfig | 1 +
43 drivers/crypto/caam/Makefile | 2 +-
44 drivers/crypto/caam/sm_test.c | 4 ++++
45 3 files changed, 6 insertions(+), 1 deletion(-)
46
47 --- a/drivers/crypto/caam/Kconfig
48 +++ b/drivers/crypto/caam/Kconfig
49 @@ -190,6 +190,7 @@ config CRYPTO_DEV_FSL_CAAM_SM_SLOTSIZE
50 config CRYPTO_DEV_FSL_CAAM_SM_TEST
51 tristate "CAAM Secure Memory - Keystore Test/Example (EXPERIMENTAL)"
52 depends on CRYPTO_DEV_FSL_CAAM_SM
53 + depends on m
54 help
55 Example thread to exercise the Keystore API and to verify that
56 stored and recovered secrets can be used for general purpose
57 --- a/drivers/crypto/caam/Makefile
58 +++ b/drivers/crypto/caam/Makefile
59 @@ -24,7 +24,7 @@ caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHA
60 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
61 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o
62 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM) += sm_store.o
63 -caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM_TEST) += sm_test.o
64 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM_TEST) += sm_test.o
65 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SECVIO) += secvio.o
66 #caam-jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_TK_API) += tag_object.o
67
68 --- a/drivers/crypto/caam/sm_test.c
69 +++ b/drivers/crypto/caam/sm_test.c
70 @@ -552,6 +552,10 @@ static int __init caam_sm_test_init(void
71 of_node_put(dev_node);
72
73 priv = dev_get_drvdata(&pdev->dev);
74 + if (!priv) {
75 + dev_info(&pdev->dev, "SM driver not ready, aborting tests\n");
76 + return -ENODEV;
77 + }
78 if (!priv->sm_present) {
79 dev_info(&pdev->dev, "No SM support, skipping tests\n");
80 return -ENODEV;