All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve()
@ 2012-10-19  8:43 Guan Xuetao
  2012-10-19  8:43 ` [PATCH 2/2] unicore32: switch to generic sys_execve() Guan Xuetao
  2012-10-19 13:18 ` [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Al Viro
  0 siblings, 2 replies; 4+ messages in thread
From: Guan Xuetao @ 2012-10-19  8:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-and-Tested-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
---
 arch/unicore32/Kconfig                 |    2 +
 arch/unicore32/include/asm/processor.h |    5 ---
 arch/unicore32/kernel/entry.S          |   15 ++++----
 arch/unicore32/kernel/process.c        |   58 ++++++++------------------------
 arch/unicore32/kernel/sys.c            |   42 -----------------------
 5 files changed, 23 insertions(+), 99 deletions(-)

diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index 5b95ba4..fda37c9 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -16,6 +16,8 @@ config UNICORE32
 	select ARCH_WANT_FRAME_POINTERS
 	select GENERIC_IOMAP
 	select MODULES_USE_ELF_REL
+	select GENERIC_KERNEL_THREAD
+	select GENERIC_KERNEL_EXECVE
 	help
 	  UniCore-32 is 32-bit Instruction Set Architecture,
 	  including a series of low-power-consumption RISC chip
diff --git a/arch/unicore32/include/asm/processor.h b/arch/unicore32/include/asm/processor.h
index 14382cb..4eaa421 100644
--- a/arch/unicore32/include/asm/processor.h
+++ b/arch/unicore32/include/asm/processor.h
@@ -72,11 +72,6 @@ unsigned long get_wchan(struct task_struct *p);
 
 #define cpu_relax()			barrier()
 
-/*
- * Create a new kernel thread
- */
-extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
-
 #define task_pt_regs(p) \
 	((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
 
diff --git a/arch/unicore32/kernel/entry.S b/arch/unicore32/kernel/entry.S
index dcb87ab..32648c9 100644
--- a/arch/unicore32/kernel/entry.S
+++ b/arch/unicore32/kernel/entry.S
@@ -573,17 +573,16 @@ ENDPROC(ret_to_user)
  */
 ENTRY(ret_from_fork)
 	b.l	schedule_tail
-	get_thread_info tsk
-	ldw	r1, [tsk+], #TI_FLAGS		@ check for syscall tracing
-	mov	why, #1
-	cand.a	r1, #_TIF_SYSCALL_TRACE		@ are we tracing syscalls?
-	beq	ret_slow_syscall
-	mov	r1, sp
-	mov	r0, #1				@ trace exit [IP = 1]
-	b.l	syscall_trace
 	b	ret_slow_syscall
 ENDPROC(ret_from_fork)
 
+ENTRY(ret_from_kernel_thread)
+	b.l	schedule_tail
+	mov	r0, r5
+	adr	lr, ret_slow_syscall
+	mov	pc, r4
+ENDPROC(ret_from_kernel_thread)
+
 /*=============================================================================
  * SWI handler
  *-----------------------------------------------------------------------------
diff --git a/arch/unicore32/kernel/process.c b/arch/unicore32/kernel/process.c
index b008586..a8fe265 100644
--- a/arch/unicore32/kernel/process.c
+++ b/arch/unicore32/kernel/process.c
@@ -258,6 +258,7 @@ void release_thread(struct task_struct *dead_task)
 }
 
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
+asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
 
 int
 copy_thread(unsigned long clone_flags, unsigned long stack_start,
@@ -266,17 +267,22 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start,
 	struct thread_info *thread = task_thread_info(p);
 	struct pt_regs *childregs = task_pt_regs(p);
 
-	*childregs = *regs;
-	childregs->UCreg_00 = 0;
-	childregs->UCreg_sp = stack_start;
-
 	memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save));
 	thread->cpu_context.sp = (unsigned long)childregs;
-	thread->cpu_context.pc = (unsigned long)ret_from_fork;
-
-	if (clone_flags & CLONE_SETTLS)
-		childregs->UCreg_16 = regs->UCreg_03;
+	if (unlikely(!regs)) {
+		thread->cpu_context.pc = (unsigned long)ret_from_kernel_thread;
+		thread->cpu_context.r4 = stack_start;
+		thread->cpu_context.r5 = stk_sz;
+		memset(childregs, 0, sizeof(struct pt_regs));
+	} else {
+		thread->cpu_context.pc = (unsigned long)ret_from_fork;
+		*childregs = *regs;
+		childregs->UCreg_00 = 0;
+		childregs->UCreg_sp = stack_start;
 
+		if (clone_flags & CLONE_SETTLS)
+			childregs->UCreg_16 = regs->UCreg_03;
+	}
 	return 0;
 }
 
@@ -305,42 +311,6 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fp)
 }
 EXPORT_SYMBOL(dump_fpu);
 
-/*
- * Shuffle the argument into the correct register before calling the
- * thread function.  r1 is the thread argument, r2 is the pointer to
- * the thread function, and r3 points to the exit function.
- */
-asm(".pushsection .text\n"
-"	.align\n"
-"	.type	kernel_thread_helper, #function\n"
-"kernel_thread_helper:\n"
-"	mov.a	asr, r7\n"
-"	mov	r0, r4\n"
-"	mov	lr, r6\n"
-"	mov	pc, r5\n"
-"	.size	kernel_thread_helper, . - kernel_thread_helper\n"
-"	.popsection");
-
-/*
- * Create a kernel thread.
- */
-pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
-{
-	struct pt_regs regs;
-
-	memset(&regs, 0, sizeof(regs));
-
-	regs.UCreg_04 = (unsigned long)arg;
-	regs.UCreg_05 = (unsigned long)fn;
-	regs.UCreg_06 = (unsigned long)do_exit;
-	regs.UCreg_07 = PRIV_MODE;
-	regs.UCreg_pc = (unsigned long)kernel_thread_helper;
-	regs.UCreg_asr = regs.UCreg_07 | PSR_I_BIT;
-
-	return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
-}
-EXPORT_SYMBOL(kernel_thread);
-
 unsigned long get_wchan(struct task_struct *p)
 {
 	struct stackframe frame;
diff --git a/arch/unicore32/kernel/sys.c b/arch/unicore32/kernel/sys.c
index fabdee9..8b6e4cc 100644
--- a/arch/unicore32/kernel/sys.c
+++ b/arch/unicore32/kernel/sys.c
@@ -63,48 +63,6 @@ out:
 	return error;
 }
 
-int kernel_execve(const char *filename,
-		  const char *const argv[],
-		  const char *const envp[])
-{
-	struct pt_regs regs;
-	int ret;
-
-	memset(&regs, 0, sizeof(struct pt_regs));
-	ret = do_execve(filename,
-			(const char __user *const __user *)argv,
-			(const char __user *const __user *)envp, &regs);
-	if (ret < 0)
-		goto out;
-
-	/*
-	 * Save argc to the register structure for userspace.
-	 */
-	regs.UCreg_00 = ret;
-
-	/*
-	 * We were successful.  We won't be returning to our caller, but
-	 * instead to user space by manipulating the kernel stack.
-	 */
-	asm("add	r0, %0, %1\n\t"
-		"mov	r1, %2\n\t"
-		"mov	r2, %3\n\t"
-		"mov	r22, #0\n\t"	/* not a syscall */
-		"mov	r23, %0\n\t"	/* thread structure */
-		"b.l	memmove\n\t"	/* copy regs to top of stack */
-		"mov	sp, r0\n\t"	/* reposition stack pointer */
-		"b	ret_to_user"
-		:
-		: "r" (current_thread_info()),
-		  "Ir" (THREAD_START_SP - sizeof(regs)),
-		  "r" (&regs),
-		  "Ir" (sizeof(regs))
-		: "r0", "r1", "r2", "r3", "ip", "lr", "memory");
-
- out:
-	return ret;
-}
-
 /* Note: used by the compat code even in 64-bit Linux. */
 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
 		unsigned long, prot, unsigned long, flags,
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] unicore32: switch to generic sys_execve()
  2012-10-19  8:43 [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Guan Xuetao
@ 2012-10-19  8:43 ` Guan Xuetao
  2012-10-19 13:18 ` [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Al Viro
  1 sibling, 0 replies; 4+ messages in thread
From: Guan Xuetao @ 2012-10-19  8:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-and-Tested-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
---
 arch/unicore32/include/uapi/asm/unistd.h |    1 +
 arch/unicore32/kernel/entry.S            |    5 -----
 arch/unicore32/kernel/sys.c              |   21 ---------------------
 3 files changed, 1 insertions(+), 26 deletions(-)

diff --git a/arch/unicore32/include/uapi/asm/unistd.h b/arch/unicore32/include/uapi/asm/unistd.h
index 2abcf61..d18a3be 100644
--- a/arch/unicore32/include/uapi/asm/unistd.h
+++ b/arch/unicore32/include/uapi/asm/unistd.h
@@ -12,3 +12,4 @@
 
 /* Use the standard ABI for syscalls. */
 #include <asm-generic/unistd.h>
+#define __ARCH_WANT_SYS_EXECVE
diff --git a/arch/unicore32/kernel/entry.S b/arch/unicore32/kernel/entry.S
index 32648c9..7049350 100644
--- a/arch/unicore32/kernel/entry.S
+++ b/arch/unicore32/kernel/entry.S
@@ -668,11 +668,6 @@ __cr_alignment:
 #endif
 	.ltorg
 
-ENTRY(sys_execve)
-		add	r3, sp, #S_OFF
-		b	__sys_execve
-ENDPROC(sys_execve)
-
 ENTRY(sys_clone)
 		add	ip, sp, #S_OFF
 		stw	ip, [sp+], #4
diff --git a/arch/unicore32/kernel/sys.c b/arch/unicore32/kernel/sys.c
index 8b6e4cc..9680134 100644
--- a/arch/unicore32/kernel/sys.c
+++ b/arch/unicore32/kernel/sys.c
@@ -42,27 +42,6 @@ asmlinkage long __sys_clone(unsigned long clone_flags, unsigned long newsp,
 			parent_tid, child_tid);
 }
 
-/* sys_execve() executes a new program.
- * This is called indirectly via a small wrapper
- */
-asmlinkage long __sys_execve(const char __user *filename,
-			  const char __user *const __user *argv,
-			  const char __user *const __user *envp,
-			  struct pt_regs *regs)
-{
-	int error;
-	struct filename *fn;
-
-	fn = getname(filename);
-	error = PTR_ERR(fn);
-	if (IS_ERR(fn))
-		goto out;
-	error = do_execve(fn->name, argv, envp, regs);
-	putname(fn);
-out:
-	return error;
-}
-
 /* Note: used by the compat code even in 64-bit Linux. */
 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
 		unsigned long, prot, unsigned long, flags,
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve()
  2012-10-19  8:43 [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Guan Xuetao
  2012-10-19  8:43 ` [PATCH 2/2] unicore32: switch to generic sys_execve() Guan Xuetao
@ 2012-10-19 13:18 ` Al Viro
  2012-10-19 13:43   ` guanxuetao
  1 sibling, 1 reply; 4+ messages in thread
From: Al Viro @ 2012-10-19 13:18 UTC (permalink / raw)
  To: Guan Xuetao; +Cc: linux-kernel

On Fri, Oct 19, 2012 at 04:43:09PM +0800, Guan Xuetao wrote:
> From: Al Viro <viro@zeniv.linux.org.uk>
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Acked-and-Tested-by: Guan Xuetao <gxt@mprc.pku.edu.cn>

You mean, it worked modulo obvious missing ')'?  Wow... OK, merged
into signal.git#for-next, obviously in no-rebase mode (as the matter
of fact, I'm dropping the local branch completely).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] unicore32: switch to generic  kernel_thread()/kernel_execve()
  2012-10-19 13:18 ` [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Al Viro
@ 2012-10-19 13:43   ` guanxuetao
  0 siblings, 0 replies; 4+ messages in thread
From: guanxuetao @ 2012-10-19 13:43 UTC (permalink / raw)
  To: Al Viro; +Cc: Guan Xuetao, linux-kernel

> On Fri, Oct 19, 2012 at 04:43:09PM +0800, Guan Xuetao wrote:
>> From: Al Viro <viro@zeniv.linux.org.uk>
>>
>> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
>> Acked-and-Tested-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
>
> You mean, it worked modulo obvious missing ')'?  Wow... OK, merged
> into signal.git#for-next, obviously in no-rebase mode (as the matter
> of fact, I'm dropping the local branch completely).
>
I've added')' in the patch. Then it works.
In addition, I pushed these two patches into my tree.

Thanks & regards,
Guan Xuetao

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-10-19 13:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-19  8:43 [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Guan Xuetao
2012-10-19  8:43 ` [PATCH 2/2] unicore32: switch to generic sys_execve() Guan Xuetao
2012-10-19 13:18 ` [PATCH 1/2] unicore32: switch to generic kernel_thread()/kernel_execve() Al Viro
2012-10-19 13:43   ` guanxuetao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.