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

anthony.yznaga
2026-04-02T23:16:33Z

On 4/2/26 12:28 AM, David Hildenbrand (Arm) wrote:
>> +
>> +/*
>> + * 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.

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