linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Barry Song <21cnbao@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	Barry Song <v-songbaohua@oppo.com>,
	Uladzislau Rezki <urezki@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	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>,
	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: Fri, 19 Jul 2024 13:26:12 +0200	[thread overview]
Message-ID: <ZppNVKK5rcs8WCJD@tiehlicka> (raw)
In-Reply-To: <4a1bd482-bfff-4843-a60f-004b3a8a99e4@suse.cz>

On Fri 19-07-24 13:13:28, Vlastimil Babka wrote:
> On 7/19/24 12:52 PM, Michal Hocko wrote:
> > On Fri 19-07-24 12:10:13, Vlastimil Babka wrote:
> >> On 7/19/24 11:33 AM, Michal Hocko wrote:
> >> > On Fri 19-07-24 10:50:07, Vlastimil Babka wrote:
> >> > [...]
> >> >> That wouldn't mean the busy loop is a correct and supported practice. It
> >> >> would just mean it's the least bad of the bad options we have to deal with
> >> >> an allocation that's wrong but we didn't catch soon enough in the development.
> >> > 
> >> > So you want to make those potential BUG_ONs hard/soft lockups (not sure
> >> > all arches have a reliable detection) instead?
> >> 
> >> I'd expect on a SMP machine there's fair chance of being rescued by kswapd
> >> or other direct reclaimer.
> > 
> > I would expect hard/soft lockups... Anyway, the question remains. What
> > is the preferred way to express this is not really supported scenario.
> 
> The documentation and warnings? I don't think the warnings are failing us
> fundamentally. We could limit the corner cases where the are not being
> reached in case a buggy code is being executed (maybe only in some debug
> config if the checks would be too intrusive for a fast path otherwise). That
> would leave the corner cases where the buggy code is executed rarely. Maybe
> Christoph's suggestion for a build-time check would catch some of those.

I fail to see what you are actually proposing here. I can see only two
ways

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9ecf99190ea2..d5b06ce04a0f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4391,7 +4391,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 		 * of any new users that actually require GFP_NOWAIT
 		 */
 		if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask))
-			goto fail;
+			goto retry;
 
 		/*
 		 * PF_MEMALLOC request from this context is rather bizarre

or

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9ecf99190ea2..6ca9c4d33732 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4387,11 +4387,11 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 	 */
 	if (gfp_mask & __GFP_NOFAIL) {
 		/*
-		 * All existing users of the __GFP_NOFAIL are blockable, so warn
-		 * of any new users that actually require GFP_NOWAIT
+		 * All existing users of the __GFP_NOFAIL are blockable
+		 * otherwise we introduce a busy loop with inside the page
+		 * allocator from non-sleepable contexts.
 		 */
-		if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask))
-			goto fail;
+		BUG_ON(!can_direct_reclaim)
 
 		/*
 		 * PF_MEMALLOC request from this context is rather bizarre

Choose your own poison ;)

BUILD_BUG_ON will only work for statically defined masks AFAIU (which
would catch the existing abuser) but it will not catch the code that
builds up the mask conditionaly so there needs to be a stop gap.
-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2024-07-19 11:26 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 [this message]
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
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=ZppNVKK5rcs8WCJD@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