| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Ard Biesheuvel <ardb@kernel.org> |
| 3 | Date: Fri, 17 Jan 2020 17:43:18 +0100 |
| 4 | Subject: [PATCH] crypto: arm/chacha - fix build failured when kernel mode NEON |
| 5 | is disabled |
| 6 | |
| 7 | commit 0bc81767c5bd9d005fae1099fb39eb3688370cb1 upstream. |
| 8 | |
| 9 | When the ARM accelerated ChaCha driver is built as part of a configuration |
| 10 | that has kernel mode NEON disabled, we expect the compiler to propagate |
| 11 | the build time constant expression IS_ENABLED(CONFIG_KERNEL_MODE_NEON) in |
| 12 | a way that eliminates all the cross-object references to the actual NEON |
| 13 | routines, which allows the chacha-neon-core.o object to be omitted from |
| 14 | the build entirely. |
| 15 | |
| 16 | Unfortunately, this fails to work as expected in some cases, and we may |
| 17 | end up with a build error such as |
| 18 | |
| 19 | chacha-glue.c:(.text+0xc0): undefined reference to `chacha_4block_xor_neon' |
| 20 | |
| 21 | caused by the fact that chacha_doneon() has not been eliminated from the |
| 22 | object code, even though it will never be called in practice. |
| 23 | |
| 24 | Let's fix this by adding some IS_ENABLED(CONFIG_KERNEL_MODE_NEON) tests |
| 25 | that are not strictly needed from a logical point of view, but should |
| 26 | help the compiler infer that the NEON code paths are unreachable in |
| 27 | those cases. |
| 28 | |
| 29 | Fixes: b36d8c09e710c71f ("crypto: arm/chacha - remove dependency on generic ...") |
| 30 | Reported-by: Russell King <linux@armlinux.org.uk> |
| 31 | Cc: Arnd Bergmann <arnd@arndb.de> |
| 32 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> |
| 33 | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> |
| 34 | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> |
| 35 | --- |
| 36 | arch/arm/crypto/chacha-glue.c | 4 ++-- |
| 37 | 1 file changed, 2 insertions(+), 2 deletions(-) |
| 38 | |
| 39 | --- a/arch/arm/crypto/chacha-glue.c |
| 40 | +++ b/arch/arm/crypto/chacha-glue.c |
| 41 | @@ -115,7 +115,7 @@ static int chacha_stream_xor(struct skci |
| 42 | if (nbytes < walk.total) |
| 43 | nbytes = round_down(nbytes, walk.stride); |
| 44 | |
| 45 | - if (!neon) { |
| 46 | + if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon) { |
| 47 | chacha_doarm(walk.dst.virt.addr, walk.src.virt.addr, |
| 48 | nbytes, state, ctx->nrounds); |
| 49 | state[12] += DIV_ROUND_UP(nbytes, CHACHA_BLOCK_SIZE); |
| 50 | @@ -159,7 +159,7 @@ static int do_xchacha(struct skcipher_re |
| 51 | |
| 52 | chacha_init_generic(state, ctx->key, req->iv); |
| 53 | |
| 54 | - if (!neon) { |
| 55 | + if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon) { |
| 56 | hchacha_block_arm(state, subctx.key, ctx->nrounds); |
| 57 | } else { |
| 58 | kernel_neon_begin(); |