Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1926947pxa; Sat, 29 Aug 2020 08:02:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziPmuzhNtzkE2xW3fKK6hwIm52UtodR+8hYphuJ8Ft1fyY/0qWnNfGaktvAIK4mmi9SZer X-Received: by 2002:a17:906:34c7:: with SMTP id h7mr4042876ejb.50.1598713344096; Sat, 29 Aug 2020 08:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598713344; cv=none; d=google.com; s=arc-20160816; b=JgG48ZdlP7Pe9lmBc3eD8v3I+Jcqj58MRIF0xeJ0DqEn5jpUJ+2DiKvBXlGAp2muTF AiyIrgWJd1Xp4GNzs7H9PGze3x2CqITVjS+f2wF3eiSUAc28ItKgUz3osxzM/8GC5sz5 xDitOvrENr66BPD77zMO62jF/vTSWStMEpSTLeH5XOSsPtbyaaZSXkoMXvYHTYaW2hkR ZeOfO7ex4hZXNAYgrgKeUV583R2oUZtySEm85Z6G+knp9Jp/njytSkSWUJhmInkt5GRb 4c0lJ8iiZKGXcj/k+KMmWjidKtpSDhO5auMjMkbOrOfwwDSBc4z/bJUCPSdKqv+kqpKj 5uxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lZ/1nHdWsM0stEqTySawdkzFBJIINrqQZQrdzHezIOg=; b=AAPM58sVemxFVQqrnkJ8udAccZUJaqvho7zy8I4cALLAeDXl+4DzdswQY8dq7NZ8UL HTAfE4v5ny4eU/FlGmYeivj7N9gMZY51bS70xRTydbHPLEaNvoX49oQK6IFbsObQt1yz SjW94fUTYjNZxaq9dCrZB02gFe3+0igYq6nVrEEP5o38DCMur2Zvd4qWkaIBfg03AYkE CkIUazN8nYLC5zjtmKkqY1obOex883QAfB2q2eH3ZyLd0CAFEtleudqD3NjKp7fwXqy0 6guExoBuRDNsVQyxcCjK11H1bgDDsNaIvj8Pd7IxvJOo+GmVCQ66TbkOybgt207S7Sm4 EQUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=TCYOE32Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u23si1572838edr.459.2020.08.29.08.01.59; Sat, 29 Aug 2020 08:02:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=TCYOE32Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728306AbgH2O64 (ORCPT + 99 others); Sat, 29 Aug 2020 10:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727772AbgH2O6z (ORCPT ); Sat, 29 Aug 2020 10:58:55 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8F0AC061236; Sat, 29 Aug 2020 07:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lZ/1nHdWsM0stEqTySawdkzFBJIINrqQZQrdzHezIOg=; b=TCYOE32QtYXHxXN0opcVrwM5Mz kBQ37SOSJy8j01V9eIlDS81eUB7wNOxLci8NDVQbTQWRfFzr8iKJZ/JEQ0ovCMLfGtjRYma+8oVi3 4GTrI/hVgiqsk4TiUa2cRVSLeODaBl1P+DEqRJQraWYo59jMIPdcnERuHCe4wKdzg1+kmi7DFhelg R7XPoLtbH7pCyVq75ml/4QsU3dxx8VPdS4IcOSKlIwOuPQqKVWQqg3KsTsoFcUzV4XwyzjXaixfIn 1SkOjl+dNuSLeDzMtGDXOJXSOxQM8ZNIJK/NEznoVucjU3VlUGeXow8D2EsSe7RbxTylDxd4+pA/d HB7xWj9Q==; Received: from hch by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kC2Jd-0003cW-VL; Sat, 29 Aug 2020 14:58:50 +0000 Date: Sat, 29 Aug 2020 15:58:49 +0100 From: Christoph Hellwig To: John Hubbard Cc: Andrew Morton , Alexander Viro , Christoph Hellwig , Ilya Dryomov , Jens Axboe , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, LKML Subject: Re: [PATCH v2 2/3] iov_iter: introduce iov_iter_pin_user_pages*() routines Message-ID: <20200829145849.GB12470@infradead.org> References: <20200829080853.20337-1-jhubbard@nvidia.com> <20200829080853.20337-3-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200829080853.20337-3-jhubbard@nvidia.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 29, 2020 at 01:08:52AM -0700, John Hubbard wrote: > The new routines are: > iov_iter_pin_user_pages() > iov_iter_pin_user_pages_alloc() > > and those correspond to these pre-existing routines: > iov_iter_get_pages() > iov_iter_get_pages_alloc() > > Also, pipe_get_pages() and related are changed so as to pass > down a "use_pup" (use pin_user_page() instead of get_page()) bool > argument. > > Unlike the iov_iter_get_pages*() routines, the > iov_iter_pin_user_pages*() routines assert that only ITER_IOVEC or > ITER_PIPE items are passed in. They then call pin_user_page*(), instead > of get_user_pages_fast() or get_page(). > > Why: In order to incrementally change Direct IO callers from calling > get_user_pages_fast() and put_page(), over to calling > pin_user_pages_fast() and unpin_user_page(), there need to be mid-level > routines that specifically call one or the other systems, for both page > acquisition and page release. > > Signed-off-by: John Hubbard > --- > include/linux/uio.h | 5 ++ > lib/iov_iter.c | 110 ++++++++++++++++++++++++++++++++++++++++---- > 2 files changed, 107 insertions(+), 8 deletions(-) > > diff --git a/include/linux/uio.h b/include/linux/uio.h > index 3835a8a8e9ea..29b0504a27cc 100644 > --- a/include/linux/uio.h > +++ b/include/linux/uio.h > @@ -229,6 +229,11 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages); > > const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags); > > +ssize_t iov_iter_pin_user_pages(struct iov_iter *i, struct page **pages, > + size_t maxsize, unsigned int maxpages, size_t *start); > +ssize_t iov_iter_pin_user_pages_alloc(struct iov_iter *i, struct page ***pages, > + size_t maxsize, size_t *start); > + > static inline size_t iov_iter_count(const struct iov_iter *i) > { > return i->count; > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 5e40786c8f12..f25555eb3279 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1269,7 +1269,8 @@ static inline ssize_t __pipe_get_pages(struct iov_iter *i, > size_t maxsize, > struct page **pages, > int iter_head, > - size_t *start) > + size_t *start, > + bool use_pup) > { > struct pipe_inode_info *pipe = i->pipe; > unsigned int p_mask = pipe->ring_size - 1; > @@ -1280,7 +1281,11 @@ static inline ssize_t __pipe_get_pages(struct iov_iter *i, > maxsize = n; > n += *start; > while (n > 0) { > - get_page(*pages++ = pipe->bufs[iter_head & p_mask].page); > + if (use_pup) > + pin_user_page(*pages++ = pipe->bufs[iter_head & p_mask].page); > + else > + get_page(*pages++ = pipe->bufs[iter_head & p_mask].page); Maybe this would become a little more readable with a local variable and a little more verbosity: struct page *page = pipe->bufs[iter_head & p_mask].page; if (use_pup) pin_user_page(page); else get_page(page); *pages++ = page;