All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,surenb@google.com,rppt@kernel.org,
	peterx@redhat.com,david@kernel.org,akpm@linux-foundation.org
Subject: + selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch added to mm-new branch
Date: Sat, 05 Dec 2026 09:09:58 -0800	[thread overview]
Message-ID: <20261205170958.BE5CD1F0092B@smtp.kernel.org> (raw)
In-Reply-To: <20261203-fixes-uffd-sashiko-v2-4-308ce557a7b6@kernel.org>


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 <akpm@linux-foundation.org>
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 <akpm@linux-foundation.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Suren Baghdasaryan <surenb@google.com>

 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


      parent reply	other threads:[~2026-12-05 17:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:15 [PATCH v2 0/4] userfaultfd: fixes for sashiko reports Mike Rapoport (Microsoft)
2026-12-03 17:15 ` [PATCH v2 1/4] userfaultfd: write-lock the VMA before clearing its uffd state Mike Rapoport (Microsoft)
2026-12-04  7:04   ` + userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch added to mm-new branch Andrew Morton
2026-12-04  9:27   ` [PATCH v2 1/4] userfaultfd: write-lock the VMA before clearing its uffd state Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Mike Rapoport (Microsoft)
2026-12-04  7:04   ` + userfaultfd-mark-zero-pages-moved-by-uffdio_move-soft-dirty.patch added to mm-new branch Andrew Morton
2026-12-04  9:31   ` [PATCH v2 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 3/4] userfaultfd: mark THPs " Mike Rapoport (Microsoft)
2026-12-04  7:04   ` + userfaultfd-mark-thps-moved-by-uffdio_move-soft-dirty.patch added to mm-new branch Andrew Morton
2026-12-04  9:32   ` [PATCH v2 3/4] userfaultfd: mark THPs moved by UFFDIO_MOVE soft-dirty Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Mike Rapoport (Microsoft)
2026-12-04  7:04   ` + selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails.patch added to mm-new branch Andrew Morton
2026-12-04  9:39   ` [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Jose A. Perez de Azpillaga
2026-12-05 17:09   ` Andrew Morton
2026-12-05 17:09   ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205170958.BE5CD1F0092B@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.