Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4455611ybi; Fri, 19 Jul 2019 23:17:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxLOxM+qW76380XWp0lVaLRTEbAL/nhpgcor7WZEU9M3+lFoZ2YMR/MgCTTJx99czDqoEl X-Received: by 2002:a17:902:20ec:: with SMTP id v41mr57930416plg.142.1563603470928; Fri, 19 Jul 2019 23:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563603470; cv=none; d=google.com; s=arc-20160816; b=AVbqZAqGjHbEsHvIbb55F0aDJ3TstF47e+VUAciFB89fiSulo5BeqSLaxVFIy67AAw 1JGjuPyfYB1CIy+625CTK2pz233PhwX3x1pTgVJqxrVtXdrKsoRccNNCjcJ5CcvthF6q OpSXda0qxfvCsRXD1PW8+2zzRpnYeaoGEL6rjuYu5vVSnaOsn4S2pg5Qj1bFniqjYycC rSj3UzbmGw2ye4rh9QrNLnI71FW8OTnDEEAs8hAlOZKkonddxOnUnXsRJyzIgke/51Z6 JAyDaX7yHBhEdb3oTHSCO3RY24D4qcmMqagnr9KiMRTO+kIjy6aI3zZy67eWsGUX2a5M CvuQ== 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=lRODC3picM28oK/N+bZmg6JsfRLb3g94XTeELCxYE9E=; b=OelQcZsSP3g0KBlupvL5u3MtJf254/lE6A6mPEDcE3+f1XCyVAWOmMGidX4ox3gLzd C2YQPRBvihmgvHYl9ORm/ocwyKWGmiMrcbGkWuYpEK9qvOeSaIpnT3fsXPvWWSq+t5U7 EfdME/Zs12nM/tN4yenenuAEVZX6aYUoB90cqmDxz9wur5RqKSMN8S/ywG+5e73yNAXu /h6JEEyAC1i2ECuaRPKvKttqAIvhKCKas3bVNxp8yjFiMZv2JZqE20xZeneeDd5dn+Yn u9OEjIKplyX7yDPvhukNPlEJQOPADsxfvf1vgcJcunZUiYWfKlQB9kBXW5YDDTEdaC1a WHnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=eh7z35pl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si4420835pld.293.2019.07.19.23.17.28; Fri, 19 Jul 2019 23:17:50 -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; dkim=pass header.i=@nvidia.com header.s=n1 header.b=eh7z35pl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731031AbfGSV2m (ORCPT + 99 others); Fri, 19 Jul 2019 17:28:42 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:10689 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727603AbfGSV2m (ORCPT ); Fri, 19 Jul 2019 17:28:42 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 19 Jul 2019 14:28:47 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 19 Jul 2019 14:28:40 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 19 Jul 2019 14:28:40 -0700 Received: from [10.110.48.28] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 19 Jul 2019 21:28:39 +0000 Subject: Re: [PATCH v3] staging: kpc2000: Convert put_page to put_user_page*() To: Bharath Vedartham , , , , CC: , , References: <20190719200235.GA16122@bharath12345-Inspiron-5559> From: John Hubbard X-Nvconfidentiality: public Message-ID: <8bce5bb2-d9a5-13f1-7d96-27c41057c519@nvidia.com> Date: Fri, 19 Jul 2019 14:28:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190719200235.GA16122@bharath12345-Inspiron-5559> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1563571727; bh=lRODC3picM28oK/N+bZmg6JsfRLb3g94XTeELCxYE9E=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=eh7z35plcsPz2hXb3Vk4ijLn+kjkYXp+kqQFis1UItWfeWWiWslIgna9z74j23y1w Q5p6kMUgK3kxxE8yrzxJl2oBaGhP9lCWpVzDjx4J5U5L3MJoptfnfFPQsrvKnItylr PaHNMghL3+oV9IGu+ITEooZjRac6iWut/8/G49SifFyn122eXOjrBtnNYVLFY/gm6f EtFa/wQZRe+RD/FLtg+ySaGSf+Coykpae7dfsLZeZZRfDfC6LbXl9Ivt3NWswUdCGa U6cdxk1zFeTxoxJkn2DubtUFF2Xml0o6HHUyuFezCwIqOEVQiD2+22q1Z1X43yos/c bY5hUBHzHbByg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/19/19 1:02 PM, Bharath Vedartham wrote: > There have been issues with coordination of various subsystems using > get_user_pages. These issues are better described in [1]. >=20 > An implementation of tracking get_user_pages is currently underway > The implementation requires the use put_user_page*() variants to release > a reference rather than put_page(). The commit that introduced > put_user_pages, Commit fc1d8e7cca2daa18d2fe56b94874848adf89d7f5 ("mm: int= roduce > put_user_page*(), placeholder version"). >=20 > The implementation currently simply calls put_page() within > put_user_page(). But in the future, it is to change to add a mechanism > to keep track of get_user_pages. Once a tracking mechanism is > implemented, we can make attempts to work on improving on coordination > between various subsystems using get_user_pages. >=20 > [1] https://lwn.net/Articles/753027/ Optional: I've been fussing about how to keep the change log reasonable, and finally came up with the following recommended template for these=20 conversion patches. This would replace the text you have above, because the= =20 put_user_page placeholder commit has all the documentation (and then some)= =20 that we need: For pages that were retained via get_user_pages*(), release those pages via the new put_user_page*() routines, instead of via put_page(). This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions"). For the change itself, you will need to rebase it onto the latest=20 linux.git, as it doesn't quite apply there.=20 Testing is good if we can get it, but as far as I can tell this is correct, so you can also add: Reviewed-by: John Hubbard thanks, --=20 John Hubbard NVIDIA >=20 > Cc: Ira Weiny > Cc: John Hubbard > Cc: J=C3=A9r=C3=B4me Glisse > Cc: Greg Kroah-Hartman > Cc: Matt Sickler > Cc: devel@driverdev.osuosl.org=20 > Cc: linux-kernel@vger.kernel.org > Cc: linux-mm@kvack.org > Signed-off-by: Bharath Vedartham > --- > Changes since v1 > - Improved changelog by John's suggestion. > - Moved logic to dirty pages below sg_dma_unmap > and removed PageReserved check. > Changes since v2 > - Added back PageResevered check as suggested by John Hubbard. > =09 > The PageReserved check needs a closer look and is not worth messing > around with for now. >=20 > Matt, Could you give any suggestions for testing this patch? > =20 > If in-case, you are willing to pick this up to test. Could you > apply this patch to this tree > https://github.com/johnhubbard/linux/tree/gup_dma_core > and test it with your devices? >=20 > --- > drivers/staging/kpc2000/kpc_dma/fileops.c | 17 ++++++----------- > 1 file changed, 6 insertions(+), 11 deletions(-) >=20 > diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/= kpc2000/kpc_dma/fileops.c > index 6166587..75ad263 100644 > --- a/drivers/staging/kpc2000/kpc_dma/fileops.c > +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c > @@ -198,9 +198,7 @@ int kpc_dma_transfer(struct dev_private_data *priv, = struct kiocb *kcb, unsigned > sg_free_table(&acd->sgt); > err_dma_map_sg: > err_alloc_sg_table: > - for (i =3D 0 ; i < acd->page_count ; i++){ > - put_page(acd->user_pages[i]); > - } > + put_user_pages(acd->user_pages, acd->page_count); > err_get_user_pages: > kfree(acd->user_pages); > err_alloc_userpages: > @@ -221,16 +219,13 @@ void transfer_complete_cb(struct aio_cb_data *acd,= size_t xfr_count, u32 flags) > =09 > dev_dbg(&acd->ldev->pldev->dev, "transfer_complete_cb(acd =3D [%p])\n",= acd); > =09 > - for (i =3D 0 ; i < acd->page_count ; i++){ > - if (!PageReserved(acd->user_pages[i])){ > - set_page_dirty(acd->user_pages[i]); > - } > - } > -=09 > dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd-= >ldev->dir); > =09 > - for (i =3D 0 ; i < acd->page_count ; i++){ > - put_page(acd->user_pages[i]); > + for (i =3D 0; i < acd->page_count; i++) { > + if (!PageReserved(acd->user_pages[i])) > + put_user_pages_dirty(&acd->user_pages[i], 1); > + else > + put_user_page(acd->user_pages[i]); > } > =09 > sg_free_table(&acd->sgt); >=20