Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4699369ybi; Mon, 15 Jul 2019 13:15:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyInnpBYS2iQDtCPnr23kAl6hRII2GDdwJQRXtsq+Y0NsNSOnwdYMNehCFdM63mRce0lpRX X-Received: by 2002:a63:494d:: with SMTP id y13mr29359890pgk.109.1563221742400; Mon, 15 Jul 2019 13:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563221742; cv=none; d=google.com; s=arc-20160816; b=A4S2YzGI0RbSemPjKLX33Z4bABNtYiYY8dexU38rh85BmkhdiHEUo9VjxCVt4XZX1E BRbZmnvXLzRtIpGqw9pJACz3G7GW7Y62rYLMzpR7Osn9+mifXEVunoy7pskcTgTKtoKA Lb6mBXgToKqzn4YohBCXtRJo8940VoLnUcKkvKT7mJpWW5kEwtRGs0DLUnwoho0MkqnP LZm27MeYsNgy5S/pP/XN3a3wU84nHUBkFn8FSDOpc0HYOPWLnwTrnIdqeSzeYNpHLLsR WO/l5wvKFiVDsdgujVR0fAlHXNMIGEH3UhADrigKoE+ORaXTzes7S4DcJV+JI2U//c2+ ADkA== 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=BMxYmaxLZP+7xtagiq4XdrfPFrAjpdxkuCAPEb6M/YE=; b=OH/XhNjsXCSXGgV8mEfDF7Ajesy5/Cp/vh9Y2eerI7R86SPfaCBlAOeLbwNw8TLytZ t3X+zrh6Bc9/5xZRVy6/YMmJUD2dw2N8KS3Ifj++cMreDWPaochZekD0yLk6/JlRosmG zP8CNSGfhEm/QJ17bRC6Kdmwj61CVjURKRNXWnQ3xlROkGMFnryybIf+y20jq4rVnLc3 n8laGkNTLK7ZX+w5wvQPcf1BveQu5YsfwwisQiJbcR1YnAwC3nwJknYtoNMlCC7R+l7L DxgnQqei7jeG86Bm5iiKNF7AeD/xeRcNh+jjFZYBUEpeGuGtdDy2Ec8tuu7n+3VyRK24 E0FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=WAapHeWX; 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 y134si17067001pfc.285.2019.07.15.13.15.26; Mon, 15 Jul 2019 13:15:42 -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=WAapHeWX; 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 S1732433AbfGOUOQ (ORCPT + 99 others); Mon, 15 Jul 2019 16:14:16 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:3041 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730937AbfGOUOQ (ORCPT ); Mon, 15 Jul 2019 16:14:16 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 15 Jul 2019 13:14:20 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 15 Jul 2019 13:14:14 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 15 Jul 2019 13:14:14 -0700 Received: from [10.110.48.28] (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 15 Jul 2019 20:14:13 +0000 Subject: Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*() To: Bharath Vedartham , , , , CC: , , References: <20190715195248.GA22495@bharath12345-Inspiron-5559> From: John Hubbard X-Nvconfidentiality: public Message-ID: <2604fcd1-4829-d77e-9f7c-d4b731782ff9@nvidia.com> Date: Mon, 15 Jul 2019 13:14:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190715195248.GA22495@bharath12345-Inspiron-5559> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL106.nvidia.com (172.18.146.12) 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=1563221660; bh=BMxYmaxLZP+7xtagiq4XdrfPFrAjpdxkuCAPEb6M/YE=; 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=WAapHeWXmLTyRYz3wNyClC6+13efTzwE10OPt/TU6UzVEhQ95SBC2gyGzhQSq8HzY jif7L106RMFBSUgWWTTOtKHY++BEoNDNqfzgiSakBgXQz7mrzurCeo5LnBL3cdHTdW 9UQh4CqliZkdYkplEcYXuJba0rR+7so4j/xBe+8jAIUwoYBK4II+W8f3W9W3kmLAMs r7cbHtFee6QReJJdSABcP7vtaZ2aA/L9fceZ+vtVh/8yr0Q/NujtUzQQnfJB33iZWA VUOTM6zOa03ibnytuPQvgFn80smv0LT15Q3+mUhiPpZjESiU6lD7H4cdBJJjkE2sEO ovaCokkakfJiQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/15/19 12:52 PM, Bharath Vedartham wrote: > There have been issues with get_user_pages and filesystem writeback. > The issues are better described in [1]. >=20 > The solution being proposed wants to keep track of gup_pinned pages which= will allow to take furthur steps to coordinate between subsystems using gu= p. >=20 > put_user_page() simply calls put_page inside for now. But the implementat= ion will change once all call sites of put_page() are converted. >=20 > I currently do not have the driver to test. Could I have some suggestions= to test this code? The solution is currently implemented in [2] and > it would be great if we could apply the patch on top of [2] and run some = tests to check if any regressions occur. Hi Bharath, Process point: the above paragraph, and other meta-questions (about the pat= ch, rather than part of the patch) should be placed either after the "---",= or in a cover letter (git-send-email --cover-letter). That way, the patch = itself is in a commit-able state. One more below: >=20 > [1] https://lwn.net/Articles/753027/ > [2] https://github.com/johnhubbard/linux/tree/gup_dma_core >=20 > Cc: Matt Sickler > Cc: Greg Kroah-Hartman > Cc: J=C3=A9r=C3=B4me Glisse > Cc: Ira Weiny > Cc: John Hubbard > Cc: linux-mm@kvack.org > Cc: devel@driverdev.osuosl.org >=20 > Signed-off-by: Bharath Vedartham > --- > drivers/staging/kpc2000/kpc_dma/fileops.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/= kpc2000/kpc_dma/fileops.c > index 6166587..82c70e6 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: > @@ -229,9 +227,7 @@ void transfer_complete_cb(struct aio_cb_data *acd, s= ize_t xfr_count, u32 flags) > =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]); > - } > + put_user_pages(acd->user_pages, acd->page_count); > =09 > sg_free_table(&acd->sgt); > =09 >=20 Because this is a common pattern, and because the code here doesn't likely = need to set page dirty before the dma_unmap_sg call, I think the following = would be better (it's untested), instead of the above diff hunk: diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kp= c2000/kpc_dma/fileops.c index 48ca88bc6b0b..d486f9866449 100644 --- a/drivers/staging/kpc2000/kpc_dma/fileops.c +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c @@ -211,16 +211,13 @@ void transfer_complete_cb(struct aio_cb_data *acd, s= ize_t xfr_count, u32 flags) BUG_ON(acd->ldev =3D=3D NULL); BUG_ON(acd->ldev->pldev =3D=3D NULL); =20 - for (i =3D 0 ; i < acd->page_count ; i++) { - if (!PageReserved(acd->user_pages[i])) { - set_page_dirty(acd->user_pages[i]); - } - } - dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, = acd->ldev->dir); =20 for (i =3D 0 ; i < acd->page_count ; i++) { - put_page(acd->user_pages[i]); + if (!PageReserved(acd->user_pages[i])) { + put_user_pages_dirty(&acd->user_pages[i], 1); + else + put_user_page(acd->user_pages[i]); } =20 sg_free_table(&acd->sgt); Assuming that you make those two changes, you can add: Reviewed-by: John Hubbard thanks, --=20 John Hubbard NVIDIA