Re: [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked
From: anthony . yznaga
Date: Thu Apr 02 2026 - 19:22:24 EST
On 4/2/26 12:28 AM, David Hildenbrand (Arm) wrote:
+Why do we need the prior mlockall()? If that is really required, the
+/*
+ * Droppable memory should not be lockable.
+ */
+static void test_mlock_droppable(void)
+{
+ char *map;
+ unsigned long page_size = getpagesize();
+
+ /*
+ * Ensure MCL_FUTURE is not set.
+ */
+ if (mlockall(MCL_CURRENT))
+ ksft_exit_fail_msg("mlockall(MCL_CURRENT): %s\n", strerror(errno));
comment should be clearer why the munlockall() is insufficient.
The mlockall() is not needed. Will remove.
Also, why can't we fail only the test?
The tests can be failed without the exit. I'll update them.
Thanks,
Anthony
+ if (munlockall())Why can't we fail only the test?
+ ksft_exit_fail_msg("munlockall() %s\n", strerror(errno));
+same.
+ map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+ if (map == MAP_FAILED) {
+ if (errno == EOPNOTSUPP) {
+ ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__);
+ return;
+ }
+ ksft_exit_fail_msg("mmap error: %s\n", strerror(errno));
+ }Not required when exiting either way?
+
+ if (mlock2_(map, 2 * page_size, 0)) {
+ munmap(map, 2 * page_size);
+ ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno));Similar comments as for the other path regarding ksft_exit_fail_msg() etc.
+ }
+
+ ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n",
+ __func__);
+
+ munmap(map, 2 * page_size);
+}
+
+static void test_mlockall_future_droppable(void)
+{
+ char *map;
+ unsigned long page_size = getpagesize();
+
+ if (mlockall(MCL_CURRENT | MCL_FUTURE))
+ ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_FUTURE): %s\n", strerror(errno));
+
+ map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
+ if (map == MAP_FAILED) {
+ if (errno == EOPNOTSUPP) {
+ ksft_test_result_skip("%s: MAP_DROPPABLE not supported\n", __func__);
+ return;
+ }
+ ksft_exit_fail_msg("mmap error: %s\n", strerror(errno));
+ }
+
+ ksft_test_result(!unlock_lock_check(map, false), "%s: droppable memory not locked\n",
+ __func__);
+
+ if (munlockall()) {
+ munmap(map, 2 * page_size);
+ ksft_exit_fail_msg("munlockall() %s\n", strerror(errno));
+ }
+
munmap(map, 2 * page_size);
}