linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2] mm/vmalloc: fix incorrect __vmap_pages_range_noflush() if vm_area_alloc_pages() from high order fallback to order0
@ 2024-07-25  3:53 hailong.liu
  2024-07-25  6:21 ` Barry Song
  2024-07-25 11:39 ` Baoquan He
  0 siblings, 2 replies; 22+ messages in thread
From: hailong.liu @ 2024-07-25  3:53 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki, Christoph Hellwig,
	Lorenzo Stoakes, Vlastimil Babka, Michal Hocko
  Cc: Hailong.Liu, Barry Song, Baoquan He, Matthew Wilcox,
	Tangquan . Zheng, linux-mm, linux-kernel

From: "Hailong.Liu" <hailong.liu@oppo.com>

The scenario where the issue occurs is as follows:
CONFIG: vmap_allow_huge = true && 2M is for PMD_SIZE
kvmalloc(2M, __GFP_NOFAIL|GFP_XXX)
    __vmalloc_node_range(vm_flags=VM_ALLOW_HUGE_VMAP)
        vm_area_alloc_pages(order=9) --->allocs order9 failed and fallback to order0
                                        and phys_addr is aligned with PMD_SIZE
            vmap_pages_range
                vmap_pages_range_noflush
                    __vmap_pages_range_noflush(page_shift = 21) ----> incorrect vmap *huge* here

In fact, as long as page_shift is not equal to PAGE_SHIFT, there
might be issues with the __vmap_pages_range_noflush().

The patch also remove VM_ALLOW_HUGE_VMAP in kvmalloc_node(), There
are several reasons for this:
- This increases memory footprint because ALIGNMENT.
- This increases the likelihood of kvmalloc allocation failures.
- Without this it fixes the origin issue of kvmalloc with __GFP_NOFAIL may return NULL.
Besides if drivers want to vmap huge, user vmalloc_huge instead.

Fix it by disabling fallback and remove VM_ALLOW_HUGE_VMAP in
kvmalloc_node().
Fixes: e9c3cda4d86e ("mm, vmalloc: fix high order __GFP_NOFAIL allocations")

CC: Barry Song <21cnbao@gmail.com>
CC: Baoquan He <bhe@redhat.com>
CC: Matthew Wilcox <willy@infradead.org>
Reported-by: Tangquan.Zheng <zhengtangquan@oppo.com>
Signed-off-by: Hailong.Liu <hailong.liu@oppo.com>
---
 mm/util.c    | 2 +-
 mm/vmalloc.c | 9 ---------
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index 669397235787..b23133b738cf 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -657,7 +657,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
 	 * protection games.
 	 */
 	return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
-			flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
+			flags, PAGE_KERNEL, 0,
 			node, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kvmalloc_node);
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 03c78fae06f3..1914768f473e 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3577,15 +3577,6 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
 			page = alloc_pages(alloc_gfp, order);
 		else
 			page = alloc_pages_node(nid, alloc_gfp, order);
-		if (unlikely(!page)) {
-			if (!nofail)
-				break;
-
-			/* fall back to the zero order allocations */
-			alloc_gfp |= __GFP_NOFAIL;
-			order = 0;
-			continue;
-		}

 		/*
 		 * Higher order allocations must be able to be treated as
--
After 1) I check the code and I can't find a resonable band-aid to fix
this. so the v2 patch works but ugly. Glad to hear a better solution :)

[1] https://lore.kernel.org/lkml/20240724182827.nlgdckimtg2gwns5@oppo.com/
2.34.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-07-30  4:30 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-25  3:53 [RFC PATCH v2] mm/vmalloc: fix incorrect __vmap_pages_range_noflush() if vm_area_alloc_pages() from high order fallback to order0 hailong.liu
2024-07-25  6:21 ` Barry Song
2024-07-25  9:17   ` Hailong Liu
2024-07-25  9:34     ` Barry Song
2024-07-25  9:58       ` Hailong Liu
2024-07-25 10:22         ` Barry Song
2024-07-25 11:39 ` Baoquan He
2024-07-25 16:40   ` Hailong Liu
2024-07-26  1:31     ` Barry Song
2024-07-26  2:31     ` Baoquan He
2024-07-26  3:53       ` Barry Song
2024-07-29  1:48         ` Baoquan He
2024-07-30  3:24           ` Hailong Liu
2024-07-30  4:29             ` Baoquan He
2024-07-26  4:00       ` Hailong Liu
2024-07-26  5:03         ` Hailong Liu
2024-07-26  5:29           ` Barry Song
2024-07-26  8:37             ` Baoquan He
2024-07-26  8:48               ` Hailong Liu
2024-07-26  9:00                 ` Hailong Liu
2024-07-26  9:29                 ` Baoquan He
2024-07-26  9:15               ` Barry Song

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