Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [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; 11+ 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] 11+ messages in thread

end of thread, other threads:[~2026-12-03  9:29 UTC | newest]

Thread overview: 11+ 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  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  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  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  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