Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1260344

[PATCH v4 08/10] xen/blkback: get the number of hardware queues/rings from blkfront

From Bob Liu <bob.liu@oracle.com>
Newsgroups linux.kernel
Subject [PATCH v4 08/10] xen/blkback: get the number of hardware queues/rings from blkfront
Date 2015-11-02 05:30 +0100
Message-ID <qqeUO-Ld-21@gated-at.bofh.it> (permalink)
References <qqeUN-Ld-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Backend advertises "multi-queue-max-queues" to front, then get the negotiated
number from "multi-queue-num-queues" wrote by blkfront.

Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
 drivers/block/xen-blkback/blkback.c | 11 +++++++++++
 drivers/block/xen-blkback/common.h  |  1 +
 drivers/block/xen-blkback/xenbus.c  | 35 +++++++++++++++++++++++++++++------
 3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index eaf7ec0..107cc4a 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -83,6 +83,11 @@ module_param_named(max_persistent_grants, xen_blkif_max_pgrants, int, 0644);
 MODULE_PARM_DESC(max_persistent_grants,
                  "Maximum number of grants to map persistently");
 
+unsigned int xenblk_max_queues;
+module_param_named(max_queues, xenblk_max_queues, uint, 0644);
+MODULE_PARM_DESC(max_queues,
+		 "Maximum number of hardware queues per virtual disk");
+
 /*
  * Maximum order of pages to be used for the shared ring between front and
  * backend, 4KB page granularity is used.
@@ -1478,6 +1483,12 @@ static int __init xen_blkif_init(void)
 		xen_blkif_max_ring_order = XENBUS_MAX_RING_PAGE_ORDER;
 	}
 
+	/* Allow as many queues as there are CPUs if user has not
+	 * specified a value.
+	 */
+	if (xenblk_max_queues == 0)
+		xenblk_max_queues = num_online_cpus();
+
 	rc = xen_blkif_interface_init();
 	if (rc)
 		goto failed_init;
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index 4de1326..fb28b91 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -45,6 +45,7 @@
 #include <xen/interface/io/protocols.h>
 
 extern unsigned int xen_blkif_max_ring_order;
+extern unsigned int xenblk_max_queues;
 /*
  * This is the maximum number of segments that would be allowed in indirect
  * requests. This value will also be passed to the frontend.
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index ac4b458..cafbadd 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -181,12 +181,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
 	INIT_LIST_HEAD(&blkif->persistent_purge_list);
 	INIT_WORK(&blkif->persistent_purge_work, xen_blkbk_unmap_purged_grants);
 
-	blkif->nr_rings = 1;
-	if (xen_blkif_alloc_rings(blkif)) {
-		kmem_cache_free(xen_blkif_cachep, blkif);
-		return ERR_PTR(-ENOMEM);
-	}
-
 	return blkif;
 }
 
@@ -606,6 +600,14 @@ static int xen_blkbk_probe(struct xenbus_device *dev,
 		goto fail;
 	}
 
+	/* Multi-queue: write how many queues are supported by the backend. */
+	err = xenbus_printf(XBT_NIL, dev->nodename,
+			    "multi-queue-max-queues", "%u", xenblk_max_queues);
+	if (err) {
+		pr_warn("Error writing multi-queue-num-queues\n");
+		goto fail;
+	}
+
 	/* setup back pointer */
 	be->blkif->be = be;
 
@@ -997,6 +999,7 @@ static int connect_ring(struct backend_info *be)
 	char *xspath;
 	size_t xspathsize;
 	const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */
+	unsigned int requested_num_queues = 0;
 
 	pr_debug("%s %s\n", __func__, dev->otherend);
 
@@ -1024,6 +1027,26 @@ static int connect_ring(struct backend_info *be)
 	be->blkif->vbd.feature_gnt_persistent = pers_grants;
 	be->blkif->vbd.overflow_max_grants = 0;
 
+	/*
+	 * Read the number of hardware queues from frontend.
+	 */
+	err = xenbus_scanf(XBT_NIL, dev->otherend, "multi-queue-num-queues", "%u", &requested_num_queues);
+	if (err < 0) {
+		requested_num_queues = 1;
+	} else {
+		if (requested_num_queues > xenblk_max_queues
+		    || requested_num_queues == 0) {
+			/* buggy or malicious guest */
+			xenbus_dev_fatal(dev, err,
+					"guest requested %u queues, exceeding the maximum of %u.",
+					requested_num_queues, xenblk_max_queues);
+			return -1;
+		}
+	}
+	be->blkif->nr_rings = requested_num_queues;
+	if (xen_blkif_alloc_rings(be->blkif))
+		return -ENOMEM;
+
 	pr_info("nr_rings:%d protocol %d (%s) %s\n", be->blkif->nr_rings,
 		 be->blkif->blk_protocol, protocol,
 		 pers_grants ? "persistent grants" : "");
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/10] xen-block: multi hardware-queues/rings support Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
  [PATCH v4 05/10] xen/blkfront: negotiate number of queues/rings to be used with backend Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
    Re: [PATCH v4 05/10] xen/blkfront: negotiate number of queues/rings  to be used with backend Bob Liu <bob.liu@oracle.com> - 2015-11-04 02:20 +0100
      Re: [PATCH v4 05/10] xen/blkfront: negotiate number of queues/rings  to be used with backend Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-04 03:00 +0100
  [PATCH v4 04/10] xen/blkfront: split per device io_lock Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
    Re: [PATCH v4 04/10] xen/blkfront: split per device io_lock Bob Liu <bob.liu@oracle.com> - 2015-11-04 02:10 +0100
      Re: [PATCH v4 04/10] xen/blkfront: split per device io_lock Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-04 03:00 +0100
  [PATCH v4 07/10] xen/blkback: pseudo support for multi hardware queues/rings Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
    Re: [PATCH v4 07/10] xen/blkback: pseudo support for multi hardware  queues/rings Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-05 03:40 +0100
      Re: [PATCH v4 07/10] xen/blkback: pseudo support for multi hardware  queues/rings Bob Liu <bob.liu@oracle.com> - 2015-11-05 04:10 +0100
        Re: [PATCH v4 07/10] xen/blkback: pseudo support for multi hardware queues/rings Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-05 04:30 +0100
  [PATCH v4 09/10] xen/blkfront: make persistent grants per-queue Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
    Re: [PATCH v4 09/10] xen/blkfront: make persistent grants per-queue Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-05 03:40 +0100
  [PATCH v4 06/10] xen/blkback: separate ring information out of struct xen_blkif Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
  [PATCH v4 02/10] xen/blkfront: separate per ring information out of device info Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
  [PATCH v4 08/10] xen/blkback: get the number of hardware queues/rings from blkfront Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
    Re: [PATCH v4 08/10] xen/blkback: get the number of hardware  queues/rings from blkfront Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> - 2015-11-05 03:40 +0100
  [PATCH v4 01/10] xen/blkif: document blkif multi-queue/ring extension Bob Liu <bob.liu@oracle.com> - 2015-11-02 05:30 +0100
  Re: [Xen-devel] [PATCH v4 00/10] xen-block: multi hardware-queues/rings  support Julien Grall <julien.grall@citrix.com> - 2015-11-02 12:30 +0100

csiph-web