linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hailong Liu <hailong.liu@oppo.com>
To: Barry Song <21cnbao@gmail.com>
Cc: <akpm@linux-foundation.org>, <urezki@gmail.com>,
	<hch@infradead.org>, <lstoakes@gmail.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <xiang@kernel.org>,
	<chao@kernel.org>, Oven <liyangouwen1@oppo.com>
Subject: Re: [RFC PATCH] mm/vmalloc: fix vmalloc which may return null if called with __GFP_NOFAIL
Date: Thu, 9 May 2024 11:33:28 +0800	[thread overview]
Message-ID: <20240509033328.q2gwgaurpeg2mqqi@oppo.com> (raw)
In-Reply-To: <CAGsJ_4xN0MBz_73wUvMp74upd9SaQ+TCRJufEj26Y619Rtr7Zw@mail.gmail.com>

On Thu, 09. May 14:20, Barry Song wrote:
> On Thu, May 9, 2024 at 12:58 AM <hailong.liu@oppo.com> wrote:
> >
> > From: "Hailong.Liu" <hailong.liu@oppo.com>
> >
> > Commit a421ef303008 ("mm: allow !GFP_KERNEL allocations for kvmalloc")
> > includes support for __GFP_NOFAIL, but it presents a conflict with
> > commit dd544141b9eb ("vmalloc: back off when the current task is
> > OOM-killed"). A possible scenario is as belows:
> >
> > process-a
> > kvcalloc(n, m, GFP_KERNEL | __GFP_NOFAIL)
> >     __vmalloc_node_range()
> >         __vmalloc_area_node()
> >             vm_area_alloc_pages()
> >             --> oom-killer send SIGKILL to process-a
> >             if (fatal_signal_pending(current)) break;
> > --> return NULL;
> >
> > to fix this, do not check fatal_signal_pending() in vm_area_alloc_pages()
> > if __GFP_NOFAIL set.
> >
> > Reported-by: Oven <liyangouwen1@oppo.com>
> > Signed-off-by: Hailong.Liu <hailong.liu@oppo.com>
> > ---
> >  mm/vmalloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 6641be0ca80b..2f359d08bf8d 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -3560,7 +3560,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
> >
> >         /* High-order pages or fallback path if "bulk" fails. */
> >         while (nr_allocated < nr_pages) {
> > -               if (fatal_signal_pending(current))
> > +               if (!(gfp & __GFP_NOFAIL) && fatal_signal_pending(current))
> >                         break;
>
> why not !nofail ?

if order = 0, nofail would not be set true in bulk allocator. in such a case,
it is still possible to break early

>
> This seems a correct fix, but it undermines the assumption made in
> commit dd544141b9eb
>  ("vmalloc: back off when the current task is OOM-killed")
>
> "
>     This may trigger some hidden problems, when caller does not handle
>     vmalloc failures, or when rollaback after failed vmalloc calls own
>     vmallocs inside.  However all of these scenarios are incorrect: vmalloc
>     does not guarantee successful allocation, it has never been called with
>     __GFP_NOFAIL and threfore either should not be used for any rollbacks or
>     should handle such errors correctly and not lead to critical failures.
> "
>
> If a significant kvmalloc operation is performed with the NOFAIL flag, it risks
> reverting the fix intended to address the OOM-killer issue in commit
> dd544141b9eb.
> Should we indeed permit the NOFAIL flag for large kvmalloc allocations?

IMO, if we encounter this issue, it should be fixed by the
caller, not here.
>

>
> Thanks
> Barry

--

Best Regards,
Hailong.


  parent reply	other threads:[~2024-05-09  3:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 12:58 hailong.liu
2024-05-08 13:41 ` Gao Xiang
2024-05-08 14:13   ` Gao Xiang
2024-05-08 14:43   ` Hailong Liu
2024-05-08 15:10     ` Gao Xiang
2024-05-08 15:31       ` Hailong Liu
2024-05-08 15:40         ` Gao Xiang
2024-05-09  1:30           ` Hailong Liu
2024-05-09  4:51             ` Christoph Hellwig
2024-05-09  2:20 ` Barry Song
2024-05-09  2:26   ` Barry Song
2024-05-09  2:30     ` Barry Song
2024-05-09  2:39   ` Gao Xiang
2024-05-09  3:09     ` Barry Song
2024-05-09  3:17       ` Gao Xiang
2024-05-09  3:11     ` Gao Xiang
2024-05-09  3:22     ` Hailong Liu
2024-05-09  3:33   ` Hailong Liu [this message]
2024-05-09  3:48     ` Barry Song
2024-05-09  4:19       ` Gao Xiang
2024-05-09  4:52   ` Christoph Hellwig
2024-05-09  6:12     ` Barry Song
2024-05-09  7:48 ` Michal Hocko
2024-05-09  8:06   ` Hailong Liu
2024-05-09  8:32     ` Barry Song
2024-05-09  8:57       ` Barry Song
2024-05-09  9:50         ` Hailong Liu

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=20240509033328.q2gwgaurpeg2mqqi@oppo.com \
    --to=hailong.liu@oppo.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chao@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liyangouwen1@oppo.com \
    --cc=lstoakes@gmail.com \
    --cc=urezki@gmail.com \
    --cc=xiang@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox