Skip to content

Commit 937f659

Browse files
lslwhchenhuacai
authored andcommitted
LoongArch: Adjust {copy, clear}_user exception handler behavior
The {copy, clear}_user function should returns number of bytes that could not be {copied, cleared}. So, try to {copy, clear} byte by byte when ld.{d,w,h} and st.{d,w,h} trapped into an exception. Reviewed-by: WANG Rui <[email protected]> Signed-off-by: Weihao Li <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 0921af6 commit 937f659

File tree

2 files changed

+127
-121
lines changed

2 files changed

+127
-121
lines changed

arch/loongarch/lib/clear_user.S

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@
1111
#include <asm/cpu.h>
1212
#include <asm/regdef.h>
1313

14-
.irp to, 0, 1, 2, 3, 4, 5, 6, 7
15-
.L_fixup_handle_\to\():
16-
sub.d a0, a2, a0
17-
addi.d a0, a0, (\to) * (-8)
18-
jr ra
19-
.endr
20-
21-
.irp to, 0, 2, 4
22-
.L_fixup_handle_s\to\():
23-
addi.d a0, a1, -\to
24-
jr ra
25-
.endr
26-
2714
SYM_FUNC_START(__clear_user)
2815
/*
2916
* Some CPUs support hardware unaligned access
@@ -51,7 +38,7 @@ SYM_FUNC_START(__clear_user_generic)
5138
2: move a0, a1
5239
jr ra
5340

54-
_asm_extable 1b, .L_fixup_handle_s0
41+
_asm_extable 1b, 2b
5542
SYM_FUNC_END(__clear_user_generic)
5643

5744
/*
@@ -173,33 +160,47 @@ SYM_FUNC_START(__clear_user_fast)
173160
jr ra
174161

175162
/* fixup and ex_table */
176-
_asm_extable 0b, .L_fixup_handle_0
177-
_asm_extable 1b, .L_fixup_handle_0
178-
_asm_extable 2b, .L_fixup_handle_1
179-
_asm_extable 3b, .L_fixup_handle_2
180-
_asm_extable 4b, .L_fixup_handle_3
181-
_asm_extable 5b, .L_fixup_handle_4
182-
_asm_extable 6b, .L_fixup_handle_5
183-
_asm_extable 7b, .L_fixup_handle_6
184-
_asm_extable 8b, .L_fixup_handle_7
185-
_asm_extable 9b, .L_fixup_handle_0
186-
_asm_extable 10b, .L_fixup_handle_1
187-
_asm_extable 11b, .L_fixup_handle_2
188-
_asm_extable 12b, .L_fixup_handle_3
189-
_asm_extable 13b, .L_fixup_handle_0
190-
_asm_extable 14b, .L_fixup_handle_1
191-
_asm_extable 15b, .L_fixup_handle_0
192-
_asm_extable 16b, .L_fixup_handle_0
193-
_asm_extable 17b, .L_fixup_handle_s0
194-
_asm_extable 18b, .L_fixup_handle_s0
195-
_asm_extable 19b, .L_fixup_handle_s0
196-
_asm_extable 20b, .L_fixup_handle_s2
197-
_asm_extable 21b, .L_fixup_handle_s0
198-
_asm_extable 22b, .L_fixup_handle_s0
199-
_asm_extable 23b, .L_fixup_handle_s4
200-
_asm_extable 24b, .L_fixup_handle_s0
201-
_asm_extable 25b, .L_fixup_handle_s4
202-
_asm_extable 26b, .L_fixup_handle_s0
203-
_asm_extable 27b, .L_fixup_handle_s4
204-
_asm_extable 28b, .L_fixup_handle_s0
163+
.Llarge_fixup:
164+
sub.d a1, a2, a0
165+
166+
.Lsmall_fixup:
167+
29: st.b zero, a0, 0
168+
addi.d a0, a0, 1
169+
addi.d a1, a1, -1
170+
bgt a1, zero, 29b
171+
172+
.Lexit:
173+
move a0, a1
174+
jr ra
175+
176+
_asm_extable 0b, .Lsmall_fixup
177+
_asm_extable 1b, .Llarge_fixup
178+
_asm_extable 2b, .Llarge_fixup
179+
_asm_extable 3b, .Llarge_fixup
180+
_asm_extable 4b, .Llarge_fixup
181+
_asm_extable 5b, .Llarge_fixup
182+
_asm_extable 6b, .Llarge_fixup
183+
_asm_extable 7b, .Llarge_fixup
184+
_asm_extable 8b, .Llarge_fixup
185+
_asm_extable 9b, .Llarge_fixup
186+
_asm_extable 10b, .Llarge_fixup
187+
_asm_extable 11b, .Llarge_fixup
188+
_asm_extable 12b, .Llarge_fixup
189+
_asm_extable 13b, .Llarge_fixup
190+
_asm_extable 14b, .Llarge_fixup
191+
_asm_extable 15b, .Llarge_fixup
192+
_asm_extable 16b, .Llarge_fixup
193+
_asm_extable 17b, .Lexit
194+
_asm_extable 18b, .Lsmall_fixup
195+
_asm_extable 19b, .Lsmall_fixup
196+
_asm_extable 20b, .Lsmall_fixup
197+
_asm_extable 21b, .Lsmall_fixup
198+
_asm_extable 22b, .Lsmall_fixup
199+
_asm_extable 23b, .Lsmall_fixup
200+
_asm_extable 24b, .Lsmall_fixup
201+
_asm_extable 25b, .Lsmall_fixup
202+
_asm_extable 26b, .Lsmall_fixup
203+
_asm_extable 27b, .Lsmall_fixup
204+
_asm_extable 28b, .Lsmall_fixup
205+
_asm_extable 29b, .Lexit
205206
SYM_FUNC_END(__clear_user_fast)

arch/loongarch/lib/copy_user.S

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@
1111
#include <asm/cpu.h>
1212
#include <asm/regdef.h>
1313

14-
.irp to, 0, 1, 2, 3, 4, 5, 6, 7
15-
.L_fixup_handle_\to\():
16-
sub.d a0, a2, a0
17-
addi.d a0, a0, (\to) * (-8)
18-
jr ra
19-
.endr
20-
21-
.irp to, 0, 2, 4
22-
.L_fixup_handle_s\to\():
23-
addi.d a0, a2, -\to
24-
jr ra
25-
.endr
26-
2714
SYM_FUNC_START(__copy_user)
2815
/*
2916
* Some CPUs support hardware unaligned access
@@ -54,8 +41,8 @@ SYM_FUNC_START(__copy_user_generic)
5441
3: move a0, a2
5542
jr ra
5643

57-
_asm_extable 1b, .L_fixup_handle_s0
58-
_asm_extable 2b, .L_fixup_handle_s0
44+
_asm_extable 1b, 3b
45+
_asm_extable 2b, 3b
5946
SYM_FUNC_END(__copy_user_generic)
6047

6148
/*
@@ -69,10 +56,10 @@ SYM_FUNC_START(__copy_user_fast)
6956
sltui t0, a2, 9
7057
bnez t0, .Lsmall
7158

72-
add.d a3, a1, a2
73-
add.d a2, a0, a2
7459
0: ld.d t0, a1, 0
7560
1: st.d t0, a0, 0
61+
add.d a3, a1, a2
62+
add.d a2, a0, a2
7663

7764
/* align up destination address */
7865
andi t1, a0, 7
@@ -94,7 +81,6 @@ SYM_FUNC_START(__copy_user_fast)
9481
7: ld.d t5, a1, 40
9582
8: ld.d t6, a1, 48
9683
9: ld.d t7, a1, 56
97-
addi.d a1, a1, 64
9884
10: st.d t0, a0, 0
9985
11: st.d t1, a0, 8
10086
12: st.d t2, a0, 16
@@ -103,6 +89,7 @@ SYM_FUNC_START(__copy_user_fast)
10389
15: st.d t5, a0, 40
10490
16: st.d t6, a0, 48
10591
17: st.d t7, a0, 56
92+
addi.d a1, a1, 64
10693
addi.d a0, a0, 64
10794
bltu a1, a4, .Lloop64
10895

@@ -114,28 +101,29 @@ SYM_FUNC_START(__copy_user_fast)
114101
19: ld.d t1, a1, 8
115102
20: ld.d t2, a1, 16
116103
21: ld.d t3, a1, 24
117-
addi.d a1, a1, 32
118104
22: st.d t0, a0, 0
119105
23: st.d t1, a0, 8
120106
24: st.d t2, a0, 16
121107
25: st.d t3, a0, 24
108+
addi.d a1, a1, 32
122109
addi.d a0, a0, 32
123110

124111
.Llt32:
125112
addi.d a4, a3, -16
126113
bgeu a1, a4, .Llt16
127114
26: ld.d t0, a1, 0
128115
27: ld.d t1, a1, 8
129-
addi.d a1, a1, 16
130116
28: st.d t0, a0, 0
131117
29: st.d t1, a0, 8
118+
addi.d a1, a1, 16
132119
addi.d a0, a0, 16
133120

134121
.Llt16:
135122
addi.d a4, a3, -8
136123
bgeu a1, a4, .Llt8
137124
30: ld.d t0, a1, 0
138125
31: st.d t0, a0, 0
126+
addi.d a1, a1, 8
139127
addi.d a0, a0, 8
140128

141129
.Llt8:
@@ -214,62 +202,79 @@ SYM_FUNC_START(__copy_user_fast)
214202
jr ra
215203

216204
/* fixup and ex_table */
217-
_asm_extable 0b, .L_fixup_handle_0
218-
_asm_extable 1b, .L_fixup_handle_0
219-
_asm_extable 2b, .L_fixup_handle_0
220-
_asm_extable 3b, .L_fixup_handle_0
221-
_asm_extable 4b, .L_fixup_handle_0
222-
_asm_extable 5b, .L_fixup_handle_0
223-
_asm_extable 6b, .L_fixup_handle_0
224-
_asm_extable 7b, .L_fixup_handle_0
225-
_asm_extable 8b, .L_fixup_handle_0
226-
_asm_extable 9b, .L_fixup_handle_0
227-
_asm_extable 10b, .L_fixup_handle_0
228-
_asm_extable 11b, .L_fixup_handle_1
229-
_asm_extable 12b, .L_fixup_handle_2
230-
_asm_extable 13b, .L_fixup_handle_3
231-
_asm_extable 14b, .L_fixup_handle_4
232-
_asm_extable 15b, .L_fixup_handle_5
233-
_asm_extable 16b, .L_fixup_handle_6
234-
_asm_extable 17b, .L_fixup_handle_7
235-
_asm_extable 18b, .L_fixup_handle_0
236-
_asm_extable 19b, .L_fixup_handle_0
237-
_asm_extable 20b, .L_fixup_handle_0
238-
_asm_extable 21b, .L_fixup_handle_0
239-
_asm_extable 22b, .L_fixup_handle_0
240-
_asm_extable 23b, .L_fixup_handle_1
241-
_asm_extable 24b, .L_fixup_handle_2
242-
_asm_extable 25b, .L_fixup_handle_3
243-
_asm_extable 26b, .L_fixup_handle_0
244-
_asm_extable 27b, .L_fixup_handle_0
245-
_asm_extable 28b, .L_fixup_handle_0
246-
_asm_extable 29b, .L_fixup_handle_1
247-
_asm_extable 30b, .L_fixup_handle_0
248-
_asm_extable 31b, .L_fixup_handle_0
249-
_asm_extable 32b, .L_fixup_handle_0
250-
_asm_extable 33b, .L_fixup_handle_0
251-
_asm_extable 34b, .L_fixup_handle_s0
252-
_asm_extable 35b, .L_fixup_handle_s0
253-
_asm_extable 36b, .L_fixup_handle_s0
254-
_asm_extable 37b, .L_fixup_handle_s0
255-
_asm_extable 38b, .L_fixup_handle_s0
256-
_asm_extable 39b, .L_fixup_handle_s0
257-
_asm_extable 40b, .L_fixup_handle_s0
258-
_asm_extable 41b, .L_fixup_handle_s2
259-
_asm_extable 42b, .L_fixup_handle_s0
260-
_asm_extable 43b, .L_fixup_handle_s0
261-
_asm_extable 44b, .L_fixup_handle_s0
262-
_asm_extable 45b, .L_fixup_handle_s0
263-
_asm_extable 46b, .L_fixup_handle_s0
264-
_asm_extable 47b, .L_fixup_handle_s4
265-
_asm_extable 48b, .L_fixup_handle_s0
266-
_asm_extable 49b, .L_fixup_handle_s0
267-
_asm_extable 50b, .L_fixup_handle_s0
268-
_asm_extable 51b, .L_fixup_handle_s4
269-
_asm_extable 52b, .L_fixup_handle_s0
270-
_asm_extable 53b, .L_fixup_handle_s0
271-
_asm_extable 54b, .L_fixup_handle_s0
272-
_asm_extable 55b, .L_fixup_handle_s4
273-
_asm_extable 56b, .L_fixup_handle_s0
274-
_asm_extable 57b, .L_fixup_handle_s0
205+
.Llarge_fixup:
206+
sub.d a2, a2, a0
207+
208+
.Lsmall_fixup:
209+
58: ld.b t0, a1, 0
210+
59: st.b t0, a0, 0
211+
addi.d a0, a0, 1
212+
addi.d a1, a1, 1
213+
addi.d a2, a2, -1
214+
bgt a2, zero, 58b
215+
216+
.Lexit:
217+
move a0, a2
218+
jr ra
219+
220+
_asm_extable 0b, .Lsmall_fixup
221+
_asm_extable 1b, .Lsmall_fixup
222+
_asm_extable 2b, .Llarge_fixup
223+
_asm_extable 3b, .Llarge_fixup
224+
_asm_extable 4b, .Llarge_fixup
225+
_asm_extable 5b, .Llarge_fixup
226+
_asm_extable 6b, .Llarge_fixup
227+
_asm_extable 7b, .Llarge_fixup
228+
_asm_extable 8b, .Llarge_fixup
229+
_asm_extable 9b, .Llarge_fixup
230+
_asm_extable 10b, .Llarge_fixup
231+
_asm_extable 11b, .Llarge_fixup
232+
_asm_extable 12b, .Llarge_fixup
233+
_asm_extable 13b, .Llarge_fixup
234+
_asm_extable 14b, .Llarge_fixup
235+
_asm_extable 15b, .Llarge_fixup
236+
_asm_extable 16b, .Llarge_fixup
237+
_asm_extable 17b, .Llarge_fixup
238+
_asm_extable 18b, .Llarge_fixup
239+
_asm_extable 19b, .Llarge_fixup
240+
_asm_extable 20b, .Llarge_fixup
241+
_asm_extable 21b, .Llarge_fixup
242+
_asm_extable 22b, .Llarge_fixup
243+
_asm_extable 23b, .Llarge_fixup
244+
_asm_extable 24b, .Llarge_fixup
245+
_asm_extable 25b, .Llarge_fixup
246+
_asm_extable 26b, .Llarge_fixup
247+
_asm_extable 27b, .Llarge_fixup
248+
_asm_extable 28b, .Llarge_fixup
249+
_asm_extable 29b, .Llarge_fixup
250+
_asm_extable 30b, .Llarge_fixup
251+
_asm_extable 31b, .Llarge_fixup
252+
_asm_extable 32b, .Llarge_fixup
253+
_asm_extable 33b, .Llarge_fixup
254+
_asm_extable 34b, .Lexit
255+
_asm_extable 35b, .Lexit
256+
_asm_extable 36b, .Lsmall_fixup
257+
_asm_extable 37b, .Lsmall_fixup
258+
_asm_extable 38b, .Lsmall_fixup
259+
_asm_extable 39b, .Lsmall_fixup
260+
_asm_extable 40b, .Lsmall_fixup
261+
_asm_extable 41b, .Lsmall_fixup
262+
_asm_extable 42b, .Lsmall_fixup
263+
_asm_extable 43b, .Lsmall_fixup
264+
_asm_extable 44b, .Lsmall_fixup
265+
_asm_extable 45b, .Lsmall_fixup
266+
_asm_extable 46b, .Lsmall_fixup
267+
_asm_extable 47b, .Lsmall_fixup
268+
_asm_extable 48b, .Lsmall_fixup
269+
_asm_extable 49b, .Lsmall_fixup
270+
_asm_extable 50b, .Lsmall_fixup
271+
_asm_extable 51b, .Lsmall_fixup
272+
_asm_extable 52b, .Lsmall_fixup
273+
_asm_extable 53b, .Lsmall_fixup
274+
_asm_extable 54b, .Lsmall_fixup
275+
_asm_extable 55b, .Lsmall_fixup
276+
_asm_extable 56b, .Lsmall_fixup
277+
_asm_extable 57b, .Lsmall_fixup
278+
_asm_extable 58b, .Lexit
279+
_asm_extable 59b, .Lexit
275280
SYM_FUNC_END(__copy_user_fast)

0 commit comments

Comments
 (0)