From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C411606A330 for ; Thu, 3 Dec 2026 09:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=B7vbKzHF Received: by kanga.kvack.org (Postfix) id 320576B05B4; Thu, 3 Dec 2026 04:27:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F76C6B05B7; Thu, 3 Dec 2026 04:27:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C0C16B05B8; Thu, 3 Dec 2026 04:27:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EF68B6B05B4 for ; Thu, 3 Dec 2026 04:27:40 -0500 (EST) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5FF41120615 for ; Thu, 3 Dec 2026 09:27:40 +0000 (UTC) X-FDA: 85502144280.03.3B9B517 Received: from mta1.migadu.com (out-15.mta1.migadu.com [95.215.58.15]) by imf26.hostedemail.com (Postfix) with ESMTP id 5B5E1140003 for ; Thu, 3 Dec 2026 09:27:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B7vbKzHF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.15 as permitted sender) smtp.mailfrom=hao.ge@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796290058; b=ObCdF0q108NBDIFDLPWoqOv42YcJnkOucsJpZ3KqIx7YnnO0TuZ0BhuosrvUKI6ZhwBtrI wsAyRFQVfgGBk16RHA44xSVR1NIYaRVsaKGajEGvk14CZ27lJJqOVMWl7hI438Dovxhjm7 bZK4ZjE0ecbyWu7qETcV0x5YEc7IveY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796290058; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=b13dCzCbPm/anFps8U8JDMYDEqnWS1mRjR5iaXIwo2U=; b=QVzN9qp6gf51wzxiASy7nmLSjhF7kSaDEqzRpFtYVOCMiYal3BTETDdXx3w7KcNbBXJOWx faXDC3068EmePIJ4usf7aWKyD+iEWvae2rLPZgYfRtAQ5I2UIXpb9W3Emhd3bf4Zo4SK+L PC+kldMsEstK0/ndSLNJeYdHUTeYOKU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B7vbKzHF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf26.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.15 as permitted sender) smtp.mailfrom=hao.ge@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=OP3j1J4HItw8PASxZJNgQjIr8O3c+2wsOHp9IncgX1k=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796290057; v=1; x=1796894857; b=B7vbKzHF2uUD8yrLoM15rLV6b/CudGtCeHLLjbjx00XUpJBgeXL1Gex0Y4DrrVGjahcou9mI JiQwy8Dx9o8DjARTz7gtaWfqaGUAgfZHl6OzAQIYGRzg5qOLfPy5SJXEHbcdkdp4g6JRXdIJ0iu CZSKqO3ORcxP/vwYCrJga8+4= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id d737a4b5a0808090; Thu, 03 Dec 2026 09:27:36 +0000 X-Mizu-Trace-ID: d737a4b5a0808090 X-Migadu-Flow: FLOW_OUT From: Hao Ge 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@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Hao Ge Subject: [PATCH v6 00/10] mm/vmalloc: fix up vmap error handling Date: Thu, 3 Dec 2026 17:27:18 +0800 Message-Id: <20261203092728.157806-1-hao.ge@linux.dev> X-Mailer: git-send-email 2.25.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5B5E1140003 X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: 9obt1refhtsiwr3xnoxbdkjadhsnchqf X-Rspam-User: X-HE-Tag: 1796290058-825760 X-HE-Meta: U2FsdGVkX1/CYSbueorqa7XQm5LU2qAF7HcpKlEo02kj1LUy91d2Ia6hrJAvXD/gevtQbvqoPQahkIIxNXHR4iyCkxAi1Rp1XN2+M16TOvXFAvcoh1XzLzK43bt5AXBs5vQ/0VGZLJL7Cy9vYdtveB3JtLM1J3cu0cWcxuplseS/DME1lH44k4C7BI4tU6AEKx4odd8m0OupatnhUk+PLy5941Jz6YRBDssIzthzt61CkDF3rbNmxVmvZqnfmmWgfqHDgHCWhc215nit9N1KJPpf6DYovAwIw9haMiTszSA5ffSFKii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SXLHofb5Bro+MyPiKZMwLtty8Kx73f9EPzP2L+RdR8kmYcvXh0zy3X1BfXUb/6UuHHLmPBbk2ILTt0uz1P+EzNTOAhLq1VkYk2HNtAhlHvpnrgxny6+OsH+SzCNsUZLiKoHuNYt8k3tgYzM15HTaNIuhqr Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 __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