Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4731893ybi; Mon, 15 Jul 2019 13:53:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqynVgtFl6pEaFPWhkc4PCZltvPF3gsMz/Cbr5rHmbe3BQhx5Vx6alYfPrLH3yETrI6t/kWw X-Received: by 2002:a65:6102:: with SMTP id z2mr28733180pgu.391.1563224001850; Mon, 15 Jul 2019 13:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563224001; cv=none; d=google.com; s=arc-20160816; b=p7v2qwNz8B3Ge3cHeEnGw0DOXRgNV2ugy25JOXqdqhgL7gLiawDYo9nO1bUsyNWwv9 h7PYhzABxcldD5Dlw9nPtcr+5rBp42HuNP8DIJtrpWyUE3LXsOdhP/Bn0MSYB7YLlQyd nyejmOfpSsoWqLtTNInsSeKinG1vmUoHp/FgS71kFiG7arr1hPiX2ETzUIO0RMqCgxMS o5t+vaG1svGXwlSWPUDYXJNHeBZ025OWuK1riodznrB/k4zhEhAcqtIcnmRoBHjyhW80 Vnf0P6qsFfWI0+4yS3M7de8mlvLDC9IFUHhOT473j3RVUBsBGkZvH8TGUO4VAYL1Zlz4 ExtA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kR4xbKeLkqzM5m4IkfGOvFM7+dvSxhNFEJ7oNVJrvqQ=; b=hY9HvF6C6yOEEr8aI+09X9yINBkCPQ8TebTJa6m7ubzdI2zFJEKb3qVQd/OeRm7ULB JG5u1NgS48Lyj3SULBhlbfjunFh8gtI+Z+0JKe9QrlnOtmPZMyFNbafaCUC6XsAuuXt2 9BtIScataRkB8s6xmFQC4K4Uu2Bg4NzYq5Pnh4CcKILB/dhizz4c7IZfoLiFhqUX7knU gDicNUboD9j64u68acAeRMBaRAu5+6c3mB27UoZtJl6sHvYDNJZtFg6Z4YxcxUKOWu99 S9dmF6k22b5R9Rij7N15cyp+FZrZczeyoaHlUM7ioKLqBQOTkvRNU043UAnIij9WWZ8L D3bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vRaErLWa; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si15863373plk.225.2019.07.15.13.53.00; Mon, 15 Jul 2019 13:53:21 -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=@gmail.com header.s=20161025 header.b=vRaErLWa; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732578AbfGOUw1 (ORCPT + 99 others); Mon, 15 Jul 2019 16:52:27 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:35295 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729640AbfGOUw0 (ORCPT ); Mon, 15 Jul 2019 16:52:26 -0400 Received: by mail-pl1-f194.google.com with SMTP id w24so8908301plp.2 for ; Mon, 15 Jul 2019 13:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=kR4xbKeLkqzM5m4IkfGOvFM7+dvSxhNFEJ7oNVJrvqQ=; b=vRaErLWauN0PK2S1rhodMt5sJ3WgJaXgnY2tZZxt8XarHR9jtlCcHgwbau1887Ce6V wPwnxhzyeoa24uBZQy/lPcYwOxNYpnCjVZOAYrzllp8Jyldk5UMiNAkuK/5gILgpL7zT I/+OhYEkG4eAPKGLBzTMxMuui60/CxzsYA7S+G0SNSSHgkuqThYPYFSErYnVpHXbHOzs 96nqyqsVFaFugyW+U8nFSigdHjuizyEtOxUb+POScUYS3z3JezDsjI6snDDWhsHxK8Bx GtaT0Zy5clHx4yrkJBeaMpdOrIW6qz1NzJ+5xML90nBEkDt+FTMB1wts3Bf9xRU/tdHX b0hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=kR4xbKeLkqzM5m4IkfGOvFM7+dvSxhNFEJ7oNVJrvqQ=; b=OUKrrB3K7Txlu/CFEOvrqhX67maugFtA8JC5qrueKje05nWZ/XT6Xt5JGq0mKcs6Ms /iUIjVtX2d7doB3+CwfwZuc0WlU3h4ZZJ8XDw+RtATXHqBpgnuManMV0+5R13m0F6T9o 5k2mp6tpMw7xUgvMR7kMezNy8sdxqPiW55VMBpBGXsjXB/kTf3JjdssIZqup7jNlXfVp innrLh+9fT/Xn51OIf4td/8rB6IQVZXTMHVFQ7bTSCqssFl8F5EzGLIsSu23Rnl7NQB9 B802dyQ9n4631rZnwKNnsRYXWEbTI6JZIEBeojvDIPsEE72l4Bx3evQtbvzh8qxSSVO1 ZtAw== X-Gm-Message-State: APjAAAW2ubjaKHrIfdoFMcfXB7XCAKHdQvHxuZxo6q5c7v+jhFm6sw1o t2FNAJWWqm/PLtLEgh1tLYc= X-Received: by 2002:a17:902:4c88:: with SMTP id b8mr31598648ple.29.1563223945760; Mon, 15 Jul 2019 13:52:25 -0700 (PDT) Received: from bharath12345-Inspiron-5559 ([103.110.42.33]) by smtp.gmail.com with ESMTPSA id 185sm22172155pfa.170.2019.07.15.13.52.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 13:52:25 -0700 (PDT) Date: Tue, 16 Jul 2019 02:22:16 +0530 From: Bharath Vedartham To: John Hubbard Cc: ira.weiny@intel.com, gregkh@linuxfoundation.org, Matt.Sickler@daktronics.com, jglisse@redhat.com, devel@driverdev.osuosl.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*() Message-ID: <20190715205216.GD21161@bharath12345-Inspiron-5559> References: <20190715195248.GA22495@bharath12345-Inspiron-5559> <2604fcd1-4829-d77e-9f7c-d4b731782ff9@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2604fcd1-4829-d77e-9f7c-d4b731782ff9@nvidia.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 15, 2019 at 01:14:13PM -0700, John Hubbard wrote: > 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]. > > > > The solution being proposed wants to keep track of gup_pinned pages which will allow to take furthur steps to coordinate between subsystems using gup. > > > > put_user_page() simply calls put_page inside for now. But the implementation will change once all call sites of put_page() are converted. > > > > 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 patch, 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: Will fix that in the next version. > > > > [1] https://lwn.net/Articles/753027/ > > [2] https://github.com/johnhubbard/linux/tree/gup_dma_core > > > > Cc: Matt Sickler > > Cc: Greg Kroah-Hartman > > Cc: J?r?me Glisse > > Cc: Ira Weiny > > Cc: John Hubbard > > Cc: linux-mm@kvack.org > > Cc: devel@driverdev.osuosl.org > > > > Signed-off-by: Bharath Vedartham > > --- > > drivers/staging/kpc2000/kpc_dma/fileops.c | 8 ++------ > > 1 file changed, 2 insertions(+), 6 deletions(-) > > > > 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 = 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, size_t xfr_count, u32 flags) > > > > dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd->ldev->dir); > > > > - for (i = 0 ; i < acd->page_count ; i++){ > > - put_page(acd->user_pages[i]); > > - } > > + put_user_pages(acd->user_pages, acd->page_count); > > > > sg_free_table(&acd->sgt); > > > > > > 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/kpc2000/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, size_t xfr_count, u32 flags) > BUG_ON(acd->ldev == NULL); > BUG_ON(acd->ldev->pldev == NULL); > > - for (i = 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); > > for (i = 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]); > } > > sg_free_table(&acd->sgt); I had my doubts on this. This definitley needs to be looked at by the driver author. > Assuming that you make those two changes, you can add: > > Reviewed-by: John Hubbard Great! > > thanks, > -- > John Hubbard > NVIDIA