Re: [PATCH 2/2] selftests/mm: verify droppable mappings cannot be locked

David Hildenbrand (Arm)
2026-04-02T07:28:24Z

> +
> +/*
> + * 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));

Why do we need the prior mlockall()? If that is really required, the
comment should be clearer why the munlockall() is insufficient.

Also, why can't we fail only the test?

> + if (munlockall())
> + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno));

Why can't we fail only the test?

> +
> + 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));

same.

> + }
> +
> + if (mlock2_(map, 2 * page_size, 0)) {
> + munmap(map, 2 * page_size);

Not required when exiting either way?

> + ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno));
> + }
> +
> + 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));

Similar comments as for the other path regarding ksft_exit_fail_msg() etc.

> +
> + 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);
> }

--
Cheers,

David