All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] xen/blkback: safely unmap purge persistent grants
@ 2015-04-03  6:42 Bob Liu
  2015-04-03  6:42 ` [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync() Bob Liu
  2015-04-29 16:36 ` [PATCH 1/2] xen/blkback: safely unmap purge persistent grants David Vrabel
  0 siblings, 2 replies; 5+ messages in thread
From: Bob Liu @ 2015-04-03  6:42 UTC (permalink / raw)
  To: xen-devel
  Cc: jennifer.herbert, axboe, Bob Liu, david.vrabel, boris.ostrovsky,
	roger.pau

Commit c43cf3ea8385 ("xen-blkback: safely unmap grants in case they are still
in use") use gnttab_unmap_refs_async() to wait until the mapped pages are no
longer in use before unmapping them, but that commit missed the persistent case.
Purge persistent pages can't be unmapped either unless no longer in use.

Signed-off-by: Bob Liu <bob.liu@oracle.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
 drivers/block/xen-blkback/blkback.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 2a04d34..f59d7c3 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -327,8 +327,18 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
 	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
 	struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
 	struct persistent_gnt *persistent_gnt;
-	int ret, segs_to_unmap = 0;
+	int segs_to_unmap = 0;
 	struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work);
+	struct gntab_unmap_queue_data unmap_data;
+	struct completion unmap_completion;
+
+	init_completion(&unmap_completion);
+
+	unmap_data.data = &unmap_completion;
+	unmap_data.done = &free_persistent_gnts_unmap_callback;
+	unmap_data.pages = pages;
+	unmap_data.unmap_ops = unmap;
+	unmap_data.kunmap_ops = NULL;
 
 	while(!list_empty(&blkif->persistent_purge_list)) {
 		persistent_gnt = list_first_entry(&blkif->persistent_purge_list,
@@ -344,17 +354,19 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
 		pages[segs_to_unmap] = persistent_gnt->page;
 
 		if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
-			ret = gnttab_unmap_refs(unmap, NULL, pages,
-				segs_to_unmap);
-			BUG_ON(ret);
+			unmap_data.count = segs_to_unmap;
+			gnttab_unmap_refs_async(&unmap_data);
+			wait_for_completion(&unmap_completion);
+
 			put_free_pages(blkif, pages, segs_to_unmap);
 			segs_to_unmap = 0;
 		}
 		kfree(persistent_gnt);
 	}
 	if (segs_to_unmap > 0) {
-		ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap);
-		BUG_ON(ret);
+		unmap_data.count = segs_to_unmap;
+		gnttab_unmap_refs_async(&unmap_data);
+		wait_for_completion(&unmap_completion);
 		put_free_pages(blkif, pages, segs_to_unmap);
 	}
 }
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync()
  2015-04-03  6:42 [PATCH 1/2] xen/blkback: safely unmap purge persistent grants Bob Liu
@ 2015-04-03  6:42 ` Bob Liu
  2015-04-15 10:37   ` Roger Pau Monné
  2015-04-29 16:36 ` [PATCH 1/2] xen/blkback: safely unmap purge persistent grants David Vrabel
  1 sibling, 1 reply; 5+ messages in thread
From: Bob Liu @ 2015-04-03  6:42 UTC (permalink / raw)
  To: xen-devel
  Cc: jennifer.herbert, axboe, Bob Liu, david.vrabel, boris.ostrovsky,
	roger.pau

There are several place using gnttab async unmap and wait for
completion, so move the common code to a function
gnttab_unmap_refs_sync().

v2: Rename to gnttab_unmap_refs_sync()

Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
 drivers/block/xen-blkback/blkback.c |   31 +++----------------------------
 drivers/xen/gntdev.c                |   28 +++-------------------------
 drivers/xen/grant-table.c           |   28 ++++++++++++++++++++++++++++
 include/xen/grant_table.h           |    1 +
 4 files changed, 35 insertions(+), 53 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index f59d7c3..a49c500 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -263,17 +263,6 @@ static void put_persistent_gnt(struct xen_blkif *blkif,
 	atomic_dec(&blkif->persistent_gnt_in_use);
 }
 
-static void free_persistent_gnts_unmap_callback(int result,
-						struct gntab_unmap_queue_data *data)
-{
-	struct completion *c = data->data;
-
-	/* BUG_ON used to reproduce existing behaviour,
-	   but is this the best way to deal with this? */
-	BUG_ON(result);
-	complete(c);
-}
-
 static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
                                  unsigned int num)
 {
@@ -283,12 +272,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
 	struct rb_node *n;
 	int segs_to_unmap = 0;
 	struct gntab_unmap_queue_data unmap_data;
-	struct completion unmap_completion;
-
-	init_completion(&unmap_completion);
 
-	unmap_data.data = &unmap_completion;
-	unmap_data.done = &free_persistent_gnts_unmap_callback;
 	unmap_data.pages = pages;
 	unmap_data.unmap_ops = unmap;
 	unmap_data.kunmap_ops = NULL;
@@ -308,8 +292,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
 			!rb_next(&persistent_gnt->node)) {
 
 			unmap_data.count = segs_to_unmap;
-			gnttab_unmap_refs_async(&unmap_data);
-			wait_for_completion(&unmap_completion);
+			BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
 
 			put_free_pages(blkif, pages, segs_to_unmap);
 			segs_to_unmap = 0;
@@ -330,12 +313,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
 	int segs_to_unmap = 0;
 	struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work);
 	struct gntab_unmap_queue_data unmap_data;
-	struct completion unmap_completion;
 
-	init_completion(&unmap_completion);
-
-	unmap_data.data = &unmap_completion;
-	unmap_data.done = &free_persistent_gnts_unmap_callback;
 	unmap_data.pages = pages;
 	unmap_data.unmap_ops = unmap;
 	unmap_data.kunmap_ops = NULL;
@@ -355,9 +333,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
 
 		if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
 			unmap_data.count = segs_to_unmap;
-			gnttab_unmap_refs_async(&unmap_data);
-			wait_for_completion(&unmap_completion);
-
+			BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
 			put_free_pages(blkif, pages, segs_to_unmap);
 			segs_to_unmap = 0;
 		}
@@ -365,8 +341,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
 	}
 	if (segs_to_unmap > 0) {
 		unmap_data.count = segs_to_unmap;
-		gnttab_unmap_refs_async(&unmap_data);
-		wait_for_completion(&unmap_completion);
+		BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
 		put_free_pages(blkif, pages, segs_to_unmap);
 	}
 }
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index d5bb1a3..8927485 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -327,30 +327,10 @@ static int map_grant_pages(struct grant_map *map)
 	return err;
 }
 
-struct unmap_grant_pages_callback_data
-{
-	struct completion completion;
-	int result;
-};
-
-static void unmap_grant_callback(int result,
-				 struct gntab_unmap_queue_data *data)
-{
-	struct unmap_grant_pages_callback_data* d = data->data;
-
-	d->result = result;
-	complete(&d->completion);
-}
-
 static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
 {
 	int i, err = 0;
 	struct gntab_unmap_queue_data unmap_data;
-	struct unmap_grant_pages_callback_data data;
-
-	init_completion(&data.completion);
-	unmap_data.data = &data;
-	unmap_data.done= &unmap_grant_callback;
 
 	if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
 		int pgno = (map->notify.addr >> PAGE_SHIFT);
@@ -367,11 +347,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
 	unmap_data.pages = map->pages + offset;
 	unmap_data.count = pages;
 
-	gnttab_unmap_refs_async(&unmap_data);
-
-	wait_for_completion(&data.completion);
-	if (data.result)
-		return data.result;
+	err = gnttab_unmap_refs_sync(&unmap_data);
+	if (err)
+		return err;
 
 	for (i = 0; i < pages; i++) {
 		if (map->unmap_ops[offset+i].status)
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 17972fb..b1c7170 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -123,6 +123,11 @@ struct gnttab_ops {
 	int (*query_foreign_access)(grant_ref_t ref);
 };
 
+struct unmap_refs_callback_data {
+	struct completion completion;
+	int result;
+};
+
 static struct gnttab_ops *gnttab_interface;
 
 static int grant_table_version;
@@ -863,6 +868,29 @@ void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item)
 }
 EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async);
 
+static void unmap_refs_callback(int result,
+		struct gntab_unmap_queue_data *data)
+{
+	struct unmap_refs_callback_data *d = data->data;
+
+	d->result = result;
+	complete(&d->completion);
+}
+
+int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item)
+{
+	struct unmap_refs_callback_data data;
+
+	init_completion(&data.completion);
+	item->data = &data;
+	item->done = &unmap_refs_callback;
+	gnttab_unmap_refs_async(item);
+	wait_for_completion(&data.completion);
+
+	return data.result;
+}
+EXPORT_SYMBOL_GPL(gnttab_unmap_refs_sync);
+
 static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes)
 {
 	int rc;
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 143ca5f..4478f4b 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -191,6 +191,7 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
 		      struct gnttab_unmap_grant_ref *kunmap_ops,
 		      struct page **pages, unsigned int count);
 void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
+int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item);
 
 
 /* Perform a batch of grant map/copy operations. Retry every batch slot
-- 
1.7.10.4

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

* Re: [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync()
  2015-04-03  6:42 ` [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync() Bob Liu
@ 2015-04-15 10:37   ` Roger Pau Monné
  2015-04-15 13:32     ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 5+ messages in thread
From: Roger Pau Monné @ 2015-04-15 10:37 UTC (permalink / raw)
  To: Bob Liu, xen-devel; +Cc: axboe, boris.ostrovsky, jennifer.herbert, david.vrabel

El 03/04/15 a les 8.42, Bob Liu ha escrit:
> There are several place using gnttab async unmap and wait for
> completion, so move the common code to a function
> gnttab_unmap_refs_sync().
> 
> v2: Rename to gnttab_unmap_refs_sync()
> 
> Signed-off-by: Bob Liu <bob.liu@oracle.com>

For the blkback bits:

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

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

* Re: [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync()
  2015-04-15 10:37   ` Roger Pau Monné
@ 2015-04-15 13:32     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-04-15 13:32 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: jennifer.herbert, axboe, david.vrabel, xen-devel, boris.ostrovsky

On Wed, Apr 15, 2015 at 12:37:27PM +0200, Roger Pau Monné wrote:
> El 03/04/15 a les 8.42, Bob Liu ha escrit:
> > There are several place using gnttab async unmap and wait for
> > completion, so move the common code to a function
> > gnttab_unmap_refs_sync().
> > 
> > v2: Rename to gnttab_unmap_refs_sync()
> > 
> > Signed-off-by: Bob Liu <bob.liu@oracle.com>
> 
> For the blkback bits:
> 
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>

And Jen's was OK with going through the Xen tree so that
it is fine then.

Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> 

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

* Re: [PATCH 1/2] xen/blkback: safely unmap purge persistent grants
  2015-04-03  6:42 [PATCH 1/2] xen/blkback: safely unmap purge persistent grants Bob Liu
  2015-04-03  6:42 ` [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync() Bob Liu
@ 2015-04-29 16:36 ` David Vrabel
  1 sibling, 0 replies; 5+ messages in thread
From: David Vrabel @ 2015-04-29 16:36 UTC (permalink / raw)
  To: Bob Liu, xen-devel
  Cc: axboe, boris.ostrovsky, jennifer.herbert, david.vrabel, roger.pau

On 03/04/15 07:42, Bob Liu wrote:
> Commit c43cf3ea8385 ("xen-blkback: safely unmap grants in case they are still
> in use") use gnttab_unmap_refs_async() to wait until the mapped pages are no
> longer in use before unmapping them, but that commit missed the persistent case.
> Purge persistent pages can't be unmapped either unless no longer in use.

Applied (this and 2/2) to for-linus-4.1b, thanks.

David

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

end of thread, other threads:[~2015-04-29 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-03  6:42 [PATCH 1/2] xen/blkback: safely unmap purge persistent grants Bob Liu
2015-04-03  6:42 ` [PATCH v2 2/2] xen/grant: introduce func gnttab_unmap_refs_sync() Bob Liu
2015-04-15 10:37   ` Roger Pau Monné
2015-04-15 13:32     ` Konrad Rzeszutek Wilk
2015-04-29 16:36 ` [PATCH 1/2] xen/blkback: safely unmap purge persistent grants David Vrabel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.