Commit ccc9d90a authored by Wei Liu's avatar Wei Liu Committed by David Vrabel

xenbus_client: Extend interface to support 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
* scsifront/back
* vtpmfront

The interface is documented, as before, in xenbus_client.c.
Signed-off-by: default avatarWei Liu <wei.liu2@citrix.com>
Signed-off-by: default avatarPaul Durrant <paul.durrant@citrix.com>
Signed-off-by: default avatarBob Liu <bob.liu@oracle.com>
Cc: Konrad Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
parent 278edfc0
...@@ -193,7 +193,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) ...@@ -193,7 +193,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
return ERR_PTR(-ENOMEM); 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) unsigned int evtchn)
{ {
int err; int err;
...@@ -202,7 +202,8 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, ...@@ -202,7 +202,8 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
if (blkif->irq) if (blkif->irq)
return 0; return 0;
err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring); err = xenbus_map_ring_valloc(blkif->be->dev, &gref, 1,
&blkif->blk_ring);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -1245,6 +1245,7 @@ static int setup_blkring(struct xenbus_device *dev, ...@@ -1245,6 +1245,7 @@ static int setup_blkring(struct xenbus_device *dev,
struct blkfront_info *info) struct blkfront_info *info)
{ {
struct blkif_sring *sring; struct blkif_sring *sring;
grant_ref_t gref;
int err; int err;
info->ring_ref = GRANT_INVALID_REF; info->ring_ref = GRANT_INVALID_REF;
...@@ -1257,13 +1258,13 @@ static int setup_blkring(struct xenbus_device *dev, ...@@ -1257,13 +1258,13 @@ static int setup_blkring(struct xenbus_device *dev,
SHARED_RING_INIT(sring); SHARED_RING_INIT(sring);
FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); 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, 1, &gref);
if (err < 0) { if (err < 0) {
free_page((unsigned long)sring); free_page((unsigned long)sring);
info->ring.sring = NULL; info->ring.sring = NULL;
goto fail; goto fail;
} }
info->ring_ref = err; info->ring_ref = gref;
err = xenbus_alloc_evtchn(dev, &info->evtchn); err = xenbus_alloc_evtchn(dev, &info->evtchn);
if (err) if (err)
......
...@@ -193,6 +193,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv) ...@@ -193,6 +193,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
const char *message = NULL; const char *message = NULL;
int rv; int rv;
grant_ref_t gref;
priv->shr = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO); priv->shr = (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
if (!priv->shr) { if (!priv->shr) {
...@@ -200,11 +201,11 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv) ...@@ -200,11 +201,11 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
return -ENOMEM; return -ENOMEM;
} }
rv = xenbus_grant_ring(dev, virt_to_mfn(priv->shr)); rv = xenbus_grant_ring(dev, &priv->shr, 1, &gref);
if (rv < 0) if (rv < 0)
return rv; return rv;
priv->ring_ref = rv; priv->ring_ref = gref;
rv = xenbus_alloc_evtchn(dev, &priv->evtchn); rv = xenbus_alloc_evtchn(dev, &priv->evtchn);
if (rv) if (rv)
......
...@@ -1781,7 +1781,7 @@ int xenvif_map_frontend_rings(struct xenvif_queue *queue, ...@@ -1781,7 +1781,7 @@ int xenvif_map_frontend_rings(struct xenvif_queue *queue,
int err = -ENOMEM; int err = -ENOMEM;
err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue->vif), err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue->vif),
tx_ring_ref, &addr); &tx_ring_ref, 1, &addr);
if (err) if (err)
goto err; goto err;
...@@ -1789,7 +1789,7 @@ int xenvif_map_frontend_rings(struct xenvif_queue *queue, ...@@ -1789,7 +1789,7 @@ int xenvif_map_frontend_rings(struct xenvif_queue *queue,
BACK_RING_INIT(&queue->tx, txs, PAGE_SIZE); BACK_RING_INIT(&queue->tx, txs, PAGE_SIZE);
err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue->vif), err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue->vif),
rx_ring_ref, &addr); &rx_ring_ref, 1, &addr);
if (err) if (err)
goto err; goto err;
......
...@@ -1486,6 +1486,7 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1486,6 +1486,7 @@ static int setup_netfront(struct xenbus_device *dev,
{ {
struct xen_netif_tx_sring *txs; struct xen_netif_tx_sring *txs;
struct xen_netif_rx_sring *rxs; struct xen_netif_rx_sring *rxs;
grant_ref_t gref;
int err; int err;
queue->tx_ring_ref = GRANT_INVALID_REF; queue->tx_ring_ref = GRANT_INVALID_REF;
...@@ -1502,10 +1503,10 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1502,10 +1503,10 @@ static int setup_netfront(struct xenbus_device *dev,
SHARED_RING_INIT(txs); SHARED_RING_INIT(txs);
FRONT_RING_INIT(&queue->tx, txs, PAGE_SIZE); FRONT_RING_INIT(&queue->tx, txs, PAGE_SIZE);
err = xenbus_grant_ring(dev, virt_to_mfn(txs)); err = xenbus_grant_ring(dev, txs, 1, &gref);
if (err < 0) if (err < 0)
goto grant_tx_ring_fail; goto grant_tx_ring_fail;
queue->tx_ring_ref = err; queue->tx_ring_ref = gref;
rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH); rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
if (!rxs) { if (!rxs) {
...@@ -1516,10 +1517,10 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1516,10 +1517,10 @@ static int setup_netfront(struct xenbus_device *dev,
SHARED_RING_INIT(rxs); SHARED_RING_INIT(rxs);
FRONT_RING_INIT(&queue->rx, rxs, PAGE_SIZE); FRONT_RING_INIT(&queue->rx, rxs, PAGE_SIZE);
err = xenbus_grant_ring(dev, virt_to_mfn(rxs)); err = xenbus_grant_ring(dev, rxs, 1, &gref);
if (err < 0) if (err < 0)
goto grant_rx_ring_fail; goto grant_rx_ring_fail;
queue->rx_ring_ref = err; queue->rx_ring_ref = gref;
if (feature_split_evtchn) if (feature_split_evtchn)
err = setup_netfront_split(queue); err = setup_netfront_split(queue);
......
...@@ -777,12 +777,13 @@ static int pcifront_publish_info(struct pcifront_device *pdev) ...@@ -777,12 +777,13 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
{ {
int err = 0; int err = 0;
struct xenbus_transaction trans; 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, 1, &gref);
if (err < 0) if (err < 0)
goto out; goto out;
pdev->gnt_ref = err; pdev->gnt_ref = gref;
err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn);
if (err) if (err)
......
...@@ -714,6 +714,7 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info) ...@@ -714,6 +714,7 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
{ {
struct xenbus_device *dev = info->dev; struct xenbus_device *dev = info->dev;
struct vscsiif_sring *sring; struct vscsiif_sring *sring;
grant_ref_t gref;
int err = -ENOMEM; int err = -ENOMEM;
/***** Frontend to Backend ring start *****/ /***** Frontend to Backend ring start *****/
...@@ -726,14 +727,14 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info) ...@@ -726,14 +727,14 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *info)
SHARED_RING_INIT(sring); SHARED_RING_INIT(sring);
FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
err = xenbus_grant_ring(dev, virt_to_mfn(sring)); err = xenbus_grant_ring(dev, sring, 1, &gref);
if (err < 0) { if (err < 0) {
free_page((unsigned long)sring); free_page((unsigned long)sring);
xenbus_dev_fatal(dev, err, xenbus_dev_fatal(dev, err,
"fail to grant shared ring (Front to Back)"); "fail to grant shared ring (Front to Back)");
return err; return err;
} }
info->ring_ref = err; info->ring_ref = gref;
err = xenbus_alloc_evtchn(dev, &info->evtchn); err = xenbus_alloc_evtchn(dev, &info->evtchn);
if (err) { if (err) {
......
...@@ -113,7 +113,7 @@ static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref, ...@@ -113,7 +113,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", "Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
gnt_ref, remote_evtchn); gnt_ref, remote_evtchn);
err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr); err = xenbus_map_ring_valloc(pdev->xdev, &gnt_ref, 1, &vaddr);
if (err < 0) { if (err < 0) {
xenbus_dev_fatal(pdev->xdev, err, xenbus_dev_fatal(pdev->xdev, err,
"Error mapping other domain page in ours."); "Error mapping other domain page in ours.");
......
...@@ -809,7 +809,7 @@ static int scsiback_init_sring(struct vscsibk_info *info, grant_ref_t ring_ref, ...@@ -809,7 +809,7 @@ static int scsiback_init_sring(struct vscsibk_info *info, grant_ref_t ring_ref,
if (info->irq) if (info->irq)
return -1; return -1;
err = xenbus_map_ring_valloc(info->dev, ring_ref, &area); err = xenbus_map_ring_valloc(info->dev, &ring_ref, 1, &area);
if (err) if (err)
return err; return err;
......
This diff is collapsed.
...@@ -46,6 +46,10 @@ ...@@ -46,6 +46,10 @@
#include <xen/interface/io/xenbus.h> #include <xen/interface/io/xenbus.h>
#include <xen/interface/io/xs_wire.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. */ /* Register callback to watch this node. */
struct xenbus_watch struct xenbus_watch
{ {
...@@ -199,15 +203,19 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, ...@@ -199,15 +203,19 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
const char *pathfmt, ...); const char *pathfmt, ...);
int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state); 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_grant_ring(struct xenbus_device *dev, void *vaddr,
int xenbus_map_ring_valloc(struct xenbus_device *dev, unsigned int nr_pages, grant_ref_t *grefs);
int gnt_ref, void **vaddr); int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref, unsigned int nr_grefs, void **vaddr);
grant_handle_t *handle, void *vaddr); int xenbus_map_ring(struct xenbus_device *dev,
grant_ref_t *gnt_refs, unsigned int nr_grefs,
grant_handle_t *handles, unsigned long *vaddrs,
bool *leaked);
int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr); int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
int xenbus_unmap_ring(struct xenbus_device *dev, int xenbus_unmap_ring(struct xenbus_device *dev,
grant_handle_t handle, void *vaddr); grant_handle_t *handles, unsigned int nr_handles,
unsigned long *vaddrs);
int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port); int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
int xenbus_free_evtchn(struct xenbus_device *dev, int port); int xenbus_free_evtchn(struct xenbus_device *dev, int port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment