mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: boris.ostrovsky@oracle.com
To: Souptick Joarder <jrdr.linux@gmail.com>,
	jgross@suse.com, sstabellini@kernel.org
Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
	John Hubbard <jhubbard@nvidia.com>
Subject: Re: [RFC PATCH] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
Date: Wed, 19 Aug 2020 20:26:31 -0400	[thread overview]
Message-ID: <82366a3d-db55-68eb-7f29-935b511dace4@oracle.com> (raw)
In-Reply-To: <1597725140-8310-1-git-send-email-jrdr.linux@gmail.com>


On 8/18/20 12:32 AM, Souptick Joarder wrote:
> In 2019, we introduced pin_user_pages*() and now we are converting
> get_user_pages*() to the new API as appropriate. [1] & [2] could
> be referred for more information. This is case 5 as per document [1].
>
> [1] Documentation/core-api/pin_user_pages.rst
>
> [2] "Explicit pinning of user-space pages":
>         https://lwn.net/Articles/807108/
>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> ---
>  drivers/xen/gntdev.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
> index 64a9025a..e480509 100644
> --- a/drivers/xen/gntdev.c
> +++ b/drivers/xen/gntdev.c
> @@ -730,7 +730,7 @@ static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt,
>  	unsigned long xen_pfn;
>  	int ret;
>  
> -	ret = get_user_pages_fast(addr, 1, writeable ? FOLL_WRITE : 0, &page);
> +	ret = pin_user_pages_fast(addr, 1, writeable ? FOLL_WRITE : 0, &page);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -744,10 +744,7 @@ static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt,
>  
>  static void gntdev_put_pages(struct gntdev_copy_batch *batch)
>  {
> -	unsigned int i;
> -
> -	for (i = 0; i < batch->nr_pages; i++)
> -		put_page(batch->pages[i]);
> +	unpin_user_pages(batch->pages, batch->nr_pages);


There seems to be a bug in the original code (just like there was in
privcmd.c that you fixed earlier) --- when gntdev_get_page() is called
with writeable=true then the page needs to be marked dirty before being
put.


You can add a `bool writeable` to gntdev_copy_batch and set it in
gntdev_grant_copy_seg() (and drop `writeable` argument to
gntdev_get_page()) and then, based on batch->writeable, use either
unpin_user_pages() or unpin_user_pages_dirty_lock().


(But to fix this in stable branches please make first patch call
set_page_dirty_lock() for each page like you did in previous series)


-boris


>  	batch->nr_pages = 0;
>  }
>  

      reply	other threads:[~2020-08-20  0:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18  4:32 Souptick Joarder
2020-08-20  0:26 ` boris.ostrovsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82366a3d-db55-68eb-7f29-935b511dace4@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=jhubbard@nvidia.com \
    --cc=jrdr.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®