From: David Hildenbrand <david@redhat.com>
To: Luiz Capitulino <luizcap@redhat.com>,
willy@infradead.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
shivankg@amd.com, sj@kernel.org, harry.yoo@oracle.com
Subject: Re: [PATCH v3 4/4] fs: stable_page_flags(): use snapshot_page()
Date: Wed, 16 Jul 2025 12:19:29 +0200 [thread overview]
Message-ID: <eb05e517-033d-4059-aaa4-05e996594182@redhat.com> (raw)
In-Reply-To: <52c16c0f00995a812a55980c2f26848a999a34ab.1752499009.git.luizcap@redhat.com>
On 14.07.25 15:16, Luiz Capitulino wrote:
> A race condition is possible in stable_page_flags() where user-space is
> reading /proc/kpageflags concurrently to a folio split. This may lead to
> oopses or BUG_ON()s being triggered.
>
> To fix this, this commit uses snapshot_page() in stable_page_flags() so
> that stable_page_flags() works with a stable page and folio snapshots
> instead.
>
> Note that stable_page_flags() makes use of some functions that require
> the original page or folio pointer to work properly (eg.
> is_free_budy_page() and folio_test_idle()). Since those functions can't
> be used on the page snapshot, we replace their usage with flags that
> were set by snapshot_page() for this purpose.
>
> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
> ---
> fs/proc/page.c | 29 +++++++++++++----------------
> 1 file changed, 13 insertions(+), 16 deletions(-)
>
> diff --git a/fs/proc/page.c b/fs/proc/page.c
> index 936f8bbe5a6f..52e4f49c0638 100644
> --- a/fs/proc/page.c
> +++ b/fs/proc/page.c
> @@ -147,6 +147,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
> u64 stable_page_flags(const struct page *page)
> {
> const struct folio *folio;
> + struct page_snapshot ps;
> unsigned long k;
> unsigned long mapping;
> bool is_anon;
> @@ -158,7 +159,9 @@ u64 stable_page_flags(const struct page *page)
> */
> if (!page)
> return 1 << KPF_NOPAGE;
> - folio = page_folio(page);
> +
> + snapshot_page(&ps, page);
> + folio = &ps.folio_snapshot;
Not sure what to do here if the snapshot is not faithful. Fortunately,
it shouldn't happen often :)
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-07-16 10:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 13:16 [PATCH v3 0/4] mm: introduce snapshot_page() Luiz Capitulino
2025-07-14 13:16 ` [PATCH v3 1/4] mm/memory: introduce is_huge_zero_pfn() and use it in vm_normal_page_pmd() Luiz Capitulino
2025-07-14 14:26 ` David Hildenbrand
2025-07-14 13:16 ` [PATCH v3 2/4] mm/util: introduce snapshot_page() Luiz Capitulino
2025-07-16 10:16 ` David Hildenbrand
2025-07-16 17:36 ` Luiz Capitulino
2025-07-16 18:18 ` David Hildenbrand
2025-07-16 22:19 ` Andrew Morton
2025-07-17 1:52 ` Luiz Capitulino
2025-07-17 15:54 ` Luiz Capitulino
2025-07-14 13:16 ` [PATCH v3 3/4] proc: kpagecount: use snapshot_page() Luiz Capitulino
2025-07-16 10:17 ` David Hildenbrand
2025-07-16 17:41 ` Luiz Capitulino
2025-07-16 18:18 ` David Hildenbrand
2025-07-14 13:16 ` [PATCH v3 4/4] fs: stable_page_flags(): " Luiz Capitulino
2025-07-16 10:19 ` David Hildenbrand [this message]
2025-07-14 13:55 ` [PATCH v3 0/4] mm: introduce snapshot_page() Shivank Garg
2025-07-15 22:53 ` Harry Yoo
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=eb05e517-033d-4059-aaa4-05e996594182@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=harry.yoo@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luizcap@redhat.com \
--cc=shivankg@amd.com \
--cc=sj@kernel.org \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).