All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: penguin-kernel@I-love.SAKURA.ne.jp, linux-mm@kvack.org,
	linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk,
	kirill.shutemov@linux.intel.com, mhocko@suse.com,
	riel@redhat.com
Subject: Re: [PATCH] mm: Check for SIGKILL inside dup_mmap() loop.
Date: Thu, 19 Apr 2018 10:54:44 +0900	[thread overview]
Message-ID: <201804190154.w3J1sieH011800@www262.sakura.ne.jp> (raw)
In-Reply-To: <20180418144401.7c9311079914803c9076d209@linux-foundation.org>

Andrew Morton wrote:
> On Sat, 7 Apr 2018 19:38:28 +0900 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> 
> > >From 31c863e57a4ab7dfb491b2860fe3653e1e8f593b Mon Sep 17 00:00:00 2001
> > From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > Date: Sat, 7 Apr 2018 19:29:30 +0900
> > Subject: [PATCH] mm: Check for SIGKILL inside dup_mmap() loop.
> > 
> > As a theoretical problem, an mm_struct with 60000+ vmas can loop with
> > potentially allocating memory, with mm->mmap_sem held for write by current
> > thread. This is bad if current thread was selected as an OOM victim, for
> > current thread will continue allocations using memory reserves while OOM
> > reaper is unable to reclaim memory.
> > 
> > As an actually observable problem, it is not difficult to make OOM reaper
> > unable to reclaim memory if the OOM victim is blocked at
> > i_mmap_lock_write() in this loop. Unfortunately, since nobody can explain
> > whether it is safe to use killable wait there, let's check for SIGKILL
> > before trying to allocate memory. Even without an OOM event, there is no
> > point with continuing the loop from the beginning if current thread is
> > killed.
> > 
> > ...
> >
> > --- a/kernel/fork.c
> > +++ b/kernel/fork.c
> > @@ -441,6 +441,10 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
> >  			continue;
> >  		}
> >  		charge = 0;
> > +		if (fatal_signal_pending(current)) {
> > +			retval = -EINTR;
> > +			goto out;
> > +		}
> >  		if (mpnt->vm_flags & VM_ACCOUNT) {
> >  			unsigned long len = vma_pages(mpnt);
> 
> Seems sane.  Has this been runtime tested?
> 

Yes, I tested with debug printk(). This patch should be safe
because we already fail if security_vm_enough_memory_mm() or
kmem_cache_alloc(GFP_KERNEL) fails and exit_mmap() handles it.

[  417.030691] ***** Aborting dup_mmap() due to SIGKILL *****
[  417.036129] ***** Aborting dup_mmap() due to SIGKILL *****
[  417.044544] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.116445] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.118401] ***** Aborting exit_mmap() due to NULL mmap *****
[  419.168917] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.169064] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.170913] ***** Aborting exit_mmap() due to NULL mmap *****
[  419.171411] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.171417] ***** Aborting exit_mmap() due to NULL mmap *****
[  419.172804] ***** Aborting exit_mmap() due to NULL mmap *****
[  419.176253] ***** Aborting dup_mmap() due to SIGKILL *****
[  419.182676] ***** Aborting exit_mmap() due to NULL mmap *****

> I would like to see a comment here explaining why we're testing for
> this at this particualr place.
> 
Such comment goes to patch description.

  reply	other threads:[~2018-04-19  1:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 11:27 [PATCH] mm: Check for SIGKILL inside dup_mmap() loop Tetsuo Handa
2018-03-29 21:30 ` Andrew Morton
2018-03-30 10:34   ` Tetsuo Handa
2018-04-03 12:14     ` Matthew Wilcox
2018-04-03 12:19       ` Michal Hocko
2018-04-03 12:25         ` Matthew Wilcox
2018-04-03 14:54           ` Tetsuo Handa
2018-04-03 12:29         ` Tetsuo Handa
2018-04-03 13:06           ` Michal Hocko
2018-04-03 11:16   ` Michal Hocko
2018-04-03 11:32     ` Tetsuo Handa
2018-04-03 11:38       ` Michal Hocko
2018-04-03 11:58   ` Matthew Wilcox
2018-04-03 12:08     ` Michal Hocko
2018-04-07 10:38   ` Tetsuo Handa
2018-04-07 10:38     ` Tetsuo Handa
2018-04-18 21:44     ` Andrew Morton
2018-04-19  1:54       ` Tetsuo Handa [this message]
2018-04-19  2:32         ` Andrew Morton
2018-06-07 22:05           ` Andrew Morton
2018-06-08 17:05             ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201804190154.w3J1sieH011800@www262.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=akpm@linux-foundation.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=riel@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.