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=1796367849; b=W/eAuy9wVPlupFodD8GgMUI2TFROnSmpqbmDWgiWSVbZ7oWcic26jgahQjCEOO+hhk4j l9FJTHG4+ImOC8xmOpeObvj/8JBSILaK4ZQcf6QTnmSo9REq76CuJu0AHsjg0QnRoSG6P X9MOFJ5WSsOosbODymFtwwLLgFcWkedkchRdjTiuIS9BA1pRoL1Y3zO9fUm6l7aU2snVU XroILgRWp3SMSKqtOfkSBEY5BAvAQjJ5KCS8AqfcHgI1Wj4+ioKp3ff+hWvY0/hlchJr7 jiWp+0kSUyFm5TpRnAfpmHhr0ko2+mkQHtc3n33Nw2ILMIdyyUIqg2uTxOufYg8oAyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367849; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=Ixjpgy9m33FkemPLlNdMkwwRNP2PcOfUIVW12Sns4WA=; b=m2eLIDkDUoi8n2Uq4FrNSJxmimd6aEIqn1wvk5o+e3b0/WyhWd2Li/RpF6Gi5r1FagzL bUaUAvfDbDRZhUt3I6lMg9Lav8Dj8EQLSABbO4pRVMspBRAiStlTn+AfUkpRvxeuBY3k7 v8gKJfkrSdRzaezyvV9er4BpSE7uXt9v1DsFbtjOmND6nQ2MYN3c7r5l6phPuqPeVyNGi FB6/9ca66/P80vNrHPVBaqa2K58yd40nML28hCKlZZJ4mv8K2EE3GTp6glTrE1Ps0YM4N IwspOW1fbfI82TOtMQ8QBSY6W/JU7g2hmR9sbE3sQEfAec2acf5Oi8IEoJda0gLWEEQ== 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=FaWBAsfZ; 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 2E1C5606A337 for ; Fri, 4 Dec 2026 07:04:08 +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=FaWBAsfZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4E361F000CE; Fri, 4 Dec 2026 07:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796367848; bh=Ixjpgy9m33FkemPLlNdMkwwRNP2PcOfUIVW12Sns4WA=; h=Date:To:From:In-Reply-To:References:Subject; b=FaWBAsfZy6I9j6rEbACeZeJPbcE7LuZA3UGzmMLuCLkYjx5r1W1y1kJ9zWqlL4DhH oGV6YEhgcTBUhY8LvUbpGmdiFbq/NEOS1jNMFi22LwMPG9Y0keJgjcmOuUy8UGe3Q8 6ryZ3zAr3Do3FvhNTtlTq5tRUX4jf/nusVUohYGo= Date: Thu, 03 Dec 2026 23:04:08 -0800 To: mm-commits@vger.kernel.org,surenb@google.com,peterx@redhat.com, david@kernel.org,rppt@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.patch added to mm-new branch Message-Id: <20261204070408.A4E361F000CE@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: free the test context when uffd_test_ctx_init() fails has been added to the -mm mm-new branch. Its filename is selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails.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.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: "Mike Rapoport (Microsoft)" Subject: selftests/mm: free the test context when uffd_test_ctx_init() fails Date: Thu, 03 Dec 2026 19:15:24 +0200 uffd_test_ctx_init() returns on errors without unmapping the test areas it has already allocated, and userfaultfd_open() leaves the userfaultfd open when UFFDIO_API fails. uffd-unit-tests then skips the test and goes on to the next one in the same process, so everything allocated for the failed test stays around until the end of the run. For hugetlb, the leaked areas keep their huge pages reserved, and the following hugetlb tests can fail to allocate their areas and get skipped with a misleading "memory allocation failed". Unmap the areas allocated so far when uffd_test_ctx_init() fails and close the userfaultfd when userfaultfd_open() fails. Link: https://patch.msgid.link/20261203-fixes-uffd-sashiko-v2-4-308ce557a7b6@kernel.org Fixes: 1c8d39fa7b63 ("selftests/mm: call uffd_test_ctx_clear at the end of the test") Signed-off-by: Mike Rapoport (Microsoft) Signed-off-by: Andrew Morton Reported-by: Sashiko Closes: https://sashiko.dev/bug/linux-3a91f55a-ede8-4950-bbda-cd0b03f9076a Cc: David Hildenbrand Cc: Peter Xu Cc: Suren Baghdasaryan tools/testing/selftests/mm/uffd-common.c | 27 +++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) --- a/tools/testing/selftests/mm/uffd-common.c~selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails +++ a/tools/testing/selftests/mm/uffd-common.c @@ -269,12 +269,17 @@ int userfaultfd_open(uffd_global_test_op uffdio_api.features = *features; if (ioctl(gopts->uffd, UFFDIO_API, &uffdio_api)) /* Probably lack of CAP_PTRACE? */ - return -1; + goto err_close; if (uffdio_api.api != UFFD_API) err("UFFDIO_API error: %" PRIu64, (uint64_t)uffdio_api.api); *features = uffdio_api.features; return 0; + +err_close: + close(gopts->uffd); + gopts->uffd = -1; + return -1; } static inline void munmap_area(uffd_global_test_opts_t *gopts, void **area) @@ -333,24 +338,30 @@ int uffd_test_ctx_init(uffd_global_test_ } ret = uffd_test_ops->allocate_area(gopts, (void **) &gopts->area_src, true); - ret |= uffd_test_ops->allocate_area(gopts, (void **) &gopts->area_dst, false); if (ret) { if (errmsg) *errmsg = "memory allocation failed"; return ret; } + ret = uffd_test_ops->allocate_area(gopts, (void **) &gopts->area_dst, false); + if (ret) { + if (errmsg) + *errmsg = "memory allocation failed"; + goto err_unmap_src; + } + if (uffd_test_case_ops && uffd_test_case_ops->post_alloc) { ret = uffd_test_case_ops->post_alloc(gopts, errmsg); if (ret) - return ret; + goto err_unmap_dst; } ret = userfaultfd_open(gopts, &features); if (ret) { if (errmsg) *errmsg = "possible lack of privilege"; - return ret; + goto err_unmap_dst; } gopts->count_verify = malloc(gopts->nr_pages * sizeof(unsigned long long)); @@ -399,6 +410,14 @@ int uffd_test_ctx_init(uffd_global_test_ err("pipe"); return 0; + +err_unmap_dst: + munmap_area(gopts, (void **)&gopts->area_dst); + munmap_area(gopts, (void **)&gopts->area_dst_alias); +err_unmap_src: + munmap_area(gopts, (void **)&gopts->area_src); + munmap_area(gopts, (void **)&gopts->area_src_alias); + return ret; } void wp_range(int ufd, __u64 start, __u64 len, bool wp) _ Patches currently in -mm which might be from rppt@kernel.org are mm-cma-simplify-cma_declare_contiguous_multi.patch mm-fake-numa-fix-leak-of-the-distance-table-copy-on-errors.patch mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch mm-cma-fix-handling-of-free-ranges-that-cross-4g-for-multi-range-areas.patch userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch userfaultfd-mark-zero-pages-moved-by-uffdio_move-soft-dirty.patch userfaultfd-mark-thps-moved-by-uffdio_move-soft-dirty.patch selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails.patch hibernation-make-swsusp_page-helpers-static.patch hibernation-ensure-secretmem-pages-dont-reach-a-snapshot.patch hibernate-handle-potential-errors-in-hibernate_mapunmap_page.patch hibernation-kfence-explicitly-map-unmap-kfence-pages.patch hibernation-make-hibernation-unavailable-when-debug_pagealloc-is-on.patch