On Fri, Nov 20, 2026 at 9:14 PM Suren Baghdasaryan <[email protected]> wrote: > > On Mon, Nov 16, 2026 at 7:13 AM Hao Ge <[email protected]> wrote: > > > > 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, the same way > > kmsan_ioremap_page_range() cleans up after a partial failure. > > __vunmap_range_noflush() only clears the PTEs; nothing has touched > > the shadow mapping, so no TLB flush is needed.
After a second thought, kmsan_ioremap_page_range() does not skip TLB flushing. __vunmap_range_noflush() comment at https://elixir.bootlin.com/linux/v7.4-rc1/source/mm/vmalloc.c#L497 says: The caller is responsible for calling flush_cache_vmap() before calling this function, and flush_tlb_kernel_range after it has returned successfully ...". There are no mentions of guarantees that mapped PTEs require explicit access to be cached. Please double-check if this is safe. > > > > Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in > > kmsan_vmap_pages_range_noflush()") > > Cc: [email protected] > > Suggested-by: Suren Baghdasaryan <[email protected]> > > Signed-off-by: Hao Ge <[email protected]> > > Reviewed-by: Suren Baghdasaryan <[email protected]> > > > --- > > mm/kmsan/shadow.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c > > index 0c88d89bf0d6..212449db34a1 100644 > > --- a/mm/kmsan/shadow.c > > +++ b/mm/kmsan/shadow.c > > @@ -258,6 +258,11 @@ 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. */ > > + kmsan_enter_runtime(); > > + __vunmap_range_noflush(shadow_start, shadow_end, > > + gfpflags_allow_blocking(gfp_mask)); > > + kmsan_leave_runtime(); > > err = mapped; > > goto ret; > > } > > -- > > 2.25.1 > >
