Skip to content

Commit 5f99c1a

Browse files
Michael KarcherUlrich Hecht
authored andcommitted
sparc: fix accurate exception reporting in copy_{from_to}_user for Niagara
[ Upstream commit 0b67c8fc10b13a9090340c5f8a37d308f4e1571c ] The referenced commit introduced exception handlers on user-space memory references in copy_from_user and copy_to_user. These handlers return from the respective function and calculate the remaining bytes left to copy using the current register contents. This commit fixes a couple of bad calculations and a broken epilogue in the exception handlers. This will prevent crashes and ensure correct return values of copy_from_user and copy_to_user in the faulting case. The behaviour of memcpy stays unchanged. Fixes: 7ae3aaf ("sparc64: Convert NGcopy_{from,to}_user to accurate exception reporting.") Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> # on SPARC T4 with modified kernel to use Niagara 1 code Tested-by: Magnus Lindholm <linmag7@gmail.com> # on Sun Fire T2000 Signed-off-by: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de> Tested-by: Ethan Hawke <ehawk@ember.systems> # on Sun Fire T2000 Tested-by: Ken Link <iissmart@numberzero.org> # on Sun Fire T1000 Reviewed-by: Andreas Larsson <andreas@gaisler.com> Link: https://lore.kernel.org/r/20250905-memcpy_series-v4-3-1ca72dda195b@mkarcher.dialup.fu-berlin.de Signed-off-by: Andreas Larsson <andreas@gaisler.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent efa34f1 commit 5f99c1a

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

arch/sparc/lib/NGmemcpy.S

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
#ifndef EX_RETVAL
8181
#define EX_RETVAL(x) x
8282
__restore_asi:
83-
ret
8483
wr %g0, ASI_AIUS, %asi
84+
ret
8585
restore
8686
ENTRY(NG_ret_i2_plus_i4_plus_1)
8787
ba,pt %xcc, __restore_asi
@@ -126,15 +126,16 @@ ENTRY(NG_ret_i2_plus_g1_minus_56)
126126
ba,pt %xcc, __restore_asi
127127
add %i2, %g1, %i0
128128
ENDPROC(NG_ret_i2_plus_g1_minus_56)
129-
ENTRY(NG_ret_i2_plus_i4)
129+
ENTRY(NG_ret_i2_plus_i4_plus_16)
130+
add %i4, 16, %i4
130131
ba,pt %xcc, __restore_asi
131132
add %i2, %i4, %i0
132-
ENDPROC(NG_ret_i2_plus_i4)
133-
ENTRY(NG_ret_i2_plus_i4_minus_8)
134-
sub %i4, 8, %i4
133+
ENDPROC(NG_ret_i2_plus_i4_plus_16)
134+
ENTRY(NG_ret_i2_plus_i4_plus_8)
135+
add %i4, 8, %i4
135136
ba,pt %xcc, __restore_asi
136137
add %i2, %i4, %i0
137-
ENDPROC(NG_ret_i2_plus_i4_minus_8)
138+
ENDPROC(NG_ret_i2_plus_i4_plus_8)
138139
ENTRY(NG_ret_i2_plus_8)
139140
ba,pt %xcc, __restore_asi
140141
add %i2, 8, %i0
@@ -161,6 +162,12 @@ ENTRY(NG_ret_i2_and_7_plus_i4)
161162
ba,pt %xcc, __restore_asi
162163
add %i2, %i4, %i0
163164
ENDPROC(NG_ret_i2_and_7_plus_i4)
165+
ENTRY(NG_ret_i2_and_7_plus_i4_plus_8)
166+
and %i2, 7, %i2
167+
add %i4, 8, %i4
168+
ba,pt %xcc, __restore_asi
169+
add %i2, %i4, %i0
170+
ENDPROC(NG_ret_i2_and_7_plus_i4)
164171
#endif
165172

166173
.align 64
@@ -406,13 +413,13 @@ FUNC_NAME: /* %i0=dst, %i1=src, %i2=len */
406413
andn %i2, 0xf, %i4
407414
and %i2, 0xf, %i2
408415
1: subcc %i4, 0x10, %i4
409-
EX_LD(LOAD(ldx, %i1, %o4), NG_ret_i2_plus_i4)
416+
EX_LD(LOAD(ldx, %i1, %o4), NG_ret_i2_plus_i4_plus_16)
410417
add %i1, 0x08, %i1
411-
EX_LD(LOAD(ldx, %i1, %g1), NG_ret_i2_plus_i4)
418+
EX_LD(LOAD(ldx, %i1, %g1), NG_ret_i2_plus_i4_plus_16)
412419
sub %i1, 0x08, %i1
413-
EX_ST(STORE(stx, %o4, %i1 + %i3), NG_ret_i2_plus_i4)
420+
EX_ST(STORE(stx, %o4, %i1 + %i3), NG_ret_i2_plus_i4_plus_16)
414421
add %i1, 0x8, %i1
415-
EX_ST(STORE(stx, %g1, %i1 + %i3), NG_ret_i2_plus_i4_minus_8)
422+
EX_ST(STORE(stx, %g1, %i1 + %i3), NG_ret_i2_plus_i4_plus_8)
416423
bgu,pt %XCC, 1b
417424
add %i1, 0x8, %i1
418425
73: andcc %i2, 0x8, %g0
@@ -469,7 +476,7 @@ FUNC_NAME: /* %i0=dst, %i1=src, %i2=len */
469476
subcc %i4, 0x8, %i4
470477
srlx %g3, %i3, %i5
471478
or %i5, %g2, %i5
472-
EX_ST(STORE(stx, %i5, %o0), NG_ret_i2_and_7_plus_i4)
479+
EX_ST(STORE(stx, %i5, %o0), NG_ret_i2_and_7_plus_i4_plus_8)
473480
add %o0, 0x8, %o0
474481
bgu,pt %icc, 1b
475482
sllx %g3, %g1, %g2

0 commit comments

Comments
 (0)