All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Umang Pokhriyal <umangpokhriyall@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Peter Xu <peterx@redhat.com>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/mm: test a uffd write-protect range with an unregistered page
Date: Tue, 3 Nov 2026 21:05:46 +0200	[thread overview]
Message-ID: <auowiuwkogQ0-g7V@kernel.org> (raw)
In-Reply-To: <20261102103621.156928-3-umangpokhriyall@gmail.com>

Hi Umang,

On Mon, Nov 02, 2026 at 04:06:21PM +0530, Umang Pokhriyal wrote:
> Register only the first of two pages and check that UFFDIO_WRITEPROTECT
> over both pages fails with ENOENT without changing the first page, when
> protecting and when unprotecting.

I don't think it's worth keeping the test for a regression we already
fixed.
 
> Signed-off-by: Umang Pokhriyal <umangpokhriyall@gmail.com>
> ---
>  tools/testing/selftests/mm/uffd-unit-tests.c | 56 ++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
> index 298609544..57e442fd2 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -375,6 +375,56 @@ static void uffd_wp_unpopulated_test(uffd_global_test_opts_t *gopts, uffd_test_a
>  	uffd_test_pass();
>  }
>  
> +/*
> + * UFFDIO_WRITEPROTECT over a range whose second page is not registered must
> + * fail without changing the first page, in both directions.
> + */
> +static void uffd_wp_partial_range_test(uffd_global_test_opts_t *gopts,
> +				       uffd_test_args_t *args)
> +{
> +	struct uffdio_writeprotect prms = {
> +		.range.start = (uint64_t)gopts->area_dst,
> +		.range.len = 2 * gopts->page_size,
> +	};
> +	uint64_t value;
> +	int pagemap_fd;
> +
> +	/* Only the first page is registered; the second is a separate VMA */
> +	if (uffd_register(gopts->uffd, gopts->area_dst, gopts->page_size,
> +			  false, true, false))
> +		err("register failed");
> +
> +	pagemap_fd = pagemap_open();
> +	*gopts->area_dst = 1;
> +
> +	prms.mode = UFFDIO_WRITEPROTECT_MODE_WP;
> +	if (!ioctl(gopts->uffd, UFFDIO_WRITEPROTECT, &prms) || errno != ENOENT) {
> +		uffd_test_fail("protect over an unregistered page did not fail with ENOENT");
> +		goto out;
> +	}
> +	value = pagemap_get_entry(pagemap_fd, gopts->area_dst);
> +	if (value & PM_UFFD_WP) {
> +		uffd_test_fail("failed protect changed the first page");
> +		goto out;
> +	}
> +
> +	wp_range(gopts->uffd, (uint64_t)gopts->area_dst, gopts->page_size, true);
> +	prms.mode = 0;
> +	if (!ioctl(gopts->uffd, UFFDIO_WRITEPROTECT, &prms) || errno != ENOENT) {
> +		uffd_test_fail("unprotect over an unregistered page did not fail with ENOENT");
> +		goto out;
> +	}
> +	value = pagemap_get_entry(pagemap_fd, gopts->area_dst);
> +	if (!(value & PM_UFFD_WP)) {
> +		uffd_test_fail("failed unprotect changed the first page");
> +		goto out;
> +	}
> +
> +	uffd_test_pass();
> +out:
> +	close(pagemap_fd);
> +}
> +
>  static void uffd_wp_fork_test_common(uffd_global_test_opts_t *gopts, uffd_test_args_t *args,
>  				     bool with_event)
>  {
> @@ -2403,6 +2453,12 @@ uffd_test_case_t uffd_tests[] = {
>  		.uffd_feature_required =
>  		UFFD_FEATURE_PAGEFAULT_FLAG_WP | UFFD_FEATURE_WP_UNPOPULATED,
>  	},
> +	{
> +		.name = "wp-partial-range",
> +		.uffd_fn = uffd_wp_partial_range_test,
> +		.mem_targets = MEM_ANON,
> +		.uffd_feature_required = UFFD_FEATURE_PAGEFAULT_FLAG_WP,
> +	},
>  	{
>  		.name = "minor",
>  		.uffd_fn = uffd_minor_test,
> -- 
> 2.53.0
> 

-- 
Sincerely yours,
Mike.


      reply	other threads:[~2026-11-03 19:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 10:36 [PATCH 0/2] userfaultfd: validate the whole range before changing write protection Umang Pokhriyal
2026-11-02 10:36 ` [PATCH 1/2] " Umang Pokhriyal
2026-11-03 18:54   ` Mike Rapoport
2026-11-04  9:21     ` Umang Pokhriyal
2026-11-02 10:36 ` [PATCH 2/2] selftests/mm: test a uffd write-protect range with an unregistered page Umang Pokhriyal
2026-11-03 19:05   ` Mike Rapoport [this message]

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=auowiuwkogQ0-g7V@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=umangpokhriyall@gmail.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 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.