mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sarthak Sharma <sarthak.sharma@arm.com>
To: "Gregory Price (Meta)" <gourry@gourry.net>,
	linux-kselftest@vger.kernel.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org,
	liam@infradead.org, vbabka@kernel.org, rppt@kernel.org,
	surenb@google.com, mhocko@suse.com, shuah@kernel.org
Subject: Re: [PATCH 7/8] selftests/mm: check MADV_PAGEOUT file permissions
Date: Fri, 16 Oct 2026 17:48:11 +0530	[thread overview]
Message-ID: <cba2a01d-630c-42d3-b6e4-b498f10c4b45@arm.com> (raw)
In-Reply-To: <20261014175756.2035176-8-gourry@gourry.net>

Hi Gregory!

On 10/14/26 11:27 PM, Gregory Price (Meta) wrote:
> MADV_PAGEOUT only pages out file pages for a caller that owns the file or
> could open it for writing, per can_do_file_pageout(). Any other caller
> gets nothing from a shared file mapping, and only the anonymous COW pages
> from a private one.
> 
> Check that the owner of a read-only file can evict a clean page of it,
> once a writable file page shows that file pages can be paged out at all.
> That test runs as an unprivileged owner even when started as root, so
> that capabilities cannot stand in for ownership.
> 
> Also check that an unauthorized caller leaves a shared file page resident,
> and that it pages out the COW page of a private mapping but not the file
> page next to it. These need root to change credentials, and skip if that
> fails.
> 
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---

[...]
>  
> +/*
> + * The owner of a file may page out its clean page-cache pages. Run as an
> + * unprivileged owner, so that capabilities cannot stand in for ownership.
> + */
> +TEST_F(madvise, pageout_evicts_owned_file_page)
> +{
> +	char *mapping, *control;
> +
> +	if (!geteuid() && !drop_privileges())
> +		SKIP(return, "could not drop privileges");
> +	pin_to_current_cpu(_metadata);

Is there a reason why we are pinning to the current CPU here and not in
the next two tests?

IIUC (please let me know if I am wrong here), without pinning, say in
the test pageout_private_file_reclaims_only_cow:

[...]

> + * A caller that neither owns nor may write a file may page out the anonymous
> + * COW pages of a private mapping of it, but must leave the file pages
> + * resident.
> + */
> +TEST_F(madvise, pageout_private_file_reclaims_only_cow)
> +{
> +	char *mapping;
> +	bool swapped;
> +
> +	if (geteuid())
> +		SKIP(return, "requires root to change credentials");
> +	mapping = map_temp_file(_metadata, 2 * page_size, MAP_PRIVATE,
> +				0400);
> +	if (!drop_privileges())
> +		SKIP(return, "could not drop privileges");
> +
> +	ASSERT_EQ(mapping[0], 0);
> +	ASSERT_EQ(mapping[page_size], 0);
> +	mapping[0] = 1;

If both pages are on CPU 1's per CPU LRU batch here and then hte task
migrates to CPU 2 here

> +
> +	ASSERT_EQ(madvise(mapping, 2 * page_size, MADV_PAGEOUT), 0);

Then this can cause lru_add_drain() on CPU 2, and therefore both pages
do not reach the main LRU list. Thus they won't be reclaimed and the
test can skip here since the CoW page wasn't swapped.

> +	ASSERT_TRUE(pagemap_is_populated(self->pagemap_fd,
> +					 mapping + page_size));
> +	swapped = pagemap_is_swapped(self->pagemap_fd, mapping);
> +	ASSERT_EQ(mapping[0], 1);
> +	ASSERT_EQ(mapping[page_size], 0);
> +	if (!swapped)
> +		SKIP(return, "MADV_PAGEOUT did not swap the COW page");

Also, here we skip if we couldn't swap out the CoW page. Won't it make
more sense to check with pageout_until_swapped() first if pages can be
skipped, and then fail here if the CoW page wasn't skipped after all the
retries, similar to how some other tests implement it?

> +
> +	ASSERT_EQ(munmap(mapping, 2 * page_size), 0);
> +}
> +
>  TEST_HARNESS_MAIN


  reply	other threads:[~2026-10-16 12:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 17:57 [PATCH 0/8] selftests/mm: add MADV_COLD and MADV_PAGEOUT contract tests Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 1/8] " Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 2/8] selftests/mm: check that MADV_PAGEOUT skips holes and swapped pages Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 3/8] selftests/mm: check MADV_COLD and MADV_PAGEOUT range handling Gregory Price (Meta)
2026-10-14 21:31   ` [PATCH] fixup! " Gregory Price (Meta)
2026-10-16 12:17   ` [PATCH 3/8] " Sarthak Sharma
2026-10-16 13:22     ` Gregory Price
2026-10-16 14:07       ` Gregory Price
2026-10-14 17:57 ` [PATCH 4/8] selftests/mm: check that MADV_COLD and MADV_PAGEOUT reject hugetlb Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 5/8] selftests/mm: check that MADV_COLD and MADV_PAGEOUT preserve shared memory Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 6/8] selftests/mm: check MADV_COLD and MADV_PAGEOUT on partly advised THPs Gregory Price (Meta)
2026-10-14 17:57 ` [PATCH 7/8] selftests/mm: check MADV_PAGEOUT file permissions Gregory Price (Meta)
2026-10-16 12:18   ` Sarthak Sharma [this message]
2026-10-16 13:48     ` Gregory Price
2026-10-14 17:57 ` [PATCH 8/8] selftests/mm: check that unauthorized MADV_PAGEOUT skips large file folios Gregory Price (Meta)
2026-10-14 21:26   ` Gregory Price

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=cba2a01d-630c-42d3-b6e4-b498f10c4b45@arm.com \
    --to=sarthak.sharma@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=kernel-team@meta.com \
    --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=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

all inboxes | Powered by JetHome®