From: Andrew Morton <akpm@linux-foundation.org>
To: Minchan Kim <minchan@kernel.org>
Cc: linux-mm <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
John Hubbard <jhubbard@nvidia.com>,
John Dias <joaodias@google.com>,
David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH v2] mm: fix is_pinnable_page against on cma page
Date: Sat, 7 May 2022 12:23:01 -0700 [thread overview]
Message-ID: <20220507122301.3b50eb030f9cd6f047f14352@linux-foundation.org> (raw)
In-Reply-To: <20220505064429.2818496-1-minchan@kernel.org>
On Wed, 4 May 2022 23:44:29 -0700 Minchan Kim <minchan@kernel.org> wrote:
> 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 putting CMA pages longterm pinning possible on
> pin_user_pages APIs so CMA allocation fails.
>
> 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 type. Thus, we don't
> need zone->lock but just checks the migratype in either of
> (MIGRATE_ISOLATE and MIGRATE_CMA).
>
> Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause
> rejecting of pinning the page on MIGRATE_ISOLATE pageblock even
> thouth it's neither CMA nor movable zone if the page is temporarily
"though"
> unmovable. However, the migration failure is general issue, not
> only come from MIGRATE_ISOLATE and the MIGRATE_ISOLATE is also
> transient state like other temporal refcount holding of pages.
>
> ...
>
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1625,8 +1625,18 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
> #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
> + /*
> + * use volatile to use local variable mt instead of
> + * refetching mt value.
> + */
> + volatile int mt = get_pageblock_migratetype(page);
> +
> + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
> + return false;
> +#endif
Open-coded use of `volatile' draws unwelcome attention.
What are we trying to do here? Prevent the compiler from rerunning all
of get_pageblock_migratetype() (really __get_pfnblock_flags_mask())
twice? That would be pretty dumb of it?
Would a suitably-commented something like
int __mt = get_pageblock_migratetype(page);
int mt = __READ_ONCE(__mt);
express this better?
> +
> + return !(is_zone_movable_page(page) || is_zero_pfn(page_to_pfn(page)));
> }
> #else
> static inline bool is_pinnable_page(struct page *page)
next prev parent reply other threads:[~2022-05-07 19:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 6:44 [PATCH v2] mm: fix is_pinnable_page against on cma page Minchan Kim
2022-05-07 19:23 ` Andrew Morton [this message]
2022-05-08 0:19 ` David Hildenbrand
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=20220507122301.3b50eb030f9cd6f047f14352@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=joaodias@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=paulmck@kernel.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;
as well as URLs for NNTP newsgroup(s).