Commit f268dfe9 authored by Michal Hocko's avatar Michal Hocko Committed by Linus Torvalds

exec: make exec path waiting for mmap_sem killable

setup_arg_pages requires mmap_sem for write.  If the waiting task gets
killed by the oom killer it would block oom_reaper from asynchronous
address space reclaim and reduce the chances of timely OOM resolving.
Wait for the lock in the killable mode and return with EINTR if the task
got killed while waiting.  All the callers are already handling error
path and the fatal signal doesn't need any additional treatment.

The same applies to __bprm_mm_init.
Signed-off-by: default avatarMichal Hocko <mhocko@suse.com>
Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 013373e8
...@@ -263,7 +263,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm) ...@@ -263,7 +263,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
if (!vma) if (!vma)
return -ENOMEM; return -ENOMEM;
down_write(&mm->mmap_sem); if (down_write_killable(&mm->mmap_sem)) {
err = -EINTR;
goto err_free;
}
vma->vm_mm = mm; vma->vm_mm = mm;
/* /*
...@@ -290,6 +293,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm) ...@@ -290,6 +293,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
return 0; return 0;
err: err:
up_write(&mm->mmap_sem); up_write(&mm->mmap_sem);
err_free:
bprm->vma = NULL; bprm->vma = NULL;
kmem_cache_free(vm_area_cachep, vma); kmem_cache_free(vm_area_cachep, vma);
return err; return err;
...@@ -696,7 +700,9 @@ int setup_arg_pages(struct linux_binprm *bprm, ...@@ -696,7 +700,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
bprm->loader -= stack_shift; bprm->loader -= stack_shift;
bprm->exec -= stack_shift; bprm->exec -= stack_shift;
down_write(&mm->mmap_sem); if (down_write_killable(&mm->mmap_sem))
return -EINTR;
vm_flags = VM_STACK_FLAGS; vm_flags = VM_STACK_FLAGS;
/* /*
......
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