Skip to content

Commit 02ce496

Browse files
author
Al Viro
committed
frv: split ret_from_fork, simplify kernel_thread() a lot
Acked-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d878d6d commit 02ce496

5 files changed

Lines changed: 32 additions & 100 deletions

File tree

‎arch/frv/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ heads-$(CONFIG_MMU) := head-mmu-fr451.o
77

88
extra-y:= head.o vmlinux.lds
99

10-
obj-y := $(heads-y) entry.o entry-table.o break.o switch_to.o kernel_thread.o \
10+
obj-y := $(heads-y) entry.o entry-table.o break.o switch_to.o \
1111
kernel_execve.o process.o traps.o ptrace.o signal.o dma.o \
1212
sys_frv.o time.o setup.o frv_ksyms.o \
1313
debug-stub.o irq.o sleep.o uaccess.o

‎arch/frv/kernel/entry.S‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,14 @@ ret_from_fork:
863863
setlos.p #0,gr8
864864
bra __syscall_exit
865865

866+
.globl ret_from_kernel_thread
867+
ret_from_kernel_thread:
868+
lddi.p @(gr28,#REG_GR(8)),gr20
869+
call schedule_tail
870+
or.p gr20,gr20,gr8
871+
calll @(gr21,gr0)
872+
bra sys_exit
873+
866874
###################################################################################################
867875
#
868876
# Return to user mode is not as complex as all this looks,

‎arch/frv/kernel/frv_ksyms.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ EXPORT_SYMBOL(ip_fast_csum);
3030
EXPORT_SYMBOL(local_irq_count);
3131
EXPORT_SYMBOL(local_bh_count);
3232
#endif
33-
EXPORT_SYMBOL(kernel_thread);
3433

3534
EXPORT_SYMBOL(__res_bus_clock_speed_HZ);
3635
EXPORT_SYMBOL(__page_offset);

‎arch/frv/kernel/kernel_thread.S‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

‎arch/frv/kernel/process.c‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "local.h"
3838

3939
asmlinkage void ret_from_fork(void);
40+
asmlinkage void ret_from_kernel_thread(void);
4041

4142
#include <asm/pgalloc.h>
4243

@@ -172,29 +173,21 @@ int copy_thread(unsigned long clone_flags,
172173
unsigned long usp, unsigned long topstk,
173174
struct task_struct *p, struct pt_regs *regs)
174175
{
175-
struct pt_regs *childregs0, *childregs, *regs0;
176+
struct pt_regs *childregs;
176177

177-
regs0 = __kernel_frame0_ptr;
178-
childregs0 = (struct pt_regs *)
178+
childregs = (struct pt_regs *)
179179
(task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
180-
childregs = childregs0;
181180

182181
/* set up the userspace frame (the only place that the USP is stored) */
183-
*childregs0 = *regs0;
184-
185-
childregs0->gr8 = 0;
186-
childregs0->sp = usp;
187-
childregs0->next_frame = NULL;
188-
189-
/* set up the return kernel frame if called from kernel_thread() */
190-
if (regs != regs0) {
191-
childregs--;
192-
*childregs = *regs;
193-
childregs->sp = (unsigned long) childregs0;
194-
childregs->next_frame = childregs0;
195-
childregs->gr15 = (unsigned long) task_thread_info(p);
196-
childregs->gr29 = (unsigned long) p;
197-
}
182+
*childregs = *regs;
183+
184+
childregs->sp = usp;
185+
childregs->next_frame = NULL;
186+
187+
if (unlikely(!user_mode(regs)))
188+
p->thread.pc = (unsigned long) ret_from_kernel_thread;
189+
else
190+
p->thread.pc = (unsigned long) ret_from_fork;
198191

199192
p->set_child_tid = p->clear_child_tid = NULL;
200193

@@ -203,8 +196,7 @@ int copy_thread(unsigned long clone_flags,
203196
p->thread.sp = (unsigned long) childregs;
204197
p->thread.fp = 0;
205198
p->thread.lr = 0;
206-
p->thread.pc = (unsigned long) ret_from_fork;
207-
p->thread.frame0 = childregs0;
199+
p->thread.frame0 = childregs;
208200

209201
/* the new TLS pointer is passed in as arg #5 to sys_clone() */
210202
if (clone_flags & CLONE_SETTLS)
@@ -347,3 +339,13 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
347339
sizeof(current->thread.user->f));
348340
return 1;
349341
}
342+
343+
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
344+
{
345+
struct pt_regs regs = {
346+
.gr8 = (unsigned long)arg;
347+
.gr9 = (unsigned long)fn;
348+
.psr = PSR_S;
349+
};
350+
return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
351+
}

0 commit comments

Comments
 (0)