Skip to content

Commit 5ceb045

Browse files
committed
Merge branch 'for-next/cortex-strings' into for-next/core
Update our kernel string routines to the latest Cortex Strings implementation. * for-next/cortex-strings: arm64: update string routine copyrights and URLs arm64: Rewrite __arch_clear_user() arm64: Better optimised memchr() arm64: Import latest memcpy()/memmove() implementation arm64: Add assembly annotations for weak-PI-alias madness arm64: Import latest version of Cortex Strings' strncmp arm64: Import updated version of Cortex Strings' strlen arm64: Import latest version of Cortex Strings' strcmp arm64: Import latest version of Cortex Strings' memcmp
2 parents 2537720 + 6b8f648 commit 5ceb045

10 files changed

Lines changed: 915 additions & 967 deletions

File tree

arch/arm64/include/asm/linkage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@
5656
SYM_FUNC_START_ALIAS(__pi_##x); \
5757
SYM_FUNC_START_WEAK(x)
5858

59+
#define SYM_FUNC_START_WEAK_ALIAS_PI(x) \
60+
SYM_FUNC_START_ALIAS(__pi_##x); \
61+
SYM_START(x, SYM_L_WEAK, SYM_A_ALIGN)
62+
5963
#define SYM_FUNC_END_PI(x) \
6064
SYM_FUNC_END(x); \
6165
SYM_FUNC_END_ALIAS(__pi_##x)
6266

67+
#define SYM_FUNC_END_ALIAS_PI(x) \
68+
SYM_FUNC_END_ALIAS(x); \
69+
SYM_FUNC_END_ALIAS(__pi_##x)
70+
6371
#endif

arch/arm64/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
lib-y := clear_user.o delay.o copy_from_user.o \
33
copy_to_user.o copy_in_user.o copy_page.o \
4-
clear_page.o csum.o memchr.o memcpy.o memmove.o \
4+
clear_page.o csum.o memchr.o memcpy.o \
55
memset.o memcmp.o strcmp.o strncmp.o strlen.o \
66
strnlen.o strchr.o strrchr.o tishift.o
77

arch/arm64/lib/clear_user.S

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
3-
* Based on arch/arm/lib/clear_user.S
4-
*
5-
* Copyright (C) 2012 ARM Ltd.
3+
* Copyright (C) 2021 Arm Ltd.
64
*/
7-
#include <linux/linkage.h>
85

9-
#include <asm/asm-uaccess.h>
6+
#include <linux/linkage.h>
107
#include <asm/assembler.h>
118

129
.text
@@ -19,32 +16,42 @@
1916
*
2017
* Alignment fixed up by hardware.
2118
*/
19+
20+
.p2align 4
21+
// Alignment is for the loop, but since the prologue (including BTI)
22+
// is also 16 bytes we can keep any padding outside the function
2223
SYM_FUNC_START(__arch_clear_user)
23-
mov x2, x1 // save the size for fixup return
24+
add x2, x0, x1
2425
subs x1, x1, #8
2526
b.mi 2f
2627
1:
27-
user_ldst 9f, sttr, xzr, x0, 8
28+
USER(9f, sttr xzr, [x0])
29+
add x0, x0, #8
2830
subs x1, x1, #8
29-
b.pl 1b
30-
2: adds x1, x1, #4
31-
b.mi 3f
32-
user_ldst 9f, sttr, wzr, x0, 4
33-
sub x1, x1, #4
34-
3: adds x1, x1, #2
35-
b.mi 4f
36-
user_ldst 9f, sttrh, wzr, x0, 2
37-
sub x1, x1, #2
38-
4: adds x1, x1, #1
39-
b.mi 5f
40-
user_ldst 9f, sttrb, wzr, x0, 0
31+
b.hi 1b
32+
USER(9f, sttr xzr, [x2, #-8])
33+
mov x0, #0
34+
ret
35+
36+
2: tbz x1, #2, 3f
37+
USER(9f, sttr wzr, [x0])
38+
USER(8f, sttr wzr, [x2, #-4])
39+
mov x0, #0
40+
ret
41+
42+
3: tbz x1, #1, 4f
43+
USER(9f, sttrh wzr, [x0])
44+
4: tbz x1, #0, 5f
45+
USER(7f, sttrb wzr, [x2, #-1])
4146
5: mov x0, #0
4247
ret
4348
SYM_FUNC_END(__arch_clear_user)
4449
EXPORT_SYMBOL(__arch_clear_user)
4550

4651
.section .fixup,"ax"
4752
.align 2
48-
9: mov x0, x2 // return the original size
53+
7: sub x0, x2, #5 // Adjust for faulting on the final byte...
54+
8: add x0, x0, #4 // ...or the second word of the 4-7 byte case
55+
9: sub x0, x2, x0
4956
ret
5057
.previous

arch/arm64/lib/memchr.S

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
3-
* Based on arch/arm/lib/memchr.S
4-
*
5-
* Copyright (C) 1995-2000 Russell King
6-
* Copyright (C) 2013 ARM Ltd.
3+
* Copyright (C) 2021 Arm Ltd.
74
*/
85

96
#include <linux/linkage.h>
@@ -19,16 +16,60 @@
1916
* Returns:
2017
* x0 - address of first occurrence of 'c' or 0
2118
*/
19+
20+
#define L(label) .L ## label
21+
22+
#define REP8_01 0x0101010101010101
23+
#define REP8_7f 0x7f7f7f7f7f7f7f7f
24+
25+
#define srcin x0
26+
#define chrin w1
27+
#define cntin x2
28+
29+
#define result x0
30+
31+
#define wordcnt x3
32+
#define rep01 x4
33+
#define repchr x5
34+
#define cur_word x6
35+
#define cur_byte w6
36+
#define tmp x7
37+
#define tmp2 x8
38+
39+
.p2align 4
40+
nop
2241
SYM_FUNC_START_WEAK_PI(memchr)
23-
and w1, w1, #0xff
24-
1: subs x2, x2, #1
25-
b.mi 2f
26-
ldrb w3, [x0], #1
27-
cmp w3, w1
28-
b.ne 1b
29-
sub x0, x0, #1
42+
and chrin, chrin, #0xff
43+
lsr wordcnt, cntin, #3
44+
cbz wordcnt, L(byte_loop)
45+
mov rep01, #REP8_01
46+
mul repchr, x1, rep01
47+
and cntin, cntin, #7
48+
L(word_loop):
49+
ldr cur_word, [srcin], #8
50+
sub wordcnt, wordcnt, #1
51+
eor cur_word, cur_word, repchr
52+
sub tmp, cur_word, rep01
53+
orr tmp2, cur_word, #REP8_7f
54+
bics tmp, tmp, tmp2
55+
b.ne L(found_word)
56+
cbnz wordcnt, L(word_loop)
57+
L(byte_loop):
58+
cbz cntin, L(not_found)
59+
ldrb cur_byte, [srcin], #1
60+
sub cntin, cntin, #1
61+
cmp cur_byte, chrin
62+
b.ne L(byte_loop)
63+
sub srcin, srcin, #1
64+
ret
65+
L(found_word):
66+
CPU_LE( rev tmp, tmp)
67+
clz tmp, tmp
68+
sub tmp, tmp, #64
69+
add result, srcin, tmp, asr #3
3070
ret
31-
2: mov x0, #0
71+
L(not_found):
72+
mov result, #0
3273
ret
3374
SYM_FUNC_END_PI(memchr)
3475
EXPORT_SYMBOL_NOKASAN(memchr)

0 commit comments

Comments
 (0)