* [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10
@ 2024-03-28 13:02 Michael Ellerman
2024-04-02 6:36 ` Herbert Xu
2024-04-22 9:21 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Michael Ellerman @ 2024-03-28 13:02 UTC (permalink / raw)
To: linuxppc-dev; +Cc: msuchanek, herbert, wireguard, dtsen
The chacha-p10-crypto module provides optimised chacha routines for
Power10. It also selects CRYPTO_ARCH_HAVE_LIB_CHACHA which says it
provides chacha_crypt_arch() to generic code.
Notably the module needs to provide chacha_crypt_arch() regardless of
whether it is loaded on Power10 or an older CPU.
The implementation of chacha_crypt_arch() already has a fallback to
chacha_crypt_generic(), however the module as a whole fails to load on
pre-Power10, because of the use of module_cpu_feature_match().
This breaks for example loading wireguard:
jostaberry-1:~ # modprobe -v wireguard
insmod /lib/modules/6.8.0-lp155.8.g7e0e887-default/kernel/arch/powerpc/crypto/chacha-p10-crypto.ko.zst
modprobe: ERROR: could not insert 'wireguard': No such device
Fix it by removing module_cpu_feature_match(), and instead check the
CPU feature manually. If the CPU feature is not found, the module
still loads successfully, but doesn't register the Power10 specific
algorithms. That allows chacha_crypt_generic() to remain available for
use, fixing the problem.
[root@fedora ~]# modprobe -v wireguard
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/net/ipv4/udp_tunnel.ko
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/net/ipv6/ip6_udp_tunnel.ko
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/lib/crypto/libchacha.ko
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/arch/powerpc/crypto/chacha-p10-crypto.ko
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/lib/crypto/libchacha20poly1305.ko
insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/drivers/net/wireguard/wireguard.ko
[ 18.910452][ T721] wireguard: allowedips self-tests: pass
[ 18.914999][ T721] wireguard: nonce counter self-tests: pass
[ 19.029066][ T721] wireguard: ratelimiter self-tests: pass
[ 19.029257][ T721] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[ 19.029361][ T721] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
Reported-by: Michal Suchánek <msuchanek@suse.de>
Closes: https://lore.kernel.org/all/20240315122005.GG20665@kitsune.suse.cz/
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/crypto/chacha-p10-glue.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/crypto/chacha-p10-glue.c b/arch/powerpc/crypto/chacha-p10-glue.c
index 74fb86b0d209..7c728755852e 100644
--- a/arch/powerpc/crypto/chacha-p10-glue.c
+++ b/arch/powerpc/crypto/chacha-p10-glue.c
@@ -197,6 +197,9 @@ static struct skcipher_alg algs[] = {
static int __init chacha_p10_init(void)
{
+ if (!cpu_has_feature(CPU_FTR_ARCH_31))
+ return 0;
+
static_branch_enable(&have_p10);
return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
@@ -204,10 +207,13 @@ static int __init chacha_p10_init(void)
static void __exit chacha_p10_exit(void)
{
+ if (!static_branch_likely(&have_p10))
+ return;
+
crypto_unregister_skciphers(algs, ARRAY_SIZE(algs));
}
-module_cpu_feature_match(PPC_MODULE_FEATURE_P10, chacha_p10_init);
+module_init(chacha_p10_init);
module_exit(chacha_p10_exit);
MODULE_DESCRIPTION("ChaCha and XChaCha stream ciphers (P10 accelerated)");
--
2.44.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10
2024-03-28 13:02 [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10 Michael Ellerman
@ 2024-04-02 6:36 ` Herbert Xu
2024-04-22 9:21 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2024-04-02 6:36 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, msuchanek, wireguard, dtsen
On Fri, Mar 29, 2024 at 12:02:00AM +1100, Michael Ellerman wrote:
> The chacha-p10-crypto module provides optimised chacha routines for
> Power10. It also selects CRYPTO_ARCH_HAVE_LIB_CHACHA which says it
> provides chacha_crypt_arch() to generic code.
>
> Notably the module needs to provide chacha_crypt_arch() regardless of
> whether it is loaded on Power10 or an older CPU.
>
> The implementation of chacha_crypt_arch() already has a fallback to
> chacha_crypt_generic(), however the module as a whole fails to load on
> pre-Power10, because of the use of module_cpu_feature_match().
>
> This breaks for example loading wireguard:
>
> jostaberry-1:~ # modprobe -v wireguard
> insmod /lib/modules/6.8.0-lp155.8.g7e0e887-default/kernel/arch/powerpc/crypto/chacha-p10-crypto.ko.zst
> modprobe: ERROR: could not insert 'wireguard': No such device
>
> Fix it by removing module_cpu_feature_match(), and instead check the
> CPU feature manually. If the CPU feature is not found, the module
> still loads successfully, but doesn't register the Power10 specific
> algorithms. That allows chacha_crypt_generic() to remain available for
> use, fixing the problem.
>
> [root@fedora ~]# modprobe -v wireguard
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/net/ipv4/udp_tunnel.ko
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/net/ipv6/ip6_udp_tunnel.ko
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/lib/crypto/libchacha.ko
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/arch/powerpc/crypto/chacha-p10-crypto.ko
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/lib/crypto/libchacha20poly1305.ko
> insmod /lib/modules/6.8.0-00001-g786a790c4d79/kernel/drivers/net/wireguard/wireguard.ko
> [ 18.910452][ T721] wireguard: allowedips self-tests: pass
> [ 18.914999][ T721] wireguard: nonce counter self-tests: pass
> [ 19.029066][ T721] wireguard: ratelimiter self-tests: pass
> [ 19.029257][ T721] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
> [ 19.029361][ T721] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
>
> Reported-by: Michal Suchánek <msuchanek@suse.de>
> Closes: https://lore.kernel.org/all/20240315122005.GG20665@kitsune.suse.cz/
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
> arch/powerpc/crypto/chacha-p10-glue.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10
2024-03-28 13:02 [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10 Michael Ellerman
2024-04-02 6:36 ` Herbert Xu
@ 2024-04-22 9:21 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2024-04-22 9:21 UTC (permalink / raw)
To: linuxppc-dev, Michael Ellerman; +Cc: msuchanek, herbert, wireguard, dtsen
On Fri, 29 Mar 2024 00:02:00 +1100, Michael Ellerman wrote:
> The chacha-p10-crypto module provides optimised chacha routines for
> Power10. It also selects CRYPTO_ARCH_HAVE_LIB_CHACHA which says it
> provides chacha_crypt_arch() to generic code.
>
> Notably the module needs to provide chacha_crypt_arch() regardless of
> whether it is loaded on Power10 or an older CPU.
>
> [...]
Applied to powerpc/fixes.
[1/1] powerpc/crypto/chacha-p10: Fix failure on non Power10
https://git.kernel.org/powerpc/c/69630926011c1f7170a465b7b5c228deb66e9372
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-18 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 13:02 [PATCH] powerpc/crypto/chacha-p10: Fix failure on non Power10 Michael Ellerman
2024-04-02 6:36 ` Herbert Xu
2024-04-22 9:21 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).