Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp328468ybl; Mon, 12 Aug 2019 17:20:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqZIMLk/Cr3+UKN8qkldWDxb1lRaPOI9ktj1en7iZYdchXuhN+KVxyFxNNIEK9YTOG7o6t X-Received: by 2002:a17:902:7686:: with SMTP id m6mr35398128pll.239.1565655628822; Mon, 12 Aug 2019 17:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565655628; cv=none; d=google.com; s=arc-20160816; b=UMHpXrfbI3oHo2xbqLHJyZiyJDq7q0UsRF+PApm43sIHueH04h4sFe5a1YVoVZoZXG hmkpbUxZZeIabJl53MwlDyZVrGaNov7EGfbi3vMijOyWxJ5JURJruKtKsJbf8Qsc5jnQ 77htGdXyPlUIvnqsw9wtG4OEKXLq1yFrsgmyrzgvdXC1APda1UzMZ509yPMP48sHR/qa xjo0OjO85flPTUazqaAOkYhPGpAIH7peg9Q8EIZseaEiT+3due72Y6i4inXDxUPWVVjw YwFQEFoaru8VAugIP5vY/xZmX0BR0YrIpppMtIv1E/o6itp5krwmhk33AIoygMuAlx/h uIYA== 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=iX33xR4Yhua2RLrmbI4AIDSh8AXn5QjobWqdqZqQIIY=; b=IElI8XNI6Y8UMcf697ZphGmsndmrtKBxXt/DHQWNCtcftb3LOfpBS8CXqRXh+4N4vb jgM/PmRG6DReAtTKih9vzRmT5LHxZzl8Pjw72w5lzLOxTp781Xj31o2RqA6KoCj3i+sK XYQLjXC0G6eWxFVu+v3WfQa/isB4QjbIn8XHXRgnD5hoDhBHQAh1u5nF3ghVtfXUyLpH DYwJ6ZjqVJEJ4NoVbx9tCqrKhLg0xVxeWOiffPvsBY0b8FkUxpgQEQXQpKqIWGGWiLG/ r18s82TeeGheubEMXHrxk38oMATlxb/fWR/GWlLUxy9dCc1cZ4weSwyD5wds/B7XgXS3 YU/g== 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 j12si64737586pfe.188.2019.08.12.17.20.12; Mon, 12 Aug 2019 17:20:28 -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 S1726882AbfHLXtv (ORCPT + 99 others); Mon, 12 Aug 2019 19:49:51 -0400 Received: from mga05.intel.com ([192.55.52.43]:48708 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbfHLXtv (ORCPT ); Mon, 12 Aug 2019 19:49:51 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2019 16:49:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,379,1559545200"; d="scan'208";a="200305528" Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by fmsmga004.fm.intel.com with ESMTP; 12 Aug 2019 16:49:50 -0700 Date: Mon, 12 Aug 2019 16:49:50 -0700 From: Ira Weiny To: john.hubbard@gmail.com Cc: Andrew Morton , Christoph Hellwig , Dan Williams , Dave Chinner , Jan Kara , Jason Gunthorpe , =?iso-8859-1?B?Suly9G1l?= Glisse , LKML , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-rdma@vger.kernel.org, John Hubbard Subject: Re: [RFC PATCH 2/2] mm/gup: introduce vaddr_pin_pages_remote() Message-ID: <20190812234950.GA6455@iweiny-DESK2.sc.intel.com> References: <20190812015044.26176-1-jhubbard@nvidia.com> <20190812015044.26176-3-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190812015044.26176-3-jhubbard@nvidia.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 Sun, Aug 11, 2019 at 06:50:44PM -0700, john.hubbard@gmail.com wrote: > From: John Hubbard > > This is the "vaddr_pin_pages" corresponding variant to > get_user_pages_remote(), but with FOLL_PIN semantics: the implementation > sets FOLL_PIN. That, in turn, means that the pages must ultimately be > released by put_user_page*()--typically, via vaddr_unpin_pages*(). > > Note that the put_user_page*() requirement won't be truly > required until all of the call sites have been converted, and > the tracking of pages is actually activated. > > Also introduce vaddr_unpin_pages(), in order to have a simpler > call for the error handling cases. > > Use both of these new calls in the Infiniband drive, replacing > get_user_pages_remote() and put_user_pages(). > > Signed-off-by: John Hubbard > --- > drivers/infiniband/core/umem_odp.c | 15 +++++---- > include/linux/mm.h | 7 +++++ > mm/gup.c | 50 ++++++++++++++++++++++++++++++ > 3 files changed, 66 insertions(+), 6 deletions(-) > > diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c > index 53085896d718..fdff034a8a30 100644 > --- a/drivers/infiniband/core/umem_odp.c > +++ b/drivers/infiniband/core/umem_odp.c > @@ -534,7 +534,7 @@ static int ib_umem_odp_map_dma_single_page( > } > > out: > - put_user_page(page); > + vaddr_unpin_pages(&page, 1, &umem_odp->umem.vaddr_pin); > > if (remove_existing_mapping) { > ib_umem_notifier_start_account(umem_odp); > @@ -635,9 +635,10 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt, > * complex (and doesn't gain us much performance in most use > * cases). > */ > - npages = get_user_pages_remote(owning_process, owning_mm, > + npages = vaddr_pin_pages_remote(owning_process, owning_mm, > user_virt, gup_num_pages, > - flags, local_page_list, NULL, NULL); > + flags, local_page_list, NULL, NULL, > + &umem_odp->umem.vaddr_pin); Thinking about this part of the patch... is this pin really necessary? This code is not doing a long term pin. The page just needs a reference while we map it into the devices page tables. Once that is done we should get notifiers if anything changes and we can adjust. right? Ira > up_read(&owning_mm->mmap_sem); > > if (npages < 0) { > @@ -657,7 +658,8 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt, > ret = -EFAULT; > break; > } > - put_user_page(local_page_list[j]); > + vaddr_unpin_pages(&local_page_list[j], 1, > + &umem_odp->umem.vaddr_pin); > continue; > } > > @@ -684,8 +686,9 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt, > * ib_umem_odp_map_dma_single_page(). > */ > if (npages - (j + 1) > 0) > - put_user_pages(&local_page_list[j+1], > - npages - (j + 1)); > + vaddr_unpin_pages(&local_page_list[j+1], > + npages - (j + 1), > + &umem_odp->umem.vaddr_pin); > break; > } > } > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 61b616cd9243..2bd76ad8787e 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1606,6 +1606,13 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, > long vaddr_pin_pages(unsigned long addr, unsigned long nr_pages, > unsigned int gup_flags, struct page **pages, > struct vaddr_pin *vaddr_pin); > +long vaddr_pin_pages_remote(struct task_struct *tsk, struct mm_struct *mm, > + unsigned long start, unsigned long nr_pages, > + unsigned int gup_flags, struct page **pages, > + struct vm_area_struct **vmas, int *locked, > + struct vaddr_pin *vaddr_pin); > +void vaddr_unpin_pages(struct page **pages, unsigned long nr_pages, > + struct vaddr_pin *vaddr_pin); > void vaddr_unpin_pages_dirty_lock(struct page **pages, unsigned long nr_pages, > struct vaddr_pin *vaddr_pin, bool make_dirty); > bool mapping_inode_has_layout(struct vaddr_pin *vaddr_pin, struct page *page); > diff --git a/mm/gup.c b/mm/gup.c > index 85f09958fbdc..bb95adfaf9b6 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2518,6 +2518,38 @@ long vaddr_pin_pages(unsigned long addr, unsigned long nr_pages, > } > EXPORT_SYMBOL(vaddr_pin_pages); > > +/** > + * vaddr_pin_pages pin pages by virtual address and return the pages to the > + * user. > + * > + * @tsk: the task_struct to use for page fault accounting, or > + * NULL if faults are not to be recorded. > + * @mm: mm_struct of target mm > + * @addr: start address > + * @nr_pages: number of pages to pin > + * @gup_flags: flags to use for the pin > + * @pages: array of pages returned > + * @vaddr_pin: initialized meta information this pin is to be associated > + * with. > + * > + * This is the "vaddr_pin_pages" corresponding variant to > + * get_user_pages_remote(), but with FOLL_PIN semantics: the implementation sets > + * FOLL_PIN. That, in turn, means that the pages must ultimately be released > + * by put_user_page(). > + */ > +long vaddr_pin_pages_remote(struct task_struct *tsk, struct mm_struct *mm, > + unsigned long start, unsigned long nr_pages, > + unsigned int gup_flags, struct page **pages, > + struct vm_area_struct **vmas, int *locked, > + struct vaddr_pin *vaddr_pin) > +{ > + gup_flags |= FOLL_TOUCH | FOLL_REMOTE | FOLL_PIN; > + > + return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas, > + locked, gup_flags, vaddr_pin); > +} > +EXPORT_SYMBOL(vaddr_pin_pages_remote); > + > /** > * vaddr_unpin_pages_dirty_lock - counterpart to vaddr_pin_pages > * > @@ -2536,3 +2568,21 @@ void vaddr_unpin_pages_dirty_lock(struct page **pages, unsigned long nr_pages, > __put_user_pages_dirty_lock(vaddr_pin, pages, nr_pages, make_dirty); > } > EXPORT_SYMBOL(vaddr_unpin_pages_dirty_lock); > + > +/** > + * vaddr_unpin_pages - simple, non-dirtying counterpart to vaddr_pin_pages > + * > + * @pages: array of pages returned > + * @nr_pages: number of pages in pages > + * @vaddr_pin: same information passed to vaddr_pin_pages > + * > + * Like vaddr_unpin_pages_dirty_lock, but for non-dirty pages. Useful in putting > + * back pages in an error case: they were never made dirty. > + */ > +void vaddr_unpin_pages(struct page **pages, unsigned long nr_pages, > + struct vaddr_pin *vaddr_pin) > +{ > + __put_user_pages_dirty_lock(vaddr_pin, pages, nr_pages, false); > +} > +EXPORT_SYMBOL(vaddr_unpin_pages); > + > -- > 2.22.0 >