__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/[email protected]/ v5 link: https://lore.kernel.org/all/[email protected]/ v4 link: https://lore.kernel.org/all/[email protected]/ v3 link: https://lore.kernel.org/all/[email protected]/ v2 link: https://lore.kernel.org/all/[email protected]/ v1 link: https://lore.kernel.org/all/[email protected]/ 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
