Message ID | 1584333244-10480-3-git-send-email-kernelfans@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fix omission of check on FOLL_LONGTERM in gup fast path | expand |
On Mon, Mar 16, 2020 at 12:34:03PM +0800, 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 > __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 > --- > mm/gup.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index 9df77b1..78132cf 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. > + */ > + if (unlikely(flags & FOLL_LONGTERM) && > + is_migrate_cma_page(page)) > + return NULL; Wrong indentation. We either align two tabs for continuation statements, or after the opening brace of the previous line. With a likely or unlikely thrown in the former IMHO looks much better. E.g. if (unlikely(flags & FOLL_LONGTERM) && is_migrate_cma_page(page)) return NULL;
On Mon, Mar 16, 2020 at 4:55 PM Christoph Hellwig <hch@infradead.org> wrote: > [...] > > Wrong indentation. We either align two tabs for continuation > statements, or after the opening brace of the previous line. With a > likely or unlikely thrown in the former IMHO looks much better. E.g. > > if (unlikely(flags & FOLL_LONGTERM) && > is_migrate_cma_page(page)) > return NULL; > OK, thanks. I will send out V7 to fix it. Regards, Pingfan
diff --git a/mm/gup.c b/mm/gup.c index 9df77b1..78132cf 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. + */ + 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().
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 __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 --- mm/gup.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.5