From: Matthew Wilcox <willy@infradead.org>
To: Jann Horn <jannh@google.com>
Cc: Linux-MM <linux-mm@kvack.org>, Zi Yan <ziy@nvidia.com>,
Peter Xu <peterx@redhat.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
Andrew Morton <akpm@linux-foundation.org>,
chinwen.chang@mediatek.com,
kernel list <linux-kernel@vger.kernel.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Vlastimil Babka <vbabka@suse.cz>,
Michel Lespinasse <walken@google.com>,
syzbot <syzbot+1f52b3a18d5633fa7f82@syzkaller.appspotmail.com>
Subject: Re: split_huge_page_to_list() races with page_mapcount() on migration entry in smaps code? [was: Re: [syzbot] kernel BUG in __page_mapcount]
Date: Mon, 7 Jun 2021 21:20:43 +0100 [thread overview]
Message-ID: <YL5/mz4isnKra18c@casper.infradead.org> (raw)
In-Reply-To: <CAG48ez08GhsK00-J=1hbZrccB7uZ10EbN8i1Zj4pfp4V=LZEZA@mail.gmail.com>
On Mon, Jun 07, 2021 at 09:55:09PM +0200, Jann Horn wrote:
> On Mon, Jun 7, 2021 at 8:03 PM Matthew Wilcox <willy@infradead.org> wrote:
> > On Mon, Jun 07, 2021 at 07:27:23PM +0200, Jann Horn wrote:
> > > === Short summary ===
> > > I believe the issue here is a race between /proc/*/smaps and
> > > split_huge_page_to_list():
> > >
> > > The codepath for /proc/*/smaps walks the pagetables and (e.g. in
> > > smaps_account()) calls page_mapcount() not just on pages from normal
> > > PTEs but also on migration entries (since commit b1d4d9e0cbd0a
> > > "proc/smaps: carefully handle migration entries", from Linux v3.5).
> > > page_mapcount() expects compound pages to be stable.
> > >
> > > The split_huge_page_to_list() path first protects the compound page by
> > > locking it and replacing all its PTEs with migration entries (since
> > > the THP rewrite in v4.5, I think?), then does the actual splitting
> > > using __split_huge_page().
> > >
> > > So there's a mismatch of expectations here:
> > > The smaps code expects that migration entries point to stable compound
> > > pages, while the THP code expects that it's okay to split a compound
> > > page while it has migration entries.
> >
> > Will it be a colossal performance penalty if we always get the page
> > refcount after looking it up? That will cause split_huge_page() to
> > fail to split the page if it hits this race.
>
> Hmm - but with that approach I'm not sure you could even easily take a
> refcount on a page whose refcount may be frozen and which may be in
> the middle of being shattered? get_page_unless_zero() is wrong because
> you can't take references on tail pages, right? (Or can you?) And
> try_get_page() is wrong because it bugs out if the refcount is zero -
> and even if it didn't do that, you might end up holding a reference on
> the head page while the page you're actually interested in is a tail
> page?
>
> I guess if it was really necessary, it'd be possible to do some kind
> of retry thing that grabs a reference on the compound head, then
> checks that the tail page is still associated with the compound head,
> and if not, drops the compound head and tries again?
Right; that's how get_user_page_fast() works -- see
try_get_compound_head(). If it can't get the reference, it just fails.
I suspect for smaps, we can just choose to not count the page. It'll be
an inaccuracy in the stats, but I don't think that's a big deal.
next prev parent reply other threads:[~2021-06-07 20:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <00000000000017977605c395a751@google.com>
2021-06-07 17:27 ` split_huge_page_to_list() races with page_mapcount() on migration entry in smaps code? [was: Re: [syzbot] kernel BUG in __page_mapcount] Jann Horn
2021-06-07 18:03 ` Matthew Wilcox
2021-06-07 19:55 ` Jann Horn
2021-06-07 20:20 ` Matthew Wilcox [this message]
2021-06-07 20:49 ` Kirill A. Shutemov
2021-12-21 17:24 ` [syzbot] kernel BUG in __page_mapcount syzbot
2021-12-21 18:24 ` Yang Shi
2021-12-21 18:40 ` Matthew Wilcox
2021-12-21 19:07 ` Yang Shi
2021-12-22 1:42 ` Yang Shi
2022-01-05 19:05 ` Yang Shi
2022-01-11 23:14 ` Yang Shi
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=YL5/mz4isnKra18c@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=chinwen.chang@mediatek.com \
--cc=jannh@google.com \
--cc=khlebnikov@yandex-team.ru \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=syzbot+1f52b3a18d5633fa7f82@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=vbabka@suse.cz \
--cc=walken@google.com \
--cc=ziy@nvidia.com \
/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).