linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (Oracle)" <ljs@kernel.org>
To: Anthony Yznaga <anthony.yznaga@oracle.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, akpm@linux-foundation.org,
	david@kernel.org,  Liam.Howlett@oracle.com, vbabka@kernel.org,
	rppt@kernel.org, surenb@google.com,  mhocko@suse.com,
	jannh@google.com, pfalcato@suse.de, Jason@zx2c4.com,
	 shuah@kernel.org
Subject: Re: [PATCH v2 2/2] selftests/mm: verify droppable mappings cannot be locked
Date: Wed, 11 Mar 2026 11:25:30 +0000	[thread overview]
Message-ID: <55662200-c212-4146-bc23-7f3d210de3ee@lucifer.local> (raw)
In-Reply-To: <20260310155821.17869-2-anthony.yznaga@oracle.com>

On Tue, Mar 10, 2026 at 08:58:21AM -0700, Anthony Yznaga wrote:
> Verify that a mapping created with MAP_DROPPABLE cannot be locked
> via mlock(), and that it will not be locked if it's created after
> mlockall(MCL_FUTURE).
>
> Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>

Can confirm this test fails before your patch and passes after, so LGTM :)

Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Tested-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>

> ---
>  tools/testing/selftests/mm/mlock2-tests.c | 78 ++++++++++++++++++++---
>  1 file changed, 69 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c
> index b474f2b20def..b5790e717dd6 100644
> --- a/tools/testing/selftests/mm/mlock2-tests.c
> +++ b/tools/testing/selftests/mm/mlock2-tests.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #define _GNU_SOURCE
>  #include <sys/mman.h>
> +#include <linux/mman.h>
>  #include <stdint.h>
>  #include <unistd.h>
>  #include <string.h>
> @@ -163,14 +164,17 @@ static int lock_check(unsigned long addr)
>  	return (vma_rss == vma_size);
>  }
>
> -static int unlock_lock_check(char *map)
> +static int unlock_lock_check(char *map, bool mlock_supported)
>  {
> -	if (is_vmflag_set((unsigned long)map, LOCKED)) {
> +	if (!is_vmflag_set((unsigned long)map, LOCKED))
> +		return 0;
> +
> +	if (mlock_supported)
>  		ksft_print_msg("VMA flag %s is present on page 1 after unlock\n", LOCKED);
> -		return 1;
> -	}
> +	else
> +		ksft_print_msg("VMA flag %s is present on an unsupported VMA\n", LOCKED);
>
> -	return 0;
> +	return 1;
>  }
>
>  static void test_mlock_lock(void)
> @@ -196,7 +200,7 @@ static void test_mlock_lock(void)
>  		ksft_exit_fail_msg("munlock(): %s\n", strerror(errno));
>  	}
>
> -	ksft_test_result(!unlock_lock_check(map), "%s: Unlocked\n", __func__);
> +	ksft_test_result(!unlock_lock_check(map, true), "%s: Unlocked\n", __func__);
>  	munmap(map, 2 * page_size);
>  }
>
> @@ -296,7 +300,7 @@ static void test_munlockall0(void)
>  		ksft_exit_fail_msg("munlockall(): %s\n", strerror(errno));
>  	}
>
> -	ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__);
> +	ksft_test_result(!unlock_lock_check(map, true), "%s: No locked memory\n", __func__);
>  	munmap(map, 2 * page_size);
>  }
>
> @@ -336,7 +340,61 @@ static void test_munlockall1(void)
>  		ksft_exit_fail_msg("munlockall() %s\n", strerror(errno));
>  	}
>
> -	ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__);
> +	ksft_test_result(!unlock_lock_check(map, true), "%s: No locked memory\n", __func__);
> +	munmap(map, 2 * page_size);
> +}
> +
> +/*
> + * 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));
> +	if (munlockall())
> +		ksft_exit_fail_msg("munlockall() %s\n", strerror(errno));
> +
> +	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
> +		   MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
> +	if (map == MAP_FAILED)
> +		ksft_exit_fail_msg("mmap error: %s", strerror(errno));
> +
> +	if (mlock2_(map, 2 * page_size, 0)) {
> +		munmap(map, 2 * page_size);
> +		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));
> +
> +	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
> +		   MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
> +
> +	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);
>  }
>
> @@ -442,7 +500,7 @@ int main(int argc, char **argv)
>
>  	munmap(map, size);
>
> -	ksft_set_plan(13);
> +	ksft_set_plan(15);
>
>  	test_mlock_lock();
>  	test_mlock_onfault();
> @@ -451,6 +509,8 @@ int main(int argc, char **argv)
>  	test_lock_onfault_of_present();
>  	test_vma_management(true);
>  	test_mlockall();
> +	test_mlock_droppable();
> +	test_mlockall_future_droppable();
>
>  	ksft_finished();
>  }
> --
> 2.47.3
>


  parent reply	other threads:[~2026-03-11 11:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 15:58 [PATCH v2 1/2] mm: prevent droppable mappings from being locked Anthony Yznaga
2026-03-10 15:58 ` [PATCH v2 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga
2026-03-11  9:56   ` Pedro Falcato
2026-03-11 11:25   ` Lorenzo Stoakes (Oracle) [this message]
2026-03-31 13:17   ` Mark Brown
2026-03-31 21:17     ` Andrew Morton
2026-04-01 11:17       ` Mark Brown
2026-04-01 20:27         ` Andrew Morton
2026-03-31 22:45     ` anthony.yznaga
2026-03-11  9:27 ` [PATCH v2 1/2] mm: prevent droppable mappings from being locked David Hildenbrand (Arm)
2026-03-12  2:01   ` anthony.yznaga
2026-03-12  8:55     ` David Hildenbrand (Arm)
2026-03-11  9:54 ` Pedro Falcato
2026-03-11 10:36 ` Lorenzo Stoakes (Oracle)
2026-03-11 17:14   ` Andrew Morton
2026-03-12  2:16   ` anthony.yznaga
2026-03-12  8:32     ` David Hildenbrand (Arm)
2026-04-02 23:59 [PATCH v2 0/2] fix MAP_DROPPABLE not supported errno Anthony Yznaga
2026-04-02 23:59 ` [PATCH v2 2/2] selftests/mm: verify droppable mappings cannot be locked Anthony Yznaga
2026-04-03 19:31   ` Andrew Morton
2026-04-08 20:35     ` anthony.yznaga
2026-04-08 21:02       ` Andrew Morton
2026-04-08 22:26         ` anthony.yznaga

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=55662200-c212-4146-bc23-7f3d210de3ee@lucifer.local \
    --to=ljs@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=anthony.yznaga@oracle.com \
    --cc=david@kernel.org \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=pfalcato@suse.de \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox