From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796490599; b=R95Joc7XFpxg7/BxW+D1xTeTv60DtMPFeOMy5HXjkYVXlzdRvu+Tg8NN0a/5GFkl7FxR FLVinlvF1Odh8I1Mwnl+vQuAsqTS8cu8fUvOG03NsiKc3gcD7yt3R0wbXGI2b36y3gFhj CzVYKyCnnAJkhkVEaTdIz9rWZNVh53RKC7+DvRzEdNM0Ql+QczjONOFtFzTLAtpTP2oxb S6ksW8KZAgVTpI5OEIQVJM82MqyFFNXkW3aTouppm3/XpUyF5RlImdbrAC/vcWBvHAU3u L03USPlIz3fcXKCkYbn7YI8oCIIWHzg1UiqfNcVAfTRDkMgiOnU0FvteNsXbDAi7fpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796490599; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=19lwltfQ5jxNtHv5ekloHeQStUgkRjincNxxDm4deto=; b=ZrMAFaPSl2FeTOdVaBjVmNMKv3YVrVq5+wcqN3iTYQI9DFxpG1ETqYHUf0o+IMcVIQT8 D59HZDM4uwif6NybowgYCrGSfA/k9tM9FALVJqSQQrS/uBmEM9CnW8oRXbA6qPbLX2eCr RhP28fGo6+Mmgb+8EN2hxr2rbuixF7OgfWCF60Qr90d6w0n75oQws9epbeAMA4vZqZknI GVy5kkQUoymP1JuOAyO5zRVB3yifgGBWQJXBG2hE25tQgkXGybVUHzBVhmAJZ71/qHHG2 0pkv8Qg73msZZXFYL8IdrxDqeM2EPpADa47ce3Wv1/5t5KqLlzRM9iDrBfJ0CcesmdA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=TyuCw97x; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F41D0606A31F for ; Sat, 5 Dec 2026 17:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=TyuCw97x Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE5CD1F0092B; Sat, 5 Dec 2026 17:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796490598; bh=19lwltfQ5jxNtHv5ekloHeQStUgkRjincNxxDm4deto=; h=Date:To:From:In-Reply-To:References:Subject; b=TyuCw97xv/N25/VGR02LpwW7yoJmeAqWR19oCXIf6JbX6f7+aZd6oy/FTL+KVLqov L2TqhU6tLRT7ruRevMzsMS1vxFnUG1xjCk4x5AvbEZ8XIGv1Ly/4FK/i1IySWoNvVR s8WP751kPXHhASOXBQF6L4C+H8NlbPTWwpDF6gsw= Date: Sat, 05 Dec 2026 09:09:58 -0800 To: mm-commits@vger.kernel.org,surenb@google.com,rppt@kernel.org, peterx@redhat.com,david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-fixes-uffd-sashiko-v2-4-308ce557a7b6@kernel.org> References: <20261203-fixes-uffd-sashiko-v2-4-308ce557a7b6@kernel.org> Subject: + selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch added to mm-new branch Message-Id: <20261205170958.BE5CD1F0092B@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: selftests/mm: release partial hugetlb area on allocation failure has been added to the -mm mm-new branch. Its filename is selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Andrew Morton Subject: selftests/mm: release partial hugetlb area on allocation failure Date: Sat, 05 Dec 2026 08:53:51 -0800 hugetlb_allocate_area() creates a memfd before mapping the test area. If the first mmap() fails, the memfd stays open. If mapping a shared alias fails, the first area also remains mapped. An error allocating the source area returns directly from uffd_test_ctx_init(), bypassing the cleanup added by the preceding patch. A skipped test can therefore leave huge pages reserved for later tests. Close the memfd on both failures, unmap the first area when its alias fails, and enter err_unmap_src for source allocation errors. Preserve the original errno across cleanup. Fault injection of the alias mmap() left one live mapping before this change and none afterward. The first mmap() failure and subsequent normal cases were also checked. The userfaultfd selftests passed 122/122 with CONFIG_USERFAULTFD=y, CONFIG_HUGETLB_PAGE=y and CONFIG_HUGETLBFS=y. CONFIG_CPA_DEBUG was disabled in the test kernel. Link: https://lore.kernel.org/r/20261203-fixes-uffd-sashiko-v2-4-308ce557a7b6@kernel.org Signed-off-by: Andrew Morton Cc: Mike Rapoport (Microsoft) Cc: David Hildenbrand Cc: Peter Xu Cc: Suren Baghdasaryan tools/testing/selftests/mm/uffd-common.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/tools/testing/selftests/mm/uffd-common.c~selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix +++ a/tools/testing/selftests/mm/uffd-common.c @@ -90,21 +90,29 @@ static int hugetlb_allocate_area(uffd_gl void *area_alias = NULL; char **alloc_area_alias; int mem_fd = uffd_mem_fd_create(size * 2, true); + int ret; *alloc_area = mmap(NULL, size, PROT_READ | PROT_WRITE, (gopts->map_shared ? MAP_SHARED : MAP_PRIVATE) | (is_src ? 0 : MAP_NORESERVE), mem_fd, offset); if (*alloc_area == MAP_FAILED) { + ret = -errno; *alloc_area = NULL; - return -errno; + close(mem_fd); + return ret; } if (gopts->map_shared) { area_alias = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); - if (area_alias == MAP_FAILED) - return -errno; + if (area_alias == MAP_FAILED) { + ret = -errno; + munmap(*alloc_area, size); + *alloc_area = NULL; + close(mem_fd); + return ret; + } } if (is_src) { @@ -341,7 +349,7 @@ int uffd_test_ctx_init(uffd_global_test_ if (ret) { if (errmsg) *errmsg = "memory allocation failed"; - return ret; + goto err_unmap_src; } ret = uffd_test_ops->allocate_area(gopts, (void **) &gopts->area_dst, false); _ Patches currently in -mm which might be from akpm@linux-foundation.org are kselftest-mm-rename-read_pmd_pagesize-to-pmd_psize-fix.patch selftests-mm-check-madv_cold-and-madv_pageout-on-partly-advised-thps-fix.patch selftests-mm-retain-move-pmd-coverage-and-verify-huge-pmds.patch lib-test_xarray-check-unused-spare-node-after-range-creation.patch selftests-mm-check-that-fsync-reports-hard-poisoned-dirty-page-cache.patch selftests-mm-memory-failure-truncate-poisoned-fuse-page-cache-before-teardown.patch selftests-mm-memory-failure-skip-poisoned-dirty-page-cache-on-nilfs2.patch selftest-mm-memory-failure-keep-page-cache-files-linked-until-cleanup.patch selftest-mm-memory-failure-keep-page-cache-files-linked-until-cleanup-fix.patch selftests-mm-memory-failure-skip-hard-dirty-page-cache-test-on-cephfs.patch selftests-mm-memory-failure-close-dirty-page-cache-files-before-unlinking-them.patch selftests-mm-memory-failure-extend-page-cache-test-files-with-pwrite.patch selftests-mm-memory-failure-write-the-whole-page-cache-test-file-for-omfs.patch selftests-mm-memory-failure-accept-eio-from-close-after-poisoning-dirty-data.patch alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix-fix.patch alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix.patch mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target.patch mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target-fix.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault-fix.patch hugetlbfs-dont-overflow-the-end-of-the-unmap-range-on-32-bit-fix.patch selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch ipc-msg-clamp-negative-msg_info-usage-counts.patch squashfs-fix-leaked-page-locks-when-page-actor-allocation-fails-fix.patch ocfs2-skip-network-flush-when-no-domain-handlers-are-registered.patch selftests-ptrace-check-that-ptrace_set_syscall_info-rejects-invalid-error-values-fix.patch lib-atomic64-separate-hashed-locks-by-smp-cache-line.patch nvdimm-btt-separate-map-locks-by-smp-cache-line.patch percpu_ref-replace-the-global-switch-lock-with-hashed-locks-fix.patch afs-do-not-put-error-pointer-after-address-lookup-failure.patch drivers-media-v4l2-core-v4l2-vp9c-reduce-inlining.patch