[PATCH 1/3] vmalloc: add __GFP_SKIP_KASAN support
From: Muhammad Usama Anjum
Date: Thu Mar 19 2026 - 07:53:05 EST
For allocations that will be accessed only with match-all pointers
(e.g., kernel stacks), setting tags is wasted work. If the caller
already set __GFP_SKIP_KASAN, don’t skip zeroing the pages and
don’t set KASAN_VMALLOC_PROT_NORMAL so kasan_unpoison_vmalloc()
returns early without tagging.
Before this patch, __GFP_SKIP_KASAN wasn't being used with vmalloc
APIs. So it wasn't being checked. Now its being checked and acted
upon. Other KASAN modes are unchanged because __GFP_SKIP_KASAN isn't
defined there.
This is a preparatory patch for optimizing kernel stack allocations.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
---
mm/vmalloc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index c607307c657a6..1baa602a0b9bb 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4041,7 +4041,10 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
* kasan_unpoison_vmalloc().
*/
if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) {
- if (kasan_hw_tags_enabled()) {
+ bool skip_kasan = kasan_hw_tags_enabled() &&
+ (gfp_mask & __GFP_SKIP_KASAN);
+
+ if (kasan_hw_tags_enabled() && !skip_kasan) {
/*
* Modify protection bits to allow tagging.
* This must be done before mapping.
@@ -4057,7 +4060,8 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
}
/* Take note that the mapping is PAGE_KERNEL. */
- kasan_flags |= KASAN_VMALLOC_PROT_NORMAL;
+ if (!skip_kasan)
+ kasan_flags |= KASAN_VMALLOC_PROT_NORMAL;
}
/* Allocate physical pages and map them into vmalloc space. */
--
2.47.3