blob: 354f58431507d7bae81abed0155fac67bc62e7fa [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Ard Biesheuvel <ardb@kernel.org>
3Date: Fri, 17 Jan 2020 17:43:18 +0100
4Subject: [PATCH] crypto: arm/chacha - fix build failured when kernel mode NEON
5 is disabled
6
7commit 0bc81767c5bd9d005fae1099fb39eb3688370cb1 upstream.
8
9When the ARM accelerated ChaCha driver is built as part of a configuration
10that has kernel mode NEON disabled, we expect the compiler to propagate
11the build time constant expression IS_ENABLED(CONFIG_KERNEL_MODE_NEON) in
12a way that eliminates all the cross-object references to the actual NEON
13routines, which allows the chacha-neon-core.o object to be omitted from
14the build entirely.
15
16Unfortunately, this fails to work as expected in some cases, and we may
17end up with a build error such as
18
19 chacha-glue.c:(.text+0xc0): undefined reference to `chacha_4block_xor_neon'
20
21caused by the fact that chacha_doneon() has not been eliminated from the
22object code, even though it will never be called in practice.
23
24Let's fix this by adding some IS_ENABLED(CONFIG_KERNEL_MODE_NEON) tests
25that are not strictly needed from a logical point of view, but should
26help the compiler infer that the NEON code paths are unreachable in
27those cases.
28
29Fixes: b36d8c09e710c71f ("crypto: arm/chacha - remove dependency on generic ...")
30Reported-by: Russell King <linux@armlinux.org.uk>
31Cc: Arnd Bergmann <arnd@arndb.de>
32Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
33Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
34Signed-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();