* [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling
@ 2026-12-03 9:27 Hao Ge
2026-12-03 9:27 ` [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context Hao Ge
` (9 more replies)
0 siblings, 10 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge
__vmap_pages_range_noflush() and friends can install some PTEs before
failing and leave them mapped, and the kernel callers do not agree on
who cleans them up. pcpu_map_pages() and kmsan_ioremap_page_range()
roll back what they mapped before the failure, while
vm_module_tags_populate() and the __GFP_NOFAIL retry loop in
__vmalloc_area_node() rely on the mapping functions cleaning up and
do not call anything like vunmap_range() themselves. When the same
range is mapped again, the attempt hits the leftovers and fails with
a warning in vmap_pages_pte_range(). A leftover huge pmd is worse.
During the retry, vmap_try_huge_pmd() calls pmd_free_pte_page() on
it, and the x86 implementation cannot tell a leaf entry from a page
table and frees the mapped page.
After discussing with Suren and Ulad [1], we move the rollback into
the mapping functions. A failed vmap leaves nothing mapped, and the
callers no longer clean up after it.
Patch 1 gives __vunmap_range_noflush() a can_resched argument, the
failure paths can be reached with a non-blocking gfp mask and the
undo must not schedule there. Patch 2 is the KMSAN part, the shadow
and the origin of a range are mapped by two separate calls, so the
rollback there has to cover both. Patch 3 fixes a stale name in a
comment, patch 4 the order of the cache flushes around the KMSAN
metadata. Patches 5 and 6 reject an unaligned range at the entries of
vmap_page_range() and __vunmap_range_noflush(). Patch 7 adds the
rollback to vmap_page_range(), patch 8 to __vmap_pages_range_noflush(),
the KMSAN metadata and the batched vmap() path. Patches 9 and 10 drop
the powerpc and percpu cleanups that are not needed anymore.
Changes since v5:
- new patch 3, the comment of __vunmap_range_noflush() asks the
caller for flush_cache_vmap(), it should be flush_cache_vunmap()
- new patch 4, the KMSAN metadata teardown flushed the cache after
the page tables were cleared, the order is the other way round, and
the ioremap metadata pages are now flushed before they are freed
- v5 patch 1 is renamed and its Fixes: tag is dropped, so it does not
travel to stable together with patch 2 anymore
- v5 patch 2 flushes the cache and the TLB of the shadow range now,
as Documentation/core-api/cachetlb.rst requires
- v5 patch 5 is folded into patch 7, the cache is only flushed after
the vmap succeeded
- v5 patches 8 and 9 are folded into patch 8, together with the
rollback of the KMSAN metadata and of the batched vmap() path
- the rollback uses the new vunmap_range_nokmsan(), it flushes the
cache and the TLB of the range it undoes
- the rollback of the KMSAN metadata uses the new kmsan_vunmap_range(),
it flushes the TLB of the metadata windows
- mapped_pages is an unsigned long now, the byte count of the undone
range overflowed an unsigned int on large mappings
- the range that the walk mapped is tracked per PMD now, v5 tracked it
per PTE chunk
[1] https://lore.kernel.org/all/20260915070001.113559-3-hao.ge@linux.dev/
v5 link: https://lore.kernel.org/all/20261116071325.263682-1-hao.ge@linux.dev/
v4 link: https://lore.kernel.org/all/20261110112546.261415-1-hao.ge@linux.dev/
v3 link: https://lore.kernel.org/all/20261026080329.140244-1-hao.ge@linux.dev/
v2 link: https://lore.kernel.org/all/20261019054531.87652-1-hao.ge@linux.dev/
v1 link: https://lore.kernel.org/all/20261009063619.112313-1-hao.ge@linux.dev/
Hao Ge (10):
mm/vmalloc: allow the vmap unmap paths to run in atomic context
mm/kmsan: undo the shadow mapping when the origin mapping fails
mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment
mm/kmsan: fix the metadata cache flush ordering
mm/vmalloc: reject an unaligned range in vmap_page_range()
mm/vmalloc: reject an unaligned range in __vunmap_range_noflush()
mm/vmalloc: undo what a failed vmap_page_range() installed
mm/vmalloc: undo what a failed __vmap_pages_range_noflush() installed
powerpc: drop redundant unmaps of failed vmap mappings
mm/percpu: stop unmapping the CPU that failed to map
arch/powerpc/kernel/isa-bridge.c | 5 +-
arch/powerpc/kernel/pci_64.c | 4 +-
include/linux/kmsan.h | 27 ++++-
mm/kmsan/hooks.c | 42 +++++---
mm/kmsan/shadow.c | 11 +-
mm/percpu-vm.c | 5 +-
mm/vmalloc.c | 175 ++++++++++++++++++++++++-------
mm/vmalloc.h | 9 +-
8 files changed, 214 insertions(+), 64 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 02/10] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
` (8 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, Sashiko
The vmap failure paths can be reached with GFP_ATOMIC or GFP_NOWAIT
since commit b186a94227b7 ("kmsan: remove hard-coded GFP_KERNEL
flags") and commit 8da89ba18ed4 ("mm/vmalloc: handle non-blocking
GFP in __vmalloc_area_node()"). An undo of a partially installed
mapping has to run in atomic context there, and the cond_resched()
in vunmap_pmd_range() cannot schedule.
Give __vunmap_range_noflush() and kmsan_vunmap_range_noflush() a
can_resched argument and skip the cond_resched() when it is false.
The existing callers are on sleepable paths and pass true, so nothing
changes for them.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-178439@kernel.org/
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
include/linux/kmsan.h | 8 ++++++--
mm/kmsan/hooks.c | 14 +++++++++-----
mm/vmalloc.c | 24 ++++++++++++++----------
mm/vmalloc.h | 3 ++-
4 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h
index 08fb79566235..e071c33abded 100644
--- a/include/linux/kmsan.h
+++ b/include/linux/kmsan.h
@@ -152,11 +152,14 @@ int __must_check kmsan_vmap_pages_range_noflush(unsigned long start,
* kmsan_vunmap_kernel_range_noflush() - Notify KMSAN about a vunmap.
* @start: start of vunmapped range.
* @end: end of vunmapped range.
+ * @can_resched: whether the unmap walk may call cond_resched(); pass
+ * false from atomic context.
*
* KMSAN unmaps the contiguous metadata ranges created by
* kmsan_map_kernel_range_noflush().
*/
-void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end);
+void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end,
+ bool can_resched);
/**
* kmsan_ioremap_page_range() - Notify KMSAN about a ioremap_page_range() call.
@@ -357,7 +360,8 @@ static inline int __must_check kmsan_vmap_pages_range_noflush(
}
static inline void kmsan_vunmap_range_noflush(unsigned long start,
- unsigned long end)
+ unsigned long end,
+ bool can_resched)
{
}
diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c
index a706666db097..69008b085658 100644
--- a/mm/kmsan/hooks.c
+++ b/mm/kmsan/hooks.c
@@ -136,10 +136,13 @@ static unsigned long vmalloc_origin(unsigned long addr)
KMSAN_META_ORIGIN);
}
-void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end)
+void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end,
+ bool can_resched)
{
- __vunmap_range_noflush(vmalloc_shadow(start), vmalloc_shadow(end));
- __vunmap_range_noflush(vmalloc_origin(start), vmalloc_origin(end));
+ __vunmap_range_noflush(vmalloc_shadow(start), vmalloc_shadow(end),
+ can_resched);
+ __vunmap_range_noflush(vmalloc_origin(start), vmalloc_origin(end),
+ can_resched);
flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
}
@@ -168,8 +171,9 @@ static void kmsan_iounmap_pages(unsigned long start, unsigned long end)
if (origin)
__free_pages(origin, KMSAN_IOREMAP_META_ORDER);
}
- __vunmap_range_noflush(shadow_start, shadow_end);
- __vunmap_range_noflush(origin_start, origin_end);
+ /* ioremap metadata mappings are always GFP_KERNEL, so resched is safe. */
+ __vunmap_range_noflush(shadow_start, shadow_end, true);
+ __vunmap_range_noflush(origin_start, origin_end, true);
flush_tlb_kernel_range(shadow_start, shadow_end);
flush_tlb_kernel_range(origin_start, origin_end);
}
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ee722162da7c..1fe81a7e617b 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -429,7 +429,7 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
}
static void vunmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
- pgtbl_mod_mask *mask)
+ pgtbl_mod_mask *mask, bool can_resched)
{
pmd_t *pmd;
unsigned long next;
@@ -451,12 +451,14 @@ static void vunmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
continue;
vunmap_pte_range(pmd, addr, next, mask);
- cond_resched();
+ /* The undo path may run in atomic context. */
+ if (can_resched)
+ cond_resched();
} while (pmd++, addr = next, addr != end);
}
static void vunmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
- pgtbl_mod_mask *mask)
+ pgtbl_mod_mask *mask, bool can_resched)
{
pud_t *pud;
unsigned long next;
@@ -476,12 +478,12 @@ static void vunmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
}
if (pud_none_or_clear_bad(pud))
continue;
- vunmap_pmd_range(pud, addr, next, mask);
+ vunmap_pmd_range(pud, addr, next, mask, can_resched);
} while (pud++, addr = next, addr != end);
}
static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
- pgtbl_mod_mask *mask)
+ pgtbl_mod_mask *mask, bool can_resched)
{
p4d_t *p4d;
unsigned long next;
@@ -496,7 +498,7 @@ static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
if (p4d_none_or_clear_bad(p4d))
continue;
- vunmap_pud_range(p4d, addr, next, mask);
+ vunmap_pud_range(p4d, addr, next, mask, can_resched);
} while (p4d++, addr = next, addr != end);
}
@@ -512,7 +514,8 @@ static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
*
* This is an internal function only. Do not use outside mm/.
*/
-void __vunmap_range_noflush(unsigned long start, unsigned long end)
+void __vunmap_range_noflush(unsigned long start, unsigned long end,
+ bool can_resched)
{
unsigned long next;
pgd_t *pgd;
@@ -527,7 +530,7 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end)
mask |= PGTBL_PGD_MODIFIED;
if (pgd_none_or_clear_bad(pgd))
continue;
- vunmap_p4d_range(pgd, addr, next, &mask);
+ vunmap_p4d_range(pgd, addr, next, &mask, can_resched);
} while (pgd++, addr = next, addr != end);
if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
@@ -536,8 +539,9 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end)
void vunmap_range_noflush(unsigned long start, unsigned long end)
{
- kmsan_vunmap_range_noflush(start, end);
- __vunmap_range_noflush(start, end);
+ /* The unmap paths are sleepable, keep the resched point. */
+ kmsan_vunmap_range_noflush(start, end, true);
+ __vunmap_range_noflush(start, end, true);
}
/**
diff --git a/mm/vmalloc.h b/mm/vmalloc.h
index d8372a4f65c4..4ec114a75f04 100644
--- a/mm/vmalloc.h
+++ b/mm/vmalloc.h
@@ -44,6 +44,7 @@ int __must_check __vmap_pages_range_noflush(unsigned long addr,
void vunmap_range_noflush(unsigned long start, unsigned long end);
-void __vunmap_range_noflush(unsigned long start, unsigned long end);
+void __vunmap_range_noflush(unsigned long start, unsigned long end,
+ bool can_resched);
#endif /* __MM_VMALLOC_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 02/10] mm/kmsan: undo the shadow mapping when the origin mapping fails
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
2026-12-03 9:27 ` [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 9:27 ` [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment Hao Ge
` (7 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, stable
kmsan_vmap_pages_range_noflush() first maps the shadow pages and then
the origin pages. If the second mapping fails, the first one is left
mapped, and the callers do not roll it back. The next vmap of the
same metadata range hits the stale PTEs again and fails with a
WARN_ON() and -EBUSY in vmap_pages_pte_range().
Undo the shadow mapping on that error path and flush the cache and the
TLB for the shadow range. The mapping may still be cached even though
nothing accessed it, and Documentation/core-api/cachetlb.rst requires
the cache flush to happen before the page table change and the TLB
flush after it.
Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()")
Cc: stable@vger.kernel.org
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/kmsan/shadow.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
index fa2a403d87c2..1af03f83d2ea 100644
--- a/mm/kmsan/shadow.c
+++ b/mm/kmsan/shadow.c
@@ -343,6 +343,13 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
o_pages, page_shift);
kmsan_leave_runtime();
if (mapped) {
+ /* Undo the shadow mapping set up above. */
+ flush_cache_vunmap(shadow_start, shadow_end);
+ kmsan_enter_runtime();
+ __vunmap_range_noflush(shadow_start, shadow_end,
+ gfpflags_allow_blocking(gfp_mask));
+ kmsan_leave_runtime();
+ flush_tlb_kernel_range(shadow_start, shadow_end);
err = mapped;
goto ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
2026-12-03 9:27 ` [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context Hao Ge
2026-12-03 9:27 ` [PATCH v6 02/10] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 04/10] mm/kmsan: fix the metadata cache flush ordering Hao Ge
` (6 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, stable
The comment asks the caller to call flush_cache_vmap() before calling
this function. flush_cache_vunmap() is meant here, the old comment that
commit 4ad0ae8c64ac ("mm/vmalloc: remove unmap_kernel_range") replaced
said flush_cache_vunmap(), and Documentation/core-api/cachetlb.rst and
vunmap_range() both use flush_cache_vunmap() before the page tables are
torn down.
Fixes: 4ad0ae8c64ac ("mm/vmalloc: remove unmap_kernel_range")
Cc: stable@vger.kernel.org
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/vmalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 1fe81a7e617b..1580b2c72727 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -506,7 +506,7 @@ static void vunmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
* vunmap_range_noflush is similar to vunmap_range, but does not
* flush caches or TLBs.
*
- * The caller is responsible for calling flush_cache_vmap() before calling
+ * The caller is responsible for calling flush_cache_vunmap() before calling
* this function, and flush_tlb_kernel_range after it has returned
* successfully (and before the addresses are expected to cause a page fault
* or be re-mapped for something else, if TLB flushes are being delayed or
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 04/10] mm/kmsan: fix the metadata cache flush ordering
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (2 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 9:27 ` [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range() Hao Ge
` (5 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, stable
kmsan_vunmap_range_noflush(), kmsan_iounmap_page_range() and the
error cleanup of kmsan_ioremap_page_range() all call
flush_cache_vmap() after the page tables were cleared.
Documentation/core-api/cachetlb.rst is explicit about the order.
6) void flush_cache_vmap(unsigned long start, unsigned long end)
void flush_cache_vunmap(unsigned long start, unsigned long end)
The first of these two routines is invoked after vmap_range()
has installed the page table entries. The second is invoked
before vunmap_range() deletes the page table entries.
Switch the teardown paths to flush_cache_vunmap() before clearing
the PTEs, and before the metadata pages are freed: a dirty cache line of
a freed page may be written back after the page has been handed out to
somebody else. The iounmap side does the flush inside
kmsan_iounmap_pages(). The successful install path of
kmsan_ioremap_page_range() keeps its flush_cache_vmap(), as it runs
after the install.
Fixes: b073d7f8aee4 ("mm: kmsan: maintain KMSAN metadata for page operations")
Cc: stable@vger.kernel.org
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/kmsan/hooks.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c
index 69008b085658..f2d6a598ad3c 100644
--- a/mm/kmsan/hooks.c
+++ b/mm/kmsan/hooks.c
@@ -139,12 +139,12 @@ static unsigned long vmalloc_origin(unsigned long addr)
void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end,
bool can_resched)
{
+ flush_cache_vunmap(vmalloc_shadow(start), vmalloc_shadow(end));
+ flush_cache_vunmap(vmalloc_origin(start), vmalloc_origin(end));
__vunmap_range_noflush(vmalloc_shadow(start), vmalloc_shadow(end),
can_resched);
__vunmap_range_noflush(vmalloc_origin(start), vmalloc_origin(end),
can_resched);
- flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
- flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
}
#define KMSAN_IOREMAP_META_ORDER 1
@@ -162,6 +162,10 @@ static void kmsan_iounmap_pages(unsigned long start, unsigned long end)
nr = (end - start) / PAGE_SIZE;
v_shadow = shadow_start;
v_origin = origin_start;
+
+ flush_cache_vunmap(shadow_start, shadow_end);
+ flush_cache_vunmap(origin_start, origin_end);
+
for (int i = 0; i < nr;
i++, v_shadow += PAGE_SIZE, v_origin += PAGE_SIZE) {
shadow = kmsan_vmalloc_to_page_or_null((void *)v_shadow);
@@ -171,6 +175,7 @@ static void kmsan_iounmap_pages(unsigned long start, unsigned long end)
if (origin)
__free_pages(origin, KMSAN_IOREMAP_META_ORDER);
}
+
/* ioremap metadata mappings are always GFP_KERNEL, so resched is safe. */
__vunmap_range_noflush(shadow_start, shadow_end, true);
__vunmap_range_noflush(origin_start, origin_end, true);
@@ -235,9 +240,10 @@ int kmsan_ioremap_page_range(unsigned long start, unsigned long end,
if (mapped_end > start)
kmsan_iounmap_pages(start, mapped_end);
+ } else {
+ flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
+ flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
}
- flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
- flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
kmsan_leave_runtime();
return err;
}
@@ -249,8 +255,6 @@ void kmsan_iounmap_page_range(unsigned long start, unsigned long end)
kmsan_enter_runtime();
kmsan_iounmap_pages(start, end);
- flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
- flush_cache_vmap(vmalloc_origin(start), vmalloc_origin(end));
kmsan_leave_runtime();
}
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range()
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (3 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 04/10] mm/kmsan: fix the metadata cache flush ordering Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 06/10] mm/vmalloc: reject an unaligned range in __vunmap_range_noflush() Hao Ge
` (4 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge
commit a739e6b557af ("mm: vmalloc: WARN_ON if mapping size is not
PAGE_SIZE aligned") put the check in vmap_pte_range(), which is too
late, because the upper levels may already have installed page tables
for a range that is rejected anyway.
The pte loop maps whole pages and stops only when addr lands exactly
on end. An unaligned end lets addr jump over it and the loop keeps
mapping past the range. An unaligned start maps the page below the
range and usually misses end too. Such a range is never a legitimate
request.
vmap_range_noflush() has a single caller, vmap_page_range(). Warn on
addr and end there and bail out with -EINVAL before any page table is
installed, and drop the check from vmap_pte_range().
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Suggested-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/vmalloc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 1580b2c72727..081c672f63ee 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -125,9 +125,6 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
unsigned long size;
unsigned int nr_pages;
- if (WARN_ON_ONCE(!PAGE_ALIGNED(end - addr)))
- return -EINVAL;
-
pfn = phys_addr >> PAGE_SHIFT;
pte = pte_alloc_kernel_track(pmd, addr, mask);
if (!pte)
@@ -369,6 +366,11 @@ int vmap_page_range(unsigned long addr, unsigned long end,
{
int err;
+ if (WARN_ON_ONCE(!PAGE_ALIGNED(addr)))
+ return -EINVAL;
+ if (WARN_ON_ONCE(!PAGE_ALIGNED(end)))
+ return -EINVAL;
+
err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
ioremap_max_page_shift);
flush_cache_vmap(addr, end);
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 06/10] mm/vmalloc: reject an unaligned range in __vunmap_range_noflush()
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (4 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range() Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 9:27 ` [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed Hao Ge
` (3 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, Sashiko
The PTE loop stops only at addr == end. An unaligned end is never
reached, so the loop keeps clearing past the range. An unaligned
start clears the page below the range first. Both are caller bugs,
and the damage is hard to attribute afterwards.
vmap only installs page aligned mappings, so an unaligned unmap
request is never a legitimate teardown. Warn and bail out at the
entry of __vunmap_range_noflush(), before any PTE is cleared.
The adjacent BUG_ON(addr >= end) is converted to the same
WARN_ON_ONCE() + return, since an empty range is a caller bug too.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-178439@kernel.org/
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/vmalloc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 081c672f63ee..dcf3ddc0c6c0 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -524,7 +524,13 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end,
unsigned long addr = start;
pgtbl_mod_mask mask = 0;
- BUG_ON(addr >= end);
+ if (WARN_ON_ONCE(addr >= end))
+ return;
+ if (WARN_ON_ONCE(!PAGE_ALIGNED(addr)))
+ return;
+ if (WARN_ON_ONCE(!PAGE_ALIGNED(end)))
+ return;
+
pgd = pgd_offset_k(addr);
do {
next = pgd_addr_end(addr, end);
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (5 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 06/10] mm/vmalloc: reject an unaligned range in __vunmap_range_noflush() Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 08/10] mm/vmalloc: undo what a failed __vmap_pages_range_noflush() installed Hao Ge
` (2 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, Sashiko
vmap_page_range() maps a physical range for ioremap and arch setup
code. The walk may fail halfway, or the KMSAN metadata may fail
after the walk, and the PTEs installed so far stay behind. The
callers do not agree on who cleans it up. The ioremap
implementations free the vm_area, which unmaps the whole range,
and powerpc calls vunmap_range() itself. The arch setup code that
maps a fixed PCI_IOBASE range either ignores the return value or
has no vm_area to free, and leaves the PTEs in place.
vmap_range_noflush() now takes a mapped_end argument that tracks
how far the walk got, and the error path undoes [addr, mapped_end),
never past the failure point. The PTEs above it were not installed
by this call and may be in use by somebody else, clearing them is
not up to the undo. If the walk completed and only the KMSAN
metadata failed, the whole range was installed by this call, and
all of it is undone.
The flush_cache_vmap() also moves after the error check. Flushing
a half-installed mapping is pointless, and on UML it is worse,
flush_cache_vmap() there is flush_tlb_kernel_range(), which syncs
the PTEs into the host OS and would leave host mappings behind
for a range that was just freed again.
The undo paths use the new vunmap_range_nokmsan() helper, which
flushes the cache, clears the PTEs and flushes the TLB, and leaves
the KMSAN metadata to the caller.
All callers are sleepable, the teardown passes can_resched = true.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-178439@kernel.org/
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/vmalloc.c | 72 ++++++++++++++++++++++++++++++++++++++++++++--------
mm/vmalloc.h | 3 +++
2 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index dcf3ddc0c6c0..0f2b50ad1a7d 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -188,7 +188,8 @@ static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
static int vmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
- unsigned int max_page_shift, pgtbl_mod_mask *mask)
+ unsigned int max_page_shift, pgtbl_mod_mask *mask,
+ unsigned long *mapped_end)
{
pmd_t *pmd;
unsigned long next;
@@ -203,12 +204,15 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
if (vmap_try_huge_pmd(pmd, addr, next, phys_addr, prot,
max_page_shift)) {
*mask |= PGTBL_PMD_MODIFIED;
+ *mapped_end = next;
continue;
}
- err = vmap_pte_range(pmd, addr, next, phys_addr, prot, max_page_shift, mask);
+ err = vmap_pte_range(pmd, addr, next, phys_addr, prot,
+ max_page_shift, mask);
if (err)
break;
+ *mapped_end = next;
} while (pmd++, phys_addr += (next - addr), addr = next, addr != end);
return err;
}
@@ -245,7 +249,8 @@ static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
static int vmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
- unsigned int max_page_shift, pgtbl_mod_mask *mask)
+ unsigned int max_page_shift, pgtbl_mod_mask *mask,
+ unsigned long *mapped_end)
{
pud_t *pud;
unsigned long next;
@@ -260,10 +265,12 @@ static int vmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
if (vmap_try_huge_pud(pud, addr, next, phys_addr, prot,
max_page_shift)) {
*mask |= PGTBL_PUD_MODIFIED;
+ *mapped_end = next;
continue;
}
- err = vmap_pmd_range(pud, addr, next, phys_addr, prot, max_page_shift, mask);
+ err = vmap_pmd_range(pud, addr, next, phys_addr, prot,
+ max_page_shift, mask, mapped_end);
if (err)
break;
} while (pud++, phys_addr += (next - addr), addr = next, addr != end);
@@ -302,7 +309,8 @@ static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
- unsigned int max_page_shift, pgtbl_mod_mask *mask)
+ unsigned int max_page_shift, pgtbl_mod_mask *mask,
+ unsigned long *mapped_end)
{
p4d_t *p4d;
unsigned long next;
@@ -317,10 +325,12 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
if (vmap_try_huge_p4d(p4d, addr, next, phys_addr, prot,
max_page_shift)) {
*mask |= PGTBL_P4D_MODIFIED;
+ *mapped_end = next;
continue;
}
- err = vmap_pud_range(p4d, addr, next, phys_addr, prot, max_page_shift, mask);
+ err = vmap_pud_range(p4d, addr, next, phys_addr, prot,
+ max_page_shift, mask, mapped_end);
if (err)
break;
} while (p4d++, phys_addr += (next - addr), addr = next, addr != end);
@@ -329,7 +339,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,
static int vmap_range_noflush(unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot,
- unsigned int max_page_shift)
+ unsigned int max_page_shift, unsigned long *mapped_end)
{
pgd_t *pgd;
unsigned long start;
@@ -346,11 +356,12 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
BUG_ON(addr >= end);
start = addr;
+ *mapped_end = addr;
pgd = pgd_offset_k(addr);
do {
next = pgd_addr_end(addr, end);
err = vmap_p4d_range(pgd, addr, next, phys_addr, prot,
- max_page_shift, &mask);
+ max_page_shift, &mask, mapped_end);
if (err)
break;
} while (pgd++, phys_addr += (next - addr), addr = next, addr != end);
@@ -364,6 +375,7 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
int vmap_page_range(unsigned long addr, unsigned long end,
phys_addr_t phys_addr, pgprot_t prot)
{
+ unsigned long mapped_end = addr;
int err;
if (WARN_ON_ONCE(!PAGE_ALIGNED(addr)))
@@ -372,11 +384,26 @@ int vmap_page_range(unsigned long addr, unsigned long end,
return -EINVAL;
err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
- ioremap_max_page_shift);
- flush_cache_vmap(addr, end);
- if (!err)
+ ioremap_max_page_shift, &mapped_end);
+ if (err) {
+ /* Undo the part the walk installed before it failed. */
+ if (mapped_end > addr)
+ vunmap_range_nokmsan(addr, mapped_end, true);
+ } else {
err = kmsan_ioremap_page_range(addr, end, phys_addr, prot,
ioremap_max_page_shift);
+ if (err) {
+ /*
+ * Only the KMSAN metadata failed, the walk mapped
+ * the whole range. Undo it all. The callers are
+ * ioremap and arch setup code, always sleepable.
+ */
+ vunmap_range_nokmsan(addr, end, true);
+ } else {
+ flush_cache_vmap(addr, end);
+ }
+ }
+
return err;
}
@@ -552,6 +579,29 @@ void vunmap_range_noflush(unsigned long start, unsigned long end)
__vunmap_range_noflush(start, end, true);
}
+/**
+ * vunmap_range_nokmsan - unmap kernel virtual addresses without the
+ * KMSAN part
+ * @addr: start of the VM area to unmap
+ * @end: end of the VM area to unmap (non-inclusive)
+ * @can_resched: whether the unmap walk may call cond_resched(); pass
+ * false from atomic context.
+ *
+ * Clears any present PTEs in the virtual address range, flushes TLBs and
+ * caches, but leaves the KMSAN metadata to the caller. The undo paths
+ * use this for a range that is not going back to vmalloc, which would
+ * flush the TLB lazily, so nobody else flushes it.
+ *
+ * This is an internal function only. Do not use outside mm/.
+ */
+void vunmap_range_nokmsan(unsigned long addr, unsigned long end,
+ bool can_resched)
+{
+ flush_cache_vunmap(addr, end);
+ __vunmap_range_noflush(addr, end, can_resched);
+ flush_tlb_kernel_range(addr, end);
+}
+
/**
* vunmap_range - unmap kernel virtual addresses
* @addr: start of the VM area to unmap
diff --git a/mm/vmalloc.h b/mm/vmalloc.h
index 4ec114a75f04..4406a1c5b1e9 100644
--- a/mm/vmalloc.h
+++ b/mm/vmalloc.h
@@ -47,4 +47,7 @@ void vunmap_range_noflush(unsigned long start, unsigned long end);
void __vunmap_range_noflush(unsigned long start, unsigned long end,
bool can_resched);
+void vunmap_range_nokmsan(unsigned long start, unsigned long end,
+ bool can_resched);
+
#endif /* __MM_VMALLOC_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 08/10] mm/vmalloc: undo what a failed __vmap_pages_range_noflush() installed
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (6 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 9:27 ` [PATCH v6 09/10] powerpc: drop redundant unmaps of failed vmap mappings Hao Ge
2026-12-03 9:27 ` [PATCH v6 10/10] mm/percpu: stop unmapping the CPU that failed to map Hao Ge
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge, Sashiko
A page array is mapped into a contiguous virtual range by
__vmap_pages_range_noflush(), which serves vmap_pages_range() and
the vmalloc paths, and by vmap_pages_range_batched(), which serves
vmap(). The walk may fail halfway, and the PTEs installed so far
stay behind.
The callers do not agree on who cleans it up. pcpu_map_pages() and
kmsan_ioremap_page_range() roll back what they mapped, while
vm_module_tags_populate() and the __GFP_NOFAIL retry loop in
__vmalloc_area_node() expect a clean range from the mapping function.
For them the leftovers stay mapped, and the next attempt to map the
same range trips the WARN_ON(!pte_none()) in vmap_pages_pte_range().
Both __vmap_pages_range_noflush() and vmap_pages_range_batched()
now undo what they installed, up to the point where the walk
failed. vmap_pages_range_noflush_walk() reports how many pages it
mapped through its index into the pages array, and the batched path
uses the end of the last installed batch.
Going further would clear PTEs that are not ours.
vmap_pages_pte_range() fails with -EBUSY instead of installing over
a PTE that is already set, so a PTE below the failure point can
only be ours, and a PTE above it belongs to somebody else, for
example when the caller's range overlaps an existing mapping.
The flush_cache_vmap() now only runs when the mapping succeeded,
as flushing a half-installed mapping is pointless. The undo flushes
the cache and the TLB itself with vunmap_range_nokmsan(), which
leaves the KMSAN metadata alone.
The KMSAN metadata is set up for the whole range before the mapping
starts, so the undo tears it down as a whole and flushes its TLB
right away, since the undo paths do not go through the lazy purge
and vmap() may retry the range right after. The undo may run with
a non-blocking gfp mask, so it passes gfpflags_allow_blocking() as
can_resched.
The undo calls a new kmsan_vunmap_range(), which tears the
metadata down and flushes its TLB in one go.
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Suggested-by: Uladzislau Rezki <urezki@gmail.com>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-a99dfd25-ba6c-40a4-94db-2046a2d97d70
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
include/linux/kmsan.h | 19 ++++++++++++++
mm/kmsan/hooks.c | 12 +++++++--
mm/kmsan/shadow.c | 4 +--
mm/vmalloc.c | 61 +++++++++++++++++++++++++++++++++++--------
mm/vmalloc.h | 3 ++-
5 files changed, 83 insertions(+), 16 deletions(-)
diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h
index e071c33abded..02b46e44385a 100644
--- a/include/linux/kmsan.h
+++ b/include/linux/kmsan.h
@@ -161,6 +161,19 @@ int __must_check kmsan_vmap_pages_range_noflush(unsigned long start,
void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end,
bool can_resched);
+/**
+ * kmsan_vunmap_range() - Notify KMSAN about a vunmap.
+ * @start: start of vunmapped range.
+ * @end: end of vunmapped range.
+ * @can_resched: whether the unmap walk may call cond_resched(); pass
+ * false from atomic context.
+ *
+ * KMSAN clears any present PTEs of the shadow and the origin of the range,
+ * flushes TLBs and caches.
+ */
+void kmsan_vunmap_range(unsigned long start, unsigned long end,
+ bool can_resched);
+
/**
* kmsan_ioremap_page_range() - Notify KMSAN about a ioremap_page_range() call.
* @addr: range start.
@@ -365,6 +378,12 @@ static inline void kmsan_vunmap_range_noflush(unsigned long start,
{
}
+static inline void kmsan_vunmap_range(unsigned long start,
+ unsigned long end,
+ bool can_resched)
+{
+}
+
static inline int __must_check kmsan_ioremap_page_range(unsigned long start,
unsigned long end,
phys_addr_t phys_addr,
diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c
index f2d6a598ad3c..674a89196d49 100644
--- a/mm/kmsan/hooks.c
+++ b/mm/kmsan/hooks.c
@@ -147,6 +147,14 @@ void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end,
can_resched);
}
+void kmsan_vunmap_range(unsigned long start, unsigned long end,
+ bool can_resched)
+{
+ kmsan_vunmap_range_noflush(start, end, can_resched);
+ flush_tlb_kernel_range(vmalloc_shadow(start), vmalloc_shadow(end));
+ flush_tlb_kernel_range(vmalloc_origin(start), vmalloc_origin(end));
+}
+
#define KMSAN_IOREMAP_META_ORDER 1
static void kmsan_iounmap_pages(unsigned long start, unsigned long end)
@@ -213,7 +221,7 @@ int kmsan_ioremap_page_range(unsigned long start, unsigned long end,
mapped = __vmap_pages_range_noflush(
vmalloc_shadow(start + off),
vmalloc_shadow(start + off + PAGE_SIZE), prot, &shadow,
- PAGE_SHIFT);
+ PAGE_SHIFT, gfp_mask);
if (mapped) {
err = mapped;
goto ret;
@@ -223,7 +231,7 @@ int kmsan_ioremap_page_range(unsigned long start, unsigned long end,
mapped = __vmap_pages_range_noflush(
vmalloc_origin(start + off),
vmalloc_origin(start + off + PAGE_SIZE), prot, &origin,
- PAGE_SHIFT);
+ PAGE_SHIFT, gfp_mask);
if (mapped) {
err = mapped;
goto ret;
diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
index 1af03f83d2ea..fb65178426be 100644
--- a/mm/kmsan/shadow.c
+++ b/mm/kmsan/shadow.c
@@ -332,7 +332,7 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
origin_end = vmalloc_meta((void *)end, KMSAN_META_ORIGIN);
kmsan_enter_runtime();
mapped = __vmap_pages_range_noflush(shadow_start, shadow_end, prot,
- s_pages, page_shift);
+ s_pages, page_shift, gfp_mask);
kmsan_leave_runtime();
if (mapped) {
err = mapped;
@@ -340,7 +340,7 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
}
kmsan_enter_runtime();
mapped = __vmap_pages_range_noflush(origin_start, origin_end, prot,
- o_pages, page_shift);
+ o_pages, page_shift, gfp_mask);
kmsan_leave_runtime();
if (mapped) {
/* Undo the shadow mapping set up above. */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 0f2b50ad1a7d..1ba543b039af 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -752,7 +752,8 @@ static int vmap_pages_p4d_range(pgd_t *pgd, unsigned long addr,
* may have contiguous chunks, as hinted by @shift.
*/
static int vmap_pages_range_noflush_walk(unsigned long addr, unsigned long end,
- pgprot_t prot, struct page **pages, unsigned int shift)
+ pgprot_t prot, struct page **pages, unsigned int shift,
+ unsigned long *mapped_pages)
{
unsigned long start = addr;
pgd_t *pgd;
@@ -775,6 +776,7 @@ static int vmap_pages_range_noflush_walk(unsigned long addr, unsigned long end,
if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
arch_sync_kernel_mappings(start, end);
+ *mapped_pages = nr;
return err;
}
@@ -785,18 +787,35 @@ static int vmap_pages_range_noflush_walk(unsigned long addr, unsigned long end,
* The caller is responsible for calling flush_cache_vmap() after this
* function returns successfully and before the addresses are accessed.
*
+ * On failure the PTEs installed by this call are torn down before
+ * returning, so a retry sees a clean range; PTEs that were already
+ * there when the walk failed are left alone. When @gfp_mask cannot
+ * block, the teardown skips cond_resched(), it may run in atomic
+ * context.
+ *
* This is an internal function only. Do not use outside mm/.
*/
int __vmap_pages_range_noflush(unsigned long addr, unsigned long end,
- pgprot_t prot, struct page **pages, unsigned int page_shift)
+ pgprot_t prot, struct page **pages, unsigned int page_shift,
+ gfp_t gfp_mask)
{
+ int err;
+ unsigned long mapped_pages = 0;
+
if (WARN_ON_ONCE(page_shift < PAGE_SHIFT))
return -EINVAL;
if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMALLOC))
page_shift = PAGE_SHIFT;
- return vmap_pages_range_noflush_walk(addr, end, prot, pages, page_shift);
+ err = vmap_pages_range_noflush_walk(addr, end, prot, pages, page_shift,
+ &mapped_pages);
+
+ if (err && mapped_pages)
+ vunmap_range_nokmsan(addr, addr + (mapped_pages * PAGE_SIZE),
+ gfpflags_allow_blocking(gfp_mask));
+
+ return err;
}
int vmap_pages_range_noflush(unsigned long addr, unsigned long end,
@@ -808,7 +827,13 @@ 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);
+
+ ret = __vmap_pages_range_noflush(addr, end, prot, pages, page_shift,
+ gfp_mask);
+ if (ret)
+ kmsan_vunmap_range(addr, end, gfpflags_allow_blocking(gfp_mask));
+
+ return ret;
}
static int __vmap_pages_range(unsigned long addr, unsigned long end,
@@ -818,7 +843,9 @@ static int __vmap_pages_range(unsigned long addr, unsigned long end,
int err;
err = vmap_pages_range_noflush(addr, end, prot, pages, page_shift, gfp_mask);
- flush_cache_vmap(addr, end);
+ if (!err)
+ flush_cache_vmap(addr, end);
+
return err;
}
@@ -3742,13 +3769,15 @@ static int vmap_pages_range_batched(unsigned long addr, unsigned long end,
const unsigned int nr_pages = (end - addr) >> PAGE_SHIFT;
unsigned int prev_shift = 0, batch_idx = 0;
unsigned long batch_start = addr, batch_end = addr;
+ unsigned long nr_mapped;
+ unsigned long mapped_end = addr;
int err;
err = kmsan_vmap_pages_range_noflush(addr, end, prot, pages,
PAGE_SHIFT, GFP_KERNEL);
if (err)
- goto out;
+ return err;
for (unsigned int i = 0; i < nr_pages; ) {
unsigned int shift = PAGE_SHIFT +
@@ -3758,8 +3787,10 @@ static int vmap_pages_range_batched(unsigned long addr, unsigned long end,
prev_shift = shift;
if (shift != prev_shift) {
- err = vmap_pages_range_noflush_walk(batch_start, batch_end,
- prot, pages + batch_idx, prev_shift);
+ err = vmap_pages_range_noflush_walk(batch_start,
+ batch_end, prot, pages + batch_idx,
+ prev_shift, &nr_mapped);
+ mapped_end = batch_start + (nr_mapped * PAGE_SIZE);
if (err)
goto out;
prev_shift = shift;
@@ -3779,12 +3810,20 @@ static int vmap_pages_range_batched(unsigned long addr, unsigned long end,
}
/* Remaining */
- if (batch_start < end)
+ if (batch_start < end) {
err = vmap_pages_range_noflush_walk(batch_start, end, prot,
- pages + batch_idx, prev_shift);
+ pages + batch_idx, prev_shift, &nr_mapped);
+ mapped_end = batch_start + (nr_mapped * PAGE_SIZE);
+ }
out:
- flush_cache_vmap(addr, end);
+ if (err) {
+ if (mapped_end > addr)
+ vunmap_range_nokmsan(addr, mapped_end, true);
+ kmsan_vunmap_range(addr, end, true);
+ } else {
+ flush_cache_vmap(addr, end);
+ }
return err;
}
diff --git a/mm/vmalloc.h b/mm/vmalloc.h
index 4406a1c5b1e9..fe6314ce55e6 100644
--- a/mm/vmalloc.h
+++ b/mm/vmalloc.h
@@ -40,7 +40,8 @@ void clear_vm_uninitialized_flag(struct vm_struct *vm);
int __must_check __vmap_pages_range_noflush(unsigned long addr,
unsigned long end, pgprot_t prot,
- struct page **pages, unsigned int page_shift);
+ struct page **pages, unsigned int page_shift,
+ gfp_t gfp_mask);
void vunmap_range_noflush(unsigned long start, unsigned long end);
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 09/10] powerpc: drop redundant unmaps of failed vmap mappings
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (7 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 08/10] mm/vmalloc: undo what a failed __vmap_pages_range_noflush() installed Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
2026-12-03 9:27 ` [PATCH v6 10/10] mm/percpu: stop unmapping the CPU that failed to map Hao Ge
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge
vmap_page_range() and ioremap_page_range() clear the PTEs they
installed when they fail, so the vunmap_range() in remap_isa_base()
and ioremap_phb() has nothing left to remove.
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
arch/powerpc/kernel/isa-bridge.c | 5 ++---
arch/powerpc/kernel/pci_64.c | 4 +---
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/kernel/isa-bridge.c b/arch/powerpc/kernel/isa-bridge.c
index 5c064485197a..93029d85e6ea 100644
--- a/arch/powerpc/kernel/isa-bridge.c
+++ b/arch/powerpc/kernel/isa-bridge.c
@@ -46,9 +46,8 @@ static void remap_isa_base(phys_addr_t pa, unsigned long size)
WARN_ON_ONCE(size & ~PAGE_MASK);
if (slab_is_available()) {
- if (vmap_page_range(ISA_IO_BASE, ISA_IO_BASE + size, pa,
- pgprot_noncached(PAGE_KERNEL)))
- vunmap_range(ISA_IO_BASE, ISA_IO_BASE + size);
+ vmap_page_range(ISA_IO_BASE, ISA_IO_BASE + size, pa,
+ pgprot_noncached(PAGE_KERNEL));
} else {
early_ioremap_range(ISA_IO_BASE, pa, size,
pgprot_noncached(PAGE_KERNEL));
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index e27342ef128b..f74269636d5e 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -139,10 +139,8 @@ void __iomem *ioremap_phb(phys_addr_t paddr, unsigned long size)
addr = (unsigned long)area->addr;
if (ioremap_page_range(addr, addr + size, paddr,
- pgprot_noncached(PAGE_KERNEL))) {
- vunmap_range(addr, addr + size);
+ pgprot_noncached(PAGE_KERNEL)))
return NULL;
- }
return (void __iomem *)addr;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v6 10/10] mm/percpu: stop unmapping the CPU that failed to map
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
` (8 preceding siblings ...)
2026-12-03 9:27 ` [PATCH v6 09/10] powerpc: drop redundant unmaps of failed vmap mappings Hao Ge
@ 2026-12-03 9:27 ` Hao Ge
9 siblings, 0 replies; 15+ messages in thread
From: Hao Ge @ 2026-12-03 9:27 UTC (permalink / raw)
To: Suren Baghdasaryan, Uladzislau Rezki, Dev Jain, Andrew Morton,
David Hildenbrand (Arm), Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: linuxppc-dev, kasan-dev, linux-mm, Hao Ge
__pcpu_map_pages() clears the PTEs it installed when it fails, so
pcpu_map_pages() only has to tear down the CPUs it mapped before
the failing one.
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/percpu-vm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 509d8901835c..59d3a336a6bd 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -252,10 +252,11 @@ static int pcpu_map_pages(struct pcpu_chunk *chunk, struct page **pages,
return 0;
err:
for_each_possible_cpu(tcpu) {
- __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
- page_end - page_start);
+ /* The failing CPU's partial mapping undoes itself */
if (tcpu == cpu)
break;
+ __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
+ page_end - page_start);
}
pcpu_post_unmap_tlb_flush(chunk, page_start, page_end);
return err;
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context
2026-12-03 9:27 ` [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context Hao Ge
@ 2026-12-03 19:44 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-03 19:44 UTC (permalink / raw)
To: Hao Ge, Suren Baghdasaryan, Uladzislau Rezki, Dev Jain,
Andrew Morton, David Hildenbrand (Arm), Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: kasan-dev, linux-mm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm/vmalloc: missing Cc: stable tag breaks stable backport of
patch 2
--
commit 44c3c42d46b29f727590eb43e59883360aed2f9b
Author: Hao Ge <hao.ge@linux.dev>
> mm/vmalloc: allow the vmap unmap paths to run in atomic context
>
> The vmap failure paths can be reached with GFP_ATOMIC or GFP_NOWAIT
> since commit b186a94227b7 ("kmsan: remove hard-coded GFP_KERNEL
> flags") and commit 8da89ba18ed4 ("mm/vmalloc: handle non-blocking
> GFP in __vmalloc_area_node()"). An undo of a partially installed
> mapping has to run in atomic context there, and the cond_resched()
> in vunmap_pmd_range() cannot schedule.
>
> Give __vunmap_range_noflush() and kmsan_vunmap_range_noflush() a
> can_resched argument and skip the cond_resched() when it is false.
> The existing callers are on sleepable paths and pass true, so nothing
> changes for them.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/sashiko-outbox-178439@kernel.org/
> Signed-off-by: Hao Ge <hao.ge@linux.dev>
[Severity: Low]
Should this commit also carry Cc: stable@vger.kernel.org?
This patch adds the can_resched parameter to __vunmap_range_noflush(),
which commit "mm/kmsan: undo the shadow mapping when the origin mapping
fails" later in this series calls while carrying Cc: stable@vger.kernel.org
without listing this patch as a prerequisite.
Cherry-picking that fix to stable trees without this commit will fail to
compile against the two-argument signature, and adapting it to the
two-argument version would call cond_resched() in atomic context.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203092728.157806-1-hao.ge@linux.dev?part=1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment
2026-12-03 9:27 ` [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment Hao Ge
@ 2026-12-03 19:44 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-03 19:44 UTC (permalink / raw)
To: Hao Ge, Suren Baghdasaryan, Uladzislau Rezki, Dev Jain,
Andrew Morton, David Hildenbrand (Arm), Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: kasan-dev, linux-mm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm/vmalloc: drop Cc: stable tag from comment-only typo fix
--
commit 7d18d3e5f3f5716159820cfe868691463b593fe8
Author: Hao Ge <hao.ge@linux.dev>
> mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment
>
> The comment asks the caller to call flush_cache_vmap() before calling
> this function. flush_cache_vunmap() is meant here, the old comment that
> commit 4ad0ae8c64ac ("mm/vmalloc: remove unmap_kernel_range") replaced
> said flush_cache_vunmap(), and Documentation/core-api/cachetlb.rst and
> vunmap_range() both use flush_cache_vunmap() before the page tables are
> torn down.
>
> Fixes: 4ad0ae8c64ac ("mm/vmalloc: remove unmap_kernel_range")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hao Ge <hao.ge@linux.dev>
[Severity: Low]
Should the Cc: stable@vger.kernel.org tag be dropped? This commit only
fixes a typo in a comment above __vunmap_range_noflush() with no
functional change, and Documentation/process/stable-kernel-rules.rst
excludes trivial spelling and comment fixes from stable trees.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203092728.157806-1-hao.ge@linux.dev?part=3
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range()
2026-12-03 9:27 ` [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range() Hao Ge
@ 2026-12-03 19:44 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-03 19:44 UTC (permalink / raw)
To: Hao Ge, Suren Baghdasaryan, Uladzislau Rezki, Dev Jain,
Andrew Morton, David Hildenbrand (Arm), Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: kasan-dev, linux-mm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: vmap_page_range() alignment check breaks omap_cf_probe()
--
commit 875f66737f08161fc6c689e08e79f67012524a9b
Author: Hao Ge <hao.ge@linux.dev>
mm/vmalloc: reject an unaligned range in vmap_page_range()
This commit moves the PAGE_SIZE alignment check from vmap_pte_range() to
vmap_page_range(), checking both addr and end before installing any page
tables.
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 6e25c2db8a9c8..5453df175a571 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
[ ... ]
> @@ -369,6 +366,11 @@ int vmap_page_range(unsigned long addr, unsigned long end,
> {
> int err;
>
> + if (WARN_ON_ONCE(!PAGE_ALIGNED(addr)))
> + return -EINVAL;
> + if (WARN_ON_ONCE(!PAGE_ALIGNED(end)))
> + return -EINVAL;
> +
> err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
> ioremap_max_page_shift);
> flush_cache_vmap(addr, end);
[Severity: Medium]
Does this alignment check break omap_cf_probe() on ARM?
In drivers/pcmcia/omap_cf.c, omap_cf_probe() declares an I/O resource with
DEFINE_RES_IO(SZ_64, SZ_4K) and passes it to pci_remap_iospace(). On ARM,
arch/arm/mm/ioremap.c:pci_remap_iospace() adds res->start to PCI_IOBASE and
forwards the unaligned vaddr and end directly to vmap_page_range().
Previously vmap_pte_range() only checked PAGE_ALIGNED(end - addr), which
passed because the size is SZ_4K. With the new checks on addr and end,
vmap_page_range() warns and returns -EINVAL, causing omap_cf_probe() to fail
with -ENOMEM and breaking CompactFlash initialization on OMAP16xx boards.
drivers/pcmcia/omap_cf.c should be updated to use a PAGE_SIZE-aligned I/O
resource start before or alongside enforcing this check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203092728.157806-1-hao.ge@linux.dev?part=5
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed
2026-12-03 9:27 ` [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed Hao Ge
@ 2026-12-03 19:44 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-12-03 19:44 UTC (permalink / raw)
To: Hao Ge, Suren Baghdasaryan, Uladzislau Rezki, Dev Jain,
Andrew Morton, David Hildenbrand (Arm), Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter
Cc: kasan-dev, linux-mm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: vunmap_range_nokmsan() sends SMP IPIs despite
atomic-context contract
--
commit a6c5a3931affbc3848f78bee8cb75dc56e46f428
Author: Hao Ge <hao.ge@linux.dev>
mm/vmalloc: undo what a failed vmap_page_range() installed
This commit tracks how far vmap_range_noflush() walked and introduces
vunmap_range_nokmsan() so vmap_page_range() can unmap partially
installed PTEs on walk or KMSAN failures.
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 8540f20eb9b6b..7ac74a866408b 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
[ ... ]
> @@ -552,6 +579,29 @@ void vunmap_range_noflush(unsigned long start, unsigned long end)
> __vunmap_range_noflush(start, end, true);
> }
>
> +/**
> + * vunmap_range_nokmsan - unmap kernel virtual addresses without the
> + * KMSAN part
> + * @addr: start of the VM area to unmap
> + * @end: end of the VM area to unmap (non-inclusive)
> + * @can_resched: whether the unmap walk may call cond_resched(); pass
> + * false from atomic context.
> + *
> + * Clears any present PTEs in the virtual address range, flushes TLBs and
> + * caches, but leaves the KMSAN metadata to the caller. The undo paths
> + * use this for a range that is not going back to vmalloc, which would
> + * flush the TLB lazily, so nobody else flushes it.
> + *
> + * This is an internal function only. Do not use outside mm/.
> + */
> +void vunmap_range_nokmsan(unsigned long addr, unsigned long end,
> + bool can_resched)
> +{
> + flush_cache_vunmap(addr, end);
> + __vunmap_range_noflush(addr, end, can_resched);
> + flush_tlb_kernel_range(addr, end);
> +}
[Severity: Medium]
Is vunmap_range_nokmsan() actually safe to call from atomic context when
can_resched is false?
flush_tlb_kernel_range() (and flush_cache_vunmap() on PA-RISC) sends
synchronous IPIs via smp_call_function_many_cond() when there is no
hardware broadcast TLB invalidation. That asserts IRQs are enabled and
in_task(), and can deadlock if two CPUs wait with IRQs disabled.
This commit only passes can_resched = true, but commit "mm/vmalloc: undo
what a failed __vmap_pages_range_noflush() installed" calls
vunmap_range_nokmsan(..., false) on GFP_ATOMIC vmalloc failures.
__get_vm_area_node() only rejects NMI, hardirq and softirq contexts, so
an IRQ-disabled task (e.g. a kprobe BPF program in
rhtab_map_update_elem() -> rhashtable_insert_rehash() falling back to
vmalloc) can reach this on a mid-walk page-table allocation failure.
Either defer cleanup for non-blocking contexts instead of issuing
synchronous IPI flushes, or reject IRQ-disabled contexts and document
that IRQs must be enabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203092728.157806-1-hao.ge@linux.dev?part=7
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-12-03 19:45 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 9:27 [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Hao Ge
2026-12-03 9:27 ` [PATCH v6 01/10] mm/vmalloc: allow the vmap unmap paths to run in atomic context Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 02/10] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
2026-12-03 9:27 ` [PATCH v6 03/10] mm/vmalloc: fix a typo in the __vunmap_range_noflush() comment Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 04/10] mm/kmsan: fix the metadata cache flush ordering Hao Ge
2026-12-03 9:27 ` [PATCH v6 05/10] mm/vmalloc: reject an unaligned range in vmap_page_range() Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 06/10] mm/vmalloc: reject an unaligned range in __vunmap_range_noflush() Hao Ge
2026-12-03 9:27 ` [PATCH v6 07/10] mm/vmalloc: undo what a failed vmap_page_range() installed Hao Ge
2026-12-03 19:44 ` sashiko-bot
2026-12-03 9:27 ` [PATCH v6 08/10] mm/vmalloc: undo what a failed __vmap_pages_range_noflush() installed Hao Ge
2026-12-03 9:27 ` [PATCH v6 09/10] powerpc: drop redundant unmaps of failed vmap mappings Hao Ge
2026-12-03 9:27 ` [PATCH v6 10/10] mm/percpu: stop unmapping the CPU that failed to map Hao Ge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox