Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp741192ybr; Fri, 22 May 2020 18:55:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdp5HvlbD8i7FS69TtiqReIQe89ZQKSyKKRRYt+FWhs4OCava694Qa1B/4Um7xyF3GeaG+ X-Received: by 2002:a17:906:f8d6:: with SMTP id lh22mr10628454ejb.132.1590198939426; Fri, 22 May 2020 18:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590198939; cv=none; d=google.com; s=arc-20160816; b=zBwTkcxJ4HZ9zGno4h7rhfRys9W2KVjdKpXVClrg4XVxgX64fYrDnfuW2wBjdGvMoS WUP2u62MVJXUAvvpk7jdAHWNgv3kYcm6sfInMFJoExvrWLyXIXEJE5mh7x02Ev+TsyF5 dwf+K/EJ70dKZGHkryNOTSSdpTS5icwut3b6t6XBPYmX6EzkJLIcoqt035kxq81M6XKg vOkwS4dBPmmIs1AId6vChrLp32oodC272ahsWOOTcWFzd2I9R5GlIlGSbmciukAyeDHY jD0nMdfTsJR6cdiDcDPEKCFP8K2TaTCPxwLHy4KorxPy07ZW9EzSg7Fugk8bvZYwFiiA oEhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=H0H4bnfmZctAlDk5DLSVcRpTFSw3qTsKUJh0ZTZurr0=; b=vBLXhEiCLoPXogJkpYIE4TKtn/KUrbIrwrAFFh1xQXaZfN9VIrH4wlU7l0cpWZDeNu SDcq5iW14Slww/f0DGvWsVwMLR+eZt0UjgRMsXrjxatJYIYJPMK0l4OAg9CCcSGshufc pnFWGM1CprqqNEm3YnGEELlL8GQu/xs7ksuCNEiEVykWLs4ieog9UzZ3qVAB9pufFUbn s5T0SoNVgT/OWLOBDZq0LgQ6sDc5B01odLH6TTOANKyOjcnh5a/UtTF7O+7dYCL5TLH3 dmlh5PIsvMA+LXjaJ+IJo7kUWfObVr6YWNOj93nY3u6eexXFOeOZvBXgPYGLzw5xvF0z 4VOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=X2SnSaT7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si4303718edx.68.2020.05.22.18.55.16; Fri, 22 May 2020 18:55:39 -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=pass header.i=@nvidia.com header.s=n1 header.b=X2SnSaT7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387662AbgEWBwf (ORCPT + 99 others); Fri, 22 May 2020 21:52:35 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:1583 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387481AbgEWBwf (ORCPT ); Fri, 22 May 2020 21:52:35 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 22 May 2020 18:51:14 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 22 May 2020 18:52:34 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 22 May 2020 18:52:34 -0700 Received: from [10.2.52.1] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 23 May 2020 01:52:34 +0000 Subject: Re: [PATCH v2] fpga: dfl: afu: convert get_user_pages() --> pin_user_pages() To: LKML CC: Xu Yilun , Wu Hao , Moritz Fischer , References: <20200519201449.3136033-1-jhubbard@nvidia.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: <64aa1494-7570-5319-b096-ea354ff20431@nvidia.com> Date: Fri, 22 May 2020 18:52:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200519201449.3136033-1-jhubbard@nvidia.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1590198674; bh=H0H4bnfmZctAlDk5DLSVcRpTFSw3qTsKUJh0ZTZurr0=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=X2SnSaT7Sre/ZYhMC6y2b6BWRFVOldzacF6lVvqQ6bEN1JPnOQM4Pr8en2VFy77DJ bu48Qgw92YsFEu3twD2Zlq5M1hRCuvLBcu8WmT+mPDWqVkfK/lYqqp5hjG16VzwFRt 9aXkfPEVxjvv//sTJZ5f3RQCkNiRMKhbunRzMyNub4PD4hzEGKUAGGDiOcQq3hSKAG LMffZkVrCKRB4ERw+wSd3szU5l07qmea/t20Bolj5+p2z/LqECpvcEPsRwLcO19voP ACBwxvYV0Yrz3KrnfmlljYgoOyFdwSVOH39ctMSHlaqCDqeR75vouuLaLMKn+nHHFD GZPSf0WA92Rcg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-19 13:14, John Hubbard wrote: > This code was using get_user_pages_fast(), in a "Case 2" scenario > (DMA/RDMA), using the categorization from [1]. That means that it's > time to convert the get_user_pages_fast() + put_page() calls to > pin_user_pages_fast() + unpin_user_pages() calls. > > There is some helpful background in [2]: basically, this is a small > part of fixing a long-standing disconnect between pinning pages, and > file systems' use of those pages. > > [1] Documentation/core-api/pin_user_pages.rst > > [2] "Explicit pinning of user-space pages": > https://lwn.net/Articles/807108/ > > Cc: Xu Yilun > Cc: Wu Hao > Cc: Moritz Fischer > Cc: linux-fpga@vger.kernel.org > Signed-off-by: John Hubbard Hi Moritz and FPGA developers, Is this OK? And if so, is it going into your git tree? Or should I send it up through a different tree? (I'm new to the FPGA development model). thanks, -- John Hubbard NVIDIA > --- > > Hi, > > Changes since v1: > > Changed the label from "put_pages", to "unpin_pages". > > thanks, > John Hubbard > NVIDIA > > drivers/fpga/dfl-afu-dma-region.c | 19 +++++-------------- > 1 file changed, 5 insertions(+), 14 deletions(-) > > diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c > index 62f924489db5..a31dd3a7e581 100644 > --- a/drivers/fpga/dfl-afu-dma-region.c > +++ b/drivers/fpga/dfl-afu-dma-region.c > @@ -16,15 +16,6 @@ > > #include "dfl-afu.h" > > -static void put_all_pages(struct page **pages, int npages) > -{ > - int i; > - > - for (i = 0; i < npages; i++) > - if (pages[i]) > - put_page(pages[i]); > -} > - > void afu_dma_region_init(struct dfl_feature_platform_data *pdata) > { > struct dfl_afu *afu = dfl_fpga_pdata_get_private(pdata); > @@ -57,11 +48,11 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, > goto unlock_vm; > } > > - pinned = get_user_pages_fast(region->user_addr, npages, FOLL_WRITE, > + pinned = pin_user_pages_fast(region->user_addr, npages, FOLL_WRITE, > region->pages); > if (pinned < 0) { > ret = pinned; > - goto put_pages; > + goto unpin_pages; > } else if (pinned != npages) { > ret = -EFAULT; > goto free_pages; > @@ -71,8 +62,8 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, > > return 0; > > -put_pages: > - put_all_pages(region->pages, pinned); > +unpin_pages: > + unpin_user_pages(region->pages, pinned); > free_pages: > kfree(region->pages); > unlock_vm: > @@ -94,7 +85,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata, > long npages = region->length >> PAGE_SHIFT; > struct device *dev = &pdata->dev->dev; > > - put_all_pages(region->pages, npages); > + unpin_user_pages(region->pages, npages); > kfree(region->pages); > account_locked_vm(current->mm, npages, false); > >