Skip to content

Commit

Permalink
task_struct cleanup: move binfmt field to mm_struct
Browse files Browse the repository at this point in the history
Because the binfmt is not different between threads in the same process,
it can be moved from task_struct to mm_struct.  And binfmt moudle is
handled per mm_struct instead of task_struct.

Signed-off-by: Hiroshi Shimamoto <[email protected]>
Acked-by: Oleg Nesterov <[email protected]>
Cc: Rusty Russell <[email protected]>
Acked-by: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
h-shimamoto authored and torvalds committed Sep 24, 2009
1 parent 2fa4341 commit 801460d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,12 @@ int do_execve(char * filename,

void set_binfmt(struct linux_binfmt *new)
{
if (current->binfmt)
module_put(current->binfmt->module);
struct mm_struct *mm = current->mm;

if (mm->binfmt)
module_put(mm->binfmt->module);

current->binfmt = new;
mm->binfmt = new;
if (new)
__module_get(new->module);
}
Expand Down Expand Up @@ -1770,7 +1772,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)

audit_core_dumps(signr);

binfmt = current->binfmt;
binfmt = mm->binfmt;
if (!binfmt || !binfmt->core_dump)
goto fail;

Expand Down
2 changes: 2 additions & 0 deletions include/linux/mm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ struct mm_struct {

unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */

struct linux_binfmt *binfmt;

cpumask_t cpu_vm_mask;

/* Architecture-specific MM context */
Expand Down
1 change: 0 additions & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ struct task_struct {
struct mm_struct *mm, *active_mm;

/* task state */
struct linux_binfmt *binfmt;
int exit_state;
int exit_code, exit_signal;
int pdeath_signal; /* The signal sent when the parent dies */
Expand Down
2 changes: 0 additions & 2 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,6 @@ NORET_TYPE void do_exit(long code)
disassociate_ctty(1);

module_put(task_thread_info(tsk)->exec_domain->module);
if (tsk->binfmt)
module_put(tsk->binfmt->module);

proc_exit_connector(tsk);

Expand Down
13 changes: 7 additions & 6 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ void mmput(struct mm_struct *mm)
spin_unlock(&mmlist_lock);
}
put_swap_token(mm);
if (mm->binfmt)
module_put(mm->binfmt->module);
mmdrop(mm);
}
}
Expand Down Expand Up @@ -643,9 +645,14 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
mm->hiwater_rss = get_mm_rss(mm);
mm->hiwater_vm = mm->total_vm;

if (mm->binfmt && !try_module_get(mm->binfmt->module))
goto free_pt;

return mm;

free_pt:
/* don't put binfmt in mmput, we haven't got module yet */
mm->binfmt = NULL;
mmput(mm);

fail_nomem:
Expand Down Expand Up @@ -1037,9 +1044,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
if (!try_module_get(task_thread_info(p)->exec_domain->module))
goto bad_fork_cleanup_count;

if (p->binfmt && !try_module_get(p->binfmt->module))
goto bad_fork_cleanup_put_domain;

p->did_exec = 0;
delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
copy_flags(clone_flags, p);
Expand Down Expand Up @@ -1327,9 +1331,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
#endif
cgroup_exit(p, cgroup_callbacks_done);
delayacct_tsk_free(p);
if (p->binfmt)
module_put(p->binfmt->module);
bad_fork_cleanup_put_domain:
module_put(task_thread_info(p)->exec_domain->module);
bad_fork_cleanup_count:
atomic_dec(&p->cred->user->processes);
Expand Down

0 comments on commit 801460d

Please sign in to comment.