aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/compat/compat.h18
-rw-r--r--src/crypto/blake2s.c2
-rw-r--r--src/crypto/chacha20poly1305.c2
-rw-r--r--src/crypto/curve25519.c2
4 files changed, 21 insertions, 3 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 7d26821..daeeef8 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -476,6 +476,24 @@ static int get_device_dump_real(a, b)
#define COMPAT_CANNOT_USE_IFF_NO_QUEUE
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)
+#include <asm/user.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
+#include <asm/xsave.h>
+#include <asm/xcr.h>
+static inline int cpu_has_xfeatures(u64 xfeatures_needed, const char **feature_name)
+{
+ return xgetbv(XCR_XFEATURE_ENABLED_MASK) & xfeatures_needed;
+}
+#endif
+#ifndef XFEATURE_MASK_YMM
+#define XFEATURE_MASK_YMM XSTATE_YMM
+#endif
+#ifndef XFEATURE_MASK_SSE
+#define XFEATURE_MASK_SSE XSTATE_SSE
+#endif
+#endif
+
/* https://lkml.org/lkml/2017/6/23/790 */
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
#include <linux/ip.h>
diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c
index 1fe4600..ab37a0c 100644
--- a/src/crypto/blake2s.c
+++ b/src/crypto/blake2s.c
@@ -115,7 +115,7 @@ void blake2s_init_key(struct blake2s_state *state, const size_t outlen, const vo
static bool blake2s_use_avx __read_mostly = false;
void __init blake2s_fpu_init(void)
{
- blake2s_use_avx = boot_cpu_has(X86_FEATURE_AVX);
+ blake2s_use_avx = boot_cpu_has(X86_FEATURE_AVX) && cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL);
}
asmlinkage void blake2s_compress_avx(struct blake2s_state *state, const u8 * block, size_t nblocks, u32 inc);
#else
diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c
index 7227617..3163009 100644
--- a/src/crypto/chacha20poly1305.c
+++ b/src/crypto/chacha20poly1305.c
@@ -35,7 +35,7 @@ void chacha20poly1305_fpu_init(void)
{
chacha20poly1305_use_sse2 = boot_cpu_has(X86_FEATURE_XMM2);
chacha20poly1305_use_ssse3 = boot_cpu_has(X86_FEATURE_SSSE3);
- chacha20poly1305_use_avx2 = boot_cpu_has(X86_FEATURE_AVX) && boot_cpu_has(X86_FEATURE_AVX2);
+ chacha20poly1305_use_avx2 = boot_cpu_has(X86_FEATURE_AVX) && boot_cpu_has(X86_FEATURE_AVX2) && cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL);
}
#elif IS_ENABLED(CONFIG_KERNEL_MODE_NEON)
#include <asm/hwcap.h>
diff --git a/src/crypto/curve25519.c b/src/crypto/curve25519.c
index ada050a..892da78 100644
--- a/src/crypto/curve25519.c
+++ b/src/crypto/curve25519.c
@@ -33,7 +33,7 @@ static const u8 null_point[CURVE25519_POINT_SIZE] = { 0 };
static bool curve25519_use_avx __read_mostly = false;
void curve25519_fpu_init(void)
{
- curve25519_use_avx = boot_cpu_has(X86_FEATURE_AVX);
+ curve25519_use_avx = boot_cpu_has(X86_FEATURE_AVX) && cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL);
}
typedef u64 fe[10];