Skip to content

Commit 9c2598d

Browse files
bjorn-rivospalmer-dabbelt
authored andcommitted
riscv: entry: Save a0 prior syscall_enter_from_user_mode()
The RISC-V calling convention passes the first argument, and the return value in the a0 register. For this reason, the a0 register needs some extra care; When handling syscalls, the a0 register is saved into regs->orig_a0, so a0 can be properly restored for, e.g. interrupted syscalls. This functionality was broken with the introduction of the generic entry patches. Here, a0 was saved into orig_a0 after calling syscall_enter_from_user_mode(), which can change regs->a0 for some paths, incorrectly restoring a0. This is resolved, by saving a0 prior doing the syscall_enter_from_user_mode() call. Fixes: f0bddf5 ("riscv: entry: Convert to generic entry") Reviewed-by: Heiko Stuebner <heiko.stuebner@vrull.eu> Tested-by: Heiko Stuebner <heiko.stuebner@vrull.eu> Signed-off-by: Björn Töpel <bjorn@rivosinc.com> Reported-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Tested-by: Conor Dooley <conor.dooley@microchip.com> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Andy Chiu <andy.chiu@sifive.com> Link: https://lore.kernel.org/r/20230403065207.1070974-1-bjorn@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent d34a6b7 commit 9c2598d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/riscv/kernel/traps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
270270
if (user_mode(regs)) {
271271
ulong syscall = regs->a7;
272272

273-
syscall = syscall_enter_from_user_mode(regs, syscall);
274-
275273
regs->epc += 4;
276274
regs->orig_a0 = regs->a0;
277275

276+
syscall = syscall_enter_from_user_mode(regs, syscall);
277+
278278
if (syscall < NR_syscalls)
279279
syscall_handler(regs, syscall);
280280
else

0 commit comments

Comments
 (0)