linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Yafang Shao <laoar.shao@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
	brauner@kernel.org, jack@suse.cz, david@fromorbit.com,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	Kent Overstreet <kent.overstreet@linux.dev>
Subject: [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM
Date: Fri, 16 Aug 2024 10:17:54 +0200	[thread overview]
Message-ID: <Zr8LMv89fkfpmBlO@tiehlicka> (raw)
In-Reply-To: <Zr2liCOFDqPiNk6_@tiehlicka>

Andrew, could you merge the following before PF_MEMALLOC_NORECLAIM can
be removed from the tree altogether please? For the full context the 
email thread starts here: https://lore.kernel.org/all/20240812090525.80299-1-laoar.shao@gmail.com/T/#u
--- 
From f17d36975ec343d9388aa6dbf9ca8d1b58ed09ce Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.com>
Date: Fri, 16 Aug 2024 10:10:00 +0200
Subject: [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM

PF_MEMALLOC_NORECLAIM has been added even when it was pointed out [1]
that such a allocation contex is inherently unsafe if the context
doesn't fully control all allocations called from this context. Any
potential __GFP_NOFAIL request from withing PF_MEMALLOC_NORECLAIM
context would BUG_ON if the allocation would fail.

[1] https://lore.kernel.org/all/ZcM0xtlKbAOFjv5n@tiehlicka/

Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/sched.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index f8d150343d42..0c9061d2a8bd 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1657,7 +1657,12 @@ extern struct pid *cad_pid;
 						 * I am cleaning dirty pages from some other bdi. */
 #define PF_KTHREAD		0x00200000	/* I am a kernel thread */
 #define PF_RANDOMIZE		0x00400000	/* Randomize virtual address space */
-#define PF_MEMALLOC_NORECLAIM	0x00800000	/* All allocation requests will clear __GFP_DIRECT_RECLAIM */
+#define PF_MEMALLOC_NORECLAIM	0x00800000	/* All allocation requests will clear __GFP_DIRECT_RECLAIM.
+						 * This is inherently unsafe unless the context fully controls
+						 * all allocations used. Any potential __GFP_NOFAIL nested allocation
+						 * could BUG_ON as the page allocator doesn't support non-sleeping
+						 * __GFP_NOFAIL requests.
+						 */
 #define PF_MEMALLOC_NOWARN	0x01000000	/* All allocation requests will inherit __GFP_NOWARN */
 #define PF__HOLE__02000000	0x02000000
 #define PF_NO_SETAFFINITY	0x04000000	/* Userland is not allowed to meddle with cpus_mask */
-- 
2.46.0

-- 
2.46.0

  reply	other threads:[~2024-08-16  8:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12  9:05 [PATCH 0/2] mm: Add readahead support for IOCB_NOWAIT Yafang Shao
2024-08-12  9:05 ` [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Yafang Shao
2024-08-12 11:37   ` Christoph Hellwig
2024-08-12 12:59     ` Yafang Shao
2024-08-12 13:21       ` Christoph Hellwig
2024-08-13  2:09         ` Yafang Shao
2024-08-14  5:27           ` Christoph Hellwig
2024-08-14  7:33             ` Yafang Shao
2024-09-01 20:24               ` Vlastimil Babka
2024-09-01 20:42                 ` Kent Overstreet
2024-08-14  7:42       ` Michal Hocko
2024-08-14  8:12         ` Yafang Shao
2024-08-14 12:43           ` Michal Hocko
2024-08-15  3:26             ` Yafang Shao
2024-08-15  6:22               ` Michal Hocko
2024-08-15  6:32                 ` Yafang Shao
2024-08-15  6:51                   ` Michal Hocko
2024-08-16  8:17                     ` Michal Hocko [this message]
2024-08-16  8:22                       ` [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM Christoph Hellwig
2024-08-16  8:54                         ` Michal Hocko
2024-08-16 14:26                           ` Christoph Hellwig
2024-08-16 15:57                             ` Michal Hocko
2024-08-21  7:30                           ` Michal Hocko
2024-08-21 11:44                           ` Christoph Hellwig
2024-08-21 12:37                             ` Michal Hocko
2024-08-22  9:09                               ` Christian Brauner
2024-08-17  2:29                       ` Yafang Shao
2024-08-19  7:57                         ` Michal Hocko
2024-08-12 16:48     ` [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Kent Overstreet
2024-08-14  5:24       ` Christoph Hellwig
2024-08-14  0:28   ` Dave Chinner
2024-08-14  2:19     ` Yafang Shao
2024-08-14  5:42       ` Dave Chinner
2024-08-14  7:32         ` Yafang Shao
2024-08-15  2:54           ` Dave Chinner
2024-08-15  3:38             ` Yafang Shao
2024-08-12  9:05 ` [PATCH 2/2] mm: allow read-ahead with IOCB_NOWAIT set Yafang Shao

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=Zr8LMv89fkfpmBlO@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=kent.overstreet@linux.dev \
    --cc=laoar.shao@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).