linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] xen/gntdev.c: Mark pages as dirty
@ 2020-09-06  6:51 Souptick Joarder
  2020-09-06  6:51 ` [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*() Souptick Joarder
  2020-09-11 14:41 ` [PATCH 1/2] xen/gntdev.c: Mark pages as dirty boris.ostrovsky
  0 siblings, 2 replies; 8+ messages in thread
From: Souptick Joarder @ 2020-09-06  6:51 UTC (permalink / raw)
  To: boris.ostrovsky, jgross, sstabellini, david.vrabel
  Cc: xen-devel, linux-kernel, Souptick Joarder, John Hubbard

There seems to be a bug in the original code when gntdev_get_page()
is called with writeable=true then the page needs to be marked dirty
before being put.

To address this, a bool writeable is added in gnt_dev_copy_batch, set
it in gntdev_grant_copy_seg() (and drop `writeable` argument to
gntdev_get_page()) and then, based on batch->writeable, use
set_page_dirty_lock().

Fixes: a4cdb556cae0 (xen/gntdev: add ioctl for grant copy)
Suggested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/gntdev.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 64a9025a..5e1411b 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -720,17 +720,18 @@ struct gntdev_copy_batch {
 	s16 __user *status[GNTDEV_COPY_BATCH];
 	unsigned int nr_ops;
 	unsigned int nr_pages;
+	bool writeable;
 };
 
 static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt,
-			   bool writeable, unsigned long *gfn)
+				unsigned long *gfn)
 {
 	unsigned long addr = (unsigned long)virt;
 	struct page *page;
 	unsigned long xen_pfn;
 	int ret;
 
-	ret = get_user_pages_fast(addr, 1, writeable ? FOLL_WRITE : 0, &page);
+	ret = get_user_pages_fast(addr, 1, batch->writeable ? FOLL_WRITE : 0, &page);
 	if (ret < 0)
 		return ret;
 
@@ -746,9 +747,13 @@ static void gntdev_put_pages(struct gntdev_copy_batch *batch)
 {
 	unsigned int i;
 
-	for (i = 0; i < batch->nr_pages; i++)
+	for (i = 0; i < batch->nr_pages; i++) {
+		if (batch->writeable && !PageDirty(batch->pages[i]))
+			set_page_dirty_lock(batch->pages[i]);
 		put_page(batch->pages[i]);
+	}
 	batch->nr_pages = 0;
+	batch->writeable = false;
 }
 
 static int gntdev_copy(struct gntdev_copy_batch *batch)
@@ -837,8 +842,9 @@ static int gntdev_grant_copy_seg(struct gntdev_copy_batch *batch,
 			virt = seg->source.virt + copied;
 			off = (unsigned long)virt & ~XEN_PAGE_MASK;
 			len = min(len, (size_t)XEN_PAGE_SIZE - off);
+			batch->writeable = false;
 
-			ret = gntdev_get_page(batch, virt, false, &gfn);
+			ret = gntdev_get_page(batch, virt, &gfn);
 			if (ret < 0)
 				return ret;
 
@@ -856,8 +862,9 @@ static int gntdev_grant_copy_seg(struct gntdev_copy_batch *batch,
 			virt = seg->dest.virt + copied;
 			off = (unsigned long)virt & ~XEN_PAGE_MASK;
 			len = min(len, (size_t)XEN_PAGE_SIZE - off);
+			batch->writeable = true;
 
-			ret = gntdev_get_page(batch, virt, true, &gfn);
+			ret = gntdev_get_page(batch, virt, &gfn);
 			if (ret < 0)
 				return ret;
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-06  6:51 [PATCH 1/2] xen/gntdev.c: Mark pages as dirty Souptick Joarder
@ 2020-09-06  6:51 ` Souptick Joarder
  2020-09-11 14:42   ` boris.ostrovsky
  2020-09-11 14:41 ` [PATCH 1/2] xen/gntdev.c: Mark pages as dirty boris.ostrovsky
  1 sibling, 1 reply; 8+ messages in thread
From: Souptick Joarder @ 2020-09-06  6:51 UTC (permalink / raw)
  To: boris.ostrovsky, jgross, sstabellini, david.vrabel
  Cc: xen-devel, linux-kernel, Souptick Joarder, John Hubbard

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>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/gntdev.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 5e1411b..a36b712 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -731,7 +731,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, batch->writeable ? FOLL_WRITE : 0, &page);
+	ret = pin_user_pages_fast(addr, 1, batch->writeable ? FOLL_WRITE : 0, &page);
 	if (ret < 0)
 		return ret;
 
@@ -745,13 +745,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++) {
-		if(batch->writeable && !PageDirty(batch->pages[i]))
-			set_page_dirty_lock(batch->pages[i]);
-		put_page(batch->pages[i]);
-	}
+	unpin_user_pages_dirty_lock(batch->pages, batch->nr_pages, batch->writeable);
 	batch->nr_pages = 0;
 	batch->writeable = false;
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] xen/gntdev.c: Mark pages as dirty
  2020-09-06  6:51 [PATCH 1/2] xen/gntdev.c: Mark pages as dirty Souptick Joarder
  2020-09-06  6:51 ` [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*() Souptick Joarder
@ 2020-09-11 14:41 ` boris.ostrovsky
  1 sibling, 0 replies; 8+ messages in thread
From: boris.ostrovsky @ 2020-09-11 14:41 UTC (permalink / raw)
  To: Souptick Joarder, jgross, sstabellini
  Cc: xen-devel, linux-kernel, John Hubbard, stable


On 9/6/20 2:51 AM, Souptick Joarder wrote:
> There seems to be a bug in the original code when gntdev_get_page()
> is called with writeable=true then the page needs to be marked dirty
> before being put.
>
> To address this, a bool writeable is added in gnt_dev_copy_batch, set
> it in gntdev_grant_copy_seg() (and drop `writeable` argument to
> gntdev_get_page()) and then, based on batch->writeable, use
> set_page_dirty_lock().
>
> Fixes: a4cdb556cae0 (xen/gntdev: add ioctl for grant copy)
> Suggested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: David Vrabel <david.vrabel@citrix.com>


Cc: stable@vger.kernel.org

(can be added at commit time)

Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-06  6:51 ` [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*() Souptick Joarder
@ 2020-09-11 14:42   ` boris.ostrovsky
  2020-09-29 12:09     ` Souptick Joarder
  0 siblings, 1 reply; 8+ messages in thread
From: boris.ostrovsky @ 2020-09-11 14:42 UTC (permalink / raw)
  To: Souptick Joarder, jgross, sstabellini
  Cc: xen-devel, linux-kernel, John Hubbard


On 9/6/20 2:51 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>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: David Vrabel <david.vrabel@citrix.com>


Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-11 14:42   ` boris.ostrovsky
@ 2020-09-29 12:09     ` Souptick Joarder
  2020-09-29 12:30       ` boris.ostrovsky
  0 siblings, 1 reply; 8+ messages in thread
From: Souptick Joarder @ 2020-09-29 12:09 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: Juergen Gross, sstabellini, xen-devel, linux-kernel, John Hubbard

On Fri, Sep 11, 2020 at 8:12 PM <boris.ostrovsky@oracle.com> wrote:
>
>
> On 9/6/20 2:51 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>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: Juergen Gross <jgross@suse.com>
> > Cc: David Vrabel <david.vrabel@citrix.com>
>
>
> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

Are these 2 patches queued for 5.10-rc1 ?
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-29 12:09     ` Souptick Joarder
@ 2020-09-29 12:30       ` boris.ostrovsky
  2020-09-30  2:14         ` Souptick Joarder
  0 siblings, 1 reply; 8+ messages in thread
From: boris.ostrovsky @ 2020-09-29 12:30 UTC (permalink / raw)
  To: Souptick Joarder
  Cc: Juergen Gross, sstabellini, xen-devel, linux-kernel, John Hubbard


On 9/29/20 8:09 AM, Souptick Joarder wrote:
> On Fri, Sep 11, 2020 at 8:12 PM <boris.ostrovsky@oracle.com> wrote:
>>
>> On 9/6/20 2:51 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>
>>> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>>> Cc: Juergen Gross <jgross@suse.com>
>>> Cc: David Vrabel <david.vrabel@citrix.com>
>>
>> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Are these 2 patches queued for 5.10-rc1 ?


Yes, I am preparing the branch. (BTW, your second patch appears to have been either manually edited or not generated on top of the first patch. Please don't do this next time)


-boris


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-29 12:30       ` boris.ostrovsky
@ 2020-09-30  2:14         ` Souptick Joarder
  2020-09-30 14:10           ` boris.ostrovsky
  0 siblings, 1 reply; 8+ messages in thread
From: Souptick Joarder @ 2020-09-30  2:14 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: Juergen Gross, sstabellini, xen-devel, linux-kernel, John Hubbard

On Tue, Sep 29, 2020 at 6:00 PM <boris.ostrovsky@oracle.com> wrote:
>
>
> On 9/29/20 8:09 AM, Souptick Joarder wrote:
> > On Fri, Sep 11, 2020 at 8:12 PM <boris.ostrovsky@oracle.com> wrote:
> >>
> >> On 9/6/20 2:51 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>
> >>> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> >>> Cc: Juergen Gross <jgross@suse.com>
> >>> Cc: David Vrabel <david.vrabel@citrix.com>
> >>
> >> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Are these 2 patches queued for 5.10-rc1 ?
>
>
> Yes, I am preparing the branch. (BTW, your second patch appears to have been either manually edited or not generated on top of the first patch. Please don't do this next time)

I created it on top of the first one and didn't edit manually.
I was able to apply it in my local repository.
What was the error ?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*()
  2020-09-30  2:14         ` Souptick Joarder
@ 2020-09-30 14:10           ` boris.ostrovsky
  0 siblings, 0 replies; 8+ messages in thread
From: boris.ostrovsky @ 2020-09-30 14:10 UTC (permalink / raw)
  To: Souptick Joarder
  Cc: Juergen Gross, sstabellini, xen-devel, linux-kernel, John Hubbard



On 9/29/20 10:14 PM, Souptick Joarder wrote:
> On Tue, Sep 29, 2020 at 6:00 PM <boris.ostrovsky@oracle.com> wrote:
>>
>>
>> On 9/29/20 8:09 AM, Souptick Joarder wrote:
>>> On Fri, Sep 11, 2020 at 8:12 PM <boris.ostrovsky@oracle.com> wrote:
>>>>
>>>> On 9/6/20 2:51 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>
>>>>> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>>>>> Cc: Juergen Gross <jgross@suse.com>
>>>>> Cc: David Vrabel <david.vrabel@citrix.com>
>>>>
>>>> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>>> Are these 2 patches queued for 5.10-rc1 ?
>>
>>
>> Yes, I am preparing the branch. (BTW, your second patch appears to have been either manually edited or not generated on top of the first patch. Please don't do this next time)
> 
> I created it on top of the first one and didn't edit manually.
> I was able to apply it in my local repository.
> What was the error ?
> 


Patch 1:

+		if (batch->writeable && !PageDirty(batch->pages[i]))


Patch 2:

-		if(batch->writeable && !PageDirty(batch->pages[i]))



This doesn't look to me like usual whitespace damage in-flight. Anyway, this has been applied to for-linus-5.10


-boris

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-09-30 14:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06  6:51 [PATCH 1/2] xen/gntdev.c: Mark pages as dirty Souptick Joarder
2020-09-06  6:51 ` [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*() Souptick Joarder
2020-09-11 14:42   ` boris.ostrovsky
2020-09-29 12:09     ` Souptick Joarder
2020-09-29 12:30       ` boris.ostrovsky
2020-09-30  2:14         ` Souptick Joarder
2020-09-30 14:10           ` boris.ostrovsky
2020-09-11 14:41 ` [PATCH 1/2] xen/gntdev.c: Mark pages as dirty boris.ostrovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).