FROMLIST: mm/oom_kill: allow process_mrelease to run under mmap_lock protection

With exit_mmap holding mmap_write_lock during free_pgtables call,
process_mrelease does not need to elevate mm->mm_users in order to
prevent exit_mmap from destrying pagetables while __oom_reap_task_mm
is walking the VMA tree. The change prevents process_mrelease from
calling the last mmput, which can lead to waiting for IO completion
in exit_aio.

Fixes: 337546e83fc7 ("mm/oom_kill.c: prevent a race between process_mrelease and exit_mmap")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>

Link: https://lore.kernel.org/all/20211124235906.14437-2-surenb@google.com/

Bug: 130172058
Bug: 189803002
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I1e2728e0c477af9cc20e9e0b715ee67dee760618
This commit is contained in:
Suren Baghdasaryan
2021-11-19 14:51:26 -08:00
parent 2452622293
commit f4f2c619d5

View File

@@ -1230,8 +1230,9 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
goto put_task; goto put_task;
} }
if (mmget_not_zero(p->mm)) {
mm = p->mm; mm = p->mm;
mmgrab(mm);
if (task_will_free_mem(p)) if (task_will_free_mem(p))
reap = true; reap = true;
else { else {
@@ -1239,7 +1240,6 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
if (!test_bit(MMF_OOM_SKIP, &mm->flags)) if (!test_bit(MMF_OOM_SKIP, &mm->flags))
ret = -EINVAL; ret = -EINVAL;
} }
}
task_unlock(p); task_unlock(p);
if (!reap) if (!reap)
@@ -1249,13 +1249,16 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
ret = -EINTR; ret = -EINTR;
goto drop_mm; goto drop_mm;
} }
if (!__oom_reap_task_mm(mm)) /*
* Check MMF_OOM_SKIP again under mmap_read_lock protection to ensure
* possible change in exit_mmap is seen
*/
if (!test_bit(MMF_OOM_SKIP, &mm->flags) && !__oom_reap_task_mm(mm))
ret = -EAGAIN; ret = -EAGAIN;
mmap_read_unlock(mm); mmap_read_unlock(mm);
drop_mm: drop_mm:
if (mm) mmdrop(mm);
mmput(mm);
put_task: put_task:
put_task_struct(task); put_task_struct(task);
put_pid: put_pid: