LF-63-1 crypto: caam - fix SM test init

Commit 77debf316c44 ("LFV-26 crypto: caam - fix Secure Memory driver init")
addressed SM driver initialization and also update SM test.

However, the fix for SM test is insufficient.
There are cases when SM test runs before SM driver, causing a crash
due to uninitialized "priv" pointer being dereferenced.

The fix consists in the following:

1. Since SM test is a "bare" device driver (doesn't sit on any bus),
there is no deferred probing support.
Thus we have no choice (*) but to abort SM tests with a notification.

(*) We don't want to force SM driver running first by means of
init levels etc. Just KISS.

2. SM test driver forced to being built only as a module
Since SM test driver's only goal is to run SM tests, it doesn't make
any sense to be built-in.
Building the driver as a module allows for running the tests
several times if needed (multiple modprobe & rmmod cycles).

Note: from the perspective of wanting to test repetitively, it would
make sense to force module unloading by returning an error code
in the module_init function.
However, this might affect test scripts (due to error code and/or
message output by unsuccessful module loading), so we postpone
this change for now.

Fixes: d02fe599d7d5 ("MLKU-25-3 crypto: caam - add Secure Memory support")
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Acked-by: Leonard Crestez <leonard.crestez@nxp.com>
This commit is contained in:
Horia Geantă 2019-11-27 12:30:41 +02:00 committed by Dong Aisheng
parent cd21a001f8
commit 97dc4e4fa4
3 changed files with 6 additions and 1 deletions

View File

@ -190,6 +190,7 @@ config CRYPTO_DEV_FSL_CAAM_SM_SLOTSIZE
config CRYPTO_DEV_FSL_CAAM_SM_TEST
tristate "CAAM Secure Memory - Keystore Test/Example (EXPERIMENTAL)"
depends on CRYPTO_DEV_FSL_CAAM_SM
depends on m
help
Example thread to exercise the Keystore API and to verify that
stored and recovered secrets can be used for general purpose

View File

@ -24,7 +24,7 @@ caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM) += sm_store.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM_TEST) += sm_test.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SM_TEST) += sm_test.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_SECVIO) += secvio.o
#caam-jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_TK_API) += tag_object.o

View File

@ -552,6 +552,10 @@ static int __init caam_sm_test_init(void)
of_node_put(dev_node);
priv = dev_get_drvdata(&pdev->dev);
if (!priv) {
dev_info(&pdev->dev, "SM driver not ready, aborting tests\n");
return -ENODEV;
}
if (!priv->sm_present) {
dev_info(&pdev->dev, "No SM support, skipping tests\n");
return -ENODEV;