mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
authorMiaohe Lin <linmiaohe@huawei.com>
Fri, 5 Nov 2021 20:40:15 +0000 (13:40 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 6 Nov 2021 20:30:37 +0000 (13:30 -0700)
Don't use with __GFP_HIGHMEM because page_address() cannot represent
highmem pages without kmap().  Newly allocated pages would leak as
page_address() will return NULL for highmem pages here.  But It works
now because the callers do not specify __GFP_HIGHMEM now.

Link: https://lkml.kernel.org/r/20210902121242.41607-6-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/page_alloc.c

index 26aebbb..307ad23 100644 (file)
@@ -5610,8 +5610,8 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)
        unsigned int order = get_order(size);
        unsigned long addr;
 
-       if (WARN_ON_ONCE(gfp_mask & __GFP_COMP))
-               gfp_mask &= ~__GFP_COMP;
+       if (WARN_ON_ONCE(gfp_mask & (__GFP_COMP | __GFP_HIGHMEM)))
+               gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM);
 
        addr = __get_free_pages(gfp_mask, order);
        return make_alloc_exact(addr, order, size);
@@ -5635,8 +5635,8 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask)
        unsigned int order = get_order(size);
        struct page *p;
 
-       if (WARN_ON_ONCE(gfp_mask & __GFP_COMP))
-               gfp_mask &= ~__GFP_COMP;
+       if (WARN_ON_ONCE(gfp_mask & (__GFP_COMP | __GFP_HIGHMEM)))
+               gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM);
 
        p = alloc_pages_node(nid, gfp_mask, order);
        if (!p)