Skip to content

Commit dc58a24

Browse files
jamieilespalmer-dabbelt
authored andcommitted
RISC-V: preserve a1 in mcount
The RISC-V ELF psABI states that both a0 and a1 are used for return values so we should preserve them both in return_to_handler. This is especially important for RV32 for functions returning a 64-bit quantity otherwise the return value can be corrupted and undefined behaviour results. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Jamie Iles <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 3bd7743 commit dc58a24

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/riscv/kernel/mcount.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
REG_S s0, 2*SZREG(sp)
3030
REG_S ra, 3*SZREG(sp)
3131
REG_S a0, 1*SZREG(sp)
32+
REG_S a1, 0*SZREG(sp)
3233
addi s0, sp, 4*SZREG
3334
.endm
3435

@@ -42,6 +43,7 @@
4243
REG_L ra, 3*SZREG(sp)
4344
REG_L s0, 2*SZREG(sp)
4445
REG_L a0, 1*SZREG(sp)
46+
REG_L a1, 0*SZREG(sp)
4547
addi sp, sp, 4*SZREG
4648
.endm
4749

@@ -71,9 +73,9 @@ ENTRY(return_to_handler)
7173
mv a0, t6
7274
#endif
7375
call ftrace_return_to_handler
74-
mv a1, a0
76+
mv a2, a0
7577
RESTORE_RET_ABI_STATE
76-
jalr a1
78+
jalr a2
7779
ENDPROC(return_to_handler)
7880
#endif
7981

0 commit comments

Comments
 (0)