From patchwork Tue Nov 21 23:11:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 10069029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B34E9602B7 for ; Tue, 21 Nov 2017 23:11:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 907EA29A43 for ; Tue, 21 Nov 2017 23:11:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82A7F29A4D; Tue, 21 Nov 2017 23:11:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DBFCC29A43 for ; Tue, 21 Nov 2017 23:11:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B54782035BB3A; Tue, 21 Nov 2017 15:07:01 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=akpm@linux-foundation.org; receiver=linux-nvdimm@lists.01.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7A22221B00DC1 for ; Tue, 21 Nov 2017 15:07:00 -0800 (PST) Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B592E9F0; Tue, 21 Nov 2017 23:11:15 +0000 (UTC) Date: Tue, 21 Nov 2017 15:11:14 -0800 From: Andrew Morton To: Dan Williams Subject: Re: [PATCH v2 1/4] mm: introduce get_user_pages_longterm Message-Id: <20171121151114.de95a3eb730ce602e52e891d@linux-foundation.org> In-Reply-To: <151068939435.7446.13560129395419350737.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151068938905.7446.12333914805308312313.stgit@dwillia2-desk3.amr.corp.intel.com> <151068939435.7446.13560129395419350737.stgit@dwillia2-desk3.amr.corp.intel.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Christoph Hellwig Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 14 Nov 2017 11:56:34 -0800 Dan Williams wrote: > Until there is a solution to the dma-to-dax vs truncate problem it is > not safe to allow long standing memory registrations against > filesytem-dax vmas. Device-dax vmas do not have this problem and are > explicitly allowed. > > This is temporary until a "memory registration with layout-lease" > mechanism can be implemented for the affected sub-systems (RDMA and > V4L2). > > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1095,6 +1095,70 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, > } > EXPORT_SYMBOL(get_user_pages); > > +#ifdef CONFIG_FS_DAX > +/* > + * This is the same as get_user_pages() in that it assumes we are > + * operating on the current task's mm, but it goes further to validate > + * that the vmas associated with the address range are suitable for > + * longterm elevated page reference counts. For example, filesystem-dax > + * mappings are subject to the lifetime enforced by the filesystem and > + * we need guarantees that longterm users like RDMA and V4L2 only > + * establish mappings that have a kernel enforced revocation mechanism. > + * > + * "longterm" == userspace controlled elevated page count lifetime. > + * Contrast this to iov_iter_get_pages() usages which are transient. > + */ > +long get_user_pages_longterm(unsigned long start, unsigned long nr_pages, > + unsigned int gup_flags, struct page **pages, > + struct vm_area_struct **vmas_arg) > +{ > + struct vm_area_struct **vmas = vmas_arg; > + struct vm_area_struct *vma_prev = NULL; > + long rc, i; > + > + if (!pages) > + return -EINVAL; > + > + if (!vmas) { > + vmas = kzalloc(sizeof(struct vm_area_struct *) * nr_pages, > + GFP_KERNEL); > + if (!vmas) > + return -ENOMEM; > + } > > ... > I'll do this: --- a/mm/gup.c~mm-introduce-get_user_pages_longterm-fix +++ a/mm/gup.c @@ -1120,8 +1120,8 @@ long get_user_pages_longterm(unsigned lo return -EINVAL; if (!vmas) { - vmas = kzalloc(sizeof(struct vm_area_struct *) * nr_pages, - GFP_KERNEL); + vmas = kcalloc(nr_pages, sizeof(struct vm_area_struct *), + GFP_KERNEL); if (!vmas) return -ENOMEM; }