linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Pingfan Liu <kernelfans@gmail.com>, <linux-mm@kvack.org>
Cc: Ira Weiny <ira.weiny@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Matthew Wilcox <willy@infradead.org>,
	Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>,
	Christoph Hellwig <hch@infradead.org>,
	Shuah Khan <shuah@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCHv7 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path
Date: Thu, 19 Mar 2020 15:17:34 -0700	[thread overview]
Message-ID: <a4e7dc4d-9925-b0c4-e543-4626b94d6f9a@nvidia.com> (raw)
In-Reply-To: <1584445652-30064-1-git-send-email-kernelfans@gmail.com>

On 3/17/20 4:47 AM, Pingfan Liu wrote:
> FOLL_LONGTERM is a special case of FOLL_PIN. It suggests a pin which is
> going to be given to hardware and can't move. It would truncate CMA
> permanently and should be excluded.
> 
> In gup slow path, slow path, where


s/slow path, slow path/slow path/


> __gup_longterm_locked->check_and_migrate_cma_pages() handles FOLL_LONGTERM,
> but in fast path, there lacks such a check, which means a possible leak of
> CMA page to longterm pinned.
> 
> Place a check in try_grab_compound_head() in the fast path to fix the leak,
> and if FOLL_LONGTERM happens on CMA, it will fall back to slow path to
> migrate the page.
> 
> Some note about the check:
> Huge page's subpages have the same migrate type due to either
> allocation from a free_list[] or alloc_contig_range() with param
> MIGRATE_MOVABLE. So it is enough to check on a single subpage
> by is_migrate_cma_page(subpage)
> 
> Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> To: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> ---
> v6 -> v7: fix coding style issue
>   mm/gup.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index 9df77b1..0a536d7 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -89,6 +89,15 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page,
>   		int orig_refs = refs;
> 
>   		/*
> +		 * Huge page's subpages have the same migrate type due to either
> +		 * allocation from a free_list[] or alloc_contig_range() with
> +		 * param MIGRATE_MOVABLE. So it is enough to check on a subpage.
> +		 */

Urggh, this comment is fine in the commit description, but at this location in the
code it is completely incomprehensible! Instead of an extremely far-removed tidbit about
interactions between CMA and huge pages, this comment should be explaining why we bail
out early in the specific case of FOLL_PIN + FOLL_LONGTERM. And we don't bail out for
FOLL_GET + FOLL_LONGTERM...


I'm expect it is something like:

		/*
		 * We can't do FOLL_LONGTERM + FOLL_PIN with CMA in the gup fast
		 * path, so fail and let the caller fall back to the slow path.
		 */


...approximately. Right?


> +		if (unlikely(flags & FOLL_LONGTERM) &&
> +				is_migrate_cma_page(page))
> +			return NULL;
> +
> +		/*
>   		 * When pinning a compound page of order > 1 (which is what
>   		 * hpage_pincount_available() checks for), use an exact count to
>   		 * track it, via hpage_pincount_add/_sub().
> --
> 2.7.5
> 




thanks,
-- 
John Hubbard
NVIDIA


  parent reply	other threads:[~2020-03-19 22:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16  4:34 [PATCHv6 0/3] fix omission of check on FOLL_LONGTERM in gup fast path Pingfan Liu
2020-03-16  4:34 ` [PATCHv6 1/3] mm/gup: rename nr as nr_pinned in get_user_pages_fast() Pingfan Liu
2020-03-16  8:54   ` Christoph Hellwig
2020-03-19 21:51   ` John Hubbard
2020-03-16  4:34 ` [PATCHv6 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Pingfan Liu
2020-03-16  8:55   ` Christoph Hellwig
2020-03-17 11:45     ` Pingfan Liu
2020-03-17 11:47   ` [PATCHv7 " Pingfan Liu
2020-03-17 12:09     ` Christoph Hellwig
2020-03-18 12:15     ` Jason Gunthorpe
2020-03-19 22:17     ` John Hubbard [this message]
2020-03-20  9:19       ` Pingfan Liu
2020-03-16  4:34 ` [PATCHv6 3/3] mm/gup_benchemark: add LONGTERM_BENCHMARK test " Pingfan Liu
2020-03-19 22:27   ` John Hubbard
2020-03-20  9:17     ` Pingfan Liu

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=a4e7dc4d-9925-b0c4-e543-4626b94d6f9a@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=hch@infradead.org \
    --cc=ira.weiny@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=kernelfans@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=willy@infradead.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).