Commit dbc4fc9c authored by Ingo Molnar's avatar Ingo Molnar

[PATCH] threading enhancements, tid-2.5.48-C0

Support more flexible child pid set/clear operations for NPTL.

there's one more improvement in the interface: set the parent-TID prior
doing the copy_mm() - this helps cfork() to pass the TID to the child as
well.
parent 7d7f493a
...@@ -170,10 +170,8 @@ ENTRY(lcall27) ...@@ -170,10 +170,8 @@ ENTRY(lcall27)
ENTRY(ret_from_fork) ENTRY(ret_from_fork)
#if CONFIG_SMP || CONFIG_PREEMPT
# NOTE: this function takes a parameter but it's unused on x86. # NOTE: this function takes a parameter but it's unused on x86.
call schedule_tail call schedule_tail
#endif
GET_THREAD_INFO(%ebx) GET_THREAD_INFO(%ebx)
jmp syscall_exit jmp syscall_exit
......
...@@ -226,7 +226,7 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) ...@@ -226,7 +226,7 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
regs.eflags = 0x286; regs.eflags = 0x286;
/* Ok, create the new process.. */ /* Ok, create the new process.. */
p = do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL); p = do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
return IS_ERR(p) ? PTR_ERR(p) : p->pid; return IS_ERR(p) ? PTR_ERR(p) : p->pid;
} }
...@@ -288,7 +288,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp, ...@@ -288,7 +288,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
struct_cpy(childregs, regs); struct_cpy(childregs, regs);
childregs->eax = 0; childregs->eax = 0;
childregs->esp = esp; childregs->esp = esp;
p->user_tid = NULL; p->set_child_tid = p->clear_child_tid = NULL;
p->thread.esp = (unsigned long) childregs; p->thread.esp = (unsigned long) childregs;
p->thread.esp0 = (unsigned long) (childregs+1); p->thread.esp0 = (unsigned long) (childregs+1);
...@@ -503,7 +503,7 @@ asmlinkage int sys_fork(struct pt_regs regs) ...@@ -503,7 +503,7 @@ asmlinkage int sys_fork(struct pt_regs regs)
{ {
struct task_struct *p; struct task_struct *p;
p = do_fork(SIGCHLD, regs.esp, &regs, 0, NULL); p = do_fork(SIGCHLD, regs.esp, &regs, 0, NULL, NULL);
return IS_ERR(p) ? PTR_ERR(p) : p->pid; return IS_ERR(p) ? PTR_ERR(p) : p->pid;
} }
...@@ -512,14 +512,15 @@ asmlinkage int sys_clone(struct pt_regs regs) ...@@ -512,14 +512,15 @@ asmlinkage int sys_clone(struct pt_regs regs)
struct task_struct *p; struct task_struct *p;
unsigned long clone_flags; unsigned long clone_flags;
unsigned long newsp; unsigned long newsp;
int *user_tid; int *parent_tidptr, *child_tidptr;
clone_flags = regs.ebx; clone_flags = regs.ebx;
newsp = regs.ecx; newsp = regs.ecx;
user_tid = (int *)regs.edx; parent_tidptr = (int *)regs.edx;
child_tidptr = (int *)regs.edi;
if (!newsp) if (!newsp)
newsp = regs.esp; newsp = regs.esp;
p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, user_tid); p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, parent_tidptr, child_tidptr);
return IS_ERR(p) ? PTR_ERR(p) : p->pid; return IS_ERR(p) ? PTR_ERR(p) : p->pid;
} }
...@@ -537,7 +538,7 @@ asmlinkage int sys_vfork(struct pt_regs regs) ...@@ -537,7 +538,7 @@ asmlinkage int sys_vfork(struct pt_regs regs)
{ {
struct task_struct *p; struct task_struct *p;
p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0, NULL); p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0, NULL, NULL);
return IS_ERR(p) ? PTR_ERR(p) : p->pid; return IS_ERR(p) ? PTR_ERR(p) : p->pid;
} }
......
...@@ -499,7 +499,7 @@ static struct task_struct * __init fork_by_hand(void) ...@@ -499,7 +499,7 @@ static struct task_struct * __init fork_by_hand(void)
* don't care about the eip and regs settings since * don't care about the eip and regs settings since
* we'll never reschedule the forked task. * we'll never reschedule the forked task.
*/ */
return do_fork(CLONE_VM|CLONE_IDLETASK, 0, &regs, 0, NULL); return do_fork(CLONE_VM|CLONE_IDLETASK, 0, &regs, 0, NULL, NULL);
} }
/* which physical APIC ID maps to which logical CPU number */ /* which physical APIC ID maps to which logical CPU number */
......
...@@ -46,10 +46,11 @@ struct exec_domain; ...@@ -46,10 +46,11 @@ struct exec_domain;
#define CLONE_NEWNS 0x00020000 /* New namespace group? */ #define CLONE_NEWNS 0x00020000 /* New namespace group? */
#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
#define CLONE_SETTID 0x00100000 /* write the TID back to userspace */ #define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
#define CLONE_CLEARTID 0x00200000 /* clear the userspace TID */ #define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
#define CLONE_DETACHED 0x00400000 /* parent wants no child-exit signal */ #define CLONE_DETACHED 0x00400000 /* parent wants no child-exit signal */
#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */ #define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
/* /*
* List of flags we want to share for kernel threads, * List of flags we want to share for kernel threads,
...@@ -332,7 +333,8 @@ struct task_struct { ...@@ -332,7 +333,8 @@ struct task_struct {
wait_queue_head_t wait_chldexit; /* for wait4() */ wait_queue_head_t wait_chldexit; /* for wait4() */
struct completion *vfork_done; /* for vfork() */ struct completion *vfork_done; /* for vfork() */
int *user_tid; /* for CLONE_CLEARTID */ int *set_child_tid; /* CLONE_CHILD_SETTID */
int *clear_child_tid; /* CLONE_CHILD_CLEARTID */
unsigned long rt_priority; unsigned long rt_priority;
unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_value, it_prof_value, it_virt_value;
...@@ -585,7 +587,7 @@ extern void daemonize(void); ...@@ -585,7 +587,7 @@ extern void daemonize(void);
extern task_t *child_reaper; extern task_t *child_reaper;
extern int do_execve(char *, char **, char **, struct pt_regs *); extern int do_execve(char *, char **, char **, struct pt_regs *);
extern struct task_struct *do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int *); extern struct task_struct *do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int *, int *);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
extern void wait_task_inactive(task_t * p); extern void wait_task_inactive(task_t * p);
......
...@@ -408,16 +408,16 @@ void mm_release(void) ...@@ -408,16 +408,16 @@ void mm_release(void)
tsk->vfork_done = NULL; tsk->vfork_done = NULL;
complete(vfork_done); complete(vfork_done);
} }
if (tsk->user_tid) { if (tsk->clear_child_tid) {
int * user_tid = tsk->user_tid; int * tidptr = tsk->clear_child_tid;
tsk->user_tid = NULL; tsk->clear_child_tid = NULL;
/* /*
* We dont check the error code - if userspace has * We dont check the error code - if userspace has
* not set up a proper pointer then tough luck. * not set up a proper pointer then tough luck.
*/ */
put_user(0, user_tid); put_user(0, tidptr);
sys_futex((unsigned long)user_tid, FUTEX_WAKE, 1, NULL); sys_futex((unsigned long)tidptr, FUTEX_WAKE, 1, NULL);
} }
} }
...@@ -680,9 +680,9 @@ static inline void copy_flags(unsigned long clone_flags, struct task_struct *p) ...@@ -680,9 +680,9 @@ static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
p->flags = new_flags; p->flags = new_flags;
} }
asmlinkage int sys_set_tid_address(int *user_tid) asmlinkage int sys_set_tid_address(int *tidptr)
{ {
current->user_tid = user_tid; current->clear_child_tid = tidptr;
return current->pid; return current->pid;
} }
...@@ -699,7 +699,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -699,7 +699,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
unsigned long stack_start, unsigned long stack_start,
struct pt_regs *regs, struct pt_regs *regs,
unsigned long stack_size, unsigned long stack_size,
int *user_tid) int *parent_tidptr,
int *child_tidptr)
{ {
int retval; int retval;
struct task_struct *p = NULL; struct task_struct *p = NULL;
...@@ -766,6 +767,11 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -766,6 +767,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
if (p->pid == -1) if (p->pid == -1)
goto bad_fork_cleanup; goto bad_fork_cleanup;
} }
retval = -EFAULT;
if (clone_flags & CLONE_PARENT_SETTID)
if (put_user(p->pid, parent_tidptr))
goto bad_fork_cleanup;
p->proc_dentry = NULL; p->proc_dentry = NULL;
INIT_LIST_HEAD(&p->run_list); INIT_LIST_HEAD(&p->run_list);
...@@ -823,19 +829,14 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -823,19 +829,14 @@ static struct task_struct *copy_process(unsigned long clone_flags,
retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs); retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
if (retval) if (retval)
goto bad_fork_cleanup_namespace; goto bad_fork_cleanup_namespace;
/*
* Notify the child of the TID?
*/
retval = -EFAULT;
if (clone_flags & CLONE_SETTID)
if (put_user(p->pid, user_tid))
goto bad_fork_cleanup_namespace;
if (clone_flags & CLONE_CHILD_SETTID)
p->set_child_tid = child_tidptr;
/* /*
* Does the userspace VM want the TID cleared on mm_release()? * Clear TID on mm_release()?
*/ */
if (clone_flags & CLONE_CLEARTID) if (clone_flags & CLONE_CHILD_CLEARTID)
p->user_tid = user_tid; p->clear_child_tid = child_tidptr;
/* /*
* Syscall tracing should be turned off in the child regardless * Syscall tracing should be turned off in the child regardless
...@@ -1004,7 +1005,8 @@ struct task_struct *do_fork(unsigned long clone_flags, ...@@ -1004,7 +1005,8 @@ struct task_struct *do_fork(unsigned long clone_flags,
unsigned long stack_start, unsigned long stack_start,
struct pt_regs *regs, struct pt_regs *regs,
unsigned long stack_size, unsigned long stack_size,
int *user_tid) int *parent_tidptr,
int *child_tidptr)
{ {
struct task_struct *p; struct task_struct *p;
int trace = 0; int trace = 0;
...@@ -1015,7 +1017,7 @@ struct task_struct *do_fork(unsigned long clone_flags, ...@@ -1015,7 +1017,7 @@ struct task_struct *do_fork(unsigned long clone_flags,
clone_flags |= CLONE_PTRACE; clone_flags |= CLONE_PTRACE;
} }
p = copy_process(clone_flags, stack_start, regs, stack_size, user_tid); p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr);
if (!IS_ERR(p)) { if (!IS_ERR(p)) {
struct completion vfork; struct completion vfork;
......
...@@ -503,12 +503,12 @@ void sched_exit(task_t * p) ...@@ -503,12 +503,12 @@ void sched_exit(task_t * p)
* schedule_tail - first thing a freshly forked thread must call. * schedule_tail - first thing a freshly forked thread must call.
* @prev: the thread we just switched away from. * @prev: the thread we just switched away from.
*/ */
#if CONFIG_SMP || CONFIG_PREEMPT
asmlinkage void schedule_tail(task_t *prev) asmlinkage void schedule_tail(task_t *prev)
{ {
finish_arch_switch(this_rq(), prev); finish_arch_switch(this_rq(), prev);
if (current->set_child_tid)
put_user(current->pid, current->set_child_tid);
} }
#endif
/* /*
* context_switch - switch to the new MM and the new * context_switch - switch to the new MM and the new
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment