Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5656398ybi; Tue, 4 Jun 2019 09:56:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIpENeDophMTJXoELrfM+HIzb6UfrgSLHkblXA3GrNSSpuAGzEd5EbaWCeo/Ywp0Wxe4E/ X-Received: by 2002:a17:902:903:: with SMTP id 3mr11788971plm.281.1559667365790; Tue, 04 Jun 2019 09:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559667365; cv=none; d=google.com; s=arc-20160816; b=uLlDJ4tLVT3NHtyg6n5/djqrJ5vcPcXdObovm4RAfRX9hwvUPOQb0eaKFSdddK7aRa qjz6X+GnBaIolFj0e3vWv+RSURKuqy4HJYAFleG4CM15f/5SrIGgG76mSb1dyAjDKa1G sF4dJ3WfHwALUXSIJrTouvM88q9eSnvdNgD7LviPledp59Lu0tKA2SDeyuSyLaSQZh09 /vHWy/TeStbLUbVFos2BWose9kSrrcFcKpB7tdhJesJRdyyzxaDOaid0RokHMqx8s3tI 850zXNe/yBJ9EiU2UD4hB2QI7EQBcKff1ypYmpQvJLnc/vjsh8i0BK82PD95hS3jftH/ S/kA== 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=UdpBYgiDIWDyW9pK5bHCF7O/6X2xvtL1enElQmIQnuU=; b=mr+TiYvtumijBH9UZXS8ACG41L+4pHRACEy8d04Lj4MBqZx+Z4ip33bF3KRh7/PDlC qocTu0XZ+hU/jJk+D1AJ4DMq/UwpKUyOSP1IT4Y2MfJa2LwXW/5oeW5bLiTvt6jPjm1E /K6kMIuUWosTtfeSJtZcmAuCbBQrworZZlUTxV5y1Dk26fL/1HsM6Hqm7kwyu5xENofz faijHuMQ2rS4yd5elUwjPMpX7s4e8IVYTfNFwgc89VcBm6AXnK0LPGnBdJedG8YYV2Gu cPys3D8e1CAFIKzMF4dHr1ZBfdMQkvR2u1FIMtq+AUYGQ6/gxv+1Kie8nAjCEoBiDPB/ uYCA== 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 i3si22714585pgq.440.2019.06.04.09.55.50; Tue, 04 Jun 2019 09:56:05 -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 S1727875AbfFDQyZ (ORCPT + 99 others); Tue, 4 Jun 2019 12:54:25 -0400 Received: from mga04.intel.com ([192.55.52.120]:50580 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727663AbfFDQyZ (ORCPT ); Tue, 4 Jun 2019 12:54:25 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 09:54:24 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by fmsmga008.fm.intel.com with ESMTP; 04 Jun 2019 09:54:24 -0700 Date: Tue, 4 Jun 2019 09:55:34 -0700 From: Ira Weiny To: Christoph Hellwig Cc: Pingfan Liu , linux-mm@kvack.org, Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , John Hubbard , "Aneesh Kumar K.V" , Keith Busch , linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 1/2] mm/gup: fix omission of check on FOLL_LONGTERM in get_user_pages_fast() Message-ID: <20190604165533.GA3980@iweiny-DESK2.sc.intel.com> References: <1559543653-13185-1-git-send-email-kernelfans@gmail.com> <20190603164206.GB29719@infradead.org> <20190603235610.GB29018@iweiny-DESK2.sc.intel.com> <20190604070808.GA28858@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190604070808.GA28858@infradead.org> 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 Tue, Jun 04, 2019 at 12:08:08AM -0700, Christoph Hellwig wrote: > On Mon, Jun 03, 2019 at 04:56:10PM -0700, Ira Weiny wrote: > > On Mon, Jun 03, 2019 at 09:42:06AM -0700, Christoph Hellwig wrote: > > > > +#if defined(CONFIG_CMA) > > > > > > You can just use #ifdef here. > > > > > > > +static inline int reject_cma_pages(int nr_pinned, unsigned int gup_flags, > > > > + struct page **pages) > > > > > > Please use two instead of one tab to indent the continuing line of > > > a function declaration. > > > > > > > +{ > > > > + if (unlikely(gup_flags & FOLL_LONGTERM)) { > > > > > > IMHO it would be a little nicer if we could move this into the caller. > > > > FWIW we already had this discussion and thought it better to put this here. > > > > https://lkml.org/lkml/2019/5/30/1565 > > I don't see any discussion like this. FYI, this is what I mean, > code might be easier than words: Indeed that is more clear. My apologies. Ira > > > diff --git a/mm/gup.c b/mm/gup.c > index ddde097cf9e4..62d770b18e2c 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2197,6 +2197,27 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages, > return ret; > } > > +#ifdef CONFIG_CMA > +static int reject_cma_pages(struct page **pages, int nr_pinned) > +{ > + int i = 0; > + > + for (i = 0; i < nr_pinned; i++) > + if (is_migrate_cma_page(pages[i])) { > + put_user_pages(pages + i, nr_pinned - i); > + return i; > + } > + } > + > + return nr_pinned; > +} > +#else > +static inline int reject_cma_pages(struct page **pages, int nr_pinned) > +{ > + return nr_pinned; > +} > +#endif /* CONFIG_CMA */ > + > /** > * get_user_pages_fast() - pin user pages in memory > * @start: starting user address > @@ -2237,6 +2258,9 @@ int get_user_pages_fast(unsigned long start, int nr_pages, > ret = nr; > } > > + if (nr && unlikely(gup_flags & FOLL_LONGTERM)) > + nr = reject_cma_pages(pages, nr); > + > if (nr < nr_pages) { > /* Try to get the remaining pages with get_user_pages */ > start += nr << PAGE_SHIFT; >