[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251030164330.44995-2-vishal.moola@gmail.com>
Date: Thu, 30 Oct 2025 09:43:27 -0700
From: "Vishal Moola (Oracle)" <vishal.moola@...il.com>
To: linux-kernel@...r.kernel.org,
	linux-mm@...ck.org
Cc: Uladzislau Rezki <urezki@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Christoph Hellwig <hch@...radead.org>,
	"Vishal Moola (Oracle)" <vishal.moola@...il.com>
Subject: [RFC PATCH 1/4] mm/vmalloc: warn on invalid vmalloc gfp flags
There are some gfp flags that are not supported by vmalloc.
vmalloc has been trying to handle these by clearing and setting flags
wherever necessary. This is messy and makes the code harder to
understand, when we could simply check for these unsupported flags
immediately.
Define a helper mask and function telling callers they have passed in
invalid flags, and clear those unsupported vmalloc flags.
Suggested-by: Christoph Hellwig <hch@...radead.org>
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@...il.com>
---
 mm/vmalloc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 0832f944544c..b86c36d51833 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3911,6 +3911,20 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 	return NULL;
 }
 
+#define GFP_VMALLOC_BUG_MASK (__GFP_COMP|__GFP_RETRY_MAYFAIL|\
+			      ~__GFP_BITS_MASK)
+static gfp_t vmalloc_fix_flags(gfp_t flags)
+{
+	gfp_t invalid_mask = flags & GFP_VMALLOC_BUG_MASK;
+
+	flags &= ~GFP_VMALLOC_BUG_MASK;
+	pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x (%pGg). Fix your code!\n",
+			invalid_mask, &invalid_mask, flags, &flags);
+	dump_stack();
+
+	return flags;
+}
+
 /**
  * __vmalloc_node_range - allocate virtually contiguous memory
  * @size:		  allocation size
@@ -3961,6 +3975,9 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 		return NULL;
 	}
 
+	if (unlikely(gfp_mask & GFP_VMALLOC_BUG_MASK))
+		gfp_mask = vmalloc_fix_flags(gfp_mask);
+
 	if (vmap_allow_huge && (vm_flags & VM_ALLOW_HUGE_VMAP)) {
 		/*
 		 * Try huge pages. Only try for PAGE_KERNEL allocations,
-- 
2.51.1
Powered by blists - more mailing lists
 
