From: David Hildenbrand <david@redhat.com>
To: Luiz Capitulino <luizcap@redhat.com>, willy@infradead.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, lcapitulino@gmail.com, shivankg@amd.com
Subject: Re: [PATCH 2/3] proc: kpagecount: use snapshot_page()
Date: Tue, 1 Jul 2025 20:36:05 +0200 [thread overview]
Message-ID: <b63563f0-5008-4900-b3df-c194435c0f1f@redhat.com> (raw)
In-Reply-To: <5e94d287b6174098938ddd9959cf3c0619fb610a.1750961812.git.luizcap@redhat.com>
On 26.06.25 20:16, Luiz Capitulino wrote:
> Currently, the call to folio_precise_page_mapcount() from kpage_read()
> can race with a folio split. When the race happens we trigger a
> VM_BUG_ON_FOLIO() in folio_entire_mapcount() (see splat below).
>
> This commit fixes this race by using snapshot_page() so that we
> retreive the folio mapcount using a folio snapshot.
>
> Splat:
>
> [ 2356.558576] page: refcount:1 mapcount:1 mapping:0000000000000000 index:0xffff85200 pfn:0x6f7c00
> [ 2356.558748] memcg:ffff000651775780
> [ 2356.558763] anon flags: 0xafffff60020838(uptodate|dirty|lru|owner_2|swapbacked|node=1|zone=2|lastcpupid=0xfffff)
> [ 2356.558796] raw: 00afffff60020838 fffffdffdb5d0048 fffffdffdadf7fc8 ffff00064c1629c1
> [ 2356.558817] raw: 0000000ffff85200 0000000000000000 0000000100000000 ffff000651775780
> [ 2356.558839] page dumped because: VM_BUG_ON_FOLIO(!folio_test_large(folio))
> [ 2356.558882] ------------[ cut here ]------------
> [ 2356.558897] kernel BUG at ./include/linux/mm.h:1103!
> [ 2356.558982] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
> [ 2356.564729] CPU: 8 UID: 0 PID: 1864 Comm: folio-split-rac Tainted: G S W 6.15.0+ #3 PREEMPT(voluntary)
> [ 2356.566196] Tainted: [S]=CPU_OUT_OF_SPEC, [W]=WARN
> [ 2356.566814] Hardware name: Red Hat KVM, BIOS edk2-20241117-3.el9 11/17/2024
> [ 2356.567684] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
> [ 2356.568563] pc : kpage_read.constprop.0+0x26c/0x290
> [ 2356.569605] lr : kpage_read.constprop.0+0x26c/0x290
> [ 2356.569992] sp : ffff80008fb739b0
> [ 2356.570263] x29: ffff80008fb739b0 x28: ffff00064aa69580 x27: 00000000ff000000
> [ 2356.570842] x26: 0000fffffffffff8 x25: ffff00064aa69580 x24: ffff80008fb73ae0
> [ 2356.571411] x23: 0000000000000001 x22: 0000ffff86c6e8b8 x21: 0000000000000008
> [ 2356.571978] x20: 00000000006f7c00 x19: 0000ffff86c6e8b8 x18: 0000000000000000
> [ 2356.572581] x17: 3630303066666666 x16: 0000000000000003 x15: 0000000000001000
> [ 2356.573217] x14: 00000000ffffffff x13: 0000000000000004 x12: 00aaaaaa00aaaaaa
> [ 2356.577674] x11: 0000000000000000 x10: 00aaaaaa00aaaaaa x9 : ffffbf3afca6c300
> [ 2356.578332] x8 : 0000000000000002 x7 : 0000000000000001 x6 : 0000000000000001
> [ 2356.578984] x5 : ffff000c79812408 x4 : 0000000000000000 x3 : 0000000000000000
> [ 2356.579635] x2 : 0000000000000000 x1 : ffff00064aa69580 x0 : 000000000000003e
> [ 2356.580286] Call trace:
> [ 2356.580524] kpage_read.constprop.0+0x26c/0x290 (P)
> [ 2356.580982] kpagecount_read+0x28/0x40
> [ 2356.581336] proc_reg_read+0x38/0x100
> [ 2356.581681] vfs_read+0xcc/0x320
> [ 2356.581992] ksys_read+0x74/0x118
> [ 2356.582306] __arm64_sys_read+0x24/0x38
> [ 2356.582668] invoke_syscall+0x70/0x100
> [ 2356.583022] el0_svc_common.constprop.0+0x48/0xf8
> [ 2356.583456] do_el0_svc+0x28/0x40
> [ 2356.583930] el0_svc+0x38/0x118
> [ 2356.584328] el0t_64_sync_handler+0x144/0x168
> [ 2356.584883] el0t_64_sync+0x19c/0x1a0
> [ 2356.585350] Code: aa0103e0 9003a541 91082021 97f813fc (d4210000)
> [ 2356.586130] ---[ end trace 0000000000000000 ]---
> [ 2356.587377] note: folio-split-rac[1864] exited with irqs disabled
> [ 2356.588050] note: folio-split-rac[1864] exited with preempt_count 1
>
> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
> ---
> fs/proc/page.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/fs/proc/page.c b/fs/proc/page.c
> index 999af26c7298..936f8bbe5a6f 100644
> --- a/fs/proc/page.c
> +++ b/fs/proc/page.c
> @@ -43,6 +43,22 @@ static inline unsigned long get_max_dump_pfn(void)
> #endif
> }
>
> +static u64 get_kpage_count(const struct page *page)
> +{
> + struct page_snapshot ps;
> + u64 ret;
> +
> + snapshot_page(&ps, page);
> +
> + if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT))
> + ret = folio_precise_page_mapcount(&ps.folio_snapshot,
> + &ps.page_snapshot);
> + else
> + ret = folio_average_page_mapcount(&ps.folio_snapshot);
> +
> + return ret;
> +}
> +
> static ssize_t kpage_read(struct file *file, char __user *buf,
> size_t count, loff_t *ppos,
> enum kpage_operation op)
> @@ -75,10 +91,7 @@ static ssize_t kpage_read(struct file *file, char __user *buf,
> info = stable_page_flags(page);
> break;
> case KPAGE_COUNT:
> - if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT))
> - info = folio_precise_page_mapcount(page_folio(page), page);
> - else
> - info = folio_average_page_mapcount(page_folio(page));
> + info = get_kpage_count(page);
> break;
> case KPAGE_CGROUP:
> info = page_cgroup_ino(page);
Yes, that should work
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-07-01 18:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 18:16 [PATCH 0/3] mm: introduce snapshot_page() Luiz Capitulino
2025-06-26 18:16 ` [PATCH 1/3] " Luiz Capitulino
2025-06-26 21:39 ` Andrew Morton
2025-06-26 21:42 ` Luiz Capitulino
2025-06-26 18:16 ` [PATCH 2/3] proc: kpagecount: use snapshot_page() Luiz Capitulino
2025-06-27 18:30 ` SeongJae Park
2025-07-01 18:36 ` David Hildenbrand [this message]
2025-07-02 6:25 ` Shivank Garg
2025-07-02 17:38 ` Luiz Capitulino
2025-06-26 18:16 ` [PATCH 3/3] fs: stable_page_flags(): " Luiz Capitulino
2025-07-01 18:44 ` David Hildenbrand
2025-07-02 17:36 ` Luiz Capitulino
2025-07-02 6:40 ` [PATCH 0/3] mm: introduce snapshot_page() Shivank Garg
2025-07-02 17:39 ` Luiz Capitulino
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=b63563f0-5008-4900-b3df-c194435c0f1f@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=lcapitulino@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luizcap@redhat.com \
--cc=shivankg@amd.com \
--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
all inboxes | Powered by JetHome®