crypto: chacha20-simd - Use generic code for small requests
[cascardo/linux.git] / arch / x86 / crypto / chacha20_glue.c
index cea061e..f910d1d 100644 (file)
@@ -70,7 +70,7 @@ static int chacha20_simd(struct blkcipher_desc *desc, struct scatterlist *dst,
        struct blkcipher_walk walk;
        int err;
 
-       if (!may_use_simd())
+       if (nbytes <= CHACHA20_BLOCK_SIZE || !may_use_simd())
                return crypto_chacha20_crypt(desc, dst, src, nbytes);
 
        state = (u32 *)roundup((uintptr_t)state_buf, CHACHA20_STATE_ALIGN);
@@ -129,7 +129,8 @@ static int __init chacha20_simd_mod_init(void)
                return -ENODEV;
 
 #ifdef CONFIG_AS_AVX2
-       chacha20_use_avx2 = cpu_has_avx && boot_cpu_has(X86_FEATURE_AVX2) &&
+       chacha20_use_avx2 = boot_cpu_has(X86_FEATURE_AVX) &&
+                           boot_cpu_has(X86_FEATURE_AVX2) &&
                            cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL);
 #endif
        return crypto_register_alg(&alg);