From: Matthew Wilcox <willy@infradead.org>
To: Jann Horn <jannh@google.com>
Cc: Linux-MM <linux-mm@kvack.org>,
kernel list <linux-kernel@vger.kernel.org>,
Youquan Song <youquan.song@intel.com>,
Andrea Arcangeli <aarcange@redhat.com>, Jan Kara <jack@suse.cz>,
Mike Kravetz <mike.kravetz@oracle.com>,
John Hubbard <jhubbard@nvidia.com>,
"Kirill A. Shutemov" <kirill@shutemov.name>
Subject: Re: page refcount race between prep_compound_gigantic_page() and __page_cache_add_speculative()?
Date: Tue, 15 Jun 2021 13:40:28 +0100 [thread overview]
Message-ID: <YMifvD723USsnWRH@casper.infradead.org> (raw)
In-Reply-To: <CAG48ez23q0Jy9cuVnwAe7t_fdhMk2S7N5Hdi-GLcCeq5bsfLxw@mail.gmail.com>
On Tue, Jun 15, 2021 at 01:03:53PM +0200, Jann Horn wrote:
> The messier path, as the original commit describes, is "gigantic" page
> allocation. In that case, we'll go through the following path (if we
> ignore CMA):
>
> alloc_fresh_huge_page():
> alloc_gigantic_page()
> alloc_contig_pages()
> __alloc_contig_pages()
> alloc_contig_range()
> isolate_freepages_range()
> split_map_pages()
> post_alloc_hook() [FOR EVERY PAGE]
> set_page_refcounted()
> set_page_count(page, 1)
> prep_compound_gigantic_page()
> set_page_count(p, 0) [FOR EVERY TAIL PAGE]
>
> so all the tail pages are initially allocated with refcount 1 by the
> page allocator, and then we overwrite those refcounts with zeroes.
>
>
> Luckily, the only non-__init codepath that can get here is
> __nr_hugepages_store_common(), which is only invoked from privileged
> writes to sysfs/sysctls.
Argh. What if we passed __GFP_COMP into alloc_contig_pages()?
The current callers of alloc_contig_range() do not pass __GFP_COMP,
so it's no behaviour change for them, and __GFP_COMP implies this
kind of behaviour. I think that would imply _not_ calling
split_map_pages(), which implies not calling post_alloc_hook(),
which means we probably need to do a lot of the parts of
post_alloc_hook() in alloc_gigantic_page(). Yuck.
next prev parent reply other threads:[~2021-06-15 12:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 11:03 page refcount race between prep_compound_gigantic_page() and __page_cache_add_speculative()? Jann Horn
2021-06-15 12:40 ` Matthew Wilcox [this message]
2021-06-15 18:27 ` Mike Kravetz
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=YMifvD723USsnWRH@casper.infradead.org \
--to=willy@infradead.org \
--cc=aarcange@redhat.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jhubbard@nvidia.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=youquan.song@intel.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).