Skip to contentSkip to conversation

xenbus_client: extend interface to suppurt multi-page ring

PATCH Superseded Wei Liu 4 participants 7 messages Aug 23, 2013 – Aug 27, 2013

Subsystems (8)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 xenbus_client: extend interface to suppurt multi-page ring

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

The patch extends Xenbus driver to support multi-page ring, which in general should improve throughput if ring is the bottleneck. Changes to various frontend / backend to adapt to the new interface are also included.

Affected Xen drivers:
* blkfront/back
* netfront/back
* pcifront/back
* tpmfront

The interface is documented, as before, in xenbus_client.c.

---
 drivers/block/xen-blkback/xenbus.c |    5 +-
 drivers/block/xen-blkfront.c       |    5 +-
 drivers/char/tpm/xen-tpmfront.c    |    5 +-
 drivers/net/xen-netback/netback.c  |    4 +-
 drivers/net/xen-netfront.c         |    9 +-
 drivers/pci/xen-pcifront.c         |    5 +-
 drivers/xen/xen-pciback/xenbus.c   |    2 +-
 drivers/xen/xenbus/xenbus_client.c |  386 ++++++++++++++++++++++++++----------
 include/xen/xenbus.h               |   19 +-
 9 files changed, 316 insertions(+), 124 deletions(-)
drivers/block/xen-blkback/xenbus.c +3 -2
index fe5c3cd..df79278 100644
@@ -176,7 +176,7 @@ fail:
 	return ERR_PTR(-ENOMEM);
 }
 
-static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
+static int xen_blkif_map(struct xen_blkif *blkif, grant_ref_t gref,
 			 unsigned int evtchn)
 {
 	int err;
@@ -185,7 +185,8 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
 	if (blkif->irq)
 		return 0;
 
-	err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
+	err = xenbus_map_ring_valloc(blkif->be->dev, &gref, 0,
+				     &blkif->blk_ring);
 	if (err < 0)
 		return err;
 
drivers/block/xen-blkfront.c +3 -2
index a4660bb..8c186a0 100644
@@ -1144,6 +1144,7 @@ static int setup_blkring(struct xenbus_device *dev,
 {
 	struct blkif_sring *sring;
 	int err;
+	grant_ref_t gref;
 
 	info->ring_ref = GRANT_INVALID_REF;
 
@@ -1155,13 +1156,13 @@ static int setup_blkring(struct xenbus_device *dev,
 	SHARED_RING_INIT(sring);
 	FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(info->ring.sring));
+	err = xenbus_grant_ring(dev, info->ring.sring, 0, &gref);
 	if (err < 0) {
 		free_page((unsigned long)sring);
 		info->ring.sring = NULL;
 		goto fail;
 	}
-	info->ring_ref = err;
+	info->ring_ref = gref;
 
 	err = xenbus_alloc_evtchn(dev, &info->evtchn);
 	if (err)
drivers/char/tpm/xen-tpmfront.c +3 -2
index 7a7929b..e5d47823 100644
@@ -270,6 +270,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
 	struct xenbus_transaction xbt;
 	const char *message = NULL;
 	int rv;
+	grant_ref_t gref;
 
 	priv->shr = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
 	if (!priv->shr) {
@@ -277,11 +278,11 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
 		return -ENOMEM;
 	}
 
-	rv = xenbus_grant_ring(dev, virt_to_mfn(priv->shr));
+	rv = xenbus_grant_ring(dev, &priv->shr, 0, &gref);
 	if (rv < 0)
 		return rv;
 
-	priv->ring_ref = rv;
+	priv->ring_ref = gref;
 
 	rv = xenbus_alloc_evtchn(dev, &priv->evtchn);
 	if (rv)
drivers/net/xen-netback/netback.c +2 -2
index 64828de..73eb928 100644
@@ -1856,7 +1856,7 @@ int xen_netbk_map_frontend_rings(struct xenvif *vif,
 	int err = -ENOMEM;
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     tx_ring_ref, &addr);
+				     &tx_ring_ref, 0, &addr);
 	if (err)
 		goto err;
 
@@ -1864,7 +1864,7 @@ int xen_netbk_map_frontend_rings(struct xenvif *vif,
 	BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
 
 	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
-				     rx_ring_ref, &addr);
+				     &rx_ring_ref, 0, &addr);
 	if (err)
 		goto err;
 
drivers/net/xen-netfront.c +5 -4
index 36808bf..5a784dc 100644
@@ -1593,6 +1593,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	int err;
 	struct net_device *netdev = info->netdev;
 	unsigned int feature_split_evtchn;
+	grant_ref_t gref;
 
 	info->tx_ring_ref = GRANT_INVALID_REF;
 	info->rx_ring_ref = GRANT_INVALID_REF;
@@ -1621,11 +1622,11 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(txs);
 	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
+	err = xenbus_grant_ring(dev, txs, 0, &gref);
 	if (err < 0)
 		goto grant_tx_ring_fail;
 
-	info->tx_ring_ref = err;
+	info->tx_ring_ref = gref;
 	rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
 	if (!rxs) {
 		err = -ENOMEM;
@@ -1635,10 +1636,10 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	SHARED_RING_INIT(rxs);
 	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
 
-	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
+	err = xenbus_grant_ring(dev, rxs, 0, &gref);
 	if (err < 0)
 		goto grant_rx_ring_fail;
-	info->rx_ring_ref = err;
+	info->rx_ring_ref = gref;
 
 	if (feature_split_evtchn)
 		err = setup_netfront_split(info);
drivers/pci/xen-pcifront.c +3 -2
index f7197a7..efdde2f 100644
@@ -771,12 +771,13 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
 {
 	int err = 0;
 	struct xenbus_transaction trans;
+	grant_ref_t gref;
 
-	err = xenbus_grant_ring(pdev->xdev, virt_to_mfn(pdev->sh_info));
+	err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 0, &gref);
 	if (err < 0)
 		goto out;
 
-	pdev->gnt_ref = err;
+	pdev->gnt_ref = gref;
 
 	err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn);
 	if (err)
drivers/xen/xen-pciback/xenbus.c +1 -1
index a9ed867..644faf0 100644
@@ -111,7 +111,7 @@ static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,
 		"Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
 		gnt_ref, remote_evtchn);
 
-	err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr);
+	err = xenbus_map_ring_valloc(pdev->xdev, &gnt_ref, 0, &vaddr);
 	if (err < 0) {
 		xenbus_dev_fatal(pdev->xdev, err,
 				"Error mapping other domain page in ours.");
drivers/xen/xenbus/xenbus_client.c +283 -103

546 lines not on this page · raw message

include/xen/xenbus.h +13 -6
index 569c07f..dc0c3d6 100644
@@ -46,6 +46,10 @@
 #include <xen/interface/io/xenbus.h>
 #include <xen/interface/io/xs_wire.h>
 
+#define XENBUS_MAX_RING_PAGE_ORDER 4
+#define XENBUS_MAX_RING_PAGES      (1U << XENBUS_MAX_RING_PAGE_ORDER)
+#define INVALID_GRANT_HANDLE       (~0U)
+
 /* Register callback to watch this node. */
 struct xenbus_watch
 {
@@ -196,15 +200,18 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      unsigned int nr_pages, grant_ref_t *grefs);
+int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
+			   unsigned int nr_grefs, void **vaddr);
+int xenbus_map_ring(struct xenbus_device *dev,
+		    grant_ref_t *gnt_refs, unsigned int nr_grefs,
+		    grant_handle_t *handles, void *vaddr, bool *leaked);
 
 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
 int xenbus_unmap_ring(struct xenbus_device *dev,
-		      grant_handle_t handle, void *vaddr);
+		      grant_handle_t *handles, unsigned int nr_handles,
+		      void **vaddr);
 
 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
 int xenbus_bind_evtchn(struct xenbus_device *dev, int remote_port, int *port);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 8 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

The patch extends Xenbus driver to support multi-page ring, which in general should improve throughput if ring is the bottleneck. Changes to various frontend / backend to adapt to the new interface are also included.

The changes to the front/backends here simply adapt to the new interface but don't actually make use of it, right?

include/xen/xenbus.h int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, · line 206

Quoted 13 lines
include/xen/xenbus.h +4 -5
@@ -196,15 +200,18 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      unsigned int nr_pages, grant_ref_t *grefs);
+int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
+			   unsigned int nr_grefs, void **vaddr);

In the definition nr_grefs is called grefs_order. From the usage I think the definition and not this prototype is correct.

Ian.

author
#2 lore raw
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

Quoted 8 lines
Quoted 4 lines

The patch extends Xenbus driver to support multi-page ring, which in general should improve throughput if ring is the bottleneck. Changes to various frontend / backend to adapt to the new interface are also included.

The changes to the front/backends here simply adapt to the new interface but don't actually make use of it, right?

No, they don't.

Quoted 17 lines

include/xen/xenbus.h int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, · line 206

Quoted 13 lines
include/xen/xenbus.h +4 -5
@@ -196,15 +200,18 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      unsigned int nr_pages, grant_ref_t *grefs);
+int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
+			   unsigned int nr_grefs, void **vaddr);

In the definition nr_grefs is called grefs_order. From the usage I think the definition and not this prototype is correct.

Good catch, thanks.

Wei.

Quoted 1 line

Ian.

#3 lore raw
Quoted 11 lines · Wei Liu
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

The patch extends Xenbus driver to support multi-page ring, which in general should improve throughput if ring is the bottleneck. Changes to various frontend / backend to adapt to the new interface are also included.

Quoted 5 lines
Quoted 3 lines

The changes to the front/backends here simply adapt to the new interface but don't actually make use of it, right?

No, they don't.

I think the scsi front or usb front (in a different branch) did use it. That is why I remember seeing something similar to this.

Either way, I am comfortable putting this in - will make it easier for folks to experiement with enlarging the ring.

Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
include/xen/xenbus.h +0 -0
@@ -196,15 +200,18 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
Quoted 14 lines

include/xen/xenbus.h int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, · line 206

Quoted 10 lines
include/xen/xenbus.h +4 -5
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      unsigned int nr_pages, grant_ref_t *grefs);
+int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
+			   unsigned int nr_grefs, void **vaddr);

In the definition nr_grefs is called grefs_order. From the usage I think the definition and not this prototype is correct.

Good catch, thanks.

Wei.

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#4 lore raw
Quoted 12 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Wei Liu
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

The patch extends Xenbus driver to support multi-page ring, which in general should improve throughput if ring is the bottleneck. Changes to various frontend / backend to adapt to the new interface are also included.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

The changes to the front/backends here simply adapt to the new interface but don't actually make use of it, right?

No, they don't.

I think the scsi front or usb front (in a different branch) did use it. That is why I remember seeing something similar to this.

Oh, those are not upstreamed.

Quoted 3 lines

Either way, I am comfortable putting this in - will make it easier for folks to experiement with enlarging the ring.

Quoted 1 line

Right. I will post another version when I collect enough comments...

Wei.

Quoted 28 lines
Quoted 28 lines
Quoted 17 lines

include/xen/xenbus.h int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, · line 206

Quoted 13 lines
include/xen/xenbus.h +4 -5
@@ -196,15 +200,18 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
 			 const char *pathfmt, ...);
 
 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
-int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
-int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
-			   grant_handle_t *handle, void *vaddr);
+int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
+		      unsigned int nr_pages, grant_ref_t *grefs);
+int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
+			   unsigned int nr_grefs, void **vaddr);

In the definition nr_grefs is called grefs_order. From the usage I think the definition and not this prototype is correct.

Good catch, thanks.

Wei.

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
In reply to Wei Liu
Quoted 3 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

Why does the number of pages in the ring have to be a power of two? Should we be able to handle any number of pages?

David

author
#6 lore raw
Quoted 8 lines · David Vrabel
Quoted 3 lines · Wei Liu

Originally Xen PV drivers only use single-page ring to pass along information. This might limit the throughput between frontend and backend.

Why does the number of pages in the ring have to be a power of two? Should we be able to handle any number of pages?

No they don't. There is no problem changing to handle any number of pages, given that the number of pages <= XENBUS_MAX_RING_PAGES. In fact my first version was like that. :-)

I change to power of two because someone suggested that at Hackathon. But that's pretty random suggestion too so it's quite safe to ignore that.

Further thought is that using arbitrary number would be more space-effecient. I will change to that.

Wei.

Quoted 1 line

David