[PATCH v5 08/11] mm/vmalloc: drop the KMSAN metadata in vmap_pages_range_noflush() on failure

From
Hao Ge <hao.ge@linux.dev>
Date
2026-11-16 07:14:29
Also in
linux-mm, lkml
Reply to
Hao Ge, 2026-11-16
vmap_pages_range_noflush() sets up the KMSAN metadata for the whole
range before it starts mapping. If the mapping fails, the page
tables undo themselves now, but the metadata stays behind, and the
next attempt to map the same range hits the leftover shadow PTEs.

Tear the metadata down on the error path, it was fully set up before
the mapping failed. The teardown follows the page tables and skips
cond_resched() when the caller's gfp mask cannot block.

Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
 mm/vmalloc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 4f3c320a4849..28e65073624a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -801,8 +801,18 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end,
 
 	if (ret)
 		return ret;
-	return __vmap_pages_range_noflush(addr, end, prot, pages, page_shift,
-					  gfp_mask);
+
+	ret = __vmap_pages_range_noflush(addr, end, prot, pages, page_shift,
+					 gfp_mask);
+	/*
+	 * The page tables undo themselves on failure. Tear down the
+	 * metadata that was fully set up before the mapping failed.
+	 */
+	if (ret)
+		kmsan_vunmap_range_noflush(addr, end,
+					   gfpflags_allow_blocking(gfp_mask));
+
+	return ret;
 }
 
 static int __vmap_pages_range(unsigned long addr, unsigned long end,
-- 
2.25.1

Thread (12 messages) 12 messages, 1 author, last reply 13h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help