kernel: 5.4: import wireguard backport
Rather than using the clunky, old, slower wireguard-linux-compat out of
tree module, this commit does a patch-by-patch backport of upstream's
wireguard to 5.4. This specific backport is in widespread use, being
part of SUSE's enterprise kernel, Oracle's enterprise kernel, Google's
Android kernel, Gentoo's distro kernel, and probably more I've forgotten
about. It's definately the "more proper" way of adding wireguard to a
kernel than the ugly compat.h hell of the wireguard-linux-compat repo.
And most importantly for OpenWRT, it allows using the same module
configuration code for 5.10 as for 5.4, with no need for bifurcation.
These patches are from the backport tree which is maintained in the
open here: https://git.zx2c4.com/wireguard-linux/log/?h=backport-5.4.y
I'll be sending PRs to update this as needed.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
(cherry picked from commit 3888fa78802354ab7bbd19b7d061fd80a16ce06b)
(cherry picked from commit d54072587146dd0db9bb52b513234d944edabda3)
(cherry picked from commit 196f3d586f11d96ba4ab60068cfb12420bcd20fd)
(cherry picked from commit 3500fd7938a6d0c0e320295f0aa2fa34b1ebc08d)
(cherry picked from commit 23b801d3ba57e34cc609ea40982c7fbed08164e9)
(cherry picked from commit 0c0cb97da7f5cc06919449131dd57ed805f8f78d)
(cherry picked from commit 2a27f6f90a430342cdbe84806e8b10acff446a2d)
Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
2021-02-19 13:29:04 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
|
|
|
|
Date: Sun, 1 Mar 2020 22:52:35 +0800
|
|
|
|
Subject: [PATCH] crypto: x86/curve25519 - support assemblers with no adx
|
|
|
|
support
|
|
|
|
|
|
|
|
commit 1579f1bc3b753d17a44de3457d5c6f4a5b14c752 upstream.
|
|
|
|
|
|
|
|
Some older version of GAS do not support the ADX instructions, similarly
|
|
|
|
to how they also don't support AVX and such. This commit adds the same
|
|
|
|
build-time detection mechanisms we use for AVX and others for ADX, and
|
|
|
|
then makes sure that the curve25519 library dispatcher calls the right
|
|
|
|
functions.
|
|
|
|
|
|
|
|
Reported-by: Willy Tarreau <w@1wt.eu>
|
|
|
|
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
|
|
|
|
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
|
|
|
|
---
|
|
|
|
arch/x86/Makefile | 5 +++--
|
|
|
|
arch/x86/crypto/Makefile | 7 ++++++-
|
|
|
|
include/crypto/curve25519.h | 6 ++++--
|
|
|
|
3 files changed, 13 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
--- a/arch/x86/Makefile
|
|
|
|
+++ b/arch/x86/Makefile
|
2021-05-15 14:21:46 +00:00
|
|
|
@@ -198,9 +198,10 @@ avx2_instr :=$(call as-instr,vpbroadcast
|
kernel: 5.4: import wireguard backport
Rather than using the clunky, old, slower wireguard-linux-compat out of
tree module, this commit does a patch-by-patch backport of upstream's
wireguard to 5.4. This specific backport is in widespread use, being
part of SUSE's enterprise kernel, Oracle's enterprise kernel, Google's
Android kernel, Gentoo's distro kernel, and probably more I've forgotten
about. It's definately the "more proper" way of adding wireguard to a
kernel than the ugly compat.h hell of the wireguard-linux-compat repo.
And most importantly for OpenWRT, it allows using the same module
configuration code for 5.10 as for 5.4, with no need for bifurcation.
These patches are from the backport tree which is maintained in the
open here: https://git.zx2c4.com/wireguard-linux/log/?h=backport-5.4.y
I'll be sending PRs to update this as needed.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
(cherry picked from commit 3888fa78802354ab7bbd19b7d061fd80a16ce06b)
(cherry picked from commit d54072587146dd0db9bb52b513234d944edabda3)
(cherry picked from commit 196f3d586f11d96ba4ab60068cfb12420bcd20fd)
(cherry picked from commit 3500fd7938a6d0c0e320295f0aa2fa34b1ebc08d)
(cherry picked from commit 23b801d3ba57e34cc609ea40982c7fbed08164e9)
(cherry picked from commit 0c0cb97da7f5cc06919449131dd57ed805f8f78d)
(cherry picked from commit 2a27f6f90a430342cdbe84806e8b10acff446a2d)
Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
2021-02-19 13:29:04 +00:00
|
|
|
avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
|
|
|
|
sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
|
|
|
|
sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
|
|
|
|
+adx_instr := $(call as-instr,adox %r10$(comma)%r10,-DCONFIG_AS_ADX=1)
|
|
|
|
|
|
|
|
-KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
|
|
|
|
-KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
|
|
|
|
+KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
|
|
|
|
+KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
|
|
|
|
|
|
|
|
KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
|
|
|
|
|
|
|
|
--- a/arch/x86/crypto/Makefile
|
|
|
|
+++ b/arch/x86/crypto/Makefile
|
|
|
|
@@ -11,6 +11,7 @@ avx2_supported := $(call as-instr,vpgath
|
|
|
|
avx512_supported :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,yes,no)
|
|
|
|
sha1_ni_supported :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,yes,no)
|
|
|
|
sha256_ni_supported :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,yes,no)
|
|
|
|
+adx_supported := $(call as-instr,adox %r10$(comma)%r10,yes,no)
|
|
|
|
|
|
|
|
obj-$(CONFIG_CRYPTO_GLUE_HELPER_X86) += glue_helper.o
|
|
|
|
|
|
|
|
@@ -39,7 +40,11 @@ obj-$(CONFIG_CRYPTO_AEGIS128_AESNI_SSE2)
|
|
|
|
|
|
|
|
obj-$(CONFIG_CRYPTO_NHPOLY1305_SSE2) += nhpoly1305-sse2.o
|
|
|
|
obj-$(CONFIG_CRYPTO_NHPOLY1305_AVX2) += nhpoly1305-avx2.o
|
|
|
|
-obj-$(CONFIG_CRYPTO_CURVE25519_X86) += curve25519-x86_64.o
|
|
|
|
+
|
|
|
|
+# These modules require the assembler to support ADX.
|
|
|
|
+ifeq ($(adx_supported),yes)
|
|
|
|
+ obj-$(CONFIG_CRYPTO_CURVE25519_X86) += curve25519-x86_64.o
|
|
|
|
+endif
|
|
|
|
|
|
|
|
# These modules require assembler to support AVX.
|
|
|
|
ifeq ($(avx_supported),yes)
|
|
|
|
--- a/include/crypto/curve25519.h
|
|
|
|
+++ b/include/crypto/curve25519.h
|
|
|
|
@@ -33,7 +33,8 @@ bool __must_check curve25519(u8 mypublic
|
|
|
|
const u8 secret[CURVE25519_KEY_SIZE],
|
|
|
|
const u8 basepoint[CURVE25519_KEY_SIZE])
|
|
|
|
{
|
|
|
|
- if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
|
|
|
|
+ if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519) &&
|
|
|
|
+ (!IS_ENABLED(CONFIG_CRYPTO_CURVE25519_X86) || IS_ENABLED(CONFIG_AS_ADX)))
|
|
|
|
curve25519_arch(mypublic, secret, basepoint);
|
|
|
|
else
|
|
|
|
curve25519_generic(mypublic, secret, basepoint);
|
|
|
|
@@ -49,7 +50,8 @@ __must_check curve25519_generate_public(
|
|
|
|
CURVE25519_KEY_SIZE)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
- if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
|
|
|
|
+ if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519) &&
|
|
|
|
+ (!IS_ENABLED(CONFIG_CRYPTO_CURVE25519_X86) || IS_ENABLED(CONFIG_AS_ADX)))
|
|
|
|
curve25519_base_arch(pub, secret);
|
|
|
|
else
|
|
|
|
curve25519_generic(pub, secret, curve25519_base_point);
|