All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen-blkback: free requests on disconnection
@ 2015-09-04 10:08 Roger Pau Monne
  2015-09-04 13:51 ` Julien Grall
  2015-09-04 13:51 ` [Xen-devel] " Julien Grall
  0 siblings, 2 replies; 19+ messages in thread
From: Roger Pau Monne @ 2015-09-04 10:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Roger Pau Monne, Julien Grall, Konrad Rzeszutek Wilk,
	Boris Ostrovsky, David Vrabel, xen-devel

Request allocation has been moved to connect_ring, which is called every
time blkback connects to the frontend (this can happen multiple times during
a blkback instance life cycle). On the other hand, request freeing has not
been moved, so it's only called when destroying the backend instance. Due to
this mismatch, blkback can allocate the request pool multiple times, without
freeing it.

In order to fix it, move the freeing of requests to xen_blkif_disconnect to
restore the symmetry between request allocation and freeing.

Reported-by: Julien Grall <julien.grall@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Julien Grall <julien.grall@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: xen-devel@lists.xenproject.org
---
This patch should be backported to 4.2.
---
 drivers/block/xen-blkback/xenbus.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index deb3f00..7676575 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -212,6 +212,9 @@ static int xen_blkif_map(struct xen_blkif *blkif, grant_ref_t *gref,
 
 static int xen_blkif_disconnect(struct xen_blkif *blkif)
 {
+	struct pending_req *req, *n;
+	int i = 0, j;
+
 	if (blkif->xenblkd) {
 		kthread_stop(blkif->xenblkd);
 		wake_up(&blkif->shutdown_wq);
@@ -238,13 +241,28 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
 	/* Remove all persistent grants and the cache of ballooned pages. */
 	xen_blkbk_free_caches(blkif);
 
+	/* Check that there is no request in use */
+	list_for_each_entry_safe(req, n, &blkif->pending_free, free_list) {
+		list_del(&req->free_list);
+
+		for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++)
+			kfree(req->segments[j]);
+
+		for (j = 0; j < MAX_INDIRECT_PAGES; j++)
+			kfree(req->indirect_pages[j]);
+
+		kfree(req);
+		i++;
+	}
+
+	WARN_ON(i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages));
+	blkif->nr_ring_pages = 0;
+
 	return 0;
 }
 
 static void xen_blkif_free(struct xen_blkif *blkif)
 {
-	struct pending_req *req, *n;
-	int i = 0, j;
 
 	xen_blkif_disconnect(blkif);
 	xen_vbd_free(&blkif->vbd);
@@ -257,22 +275,6 @@ static void xen_blkif_free(struct xen_blkif *blkif)
 	BUG_ON(!list_empty(&blkif->free_pages));
 	BUG_ON(!RB_EMPTY_ROOT(&blkif->persistent_gnts));
 
-	/* Check that there is no request in use */
-	list_for_each_entry_safe(req, n, &blkif->pending_free, free_list) {
-		list_del(&req->free_list);
-
-		for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++)
-			kfree(req->segments[j]);
-
-		for (j = 0; j < MAX_INDIRECT_PAGES; j++)
-			kfree(req->indirect_pages[j]);
-
-		kfree(req);
-		i++;
-	}
-
-	WARN_ON(i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages));
-
 	kmem_cache_free(xen_blkif_cachep, blkif);
 }
 
-- 
1.9.5 (Apple Git-50.3)


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

end of thread, other threads:[~2015-09-25 20:06 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-04 10:08 [PATCH] xen-blkback: free requests on disconnection Roger Pau Monne
2015-09-04 13:51 ` Julien Grall
2015-09-04 13:51 ` [Xen-devel] " Julien Grall
2015-09-04 17:21   ` Konrad Rzeszutek Wilk
2015-09-04 17:21   ` Konrad Rzeszutek Wilk
2015-09-07  6:07   ` Bob Liu
2015-09-07  6:07   ` [Xen-devel] " Bob Liu
2015-09-07 11:10     ` Julien Grall
2015-09-07 11:35       ` Bob Liu
2015-09-08 10:43         ` Roger Pau Monné
2015-09-08 10:43         ` [Xen-devel] " Roger Pau Monné
2015-09-09 15:02           ` Konrad Rzeszutek Wilk
2015-09-21 23:10             ` Julien Grall
2015-09-25 20:05               ` Konrad Rzeszutek Wilk
2015-09-25 20:05               ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-09-21 23:10             ` Julien Grall
2015-09-09 15:02           ` Konrad Rzeszutek Wilk
2015-09-07 11:35       ` Bob Liu
2015-09-07 11:10     ` Julien Grall

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.