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=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 ECC72C4332D for ; Thu, 19 Mar 2020 22:17:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A682F20772 for ; Thu, 19 Mar 2020 22:17:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="OD9DOw9p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A682F20772 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2BD516B0005; Thu, 19 Mar 2020 18:17:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26E626B0006; Thu, 19 Mar 2020 18:17:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 184296B0007; Thu, 19 Mar 2020 18:17:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id EE4D96B0005 for ; Thu, 19 Mar 2020 18:17:38 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 511485DCD for ; Thu, 19 Mar 2020 22:17:38 +0000 (UTC) X-FDA: 76613524596.18.lift48_257e1bab87c41 X-HE-Tag: lift48_257e1bab87c41 X-Filterd-Recvd-Size: 5829 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Mar 2020 22:17:37 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 19 Mar 2020 15:17:22 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 19 Mar 2020 15:17:35 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 19 Mar 2020 15:17:35 -0700 Received: from [10.2.57.192] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 19 Mar 2020 22:17:35 +0000 Subject: Re: [PATCHv7 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path To: Pingfan Liu , CC: Ira Weiny , Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , Aneesh Kumar K.V , Christoph Hellwig , Shuah Khan , Jason Gunthorpe , References: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> <1584445652-30064-1-git-send-email-kernelfans@gmail.com> From: John Hubbard Message-ID: Date: Thu, 19 Mar 2020 15:17:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1584445652-30064-1-git-send-email-kernelfans@gmail.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1584656243; bh=7RS8cNf86O4cn45oHoPDcDaN6ugQPAEMqcDGDuyltGI=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=OD9DOw9ps11yDoJO78JaN5l/ZzyOGO3peaR1QILO3dckGpLF0hdYByFlYnrlqLB7Z 9VuCQE1kM6R4/Y22UgcL/YeDLSJmhzYGbQfCWWaS6U+3bSRkmyuUjq2w3CFBj4vfLD TTdDy012r4ZaF4oXR/1/FXgTELLDTxxKBToRnKmNXGdoe37SpBvzdI7Qm3JjMplEYL v6litjWonZapTlWBdrF2HskmETnv6hMwLRN1ZpAfNBkhoARuayjxrhZ0HPDqVHsjYS +G45k368GS30eC203FVJQlH6qBfkxj4lfotjUv5Mcw9NfEr5I+CYfPeRCOkeaLy4rU VyGIv0CS7j4og== 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 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 > Cc: Ira Weiny > Cc: Andrew Morton > Cc: Mike Rapoport > Cc: Dan Williams > Cc: Matthew Wilcox > Cc: John Hubbard > Cc: "Aneesh Kumar K.V" > Cc: Christoph Hellwig > Cc: Shuah Khan > Cc: Jason Gunthorpe > 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