Re: [PATCH -next 4/7] riscv: syscall: Don't clobber s0 when syscall

From: Guo Ren
Date: Tue Sep 20 2022 - 21:31:11 EST


On Tue, Sep 20, 2022 at 11:15 PM Chen Zhongjin <chenzhongjin@xxxxxxxxxx> wrote:
>
> syscall uses s0 to load address of sys_call_table.
>
> Since now we uses s0 to save pt_regs for unwinding, clobber
> s0 can make unwinder treat s0 as pt_regs address. Use s1 for
> this job.
This patch does not make sense. Why couldn't we use s1 for pt_regs?

No need to modify the entry.S here.

>
> Signed-off-by: Chen Zhongjin <chenzhongjin@xxxxxxxxxx>
> ---
> arch/riscv/kernel/entry.S | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
> index ecb15c7430b4..a3b14a649782 100644
> --- a/arch/riscv/kernel/entry.S
> +++ b/arch/riscv/kernel/entry.S
> @@ -205,33 +205,33 @@ handle_syscall:
> check_syscall_nr:
> /* Check to make sure we don't jump to a bogus syscall number. */
> li t0, __NR_syscalls
> - la s0, sys_ni_syscall
> + la s1, sys_ni_syscall
> /*
> * Syscall number held in a7.
> * If syscall number is above allowed value, redirect to ni_syscall.
> */
> bgeu a7, t0, 3f
> #ifdef CONFIG_COMPAT
> - REG_L s0, PT_STATUS(sp)
> - srli s0, s0, SR_UXL_SHIFT
> - andi s0, s0, (SR_UXL >> SR_UXL_SHIFT)
> + REG_L s1, PT_STATUS(sp)
> + srli s1, s1, SR_UXL_SHIFT
> + andi s1, s1, (SR_UXL >> SR_UXL_SHIFT)
> li t0, (SR_UXL_32 >> SR_UXL_SHIFT)
> - sub t0, s0, t0
> + sub t0, s1, t0
> bnez t0, 1f
>
> /* Call compat_syscall */
> - la s0, compat_sys_call_table
> + la s1, compat_sys_call_table
> j 2f
> 1:
> #endif
> /* Call syscall */
> - la s0, sys_call_table
> + la s1, sys_call_table
> 2:
> slli t0, a7, RISCV_LGPTR
> - add s0, s0, t0
> - REG_L s0, 0(s0)
> + add s1, s1, t0
> + REG_L s1, 0(s1)
> 3:
> - jalr s0
> + jalr s1
>
> ret_from_syscall:
> /* Set user a0 to kernel a0 */
> --
> 2.17.1
>


--
Best Regards
Guo Ren