From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: mm-commits@vger.kernel.org, sfr@canb.auug.org.au,
paulmck@kernel.org, joaodias@google.com, jhubbard@nvidia.com,
david@redhat.com
Subject: Re: [alternative-merged] mm-fix-is_pinnable_page-against-on-cma-page.patch removed from -mm tree
Date: Fri, 20 May 2022 14:42:00 -0700 [thread overview]
Message-ID: <YogLKAuBnDfSJjwm@google.com> (raw)
In-Reply-To: <20220517194801.85817C385B8@smtp.kernel.org>
On Tue, May 17, 2022 at 12:48:00PM -0700, Andrew Morton wrote:
>
> The quilt patch titled
> Subject: mm: fix is_pinnable_page against on cma page
> has been removed from the -mm tree. Its filename was
> mm-fix-is_pinnable_page-against-on-cma-page.patch
>
> This patch was dropped because an alternative patch was merged
Hi Andrew,
I didn't see what an alternative patch was merged.
What I observed from last discussion[1] was that let's use
READ_ONCE in __get_pfnblock_flags_mask and remove READ_ONCE
in is_pinnable_page.
Please point me out if you merged other alternative. Otherwise,
I am happy to post new version based on the comment of [1]
Let me know.
[1] https://lore.kernel.org/all/b6eef200-43d1-7913-21ed-176b05fcb4fe@nvidia.com/
>
> ------------------------------------------------------
> From: Minchan Kim <minchan@kernel.org>
> Subject: mm: fix is_pinnable_page against on cma page
>
> Pages on CMA area could have MIGRATE_ISOLATE as well as MIGRATE_CMA so
> current is_pinnable_page could miss CMA pages which has MIGRATE_ ISOLATE.
> It ends up pinning CMA pages as longterm at pin_user_pages APIs so CMA
> allocation keep failed until the pin is released.
>
> CPU 0 CPU 1 - Task B
>
> cma_alloc
> alloc_contig_range
> pin_user_pages_fast(FOLL_LONGTERM)
> change pageblock as MIGRATE_ISOLATE
> internal_get_user_pages_fast
> lockless_pages_from_mm
> gup_pte_range
> try_grab_folio
> is_pinnable_page
> return true;
> So, pinned the page successfully.
> page migration failure with pinned page
> ..
> .. After 30 sec
> unpin_user_page(page)
>
> CMA allocation succeeded after 30 sec.
>
> The CMA allocation path protects the migration type change race using
> zone->lock but what GUP path need to know is just whether the page is on
> CMA area or not rather than exact migration type. Thus, we don't need
> zone->lock but just checks migration type in either of (MIGRATE_ISOLATE
> and MIGRATE_CMA).
>
> Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause rejecting
> of pinning pages on MIGRATE_ISOLATE pageblocks even though it's neither
> CMA nor movable zone if the page is temporarily unmovable. However, such
> a migration failure by unexpected temporal refcount holding is general
> issue, not only come from MIGRATE_ISOLATE and the MIGRATE_ISOLATE is also
> transient state like other temporal elevated refcount problem.
>
> [akpm@linux-foundation.org: MIGRATE_CMA and MIGRATE_ISOLATE are not bitwise, per Minchan]
> [minchan@kernel.org: restore __mt definition]
> [minchan@kernel.org: changes per Paul and John]
> Link: https://lkml.kernel.org/r/20220512204143.3961150-1-minchan@kernel.org
> Link: https://lkml.kernel.org/r/20220510211743.95831-1-minchan@kernel.org
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: "Paul E . McKenney" <paulmck@kernel.org>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: John Dias <joaodias@google.com>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> include/linux/mm.h | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> --- a/include/linux/mm.h~mm-fix-is_pinnable_page-against-on-cma-page
> +++ a/include/linux/mm.h
> @@ -1625,8 +1625,21 @@ static inline bool page_needs_cow_for_dm
> #ifdef CONFIG_MIGRATION
> static inline bool is_pinnable_page(struct page *page)
> {
> - return !(is_zone_movable_page(page) || is_migrate_cma_page(page)) ||
> - is_zero_pfn(page_to_pfn(page));
> +#ifdef CONFIG_CMA
> + /*
> + * Defend against future compiler LTO features, or code refactoring
> + * that inlines the above function, by forcing a single read. Because,
> + * this routine races with set_pageblock_migratetype(), and we want to
> + * avoid reading zero, when actually one or the other flags was set.
> + */
> + int __mt = get_pageblock_migratetype(page);
> + int mt = __READ_ONCE(__mt);
> +
> + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
> + return false;
> +#endif
> +
> + return !(is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)));
> }
> #else
> static inline bool is_pinnable_page(struct page *page)
> _
>
> Patches currently in -mm which might be from minchan@kernel.org are
>
> mm-dont-be-stuck-to-rmap-lock-on-reclaim-path.patch
>
next prev parent reply other threads:[~2022-05-20 21:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-17 19:48 [alternative-merged] mm-fix-is_pinnable_page-against-on-cma-page.patch removed from -mm tree Andrew Morton
2022-05-20 21:42 ` Minchan Kim [this message]
2022-05-21 3:01 ` Andrew Morton
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=YogLKAuBnDfSJjwm@google.com \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=joaodias@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=sfr@canb.auug.org.au \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.