Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp217067ybi; Thu, 13 Jun 2019 14:38:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6Fo7y2OUzFrIS+21udh3VyaIDztio4XkUiXpIvx2/QSj1k2vThX7ji3LuOhlsYXzX7+jI X-Received: by 2002:a63:306:: with SMTP id 6mr19480160pgd.263.1560461907882; Thu, 13 Jun 2019 14:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560461907; cv=none; d=google.com; s=arc-20160816; b=sVB0KZInad+wz1O6BSV/XHbSNRG5Jtv+D2WN1WSnggIuBqjX57mDSSE6EV04LDswf7 /SvvL3XuiS3Y+7Gs1gDFsrxcEzoYLXn0qc1ja6cHkn+r4nzhjsrit3IBvb1iDK99+HTX oPXK3DdTli3HrRaWwRr76QpFpBvNQJ4xgCvPcdO8FV2fHTF4arupgiDatqltMbu9GyRi vZ78KFYxcLcqEvefo1b3IVPIIDHsRS06cfe+/AESeYIWfC6g3AnHBJbEZmOImfD6mGWe Wy9cjSFdX0ITiMg+miNXvOjAEsP7v+1EAMmunAeZHkf1VZTxzglVD0M32yMBqC26TVG4 s8mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=By13X09yL97FSwMh6aklOWCz4WgFg5XbT9Q4PzBiefs=; b=su+L3m/ZeLWQsgkwE29ARelvY4ehHjTWkE9n/jB4jlkWsI/Wg3yHHzcawG4W9tyxgY z5OpwcwcCCCw8u7IvMe1bd+OcTGCcxUI2YK+TQ1Sz9HQmeGmrcHHrtVPRK9mfhZQzYpY KfrgtGxTfN8eryEDWY+b2v53T2qDW4PUXh9NUaCvnnDNmzH00yNJuUc4fmJNU/SxZRhC mOzXQP60D3YNqJGS24X+Nc30Emf+v18ff+GxGqof+S+TxCqXkmHskI/Y0YMaszkD1xYw 9bWsAobw5Urm9dfknZ/0qvmvZYFtub+mlXXtzLVWwyINmM54h+avVBYWynjDZYSoL5Wo fMJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f16si475123plr.340.2019.06.13.14.38.12; Thu, 13 Jun 2019 14:38:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727320AbfFMVhz (ORCPT + 99 others); Thu, 13 Jun 2019 17:37:55 -0400 Received: from mga07.intel.com ([134.134.136.100]:44112 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726806AbfFMVhz (ORCPT ); Thu, 13 Jun 2019 17:37:55 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2019 14:37:55 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by orsmga008.jf.intel.com with ESMTP; 13 Jun 2019 14:37:54 -0700 Date: Thu, 13 Jun 2019 14:39:16 -0700 From: Ira Weiny To: Pingfan Liu Cc: linux-mm@kvack.org, Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , John Hubbard , "Aneesh Kumar K.V" , Keith Busch , Christoph Hellwig , Shuah Khan , linux-kernel@vger.kernel.org Subject: Re: [PATCHv4 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Message-ID: <20190613213915.GE32404@iweiny-DESK2.sc.intel.com> References: <1560422702-11403-1-git-send-email-kernelfans@gmail.com> <1560422702-11403-3-git-send-email-kernelfans@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1560422702-11403-3-git-send-email-kernelfans@gmail.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 13, 2019 at 06:45:01PM +0800, Pingfan Liu wrote: > FOLL_LONGTERM suggests a pin which is going to be given to hardware and > can't move. It would truncate CMA permanently and should be excluded. > > FOLL_LONGTERM has already been checked in the slow path, but not checked in > the fast path, which means a possible leak of CMA page to longterm pinned > requirement through this crack. > > Place a check in gup_pte_range() in the fast path. > > 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: Keith Busch > Cc: Christoph Hellwig > Cc: Shuah Khan > Cc: linux-kernel@vger.kernel.org > --- > mm/gup.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index 766ae54..de1b03f 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1757,6 +1757,14 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, > VM_BUG_ON(!pfn_valid(pte_pfn(pte))); > page = pte_page(pte); > > + /* > + * FOLL_LONGTERM suggests a pin given to hardware. Prevent it > + * from truncating CMA area > + */ > + if (unlikely(flags & FOLL_LONGTERM) && > + is_migrate_cma_page(page)) > + goto pte_unmap; > + > head = try_get_compound_head(page, 1); > if (!head) > goto pte_unmap; > @@ -1900,6 +1908,12 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, > refs++; > } while (addr += PAGE_SIZE, addr != end); > > + if (unlikely(flags & FOLL_LONGTERM) && > + is_migrate_cma_page(page)) { > + *nr -= refs; > + return 0; > + } > + Why can't we place this check before the while loop and skip subtracting the page count? Can is_migrate_cma_page() operate on any "subpage" of a compound page? Here this calls is_magrate_cma_page() on the tail page of the compound page. I'm not an expert on compound pages nor cma handling so is this ok? It seems like you need to call is_migrate_cma_page() on each page within the while loop? > head = try_get_compound_head(pmd_page(orig), refs); > if (!head) { > *nr -= refs; > @@ -1941,6 +1955,12 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr, > refs++; > } while (addr += PAGE_SIZE, addr != end); > > + if (unlikely(flags & FOLL_LONGTERM) && > + is_migrate_cma_page(page)) { > + *nr -= refs; > + return 0; > + } > + Same comment here. > head = try_get_compound_head(pud_page(orig), refs); > if (!head) { > *nr -= refs; > @@ -1978,6 +1998,12 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr, > refs++; > } while (addr += PAGE_SIZE, addr != end); > > + if (unlikely(flags & FOLL_LONGTERM) && > + is_migrate_cma_page(page)) { > + *nr -= refs; > + return 0; > + } > + And here. Ira > head = try_get_compound_head(pgd_page(orig), refs); > if (!head) { > *nr -= refs; > -- > 2.7.5 >