Skip to content

Commit a197b59

Browse files
rientjestorvalds
authored andcommitted
mm: fail GFP_DMA allocations when ZONE_DMA is not configured
The page allocator will improperly return a page from ZONE_NORMAL even when __GFP_DMA is passed if CONFIG_ZONE_DMA is disabled. The caller expects DMA memory, perhaps for ISA devices with 16-bit address registers, and may get higher memory resulting in undefined behavior. This patch causes the page allocator to return NULL in such circumstances with a warning emitted to the kernel log on the first occurrence. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ba93fa8 commit a197b59

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/page_alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
22472247

22482248
if (should_fail_alloc_page(gfp_mask, order))
22492249
return NULL;
2250+
#ifndef CONFIG_ZONE_DMA
2251+
if (WARN_ON_ONCE(gfp_mask & __GFP_DMA))
2252+
return NULL;
2253+
#endif
22502254

22512255
/*
22522256
* Check the zones suitable for the gfp_mask contain at least one

0 commit comments

Comments
 (0)