From: Andrew Morton <akpm@linux-foundation.org>
To: Yang Shi <shy828301@gmail.com>
Cc: david@redhat.com, peterx@redhat.com,
kirill.shutemov@linux.intel.com, jhubbard@nvidia.com,
jgg@nvidia.com, hughd@google.com, aneesh.kumar@linux.ibm.com,
linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Subject: Re: [v2 PATCH 1/2] mm: gup: fix the fast GUP race against THP collapse
Date: Wed, 7 Sep 2022 14:22:46 -0700 [thread overview]
Message-ID: <20220907142246.c7d6f55e1b56fba3e16d974b@linux-foundation.org> (raw)
In-Reply-To: <20220907180144.555485-1-shy828301@gmail.com>
On Wed, 7 Sep 2022 11:01:43 -0700 Yang Shi <shy828301@gmail.com> wrote:
> Since general RCU GUP fast was introduced in commit 2667f50e8b81 ("mm:
> introduce a general RCU get_user_pages_fast()"), a TLB flush is no longer
> sufficient to handle concurrent GUP-fast in all cases, it only handles
> traditional IPI-based GUP-fast correctly. On architectures that send
> an IPI broadcast on TLB flush, it works as expected. But on the
> architectures that do not use IPI to broadcast TLB flush, it may have
> the below race:
>
> CPU A CPU B
> THP collapse fast GUP
> gup_pmd_range() <-- see valid pmd
> gup_pte_range() <-- work on pte
> pmdp_collapse_flush() <-- clear pmd and flush
> __collapse_huge_page_isolate()
> check page pinned <-- before GUP bump refcount
> pin the page
> check PTE <-- no change
> __collapse_huge_page_copy()
> copy data to huge page
> ptep_clear()
> install huge pmd for the huge page
> return the stale page
> discard the stale page
>
> The race could be fixed by checking whether PMD is changed or not after
> taking the page pin in fast GUP, just like what it does for PTE. If the
> PMD is changed it means there may be parallel THP collapse, so GUP
> should back off.
>
> Also update the stale comment about serializing against fast GUP in
> khugepaged.
>
> Fixes: 2667f50e8b81 ("mm: introduce a general RCU get_user_pages_fast()")
Is this not worth a -stable backport?
next prev parent reply other threads:[~2022-09-07 21:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 18:01 [v2 PATCH 1/2] mm: gup: fix the fast GUP race against THP collapse Yang Shi
2022-09-07 18:01 ` [v2 PATCH 2/2] powerpc/64s/radix: don't need to broadcast IPI for radix pmd collapse flush Yang Shi
2022-09-07 19:34 ` David Hildenbrand
2022-09-07 20:12 ` Peter Xu
2022-09-07 21:22 ` Andrew Morton [this message]
2022-09-07 21:23 ` [v2 PATCH 1/2] mm: gup: fix the fast GUP race against THP collapse Yang Shi
2022-09-08 0:06 ` John Hubbard
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=20220907142246.c7d6f55e1b56fba3e16d974b@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=peterx@redhat.com \
--cc=shy828301@gmail.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).