linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] mm: Fix potentically scheduling in GFP_ATOMIC allocations.
@ 2015-08-01 13:53 Tetsuo Handa
  0 siblings, 0 replies; only message in thread
From: Tetsuo Handa @ 2015-08-01 13:53 UTC (permalink / raw)
  To: linux-mm

>From 08a638e04351386ab03cd1223988ac7940d4d3aa Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Sat, 1 Aug 2015 22:46:12 +0900
Subject: [PATCH 2/2] mm: Fix potentically scheduling in GFP_ATOMIC
 allocations.

Currently, if somebody does GFP_ATOMIC | __GFP_NOFAIL allocation,
wait_iff_congested() might be called via __alloc_pages_high_priority()
before reaching

  if (!wait) {
    WARN_ON_ONCE(gfp_mask & __GFP_NOFAIL);
    goto nopage;
  }

because gfp_to_alloc_flags() includes ALLOC_NO_WATERMARKS if TIF_MEMDIE
was set.

We need to check for __GFP_WAIT flag at __alloc_pages_high_priority()
in order to make sure that we won't schedule.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 mm/page_alloc.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 37a0390..f9f09fa 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2917,16 +2917,15 @@ __alloc_pages_high_priority(gfp_t gfp_mask, unsigned int order,
 {
 	struct page *page;
 
-	do {
+	for (;;) {
 		page = get_page_from_freelist(gfp_mask, order,
 						ALLOC_NO_WATERMARKS, ac);
 
-		if (!page && gfp_mask & __GFP_NOFAIL)
-			wait_iff_congested(ac->preferred_zone, BLK_RW_ASYNC,
-									HZ/50);
-	} while (!page && (gfp_mask & __GFP_NOFAIL));
-
-	return page;
+		if (page || (gfp_mask & (__GFP_NOFAIL | __GFP_WAIT)) !=
+		    (__GFP_NOFAIL | __GFP_WAIT))
+			return page;
+		wait_iff_congested(ac->preferred_zone, BLK_RW_ASYNC, HZ/50);
+	}
 }
 
 static void wake_all_kswapds(unsigned int order, const struct alloc_context *ac)
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-01 13:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-01 13:53 [PATCH 2/2] mm: Fix potentically scheduling in GFP_ATOMIC allocations Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox