From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752897AbbIEMmk (ORCPT ); Sat, 5 Sep 2015 08:42:40 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:43753 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752070AbbIEMlK (ORCPT ); Sat, 5 Sep 2015 08:41:10 -0400 From: Bob Liu To: xen-devel@lists.xen.org Cc: david.vrabel@citrix.com, linux-kernel@vger.kernel.org, roger.pau@citrix.com, konrad.wilk@oracle.com, felipe.franciosi@citrix.com, axboe@fb.com, hch@infradead.org, avanzini.arianna@gmail.com, rafal.mielniczuk@citrix.com, boris.ostrovsky@oracle.com, jonathan.davies@citrix.com, Bob Liu Subject: [PATCH v3 9/9] xen/blkback: get number of hardware queues/rings from blkfront Date: Sat, 5 Sep 2015 20:39:42 +0800 Message-Id: <1441456782-31318-10-git-send-email-bob.liu@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1441456782-31318-1-git-send-email-bob.liu@oracle.com> References: <1441456782-31318-1-git-send-email-bob.liu@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Backend advertises "multi-queue-max-queues" to front, and then read back the final negotiated queues/rings from "multi-queue-num-queues" which is wrote by blkfront. Signed-off-by: Bob Liu --- drivers/block/xen-blkback/blkback.c | 8 ++++++++ drivers/block/xen-blkback/xenbus.c | 36 ++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index fd02240..b904fe05f0 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. @@ -1458,6 +1463,9 @@ 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, by default */ + xenblk_max_queues = num_online_cpus(); + rc = xen_blkif_interface_init(); if (rc) goto failed_init; diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 04b8d0d..aa97ea5 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -28,6 +28,8 @@ #define RINGREF_NAME_LEN (20) #define RINGREF_NAME_LEN (20) +extern unsigned int xenblk_max_queues; + struct backend_info { struct xenbus_device *dev; struct xen_blkif *blkif; @@ -191,11 +193,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) atomic_set(&blkif->drain, 0); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); - blkif->nr_rings = 1; - if (xen_blkif_alloc_rings(blkif)) { - kmem_cache_free(xen_blkif_cachep, blkif); - return ERR_PTR(-ENOMEM); - } return blkif; } @@ -618,6 +615,14 @@ static int xen_blkbk_probe(struct xenbus_device *dev, goto fail; } + /* Multi-queue: wrte how many queues backend supported. */ + err = xenbus_printf(XBT_NIL, dev->nodename, + "multi-queue-max-queues", "%u", xenblk_max_queues); + if (err) { + pr_debug("Error writing multi-queue-num-queues\n"); + goto fail; + } + /* setup back pointer */ be->blkif->be = be; @@ -1008,6 +1013,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); @@ -1035,6 +1041,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 queus 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.7.10.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bob Liu Subject: [PATCH v3 9/9] xen/blkback: get number of hardware queues/rings from blkfront Date: Sat, 5 Sep 2015 20:39:42 +0800 Message-ID: <1441456782-31318-10-git-send-email-bob.liu@oracle.com> References: <1441456782-31318-1-git-send-email-bob.liu@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1441456782-31318-1-git-send-email-bob.liu@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: hch@infradead.org, felipe.franciosi@citrix.com, rafal.mielniczuk@citrix.com, linux-kernel@vger.kernel.org, jonathan.davies@citrix.com, axboe@fb.com, Bob Liu , david.vrabel@citrix.com, avanzini.arianna@gmail.com, boris.ostrovsky@oracle.com, roger.pau@citrix.com List-Id: xen-devel@lists.xenproject.org Backend advertises "multi-queue-max-queues" to front, and then read back the final negotiated queues/rings from "multi-queue-num-queues" which is wrote by blkfront. Signed-off-by: Bob Liu --- drivers/block/xen-blkback/blkback.c | 8 ++++++++ drivers/block/xen-blkback/xenbus.c | 36 ++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index fd02240..b904fe05f0 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. @@ -1458,6 +1463,9 @@ 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, by default */ + xenblk_max_queues = num_online_cpus(); + rc = xen_blkif_interface_init(); if (rc) goto failed_init; diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 04b8d0d..aa97ea5 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -28,6 +28,8 @@ #define RINGREF_NAME_LEN (20) #define RINGREF_NAME_LEN (20) +extern unsigned int xenblk_max_queues; + struct backend_info { struct xenbus_device *dev; struct xen_blkif *blkif; @@ -191,11 +193,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) atomic_set(&blkif->drain, 0); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); - blkif->nr_rings = 1; - if (xen_blkif_alloc_rings(blkif)) { - kmem_cache_free(xen_blkif_cachep, blkif); - return ERR_PTR(-ENOMEM); - } return blkif; } @@ -618,6 +615,14 @@ static int xen_blkbk_probe(struct xenbus_device *dev, goto fail; } + /* Multi-queue: wrte how many queues backend supported. */ + err = xenbus_printf(XBT_NIL, dev->nodename, + "multi-queue-max-queues", "%u", xenblk_max_queues); + if (err) { + pr_debug("Error writing multi-queue-num-queues\n"); + goto fail; + } + /* setup back pointer */ be->blkif->be = be; @@ -1008,6 +1013,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); @@ -1035,6 +1041,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 queus 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.7.10.4