From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 237CFC00A89 for ; Fri, 30 Oct 2020 20:50:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D1A12076D for ; Fri, 30 Oct 2020 20:50:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D1A12076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 745BC6B0036; Fri, 30 Oct 2020 16:50:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F92C6B005C; Fri, 30 Oct 2020 16:50:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BD1D6B005D; Fri, 30 Oct 2020 16:50:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 31DF06B0036 for ; Fri, 30 Oct 2020 16:50:33 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C0C171F0A for ; Fri, 30 Oct 2020 20:50:32 +0000 (UTC) X-FDA: 77429785104.09.drain17_3a102cd27299 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id A44C4180AD804 for ; Fri, 30 Oct 2020 20:50:32 +0000 (UTC) X-HE-Tag: drain17_3a102cd27299 X-Filterd-Recvd-Size: 3660 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 20:50:30 +0000 (UTC) IronPort-SDR: uJ/XbuFpm2Og2FonMsYbim0aIEQhh9+43MeHNonkZ07ZDYzHsnuSlGSyKttPqK1jFyGWia9tAu oL0eJihM6Pkw== X-IronPort-AV: E=McAfee;i="6000,8403,9790"; a="167881276" X-IronPort-AV: E=Sophos;i="5.77,434,1596524400"; d="scan'208";a="167881276" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2020 13:50:27 -0700 IronPort-SDR: T3/uVVg6MWYaPTTQS4hwI2PCeWGSaX5aksjwy57/ZVrGf5btjtvKO5/PnQbiMpWFphdIEHWc3x XW/JS4XtviaA== X-IronPort-AV: E=Sophos;i="5.77,434,1596524400"; d="scan'208";a="362554876" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2020 13:50:26 -0700 Date: Fri, 30 Oct 2020 13:50:26 -0700 From: Ira Weiny To: Jason Gunthorpe Cc: Andrew Morton , linux-mm@kvack.org, "Aneesh Kumar K.V" , Claudio Imbrenda , Jan Kara , John Hubbard Subject: Re: [PATCH rc] mm/gup: use unpin_user_pages() in check_and_migrate_cma_pages() Message-ID: <20201030205026.GC971338@iweiny-DESK2.sc.intel.com> References: <0-v1-976effcd4468+d4-gup_cma_fix_jgg@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0-v1-976effcd4468+d4-gup_cma_fix_jgg@nvidia.com> User-Agent: Mutt/1.11.1 (2018-12-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Oct 30, 2020 at 01:32:28PM -0300, Jason Gunthorpe wrote: > When FOLL_PIN is passed to __get_user_pages() the page list must be put > back using unpin_user_pages() otherwise the page pin reference persists in > a corrupted state. > > Cc: > Cc: Aneesh Kumar K.V > Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages") > Signed-off-by: Jason Gunthorpe > --- > mm/gup.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > I don't have any way to test CMA stuff, this was noticed by inspection. > > diff --git a/mm/gup.c b/mm/gup.c > index 1bb349e5ed212a..2e26757f3c9276 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1630,8 +1630,11 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > /* > * drop the above get_user_pages reference. > */ I wonder if that comment should be deleted/modified? It does not seem to apply any longer. Also, looks like there is another place this occurs right before the call to check_and_migrate_cma_pages() in __gup_longterm_locked() 1730 if (check_dax_vmas(vmas_tmp, rc)) { 1731 for (i = 0; i < rc; i++) 1732 put_page(pages[i]); 1733 rc = -EOPNOTSUPP; 1734 goto out; 1735 } We should change that site as well. And since we now have 2 places should this be a helper? Ira > - for (i = 0; i < nr_pages; i++) > - put_page(pages[i]); > + if (gup_flags & FOLL_PIN) > + unpin_user_pages(pages, nr_pages); > + else > + for (i = 0; i < nr_pages; i++) > + put_page(pages[i]); > > if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, > (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { > -- > 2.28.0 >