On Tue, Mar 17, 2020 at 07:47:32PM +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@xxxxxxxxx> > Cc: Ira Weiny <ira.weiny@xxxxxxxxx> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > Cc: Mike Rapoport <rppt@xxxxxxxxxxxxx> > Cc: Dan Williams <dan.j.williams@xxxxxxxxx> > Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> > Cc: John Hubbard <jhubbard@xxxxxxxxxx> > Cc: "Aneesh Kumar K.V" <aneesh.kumar@xxxxxxxxxxxxx> > Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> > Cc: Shuah Khan <shuah@xxxxxxxxxx> > Cc: Jason Gunthorpe <jgg@xxxxxxxx> > To: linux-mm@xxxxxxxxx > Cc: linux-kernel@xxxxxxxxxxxxxxx > --- > v6 -> v7: fix coding style issue > mm/gup.c | 9 +++++++++ > 1 file changed, 9 insertions(+) Much clearer, thank you Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Jason