summaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-03-13 01:12:47 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-03-22 08:57:27 -0400
commitb55e1a39543f5e9aadf1149f8ad4bcff5cace8a4 (patch)
tree9f50f2eee2a2e57fe689f899ff572f097feab054 /crypto/testmgr.c
parent580e295178402d14bbf598a5702f8e01fc59dbaa (diff)
crypto: simd,testmgr - introduce crypto_simd_usable()
So that the no-SIMD fallback code can be tested by the crypto self-tests, add a macro crypto_simd_usable() which wraps may_use_simd(), but also returns false if the crypto self-tests have set a per-CPU bool to disable SIMD in crypto code on the current CPU. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 5d56b2990762..52417dde811f 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -37,6 +37,7 @@
37#include <crypto/akcipher.h> 37#include <crypto/akcipher.h>
38#include <crypto/kpp.h> 38#include <crypto/kpp.h>
39#include <crypto/acompress.h> 39#include <crypto/acompress.h>
40#include <crypto/internal/simd.h>
40 41
41#include "internal.h" 42#include "internal.h"
42 43
@@ -52,6 +53,9 @@ MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
52static unsigned int fuzz_iterations = 100; 53static unsigned int fuzz_iterations = 100;
53module_param(fuzz_iterations, uint, 0644); 54module_param(fuzz_iterations, uint, 0644);
54MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations"); 55MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
56
57DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
58EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
55#endif 59#endif
56 60
57#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS 61#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
@@ -838,7 +842,27 @@ static void generate_random_testvec_config(struct testvec_config *cfg,
838 842
839 WARN_ON_ONCE(!valid_testvec_config(cfg)); 843 WARN_ON_ONCE(!valid_testvec_config(cfg));
840} 844}
841#endif /* CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ 845
846static void crypto_disable_simd_for_test(void)
847{
848 preempt_disable();
849 __this_cpu_write(crypto_simd_disabled_for_test, true);
850}
851
852static void crypto_reenable_simd_for_test(void)
853{
854 __this_cpu_write(crypto_simd_disabled_for_test, false);
855 preempt_enable();
856}
857#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
858static void crypto_disable_simd_for_test(void)
859{
860}
861
862static void crypto_reenable_simd_for_test(void)
863{
864}
865#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
842 866
843static int check_nonfinal_hash_op(const char *op, int err, 867static int check_nonfinal_hash_op(const char *op, int err,
844 u8 *result, unsigned int digestsize, 868 u8 *result, unsigned int digestsize,