Skip to content

Commit ab9164d

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: entry: Consolidate ret_from_kernel_thread into ret_from_fork
The ret_from_kernel_thread() behaves similarly with ret_from_fork(), the only difference is whether call the fn(arg) or not, this can be achieved by testing fn is NULL or not, I.E s0 is 0 or not. Many architectures have done the same thing, it makes entry.S more clean. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Reviewed-by: Guo Ren <guoren@kernel.org> Tested-by: Guo Ren <guoren@kernel.org> Signed-off-by: Guo Ren <guoren@kernel.org> Link: https://lore.kernel.org/r/20230222033021.983168-7-guoren@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 0bf298a commit ab9164d

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

arch/riscv/kernel/entry.S

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ SYM_CODE_END(handle_exception)
132132
* caller list:
133133
* - handle_exception
134134
* - ret_from_fork
135-
* - ret_from_kernel_thread
136135
*/
137136
SYM_CODE_START_NOALIGN(ret_from_exception)
138137
REG_L s0, PT_STATUS(sp)
@@ -334,20 +333,15 @@ SYM_CODE_END(handle_kernel_stack_overflow)
334333

335334
SYM_CODE_START(ret_from_fork)
336335
call schedule_tail
337-
move a0, sp /* pt_regs */
338-
la ra, ret_from_exception
339-
tail syscall_exit_to_user_mode
340-
SYM_CODE_END(ret_from_fork)
341-
342-
SYM_CODE_START(ret_from_kernel_thread)
343-
call schedule_tail
336+
beqz s0, 1f /* not from kernel thread */
344337
/* Call fn(arg) */
345338
move a0, s1
346339
jalr s0
340+
1:
347341
move a0, sp /* pt_regs */
348342
la ra, ret_from_exception
349343
tail syscall_exit_to_user_mode
350-
SYM_CODE_END(ret_from_kernel_thread)
344+
SYM_CODE_END(ret_from_fork)
351345

352346
/*
353347
* Integer register context switch

arch/riscv/kernel/process.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ EXPORT_SYMBOL(__stack_chk_guard);
3434
#endif
3535

3636
extern asmlinkage void ret_from_fork(void);
37-
extern asmlinkage void ret_from_kernel_thread(void);
3837

3938
void arch_cpu_idle(void)
4039
{
@@ -173,7 +172,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
173172
/* Supervisor/Machine, irqs on: */
174173
childregs->status = SR_PP | SR_PIE;
175174

176-
p->thread.ra = (unsigned long)ret_from_kernel_thread;
177175
p->thread.s[0] = (unsigned long)args->fn;
178176
p->thread.s[1] = (unsigned long)args->fn_arg;
179177
} else {
@@ -183,8 +181,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
183181
if (clone_flags & CLONE_SETTLS)
184182
childregs->tp = tls;
185183
childregs->a0 = 0; /* Return value of fork() */
186-
p->thread.ra = (unsigned long)ret_from_fork;
184+
p->thread.s[0] = 0;
187185
}
186+
p->thread.ra = (unsigned long)ret_from_fork;
188187
p->thread.sp = (unsigned long)childregs; /* kernel sp */
189188
return 0;
190189
}

0 commit comments

Comments
 (0)