Skip to content

Commit fc74541

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64/lib: Handle CRC-32 alternative in C code
In preparation for adding another code path for performing CRC-32, move the alternative patching for ARM64_HAS_CRC32 into C code. The logic for deciding whether to use this new code path will be implemented in C too. Reviewed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20241018075347.2821102-6-ardb+git@google.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 9852d85 commit fc74541

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

arch/arm64/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif
1313

1414
lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o
1515

16-
obj-$(CONFIG_CRC32) += crc32.o
16+
obj-$(CONFIG_CRC32) += crc32.o crc32-glue.o
1717

1818
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
1919

arch/arm64/lib/crc32-glue.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/crc32.h>
4+
#include <linux/linkage.h>
5+
6+
#include <asm/alternative.h>
7+
8+
asmlinkage u32 crc32_le_arm64(u32 crc, unsigned char const *p, size_t len);
9+
asmlinkage u32 crc32c_le_arm64(u32 crc, unsigned char const *p, size_t len);
10+
asmlinkage u32 crc32_be_arm64(u32 crc, unsigned char const *p, size_t len);
11+
12+
u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
13+
{
14+
if (!alternative_has_cap_likely(ARM64_HAS_CRC32))
15+
return crc32_le_base(crc, p, len);
16+
17+
return crc32_le_arm64(crc, p, len);
18+
}
19+
20+
u32 __pure __crc32c_le(u32 crc, unsigned char const *p, size_t len)
21+
{
22+
if (!alternative_has_cap_likely(ARM64_HAS_CRC32))
23+
return __crc32c_le_base(crc, p, len);
24+
25+
return crc32c_le_arm64(crc, p, len);
26+
}
27+
28+
u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
29+
{
30+
if (!alternative_has_cap_likely(ARM64_HAS_CRC32))
31+
return crc32_be_base(crc, p, len);
32+
33+
return crc32_be_arm64(crc, p, len);
34+
}

arch/arm64/lib/crc32.S

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include <linux/linkage.h>
9-
#include <asm/alternative.h>
109
#include <asm/assembler.h>
1110

1211
.arch armv8-a+crc
@@ -136,25 +135,16 @@ CPU_BE( rev16 \reg, \reg )
136135
.endm
137136

138137
.align 5
139-
SYM_FUNC_START(crc32_le)
140-
alternative_if_not ARM64_HAS_CRC32
141-
b crc32_le_base
142-
alternative_else_nop_endif
138+
SYM_FUNC_START(crc32_le_arm64)
143139
__crc32
144-
SYM_FUNC_END(crc32_le)
140+
SYM_FUNC_END(crc32_le_arm64)
145141

146142
.align 5
147-
SYM_FUNC_START(__crc32c_le)
148-
alternative_if_not ARM64_HAS_CRC32
149-
b __crc32c_le_base
150-
alternative_else_nop_endif
143+
SYM_FUNC_START(crc32c_le_arm64)
151144
__crc32 c
152-
SYM_FUNC_END(__crc32c_le)
145+
SYM_FUNC_END(crc32c_le_arm64)
153146

154147
.align 5
155-
SYM_FUNC_START(crc32_be)
156-
alternative_if_not ARM64_HAS_CRC32
157-
b crc32_be_base
158-
alternative_else_nop_endif
148+
SYM_FUNC_START(crc32_be_arm64)
159149
__crc32 be=1
160-
SYM_FUNC_END(crc32_be)
150+
SYM_FUNC_END(crc32_be_arm64)

0 commit comments

Comments
 (0)