The patch titled Subject: memcg: close the race between migration and installing bprm->mm as mm has been added to the -mm tree. Its filename is memcg-replace-mm-owner-with-mm-memcg-fix-2.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/memcg-replace-mm-owner-with-mm-memcg-fix-2.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/memcg-replace-mm-owner-with-mm-memcg-fix-2.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Subject: memcg: close the race between migration and installing bprm->mm as mm Oleg pointed out that there is a race at exec time between when bprm->mm is initialized and the exec'ing task being migrated to a different memory control group. Ractor the code in memcontrol so exec_mmap can use the same code as as fork to ensure that task->memcg == task->mm->memcg. Link: http://lkml.kernel.org/r/87fu37cow4.fsf_-_@xxxxxxxxxxxx Signed-off-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Reported-by: Oleg Nesterov <oleg@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/exec.c | 2 ++ include/linux/memcontrol.h | 5 +++++ mm/memcontrol.c | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff -puN fs/exec.c~memcg-replace-mm-owner-with-mm-memcg-fix-2 fs/exec.c --- a/fs/exec.c~memcg-replace-mm-owner-with-mm-memcg-fix-2 +++ a/fs/exec.c @@ -1044,6 +1044,8 @@ static int exec_mmap(struct mm_struct *m return 0; } mmdrop(active_mm); + /* The tsk may have migrated before the new mm was attached */ + mm_sync_memcg_from_task(tsk); return 0; } diff -puN include/linux/memcontrol.h~memcg-replace-mm-owner-with-mm-memcg-fix-2 include/linux/memcontrol.h --- a/include/linux/memcontrol.h~memcg-replace-mm-owner-with-mm-memcg-fix-2 +++ a/include/linux/memcontrol.h @@ -408,6 +408,7 @@ static inline bool mem_cgroup_is_descend } void mm_update_memcg(struct mm_struct *mm, struct mem_cgroup *new); +void mm_sync_memcg_from_task(struct task_struct *tsk); static inline bool mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *memcg) @@ -792,6 +793,10 @@ static inline void mm_update_memcg(struc { } +static inline void mm_sync_memcg_from_task(struct task_struct *tsk) +{ +} + static inline bool mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *memcg) { diff -puN mm/memcontrol.c~memcg-replace-mm-owner-with-mm-memcg-fix-2 mm/memcontrol.c --- a/mm/memcontrol.c~memcg-replace-mm-owner-with-mm-memcg-fix-2 +++ a/mm/memcontrol.c @@ -5079,7 +5079,7 @@ static void mem_cgroup_attach(struct cgr } } -static void mem_cgroup_fork(struct task_struct *tsk) +void mm_sync_memcg_from_task(struct task_struct *tsk) { struct cgroup_subsys_state *css; @@ -5393,7 +5393,7 @@ struct cgroup_subsys memory_cgrp_subsys .attach = mem_cgroup_attach, .cancel_attach = mem_cgroup_cancel_attach, .post_attach = mem_cgroup_move_task, - .fork = mem_cgroup_fork, + .fork = mm_sync_memcg_from_task, .bind = mem_cgroup_bind, .dfl_cftypes = memory_files, .legacy_cftypes = mem_cgroup_legacy_files, _ Patches currently in -mm which might be from ebiederm@xxxxxxxxxxxx are memcg-replace-mm-owner-with-mm-memcg.patch memcg-replace-mm-owner-with-mm-memcg-fix.patch memcg-replace-mm-owner-with-mm-memcg-fix-2.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html