Skip to contentSkip to conversation

xtensa: conversion to generic kernel_thread and friends

PATCH Superseded Max Filippov 2 participants 7 messages Oct 24, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Max Filippov

author maintainer
#0 lore raw

cover xtensa: conversion to generic kernel_thread and friends

Hi.

This series converts xtensa arch to use kernel_thread, kernel_execve and generic sys_execve.

Max Filippov (3):
xtensa: switch to generic kernel_thread()
xtensa: switch to generic kernel_execve()
xtensa: switch to generic sys_execve()

 arch/xtensa/Kconfig                   |    2 +
 arch/xtensa/include/asm/processor.h   |    3 -
 arch/xtensa/include/asm/syscall.h     |    2 +-
 arch/xtensa/include/asm/unistd.h      |    1 +
 arch/xtensa/include/uapi/asm/unistd.h |    2 +-
 arch/xtensa/kernel/entry.S            |   57 +++++---------------
 arch/xtensa/kernel/process.c          |   97 +++++++++++++++------------------
 arch/xtensa/kernel/xtensa_ksyms.c     |    1 -
 8 files changed, 62 insertions(+), 103 deletions(-)
Signature · 1 line
1.7.7.6
author maintainer
#1 lore raw

PATCH 1/3 xtensa: switch to generic kernel_thread()

---
 arch/xtensa/Kconfig                 |    1 +
 arch/xtensa/include/asm/processor.h |    3 -
 arch/xtensa/kernel/entry.S          |   41 ++++++-------------
 arch/xtensa/kernel/process.c        |   72 +++++++++++++++++++++-------------
 arch/xtensa/kernel/xtensa_ksyms.c   |    1 -
 5 files changed, 58 insertions(+), 60 deletions(-)
arch/xtensa/Kconfig +1 -0
index cdcb48a..9525b70 100644
@@ -13,6 +13,7 @@ config XTENSA
 	select GENERIC_CPU_DEVICES
 	select MODULES_USE_ELF_RELA
 	select GENERIC_PCI_IOMAP
+	select GENERIC_KERNEL_THREAD
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	help
 	  Xtensa processors are 32-bit RISC machines designed by Tensilica
arch/xtensa/include/asm/processor.h +0 -3
index 5c371d8..a8642da 100644
@@ -168,9 +168,6 @@ struct mm_struct;
 /* Free all resources held by a thread. */
 #define release_thread(thread) do { } while(0)
 
-/* Create a kernel thread without removing it from tasklists */
-extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
-
 /* Copy and release all segment info associated with a VM */
 #define copy_segments(p, mm)	do { } while(0)
 #define release_segments(mm)	do { } while(0)
arch/xtensa/kernel/entry.S +13 -28

50 lines not on this page · raw message

arch/xtensa/kernel/process.c +44 -28

120 lines not on this page · raw message

arch/xtensa/kernel/xtensa_ksyms.c +0 -1
index a8b9f1f..afe058b 100644
@@ -43,7 +43,6 @@ EXPORT_SYMBOL(__strncpy_user);
 EXPORT_SYMBOL(clear_page);
 EXPORT_SYMBOL(copy_page);
 
-EXPORT_SYMBOL(kernel_thread);
 EXPORT_SYMBOL(empty_zero_page);
 
 /*
Signature · 1 line
1.7.7.6
author maintainer
#2 lore raw

PATCH 2/3 xtensa: switch to generic kernel_execve()

In reply to Max Filippov
---
 arch/xtensa/Kconfig        |    1 +
 arch/xtensa/kernel/entry.S |   18 +-----------------
 2 files changed, 2 insertions(+), 17 deletions(-)
arch/xtensa/Kconfig +1 -0
index 9525b70..0d1f36a 100644
@@ -14,6 +14,7 @@ config XTENSA
 	select MODULES_USE_ELF_RELA
 	select GENERIC_PCI_IOMAP
 	select GENERIC_KERNEL_THREAD
+	select GENERIC_KERNEL_EXECVE
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	help
 	  Xtensa processors are 32-bit RISC machines designed by Tensilica
arch/xtensa/kernel/entry.S +1 -17
index d4ec138..90bfc1d 100644
@@ -1833,22 +1833,6 @@ ENTRY(system_call)
 
 
 /*
- * Do a system call from kernel instead of calling sys_execve, so we end up
- * with proper pt_regs.
- *
- * int kernel_execve(const char *fname, char *const argv[], charg *const envp[])
- * a2                        a2               a3                  a4
- */
-
-ENTRY(kernel_execve)
-	entry	a1, 16
-	mov	a6, a2			# arg0 is in a6
-	movi	a2, __NR_execve
-	syscall
-
-	retw
-
-/*
  * Task switch.
  *
  * struct task*  _switch_to (struct task* prev, struct task* next)
@@ -1940,6 +1924,6 @@ ENTRY(ret_from_kernel_thread)
 	call4	schedule_tail
 	mov	a6, a3
 	callx4	a2
-	call4	do_exit
+	j	common_exception_return
 
 ENDPROC(ret_from_kernel_thread)
Signature · 1 line
1.7.7.6
author maintainer
#3 lore raw

PATCH 3/3 xtensa: switch to generic sys_execve()

In reply to Max Filippov
---
 arch/xtensa/include/asm/syscall.h     |    2 +-
 arch/xtensa/include/asm/unistd.h      |    1 +
 arch/xtensa/include/uapi/asm/unistd.h |    2 +-
 arch/xtensa/kernel/process.c          |   25 -------------------------
 4 files changed, 3 insertions(+), 27 deletions(-)
arch/xtensa/include/asm/syscall.h +1 -1
index c1dacca..124aeee 100644
@@ -10,7 +10,7 @@
 
 struct pt_regs;
 struct sigaction;
-asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*);
+asmlinkage long sys_execve(char*, char**, char**, struct pt_regs*);
 asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*);
 asmlinkage long xtensa_ptrace(long, long, long, long);
 asmlinkage long xtensa_sigreturn(struct pt_regs*);
arch/xtensa/include/asm/unistd.h +1 -0
index 9ef1c31..e83e966 100644
@@ -8,6 +8,7 @@
  * Copyright (C) 2001 - 2005 Tensilica Inc.
  */
 
+#define __ARCH_WANT_SYS_EXECVE
 #include <uapi/asm/unistd.h>
 
 
arch/xtensa/include/uapi/asm/unistd.h +1 -1
index ac37eb4..c5d736f 100644
@@ -269,7 +269,7 @@ __SYSCALL(115, sys_sendmmsg, 4)
 #define __NR_clone 				116
 __SYSCALL(116, xtensa_clone, 5)
 #define __NR_execve 				117
-__SYSCALL(117, xtensa_execve, 3)
+__SYSCALL(117, sys_execve, 3)
 #define __NR_exit 				118
 __SYSCALL(118, sys_exit, 1)
 #define __NR_exit_group 			119
arch/xtensa/kernel/process.c +0 -25
index fd538bb..58e50ff 100644
@@ -350,28 +350,3 @@ long xtensa_clone(unsigned long clone_flags, unsigned long newsp,
                 newsp = regs->areg[1];
         return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
 }
-
-/*
- * xtensa_execve() executes a new program.
- */
-
-asmlinkage
-long xtensa_execve(const char __user *name,
-		   const char __user *const __user *argv,
-                   const char __user *const __user *envp,
-                   long a3, long a4, long a5,
-                   struct pt_regs *regs)
-{
-	long error;
-	struct filename *filename;
-
-	filename = getname(name);
-	error = PTR_ERR(filename);
-	if (IS_ERR(filename))
-		goto out;
-	error = do_execve(filename->name, argv, envp, regs);
-	putname(filename);
-out:
-	return error;
-}
-
Signature · 1 line
1.7.7.6
#4 lore raw

Re: [PATCH 3/3] xtensa: switch to generic sys_execve()

Quoted 7 lines · Max Filippov
---
 arch/xtensa/include/asm/syscall.h     |    2 +-
 arch/xtensa/include/asm/unistd.h      |    1 +
 arch/xtensa/include/uapi/asm/unistd.h |    2 +-
 arch/xtensa/kernel/process.c          |   25 -------------------------
 4 files changed, 3 insertions(+), 27 deletions(-)

All three applied, but there's a couple of things I'd like to have on top of that. Are you OK with the following incremental?
1) ->{set,clear}_child_tid is set by the caller; no need to set it
in copy_thread().
2) for later work it would be easier if copy_thread() hadn't looked
at regs argument at all; telling kernel_thread(9) from clone(2) can be done by checking p->flags & PF_KTHREAD and for clone(2) it's always going to get current_pt_regs().
3) interpretation of zero newsp is probably better off in copy_thread()
as well. Eventually we are going to kill regs argument of do_fork() et.al.

arch/xtensa/kernel/process.c +5 -6
index 58e50ff..9d8f387 100644
@@ -200,7 +200,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 
 int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
 		unsigned long thread_fn_arg,
-                struct task_struct * p, struct pt_regs * regs)
+                struct task_struct * p, struct pt_regs *unused)
 {
 	struct pt_regs *childregs = task_pt_regs(p);
 
@@ -212,10 +212,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
 	*((int*)childregs - 3) = (unsigned long)childregs;
 	*((int*)childregs - 4) = 0;
 
-	p->set_child_tid = p->clear_child_tid = NULL;
 	p->thread.sp = (unsigned long)childregs;
 
-	if (regs) {
+	if (!(p->flags & PF_KTHREAD)) {
+		struct pt_regs *regs = current_pt_regs();
 		p->thread.ra = MAKE_RA_FOR_CALL(
 				(unsigned long)ret_from_fork, 0x1);
 
@@ -224,7 +224,8 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
 		 * ARs beyond a0-a15 exist past the end of the struct.
 		 */
 		*childregs = *regs;
-		childregs->areg[1] = usp_thread_fn;
+		if (usp_thread_fn)
+			childregs->areg[1] = usp_thread_fn;
 		childregs->areg[2] = 0;
 
 		if (clone_flags & CLONE_VM) {
@@ -346,7 +347,5 @@ long xtensa_clone(unsigned long clone_flags, unsigned long newsp,
                   void __user *child_tid, long a5,
                   struct pt_regs *regs)
 {
-        if (!newsp)
-                newsp = regs->areg[1];
         return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
 }
author maintainer
#5 lore raw

Re: [PATCH 3/3] xtensa: switch to generic sys_execve()

Quoted 11 lines · Al Viro
Quoted 7 lines · Max Filippov
---
 arch/xtensa/include/asm/syscall.h     |    2 +-
 arch/xtensa/include/asm/unistd.h      |    1 +
 arch/xtensa/include/uapi/asm/unistd.h |    2 +-
 arch/xtensa/kernel/process.c          |   25 -------------------------
 4 files changed, 3 insertions(+), 27 deletions(-)

All three applied, but there's a couple of things I'd like to have on top of that. Are you OK with the following incremental?

Yes. Looks like I need to send v2 to address Chris' comments, I can put these changes there as well.

Quoted 53 lines

1) ->{set,clear}_child_tid is set by the caller; no need to set it
in copy_thread().
2) for later work it would be easier if copy_thread() hadn't looked
at regs argument at all; telling kernel_thread(9) from clone(2) can be done by checking p->flags & PF_KTHREAD and for clone(2) it's always going to get current_pt_regs().
3) interpretation of zero newsp is probably better off in copy_thread()
as well. Eventually we are going to kill regs argument of do_fork() et.al.

arch/xtensa/kernel/process.c +5 -6
index 58e50ff..9d8f387 100644
@@ -200,7 +200,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 
 int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
                unsigned long thread_fn_arg,
-                struct task_struct * p, struct pt_regs * regs)
+                struct task_struct * p, struct pt_regs *unused)
 {
        struct pt_regs *childregs = task_pt_regs(p);
 
@@ -212,10 +212,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
        *((int*)childregs - 3) = (unsigned long)childregs;
        *((int*)childregs - 4) = 0;
 
-       p->set_child_tid = p->clear_child_tid = NULL;
        p->thread.sp = (unsigned long)childregs;
 
-       if (regs) {
+       if (!(p->flags & PF_KTHREAD)) {
+               struct pt_regs *regs = current_pt_regs();
                p->thread.ra = MAKE_RA_FOR_CALL(
                                (unsigned long)ret_from_fork, 0x1);
 
@@ -224,7 +224,8 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
                 * ARs beyond a0-a15 exist past the end of the struct.
                 */
                *childregs = *regs;
-               childregs->areg[1] = usp_thread_fn;
+               if (usp_thread_fn)
+                       childregs->areg[1] = usp_thread_fn;
                childregs->areg[2] = 0;
 
                if (clone_flags & CLONE_VM) {
@@ -346,7 +347,5 @@ long xtensa_clone(unsigned long clone_flags, unsigned long newsp,
                   void __user *child_tid, long a5,
                   struct pt_regs *regs)
 {
-        if (!newsp)
-                newsp = regs->areg[1];
         return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
 }
Signature · 2 lines
Thanks.
-- Max
#6 lore raw

Re: [PATCH 3/3] xtensa: switch to generic sys_execve()

Quoted 10 lines · Max Filippov
Quoted 9 lines · Al Viro
Quoted 7 lines · Max Filippov
---
 arch/xtensa/include/asm/syscall.h     |    2 +-
 arch/xtensa/include/asm/unistd.h      |    1 +
 arch/xtensa/include/uapi/asm/unistd.h |    2 +-
 arch/xtensa/kernel/process.c          |   25 -------------------------
 4 files changed, 3 insertions(+), 27 deletions(-)
Quoted 5 lines
Quoted 2 lines

All three applied, but there's a couple of things I'd like to have on top of that. Are you OK with the following incremental?

Yes. Looks like I need to send v2 to address Chris' comments, I can put these changes there as well.

Please, do.