linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Barry Song <21cnbao@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	Barry Song <v-songbaohua@oppo.com>,
	Uladzislau Rezki <urezki@gmail.com>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>
Subject: Re: [PATCH RFC] mm: warn potential return NULL for kmalloc_array and kvmalloc_array with __GFP_NOFAIL
Date: Mon, 22 Jul 2024 11:01:23 +0200	[thread overview]
Message-ID: <Zp4f41RYfpUw4D1M@tiehlicka> (raw)
In-Reply-To: <CAGsJ_4xRH1xExM1VRnMNnoHjwDz8Xq6ibxc+EYMNBZjVwj3d5A@mail.gmail.com>

On Mon 22-07-24 20:09:37, Barry Song wrote:
> On Mon, Jul 22, 2024 at 7:26 PM Michal Hocko <mhocko@suse.com> wrote:
> >
> > On Sun 21-07-24 10:14:03, Barry Song wrote:
> > > On Fri, Jul 19, 2024 at 7:53 PM Christoph Hellwig <hch@infradead.org> wrote:
> > > >
> > > > On Fri, Jul 19, 2024 at 07:43:38PM +1200, Barry Song wrote:
> > > > > I doubt this is going to work as users can use a variant to save gfp_flags.
> > > > > On the other hand, isn't it necessarily a bug of vdpa, why can't it be mm?
> > > > >
> > > > > if mm disallows GFP_NOFAIL,  there must be a doc to say that; if it allows,
> > > > > we should never return NULL.
> > > >
> > > > Yeah.  Maybe the right answer is to have separate _nofail variants that
> > > > don't take any flags and make GFP_NOFAIL an entirely mm-private internal
> > > > flags that is rejected by all external interfaces.  That should also
> > > > really help with auditing the users.
> >
> > This would require duplicating many of our allocations APIs.
> >
> > > Just like Michal has consistently asserted that using GFP_NOFAIL with
> > > non-wait is against the rules, I think we should enforce this policy by:
> > >
> > > diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h
> > > index 313be4ad79fd..a5c09f9590f2 100644
> > > --- a/include/linux/gfp_types.h
> > > +++ b/include/linux/gfp_types.h
> > > @@ -258,7 +258,7 @@ enum {
> > >  #define __GFP_KSWAPD_RECLAIM   ((__force gfp_t)___GFP_KSWAPD_RECLAIM)
> > > /* kswapd can wake */
> > >  #define __GFP_RECLAIM ((__force
> > > gfp_t)(___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM))
> > >  #define __GFP_RETRY_MAYFAIL    ((__force gfp_t)___GFP_RETRY_MAYFAIL)
> > > -#define __GFP_NOFAIL   ((__force gfp_t)___GFP_NOFAIL)
> > > +#define __GFP_NOFAIL   ((__force gfp_t)(___GFP_NOFAIL | ___GFP_DIRECT_RECLAIM))
> > >  #define __GFP_NORETRY  ((__force gfp_t)___GFP_NORETRY)
> > >
> > > Anyone misusing GFP_ATOMIC | __GFP_NOFAIL in an atomic context
> > > risks experiencing a crash due to sleep in atomic. This is a common
> > > consequence, as all instances of sleep in atomic should result in the
> > > same issue.
> >
> > I really dislike any of __GFP_$FOO to have side effects like this.
> > Please let's not overdo this.
> 
> Okay, but my point is that if GFP_NOFAIL is inevitably blockable, why
> not enforce this and let users understand that it is definitively
> blockable?  ust like when we call alloc_pages(GFP_KERNEL), we know
> it might sleep.

__GFP_$FOO are usually low level. GFP_$FOO are high level and they
combine several subflags to have a specific meaning. So this would need
to be GFP_NOFAIL. Btw. the same applies to __GFP_NORETRY and
__GFP_RETRY_MAYFAIL.

Whether changing existing users of those flags is worth is a different
question.
-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2024-07-22  9:01 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17 23:00 Barry Song
2024-07-18  6:58 ` Michal Hocko
2024-07-18  7:04   ` Christoph Hellwig
2024-07-18  7:12     ` Michal Hocko
2024-07-18  8:16       ` Vlastimil Babka
2024-07-18  7:22   ` Barry Song
2024-07-18  7:27     ` Michal Hocko
2024-07-18  7:41       ` Barry Song
2024-07-18  7:53         ` Michal Hocko
2024-07-18  8:18           ` Barry Song
2024-07-18  8:32             ` Michal Hocko
2024-07-18  8:43               ` Barry Song
2024-07-18  8:50                 ` Michal Hocko
2024-07-19  0:35                   ` Barry Song
2024-07-19  7:02                     ` Michal Hocko
2024-07-19  7:07                       ` Barry Song
2024-07-19  7:42                         ` Michal Hocko
2024-07-19  7:51                           ` Barry Song
2024-07-19  8:01                             ` Michal Hocko
2024-07-19  8:28                               ` Barry Song
2024-07-19  8:40                                 ` Michal Hocko
2024-07-19  9:36                                   ` Barry Song
2024-07-19  9:45                                     ` Michal Hocko
2024-07-19  9:58                                       ` Barry Song
2024-07-19 10:57                                         ` Michal Hocko
2024-07-19 11:05                                           ` Barry Song
2024-07-19 11:19                                             ` Michal Hocko
2024-07-19  8:50                               ` Vlastimil Babka
2024-07-19  9:33                                 ` Michal Hocko
2024-07-19 10:10                                   ` Vlastimil Babka
2024-07-19 10:52                                     ` Michal Hocko
2024-07-19 11:13                                       ` Vlastimil Babka
2024-07-19 11:26                                         ` Michal Hocko
2024-07-19 13:02                                           ` Barry Song
2024-07-19 13:30                                             ` Michal Hocko
2024-07-20  0:36                                               ` Barry Song
2024-07-22  7:23                                                 ` Michal Hocko
2024-07-22  7:34                                                   ` Vlastimil Babka
2024-07-19  7:37                       ` Christoph Hellwig
2024-07-19  7:43                         ` Barry Song
2024-07-19  7:53                           ` Christoph Hellwig
2024-07-20 22:14                             ` Barry Song
2024-07-22  7:26                               ` Michal Hocko
2024-07-22  8:09                                 ` Barry Song
2024-07-22  9:01                                   ` Michal Hocko [this message]
2024-07-22 23:18                                     ` Christoph Hellwig
2024-07-22 23:22                                       ` Barry Song
2024-07-19  8:35                     ` Vlastimil Babka
2024-07-18  7:48 ` Hailong Liu
2024-07-18  8:33   ` Barry Song

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=Zp4f41RYfpUw4D1M@tiehlicka \
    --to=mhocko@suse.com \
    --cc=21cnbao@gmail.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=hch@infradead.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=urezki@gmail.com \
    --cc=v-songbaohua@oppo.com \
    --cc=vbabka@suse.cz \
    /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