On 7/8/20 9:41 AM, Michal Hocko wrote: > On Wed 08-07-20 16:16:02, Joonsoo Kim wrote: >> On Tue, Jul 07, 2020 at 01:22:31PM +0200, Vlastimil Babka wrote: >> >> Simply, I call memalloc_nocma_{save,restore} in new_non_cma_page(). It >> would not cause any problem. > > I believe a proper fix is the following. The scope is really defined for > FOLL_LONGTERM pins and pushing it inside check_and_migrate_cma_pages > will solve the problem as well but it imho makes more sense to do it in > the caller the same way we do for any others. > > Fixes: 9a4e9f3b2d73 ("mm: update get_user_pages_longterm to migrate pages allocated from CMA region") Agreed. > > I am not sure this is worth backporting to stable yet. CC Aneesh. Context: since check_and_migrate_cma_pages() calls __get_user_pages_locked(), it should also be called under memalloc_nocma_save(). > diff --git a/mm/gup.c b/mm/gup.c > index de9e36262ccb..75980dd5a2fc 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1794,7 +1794,6 @@ static long __gup_longterm_locked(struct task_struct *tsk, > vmas_tmp, NULL, gup_flags); > > if (gup_flags & FOLL_LONGTERM) { > - memalloc_nocma_restore(flags); > if (rc < 0) > goto out; > > @@ -1802,11 +1801,13 @@ static long __gup_longterm_locked(struct task_struct *tsk, > for (i = 0; i < rc; i++) > put_page(pages[i]); > rc = -EOPNOTSUPP; > + memalloc_nocma_restore(flags); > goto out; > } > > rc = check_and_migrate_cma_pages(tsk, mm, start, rc, pages, > vmas_tmp, gup_flags); > + memalloc_nocma_restore(flags); > } > > out: >