All of lore.kernel.org
 help / color / mirror / Atom feed
* + selftests-mm-test-mlock-and-munlock-range-normalisation-fix.patch added to mm-unstable branch
@ 2026-12-05 22:47 Andrew Morton
  0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-12-05 22:47 UTC (permalink / raw)
  To: mm-commits, azpijr, akpm


The patch titled
     Subject: selftests-mm-test-mlock-and-munlock-range-normalisation-fix
has been added to the -mm mm-unstable branch.  Its filename is
     selftests-mm-test-mlock-and-munlock-range-normalisation-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-test-mlock-and-munlock-range-normalisation-fix.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

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-test-mlock-and-munlock-range-normalisation-fix
Date: Wed, 25 Nov 2026 13:05:16 -0800

ULONG_MAX has the test binary's width. A 32-bit
binary on a 64-bit kernel passes 0xffffffff, which does not overflow
the kernel's arithmetic. Requiring EINVAL can therefore fail on a
correct kernel.

Require the calls to fail on a 32-bit binary, while retaining the EINVAL
check on a 64-bit binary.  The mlock tests continue to check that the
failed calls did not change VmLck.

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Jose A. Perez de Azpillaga <azpijr@gmail.com>

 tools/testing/selftests/mm/mlock2-tests.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

--- a/tools/testing/selftests/mm/mlock2-tests.c~selftests-mm-test-mlock-and-munlock-range-normalisation-fix
+++ a/tools/testing/selftests/mm/mlock2-tests.c
@@ -286,6 +286,13 @@ static void test_munlock_zero_length(voi
 	munmap(map, 2 * page_size);
 }
 
+/* A 32-bit request may not wrap in a 64-bit kernel. */
+static bool overflow_rejected(int ret)
+{
+	return ret == -1 &&
+		(sizeof(unsigned long) == 4 || errno == EINVAL);
+}
+
 static void test_mlock_length_wrap(void)
 {
 	unsigned long page_size = getpagesize();
@@ -301,7 +308,7 @@ static void test_mlock_length_wrap(void)
 	vmlck_before = get_vmlck();
 	errno = 0;
 	ret = mlock(map, ULONG_MAX);
-	ksft_test_result(ret == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(ret),
 			 "%s: mlock() with a wrapping length is rejected\n",
 			 __func__);
 
@@ -313,7 +320,7 @@ static void test_mlock_length_wrap(void)
 	vmlck_before = get_vmlck();
 	errno = 0;
 	ret = mlock(map + 5, ULONG_MAX);
-	ksft_test_result(ret == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(ret),
 			 "%s: unaligned mlock() with a wrapping length is rejected\n",
 			 __func__);
 
@@ -345,7 +352,7 @@ static void test_mlock_addr_overflow(voi
 	vmlck_before = get_vmlck();
 	errno = 0;
 	ret = mlock(map, len);
-	ksft_test_result(ret == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(ret),
 			 "%s: mlock() with an overflowing addr + len is rejected\n",
 			 __func__);
 
@@ -369,18 +376,18 @@ static void test_munlock_range_overflow(
 		ksft_exit_fail_msg("mmap error: %s\n", strerror(errno));
 
 	errno = 0;
-	ksft_test_result(munlock(map, ULONG_MAX) == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(munlock(map, ULONG_MAX)),
 			 "%s: munlock() with a wrapping length is rejected\n",
 			 __func__);
 
 	errno = 0;
-	ksft_test_result(munlock(map + 5, ULONG_MAX) == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(munlock(map + 5, ULONG_MAX)),
 			 "%s: unaligned munlock() with a wrapping length is rejected\n",
 			 __func__);
 
 	len = (size_t)(0UL - (unsigned long)map);
 	errno = 0;
-	ksft_test_result(munlock(map, len) == -1 && errno == EINVAL,
+	ksft_test_result(overflow_rejected(munlock(map, len)),
 			 "%s: munlock() with an overflowing addr + len is rejected\n",
 			 __func__);
 
_

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
selftests-mm-test-mlock-and-munlock-range-normalisation-fix.patch
selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.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
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 22:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 22:47 + selftests-mm-test-mlock-and-munlock-range-normalisation-fix.patch added to mm-unstable branch Andrew Morton

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.