Skip to content

Commit f955aa8

Browse files
charlie-rivosKAGA-KOKO
authored andcommitted
riscv: entry: Convert ret_from_fork() to C
Move the main section of ret_from_fork() to C to allow inlining of syscall_exit_to_user_mode(). Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/all/20250320-riscv_optimize_entry-v6-1-63e187e26041@rivosinc.com
1 parent b443265 commit f955aa8

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

arch/riscv/include/asm/asm-prototypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ DECLARE_DO_ERROR_INFO(do_trap_ecall_s);
5252
DECLARE_DO_ERROR_INFO(do_trap_ecall_m);
5353
DECLARE_DO_ERROR_INFO(do_trap_break);
5454

55+
asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), struct pt_regs *regs);
5556
asmlinkage void handle_bad_stack(struct pt_regs *regs);
5657
asmlinkage void do_page_fault(struct pt_regs *regs);
5758
asmlinkage void do_irq(struct pt_regs *regs);

arch/riscv/kernel/entry.S

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,14 @@ SYM_CODE_END(handle_kernel_stack_overflow)
319319
ASM_NOKPROBE(handle_kernel_stack_overflow)
320320
#endif
321321

322-
SYM_CODE_START(ret_from_fork)
322+
SYM_CODE_START(ret_from_fork_asm)
323323
call schedule_tail
324-
beqz s0, 1f /* not from kernel thread */
325-
/* Call fn(arg) */
326-
move a0, s1
327-
jalr s0
328-
1:
329-
move a0, sp /* pt_regs */
330-
call syscall_exit_to_user_mode
324+
move a0, s1 /* fn_arg */
325+
move a1, s0 /* fn */
326+
move a2, sp /* pt_regs */
327+
call ret_from_fork
331328
j ret_from_exception
332-
SYM_CODE_END(ret_from_fork)
329+
SYM_CODE_END(ret_from_fork_asm)
333330

334331
#ifdef CONFIG_IRQ_STACKS
335332
/*

arch/riscv/kernel/process.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include <linux/ptrace.h>
1818
#include <linux/uaccess.h>
1919
#include <linux/personality.h>
20+
#include <linux/entry-common.h>
2021

22+
#include <asm/asm-prototypes.h>
2123
#include <asm/unistd.h>
2224
#include <asm/processor.h>
2325
#include <asm/csr.h>
@@ -36,7 +38,7 @@ unsigned long __stack_chk_guard __read_mostly;
3638
EXPORT_SYMBOL(__stack_chk_guard);
3739
#endif
3840

39-
extern asmlinkage void ret_from_fork(void);
41+
extern asmlinkage void ret_from_fork_asm(void);
4042

4143
void noinstr arch_cpu_idle(void)
4244
{
@@ -206,6 +208,14 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
206208
return 0;
207209
}
208210

211+
asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), struct pt_regs *regs)
212+
{
213+
if (unlikely(fn))
214+
fn(fn_arg);
215+
216+
syscall_exit_to_user_mode(regs);
217+
}
218+
209219
int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
210220
{
211221
unsigned long clone_flags = args->flags;
@@ -242,7 +252,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
242252
p->thread.riscv_v_flags = 0;
243253
if (has_vector() || has_xtheadvector())
244254
riscv_v_thread_alloc(p);
245-
p->thread.ra = (unsigned long)ret_from_fork;
255+
p->thread.ra = (unsigned long)ret_from_fork_asm;
246256
p->thread.sp = (unsigned long)childregs; /* kernel sp */
247257
return 0;
248258
}

0 commit comments

Comments
 (0)