Skip to contentSkip to conversation

: xen-net{back, front}: Multiple transmit and receive queues

RFC PATCH Superseded Andrew J. Bennieston 5 participants 31 messages Jan 15, 2014 – Jan 27, 2014

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover : xen-net{back, front}: Multiple transmit and receive queues

This patch series implements multiple transmit and receive queues (i.e. multiple shared rings) for the xen virtual network interfaces.

The series is split up as follows:
- Patches 1 and 3 factor out the queue-specific data for netback and netfront respectively, and modify the rest of the code to use these as appropriate.
- Patches 2 and 4 introduce new XenStore keys to negotiate and use multiple shared rings and event channels, and code to connect these as appropriate.

All other transmit and receive processing remains unchanged, i.e. there is a kthread per queue and a NAPI context per queue.

The performance of these patches has been analysed in detail, with results available at:

http://wiki.xenproject.org/wiki/Xen-netback_and_xen-netfront_multi-queue_performance_testing

To summarise:
* Using multiple queues allows a VM to transmit at line rate on a 10 Gbit/s NIC, compared with a maximum aggregate throughput of 6 Gbit/s with a single queue.
* For intra-host VM--VM traffic, eight queues provide 171% of the throughput of a single queue; almost 12 Gbit/s instead of 6 Gbit/s.
* There is a corresponding increase in total CPU usage, i.e. this is a scaling out over available resources, not an efficiency improvement.
* Results depend on the availability of sufficient CPUs, as well as the distribution of interrupts and the distribution of TCP streams across the queues.

One open issue is how to deal with the tx_credit data for rate limiting. This used to exist on a per-VIF basis, and these patches move it to per-queue to avoid contention on concurrent access to the tx_credit data from multiple threads. This has the side effect of breaking the tx_credit accounting across the VIF as a whole. I cannot see a situation in which people would want to use both rate limiting and a high-performance multi-queue mode, but if this is problematic then it can be brought back to the VIF level, with appropriate protection. Obviously, it continues to work identically in the case where there is only one queue.

Queue selection is currently achieved via an L4 hash on the packet (i.e. TCP src/dst port, IP src/dst address) and is not negotiated between the frontend and backend, since only one option exists. Future patches to support other frontends (particularly Windows) will need to add some capability to negotiate not only the hash algorithm selection, but also allow the frontend to specify some parameters to this.

Queue-specific XenStore entries for ring references and event channels are stored hierarchically, i.e. under .../queue-N/... where N varies from 0 to one less than the requested number of queues (inclusive). If only one queue is requested, it falls back to the flat structure where the ring references and event channels are written at the same level as other vif information.

--
Andrew J. Bennieston

#1 lore raw

RFC PATCH 1/4 xen-netback: Factor queue-specific data into queue struct.

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netback, move the queue-specific data from struct xenvif into struct xenvif_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_netdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0 for a single queue and uses skb_get_rxhash() to compute the queue index otherwise.

---
 drivers/net/xen-netback/common.h    |   66 +++--
 drivers/net/xen-netback/interface.c |  308 +++++++++++++--------
 drivers/net/xen-netback/netback.c   |  516 +++++++++++++++++------------------
 drivers/net/xen-netback/xenbus.c    |   89 ++++--
 4 files changed, 556 insertions(+), 423 deletions(-)
drivers/net/xen-netback/common.h +42 -24
index c47794b..54d2eeb 100644
@@ -108,17 +108,19 @@ struct xenvif_rx_meta {
  */
 #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS * XEN_NETIF_RX_RING_SIZE)
 
-struct xenvif {
-	/* Unique identifier for this interface. */
-	domid_t          domid;
-	unsigned int     handle;
+struct xenvif;
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct xenvif *vif; /* Parent VIF */
 
 	/* Use NAPI for guest TX */
 	struct napi_struct napi;
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int tx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
 	struct xen_netif_tx_back_ring tx;
 	struct sk_buff_head tx_queue;
 	struct page *mmap_pages[MAX_PENDING_REQS];
@@ -140,7 +142,7 @@ struct xenvif {
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int rx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
 	struct xen_netif_rx_back_ring rx;
 	struct sk_buff_head rx_queue;
 
@@ -150,14 +152,27 @@ struct xenvif {
 	 */
 	RING_IDX rx_req_cons_peek;
 
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
 
 	/* We create one meta structure per ring request we consume, so
 	 * the maximum number is the same as the ring size.
 	 */
 	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+
+struct xenvif {
+	/* Unique identifier for this interface. */
+	domid_t          domid;
+	unsigned int     handle;
+
 	u8               fe_dev_addr[6];
 
 	/* Frontend feature information. */
@@ -171,12 +186,9 @@ struct xenvif {
 	/* Internal feature information. */
 	u8 can_queue:1;	    /* can queue packets for receiver? */
 
-	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
-	unsigned long   credit_bytes;
-	unsigned long   credit_usec;
-	unsigned long   remaining_credit;
-	struct timer_list credit_timeout;
-	u64 credit_window_start;
+	/* Queues */
+	unsigned int num_queues;
+	struct xenvif_queue *queues;
 
 	/* Statistics */
 	unsigned long rx_gso_checksum_fixup;
@@ -194,7 +206,9 @@ struct xenvif *xenvif_alloc(struct device *parent,
 			    domid_t domid,
 			    unsigned int handle);
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
+void xenvif_init_queue(struct xenvif_queue *queue);
+
+int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
 		   unsigned int rx_evtchn);
 void xenvif_disconnect(struct xenvif *vif);
@@ -205,23 +219,23 @@ void xenvif_xenbus_fini(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
-int xenvif_rx_ring_full(struct xenvif *vif);
+int xenvif_rx_ring_full(struct xenvif_queue *queue);
 
-int xenvif_must_stop_queue(struct xenvif *vif);
+int xenvif_must_stop_queue(struct xenvif_queue *queue);
 
 /* (Un)Map communication rings. */
-void xenvif_unmap_frontend_rings(struct xenvif *vif);
-int xenvif_map_frontend_rings(struct xenvif *vif,
+void xenvif_unmap_frontend_rings(struct xenvif_queue *queue);
+int xenvif_map_frontend_rings(struct xenvif_queue *queue,
 			      grant_ref_t tx_ring_ref,
 			      grant_ref_t rx_ring_ref);
 
 /* Check for SKBs from frontend and schedule backend processing */
-void xenvif_check_rx_xenvif(struct xenvif *vif);
+void xenvif_check_rx_xenvif(struct xenvif_queue *queue);
 
 /* Queue an SKB for transmission to the frontend */
-void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
+void xenvif_queue_tx_skb(struct xenvif_queue *queue, struct sk_buff *skb);
 /* Notify xenvif that ring now has space to send an skb to the frontend */
-void xenvif_notify_tx_completion(struct xenvif *vif);
+void xenvif_notify_tx_completion(struct xenvif_queue *queue);
 
 /* Prevent the device from generating any further traffic. */
 void xenvif_carrier_off(struct xenvif *vif);
@@ -229,11 +243,15 @@ void xenvif_carrier_off(struct xenvif *vif);
 /* Returns number of ring slots required to send an skb to the frontend */
 unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
-int xenvif_tx_action(struct xenvif *vif, int budget);
-void xenvif_rx_action(struct xenvif *vif);
+int xenvif_tx_action(struct xenvif_queue *queue, int budget);
+void xenvif_rx_action(struct xenvif_queue *queue);
 
 int xenvif_kthread(void *data);
 
+int xenvif_poll(struct napi_struct *napi, int budget);
+
+void xenvif_carrier_on(struct xenvif *vif);
+
 extern bool separate_tx_rx_irq;
 
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +193 -115

502 lines not on this page · raw message

drivers/net/xen-netback/netback.c +257 -259

1,261 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +64 -25

141 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

On Wed, Jan 15, 2014 at 04:23:21PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 114

Quoted 3 lines
drivers/net/xen-netback/common.h +3 -0
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */

Use "id" instead?

Quoted 23 lines
drivers/net/xen-netback/common.h +4 -2
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct xenvif *vif; /* Parent VIF */
 
 	/* Use NAPI for guest TX */
 	struct napi_struct napi;
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int tx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
 	struct xen_netif_tx_back_ring tx;
 	struct sk_buff_head tx_queue;
 	struct page *mmap_pages[MAX_PENDING_REQS];
@@ -140,7 +142,7 @@ struct xenvif {
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int rx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
 	struct xen_netif_rx_back_ring rx;
 	struct sk_buff_head rx_queue;
 

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 6 lines
drivers/net/xen-netback/common.h +1 -2
@@ -150,14 +152,27 @@ struct xenvif {
 	 */
 	RING_IDX rx_req_cons_peek;
 
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

Any reason to swtich back to array inside structure? This array is really large.

Quoted 15 lines
drivers/net/xen-netback/common.h +9 -0
 	/* We create one meta structure per ring request we consume, so
 	 * the maximum number is the same as the ring size.
 	 */
 	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+

[...]

Quoted 2 lines

+static u16 select_queue(struct net_device *dev, struct sk_buff *skb)

Suggest add xenvif_ prefix.

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 149

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+{
+	struct xenvif *vif = netdev_priv(dev);
+	u32 hash;
+	u16 queue_index;
+
+	/* First, check if there is only one queue */
+	if (vif->num_queues == 1) {
+		queue_index = 0;
+	}
+	else {

Coding style.

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 153

Quoted 4 lines
drivers/net/xen-netback/interface.c +4 -0
+		/* Use skb_get_rxhash to obtain an L4 hash if available */
+		hash = skb_get_rxhash(skb);
+		queue_index = (u16) (((u64)hash * vif->num_queues) >> 32);
+	}

Actually why do you special-case num_queues == 1? If it is an optimazation for old frontend then please add some comment.

Quoted 6 lines
drivers/net/xen-netback/interface.c +4 -0
+
+	return queue_index;
+}
+
 static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 167

Quoted 10 lines
drivers/net/xen-netback/interface.c +4 -2
 	struct xenvif *vif = netdev_priv(dev);
+	u16 queue_index = 0;
+	struct xenvif_queue *queue = NULL;
 
 	BUG_ON(skb->dev != dev);
 
-	/* Drop the packet if vif is not ready */
-	if (vif->task == NULL)
+	/* Drop the packet if the queues are not set up */
+	if (vif->num_queues < 1 || vif->queues == NULL)

You don't need both, do you? They should be strictly synchronized.

Quoted 10 lines
drivers/net/xen-netback/interface.c +8 -0
+		goto drop;
+
+	/* Obtain the queue to be used to transmit this packet */
+	queue_index = skb_get_queue_mapping(skb);
+	queue = &vif->queues[queue_index];
+
+	/* Drop the packet if queue is not ready */
+	if (queue->task == NULL)
 		goto drop;

[...]

drivers/net/xen-netback/interface.c static struct net_device_stats *xenvif_get_stats(struct net_device *dev) · line 213

Quoted 12 lines

static struct net_device_stats *xenvif_get_stats(struct net_device *dev)

drivers/net/xen-netback/interface.c +2 -5
@@ -163,20 +209,30 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
 
 static void xenvif_up(struct xenvif *vif)
 {
-	napi_enable(&vif->napi);
-	enable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		enable_irq(vif->rx_irq);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;

Better insert empty line here.

Quoted 9 lines
drivers/net/xen-netback/interface.c +8 -0
+	for (queue_index = 0; queue_index < vif->num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_enable(&queue->napi);
+		enable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			enable_irq(queue->rx_irq);
+		xenvif_check_rx_xenvif(queue);
+	}
 }

drivers/net/xen-netback/interface.c static struct net_device_stats *xenvif_get_stats(struct net_device *dev) · line 227

Quoted 10 lines
drivers/net/xen-netback/interface.c +2 -5
 
 static void xenvif_down(struct xenvif *vif)
 {
-	napi_disable(&vif->napi);
-	disable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		disable_irq(vif->rx_irq);
-	del_timer_sync(&vif->credit_timeout);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;

Ditto.

Quoted 10 lines
drivers/net/xen-netback/interface.c +8 -0
+	for (queue_index = 0; queue_index < vif->num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_disable(&queue->napi);
+		disable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			disable_irq(queue->rx_irq);
+		del_timer_sync(&queue->credit_timeout);
+	}
 }
 

[...]

Quoted 8 lines
drivers/net/xen-netback/xenbus.c +0 -4
@@ -622,20 +672,9 @@ static int connect_rings(struct backend_info *be)
 		val = 0;
 	vif->ipv6_csum = !!val;
 
-	/* Map the shared frame, irq etc. */
-	err = xenvif_connect(vif, tx_ring_ref, rx_ring_ref,
-			     tx_evtchn, rx_evtchn);
-	if (err) {

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be) · line 638

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +0 -7
-		xenbus_dev_fatal(dev, err,
-				 "mapping shared-frames %lu/%lu port tx %u rx %u",
-				 tx_ring_ref, rx_ring_ref,
-				 tx_evtchn, rx_evtchn);
-		return err;
-	}
 	return 0;
 }
 
-

Blank line change, not necessary.

Wei.

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -0
 /* ** Driver Registration ** */
 
 
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 7 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:21PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 114

Quoted 3 lines
drivers/net/xen-netback/common.h +3 -0
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */

Use "id" instead?

Ok; I suppose number implies "the number of queues", not "which queue is this?"

Quoted 27 lines
Quoted 27 lines
drivers/net/xen-netback/common.h +4 -2
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct xenvif *vif; /* Parent VIF */
 
  	/* Use NAPI for guest TX */
  	struct napi_struct napi;
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int tx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
  	struct xen_netif_tx_back_ring tx;
  	struct sk_buff_head tx_queue;
  	struct page *mmap_pages[MAX_PENDING_REQS];
@@ -140,7 +142,7 @@ struct xenvif {
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int rx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
  	struct xen_netif_rx_back_ring rx;
  	struct sk_buff_head rx_queue;
 
@@ -150,14 +152,27 @@ struct xenvif {
  	 */
  	RING_IDX rx_req_cons_peek;
 
Quoted 7 lines

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 3 lines
drivers/net/xen-netback/common.h +1 -2
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

Any reason to swtich back to array inside structure? This array is really large.

It was moved to a separate vmalloc because it was large, but now the array of queues is allocated through vmalloc anyway. I preferred to bring this back into the structure rather than have more allocations to track and remember to free at all relevant points. If there is any significant reason to split this out I'm happy to do so...

Quoted 17 lines
Quoted 15 lines
drivers/net/xen-netback/common.h +9 -0
  	/* We create one meta structure per ring request we consume, so
  	 * the maximum number is the same as the ring size.
  	 */
  	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+

[...]

Quoted 1 line
Quoted 4 lines
Quoted 1 line

+static u16 select_queue(struct net_device *dev, struct sk_buff *skb)

Suggest add xenvif_ prefix.

Ok.

Quoted 13 lines

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 149

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+{
+	struct xenvif *vif = netdev_priv(dev);
+	u32 hash;
+	u16 queue_index;
+
+	/* First, check if there is only one queue */
+	if (vif->num_queues == 1) {
+		queue_index = 0;
+	}
+	else {

Coding style.

Quoted 8 lines

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 153

Quoted 4 lines
drivers/net/xen-netback/interface.c +4 -0
+		/* Use skb_get_rxhash to obtain an L4 hash if available */
+		hash = skb_get_rxhash(skb);
+		queue_index = (u16) (((u64)hash * vif->num_queues) >> 32);
+	}

Actually why do you special-case num_queues == 1? If it is an optimazation for old frontend then please add some comment.

That was the intention. I'll add a comment to that effect.

Quoted 10 lines
Quoted 10 lines
drivers/net/xen-netback/interface.c +6 -0
+
+	return queue_index;
+}
+
  static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
  {
  	struct xenvif *vif = netdev_priv(dev);
+	u16 queue_index = 0;
+	struct xenvif_queue *queue = NULL;
Quoted 9 lines

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 167

Quoted 6 lines
  	BUG_ON(skb->dev != dev);
drivers/net/xen-netback/interface.c +2 -2
-	/* Drop the packet if vif is not ready */
-	if (vif->task == NULL)
+	/* Drop the packet if the queues are not set up */
+	if (vif->num_queues < 1 || vif->queues == NULL)

You don't need both, do you? They should be strictly synchronized.

Hmm... true. I'll change to just if (vif->num_queues < 1), since it states the intent more clearly than the pointer check.

Quoted 76 lines
Quoted 10 lines
drivers/net/xen-netback/interface.c +8 -0
+		goto drop;
+
+	/* Obtain the queue to be used to transmit this packet */
+	queue_index = skb_get_queue_mapping(skb);
+	queue = &vif->queues[queue_index];
+
+	/* Drop the packet if queue is not ready */
+	if (queue->task == NULL)
  		goto drop;

[...]

drivers/net/xen-netback/interface.c static struct net_device_stats *xenvif_get_stats(struct net_device *dev) · line 213

Quoted 12 lines

static struct net_device_stats *xenvif_get_stats(struct net_device *dev)

drivers/net/xen-netback/interface.c +2 -5
@@ -163,20 +209,30 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
 
  static void xenvif_up(struct xenvif *vif)
  {
-	napi_enable(&vif->napi);
-	enable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		enable_irq(vif->rx_irq);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;

Better insert empty line here.

Quoted 9 lines
drivers/net/xen-netback/interface.c +8 -0
+	for (queue_index = 0; queue_index < vif->num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_enable(&queue->napi);
+		enable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			enable_irq(queue->rx_irq);
+		xenvif_check_rx_xenvif(queue);
+	}
  }

drivers/net/xen-netback/interface.c static struct net_device_stats *xenvif_get_stats(struct net_device *dev) · line 227

Quoted 10 lines
drivers/net/xen-netback/interface.c +2 -5
 
  static void xenvif_down(struct xenvif *vif)
  {
-	napi_disable(&vif->napi);
-	disable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		disable_irq(vif->rx_irq);
-	del_timer_sync(&vif->credit_timeout);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;

Ditto.

Quoted 10 lines
drivers/net/xen-netback/interface.c +8 -0
+	for (queue_index = 0; queue_index < vif->num_queues; ++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_disable(&queue->napi);
+		disable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			disable_irq(queue->rx_irq);
+		del_timer_sync(&queue->credit_timeout);
+	}
  }
 

[...]

Quoted 17 lines
drivers/net/xen-netback/xenbus.c +0 -10
@@ -622,20 +672,9 @@ static int connect_rings(struct backend_info *be)
  		val = 0;
  	vif->ipv6_csum = !!val;
 
-	/* Map the shared frame, irq etc. */
-	err = xenvif_connect(vif, tx_ring_ref, rx_ring_ref,
-			     tx_evtchn, rx_evtchn);
-	if (err) {
-		xenbus_dev_fatal(dev, err,
-				 "mapping shared-frames %lu/%lu port tx %u rx %u",
-				 tx_ring_ref, rx_ring_ref,
-				 tx_evtchn, rx_evtchn);
-		return err;
-	}
  	return 0;
  }
 
Quoted 4 lines

Review static int connect_rings(struct backend_info *be) · line 638

Quoted 1 line
(quoted diff) +0 -1
-

Blank line change, not necessary.

I thought I'd caught all of those; must have missed one!

Andrew.

Quoted 7 lines

Wei.

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -1
  /* ** Driver Registration ** */
 
 
--

1.7.10.4

#4 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 12 lines · Andrew Bennieston
Quoted 7 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:21PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 114

Quoted 3 lines
drivers/net/xen-netback/common.h +3 -0
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */

Use "id" instead?

Ok; I suppose number implies "the number of queues", not "which queue is this?"

Right. "id" sounds more intuitive to me. And it saves you from some typing, big win! ;-)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/xen-netback/common.h +2 -0
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct xenvif *vif; /* Parent VIF */

[...]

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/xen-netback/common.h +0 -0
@@ -150,14 +152,27 @@ struct xenvif {
 	 */
 	RING_IDX rx_req_cons_peek;
 
Quoted 7 lines

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 3 lines
drivers/net/xen-netback/common.h +1 -2
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

Any reason to swtich back to array inside structure? This array is really large.

Quoted 6 lines

It was moved to a separate vmalloc because it was large, but now the array of queues is allocated through vmalloc anyway. I preferred to bring this back into the structure rather than have more allocations to track and remember to free at all relevant points. If there is any significant reason to split this out I'm happy to do so...

OK, if everything is allocated via vmalloc then I think it's fine.

Wei.

#5 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 10 lines · Wei Liu
Quoted 9 lines · Andrew Bennieston
Quoted 7 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:21PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 114

Quoted 3 lines
drivers/net/xen-netback/common.h +3 -0
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */

Use "id" instead?

Quoted 6 lines
Quoted 3 lines

Ok; I suppose number implies "the number of queues", not "which queue is this?"

Right. "id" sounds more intuitive to me. And it saves you from some typing, big win! ;-)

Actually it's more typing, since I've already typed "number" (and I don't think :%s/number/id/g is a safe thing to do!)... but I'll change it anyway. :)

Andrew

Quoted 29 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/xen-netback/common.h +2 -0
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct xenvif *vif; /* Parent VIF */

[...]

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/xen-netback/common.h +0 -0
@@ -150,14 +152,27 @@ struct xenvif {
  	 */
  	RING_IDX rx_req_cons_peek;
 
Quoted 7 lines

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 3 lines
drivers/net/xen-netback/common.h +1 -2
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

Any reason to swtich back to array inside structure? This array is really large.

Quoted 6 lines

It was moved to a separate vmalloc because it was large, but now the array of queues is allocated through vmalloc anyway. I preferred to bring this back into the structure rather than have more allocations to track and remember to free at all relevant points. If there is any significant reason to split this out I'm happy to do so...

OK, if everything is allocated via vmalloc then I think it's fine.

Wei.

#6 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

In reply to Andrew J. Bennieston
Quoted 41 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston
Subject: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netback, move the queue-specific data from struct xenvif into struct xenvif_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_netdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0 for a single queue and uses skb_get_rxhash() to compute the queue index otherwise.

---
 drivers/net/xen-netback/common.h    |   66 +++--
 drivers/net/xen-netback/interface.c |  308 +++++++++++++--------
 drivers/net/xen-netback/netback.c   |  516 +++++++++++++++++-------------
-----
 drivers/net/xen-netback/xenbus.c    |   89 ++++--
 4 files changed, 556 insertions(+), 423 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h
index c47794b..54d2eeb 100644

drivers/net/xen-netback/common.h +0 -0
@@ -108,17 +108,19 @@ struct xenvif_rx_meta {
  */
 #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS *
 XEN_NETIF_RX_RING_SIZE)

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 116

Quoted 10 lines
drivers/net/xen-netback/common.h +5 -4
 
-struct xenvif {
-	/* Unique identifier for this interface. */
-	domid_t          domid;
-	unsigned int     handle;
+struct xenvif;
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */

I wonder whether it would be neater to #define the name size here...

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 123

Quoted 9 lines
drivers/net/xen-netback/common.h +2 -1
+	struct xenvif *vif; /* Parent VIF */
 
 	/* Use NAPI for guest TX */
 	struct napi_struct napi;
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int tx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */

...and the IRQ name size here. It's kind of ugly to have + some_magic_value in array definitions.

Quoted 13 lines
drivers/net/xen-netback/common.h +0 -0
 	struct xen_netif_tx_back_ring tx;
 	struct sk_buff_head tx_queue;
drivers/net/xen-netback/common.h +1 -1
 	struct page *mmap_pages[MAX_PENDING_REQS];
@@ -140,7 +142,7 @@ struct xenvif {
 	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
 	unsigned int rx_irq;
 	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
 	struct xen_netif_rx_back_ring rx;
 	struct sk_buff_head rx_queue;
 

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 6 lines
drivers/net/xen-netback/common.h +1 -2
@@ -150,14 +152,27 @@ struct xenvif {
 	 */
 	RING_IDX rx_req_cons_peek;
 
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

I see you brought this back in line, which is reasonable as the queue is now a separately allocated struct.

Quoted 28 lines
drivers/net/xen-netback/common.h +14 -1
 	/* We create one meta structure per ring request we consume, so
 	 * the maximum number is the same as the ring size.
 	 */
 	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+
+struct xenvif {
+	/* Unique identifier for this interface. */
+	domid_t          domid;
+	unsigned int     handle;
+
 	u8               fe_dev_addr[6];
 
 	/* Frontend feature information. */
@@ -171,12 +186,9 @@ struct xenvif {
 	/* Internal feature information. */
 	u8 can_queue:1;	    /* can queue packets for receiver? */
 
-	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */

drivers/net/xen-netback/common.h struct xenvif { · line 193

Quoted 10 lines
drivers/net/xen-netback/common.h +3 -5
-	unsigned long   credit_bytes;
-	unsigned long   credit_usec;
-	unsigned long   remaining_credit;
-	struct timer_list credit_timeout;
-	u64 credit_window_start;
+	/* Queues */
+	unsigned int num_queues;
+	struct xenvif_queue *queues;
 
 	/* Statistics */

Do stats need to be per-queue (and then possibly aggregated at query time)?

Quoted 76 lines
drivers/net/xen-netback/common.h +10 -8
 	unsigned long rx_gso_checksum_fixup;
@@ -194,7 +206,9 @@ struct xenvif *xenvif_alloc(struct device *parent,
 			    domid_t domid,
 			    unsigned int handle);
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
+void xenvif_init_queue(struct xenvif_queue *queue);
+
+int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
 		   unsigned int rx_evtchn);
 void xenvif_disconnect(struct xenvif *vif);
@@ -205,23 +219,23 @@ void xenvif_xenbus_fini(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
-int xenvif_rx_ring_full(struct xenvif *vif);
+int xenvif_rx_ring_full(struct xenvif_queue *queue);
 
-int xenvif_must_stop_queue(struct xenvif *vif);
+int xenvif_must_stop_queue(struct xenvif_queue *queue);
 
 /* (Un)Map communication rings. */
-void xenvif_unmap_frontend_rings(struct xenvif *vif);
-int xenvif_map_frontend_rings(struct xenvif *vif,
+void xenvif_unmap_frontend_rings(struct xenvif_queue *queue);
+int xenvif_map_frontend_rings(struct xenvif_queue *queue,
 			      grant_ref_t tx_ring_ref,
 			      grant_ref_t rx_ring_ref);
 
 /* Check for SKBs from frontend and schedule backend processing */
-void xenvif_check_rx_xenvif(struct xenvif *vif);
+void xenvif_check_rx_xenvif(struct xenvif_queue *queue);
 
 /* Queue an SKB for transmission to the frontend */
-void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
+void xenvif_queue_tx_skb(struct xenvif_queue *queue, struct sk_buff
 *skb);
 /* Notify xenvif that ring now has space to send an skb to the frontend */
-void xenvif_notify_tx_completion(struct xenvif *vif);
+void xenvif_notify_tx_completion(struct xenvif_queue *queue);
 
 /* Prevent the device from generating any further traffic. */

void xenvif_carrier_off(struct xenvif *vif);

drivers/net/xen-netback/common.h +6 -2
@@ -229,11 +243,15 @@ void xenvif_carrier_off(struct xenvif *vif);
 /* Returns number of ring slots required to send an skb to the frontend */
 unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
-int xenvif_tx_action(struct xenvif *vif, int budget);
-void xenvif_rx_action(struct xenvif *vif);
+int xenvif_tx_action(struct xenvif_queue *queue, int budget);
+void xenvif_rx_action(struct xenvif_queue *queue);
 
 int xenvif_kthread(void *data);
 
+int xenvif_poll(struct napi_struct *napi, int budget);
+
+void xenvif_carrier_on(struct xenvif *vif);
+
 extern bool separate_tx_rx_irq;
 
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen- renamed from drivers/net/xen-netback/interface.c +0 -0

netback/interface.c
index fff8cdd..0113324 100644

drivers/net/xen-netback/interface.c +0 -1
@@ -34,7 +34,6 @@
 #include <linux/ethtool.h>
 #include <linux/rtnetlink.h>
 #include <linux/if_vlan.h>
-#include <linux/vmalloc.h>
 
 #include <xen/events.h>
 #include <asm/xen/hypercall.h>

drivers/net/xen-netback/interface.c line 48

Quoted 8 lines
drivers/net/xen-netback/interface.c +4 -0
@@ -42,32 +41,50 @@
 #define XENVIF_QUEUE_LENGTH 32
 #define XENVIF_NAPI_WEIGHT  64
 
+static inline void xenvif_wake_queue(struct xenvif_queue *queue)
+{
+	netif_tx_wake_queue(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 >number));

Might be neater to declare some stack variables for dev and number to avoid the long line.

drivers/net/xen-netback/interface.c

Quoted 7 lines
drivers/net/xen-netback/interface.c +6 -0
+}
+
+static inline void xenvif_stop_queue(struct xenvif_queue *queue)
+{
+	netif_tx_stop_queue(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 >number));

Ditto.

drivers/net/xen-netback/interface.c

Quoted 7 lines
drivers/net/xen-netback/interface.c +6 -0
+}
+
+static inline int xenvif_queue_stopped(struct xenvif_queue *queue)
+{
+	return netif_tx_queue_stopped(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 >number));

Ditto.

drivers/net/xen-netback/interface.c

Quoted 13 lines
drivers/net/xen-netback/interface.c +4 -2
+}
+
 int xenvif_schedulable(struct xenvif *vif)
 {
 	return netif_running(vif->dev) && netif_carrier_ok(vif->dev);
 }
 
-static int xenvif_rx_schedulable(struct xenvif *vif)
+static int xenvif_rx_schedulable(struct xenvif_queue *queue)
 {
-	return xenvif_schedulable(vif) && !xenvif_rx_ring_full(vif);
+	return xenvif_schedulable(queue->vif) &&
 !xenvif_rx_ring_full(queue);

I guess your patches have not been re-based onto net-next? xenvif_ring_full() and xenvif_rx_schedulable() went away in c/s ca2f09f2b2c6c25047cfc545d057c4edfcfe561c (xen-netback: improve guest-receive-side flow control).

Can you rebase? Eventual patches will need to go into net-next.

Paul

Quoted 60 lines
drivers/net/xen-netback/interface.c +7 -7
 }
 
 static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id)
 {
-	struct xenvif *vif = dev_id;
+	struct xenvif_queue *queue = dev_id;
 
-	if (RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
-		napi_schedule(&vif->napi);
+	if (RING_HAS_UNCONSUMED_REQUESTS(&queue->tx))
+		napi_schedule(&queue->napi);
 
 	return IRQ_HANDLED;
 }
 
-static int xenvif_poll(struct napi_struct *napi, int budget)
+int xenvif_poll(struct napi_struct *napi, int budget)
 {
-	struct xenvif *vif = container_of(napi, struct xenvif, napi);
+	struct xenvif_queue *queue = container_of(napi, struct
 xenvif_queue, napi);
 	int work_done;
 
-	work_done = xenvif_tx_action(vif, budget);
+	work_done = xenvif_tx_action(queue, budget);
 
 	if (work_done < budget) {
 		int more_to_do = 0;
@@ -91,7 +108,7 @@ static int xenvif_poll(struct napi_struct *napi, int
 budget)
 
 		local_irq_save(flags);
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,
 more_to_do);
+		RING_FINAL_CHECK_FOR_REQUESTS(&queue->tx,
 more_to_do);
drivers/net/xen-netback/interface.c +3 -3
 		if (!more_to_do)
 			__napi_complete(napi);
@@ -103,10 +120,10 @@ static int xenvif_poll(struct napi_struct *napi, int
 budget)
 
 static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
 {
-	struct xenvif *vif = dev_id;
+	struct xenvif_queue *queue = dev_id;
 
-	if (xenvif_rx_schedulable(vif))
-		netif_wake_queue(vif->dev);
+	if (xenvif_rx_schedulable(queue))
+		xenvif_wake_queue(queue);
 
 	return IRQ_HANDLED;

}

drivers/net/xen-netback/interface.c +0 -0
@@ -119,27 +136,56 @@ static irqreturn_t xenvif_interrupt(int irq, void
 *dev_id)
 	return IRQ_HANDLED;
 }
 

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void · line 149

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+static u16 select_queue(struct net_device *dev, struct sk_buff *skb)
+{
+	struct xenvif *vif = netdev_priv(dev);
+	u32 hash;
+	u16 queue_index;
+
+	/* First, check if there is only one queue */
+	if (vif->num_queues == 1) {
+		queue_index = 0;
+	}

Style.

Quoted 13 lines
drivers/net/xen-netback/interface.c +9 -0
+	else {
+		/* Use skb_get_rxhash to obtain an L4 hash if available */
+		hash = skb_get_rxhash(skb);
+		queue_index = (u16) (((u64)hash * vif->num_queues) >>
 32);
+	}
+
+	return queue_index;
+}
+
 static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xenvif *vif = netdev_priv(dev);

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 168

Quoted 10 lines
drivers/net/xen-netback/interface.c +5 -2
+	u16 queue_index = 0;
+	struct xenvif_queue *queue = NULL;
 
 	BUG_ON(skb->dev != dev);
 
-	/* Drop the packet if vif is not ready */
-	if (vif->task == NULL)
+	/* Drop the packet if the queues are not set up */
+	if (vif->num_queues < 1 || vif->queues == NULL)
+		goto drop;

Just do the former test and ASSERT the second.

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 171

Quoted 3 lines
drivers/net/xen-netback/interface.c +3 -0
+
+	/* Obtain the queue to be used to transmit this packet */
+	queue_index = skb_get_queue_mapping(skb);

Personally, I'd stick a range check here.

Quoted 2,014 lines
drivers/net/xen-netback/interface.c +9 -5
+	queue = &vif->queues[queue_index];
+
+	/* Drop the packet if queue is not ready */
+	if (queue->task == NULL)
 		goto drop;
 
 	/* Drop the packet if the target domain has no receive buffers. */
-	if (!xenvif_rx_schedulable(vif))
+	if (!xenvif_rx_schedulable(queue))
 		goto drop;
 
 	/* Reserve ring slots for the worst-case number of fragments. */
-	vif->rx_req_cons_peek += xenvif_count_skb_slots(vif, skb);
+	queue->rx_req_cons_peek += xenvif_count_skb_slots(vif, skb);
 
-	if (vif->can_queue && xenvif_must_stop_queue(vif))
-		netif_stop_queue(dev);
+	if (vif->can_queue && xenvif_must_stop_queue(queue))
+		xenvif_stop_queue(queue);
 
-	xenvif_queue_tx_skb(vif, skb);
+	xenvif_queue_tx_skb(queue, skb);
 
drivers/net/xen-netback/interface.c +3 -3
 	return NETDEV_TX_OK;
@@ -149,10 +195,10 @@ static int xenvif_start_xmit(struct sk_buff *skb,
 struct net_device *dev)
 	return NETDEV_TX_OK;
 }
 
-void xenvif_notify_tx_completion(struct xenvif *vif)
+void xenvif_notify_tx_completion(struct xenvif_queue *queue)
 {
-	if (netif_queue_stopped(vif->dev) && xenvif_rx_schedulable(vif))
-		netif_wake_queue(vif->dev);
+	if (xenvif_queue_stopped(queue) &&
 xenvif_rx_schedulable(queue))
+		xenvif_wake_queue(queue);
 }

static struct net_device_stats *xenvif_get_stats(struct net_device *dev)

drivers/net/xen-netback/interface.c +25 -12
@@ -163,20 +209,30 @@ static struct net_device_stats
 *xenvif_get_stats(struct net_device *dev)
 
 static void xenvif_up(struct xenvif *vif)
 {
-	napi_enable(&vif->napi);
-	enable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		enable_irq(vif->rx_irq);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_enable(&queue->napi);
+		enable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			enable_irq(queue->rx_irq);
+		xenvif_check_rx_xenvif(queue);
+	}
 }
 
 static void xenvif_down(struct xenvif *vif)
 {
-	napi_disable(&vif->napi);
-	disable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		disable_irq(vif->rx_irq);
-	del_timer_sync(&vif->credit_timeout);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_disable(&queue->napi);
+		disable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			disable_irq(queue->rx_irq);
+		del_timer_sync(&queue->credit_timeout);
+	}
 }
 
 static int xenvif_open(struct net_device *dev)
@@ -184,7 +240,7 @@ static int xenvif_open(struct net_device *dev)
 	struct xenvif *vif = netdev_priv(dev);
 	if (netif_carrier_ok(dev))
 		xenvif_up(vif);
-	netif_start_queue(dev);
+	netif_tx_start_all_queues(dev);
 	return 0;
 }
 
@@ -193,7 +249,7 @@ static int xenvif_close(struct net_device *dev)
 	struct xenvif *vif = netdev_priv(dev);
 	if (netif_carrier_ok(dev))
 		xenvif_down(vif);
-	netif_stop_queue(dev);
+	netif_tx_stop_all_queues(dev);
 	return 0;
 }
 
@@ -287,6 +343,7 @@ static const struct net_device_ops
 xenvif_netdev_ops = {
 	.ndo_fix_features = xenvif_fix_features,
 	.ndo_set_mac_address = eth_mac_addr,
 	.ndo_validate_addr   = eth_validate_addr,
+	.ndo_select_queue = select_queue,
 };
 

struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,

drivers/net/xen-netback/interface.c +1 -2
@@ -296,10 +353,9 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 	struct net_device *dev;
 	struct xenvif *vif;
 	char name[IFNAMSIZ] = {};
-	int i;
 
 	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev(sizeof(struct xenvif), name, ether_setup);
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
 	if (dev == NULL) {
 		pr_warn("Could not allocate netdev for %s\n", name);
drivers/net/xen-netback/interface.c +3 -12
 		return ERR_PTR(-ENOMEM);
@@ -309,24 +365,15 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 
 	vif = netdev_priv(dev);
 
-	vif->grant_copy_op = vmalloc(sizeof(struct gnttab_copy) *
-				     MAX_GRANT_COPY_OPS);
-	if (vif->grant_copy_op == NULL) {
-		pr_warn("Could not allocate grant copy space for %s\n",
 name);
-		free_netdev(dev);
-		return ERR_PTR(-ENOMEM);
-	}
-
 	vif->domid  = domid;
 	vif->handle = handle;
 	vif->can_sg = 1;
 	vif->ip_csum = 1;
 	vif->dev = dev;
 
-	vif->credit_bytes = vif->remaining_credit = ~0UL;
-	vif->credit_usec  = 0UL;
-	init_timer(&vif->credit_timeout);
-	vif->credit_window_start = get_jiffies_64();
+	/* Start out with no queues */
+	vif->num_queues = 0;
+	vif->queues = NULL;
 
drivers/net/xen-netback/interface.c +0 -10
 	dev->netdev_ops	= &xenvif_netdev_ops;
 	dev->hw_features = NETIF_F_SG |
@@ -337,16 +384,6 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 
 	dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
 
-	skb_queue_head_init(&vif->rx_queue);
-	skb_queue_head_init(&vif->tx_queue);
-
-	vif->pending_cons = 0;
-	vif->pending_prod = MAX_PENDING_REQS;
-	for (i = 0; i < MAX_PENDING_REQS; i++)
-		vif->pending_ring[i] = i;
-	for (i = 0; i < MAX_PENDING_REQS; i++)
-		vif->mmap_pages[i] = NULL;
-
 	/*
 	 * Initialise a dummy MAC address. We choose the numerically
drivers/net/xen-netback/interface.c +0 -2
 	 * largest non-broadcast address to prevent the address getting
@@ -356,8 +393,6 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 	memset(dev->dev_addr, 0xFF, ETH_ALEN);
 	dev->dev_addr[0] &= ~0x01;
 
-	netif_napi_add(dev, &vif->napi, xenvif_poll,
 XENVIF_NAPI_WEIGHT);
-
 	netif_carrier_off(dev);
drivers/net/xen-netback/interface.c +64 -38
 	err = register_netdev(dev);
@@ -374,84 +409,110 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 	return vif;
 }
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
+void xenvif_init_queue(struct xenvif_queue *queue)
+{
+	int i;
+
+	queue->credit_bytes = queue->remaining_credit = ~0UL;
+	queue->credit_usec  = 0UL;
+	init_timer(&queue->credit_timeout);
+	queue->credit_window_start = get_jiffies_64();
+
+	skb_queue_head_init(&queue->rx_queue);
+	skb_queue_head_init(&queue->tx_queue);
+
+	queue->pending_cons = 0;
+	queue->pending_prod = MAX_PENDING_REQS;
+	for (i = 0; i < MAX_PENDING_REQS; ++i) {
+		queue->pending_ring[i] = i;
+		queue->mmap_pages[i] = NULL;
+	}
+
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+}
+
+void xenvif_carrier_on(struct xenvif *vif)
+{
+	rtnl_lock();
+	if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
+		dev_set_mtu(vif->dev, ETH_DATA_LEN);
+	netdev_update_features(vif->dev);
+	netif_carrier_on(vif->dev);
+	if (netif_running(vif->dev))
+		xenvif_up(vif);
+	rtnl_unlock();
+}
+
+int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
 		   unsigned int rx_evtchn)
 {
 	struct task_struct *task;
 	int err = -ENOMEM;
 
-	BUG_ON(vif->tx_irq);
-	BUG_ON(vif->task);
+	BUG_ON(queue->tx_irq);
+	BUG_ON(queue->task);
 
-	err = xenvif_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
+	err = xenvif_map_frontend_rings(queue, tx_ring_ref, rx_ring_ref);
 	if (err < 0)
 		goto err;
 
 	if (tx_evtchn == rx_evtchn) {
 		/* feature-split-event-channels == 0 */
 		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, tx_evtchn, xenvif_interrupt, 0,
-			vif->dev->name, vif);
+			queue->vif->domid, tx_evtchn, xenvif_interrupt, 0,
+			queue->name, queue);
 		if (err < 0)
 			goto err_unmap;
-		vif->tx_irq = vif->rx_irq = err;
-		disable_irq(vif->tx_irq);
+		queue->tx_irq = queue->rx_irq = err;
+		disable_irq(queue->tx_irq);
 	} else {
 		/* feature-split-event-channels == 1 */
-		snprintf(vif->tx_irq_name, sizeof(vif->tx_irq_name),
-			 "%s-tx", vif->dev->name);
+		snprintf(queue->tx_irq_name, sizeof(queue->tx_irq_name),
+			 "%s-tx", queue->name);
 		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, tx_evtchn, xenvif_tx_interrupt, 0,
-			vif->tx_irq_name, vif);
+			queue->vif->domid, tx_evtchn, xenvif_tx_interrupt,
 0,
+			queue->tx_irq_name, queue);
 		if (err < 0)
 			goto err_unmap;
-		vif->tx_irq = err;
-		disable_irq(vif->tx_irq);
+		queue->tx_irq = err;
+		disable_irq(queue->tx_irq);
 
-		snprintf(vif->rx_irq_name, sizeof(vif->rx_irq_name),
-			 "%s-rx", vif->dev->name);
+		snprintf(queue->rx_irq_name, sizeof(queue->rx_irq_name),
+			 "%s-rx", queue->name);
 		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, rx_evtchn, xenvif_rx_interrupt, 0,
-			vif->rx_irq_name, vif);
+			queue->vif->domid, rx_evtchn, xenvif_rx_interrupt,
 0,
+			queue->rx_irq_name, queue);
 		if (err < 0)
 			goto err_tx_unbind;
-		vif->rx_irq = err;
-		disable_irq(vif->rx_irq);
+		queue->rx_irq = err;
+		disable_irq(queue->rx_irq);
 	}
 
-	init_waitqueue_head(&vif->wq);
+	init_waitqueue_head(&queue->wq);
 	task = kthread_create(xenvif_kthread,
-			      (void *)vif, "%s", vif->dev->name);
+			      (void *)queue, "%s", queue->name);
 	if (IS_ERR(task)) {
-		pr_warn("Could not allocate kthread for %s\n", vif->dev-
 >name);
+		pr_warn("Could not allocate kthread for %s\n", queue-
 >name);
 		err = PTR_ERR(task);
 		goto err_rx_unbind;
 	}
 
-	vif->task = task;
-
-	rtnl_lock();
-	if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
-		dev_set_mtu(vif->dev, ETH_DATA_LEN);
-	netdev_update_features(vif->dev);
-	netif_carrier_on(vif->dev);
-	if (netif_running(vif->dev))
-		xenvif_up(vif);
-	rtnl_unlock();
+	queue->task = task;
 
-	wake_up_process(vif->task);
+	wake_up_process(queue->task);
 
 	return 0;
 
 err_rx_unbind:
-	unbind_from_irqhandler(vif->rx_irq, vif);
-	vif->rx_irq = 0;
+	unbind_from_irqhandler(queue->rx_irq, queue);
+	queue->rx_irq = 0;
 err_tx_unbind:
-	unbind_from_irqhandler(vif->tx_irq, vif);
-	vif->tx_irq = 0;
+	unbind_from_irqhandler(queue->tx_irq, queue);
+	queue->tx_irq = 0;

err_unmap:

drivers/net/xen-netback/interface.c +35 -16
-	xenvif_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(queue);
 err:
 	module_put(THIS_MODULE);
 	return err;
@@ -470,34 +531,51 @@ void xenvif_carrier_off(struct xenvif *vif)
 
 void xenvif_disconnect(struct xenvif *vif)
 {
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+
 	if (netif_carrier_ok(vif->dev))
 		xenvif_carrier_off(vif);
 
-	if (vif->task) {
-		kthread_stop(vif->task);
-		vif->task = NULL;
-	}
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
 
-	if (vif->tx_irq) {
-		if (vif->tx_irq == vif->rx_irq)
-			unbind_from_irqhandler(vif->tx_irq, vif);
-		else {
-			unbind_from_irqhandler(vif->tx_irq, vif);
-			unbind_from_irqhandler(vif->rx_irq, vif);
+		if (queue->task) {
+			kthread_stop(queue->task);
+			queue->task = NULL;
 		}
-		vif->tx_irq = 0;
+
+		if (queue->tx_irq) {
+			if (queue->tx_irq == queue->rx_irq)
+				unbind_from_irqhandler(queue->tx_irq,
 queue);
+			else {
+				unbind_from_irqhandler(queue->tx_irq,
 queue);
+				unbind_from_irqhandler(queue->rx_irq,
 queue);
+			}
+			queue->tx_irq = 0;
+		}
+
+		xenvif_unmap_frontend_rings(queue);
 	}
 
-	xenvif_unmap_frontend_rings(vif);
+
 }
 
 void xenvif_free(struct xenvif *vif)
 {
-	netif_napi_del(&vif->napi);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
 
-	unregister_netdev(vif->dev);
+	for(queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		netif_napi_del(&queue->napi);
+	}
 
-	vfree(vif->grant_copy_op);
+	/* Free the array of queues */
+	vfree(vif->queues);
+	vif->num_queues = 0;
+	vif->queues = 0;
+
+	unregister_netdev(vif->dev);
 	free_netdev(vif->dev);
 
 	module_put(THIS_MODULE);
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 7842555..586e741 100644

drivers/net/xen-netback/netback.c +10 -10
@@ -76,38 +76,38 @@ module_param(fatal_skb_slots, uint, 0444);
  * one or more merged tx requests, otherwise it is the continuation of
  * previous tx request.
  */
-static inline int pending_tx_is_head(struct xenvif *vif, RING_IDX idx)
+static inline int pending_tx_is_head(struct xenvif_queue *queue,
 RING_IDX idx)
 {
-	return vif->pending_tx_info[idx].head !=
 INVALID_PENDING_RING_IDX;
+	return queue->pending_tx_info[idx].head !=
 INVALID_PENDING_RING_IDX;
 }
 
-static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
+static void xenvif_idx_release(struct xenvif_queue *queue, u16
 pending_idx,
 			       u8 status);
 
-static void make_tx_response(struct xenvif *vif,
+static void make_tx_response(struct xenvif_queue *queue,
 			     struct xen_netif_tx_request *txp,
 			     s8       st);
 
-static inline int tx_work_todo(struct xenvif *vif);
-static inline int rx_work_todo(struct xenvif *vif);
+static inline int tx_work_todo(struct xenvif_queue *queue);
+static inline int rx_work_todo(struct xenvif_queue *queue);
 
-static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
+static struct xen_netif_rx_response *make_rx_response(struct
 xenvif_queue *queue,
 					     u16      id,
 					     s8       st,
 					     u16      offset,
 					     u16      size,
 					     u16      flags);
 
-static inline unsigned long idx_to_pfn(struct xenvif *vif,
+static inline unsigned long idx_to_pfn(struct xenvif_queue *queue,
 				       u16 idx)
 {
-	return page_to_pfn(vif->mmap_pages[idx]);
+	return page_to_pfn(queue->mmap_pages[idx]);
 }
 
-static inline unsigned long idx_to_kaddr(struct xenvif *vif,
+static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
 					 u16 idx)

{

drivers/net/xen-netback/netback.c +3 -3
-	return (unsigned long)pfn_to_kaddr(idx_to_pfn(vif, idx));
+	return (unsigned long)pfn_to_kaddr(idx_to_pfn(queue, idx));
 }
 
 /* This is a miniumum size for the linear area to avoid lots of
@@ -132,10 +132,10 @@ static inline pending_ring_idx_t
 pending_index(unsigned i)
 	return i & (MAX_PENDING_REQS-1);
 }
 
-static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif)
+static inline pending_ring_idx_t nr_pending_reqs(struct xenvif_queue
 *queue)
 {
 	return MAX_PENDING_REQS -
-		vif->pending_prod + vif->pending_cons;
+		queue->pending_prod + queue->pending_cons;
 }

static int max_required_rx_slots(struct xenvif *vif)

drivers/net/xen-netback/netback.c +10 -10
@@ -149,25 +149,25 @@ static int max_required_rx_slots(struct xenvif *vif)
 	return max;
 }
 
-int xenvif_rx_ring_full(struct xenvif *vif)
+int xenvif_rx_ring_full(struct xenvif_queue *queue)
 {
-	RING_IDX peek   = vif->rx_req_cons_peek;
-	RING_IDX needed = max_required_rx_slots(vif);
+	RING_IDX peek   = queue->rx_req_cons_peek;
+	RING_IDX needed = max_required_rx_slots(queue->vif);
 
-	return ((vif->rx.sring->req_prod - peek) < needed) ||
-	       ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) <
 needed);
+	return ((queue->rx.sring->req_prod - peek) < needed) ||
+	       ((queue->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) <
 needed);
 }
 
-int xenvif_must_stop_queue(struct xenvif *vif)
+int xenvif_must_stop_queue(struct xenvif_queue *queue)
 {
-	if (!xenvif_rx_ring_full(vif))
+	if (!xenvif_rx_ring_full(queue))
 		return 0;
 
-	vif->rx.sring->req_event = vif->rx_req_cons_peek +
-		max_required_rx_slots(vif);
+	queue->rx.sring->req_event = queue->rx_req_cons_peek +
+		max_required_rx_slots(queue->vif);
 	mb(); /* request notification /then/ check the queue */
 
-	return xenvif_rx_ring_full(vif);
+	return xenvif_rx_ring_full(queue);
 }

/*

drivers/net/xen-netback/netback.c +2 -2
@@ -306,13 +306,13 @@ struct netrx_pending_operations {
 	grant_ref_t copy_gref;
 };
 
-static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif *vif,
+static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif_queue
 *queue,
 						 struct
 netrx_pending_operations *npo)
 {
 	struct xenvif_rx_meta *meta;
 	struct xen_netif_rx_request *req;
 
-	req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+	req = RING_GET_REQUEST(&queue->rx, queue->rx.req_cons++);
 
drivers/net/xen-netback/netback.c +1 -1
 	meta = npo->meta + npo->meta_prod++;
 	meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
@@ -330,7 +330,7 @@ static struct xenvif_rx_meta
 *get_next_rx_buffer(struct xenvif *vif,
  * Set up the grant operations for this fragment. If it's a flipping
  * interface, we also set up the unmap request from here.
  */
-static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
+static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct
 sk_buff *skb,
 				 struct netrx_pending_operations *npo,
drivers/net/xen-netback/netback.c +1 -1
 				 struct page *page, unsigned long size,
 				 unsigned long offset, int *head)
@@ -365,7 +365,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
 			 */
 			BUG_ON(*head);
 
-			meta = get_next_rx_buffer(vif, npo);
+			meta = get_next_rx_buffer(queue, npo);
 		}
 
drivers/net/xen-netback/netback.c +1 -1
 		if (npo->copy_off + bytes > MAX_BUFFER_OFFSET)
@@ -379,7 +379,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
 		copy_gop->source.u.gmfn =
 virt_to_mfn(page_address(page));
 		copy_gop->source.offset = offset;
 
-		copy_gop->dest.domid = vif->domid;
+		copy_gop->dest.domid = queue->vif->domid;
 		copy_gop->dest.offset = npo->copy_off;
drivers/net/xen-netback/netback.c +4 -3
 		copy_gop->dest.u.ref = npo->copy_gref;
@@ -404,8 +404,8 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
 		else
 			gso_type = XEN_NETIF_GSO_TYPE_NONE;
 
-		if (*head && ((1 << gso_type) & vif->gso_mask))
-			vif->rx.req_cons++;
+		if (*head && ((1 << gso_type) & queue->vif->gso_mask))
+			queue->rx.req_cons++;
 
 		*head = 0; /* There must be something in this buffer now. */
@@ -425,7 +425,8 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
  * frontend-side LRO).
  */
 static int xenvif_gop_skb(struct sk_buff *skb,
-			  struct netrx_pending_operations *npo)
+			  struct netrx_pending_operations *npo,
+			  struct xenvif_queue *queue)
 {
 	struct xenvif *vif = netdev_priv(skb->dev);
drivers/net/xen-netback/netback.c +1 -1
 	int nr_frags = skb_shinfo(skb)->nr_frags;
@@ -453,7 +454,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
 
 	/* Set up a GSO prefix descriptor, if necessary */
 	if ((1 << gso_type) & vif->gso_prefix_mask) {
-		req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+		req = RING_GET_REQUEST(&queue->rx, queue-
 >rx.req_cons++);
 		meta = npo->meta + npo->meta_prod++;
 		meta->gso_type = gso_type;
drivers/net/xen-netback/netback.c +3 -3
 		meta->gso_size = gso_size;
@@ -461,7 +462,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
 		meta->id = req->id;
 	}
 
-	req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+	req = RING_GET_REQUEST(&queue->rx, queue->rx.req_cons++);
 	meta = npo->meta + npo->meta_prod++;
 
 	if ((1 << gso_type) & vif->gso_mask) {
@@ -485,13 +486,13 @@ static int xenvif_gop_skb(struct sk_buff *skb,
 		if (data + len > skb_tail_pointer(skb))
 			len = skb_tail_pointer(skb) - data;
 
-		xenvif_gop_frag_copy(vif, skb, npo,
+		xenvif_gop_frag_copy(queue, skb, npo,
 				     virt_to_page(data), len, offset, &head);
 		data += len;
 	}
 
 	for (i = 0; i < nr_frags; i++) {
-		xenvif_gop_frag_copy(vif, skb, npo,
+		xenvif_gop_frag_copy(queue, skb, npo,
 				     skb_frag_page(&skb_shinfo(skb)-
 >frags[i]),
 				     skb_frag_size(&skb_shinfo(skb)->frags[i]),
drivers/net/xen-netback/netback.c +1 -1
 				     skb_shinfo(skb)->frags[i].page_offset,
@@ -527,7 +528,7 @@ static int xenvif_check_gop(struct xenvif *vif, int
 nr_meta_slots,
 	return status;
 }
 
-static void xenvif_add_frag_responses(struct xenvif *vif, int status,
+static void xenvif_add_frag_responses(struct xenvif_queue *queue, int
 status,
 				      struct xenvif_rx_meta *meta,
drivers/net/xen-netback/netback.c +1 -1
 				      int nr_meta_slots)
 {
@@ -548,7 +549,7 @@ static void xenvif_add_frag_responses(struct xenvif
 *vif, int status,
 			flags = XEN_NETRXF_more_data;
 
 		offset = 0;
-		make_rx_response(vif, meta[i].id, status, offset,
+		make_rx_response(queue, meta[i].id, status, offset,
 				 meta[i].size, flags);
 	}

}

drivers/net/xen-netback/netback.c +15 -18
@@ -557,12 +558,12 @@ struct skb_cb_overlay {
 	int meta_slots_used;
 };
 
-static void xenvif_kick_thread(struct xenvif *vif)
+static void xenvif_kick_thread(struct xenvif_queue *queue)
 {
-	wake_up(&vif->wq);
+	wake_up(&queue->wq);
 }
 
-void xenvif_rx_action(struct xenvif *vif)
+void xenvif_rx_action(struct xenvif_queue *queue)
 {
 	s8 status;
 	u16 flags;
@@ -578,20 +579,19 @@ void xenvif_rx_action(struct xenvif *vif)
 	int need_to_notify = 0;
 
 	struct netrx_pending_operations npo = {
-		.copy  = vif->grant_copy_op,
-		.meta  = vif->meta,
+		.copy  = queue->grant_copy_op,
+		.meta  = queue->meta,
 	};
 
 	skb_queue_head_init(&rxq);
 
 	count = 0;
 
-	while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) {
-		vif = netdev_priv(skb->dev);
+	while ((skb = skb_dequeue(&queue->rx_queue)) != NULL) {
 		nr_frags = skb_shinfo(skb)->nr_frags;
 
 		sco = (struct skb_cb_overlay *)skb->cb;
-		sco->meta_slots_used = xenvif_gop_skb(skb, &npo);
+		sco->meta_slots_used = xenvif_gop_skb(skb, &npo, queue);
 
 		count += nr_frags + 1;
 
@@ -603,28 +603,26 @@ void xenvif_rx_action(struct xenvif *vif)
 			break;
 	}
 
-	BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta));
+	BUG_ON(npo.meta_prod > ARRAY_SIZE(queue->meta));
 
 	if (!npo.copy_prod)
 		return;
 
 	BUG_ON(npo.copy_prod > MAX_GRANT_COPY_OPS);
-	gnttab_batch_copy(vif->grant_copy_op, npo.copy_prod);
+	gnttab_batch_copy(queue->grant_copy_op, npo.copy_prod);
 
 	while ((skb = __skb_dequeue(&rxq)) != NULL) {
 		sco = (struct skb_cb_overlay *)skb->cb;
 
-		vif = netdev_priv(skb->dev);
-
-		if ((1 << vif->meta[npo.meta_cons].gso_type) &
-		    vif->gso_prefix_mask) {
-			resp = RING_GET_RESPONSE(&vif->rx,
-						 vif->rx.rsp_prod_pvt++);
+		if ((1 << queue->meta[npo.meta_cons].gso_type) &
+		    queue->vif->gso_prefix_mask) {
+			resp = RING_GET_RESPONSE(&queue->rx,
+						 queue->rx.rsp_prod_pvt++);
 
 			resp->flags = XEN_NETRXF_gso_prefix |
 XEN_NETRXF_more_data;
 
-			resp->offset = vif->meta[npo.meta_cons].gso_size;
-			resp->id = vif->meta[npo.meta_cons].id;
+			resp->offset = queue-
 >meta[npo.meta_cons].gso_size;
+			resp->id = queue->meta[npo.meta_cons].id;
 			resp->status = sco->meta_slots_used;
drivers/net/xen-netback/netback.c +3 -3
 			npo.meta_cons++;
@@ -632,10 +630,10 @@ void xenvif_rx_action(struct xenvif *vif)
 		}
 
 
-		vif->dev->stats.tx_bytes += skb->len;
-		vif->dev->stats.tx_packets++;
+		queue->vif->dev->stats.tx_bytes += skb->len;
+		queue->vif->dev->stats.tx_packets++;
 
-		status = xenvif_check_gop(vif, sco->meta_slots_used,
 &npo);
+		status = xenvif_check_gop(queue->vif, sco-
 >meta_slots_used, &npo);
 
drivers/net/xen-netback/netback.c +6 -8
 		if (sco->meta_slots_used == 1)
 			flags = 0;
@@ -649,22 +647,22 @@ void xenvif_rx_action(struct xenvif *vif)
 			flags |= XEN_NETRXF_data_validated;
 
 		offset = 0;
-		resp = make_rx_response(vif, vif->meta[npo.meta_cons].id,
+		resp = make_rx_response(queue, queue-
 >meta[npo.meta_cons].id,
 					status, offset,
-					vif->meta[npo.meta_cons].size,
+					queue->meta[npo.meta_cons].size,
 					flags);
 
-		if ((1 << vif->meta[npo.meta_cons].gso_type) &
-		    vif->gso_mask) {
+		if ((1 << queue->meta[npo.meta_cons].gso_type) &
+		    queue->vif->gso_mask) {
 			struct xen_netif_extra_info *gso =
 				(struct xen_netif_extra_info *)
-				RING_GET_RESPONSE(&vif->rx,
-						  vif->rx.rsp_prod_pvt++);
+				RING_GET_RESPONSE(&queue->rx,
+						  queue-
 >rx.rsp_prod_pvt++);
 
 			resp->flags |= XEN_NETRXF_extra_info;
 
-			gso->u.gso.type = vif-
 >meta[npo.meta_cons].gso_type;
-			gso->u.gso.size = vif-
Quoted 1 line

meta[npo.meta_cons].gso_size;

drivers/net/xen-netback/netback.c +1 -0
+			gso->u.gso.type = queue-
Quoted 1 line

meta[npo.meta_cons].gso_type;

drivers/net/xen-netback/netback.c +1 -0
+			gso->u.gso.size = queue-
Quoted 1 line

meta[npo.meta_cons].gso_size;

drivers/net/xen-netback/netback.c +14 -14
 			gso->u.gso.pad = 0;
 			gso->u.gso.features = 0;
@@ -672,47 +670,47 @@ void xenvif_rx_action(struct xenvif *vif)
 			gso->flags = 0;
 		}
 
-		xenvif_add_frag_responses(vif, status,
-					  vif->meta + npo.meta_cons + 1,
+		xenvif_add_frag_responses(queue, status,
+					  queue->meta + npo.meta_cons + 1,
 					  sco->meta_slots_used);
 
-		RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->rx,
 ret);
+		RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->rx,
 ret);
 
 		if (ret)
 			need_to_notify = 1;
 
-		xenvif_notify_tx_completion(vif);
+		xenvif_notify_tx_completion(queue);
 
 		npo.meta_cons += sco->meta_slots_used;
 		dev_kfree_skb(skb);
 	}
 
 	if (need_to_notify)
-		notify_remote_via_irq(vif->rx_irq);
+		notify_remote_via_irq(queue->rx_irq);
 
 	/* More work to do? */
-	if (!skb_queue_empty(&vif->rx_queue))
-		xenvif_kick_thread(vif);
+	if (!skb_queue_empty(&queue->rx_queue))
+		xenvif_kick_thread(queue);
 }
 
-void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb)
+void xenvif_queue_tx_skb(struct xenvif_queue *queue, struct sk_buff
 *skb)
 {
-	skb_queue_tail(&vif->rx_queue, skb);
+	skb_queue_tail(&queue->rx_queue, skb);
 
-	xenvif_kick_thread(vif);
+	xenvif_kick_thread(queue);
 }
 
-void xenvif_check_rx_xenvif(struct xenvif *vif)
+void xenvif_check_rx_xenvif(struct xenvif_queue *queue)
 {
 	int more_to_do;
 
-	RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, more_to_do);
+	RING_FINAL_CHECK_FOR_REQUESTS(&queue->tx, more_to_do);
 
 	if (more_to_do)
-		napi_schedule(&vif->napi);
+		napi_schedule(&queue->napi);
 }
 
-static void tx_add_credit(struct xenvif *vif)
+static void tx_add_credit(struct xenvif_queue *queue)

{

drivers/net/xen-netback/netback.c +0 -0
 	unsigned long max_burst, max_credit;
@@ -720,37 +718,37 @@ static void tx_add_credit(struct xenvif *vif)
 	 * Allow a burst big enough to transmit a jumbo packet of up to

128kB.

drivers/net/xen-netback/netback.c +1 -1
 	 * Otherwise the interface can seize up due to insufficient credit.
 	 */
-	max_burst = RING_GET_REQUEST(&vif->tx, vif->tx.req_cons)->size;
+	max_burst = RING_GET_REQUEST(&queue->tx, queue-
Quoted 1 line

tx.req_cons)->size;

drivers/net/xen-netback/netback.c +1 -1
 	max_burst = min(max_burst, 131072UL);
-	max_burst = max(max_burst, vif->credit_bytes);
+	max_burst = max(max_burst, queue->credit_bytes);
 
 	/* Take care that adding a new chunk of credit doesn't wrap to zero.

*/

drivers/net/xen-netback/netback.c +2 -2
-	max_credit = vif->remaining_credit + vif->credit_bytes;
-	if (max_credit < vif->remaining_credit)
+	max_credit = queue->remaining_credit + queue->credit_bytes;
+	if (max_credit < queue->remaining_credit)
 		max_credit = ULONG_MAX; /* wrapped: clamp to

ULONG_MAX */

drivers/net/xen-netback/netback.c +16 -16
-	vif->remaining_credit = min(max_credit, max_burst);
+	queue->remaining_credit = min(max_credit, max_burst);
 }
 
 static void tx_credit_callback(unsigned long data)
 {
-	struct xenvif *vif = (struct xenvif *)data;
-	tx_add_credit(vif);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = (struct xenvif_queue *)data;
+	tx_add_credit(queue);
+	xenvif_check_rx_xenvif(queue);
 }
 
-static void xenvif_tx_err(struct xenvif *vif,
+static void xenvif_tx_err(struct xenvif_queue *queue,
 			  struct xen_netif_tx_request *txp, RING_IDX end)
 {
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
 
 	do {
-		make_tx_response(vif, txp, XEN_NETIF_RSP_ERROR);
+		make_tx_response(queue, txp, XEN_NETIF_RSP_ERROR);
 		if (cons == end)
 			break;
-		txp = RING_GET_REQUEST(&vif->tx, cons++);
+		txp = RING_GET_REQUEST(&queue->tx, cons++);
 	} while (1);
-	vif->tx.req_cons = cons;
+	queue->tx.req_cons = cons;
 }
 
 static void xenvif_fatal_tx_err(struct xenvif *vif)
@@ -759,12 +757,12 @@ static void xenvif_fatal_tx_err(struct xenvif *vif)
 	xenvif_carrier_off(vif);
 }
 
-static int xenvif_count_requests(struct xenvif *vif,
+static int xenvif_count_requests(struct xenvif_queue *queue,
 				 struct xen_netif_tx_request *first,
 				 struct xen_netif_tx_request *txp,
 				 int work_to_do)
 {
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
 	int slots = 0;
 	int drop_err = 0;
 	int more_data;
@@ -776,10 +774,10 @@ static int xenvif_count_requests(struct xenvif *vif,
 		struct xen_netif_tx_request dropped_tx = { 0 };
 
 		if (slots >= work_to_do) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
 				   "Asked for %d slots but exceeds this
 limit\n",
 				   work_to_do);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			return -ENODATA;
 		}
@@ -787,10 +785,10 @@ static int xenvif_count_requests(struct xenvif *vif,
 		 * considered malicious.
 		 */
 		if (unlikely(slots >= fatal_skb_slots)) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
 				   "Malicious frontend using %d slots,
 threshold %u\n",
 				   slots, fatal_skb_slots);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			return -E2BIG;
 		}
@@ -803,7 +801,7 @@ static int xenvif_count_requests(struct xenvif *vif,
 		 */
 		if (!drop_err && slots >= XEN_NETBK_LEGACY_SLOTS_MAX)
 {
 			if (net_ratelimit())
-				netdev_dbg(vif->dev,
+				netdev_dbg(queue->vif->dev,
 					   "Too many slots (%d) exceeding
 limit (%d), dropping packet\n",

slots,
XEN_NETBK_LEGACY_SLOTS_MAX);

drivers/net/xen-netback/netback.c +1 -1
 			drop_err = -E2BIG;
@@ -812,7 +810,7 @@ static int xenvif_count_requests(struct xenvif *vif,
 		if (drop_err)
 			txp = &dropped_tx;
 
-		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + slots),
+		memcpy(txp, RING_GET_REQUEST(&queue->tx, cons +
 slots),
 		       sizeof(*txp));
 
drivers/net/xen-netback/netback.c +1 -1
 		/* If the guest submitted a frame >= 64 KiB then
@@ -826,7 +824,7 @@ static int xenvif_count_requests(struct xenvif *vif,
 		 */
 		if (!drop_err && txp->size > first->size) {
 			if (net_ratelimit())
-				netdev_dbg(vif->dev,
+				netdev_dbg(queue->vif->dev,
 					   "Invalid tx request, slot size %u >
 remaining size %u\n",
 					   txp->size, first->size);
drivers/net/xen-netback/netback.c +2 -2
 			drop_err = -EIO;
@@ -836,9 +834,9 @@ static int xenvif_count_requests(struct xenvif *vif,
 		slots++;
 
 		if (unlikely((txp->offset + txp->size) > PAGE_SIZE)) {
-			netdev_err(vif->dev, "Cross page boundary, txp-
 >offset: %x, size: %u\n",
+			netdev_err(queue->vif->dev, "Cross page boundary,
 txp->offset: %x, size: %u\n",
 				 txp->offset, txp->size);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			return -EINVAL;
drivers/net/xen-netback/netback.c +4 -4
 		}
@@ -850,14 +848,14 @@ static int xenvif_count_requests(struct xenvif *vif,
 	} while (more_data);
 
 	if (drop_err) {
-		xenvif_tx_err(vif, first, cons + slots);
+		xenvif_tx_err(queue, first, cons + slots);
 		return drop_err;
 	}
 
 	return slots;
 }
 
-static struct page *xenvif_alloc_page(struct xenvif *vif,
+static struct page *xenvif_alloc_page(struct xenvif_queue *queue,
 				      u16 pending_idx)
 {
 	struct page *page;
@@ -865,12 +863,12 @@ static struct page *xenvif_alloc_page(struct xenvif
 *vif,
 	page = alloc_page(GFP_ATOMIC|__GFP_COLD);
 	if (!page)
 		return NULL;
-	vif->mmap_pages[pending_idx] = page;
+	queue->mmap_pages[pending_idx] = page;
 
 	return page;
 }
 
-static struct gnttab_copy *xenvif_get_requests(struct xenvif *vif,
+static struct gnttab_copy *xenvif_get_requests(struct xenvif_queue
 *queue,
 					       struct sk_buff *skb,
drivers/net/xen-netback/netback.c +1 -1
 					       struct xen_netif_tx_request *txp,
 					       struct gnttab_copy *gop)
@@ -901,7 +899,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
 	for (shinfo->nr_frags = slot = start; slot < nr_slots;
 	     shinfo->nr_frags++) {
 		struct pending_tx_info *pending_tx_info =
-			vif->pending_tx_info;
+			queue->pending_tx_info;
 
 		page = alloc_page(GFP_ATOMIC|__GFP_COLD);
drivers/net/xen-netback/netback.c +1 -1
 		if (!page)
@@ -913,7 +911,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
 			gop->flags = GNTCOPY_source_gref;
 
 			gop->source.u.ref = txp->gref;
-			gop->source.domid = vif->domid;
+			gop->source.domid = queue->vif->domid;
 			gop->source.offset = txp->offset;
 
drivers/net/xen-netback/netback.c +2 -2
 			gop->dest.domid = DOMID_SELF;
@@ -938,9 +936,9 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
 				gop->len = txp->size;
 				dst_offset += gop->len;
 
-				index = pending_index(vif-
 >pending_cons++);
+				index = pending_index(queue-
 >pending_cons++);
 
-				pending_idx = vif->pending_ring[index];
+				pending_idx = queue->pending_ring[index];

memcpy(&pending_tx_info[pending_idx].req, txp,

drivers/net/xen-netback/netback.c +1 -1
 				       sizeof(*txp));
@@ -949,7 +947,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
 				 * fields for head tx req will be set
 				 * to correct values after the loop.
 				 */
-				vif->mmap_pages[pending_idx] = (void
 *)(~0UL);
+				queue->mmap_pages[pending_idx] = (void
 *)(~0UL);
drivers/net/xen-netback/netback.c +5 -5
 				pending_tx_info[pending_idx].head =
 					INVALID_PENDING_RING_IDX;
@@ -969,7 +967,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
 		first->req.offset = 0;
 		first->req.size = dst_offset;
 		first->head = start_idx;
-		vif->mmap_pages[head_idx] = page;
+		queue->mmap_pages[head_idx] = page;
 		frag_set_pending_idx(&frags[shinfo->nr_frags], head_idx);
 	}
@@ -979,18 +977,18 @@ static struct gnttab_copy
 *xenvif_get_requests(struct xenvif *vif,
 err:
 	/* Unwind, freeing all pages and sending error responses. */
 	while (shinfo->nr_frags-- > start) {
-		xenvif_idx_release(vif,
+		xenvif_idx_release(queue,
 				frag_get_pending_idx(&frags[shinfo-
 >nr_frags]),
 				XEN_NETIF_RSP_ERROR);
 	}
 	/* The head too, if necessary. */
 	if (start)
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);
 
 	return NULL;
 }
 
-static int xenvif_tx_check_gop(struct xenvif *vif,
+static int xenvif_tx_check_gop(struct xenvif_queue *queue,
 			       struct sk_buff *skb,
 			       struct gnttab_copy **gopp)
 {
@@ -1005,7 +1003,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 	/* Check status of header. */
 	err = gop->status;
 	if (unlikely(err))
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);
 
drivers/net/xen-netback/netback.c +1 -1
 	/* Skip first skb fragment if it is on same page as header fragment. */
 	start = (frag_get_pending_idx(&shinfo->frags[0]) == pending_idx);
@@ -1015,7 +1013,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 		pending_ring_idx_t head;
 
 		pending_idx = frag_get_pending_idx(&shinfo->frags[i]);
-		tx_info = &vif->pending_tx_info[pending_idx];
+		tx_info = &queue->pending_tx_info[pending_idx];
 		head = tx_info->head;
 
 		/* Check error status: if okay then remember grant handle.

*/

drivers/net/xen-netback/netback.c +4 -4
@@ -1023,19 +1021,19 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 			newerr = (++gop)->status;
 			if (newerr)
 				break;
-			peek = vif->pending_ring[pending_index(++head)];
-		} while (!pending_tx_is_head(vif, peek));
+			peek = queue-
 >pending_ring[pending_index(++head)];
+		} while (!pending_tx_is_head(queue, peek));
 
 		if (likely(!newerr)) {
 			/* Had a previous error? Invalidate this fragment. */
 			if (unlikely(err))
-				xenvif_idx_release(vif, pending_idx,
+				xenvif_idx_release(queue, pending_idx,
 						   XEN_NETIF_RSP_OKAY);
 			continue;
 		}
 
 		/* Error on this fragment: respond to client with an error. */
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);
drivers/net/xen-netback/netback.c +2 -2
 		/* Not the first error? Preceding frags already invalidated. */
 		if (err)
@@ -1043,10 +1041,10 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 
 		/* First error: invalidate header and preceding fragments. */
 		pending_idx = *((u16 *)skb->data);
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_OKAY);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_OKAY);
 		for (j = start; j < i; j++) {
 			pending_idx = frag_get_pending_idx(&shinfo-
 >frags[j]);
-			xenvif_idx_release(vif, pending_idx,
+			xenvif_idx_release(queue, pending_idx,
drivers/net/xen-netback/netback.c +1 -1
 					   XEN_NETIF_RSP_OKAY);
 		}
@@ -1058,7 +1056,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 	return err;
 }
 
-static void xenvif_fill_frags(struct xenvif *vif, struct sk_buff *skb)
+static void xenvif_fill_frags(struct xenvif_queue *queue, struct sk_buff
 *skb)
 {
 	struct skb_shared_info *shinfo = skb_shinfo(skb);
drivers/net/xen-netback/netback.c +25 -25
 	int nr_frags = shinfo->nr_frags;
@@ -1072,46 +1070,46 @@ static void xenvif_fill_frags(struct xenvif *vif,
 struct sk_buff *skb)
 
 		pending_idx = frag_get_pending_idx(frag);
 
-		txp = &vif->pending_tx_info[pending_idx].req;
-		page = virt_to_page(idx_to_kaddr(vif, pending_idx));
+		txp = &queue->pending_tx_info[pending_idx].req;
+		page = virt_to_page(idx_to_kaddr(queue, pending_idx));
 		__skb_fill_page_desc(skb, i, page, txp->offset, txp->size);
 		skb->len += txp->size;
 		skb->data_len += txp->size;
 		skb->truesize += txp->size;
 
 		/* Take an extra reference to offset xenvif_idx_release */
-		get_page(vif->mmap_pages[pending_idx]);
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_OKAY);
+		get_page(queue->mmap_pages[pending_idx]);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_OKAY);
 	}
 }
 
-static int xenvif_get_extras(struct xenvif *vif,
+static int xenvif_get_extras(struct xenvif_queue *queue,
 				struct xen_netif_extra_info *extras,
 				int work_to_do)
 {
 	struct xen_netif_extra_info extra;
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
 
 	do {
 		if (unlikely(work_to_do-- <= 0)) {
-			netdev_err(vif->dev, "Missing extra info\n");
-			xenvif_fatal_tx_err(vif);
+			netdev_err(queue->vif->dev, "Missing extra
 info\n");
+			xenvif_fatal_tx_err(queue->vif);
 			return -EBADR;
 		}
 
-		memcpy(&extra, RING_GET_REQUEST(&vif->tx, cons),
+		memcpy(&extra, RING_GET_REQUEST(&queue->tx, cons),
 		       sizeof(extra));
 		if (unlikely(!extra.type ||
 			     extra.type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
-			vif->tx.req_cons = ++cons;
-			netdev_err(vif->dev,
+			queue->tx.req_cons = ++cons;
+			netdev_err(queue->vif->dev,
 				   "Invalid extra type: %d\n", extra.type);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			return -EINVAL;
 		}
 
 		memcpy(&extras[extra.type - 1], &extra, sizeof(extra));
-		vif->tx.req_cons = ++cons;
+		queue->tx.req_cons = ++cons;
 	} while (extra.flags & XEN_NETIF_EXTRA_FLAG_MORE);
 
 	return work_to_do;
@@ -1424,31 +1422,31 @@ static int checksum_setup(struct xenvif *vif,
 struct sk_buff *skb)
 	return err;
 }
 
-static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
+static bool tx_credit_exceeded(struct xenvif_queue *queue, unsigned
 size)
 {
 	u64 now = get_jiffies_64();
-	u64 next_credit = vif->credit_window_start +
-		msecs_to_jiffies(vif->credit_usec / 1000);
+	u64 next_credit = queue->credit_window_start +
+		msecs_to_jiffies(queue->credit_usec / 1000);
 
 	/* Timer could already be pending in rare cases. */
-	if (timer_pending(&vif->credit_timeout))
+	if (timer_pending(&queue->credit_timeout))
 		return true;
 
 	/* Passed the point where we can replenish credit? */
 	if (time_after_eq64(now, next_credit)) {
-		vif->credit_window_start = now;
-		tx_add_credit(vif);
+		queue->credit_window_start = now;
+		tx_add_credit(queue);
 	}
 
 	/* Still too big to send right now? Set a callback. */
-	if (size > vif->remaining_credit) {
-		vif->credit_timeout.data     =
-			(unsigned long)vif;
-		vif->credit_timeout.function =
+	if (size > queue->remaining_credit) {
+		queue->credit_timeout.data     =
+			(unsigned long)queue;
+		queue->credit_timeout.function =
 			tx_credit_callback;
-		mod_timer(&vif->credit_timeout,
+		mod_timer(&queue->credit_timeout,
 			  next_credit);
-		vif->credit_window_start = next_credit;
+		queue->credit_window_start = next_credit;
 
drivers/net/xen-netback/netback.c +3 -3
 		return true;
 	}
@@ -1456,15 +1454,15 @@ static bool tx_credit_exceeded(struct xenvif *vif,
 unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
+static unsigned xenvif_tx_build_gops(struct xenvif_queue *queue, int
 budget)
 {
-	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
+	struct gnttab_copy *gop = queue->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
-	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
+	while ((nr_pending_reqs(queue) +

XEN_NETBK_LEGACY_SLOTS_MAX

drivers/net/xen-netback/netback.c +1 -1
 		< MAX_PENDING_REQS) &&
-	       (skb_queue_len(&vif->tx_queue) < budget)) {
+	       (skb_queue_len(&queue->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];

drivers/net/xen-netback/netback.c +23 -23
 		struct page *page;
@@ -1475,69 +1473,69 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
 		unsigned int data_len;
 		pending_ring_idx_t index;
 
-		if (vif->tx.sring->req_prod - vif->tx.req_cons >
+		if (queue->tx.sring->req_prod - queue->tx.req_cons >
 		    XEN_NETIF_TX_RING_SIZE) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
 				   "Impossible number of requests. "
 				   "req_prod %d, req_cons %d, size %ld\n",
-				   vif->tx.sring->req_prod, vif->tx.req_cons,
+				   queue->tx.sring->req_prod, queue-
 >tx.req_cons,
 				   XEN_NETIF_TX_RING_SIZE);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			continue;
 		}
 
-		work_to_do = RING_HAS_UNCONSUMED_REQUESTS(&vif-
 >tx);
+		work_to_do =
 RING_HAS_UNCONSUMED_REQUESTS(&queue->tx);
 		if (!work_to_do)
 			break;
 
-		idx = vif->tx.req_cons;
+		idx = queue->tx.req_cons;
 		rmb(); /* Ensure that we see the request before we copy it.
 */
-		memcpy(&txreq, RING_GET_REQUEST(&vif->tx, idx),
 sizeof(txreq));
+		memcpy(&txreq, RING_GET_REQUEST(&queue->tx, idx),
 sizeof(txreq));
 
 		/* Credit-based scheduling. */
-		if (txreq.size > vif->remaining_credit &&
-		    tx_credit_exceeded(vif, txreq.size))
+		if (txreq.size > queue->remaining_credit &&
+		    tx_credit_exceeded(queue, txreq.size))
 			break;
 
-		vif->remaining_credit -= txreq.size;
+		queue->remaining_credit -= txreq.size;
 
 		work_to_do--;
-		vif->tx.req_cons = ++idx;
+		queue->tx.req_cons = ++idx;
 
 		memset(extras, 0, sizeof(extras));
 		if (txreq.flags & XEN_NETTXF_extra_info) {
-			work_to_do = xenvif_get_extras(vif, extras,
+			work_to_do = xenvif_get_extras(queue, extras,
 						       work_to_do);
-			idx = vif->tx.req_cons;
+			idx = queue->tx.req_cons;
 			if (unlikely(work_to_do < 0))
 				break;
 		}
 
-		ret = xenvif_count_requests(vif, &txreq, txfrags,
 work_to_do);
+		ret = xenvif_count_requests(queue, &txreq, txfrags,
 work_to_do);
 		if (unlikely(ret < 0))
 			break;
 
 		idx += ret;
 
 		if (unlikely(txreq.size < ETH_HLEN)) {
-			netdev_dbg(vif->dev,
+			netdev_dbg(queue->vif->dev,
 				   "Bad packet size: %d\n", txreq.size);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
 			break;
 		}
 
 		/* No crossing a page as the payload mustn't fragment. */
 		if (unlikely((txreq.offset + txreq.size) > PAGE_SIZE)) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
 				   "txreq.offset: %x, size: %u, end: %lu\n",
 				   txreq.offset, txreq.size,
 				   (txreq.offset&~PAGE_MASK) + txreq.size);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
 			break;
 		}
 
-		index = pending_index(vif->pending_cons);
-		pending_idx = vif->pending_ring[index];
+		index = pending_index(queue->pending_cons);
+		pending_idx = queue->pending_ring[index];
 
 		data_len = (txreq.size > PKT_PROT_LEN &&
 			    ret < XEN_NETBK_LEGACY_SLOTS_MAX) ?
@@ -1546,9 +1544,9 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
 		skb = alloc_skb(data_len + NET_SKB_PAD + NET_IP_ALIGN,
 				GFP_ATOMIC | __GFP_NOWARN);
 		if (unlikely(skb == NULL)) {
-			netdev_dbg(vif->dev,
+			netdev_dbg(queue->vif->dev,
 				   "Can't allocate a skb in start_xmit.\n");
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
 			break;
 		}
@@ -1559,7 +1557,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
 			struct xen_netif_extra_info *gso;
 			gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
 
-			if (xenvif_set_skb_gso(vif, skb, gso)) {
+			if (xenvif_set_skb_gso(queue->vif, skb, gso)) {
 				/* Failure in xenvif_set_skb_gso is fatal. */
 				kfree_skb(skb);
drivers/net/xen-netback/netback.c +3 -3
 				break;
@@ -1567,15 +1565,15 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
 		}
 
 		/* XXX could copy straight to head */
-		page = xenvif_alloc_page(vif, pending_idx);
+		page = xenvif_alloc_page(queue, pending_idx);
 		if (!page) {
 			kfree_skb(skb);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
 			break;
 		}
 
 		gop->source.u.ref = txreq.gref;
-		gop->source.domid = vif->domid;
+		gop->source.domid = queue->vif->domid;
 		gop->source.offset = txreq.offset;
 
drivers/net/xen-netback/netback.c +2 -2
 		gop->dest.u.gmfn = virt_to_mfn(page_address(page));
@@ -1587,9 +1585,9 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
 
 		gop++;
 
-		memcpy(&vif->pending_tx_info[pending_idx].req,
+		memcpy(&queue->pending_tx_info[pending_idx].req,
 		       &txreq, sizeof(txreq));
-		vif->pending_tx_info[pending_idx].head = index;
+		queue->pending_tx_info[pending_idx].head = index;
 		*((u16 *)skb->data) = pending_idx;
 
drivers/net/xen-netback/netback.c +13 -13
 		__skb_put(skb, data_len);
@@ -1604,45 +1602,45 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
 					     INVALID_PENDING_IDX);
 		}
 
-		vif->pending_cons++;
+		queue->pending_cons++;
 
-		request_gop = xenvif_get_requests(vif, skb, txfrags, gop);
+		request_gop = xenvif_get_requests(queue, skb, txfrags,
 gop);
 		if (request_gop == NULL) {
 			kfree_skb(skb);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
 			break;
 		}
 		gop = request_gop;
 
-		__skb_queue_tail(&vif->tx_queue, skb);
+		__skb_queue_tail(&queue->tx_queue, skb);
 
-		vif->tx.req_cons = idx;
+		queue->tx.req_cons = idx;
 
-		if ((gop-vif->tx_copy_ops) >= ARRAY_SIZE(vif-
 >tx_copy_ops))
+		if ((gop - queue->tx_copy_ops) >= ARRAY_SIZE(queue-
 >tx_copy_ops))
 			break;
 	}
 
-	return gop - vif->tx_copy_ops;
+	return gop - queue->tx_copy_ops;
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif)
+static int xenvif_tx_submit(struct xenvif_queue *queue)
 {
-	struct gnttab_copy *gop = vif->tx_copy_ops;
+	struct gnttab_copy *gop = queue->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&queue->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
 
 		pending_idx = *((u16 *)skb->data);
-		txp = &vif->pending_tx_info[pending_idx].req;
+		txp = &queue->pending_tx_info[pending_idx].req;
 
 		/* Check the remap error code. */
-		if (unlikely(xenvif_tx_check_gop(vif, skb, &gop))) {
-			netdev_dbg(vif->dev, "netback grant failed.\n");
+		if (unlikely(xenvif_tx_check_gop(queue, skb, &gop))) {
+			netdev_dbg(queue->vif->dev, "netback grant

failed.\n");

drivers/net/xen-netback/netback.c +6 -6
 			skb_shinfo(skb)->nr_frags = 0;
 			kfree_skb(skb);
 			continue;
@@ -1650,7 +1648,7 @@ static int xenvif_tx_submit(struct xenvif *vif)
 
 		data_len = skb->len;
 		memcpy(skb->data,
-		       (void *)(idx_to_kaddr(vif, pending_idx)|txp->offset),
+		       (void *)(idx_to_kaddr(queue, pending_idx)|txp->offset),
 		       data_len);
 		if (data_len < txp->size) {
 			/* Append the packet payload as a fragment. */
@@ -1658,7 +1656,7 @@ static int xenvif_tx_submit(struct xenvif *vif)
 			txp->size -= data_len;
 		} else {
 			/* Schedule a response immediately. */
-			xenvif_idx_release(vif, pending_idx,
+			xenvif_idx_release(queue, pending_idx,
 					   XEN_NETIF_RSP_OKAY);
 		}
 
@@ -1667,19 +1665,19 @@ static int xenvif_tx_submit(struct xenvif *vif)
 		else if (txp->flags & XEN_NETTXF_data_validated)
 			skb->ip_summed = CHECKSUM_UNNECESSARY;
 
-		xenvif_fill_frags(vif, skb);
+		xenvif_fill_frags(queue, skb);
 
 		if (skb_is_nonlinear(skb) && skb_headlen(skb) <
 PKT_PROT_LEN) {
 			int target = min_t(int, skb->len, PKT_PROT_LEN);
 			__pskb_pull_tail(skb, target - skb_headlen(skb));
 		}
 
-		skb->dev      = vif->dev;
+		skb->dev      = queue->vif->dev;
 		skb->protocol = eth_type_trans(skb, skb->dev);
 		skb_reset_network_header(skb);
 
-		if (checksum_setup(vif, skb)) {
-			netdev_dbg(vif->dev,
+		if (checksum_setup(queue->vif, skb)) {
+			netdev_dbg(queue->vif->dev,
 				   "Can't setup checksum in
 net_tx_action\n");
drivers/net/xen-netback/netback.c +16 -16
 			kfree_skb(skb);
 			continue;
@@ -1687,8 +1685,8 @@ static int xenvif_tx_submit(struct xenvif *vif)
 
 		skb_probe_transport_header(skb, 0);
 
-		vif->dev->stats.rx_bytes += skb->len;
-		vif->dev->stats.rx_packets++;
+		queue->vif->dev->stats.rx_bytes += skb->len;
+		queue->vif->dev->stats.rx_packets++;
 
 		work_done++;
 
@@ -1699,53 +1697,53 @@ static int xenvif_tx_submit(struct xenvif *vif)
 }
 
 /* Called after netfront has transmitted */
-int xenvif_tx_action(struct xenvif *vif, int budget)
+int xenvif_tx_action(struct xenvif_queue *queue, int budget)
 {
 	unsigned nr_gops;
 	int work_done;
 
-	if (unlikely(!tx_work_todo(vif)))
+	if (unlikely(!tx_work_todo(queue)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif, budget);
+	nr_gops = xenvif_tx_build_gops(queue, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
-	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
+	gnttab_batch_copy(queue->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif);
+	work_done = xenvif_tx_submit(queue);
 
 	return work_done;
 }
 
-static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
+static void xenvif_idx_release(struct xenvif_queue *queue, u16
 pending_idx,
 			       u8 status)
 {
 	struct pending_tx_info *pending_tx_info;
 	pending_ring_idx_t head;
 	u16 peek; /* peek into next tx request */
 
-	BUG_ON(vif->mmap_pages[pending_idx] == (void *)(~0UL));
+	BUG_ON(queue->mmap_pages[pending_idx] == (void *)(~0UL));
 
 	/* Already complete? */
-	if (vif->mmap_pages[pending_idx] == NULL)
+	if (queue->mmap_pages[pending_idx] == NULL)
 		return;
 
-	pending_tx_info = &vif->pending_tx_info[pending_idx];
+	pending_tx_info = &queue->pending_tx_info[pending_idx];
 
 	head = pending_tx_info->head;
 
-	BUG_ON(!pending_tx_is_head(vif, head));
-	BUG_ON(vif->pending_ring[pending_index(head)] != pending_idx);
+	BUG_ON(!pending_tx_is_head(queue, head));
+	BUG_ON(queue->pending_ring[pending_index(head)] !=
 pending_idx);
 
 	do {
 		pending_ring_idx_t index;
 		pending_ring_idx_t idx = pending_index(head);
-		u16 info_idx = vif->pending_ring[idx];
+		u16 info_idx = queue->pending_ring[idx];
 
-		pending_tx_info = &vif->pending_tx_info[info_idx];
-		make_tx_response(vif, &pending_tx_info->req, status);
+		pending_tx_info = &queue->pending_tx_info[info_idx];
+		make_tx_response(queue, &pending_tx_info->req, status);
 
drivers/net/xen-netback/netback.c +30 -30
 		/* Setting any number other than
 		 * INVALID_PENDING_RING_IDX indicates this slot is
@@ -1753,50 +1751,50 @@ static void xenvif_idx_release(struct xenvif *vif,
 u16 pending_idx,
 		 */
 		pending_tx_info->head = 0;
 
-		index = pending_index(vif->pending_prod++);
-		vif->pending_ring[index] = vif->pending_ring[info_idx];
+		index = pending_index(queue->pending_prod++);
+		queue->pending_ring[index] = queue-
 >pending_ring[info_idx];
 
-		peek = vif->pending_ring[pending_index(++head)];
+		peek = queue->pending_ring[pending_index(++head)];
 
-	} while (!pending_tx_is_head(vif, peek));
+	} while (!pending_tx_is_head(queue, peek));
 
-	put_page(vif->mmap_pages[pending_idx]);
-	vif->mmap_pages[pending_idx] = NULL;
+	put_page(queue->mmap_pages[pending_idx]);
+	queue->mmap_pages[pending_idx] = NULL;
 }
 
 
-static void make_tx_response(struct xenvif *vif,
+static void make_tx_response(struct xenvif_queue *queue,
 			     struct xen_netif_tx_request *txp,
 			     s8       st)
 {
-	RING_IDX i = vif->tx.rsp_prod_pvt;
+	RING_IDX i = queue->tx.rsp_prod_pvt;
 	struct xen_netif_tx_response *resp;
 	int notify;
 
-	resp = RING_GET_RESPONSE(&vif->tx, i);
+	resp = RING_GET_RESPONSE(&queue->tx, i);
 	resp->id     = txp->id;
 	resp->status = st;
 
 	if (txp->flags & XEN_NETTXF_extra_info)
-		RING_GET_RESPONSE(&vif->tx, ++i)->status =
 XEN_NETIF_RSP_NULL;
+		RING_GET_RESPONSE(&queue->tx, ++i)->status =
 XEN_NETIF_RSP_NULL;
 
-	vif->tx.rsp_prod_pvt = ++i;
-	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->tx, notify);
+	queue->tx.rsp_prod_pvt = ++i;
+	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->tx, notify);
 	if (notify)
-		notify_remote_via_irq(vif->tx_irq);
+		notify_remote_via_irq(queue->tx_irq);
 }
 
-static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
+static struct xen_netif_rx_response *make_rx_response(struct
 xenvif_queue *queue,
 					     u16      id,
 					     s8       st,
 					     u16      offset,
 					     u16      size,
 					     u16      flags)
 {
-	RING_IDX i = vif->rx.rsp_prod_pvt;
+	RING_IDX i = queue->rx.rsp_prod_pvt;
 	struct xen_netif_rx_response *resp;
 
-	resp = RING_GET_RESPONSE(&vif->rx, i);
+	resp = RING_GET_RESPONSE(&queue->rx, i);
 	resp->offset     = offset;
 	resp->flags      = flags;
 	resp->id         = id;
@@ -1804,38 +1802,38 @@ static struct xen_netif_rx_response
 *make_rx_response(struct xenvif *vif,
 	if (st < 0)
 		resp->status = (s16)st;
 
-	vif->rx.rsp_prod_pvt = ++i;
+	queue->rx.rsp_prod_pvt = ++i;
 
 	return resp;
 }
 
-static inline int rx_work_todo(struct xenvif *vif)
+static inline int rx_work_todo(struct xenvif_queue *queue)
 {
-	return !skb_queue_empty(&vif->rx_queue);
+	return !skb_queue_empty(&queue->rx_queue);
 }
 
-static inline int tx_work_todo(struct xenvif *vif)
+static inline int tx_work_todo(struct xenvif_queue *queue)
 {
 
-	if (likely(RING_HAS_UNCONSUMED_REQUESTS(&vif->tx)) &&
-	    (nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
+	if (likely(RING_HAS_UNCONSUMED_REQUESTS(&queue->tx)) &&
+	    (nr_pending_reqs(queue) + XEN_NETBK_LEGACY_SLOTS_MAX
 	     < MAX_PENDING_REQS))
 		return 1;
 
 	return 0;
 }
 
-void xenvif_unmap_frontend_rings(struct xenvif *vif)
+void xenvif_unmap_frontend_rings(struct xenvif_queue *queue)
 {
-	if (vif->tx.sring)
-		xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
-					vif->tx.sring);
-	if (vif->rx.sring)
-		xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
-					vif->rx.sring);
+	if (queue->tx.sring)
+
 	xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif),
+					queue->tx.sring);
+	if (queue->rx.sring)
+
 	xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif),
+					queue->rx.sring);
 }
 
-int xenvif_map_frontend_rings(struct xenvif *vif,
+int xenvif_map_frontend_rings(struct xenvif_queue *queue,
drivers/net/xen-netback/netback.c +11 -11
 			      grant_ref_t tx_ring_ref,
 			      grant_ref_t rx_ring_ref)
 {
@@ -1845,44 +1843,44 @@ int xenvif_map_frontend_rings(struct xenvif
 *vif,
 
 	int err = -ENOMEM;
 
-	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
+	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue-
 >vif),
 				     tx_ring_ref, &addr);
 	if (err)
 		goto err;
 
 	txs = (struct xen_netif_tx_sring *)addr;
-	BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
+	BACK_RING_INIT(&queue->tx, txs, PAGE_SIZE);
 
-	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
+	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue-
 >vif),
 				     rx_ring_ref, &addr);
 	if (err)
 		goto err;
 
 	rxs = (struct xen_netif_rx_sring *)addr;
-	BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
+	BACK_RING_INIT(&queue->rx, rxs, PAGE_SIZE);
 
-	vif->rx_req_cons_peek = 0;
+	queue->rx_req_cons_peek = 0;
 
 	return 0;
 
 err:
-	xenvif_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(queue);
 	return err;
 }
 
 int xenvif_kthread(void *data)
 {
-	struct xenvif *vif = data;
+	struct xenvif_queue *queue = data;
 
 	while (!kthread_should_stop()) {
-		wait_event_interruptible(vif->wq,
-					 rx_work_todo(vif) ||
+		wait_event_interruptible(queue->wq,
+					 rx_work_todo(queue) ||
 					 kthread_should_stop());
 		if (kthread_should_stop())
 			break;
 
-		if (rx_work_todo(vif))
-			xenvif_rx_action(vif);
+		if (rx_work_todo(queue))
+			xenvif_rx_action(queue);
drivers/net/xen-netback/netback.c +0 -0
 		cond_resched();
 	}
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c
index f035899..c3332e2 100644

drivers/net/xen-netback/xenbus.c +4 -2
@@ -20,6 +20,7 @@
 */
 
 #include "common.h"
+#include <linux/vmalloc.h>
 
 struct backend_info {
 	struct xenbus_device *dev;
@@ -35,8 +36,9 @@ struct backend_info {
 	u8 have_hotplug_status_watch:1;
 };
 
-static int connect_rings(struct backend_info *);
-static void connect(struct backend_info *);
+static int connect_rings(struct backend_info *be, struct xenvif_queue
 *queue);
+static void connect(struct backend_info *be);
+static int read_xenbus_vif_flags(struct backend_info *be);
 static void backend_create_xenvif(struct backend_info *be);
 static void unregister_hotplug_status_watch(struct backend_info *be);

static void set_backend_state(struct backend_info *be,

drivers/net/xen-netback/xenbus.c +40 -12
@@ -486,10 +488,9 @@ static void connect(struct backend_info *be)
 {
 	int err;
 	struct xenbus_device *dev = be->dev;
-
-	err = connect_rings(be);
-	if (err)
-		return;
+	unsigned long credit_bytes, credit_usec;
+	unsigned int queue_index;
+	struct xenvif_queue *queue;
 
 	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
 	if (err) {
@@ -497,9 +498,31 @@ static void connect(struct backend_info *be)
 		return;
 	}
 
-	xen_net_read_rate(dev, &be->vif->credit_bytes,
-			  &be->vif->credit_usec);
-	be->vif->remaining_credit = be->vif->credit_bytes;
+	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
+	read_xenbus_vif_flags(be);
+
+	be->vif->num_queues = 1;
+	be->vif->queues = vzalloc(be->vif->num_queues *
+			sizeof(struct xenvif_queue));
+
+	for (queue_index = 0; queue_index < be->vif->num_queues;
++queue_index)
+	{
+		queue = &be->vif->queues[queue_index];
+		queue->vif = be->vif;
+		queue->number = queue_index;
+		snprintf(queue->name, sizeof(queue->name), "%s-q%u",
+				be->vif->dev->name, queue->number);
+
+		xenvif_init_queue(queue);
+
+		queue->remaining_credit = credit_bytes;
+
+		err = connect_rings(be, queue);
+		if (err)
+			goto err;
+	}
+
+	xenvif_carrier_on(be->vif);
 
 	unregister_hotplug_status_watch(be);
 	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
@@ -508,18 +531,24 @@ static void connect(struct backend_info *be)
 	if (!err)
 		be->have_hotplug_status_watch = 1;
 
-	netif_wake_queue(be->vif->dev);
+	netif_tx_wake_all_queues(be->vif->dev);
+
+	return;
+
+err:
+	vfree(be->vif->queues);
+	be->vif->queues = NULL;
+	be->vif->num_queues = 0;
+	return;
 }
 
 
-static int connect_rings(struct backend_info *be)
+static int connect_rings(struct backend_info *be, struct xenvif_queue
 *queue)
 {
-	struct xenvif *vif = be->vif;
 	struct xenbus_device *dev = be->dev;
 	unsigned long tx_ring_ref, rx_ring_ref;
-	unsigned int tx_evtchn, rx_evtchn, rx_copy;
+	unsigned int tx_evtchn, rx_evtchn;
 	int err;
-	int val;
 
 	err = xenbus_gather(XBT_NIL, dev->otherend,
drivers/net/xen-netback/xenbus.c +21 -0
 			    "tx-ring-ref", "%lu", &tx_ring_ref,
@@ -547,6 +576,27 @@ static int connect_rings(struct backend_info *be)
 		rx_evtchn = tx_evtchn;
 	}
 
+	/* Map the shared frame, irq etc. */
+	err = xenvif_connect(queue, tx_ring_ref, rx_ring_ref,
+			     tx_evtchn, rx_evtchn);
+	if (err) {
+		xenbus_dev_fatal(dev, err,
+				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
+				 tx_ring_ref, rx_ring_ref,
+				 tx_evtchn, rx_evtchn);
+		return err;
+	}
+
+	return 0;
+}
+
+static int read_xenbus_vif_flags(struct backend_info *be)
+{
+	struct xenvif *vif = be->vif;
+	struct xenbus_device *dev = be->dev;
+	unsigned int rx_copy;
+	int err, val;
+
 	err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy",
 "%u",
drivers/net/xen-netback/xenbus.c +0 -12
 			   &rx_copy);
 	if (err == -ENOENT) {
@@ -622,20 +672,9 @@ static int connect_rings(struct backend_info *be)
 		val = 0;
 	vif->ipv6_csum = !!val;
 
-	/* Map the shared frame, irq etc. */
-	err = xenvif_connect(vif, tx_ring_ref, rx_ring_ref,
-			     tx_evtchn, rx_evtchn);
-	if (err) {
-		xenbus_dev_fatal(dev, err,
-				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
-				 tx_ring_ref, rx_ring_ref,
-				 tx_evtchn, rx_evtchn);
-		return err;
-	}
 	return 0;
 }
 
-
 /* ** Driver Registration ** */
 
 
--

1.7.10.4

#7 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 42 lines · Paul Durrant
Quoted 42 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston
Subject: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netback, move the queue-specific data from struct xenvif into struct xenvif_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_netdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0 for a single queue and uses skb_get_rxhash() to compute the queue index otherwise.

---
  drivers/net/xen-netback/common.h    |   66 +++--
  drivers/net/xen-netback/interface.c |  308 +++++++++++++--------
  drivers/net/xen-netback/netback.c   |  516 +++++++++++++++++-------------
-----
  drivers/net/xen-netback/xenbus.c    |   89 ++++--
  4 files changed, 556 insertions(+), 423 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h
index c47794b..54d2eeb 100644

drivers/net/xen-netback/common.h +0 -0
@@ -108,17 +108,19 @@ struct xenvif_rx_meta {
   */
  #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS *
 XEN_NETIF_RX_RING_SIZE)
 
Quoted 12 lines

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 115

Quoted 9 lines
drivers/net/xen-netback/common.h +5 -4
-struct xenvif {
-	/* Unique identifier for this interface. */
-	domid_t          domid;
-	unsigned int     handle;
+struct xenvif;
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */

I wonder whether it would be neater to #define the name size here...

Absolutely. I'll do this in V2.

Quoted 12 lines

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 123

Quoted 9 lines
drivers/net/xen-netback/common.h +2 -1
+	struct xenvif *vif; /* Parent VIF */
 
  	/* Use NAPI for guest TX */
  	struct napi_struct napi;
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int tx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */

...and the IRQ name size here. It's kind of ugly to have + some_magic_value in array definitions.

As above.

Quoted 16 lines
Quoted 16 lines
drivers/net/xen-netback/common.h +0 -0
  	struct xen_netif_tx_back_ring tx;
  	struct sk_buff_head tx_queue;
  	struct page *mmap_pages[MAX_PENDING_REQS];
drivers/net/xen-netback/common.h +1 -1
@@ -140,7 +142,7 @@ struct xenvif {
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int rx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
  	struct xen_netif_rx_back_ring rx;
  	struct sk_buff_head rx_queue;
 
@@ -150,14 +152,27 @@ struct xenvif {
  	 */
  	RING_IDX rx_req_cons_peek;
 
Quoted 6 lines

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 3 lines
drivers/net/xen-netback/common.h +1 -2
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

I see you brought this back in line, which is reasonable as the queue is now a separately allocated struct.

Indeed; trying to keep the number of separate allocs/frees to a minimum, for everybody's sanity!

Quoted 37 lines
Quoted 37 lines
drivers/net/xen-netback/common.h +17 -6
  	/* We create one meta structure per ring request we consume, so
  	 * the maximum number is the same as the ring size.
  	 */
  	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+
+struct xenvif {
+	/* Unique identifier for this interface. */
+	domid_t          domid;
+	unsigned int     handle;
+
  	u8               fe_dev_addr[6];
 
  	/* Frontend feature information. */
@@ -171,12 +186,9 @@ struct xenvif {
  	/* Internal feature information. */
  	u8 can_queue:1;	    /* can queue packets for receiver? */
 
-	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
-	unsigned long   credit_bytes;
-	unsigned long   credit_usec;
-	unsigned long   remaining_credit;
-	struct timer_list credit_timeout;
-	u64 credit_window_start;
+	/* Queues */
+	unsigned int num_queues;
+	struct xenvif_queue *queues;
 
Quoted 4 lines

drivers/net/xen-netback/common.h struct xenvif { · line 193

Quoted 1 line
drivers/net/xen-netback/common.h +0 -0
  	/* Statistics */

Do stats need to be per-queue (and then possibly aggregated at query time)?

Aside from the potential to see the stats for each queue, which may be useful in some limited circumstances for performance testing or debugging, I don't see what this buys us...

Quoted 123 lines
Quoted 76 lines
drivers/net/xen-netback/common.h +10 -8
  	unsigned long rx_gso_checksum_fixup;
@@ -194,7 +206,9 @@ struct xenvif *xenvif_alloc(struct device *parent,
  			    domid_t domid,
  			    unsigned int handle);
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
+void xenvif_init_queue(struct xenvif_queue *queue);
+
+int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
  		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
  		   unsigned int rx_evtchn);
  void xenvif_disconnect(struct xenvif *vif);
@@ -205,23 +219,23 @@ void xenvif_xenbus_fini(void);
 
  int xenvif_schedulable(struct xenvif *vif);
 
-int xenvif_rx_ring_full(struct xenvif *vif);
+int xenvif_rx_ring_full(struct xenvif_queue *queue);
 
-int xenvif_must_stop_queue(struct xenvif *vif);
+int xenvif_must_stop_queue(struct xenvif_queue *queue);
 
  /* (Un)Map communication rings. */
-void xenvif_unmap_frontend_rings(struct xenvif *vif);
-int xenvif_map_frontend_rings(struct xenvif *vif,
+void xenvif_unmap_frontend_rings(struct xenvif_queue *queue);
+int xenvif_map_frontend_rings(struct xenvif_queue *queue,
  			      grant_ref_t tx_ring_ref,
  			      grant_ref_t rx_ring_ref);
 
  /* Check for SKBs from frontend and schedule backend processing */
-void xenvif_check_rx_xenvif(struct xenvif *vif);
+void xenvif_check_rx_xenvif(struct xenvif_queue *queue);
 
  /* Queue an SKB for transmission to the frontend */
-void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);
+void xenvif_queue_tx_skb(struct xenvif_queue *queue, struct sk_buff
 *skb);
  /* Notify xenvif that ring now has space to send an skb to the frontend */
-void xenvif_notify_tx_completion(struct xenvif *vif);
+void xenvif_notify_tx_completion(struct xenvif_queue *queue);
 
  /* Prevent the device from generating any further traffic. */
  void xenvif_carrier_off(struct xenvif *vif);
drivers/net/xen-netback/common.h +6 -2
@@ -229,11 +243,15 @@ void xenvif_carrier_off(struct xenvif *vif);
  /* Returns number of ring slots required to send an skb to the frontend */
  unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb);
 
-int xenvif_tx_action(struct xenvif *vif, int budget);
-void xenvif_rx_action(struct xenvif *vif);
+int xenvif_tx_action(struct xenvif_queue *queue, int budget);
+void xenvif_rx_action(struct xenvif_queue *queue);
 
  int xenvif_kthread(void *data);
 
+int xenvif_poll(struct napi_struct *napi, int budget);
+
+void xenvif_carrier_on(struct xenvif *vif);
+
  extern bool separate_tx_rx_irq;
 
  #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen- renamed from drivers/net/xen-netback/interface.c +0 -0

netback/interface.c
index fff8cdd..0113324 100644

drivers/net/xen-netback/interface.c +0 -1
@@ -34,7 +34,6 @@
  #include <linux/ethtool.h>
  #include <linux/rtnetlink.h>
  #include <linux/if_vlan.h>
-#include <linux/vmalloc.h>
 
  #include <xen/events.h>
  #include <asm/xen/hypercall.h>

drivers/net/xen-netback/interface.c line 48

Quoted 8 lines
drivers/net/xen-netback/interface.c +4 -0
@@ -42,32 +41,50 @@
  #define XENVIF_QUEUE_LENGTH 32
  #define XENVIF_NAPI_WEIGHT  64
 
+static inline void xenvif_wake_queue(struct xenvif_queue *queue)
+{
+	netif_tx_wake_queue(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 > number));

Might be neater to declare some stack variables for dev and number to avoid the long line.

drivers/net/xen-netback/interface.c

Quoted 7 lines
drivers/net/xen-netback/interface.c +6 -0
+}
+
+static inline void xenvif_stop_queue(struct xenvif_queue *queue)
+{
+	netif_tx_stop_queue(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 > number));

Ditto.

drivers/net/xen-netback/interface.c

Quoted 7 lines
drivers/net/xen-netback/interface.c +6 -0
+}
+
+static inline int xenvif_queue_stopped(struct xenvif_queue *queue)
+{
+	return netif_tx_queue_stopped(
+			netdev_get_tx_queue(queue->vif->dev, queue-
 > number));

Ditto.

drivers/net/xen-netback/interface.c

Quoted 13 lines
drivers/net/xen-netback/interface.c +4 -2
+}
+
  int xenvif_schedulable(struct xenvif *vif)
  {
  	return netif_running(vif->dev) && netif_carrier_ok(vif->dev);
  }
 
-static int xenvif_rx_schedulable(struct xenvif *vif)
+static int xenvif_rx_schedulable(struct xenvif_queue *queue)
  {
-	return xenvif_schedulable(vif) && !xenvif_rx_ring_full(vif);
+	return xenvif_schedulable(queue->vif) &&
 !xenvif_rx_ring_full(queue);

I guess your patches have not been re-based onto net-next? xenvif_ring_full() and xenvif_rx_schedulable() went away in c/s ca2f09f2b2c6c25047cfc545d057c4edfcfe561c (xen-netback: improve guest-receive-side flow control).

Quoted 1 line

Can you rebase? Eventual patches will need to go into net-next.

They haven't yet; I wanted to get some comments on these, but I will definitely rebase onto net-next in the near future.

Quoted 101 lines

Paul

Quoted 60 lines
drivers/net/xen-netback/interface.c +7 -7
  }
 
  static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id)
  {
-	struct xenvif *vif = dev_id;
+	struct xenvif_queue *queue = dev_id;
 
-	if (RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
-		napi_schedule(&vif->napi);
+	if (RING_HAS_UNCONSUMED_REQUESTS(&queue->tx))
+		napi_schedule(&queue->napi);
 
  	return IRQ_HANDLED;
  }
 
-static int xenvif_poll(struct napi_struct *napi, int budget)
+int xenvif_poll(struct napi_struct *napi, int budget)
  {
-	struct xenvif *vif = container_of(napi, struct xenvif, napi);
+	struct xenvif_queue *queue = container_of(napi, struct
 xenvif_queue, napi);
  	int work_done;
 
-	work_done = xenvif_tx_action(vif, budget);
+	work_done = xenvif_tx_action(queue, budget);
 
  	if (work_done < budget) {
  		int more_to_do = 0;
@@ -91,7 +108,7 @@ static int xenvif_poll(struct napi_struct *napi, int
 budget)
 
  		local_irq_save(flags);
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,
 more_to_do);
+		RING_FINAL_CHECK_FOR_REQUESTS(&queue->tx,
 more_to_do);
  		if (!more_to_do)
  			__napi_complete(napi);
drivers/net/xen-netback/interface.c +3 -3
@@ -103,10 +120,10 @@ static int xenvif_poll(struct napi_struct *napi, int
 budget)
 
  static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
  {
-	struct xenvif *vif = dev_id;
+	struct xenvif_queue *queue = dev_id;
 
-	if (xenvif_rx_schedulable(vif))
-		netif_wake_queue(vif->dev);
+	if (xenvif_rx_schedulable(queue))
+		xenvif_wake_queue(queue);
 
  	return IRQ_HANDLED;
  }
drivers/net/xen-netback/interface.c +0 -0
@@ -119,27 +136,56 @@ static irqreturn_t xenvif_interrupt(int irq, void
 *dev_id)
  	return IRQ_HANDLED;
  }
 

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void · line 149

Quoted 10 lines
drivers/net/xen-netback/interface.c +10 -0
+static u16 select_queue(struct net_device *dev, struct sk_buff *skb)
+{
+	struct xenvif *vif = netdev_priv(dev);
+	u32 hash;
+	u16 queue_index;
+
+	/* First, check if there is only one queue */
+	if (vif->num_queues == 1) {
+		queue_index = 0;
+	}

Style.

Quoted 13 lines
drivers/net/xen-netback/interface.c +9 -0
+	else {
+		/* Use skb_get_rxhash to obtain an L4 hash if available */
+		hash = skb_get_rxhash(skb);
+		queue_index = (u16) (((u64)hash * vif->num_queues) >>
 32);
+	}
+
+	return queue_index;
+}
+
  static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
  {
  	struct xenvif *vif = netdev_priv(dev);

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 168

Quoted 10 lines
drivers/net/xen-netback/interface.c +5 -2
+	u16 queue_index = 0;
+	struct xenvif_queue *queue = NULL;
 
  	BUG_ON(skb->dev != dev);
 
-	/* Drop the packet if vif is not ready */
-	if (vif->task == NULL)
+	/* Drop the packet if the queues are not set up */
+	if (vif->num_queues < 1 || vif->queues == NULL)
+		goto drop;

Just do the former test and ASSERT the second.

Quoted 6 lines

drivers/net/xen-netback/interface.c static irqreturn_t xenvif_interrupt(int irq, void *dev_id) · line 171

Quoted 3 lines
drivers/net/xen-netback/interface.c +3 -0
+
+	/* Obtain the queue to be used to transmit this packet */
+	queue_index = skb_get_queue_mapping(skb);

Personally, I'd stick a range check here.

OK.

Andrew

Quoted 2,016 lines
Quoted 2,015 lines
drivers/net/xen-netback/interface.c +9 -5
+	queue = &vif->queues[queue_index];
+
+	/* Drop the packet if queue is not ready */
+	if (queue->task == NULL)
  		goto drop;
 
  	/* Drop the packet if the target domain has no receive buffers. */
-	if (!xenvif_rx_schedulable(vif))
+	if (!xenvif_rx_schedulable(queue))
  		goto drop;
 
  	/* Reserve ring slots for the worst-case number of fragments. */
-	vif->rx_req_cons_peek += xenvif_count_skb_slots(vif, skb);
+	queue->rx_req_cons_peek += xenvif_count_skb_slots(vif, skb);
 
-	if (vif->can_queue && xenvif_must_stop_queue(vif))
-		netif_stop_queue(dev);
+	if (vif->can_queue && xenvif_must_stop_queue(queue))
+		xenvif_stop_queue(queue);
 
-	xenvif_queue_tx_skb(vif, skb);
+	xenvif_queue_tx_skb(queue, skb);
 

return NETDEV_TX_OK;

drivers/net/xen-netback/interface.c +3 -3
@@ -149,10 +195,10 @@ static int xenvif_start_xmit(struct sk_buff *skb,
 struct net_device *dev)
  	return NETDEV_TX_OK;
  }
 
-void xenvif_notify_tx_completion(struct xenvif *vif)
+void xenvif_notify_tx_completion(struct xenvif_queue *queue)
  {
-	if (netif_queue_stopped(vif->dev) && xenvif_rx_schedulable(vif))
-		netif_wake_queue(vif->dev);
+	if (xenvif_queue_stopped(queue) &&
 xenvif_rx_schedulable(queue))
+		xenvif_wake_queue(queue);
  }

static struct net_device_stats *xenvif_get_stats(struct net_device *dev)

drivers/net/xen-netback/interface.c +25 -12
@@ -163,20 +209,30 @@ static struct net_device_stats
 *xenvif_get_stats(struct net_device *dev)
 
  static void xenvif_up(struct xenvif *vif)
  {
-	napi_enable(&vif->napi);
-	enable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		enable_irq(vif->rx_irq);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_enable(&queue->napi);
+		enable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			enable_irq(queue->rx_irq);
+		xenvif_check_rx_xenvif(queue);
+	}
  }
 
  static void xenvif_down(struct xenvif *vif)
  {
-	napi_disable(&vif->napi);
-	disable_irq(vif->tx_irq);
-	if (vif->tx_irq != vif->rx_irq)
-		disable_irq(vif->rx_irq);
-	del_timer_sync(&vif->credit_timeout);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
+		napi_disable(&queue->napi);
+		disable_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			disable_irq(queue->rx_irq);
+		del_timer_sync(&queue->credit_timeout);
+	}
  }
 
  static int xenvif_open(struct net_device *dev)
@@ -184,7 +240,7 @@ static int xenvif_open(struct net_device *dev)
  	struct xenvif *vif = netdev_priv(dev);
  	if (netif_carrier_ok(dev))
  		xenvif_up(vif);
-	netif_start_queue(dev);
+	netif_tx_start_all_queues(dev);
  	return 0;
  }
 
@@ -193,7 +249,7 @@ static int xenvif_close(struct net_device *dev)
  	struct xenvif *vif = netdev_priv(dev);
  	if (netif_carrier_ok(dev))
  		xenvif_down(vif);
-	netif_stop_queue(dev);
+	netif_tx_stop_all_queues(dev);
  	return 0;
  }
 
@@ -287,6 +343,7 @@ static const struct net_device_ops
 xenvif_netdev_ops = {
  	.ndo_fix_features = xenvif_fix_features,
  	.ndo_set_mac_address = eth_mac_addr,
  	.ndo_validate_addr   = eth_validate_addr,
+	.ndo_select_queue = select_queue,
  };
 

struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,

drivers/net/xen-netback/interface.c +1 -2
@@ -296,10 +353,9 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
  	struct net_device *dev;
  	struct xenvif *vif;
  	char name[IFNAMSIZ] = {};
-	int i;
 
  	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev(sizeof(struct xenvif), name, ether_setup);
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
  	if (dev == NULL) {
  		pr_warn("Could not allocate netdev for %s\n", name);
  		return ERR_PTR(-ENOMEM);
drivers/net/xen-netback/interface.c +3 -12
@@ -309,24 +365,15 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 
  	vif = netdev_priv(dev);
 
-	vif->grant_copy_op = vmalloc(sizeof(struct gnttab_copy) *
-				     MAX_GRANT_COPY_OPS);
-	if (vif->grant_copy_op == NULL) {
-		pr_warn("Could not allocate grant copy space for %s\n",
 name);
-		free_netdev(dev);
-		return ERR_PTR(-ENOMEM);
-	}
-
  	vif->domid  = domid;
  	vif->handle = handle;
  	vif->can_sg = 1;
  	vif->ip_csum = 1;
  	vif->dev = dev;
 
-	vif->credit_bytes = vif->remaining_credit = ~0UL;
-	vif->credit_usec  = 0UL;
-	init_timer(&vif->credit_timeout);
-	vif->credit_window_start = get_jiffies_64();
+	/* Start out with no queues */
+	vif->num_queues = 0;
+	vif->queues = NULL;
 
  	dev->netdev_ops	= &xenvif_netdev_ops;
  	dev->hw_features = NETIF_F_SG |
drivers/net/xen-netback/interface.c +0 -10
@@ -337,16 +384,6 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 
  	dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
 
-	skb_queue_head_init(&vif->rx_queue);
-	skb_queue_head_init(&vif->tx_queue);
-
-	vif->pending_cons = 0;
-	vif->pending_prod = MAX_PENDING_REQS;
-	for (i = 0; i < MAX_PENDING_REQS; i++)
-		vif->pending_ring[i] = i;
-	for (i = 0; i < MAX_PENDING_REQS; i++)
-		vif->mmap_pages[i] = NULL;
-
  	/*
  	 * Initialise a dummy MAC address. We choose the numerically

* largest non-broadcast address to prevent the address getting

drivers/net/xen-netback/interface.c +0 -2
@@ -356,8 +393,6 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
  	memset(dev->dev_addr, 0xFF, ETH_ALEN);
  	dev->dev_addr[0] &= ~0x01;
 
-	netif_napi_add(dev, &vif->napi, xenvif_poll,
 XENVIF_NAPI_WEIGHT);
-
  	netif_carrier_off(dev);
  	err = register_netdev(dev);
drivers/net/xen-netback/interface.c +64 -38
@@ -374,84 +409,110 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
  	return vif;
  }
 
-int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,
+void xenvif_init_queue(struct xenvif_queue *queue)
+{
+	int i;
+
+	queue->credit_bytes = queue->remaining_credit = ~0UL;
+	queue->credit_usec  = 0UL;
+	init_timer(&queue->credit_timeout);
+	queue->credit_window_start = get_jiffies_64();
+
+	skb_queue_head_init(&queue->rx_queue);
+	skb_queue_head_init(&queue->tx_queue);
+
+	queue->pending_cons = 0;
+	queue->pending_prod = MAX_PENDING_REQS;
+	for (i = 0; i < MAX_PENDING_REQS; ++i) {
+		queue->pending_ring[i] = i;
+		queue->mmap_pages[i] = NULL;
+	}
+
+	netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
+			XENVIF_NAPI_WEIGHT);
+}
+
+void xenvif_carrier_on(struct xenvif *vif)
+{
+	rtnl_lock();
+	if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
+		dev_set_mtu(vif->dev, ETH_DATA_LEN);
+	netdev_update_features(vif->dev);
+	netif_carrier_on(vif->dev);
+	if (netif_running(vif->dev))
+		xenvif_up(vif);
+	rtnl_unlock();
+}
+
+int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
  		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
  		   unsigned int rx_evtchn)
  {
  	struct task_struct *task;
  	int err = -ENOMEM;
 
-	BUG_ON(vif->tx_irq);
-	BUG_ON(vif->task);
+	BUG_ON(queue->tx_irq);
+	BUG_ON(queue->task);
 
-	err = xenvif_map_frontend_rings(vif, tx_ring_ref, rx_ring_ref);
+	err = xenvif_map_frontend_rings(queue, tx_ring_ref, rx_ring_ref);
  	if (err < 0)
  		goto err;
 
  	if (tx_evtchn == rx_evtchn) {
  		/* feature-split-event-channels == 0 */
  		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, tx_evtchn, xenvif_interrupt, 0,
-			vif->dev->name, vif);
+			queue->vif->domid, tx_evtchn, xenvif_interrupt, 0,
+			queue->name, queue);
  		if (err < 0)
  			goto err_unmap;
-		vif->tx_irq = vif->rx_irq = err;
-		disable_irq(vif->tx_irq);
+		queue->tx_irq = queue->rx_irq = err;
+		disable_irq(queue->tx_irq);
  	} else {
  		/* feature-split-event-channels == 1 */
-		snprintf(vif->tx_irq_name, sizeof(vif->tx_irq_name),
-			 "%s-tx", vif->dev->name);
+		snprintf(queue->tx_irq_name, sizeof(queue->tx_irq_name),
+			 "%s-tx", queue->name);
  		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, tx_evtchn, xenvif_tx_interrupt, 0,
-			vif->tx_irq_name, vif);
+			queue->vif->domid, tx_evtchn, xenvif_tx_interrupt,
 0,
+			queue->tx_irq_name, queue);
  		if (err < 0)
  			goto err_unmap;
-		vif->tx_irq = err;
-		disable_irq(vif->tx_irq);
+		queue->tx_irq = err;
+		disable_irq(queue->tx_irq);
 
-		snprintf(vif->rx_irq_name, sizeof(vif->rx_irq_name),
-			 "%s-rx", vif->dev->name);
+		snprintf(queue->rx_irq_name, sizeof(queue->rx_irq_name),
+			 "%s-rx", queue->name);
  		err = bind_interdomain_evtchn_to_irqhandler(
-			vif->domid, rx_evtchn, xenvif_rx_interrupt, 0,
-			vif->rx_irq_name, vif);
+			queue->vif->domid, rx_evtchn, xenvif_rx_interrupt,
 0,
+			queue->rx_irq_name, queue);
  		if (err < 0)
  			goto err_tx_unbind;
-		vif->rx_irq = err;
-		disable_irq(vif->rx_irq);
+		queue->rx_irq = err;
+		disable_irq(queue->rx_irq);
  	}
 
-	init_waitqueue_head(&vif->wq);
+	init_waitqueue_head(&queue->wq);
  	task = kthread_create(xenvif_kthread,
-			      (void *)vif, "%s", vif->dev->name);
+			      (void *)queue, "%s", queue->name);
  	if (IS_ERR(task)) {
-		pr_warn("Could not allocate kthread for %s\n", vif->dev-
 > name);
+		pr_warn("Could not allocate kthread for %s\n", queue-
 > name);
  		err = PTR_ERR(task);
  		goto err_rx_unbind;
  	}
 
-	vif->task = task;
-
-	rtnl_lock();
-	if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
-		dev_set_mtu(vif->dev, ETH_DATA_LEN);
-	netdev_update_features(vif->dev);
-	netif_carrier_on(vif->dev);
-	if (netif_running(vif->dev))
-		xenvif_up(vif);
-	rtnl_unlock();
+	queue->task = task;
 
-	wake_up_process(vif->task);
+	wake_up_process(queue->task);
 
  	return 0;
 
  err_rx_unbind:
-	unbind_from_irqhandler(vif->rx_irq, vif);
-	vif->rx_irq = 0;
+	unbind_from_irqhandler(queue->rx_irq, queue);
+	queue->rx_irq = 0;
  err_tx_unbind:
-	unbind_from_irqhandler(vif->tx_irq, vif);
-	vif->tx_irq = 0;
+	unbind_from_irqhandler(queue->tx_irq, queue);
+	queue->tx_irq = 0;

err_unmap:

drivers/net/xen-netback/interface.c +35 -16
-	xenvif_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(queue);
  err:
  	module_put(THIS_MODULE);
  	return err;
@@ -470,34 +531,51 @@ void xenvif_carrier_off(struct xenvif *vif)
 
  void xenvif_disconnect(struct xenvif *vif)
  {
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
+
  	if (netif_carrier_ok(vif->dev))
  		xenvif_carrier_off(vif);
 
-	if (vif->task) {
-		kthread_stop(vif->task);
-		vif->task = NULL;
-	}
+	for (queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		queue = &vif->queues[queue_index];
 
-	if (vif->tx_irq) {
-		if (vif->tx_irq == vif->rx_irq)
-			unbind_from_irqhandler(vif->tx_irq, vif);
-		else {
-			unbind_from_irqhandler(vif->tx_irq, vif);
-			unbind_from_irqhandler(vif->rx_irq, vif);
+		if (queue->task) {
+			kthread_stop(queue->task);
+			queue->task = NULL;
  		}
-		vif->tx_irq = 0;
+
+		if (queue->tx_irq) {
+			if (queue->tx_irq == queue->rx_irq)
+				unbind_from_irqhandler(queue->tx_irq,
 queue);
+			else {
+				unbind_from_irqhandler(queue->tx_irq,
 queue);
+				unbind_from_irqhandler(queue->rx_irq,
 queue);
+			}
+			queue->tx_irq = 0;
+		}
+
+		xenvif_unmap_frontend_rings(queue);
  	}
 
-	xenvif_unmap_frontend_rings(vif);
+
  }
 
  void xenvif_free(struct xenvif *vif)
  {
-	netif_napi_del(&vif->napi);
+	struct xenvif_queue *queue = NULL;
+	unsigned int queue_index;
 
-	unregister_netdev(vif->dev);
+	for(queue_index = 0; queue_index < vif->num_queues;
++queue_index) {
+		netif_napi_del(&queue->napi);
+	}
 
-	vfree(vif->grant_copy_op);
+	/* Free the array of queues */
+	vfree(vif->queues);
+	vif->num_queues = 0;
+	vif->queues = 0;
+
+	unregister_netdev(vif->dev);
  	free_netdev(vif->dev);
 
  	module_put(THIS_MODULE);
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 7842555..586e741 100644

drivers/net/xen-netback/netback.c +10 -10
@@ -76,38 +76,38 @@ module_param(fatal_skb_slots, uint, 0444);
   * one or more merged tx requests, otherwise it is the continuation of
   * previous tx request.
   */
-static inline int pending_tx_is_head(struct xenvif *vif, RING_IDX idx)
+static inline int pending_tx_is_head(struct xenvif_queue *queue,
 RING_IDX idx)
  {
-	return vif->pending_tx_info[idx].head !=
 INVALID_PENDING_RING_IDX;
+	return queue->pending_tx_info[idx].head !=
 INVALID_PENDING_RING_IDX;
  }
 
-static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
+static void xenvif_idx_release(struct xenvif_queue *queue, u16
 pending_idx,
  			       u8 status);
 
-static void make_tx_response(struct xenvif *vif,
+static void make_tx_response(struct xenvif_queue *queue,
  			     struct xen_netif_tx_request *txp,
  			     s8       st);
 
-static inline int tx_work_todo(struct xenvif *vif);
-static inline int rx_work_todo(struct xenvif *vif);
+static inline int tx_work_todo(struct xenvif_queue *queue);
+static inline int rx_work_todo(struct xenvif_queue *queue);
 
-static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
+static struct xen_netif_rx_response *make_rx_response(struct
 xenvif_queue *queue,
  					     u16      id,
  					     s8       st,
  					     u16      offset,
  					     u16      size,
  					     u16      flags);
 
-static inline unsigned long idx_to_pfn(struct xenvif *vif,
+static inline unsigned long idx_to_pfn(struct xenvif_queue *queue,
  				       u16 idx)
  {
-	return page_to_pfn(vif->mmap_pages[idx]);
+	return page_to_pfn(queue->mmap_pages[idx]);
  }
 
-static inline unsigned long idx_to_kaddr(struct xenvif *vif,
+static inline unsigned long idx_to_kaddr(struct xenvif_queue *queue,
  					 u16 idx)
  {
drivers/net/xen-netback/netback.c +3 -3
-	return (unsigned long)pfn_to_kaddr(idx_to_pfn(vif, idx));
+	return (unsigned long)pfn_to_kaddr(idx_to_pfn(queue, idx));
  }
 
  /* This is a miniumum size for the linear area to avoid lots of
@@ -132,10 +132,10 @@ static inline pending_ring_idx_t
 pending_index(unsigned i)
  	return i & (MAX_PENDING_REQS-1);
  }
 
-static inline pending_ring_idx_t nr_pending_reqs(struct xenvif *vif)
+static inline pending_ring_idx_t nr_pending_reqs(struct xenvif_queue
 *queue)
  {
  	return MAX_PENDING_REQS -
-		vif->pending_prod + vif->pending_cons;
+		queue->pending_prod + queue->pending_cons;
  }

static int max_required_rx_slots(struct xenvif *vif)

drivers/net/xen-netback/netback.c +10 -10
@@ -149,25 +149,25 @@ static int max_required_rx_slots(struct xenvif *vif)
  	return max;
  }
 
-int xenvif_rx_ring_full(struct xenvif *vif)
+int xenvif_rx_ring_full(struct xenvif_queue *queue)
  {
-	RING_IDX peek   = vif->rx_req_cons_peek;
-	RING_IDX needed = max_required_rx_slots(vif);
+	RING_IDX peek   = queue->rx_req_cons_peek;
+	RING_IDX needed = max_required_rx_slots(queue->vif);
 
-	return ((vif->rx.sring->req_prod - peek) < needed) ||
-	       ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) <
 needed);
+	return ((queue->rx.sring->req_prod - peek) < needed) ||
+	       ((queue->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) <
 needed);
  }
 
-int xenvif_must_stop_queue(struct xenvif *vif)
+int xenvif_must_stop_queue(struct xenvif_queue *queue)
  {
-	if (!xenvif_rx_ring_full(vif))
+	if (!xenvif_rx_ring_full(queue))
  		return 0;
 
-	vif->rx.sring->req_event = vif->rx_req_cons_peek +
-		max_required_rx_slots(vif);
+	queue->rx.sring->req_event = queue->rx_req_cons_peek +
+		max_required_rx_slots(queue->vif);
  	mb(); /* request notification /then/ check the queue */
 
-	return xenvif_rx_ring_full(vif);
+	return xenvif_rx_ring_full(queue);
  }

/*

drivers/net/xen-netback/netback.c +2 -2
@@ -306,13 +306,13 @@ struct netrx_pending_operations {
  	grant_ref_t copy_gref;
  };
 
-static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif *vif,
+static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif_queue
 *queue,
  						 struct
 netrx_pending_operations *npo)
  {
  	struct xenvif_rx_meta *meta;
  	struct xen_netif_rx_request *req;
 
-	req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+	req = RING_GET_REQUEST(&queue->rx, queue->rx.req_cons++);
 
  	meta = npo->meta + npo->meta_prod++;
  	meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
drivers/net/xen-netback/netback.c +1 -1
@@ -330,7 +330,7 @@ static struct xenvif_rx_meta
 *get_next_rx_buffer(struct xenvif *vif,
   * Set up the grant operations for this fragment. If it's a flipping
   * interface, we also set up the unmap request from here.
   */
-static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
+static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct
 sk_buff *skb,
  				 struct netrx_pending_operations *npo,

struct page *page, unsigned long size, unsigned long offset, int *head)

drivers/net/xen-netback/netback.c +1 -1
@@ -365,7 +365,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
  			 */
  			BUG_ON(*head);
 
-			meta = get_next_rx_buffer(vif, npo);
+			meta = get_next_rx_buffer(queue, npo);
  		}
 

if (npo->copy_off + bytes > MAX_BUFFER_OFFSET)

drivers/net/xen-netback/netback.c +1 -1
@@ -379,7 +379,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
  		copy_gop->source.u.gmfn =
 virt_to_mfn(page_address(page));
  		copy_gop->source.offset = offset;
 
-		copy_gop->dest.domid = vif->domid;
+		copy_gop->dest.domid = queue->vif->domid;
  		copy_gop->dest.offset = npo->copy_off;
  		copy_gop->dest.u.ref = npo->copy_gref;
drivers/net/xen-netback/netback.c +4 -3
@@ -404,8 +404,8 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
  		else
  			gso_type = XEN_NETIF_GSO_TYPE_NONE;
 
-		if (*head && ((1 << gso_type) & vif->gso_mask))
-			vif->rx.req_cons++;
+		if (*head && ((1 << gso_type) & queue->vif->gso_mask))
+			queue->rx.req_cons++;
 
  		*head = 0; /* There must be something in this buffer now. */
@@ -425,7 +425,8 @@ static void xenvif_gop_frag_copy(struct xenvif *vif,
 struct sk_buff *skb,
   * frontend-side LRO).
   */
  static int xenvif_gop_skb(struct sk_buff *skb,
-			  struct netrx_pending_operations *npo)
+			  struct netrx_pending_operations *npo,
+			  struct xenvif_queue *queue)
  {
  	struct xenvif *vif = netdev_priv(skb->dev);
  	int nr_frags = skb_shinfo(skb)->nr_frags;
drivers/net/xen-netback/netback.c +1 -1
@@ -453,7 +454,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
 
  	/* Set up a GSO prefix descriptor, if necessary */
  	if ((1 << gso_type) & vif->gso_prefix_mask) {
-		req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+		req = RING_GET_REQUEST(&queue->rx, queue-
 > rx.req_cons++);
  		meta = npo->meta + npo->meta_prod++;
  		meta->gso_type = gso_type;
  		meta->gso_size = gso_size;
drivers/net/xen-netback/netback.c +3 -3
@@ -461,7 +462,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
  		meta->id = req->id;
  	}
 
-	req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
+	req = RING_GET_REQUEST(&queue->rx, queue->rx.req_cons++);
  	meta = npo->meta + npo->meta_prod++;
 
  	if ((1 << gso_type) & vif->gso_mask) {
@@ -485,13 +486,13 @@ static int xenvif_gop_skb(struct sk_buff *skb,
  		if (data + len > skb_tail_pointer(skb))
  			len = skb_tail_pointer(skb) - data;
 
-		xenvif_gop_frag_copy(vif, skb, npo,
+		xenvif_gop_frag_copy(queue, skb, npo,
  				     virt_to_page(data), len, offset, &head);
  		data += len;
  	}
 
  	for (i = 0; i < nr_frags; i++) {
-		xenvif_gop_frag_copy(vif, skb, npo,
+		xenvif_gop_frag_copy(queue, skb, npo,
  				     skb_frag_page(&skb_shinfo(skb)-
 > frags[i]),
  				     skb_frag_size(&skb_shinfo(skb)->frags[i]),

skb_shinfo(skb)->frags[i].page_offset,

drivers/net/xen-netback/netback.c +1 -1
@@ -527,7 +528,7 @@ static int xenvif_check_gop(struct xenvif *vif, int
 nr_meta_slots,
  	return status;
  }
 
-static void xenvif_add_frag_responses(struct xenvif *vif, int status,
+static void xenvif_add_frag_responses(struct xenvif_queue *queue, int
 status,
  				      struct xenvif_rx_meta *meta,
  				      int nr_meta_slots)
  {
drivers/net/xen-netback/netback.c +1 -1
@@ -548,7 +549,7 @@ static void xenvif_add_frag_responses(struct xenvif
 *vif, int status,
  			flags = XEN_NETRXF_more_data;
 
  		offset = 0;
-		make_rx_response(vif, meta[i].id, status, offset,
+		make_rx_response(queue, meta[i].id, status, offset,
  				 meta[i].size, flags);
  	}
  }
drivers/net/xen-netback/netback.c +15 -18
@@ -557,12 +558,12 @@ struct skb_cb_overlay {
  	int meta_slots_used;
  };
 
-static void xenvif_kick_thread(struct xenvif *vif)
+static void xenvif_kick_thread(struct xenvif_queue *queue)
  {
-	wake_up(&vif->wq);
+	wake_up(&queue->wq);
  }
 
-void xenvif_rx_action(struct xenvif *vif)
+void xenvif_rx_action(struct xenvif_queue *queue)
  {
  	s8 status;
  	u16 flags;
@@ -578,20 +579,19 @@ void xenvif_rx_action(struct xenvif *vif)
  	int need_to_notify = 0;
 
  	struct netrx_pending_operations npo = {
-		.copy  = vif->grant_copy_op,
-		.meta  = vif->meta,
+		.copy  = queue->grant_copy_op,
+		.meta  = queue->meta,
  	};
 
  	skb_queue_head_init(&rxq);
 
  	count = 0;
 
-	while ((skb = skb_dequeue(&vif->rx_queue)) != NULL) {
-		vif = netdev_priv(skb->dev);
+	while ((skb = skb_dequeue(&queue->rx_queue)) != NULL) {
  		nr_frags = skb_shinfo(skb)->nr_frags;
 
  		sco = (struct skb_cb_overlay *)skb->cb;
-		sco->meta_slots_used = xenvif_gop_skb(skb, &npo);
+		sco->meta_slots_used = xenvif_gop_skb(skb, &npo, queue);
 
  		count += nr_frags + 1;
 
@@ -603,28 +603,26 @@ void xenvif_rx_action(struct xenvif *vif)
  			break;
  	}
 
-	BUG_ON(npo.meta_prod > ARRAY_SIZE(vif->meta));
+	BUG_ON(npo.meta_prod > ARRAY_SIZE(queue->meta));
 
  	if (!npo.copy_prod)
  		return;
 
  	BUG_ON(npo.copy_prod > MAX_GRANT_COPY_OPS);
-	gnttab_batch_copy(vif->grant_copy_op, npo.copy_prod);
+	gnttab_batch_copy(queue->grant_copy_op, npo.copy_prod);
 
  	while ((skb = __skb_dequeue(&rxq)) != NULL) {
  		sco = (struct skb_cb_overlay *)skb->cb;
 
-		vif = netdev_priv(skb->dev);
-
-		if ((1 << vif->meta[npo.meta_cons].gso_type) &
-		    vif->gso_prefix_mask) {
-			resp = RING_GET_RESPONSE(&vif->rx,
-						 vif->rx.rsp_prod_pvt++);
+		if ((1 << queue->meta[npo.meta_cons].gso_type) &
+		    queue->vif->gso_prefix_mask) {
+			resp = RING_GET_RESPONSE(&queue->rx,
+						 queue->rx.rsp_prod_pvt++);
 
  			resp->flags = XEN_NETRXF_gso_prefix |
 XEN_NETRXF_more_data;
 
-			resp->offset = vif->meta[npo.meta_cons].gso_size;
-			resp->id = vif->meta[npo.meta_cons].id;
+			resp->offset = queue-
 > meta[npo.meta_cons].gso_size;
+			resp->id = queue->meta[npo.meta_cons].id;
  			resp->status = sco->meta_slots_used;

npo.meta_cons++;

drivers/net/xen-netback/netback.c +3 -3
@@ -632,10 +630,10 @@ void xenvif_rx_action(struct xenvif *vif)
  		}
 
 
-		vif->dev->stats.tx_bytes += skb->len;
-		vif->dev->stats.tx_packets++;
+		queue->vif->dev->stats.tx_bytes += skb->len;
+		queue->vif->dev->stats.tx_packets++;
 
-		status = xenvif_check_gop(vif, sco->meta_slots_used,
 &npo);
+		status = xenvif_check_gop(queue->vif, sco-
 > meta_slots_used, &npo);
 
  		if (sco->meta_slots_used == 1)
  			flags = 0;
drivers/net/xen-netback/netback.c +6 -8
@@ -649,22 +647,22 @@ void xenvif_rx_action(struct xenvif *vif)
  			flags |= XEN_NETRXF_data_validated;
 
  		offset = 0;
-		resp = make_rx_response(vif, vif->meta[npo.meta_cons].id,
+		resp = make_rx_response(queue, queue-
 > meta[npo.meta_cons].id,
  					status, offset,
-					vif->meta[npo.meta_cons].size,
+					queue->meta[npo.meta_cons].size,
  					flags);
 
-		if ((1 << vif->meta[npo.meta_cons].gso_type) &
-		    vif->gso_mask) {
+		if ((1 << queue->meta[npo.meta_cons].gso_type) &
+		    queue->vif->gso_mask) {
  			struct xen_netif_extra_info *gso =
  				(struct xen_netif_extra_info *)
-				RING_GET_RESPONSE(&vif->rx,
-						  vif->rx.rsp_prod_pvt++);
+				RING_GET_RESPONSE(&queue->rx,
+						  queue-
 > rx.rsp_prod_pvt++);
 
  			resp->flags |= XEN_NETRXF_extra_info;
 
-			gso->u.gso.type = vif-
 > meta[npo.meta_cons].gso_type;
-			gso->u.gso.size = vif-
Quoted 1 line

meta[npo.meta_cons].gso_size;

drivers/net/xen-netback/netback.c +1 -0
+			gso->u.gso.type = queue-
Quoted 1 line

meta[npo.meta_cons].gso_type;

drivers/net/xen-netback/netback.c +1 -0
+			gso->u.gso.size = queue-
Quoted 1 line

meta[npo.meta_cons].gso_size;

gso->u.gso.pad = 0;
gso->u.gso.features = 0;

drivers/net/xen-netback/netback.c +14 -14
@@ -672,47 +670,47 @@ void xenvif_rx_action(struct xenvif *vif)
  			gso->flags = 0;
  		}
 
-		xenvif_add_frag_responses(vif, status,
-					  vif->meta + npo.meta_cons + 1,
+		xenvif_add_frag_responses(queue, status,
+					  queue->meta + npo.meta_cons + 1,
  					  sco->meta_slots_used);
 
-		RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->rx,
 ret);
+		RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->rx,
 ret);
 
  		if (ret)
  			need_to_notify = 1;
 
-		xenvif_notify_tx_completion(vif);
+		xenvif_notify_tx_completion(queue);
 
  		npo.meta_cons += sco->meta_slots_used;
  		dev_kfree_skb(skb);
  	}
 
  	if (need_to_notify)
-		notify_remote_via_irq(vif->rx_irq);
+		notify_remote_via_irq(queue->rx_irq);
 
  	/* More work to do? */
-	if (!skb_queue_empty(&vif->rx_queue))
-		xenvif_kick_thread(vif);
+	if (!skb_queue_empty(&queue->rx_queue))
+		xenvif_kick_thread(queue);
  }
 
-void xenvif_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb)
+void xenvif_queue_tx_skb(struct xenvif_queue *queue, struct sk_buff
 *skb)
  {
-	skb_queue_tail(&vif->rx_queue, skb);
+	skb_queue_tail(&queue->rx_queue, skb);
 
-	xenvif_kick_thread(vif);
+	xenvif_kick_thread(queue);
  }
 
-void xenvif_check_rx_xenvif(struct xenvif *vif)
+void xenvif_check_rx_xenvif(struct xenvif_queue *queue)
  {
  	int more_to_do;
 
-	RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, more_to_do);
+	RING_FINAL_CHECK_FOR_REQUESTS(&queue->tx, more_to_do);
 
  	if (more_to_do)
-		napi_schedule(&vif->napi);
+		napi_schedule(&queue->napi);
  }
 
-static void tx_add_credit(struct xenvif *vif)
+static void tx_add_credit(struct xenvif_queue *queue)
  {
  	unsigned long max_burst, max_credit;
drivers/net/xen-netback/netback.c +0 -0
@@ -720,37 +718,37 @@ static void tx_add_credit(struct xenvif *vif)
  	 * Allow a burst big enough to transmit a jumbo packet of up to

128kB.
* Otherwise the interface can seize up due to insufficient credit. */

drivers/net/xen-netback/netback.c +1 -1
-	max_burst = RING_GET_REQUEST(&vif->tx, vif->tx.req_cons)->size;
+	max_burst = RING_GET_REQUEST(&queue->tx, queue-
Quoted 1 line

tx.req_cons)->size;

max_burst = min(max_burst, 131072UL);

drivers/net/xen-netback/netback.c +1 -1
-	max_burst = max(max_burst, vif->credit_bytes);
+	max_burst = max(max_burst, queue->credit_bytes);
 
  	/* Take care that adding a new chunk of credit doesn't wrap to zero.

*/

drivers/net/xen-netback/netback.c +2 -2
-	max_credit = vif->remaining_credit + vif->credit_bytes;
-	if (max_credit < vif->remaining_credit)
+	max_credit = queue->remaining_credit + queue->credit_bytes;
+	if (max_credit < queue->remaining_credit)
  		max_credit = ULONG_MAX; /* wrapped: clamp to

ULONG_MAX */

drivers/net/xen-netback/netback.c +16 -16
-	vif->remaining_credit = min(max_credit, max_burst);
+	queue->remaining_credit = min(max_credit, max_burst);
  }
 
  static void tx_credit_callback(unsigned long data)
  {
-	struct xenvif *vif = (struct xenvif *)data;
-	tx_add_credit(vif);
-	xenvif_check_rx_xenvif(vif);
+	struct xenvif_queue *queue = (struct xenvif_queue *)data;
+	tx_add_credit(queue);
+	xenvif_check_rx_xenvif(queue);
  }
 
-static void xenvif_tx_err(struct xenvif *vif,
+static void xenvif_tx_err(struct xenvif_queue *queue,
  			  struct xen_netif_tx_request *txp, RING_IDX end)
  {
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
 
  	do {
-		make_tx_response(vif, txp, XEN_NETIF_RSP_ERROR);
+		make_tx_response(queue, txp, XEN_NETIF_RSP_ERROR);
  		if (cons == end)
  			break;
-		txp = RING_GET_REQUEST(&vif->tx, cons++);
+		txp = RING_GET_REQUEST(&queue->tx, cons++);
  	} while (1);
-	vif->tx.req_cons = cons;
+	queue->tx.req_cons = cons;
  }
 
  static void xenvif_fatal_tx_err(struct xenvif *vif)
@@ -759,12 +757,12 @@ static void xenvif_fatal_tx_err(struct xenvif *vif)
  	xenvif_carrier_off(vif);
  }
 
-static int xenvif_count_requests(struct xenvif *vif,
+static int xenvif_count_requests(struct xenvif_queue *queue,
  				 struct xen_netif_tx_request *first,
  				 struct xen_netif_tx_request *txp,
  				 int work_to_do)
  {
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
  	int slots = 0;
  	int drop_err = 0;
  	int more_data;
@@ -776,10 +774,10 @@ static int xenvif_count_requests(struct xenvif *vif,
  		struct xen_netif_tx_request dropped_tx = { 0 };
 
  		if (slots >= work_to_do) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
  				   "Asked for %d slots but exceeds this
 limit\n",
  				   work_to_do);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			return -ENODATA;
  		}
@@ -787,10 +785,10 @@ static int xenvif_count_requests(struct xenvif *vif,
  		 * considered malicious.
  		 */
  		if (unlikely(slots >= fatal_skb_slots)) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
  				   "Malicious frontend using %d slots,
 threshold %u\n",
  				   slots, fatal_skb_slots);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			return -E2BIG;
  		}
@@ -803,7 +801,7 @@ static int xenvif_count_requests(struct xenvif *vif,
  		 */
  		if (!drop_err && slots >= XEN_NETBK_LEGACY_SLOTS_MAX)
 {
  			if (net_ratelimit())
-				netdev_dbg(vif->dev,
+				netdev_dbg(queue->vif->dev,
  					   "Too many slots (%d) exceeding
 limit (%d), dropping packet\n",

slots,
XEN_NETBK_LEGACY_SLOTS_MAX);
drop_err = -E2BIG;

drivers/net/xen-netback/netback.c +1 -1
@@ -812,7 +810,7 @@ static int xenvif_count_requests(struct xenvif *vif,
  		if (drop_err)
  			txp = &dropped_tx;
 
-		memcpy(txp, RING_GET_REQUEST(&vif->tx, cons + slots),
+		memcpy(txp, RING_GET_REQUEST(&queue->tx, cons +
 slots),
  		       sizeof(*txp));
 

/* If the guest submitted a frame >= 64 KiB then

drivers/net/xen-netback/netback.c +1 -1
@@ -826,7 +824,7 @@ static int xenvif_count_requests(struct xenvif *vif,
  		 */
  		if (!drop_err && txp->size > first->size) {
  			if (net_ratelimit())
-				netdev_dbg(vif->dev,
+				netdev_dbg(queue->vif->dev,
  					   "Invalid tx request, slot size %u >
 remaining size %u\n",
  					   txp->size, first->size);
  			drop_err = -EIO;
drivers/net/xen-netback/netback.c +2 -2
@@ -836,9 +834,9 @@ static int xenvif_count_requests(struct xenvif *vif,
  		slots++;
 
  		if (unlikely((txp->offset + txp->size) > PAGE_SIZE)) {
-			netdev_err(vif->dev, "Cross page boundary, txp-
 > offset: %x, size: %u\n",
+			netdev_err(queue->vif->dev, "Cross page boundary,
 txp->offset: %x, size: %u\n",
  				 txp->offset, txp->size);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			return -EINVAL;
  		}
drivers/net/xen-netback/netback.c +4 -4
@@ -850,14 +848,14 @@ static int xenvif_count_requests(struct xenvif *vif,
  	} while (more_data);
 
  	if (drop_err) {
-		xenvif_tx_err(vif, first, cons + slots);
+		xenvif_tx_err(queue, first, cons + slots);
  		return drop_err;
  	}
 
  	return slots;
  }
 
-static struct page *xenvif_alloc_page(struct xenvif *vif,
+static struct page *xenvif_alloc_page(struct xenvif_queue *queue,
  				      u16 pending_idx)
  {
  	struct page *page;
@@ -865,12 +863,12 @@ static struct page *xenvif_alloc_page(struct xenvif
 *vif,
  	page = alloc_page(GFP_ATOMIC|__GFP_COLD);
  	if (!page)
  		return NULL;
-	vif->mmap_pages[pending_idx] = page;
+	queue->mmap_pages[pending_idx] = page;
 
  	return page;
  }
 
-static struct gnttab_copy *xenvif_get_requests(struct xenvif *vif,
+static struct gnttab_copy *xenvif_get_requests(struct xenvif_queue
 *queue,
  					       struct sk_buff *skb,

struct xen_netif_tx_request *txp, struct gnttab_copy *gop)

drivers/net/xen-netback/netback.c +1 -1
@@ -901,7 +899,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
  	for (shinfo->nr_frags = slot = start; slot < nr_slots;
  	     shinfo->nr_frags++) {
  		struct pending_tx_info *pending_tx_info =
-			vif->pending_tx_info;
+			queue->pending_tx_info;
 
  		page = alloc_page(GFP_ATOMIC|__GFP_COLD);

if (!page)

drivers/net/xen-netback/netback.c +1 -1
@@ -913,7 +911,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
  			gop->flags = GNTCOPY_source_gref;
 
  			gop->source.u.ref = txp->gref;
-			gop->source.domid = vif->domid;
+			gop->source.domid = queue->vif->domid;
  			gop->source.offset = txp->offset;
 
  			gop->dest.domid = DOMID_SELF;
drivers/net/xen-netback/netback.c +2 -2
@@ -938,9 +936,9 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
  				gop->len = txp->size;
  				dst_offset += gop->len;
 
-				index = pending_index(vif-
 > pending_cons++);
+				index = pending_index(queue-
 > pending_cons++);
 
-				pending_idx = vif->pending_ring[index];
+				pending_idx = queue->pending_ring[index];

memcpy(&pending_tx_info[pending_idx].req, txp,
sizeof(*txp));

drivers/net/xen-netback/netback.c +1 -1
@@ -949,7 +947,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
  				 * fields for head tx req will be set
  				 * to correct values after the loop.
  				 */
-				vif->mmap_pages[pending_idx] = (void
 *)(~0UL);
+				queue->mmap_pages[pending_idx] = (void
 *)(~0UL);

pending_tx_info[pending_idx].head =
INVALID_PENDING_RING_IDX;

drivers/net/xen-netback/netback.c +5 -5
@@ -969,7 +967,7 @@ static struct gnttab_copy *xenvif_get_requests(struct
 xenvif *vif,
  		first->req.offset = 0;
  		first->req.size = dst_offset;
  		first->head = start_idx;
-		vif->mmap_pages[head_idx] = page;
+		queue->mmap_pages[head_idx] = page;
  		frag_set_pending_idx(&frags[shinfo->nr_frags], head_idx);
  	}
@@ -979,18 +977,18 @@ static struct gnttab_copy
 *xenvif_get_requests(struct xenvif *vif,
  err:
  	/* Unwind, freeing all pages and sending error responses. */
  	while (shinfo->nr_frags-- > start) {
-		xenvif_idx_release(vif,
+		xenvif_idx_release(queue,
  				frag_get_pending_idx(&frags[shinfo-
 > nr_frags]),
  				XEN_NETIF_RSP_ERROR);
  	}
  	/* The head too, if necessary. */
  	if (start)
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);
 
  	return NULL;
  }
 
-static int xenvif_tx_check_gop(struct xenvif *vif,
+static int xenvif_tx_check_gop(struct xenvif_queue *queue,
  			       struct sk_buff *skb,
  			       struct gnttab_copy **gopp)
  {
@@ -1005,7 +1003,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
  	/* Check status of header. */
  	err = gop->status;
  	if (unlikely(err))
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);
 

/* Skip first skb fragment if it is on same page as header fragment. */ start = (frag_get_pending_idx(&shinfo->frags[0]) == pending_idx);

drivers/net/xen-netback/netback.c +1 -1
@@ -1015,7 +1013,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
  		pending_ring_idx_t head;
 
  		pending_idx = frag_get_pending_idx(&shinfo->frags[i]);
-		tx_info = &vif->pending_tx_info[pending_idx];
+		tx_info = &queue->pending_tx_info[pending_idx];
  		head = tx_info->head;
 
  		/* Check error status: if okay then remember grant handle.

*/

drivers/net/xen-netback/netback.c +4 -4
@@ -1023,19 +1021,19 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
  			newerr = (++gop)->status;
  			if (newerr)
  				break;
-			peek = vif->pending_ring[pending_index(++head)];
-		} while (!pending_tx_is_head(vif, peek));
+			peek = queue-
 > pending_ring[pending_index(++head)];
+		} while (!pending_tx_is_head(queue, peek));
 
  		if (likely(!newerr)) {
  			/* Had a previous error? Invalidate this fragment. */
  			if (unlikely(err))
-				xenvif_idx_release(vif, pending_idx,
+				xenvif_idx_release(queue, pending_idx,
  						   XEN_NETIF_RSP_OKAY);
  			continue;
  		}
 
  		/* Error on this fragment: respond to client with an error. */
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_ERROR);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_ERROR);

/* Not the first error? Preceding frags already invalidated. */ if (err)

drivers/net/xen-netback/netback.c +2 -2
@@ -1043,10 +1041,10 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
 
  		/* First error: invalidate header and preceding fragments. */
  		pending_idx = *((u16 *)skb->data);
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_OKAY);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_OKAY);
  		for (j = start; j < i; j++) {
  			pending_idx = frag_get_pending_idx(&shinfo-
 > frags[j]);
-			xenvif_idx_release(vif, pending_idx,
+			xenvif_idx_release(queue, pending_idx,
  					   XEN_NETIF_RSP_OKAY);
  		}
drivers/net/xen-netback/netback.c +1 -1
@@ -1058,7 +1056,7 @@ static int xenvif_tx_check_gop(struct xenvif *vif,
  	return err;
  }
 
-static void xenvif_fill_frags(struct xenvif *vif, struct sk_buff *skb)
+static void xenvif_fill_frags(struct xenvif_queue *queue, struct sk_buff
 *skb)
  {
  	struct skb_shared_info *shinfo = skb_shinfo(skb);
  	int nr_frags = shinfo->nr_frags;
drivers/net/xen-netback/netback.c +25 -25
@@ -1072,46 +1070,46 @@ static void xenvif_fill_frags(struct xenvif *vif,
 struct sk_buff *skb)
 
  		pending_idx = frag_get_pending_idx(frag);
 
-		txp = &vif->pending_tx_info[pending_idx].req;
-		page = virt_to_page(idx_to_kaddr(vif, pending_idx));
+		txp = &queue->pending_tx_info[pending_idx].req;
+		page = virt_to_page(idx_to_kaddr(queue, pending_idx));
  		__skb_fill_page_desc(skb, i, page, txp->offset, txp->size);
  		skb->len += txp->size;
  		skb->data_len += txp->size;
  		skb->truesize += txp->size;
 
  		/* Take an extra reference to offset xenvif_idx_release */
-		get_page(vif->mmap_pages[pending_idx]);
-		xenvif_idx_release(vif, pending_idx,
 XEN_NETIF_RSP_OKAY);
+		get_page(queue->mmap_pages[pending_idx]);
+		xenvif_idx_release(queue, pending_idx,
 XEN_NETIF_RSP_OKAY);
  	}
  }
 
-static int xenvif_get_extras(struct xenvif *vif,
+static int xenvif_get_extras(struct xenvif_queue *queue,
  				struct xen_netif_extra_info *extras,
  				int work_to_do)
  {
  	struct xen_netif_extra_info extra;
-	RING_IDX cons = vif->tx.req_cons;
+	RING_IDX cons = queue->tx.req_cons;
 
  	do {
  		if (unlikely(work_to_do-- <= 0)) {
-			netdev_err(vif->dev, "Missing extra info\n");
-			xenvif_fatal_tx_err(vif);
+			netdev_err(queue->vif->dev, "Missing extra
 info\n");
+			xenvif_fatal_tx_err(queue->vif);
  			return -EBADR;
  		}
 
-		memcpy(&extra, RING_GET_REQUEST(&vif->tx, cons),
+		memcpy(&extra, RING_GET_REQUEST(&queue->tx, cons),
  		       sizeof(extra));
  		if (unlikely(!extra.type ||
  			     extra.type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
-			vif->tx.req_cons = ++cons;
-			netdev_err(vif->dev,
+			queue->tx.req_cons = ++cons;
+			netdev_err(queue->vif->dev,
  				   "Invalid extra type: %d\n", extra.type);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			return -EINVAL;
  		}
 
  		memcpy(&extras[extra.type - 1], &extra, sizeof(extra));
-		vif->tx.req_cons = ++cons;
+		queue->tx.req_cons = ++cons;
  	} while (extra.flags & XEN_NETIF_EXTRA_FLAG_MORE);
 
  	return work_to_do;
@@ -1424,31 +1422,31 @@ static int checksum_setup(struct xenvif *vif,
 struct sk_buff *skb)
  	return err;
  }
 
-static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
+static bool tx_credit_exceeded(struct xenvif_queue *queue, unsigned
 size)
  {
  	u64 now = get_jiffies_64();
-	u64 next_credit = vif->credit_window_start +
-		msecs_to_jiffies(vif->credit_usec / 1000);
+	u64 next_credit = queue->credit_window_start +
+		msecs_to_jiffies(queue->credit_usec / 1000);
 
  	/* Timer could already be pending in rare cases. */
-	if (timer_pending(&vif->credit_timeout))
+	if (timer_pending(&queue->credit_timeout))
  		return true;
 
  	/* Passed the point where we can replenish credit? */
  	if (time_after_eq64(now, next_credit)) {
-		vif->credit_window_start = now;
-		tx_add_credit(vif);
+		queue->credit_window_start = now;
+		tx_add_credit(queue);
  	}
 
  	/* Still too big to send right now? Set a callback. */
-	if (size > vif->remaining_credit) {
-		vif->credit_timeout.data     =
-			(unsigned long)vif;
-		vif->credit_timeout.function =
+	if (size > queue->remaining_credit) {
+		queue->credit_timeout.data     =
+			(unsigned long)queue;
+		queue->credit_timeout.function =
  			tx_credit_callback;
-		mod_timer(&vif->credit_timeout,
+		mod_timer(&queue->credit_timeout,
  			  next_credit);
-		vif->credit_window_start = next_credit;
+		queue->credit_window_start = next_credit;
 
  		return true;
  	}
drivers/net/xen-netback/netback.c +3 -3
@@ -1456,15 +1454,15 @@ static bool tx_credit_exceeded(struct xenvif *vif,
 unsigned size)
  	return false;
  }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
+static unsigned xenvif_tx_build_gops(struct xenvif_queue *queue, int
 budget)
  {
-	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
+	struct gnttab_copy *gop = queue->tx_copy_ops, *request_gop;
  	struct sk_buff *skb;
  	int ret;
 
-	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
+	while ((nr_pending_reqs(queue) +

XEN_NETBK_LEGACY_SLOTS_MAX
< MAX_PENDING_REQS) &&

drivers/net/xen-netback/netback.c +1 -1
-	       (skb_queue_len(&vif->tx_queue) < budget)) {
+	       (skb_queue_len(&queue->tx_queue) < budget)) {
  		struct xen_netif_tx_request txreq;
  		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];
struct page *page;

drivers/net/xen-netback/netback.c +23 -23
@@ -1475,69 +1473,69 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
  		unsigned int data_len;
  		pending_ring_idx_t index;
 
-		if (vif->tx.sring->req_prod - vif->tx.req_cons >
+		if (queue->tx.sring->req_prod - queue->tx.req_cons >
  		    XEN_NETIF_TX_RING_SIZE) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
  				   "Impossible number of requests. "
  				   "req_prod %d, req_cons %d, size %ld\n",
-				   vif->tx.sring->req_prod, vif->tx.req_cons,
+				   queue->tx.sring->req_prod, queue-
 > tx.req_cons,
  				   XEN_NETIF_TX_RING_SIZE);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			continue;
  		}
 
-		work_to_do = RING_HAS_UNCONSUMED_REQUESTS(&vif-
 > tx);
+		work_to_do =
 RING_HAS_UNCONSUMED_REQUESTS(&queue->tx);
  		if (!work_to_do)
  			break;
 
-		idx = vif->tx.req_cons;
+		idx = queue->tx.req_cons;
  		rmb(); /* Ensure that we see the request before we copy it.
 */
-		memcpy(&txreq, RING_GET_REQUEST(&vif->tx, idx),
 sizeof(txreq));
+		memcpy(&txreq, RING_GET_REQUEST(&queue->tx, idx),
 sizeof(txreq));
 
  		/* Credit-based scheduling. */
-		if (txreq.size > vif->remaining_credit &&
-		    tx_credit_exceeded(vif, txreq.size))
+		if (txreq.size > queue->remaining_credit &&
+		    tx_credit_exceeded(queue, txreq.size))
  			break;
 
-		vif->remaining_credit -= txreq.size;
+		queue->remaining_credit -= txreq.size;
 
  		work_to_do--;
-		vif->tx.req_cons = ++idx;
+		queue->tx.req_cons = ++idx;
 
  		memset(extras, 0, sizeof(extras));
  		if (txreq.flags & XEN_NETTXF_extra_info) {
-			work_to_do = xenvif_get_extras(vif, extras,
+			work_to_do = xenvif_get_extras(queue, extras,
  						       work_to_do);
-			idx = vif->tx.req_cons;
+			idx = queue->tx.req_cons;
  			if (unlikely(work_to_do < 0))
  				break;
  		}
 
-		ret = xenvif_count_requests(vif, &txreq, txfrags,
 work_to_do);
+		ret = xenvif_count_requests(queue, &txreq, txfrags,
 work_to_do);
  		if (unlikely(ret < 0))
  			break;
 
  		idx += ret;
 
  		if (unlikely(txreq.size < ETH_HLEN)) {
-			netdev_dbg(vif->dev,
+			netdev_dbg(queue->vif->dev,
  				   "Bad packet size: %d\n", txreq.size);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
  			break;
  		}
 
  		/* No crossing a page as the payload mustn't fragment. */
  		if (unlikely((txreq.offset + txreq.size) > PAGE_SIZE)) {
-			netdev_err(vif->dev,
+			netdev_err(queue->vif->dev,
  				   "txreq.offset: %x, size: %u, end: %lu\n",
  				   txreq.offset, txreq.size,
  				   (txreq.offset&~PAGE_MASK) + txreq.size);
-			xenvif_fatal_tx_err(vif);
+			xenvif_fatal_tx_err(queue->vif);
  			break;
  		}
 
-		index = pending_index(vif->pending_cons);
-		pending_idx = vif->pending_ring[index];
+		index = pending_index(queue->pending_cons);
+		pending_idx = queue->pending_ring[index];
 
  		data_len = (txreq.size > PKT_PROT_LEN &&
  			    ret < XEN_NETBK_LEGACY_SLOTS_MAX) ?
@@ -1546,9 +1544,9 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
  		skb = alloc_skb(data_len + NET_SKB_PAD + NET_IP_ALIGN,
  				GFP_ATOMIC | __GFP_NOWARN);
  		if (unlikely(skb == NULL)) {
-			netdev_dbg(vif->dev,
+			netdev_dbg(queue->vif->dev,
  				   "Can't allocate a skb in start_xmit.\n");
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
  			break;
  		}
@@ -1559,7 +1557,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
  			struct xen_netif_extra_info *gso;
  			gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
 
-			if (xenvif_set_skb_gso(vif, skb, gso)) {
+			if (xenvif_set_skb_gso(queue->vif, skb, gso)) {
  				/* Failure in xenvif_set_skb_gso is fatal. */
  				kfree_skb(skb);

break;

drivers/net/xen-netback/netback.c +3 -3
@@ -1567,15 +1565,15 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
  		}
 
  		/* XXX could copy straight to head */
-		page = xenvif_alloc_page(vif, pending_idx);
+		page = xenvif_alloc_page(queue, pending_idx);
  		if (!page) {
  			kfree_skb(skb);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
  			break;
  		}
 
  		gop->source.u.ref = txreq.gref;
-		gop->source.domid = vif->domid;
+		gop->source.domid = queue->vif->domid;
  		gop->source.offset = txreq.offset;
 
  		gop->dest.u.gmfn = virt_to_mfn(page_address(page));
drivers/net/xen-netback/netback.c +2 -2
@@ -1587,9 +1585,9 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif, int budget)
 
  		gop++;
 
-		memcpy(&vif->pending_tx_info[pending_idx].req,
+		memcpy(&queue->pending_tx_info[pending_idx].req,
  		       &txreq, sizeof(txreq));
-		vif->pending_tx_info[pending_idx].head = index;
+		queue->pending_tx_info[pending_idx].head = index;
  		*((u16 *)skb->data) = pending_idx;
 
  		__skb_put(skb, data_len);
drivers/net/xen-netback/netback.c +13 -13
@@ -1604,45 +1602,45 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif, int budget)
  					     INVALID_PENDING_IDX);
  		}
 
-		vif->pending_cons++;
+		queue->pending_cons++;
 
-		request_gop = xenvif_get_requests(vif, skb, txfrags, gop);
+		request_gop = xenvif_get_requests(queue, skb, txfrags,
 gop);
  		if (request_gop == NULL) {
  			kfree_skb(skb);
-			xenvif_tx_err(vif, &txreq, idx);
+			xenvif_tx_err(queue, &txreq, idx);
  			break;
  		}
  		gop = request_gop;
 
-		__skb_queue_tail(&vif->tx_queue, skb);
+		__skb_queue_tail(&queue->tx_queue, skb);
 
-		vif->tx.req_cons = idx;
+		queue->tx.req_cons = idx;
 
-		if ((gop-vif->tx_copy_ops) >= ARRAY_SIZE(vif-
 > tx_copy_ops))
+		if ((gop - queue->tx_copy_ops) >= ARRAY_SIZE(queue-
 > tx_copy_ops))
  			break;
  	}
 
-	return gop - vif->tx_copy_ops;
+	return gop - queue->tx_copy_ops;
  }
 
 
-static int xenvif_tx_submit(struct xenvif *vif)
+static int xenvif_tx_submit(struct xenvif_queue *queue)
  {
-	struct gnttab_copy *gop = vif->tx_copy_ops;
+	struct gnttab_copy *gop = queue->tx_copy_ops;
  	struct sk_buff *skb;
  	int work_done = 0;
 
-	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&queue->tx_queue)) != NULL) {
  		struct xen_netif_tx_request *txp;
  		u16 pending_idx;
  		unsigned data_len;
 
  		pending_idx = *((u16 *)skb->data);
-		txp = &vif->pending_tx_info[pending_idx].req;
+		txp = &queue->pending_tx_info[pending_idx].req;
 
  		/* Check the remap error code. */
-		if (unlikely(xenvif_tx_check_gop(vif, skb, &gop))) {
-			netdev_dbg(vif->dev, "netback grant failed.\n");
+		if (unlikely(xenvif_tx_check_gop(queue, skb, &gop))) {
+			netdev_dbg(queue->vif->dev, "netback grant

failed.\n");
skb_shinfo(skb)->nr_frags = 0; kfree_skb(skb); continue;

drivers/net/xen-netback/netback.c +6 -6
@@ -1650,7 +1648,7 @@ static int xenvif_tx_submit(struct xenvif *vif)
 
  		data_len = skb->len;
  		memcpy(skb->data,
-		       (void *)(idx_to_kaddr(vif, pending_idx)|txp->offset),
+		       (void *)(idx_to_kaddr(queue, pending_idx)|txp->offset),
  		       data_len);
  		if (data_len < txp->size) {
  			/* Append the packet payload as a fragment. */
@@ -1658,7 +1656,7 @@ static int xenvif_tx_submit(struct xenvif *vif)
  			txp->size -= data_len;
  		} else {
  			/* Schedule a response immediately. */
-			xenvif_idx_release(vif, pending_idx,
+			xenvif_idx_release(queue, pending_idx,
  					   XEN_NETIF_RSP_OKAY);
  		}
 
@@ -1667,19 +1665,19 @@ static int xenvif_tx_submit(struct xenvif *vif)
  		else if (txp->flags & XEN_NETTXF_data_validated)
  			skb->ip_summed = CHECKSUM_UNNECESSARY;
 
-		xenvif_fill_frags(vif, skb);
+		xenvif_fill_frags(queue, skb);
 
  		if (skb_is_nonlinear(skb) && skb_headlen(skb) <
 PKT_PROT_LEN) {
  			int target = min_t(int, skb->len, PKT_PROT_LEN);
  			__pskb_pull_tail(skb, target - skb_headlen(skb));
  		}
 
-		skb->dev      = vif->dev;
+		skb->dev      = queue->vif->dev;
  		skb->protocol = eth_type_trans(skb, skb->dev);
  		skb_reset_network_header(skb);
 
-		if (checksum_setup(vif, skb)) {
-			netdev_dbg(vif->dev,
+		if (checksum_setup(queue->vif, skb)) {
+			netdev_dbg(queue->vif->dev,
  				   "Can't setup checksum in
 net_tx_action\n");
  			kfree_skb(skb);
  			continue;
drivers/net/xen-netback/netback.c +16 -16
@@ -1687,8 +1685,8 @@ static int xenvif_tx_submit(struct xenvif *vif)
 
  		skb_probe_transport_header(skb, 0);
 
-		vif->dev->stats.rx_bytes += skb->len;
-		vif->dev->stats.rx_packets++;
+		queue->vif->dev->stats.rx_bytes += skb->len;
+		queue->vif->dev->stats.rx_packets++;
 
 
  		work_done++;
@@ -1699,53 +1697,53 @@ static int xenvif_tx_submit(struct xenvif *vif)
  }
 
  /* Called after netfront has transmitted */
-int xenvif_tx_action(struct xenvif *vif, int budget)
+int xenvif_tx_action(struct xenvif_queue *queue, int budget)
  {
  	unsigned nr_gops;
  	int work_done;
 
-	if (unlikely(!tx_work_todo(vif)))
+	if (unlikely(!tx_work_todo(queue)))
  		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif, budget);
+	nr_gops = xenvif_tx_build_gops(queue, budget);
 
  	if (nr_gops == 0)
  		return 0;
 
-	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
+	gnttab_batch_copy(queue->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif);
+	work_done = xenvif_tx_submit(queue);
 
  	return work_done;
  }
 
-static void xenvif_idx_release(struct xenvif *vif, u16 pending_idx,
+static void xenvif_idx_release(struct xenvif_queue *queue, u16
 pending_idx,
  			       u8 status)
  {
  	struct pending_tx_info *pending_tx_info;
  	pending_ring_idx_t head;
  	u16 peek; /* peek into next tx request */
 
-	BUG_ON(vif->mmap_pages[pending_idx] == (void *)(~0UL));
+	BUG_ON(queue->mmap_pages[pending_idx] == (void *)(~0UL));
 
  	/* Already complete? */
-	if (vif->mmap_pages[pending_idx] == NULL)
+	if (queue->mmap_pages[pending_idx] == NULL)
  		return;
 
-	pending_tx_info = &vif->pending_tx_info[pending_idx];
+	pending_tx_info = &queue->pending_tx_info[pending_idx];
 
  	head = pending_tx_info->head;
 
-	BUG_ON(!pending_tx_is_head(vif, head));
-	BUG_ON(vif->pending_ring[pending_index(head)] != pending_idx);
+	BUG_ON(!pending_tx_is_head(queue, head));
+	BUG_ON(queue->pending_ring[pending_index(head)] !=
 pending_idx);
 
  	do {
  		pending_ring_idx_t index;
  		pending_ring_idx_t idx = pending_index(head);
-		u16 info_idx = vif->pending_ring[idx];
+		u16 info_idx = queue->pending_ring[idx];
 
-		pending_tx_info = &vif->pending_tx_info[info_idx];
-		make_tx_response(vif, &pending_tx_info->req, status);
+		pending_tx_info = &queue->pending_tx_info[info_idx];
+		make_tx_response(queue, &pending_tx_info->req, status);
 

/* Setting any number other than
* INVALID_PENDING_RING_IDX indicates this slot is

drivers/net/xen-netback/netback.c +30 -30
@@ -1753,50 +1751,50 @@ static void xenvif_idx_release(struct xenvif *vif,
 u16 pending_idx,
  		 */
  		pending_tx_info->head = 0;
 
-		index = pending_index(vif->pending_prod++);
-		vif->pending_ring[index] = vif->pending_ring[info_idx];
+		index = pending_index(queue->pending_prod++);
+		queue->pending_ring[index] = queue-
 > pending_ring[info_idx];
 
-		peek = vif->pending_ring[pending_index(++head)];
+		peek = queue->pending_ring[pending_index(++head)];
 
-	} while (!pending_tx_is_head(vif, peek));
+	} while (!pending_tx_is_head(queue, peek));
 
-	put_page(vif->mmap_pages[pending_idx]);
-	vif->mmap_pages[pending_idx] = NULL;
+	put_page(queue->mmap_pages[pending_idx]);
+	queue->mmap_pages[pending_idx] = NULL;
  }
 
 
-static void make_tx_response(struct xenvif *vif,
+static void make_tx_response(struct xenvif_queue *queue,
  			     struct xen_netif_tx_request *txp,
  			     s8       st)
  {
-	RING_IDX i = vif->tx.rsp_prod_pvt;
+	RING_IDX i = queue->tx.rsp_prod_pvt;
  	struct xen_netif_tx_response *resp;
  	int notify;
 
-	resp = RING_GET_RESPONSE(&vif->tx, i);
+	resp = RING_GET_RESPONSE(&queue->tx, i);
  	resp->id     = txp->id;
  	resp->status = st;
 
  	if (txp->flags & XEN_NETTXF_extra_info)
-		RING_GET_RESPONSE(&vif->tx, ++i)->status =
 XEN_NETIF_RSP_NULL;
+		RING_GET_RESPONSE(&queue->tx, ++i)->status =
 XEN_NETIF_RSP_NULL;
 
-	vif->tx.rsp_prod_pvt = ++i;
-	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&vif->tx, notify);
+	queue->tx.rsp_prod_pvt = ++i;
+	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&queue->tx, notify);
  	if (notify)
-		notify_remote_via_irq(vif->tx_irq);
+		notify_remote_via_irq(queue->tx_irq);
  }
 
-static struct xen_netif_rx_response *make_rx_response(struct xenvif *vif,
+static struct xen_netif_rx_response *make_rx_response(struct
 xenvif_queue *queue,
  					     u16      id,
  					     s8       st,
  					     u16      offset,
  					     u16      size,
  					     u16      flags)
  {
-	RING_IDX i = vif->rx.rsp_prod_pvt;
+	RING_IDX i = queue->rx.rsp_prod_pvt;
  	struct xen_netif_rx_response *resp;
 
-	resp = RING_GET_RESPONSE(&vif->rx, i);
+	resp = RING_GET_RESPONSE(&queue->rx, i);
  	resp->offset     = offset;
  	resp->flags      = flags;
  	resp->id         = id;
@@ -1804,38 +1802,38 @@ static struct xen_netif_rx_response
 *make_rx_response(struct xenvif *vif,
  	if (st < 0)
  		resp->status = (s16)st;
 
-	vif->rx.rsp_prod_pvt = ++i;
+	queue->rx.rsp_prod_pvt = ++i;
 
  	return resp;
  }
 
-static inline int rx_work_todo(struct xenvif *vif)
+static inline int rx_work_todo(struct xenvif_queue *queue)
  {
-	return !skb_queue_empty(&vif->rx_queue);
+	return !skb_queue_empty(&queue->rx_queue);
  }
 
-static inline int tx_work_todo(struct xenvif *vif)
+static inline int tx_work_todo(struct xenvif_queue *queue)
  {
 
-	if (likely(RING_HAS_UNCONSUMED_REQUESTS(&vif->tx)) &&
-	    (nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
+	if (likely(RING_HAS_UNCONSUMED_REQUESTS(&queue->tx)) &&
+	    (nr_pending_reqs(queue) + XEN_NETBK_LEGACY_SLOTS_MAX
  	     < MAX_PENDING_REQS))
  		return 1;
 
  	return 0;
  }
 
-void xenvif_unmap_frontend_rings(struct xenvif *vif)
+void xenvif_unmap_frontend_rings(struct xenvif_queue *queue)
  {
-	if (vif->tx.sring)
-		xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
-					vif->tx.sring);
-	if (vif->rx.sring)
-		xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
-					vif->rx.sring);
+	if (queue->tx.sring)
+
 	xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif),
+					queue->tx.sring);
+	if (queue->rx.sring)
+
 	xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(queue->vif),
+					queue->rx.sring);
  }
 
-int xenvif_map_frontend_rings(struct xenvif *vif,
+int xenvif_map_frontend_rings(struct xenvif_queue *queue,
  			      grant_ref_t tx_ring_ref,
  			      grant_ref_t rx_ring_ref)
  {
drivers/net/xen-netback/netback.c +11 -11
@@ -1845,44 +1843,44 @@ int xenvif_map_frontend_rings(struct xenvif
 *vif,
 
  	int err = -ENOMEM;
 
-	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
+	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue-
 > vif),
  				     tx_ring_ref, &addr);
  	if (err)
  		goto err;
 
  	txs = (struct xen_netif_tx_sring *)addr;
-	BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
+	BACK_RING_INIT(&queue->tx, txs, PAGE_SIZE);
 
-	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
+	err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(queue-
 > vif),
  				     rx_ring_ref, &addr);
  	if (err)
  		goto err;
 
  	rxs = (struct xen_netif_rx_sring *)addr;
-	BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
+	BACK_RING_INIT(&queue->rx, rxs, PAGE_SIZE);
 
-	vif->rx_req_cons_peek = 0;
+	queue->rx_req_cons_peek = 0;
 
  	return 0;
 
  err:
-	xenvif_unmap_frontend_rings(vif);
+	xenvif_unmap_frontend_rings(queue);
  	return err;
  }
 
  int xenvif_kthread(void *data)
  {
-	struct xenvif *vif = data;
+	struct xenvif_queue *queue = data;
 
  	while (!kthread_should_stop()) {
-		wait_event_interruptible(vif->wq,
-					 rx_work_todo(vif) ||
+		wait_event_interruptible(queue->wq,
+					 rx_work_todo(queue) ||
  					 kthread_should_stop());
  		if (kthread_should_stop())
  			break;
 
-		if (rx_work_todo(vif))
-			xenvif_rx_action(vif);
+		if (rx_work_todo(queue))
+			xenvif_rx_action(queue);
  		cond_resched();
  	}
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c
index f035899..c3332e2 100644

drivers/net/xen-netback/xenbus.c +4 -2
@@ -20,6 +20,7 @@
  */
 
  #include "common.h"
+#include <linux/vmalloc.h>
 
  struct backend_info {
  	struct xenbus_device *dev;
@@ -35,8 +36,9 @@ struct backend_info {
  	u8 have_hotplug_status_watch:1;
  };
 
-static int connect_rings(struct backend_info *);
-static void connect(struct backend_info *);
+static int connect_rings(struct backend_info *be, struct xenvif_queue
 *queue);
+static void connect(struct backend_info *be);
+static int read_xenbus_vif_flags(struct backend_info *be);
  static void backend_create_xenvif(struct backend_info *be);
  static void unregister_hotplug_status_watch(struct backend_info *be);

static void set_backend_state(struct backend_info *be,

drivers/net/xen-netback/xenbus.c +40 -12
@@ -486,10 +488,9 @@ static void connect(struct backend_info *be)
  {
  	int err;
  	struct xenbus_device *dev = be->dev;
-
-	err = connect_rings(be);
-	if (err)
-		return;
+	unsigned long credit_bytes, credit_usec;
+	unsigned int queue_index;
+	struct xenvif_queue *queue;
 
  	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
  	if (err) {
@@ -497,9 +498,31 @@ static void connect(struct backend_info *be)
  		return;
  	}
 
-	xen_net_read_rate(dev, &be->vif->credit_bytes,
-			  &be->vif->credit_usec);
-	be->vif->remaining_credit = be->vif->credit_bytes;
+	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
+	read_xenbus_vif_flags(be);
+
+	be->vif->num_queues = 1;
+	be->vif->queues = vzalloc(be->vif->num_queues *
+			sizeof(struct xenvif_queue));
+
+	for (queue_index = 0; queue_index < be->vif->num_queues;
++queue_index)
+	{
+		queue = &be->vif->queues[queue_index];
+		queue->vif = be->vif;
+		queue->number = queue_index;
+		snprintf(queue->name, sizeof(queue->name), "%s-q%u",
+				be->vif->dev->name, queue->number);
+
+		xenvif_init_queue(queue);
+
+		queue->remaining_credit = credit_bytes;
+
+		err = connect_rings(be, queue);
+		if (err)
+			goto err;
+	}
+
+	xenvif_carrier_on(be->vif);
 
  	unregister_hotplug_status_watch(be);
  	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
@@ -508,18 +531,24 @@ static void connect(struct backend_info *be)
  	if (!err)
  		be->have_hotplug_status_watch = 1;
 
-	netif_wake_queue(be->vif->dev);
+	netif_tx_wake_all_queues(be->vif->dev);
+
+	return;
+
+err:
+	vfree(be->vif->queues);
+	be->vif->queues = NULL;
+	be->vif->num_queues = 0;
+	return;
  }
 
 
-static int connect_rings(struct backend_info *be)
+static int connect_rings(struct backend_info *be, struct xenvif_queue
 *queue)
  {
-	struct xenvif *vif = be->vif;
  	struct xenbus_device *dev = be->dev;
  	unsigned long tx_ring_ref, rx_ring_ref;
-	unsigned int tx_evtchn, rx_evtchn, rx_copy;
+	unsigned int tx_evtchn, rx_evtchn;
  	int err;
-	int val;
 
  	err = xenbus_gather(XBT_NIL, dev->otherend,

"tx-ring-ref", "%lu", &tx_ring_ref,

drivers/net/xen-netback/xenbus.c +21 -0
@@ -547,6 +576,27 @@ static int connect_rings(struct backend_info *be)
  		rx_evtchn = tx_evtchn;
  	}
 
+	/* Map the shared frame, irq etc. */
+	err = xenvif_connect(queue, tx_ring_ref, rx_ring_ref,
+			     tx_evtchn, rx_evtchn);
+	if (err) {
+		xenbus_dev_fatal(dev, err,
+				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
+				 tx_ring_ref, rx_ring_ref,
+				 tx_evtchn, rx_evtchn);
+		return err;
+	}
+
+	return 0;
+}
+
+static int read_xenbus_vif_flags(struct backend_info *be)
+{
+	struct xenvif *vif = be->vif;
+	struct xenbus_device *dev = be->dev;
+	unsigned int rx_copy;
+	int err, val;
+
  	err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy",
 "%u",
  			   &rx_copy);
  	if (err == -ENOENT) {
drivers/net/xen-netback/xenbus.c +0 -12
@@ -622,20 +672,9 @@ static int connect_rings(struct backend_info *be)
  		val = 0;
  	vif->ipv6_csum = !!val;
 
-	/* Map the shared frame, irq etc. */
-	err = xenvif_connect(vif, tx_ring_ref, rx_ring_ref,
-			     tx_evtchn, rx_evtchn);
-	if (err) {
-		xenbus_dev_fatal(dev, err,
-				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
-				 tx_ring_ref, rx_ring_ref,
-				 tx_evtchn, rx_evtchn);
-		return err;
-	}
  	return 0;
  }
 
-
  /* ** Driver Registration ** */
 
 
--

1.7.10.4

#8 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 150 lines

-----Original Message-----
From: Andrew Bennieston [mailto:[email protected]]
Sent: 16 January 2014 10:39
To: Paul Durrant; [email protected]
Cc: Ian Campbell; Wei Liu
Subject: Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 23 lines · Paul Durrant
Quoted 23 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston
Subject: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netback, move the queue-specific data from struct xenvif into struct xenvif_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_netdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0 for a single queue and uses skb_get_rxhash() to compute the queue index otherwise.

Quoted 5 lines
Quoted 5 lines
---
  drivers/net/xen-netback/common.h    |   66 +++--
  drivers/net/xen-netback/interface.c |  308 +++++++++++++--------
  drivers/net/xen-netback/netback.c   |  516 +++++++++++++++++---------

----

Quoted 14 lines
Quoted 14 lines

-----

  drivers/net/xen-netback/xenbus.c    |   89 ++++--
  4 files changed, 556 insertions(+), 423 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h
index c47794b..54d2eeb 100644

drivers/net/xen-netback/common.h +0 -0
@@ -108,17 +108,19 @@ struct xenvif_rx_meta {
   */
  #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS *
 XEN_NETIF_RX_RING_SIZE)
 
Quoted 12 lines

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 115

Quoted 9 lines
drivers/net/xen-netback/common.h +5 -4
-struct xenvif {
-	/* Unique identifier for this interface. */
-	domid_t          domid;
-	unsigned int     handle;
+struct xenvif;
+
+struct xenvif_queue { /* Per-queue data for xenvif */
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */

I wonder whether it would be neater to #define the name size here...

Absolutely. I'll do this in V2.

Quoted 11 lines

drivers/net/xen-netback/common.h struct xenvif_rx_meta { · line 123

Quoted 9 lines
drivers/net/xen-netback/common.h +2 -1
+	struct xenvif *vif; /* Parent VIF */
 
  	/* Use NAPI for guest TX */
  	struct napi_struct napi;
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int tx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */

...and the IRQ name size here. It's kind of ugly to have + some_magic_value

in array definitions.

Quoted 1 line

As above.

Quoted 16 lines
Quoted 16 lines
drivers/net/xen-netback/common.h +0 -0
  	struct xen_netif_tx_back_ring tx;
  	struct sk_buff_head tx_queue;
  	struct page *mmap_pages[MAX_PENDING_REQS];
drivers/net/xen-netback/common.h +1 -1
@@ -140,7 +142,7 @@ struct xenvif {
  	/* When feature-split-event-channels = 0, tx_irq = rx_irq. */
  	unsigned int rx_irq;
  	/* Only used when feature-split-event-channels = 1 */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
  	struct xen_netif_rx_back_ring rx;
  	struct sk_buff_head rx_queue;
 
@@ -150,14 +152,27 @@ struct xenvif {
  	 */
  	RING_IDX rx_req_cons_peek;
 
Quoted 5 lines

drivers/net/xen-netback/common.h struct xenvif { · line 155

Quoted 3 lines
drivers/net/xen-netback/common.h +1 -2
-	/* This array is allocated seperately as it is large */
-	struct gnttab_copy *grant_copy_op;
+	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];

I see you brought this back in line, which is reasonable as the queue is now

a separately allocated struct.

Quoted 1 line

Indeed; trying to keep the number of separate allocs/frees to a minimum, for everybody's sanity!

Quoted 37 lines
Quoted 37 lines
drivers/net/xen-netback/common.h +17 -6
  	/* We create one meta structure per ring request we consume, so
  	 * the maximum number is the same as the ring size.
  	 */
  	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
 
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
+	unsigned long   credit_bytes;
+	unsigned long   credit_usec;
+	unsigned long   remaining_credit;
+	struct timer_list credit_timeout;
+	u64 credit_window_start;
+
+};
+
+struct xenvif {
+	/* Unique identifier for this interface. */
+	domid_t          domid;
+	unsigned int     handle;
+
  	u8               fe_dev_addr[6];
 
  	/* Frontend feature information. */
@@ -171,12 +186,9 @@ struct xenvif {
  	/* Internal feature information. */
  	u8 can_queue:1;	    /* can queue packets for receiver? */
 
-	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
-	unsigned long   credit_bytes;
-	unsigned long   credit_usec;
-	unsigned long   remaining_credit;
-	struct timer_list credit_timeout;
-	u64 credit_window_start;
+	/* Queues */
+	unsigned int num_queues;
+	struct xenvif_queue *queues;
 
Quoted 3 lines

drivers/net/xen-netback/common.h struct xenvif { · line 193

Quoted 1 line
drivers/net/xen-netback/common.h +0 -0
  	/* Statistics */

Do stats need to be per-queue (and then possibly aggregated at query

Quoted 7 lines

time)?

Quoted 1 line

Aside from the potential to see the stats for each queue, which may be useful in some limited circumstances for performance testing or debugging, I don't see what this buys us...

Well, if you have multiple queues running simultaneously, do you make sure global stats are atomically adjusted? I didn't see any code to that effect, and since atomic ops are expensive it's usually better to keep per queue stats and aggregate at the point of query.

Paul

#9 lore raw

Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Subject:   Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data
into queue struct.  To:        Paul Durrant

<[email protected]>,"[email protected]"
<[email protected]> Cc: Ian Campbell
<[email protected]>,Wei Liu <[email protected]> Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=- On

Quoted 129 lines · Paul Durrant
Quoted 121 lines

-----Original Message----- From: Andrew Bennieston [mailto:[email protected]] Sent: 16 January 2014 10:39 To:
Paul Durrant; [email protected] Cc: Ian Campbell; Wei Liu Subject: Re: [PATCH RFC 1/4] xen-netback: Factor queue-specific data into queue struct.

Quoted 21 lines · Paul Durrant
Quoted 21 lines

-----Original Message----- From: Andrew J. Bennieston [mailto:[email protected]] Sent: 15 January 2014 16:23
To: [email protected] Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston Subject: [PATCH RFC 1/4] xen-netback:
Factor queue-specific data into queue struct.

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netback, move the queue-specific data from struct xenvif into struct xenvif_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_netdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0 for a single queue and uses skb_get_rxhash() to compute the queue index otherwise.

Quoted 5 lines
Quoted 5 lines

--- drivers/net/xen-netback/common.h | 66 +++--

drivers/net/xen-netback/interface.c |  308 +++++++++++++--------
drivers/net/xen-netback/netback.c   |  516

+++++++++++++++++---------

----

Quoted 10 lines
Quoted 10 lines

----- drivers/net/xen-netback/xenbus.c | 89 ++++-- 4 files
changed, 556 insertions(+), 423 deletions(-)

drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h index c47794b..54d2eeb 100644 --- a/drivers/net/xen-netback/common.h +++ b/drivers/net/xen-netback/common.h @@ -108,17 +108,19 @@ struct xenvif_rx_meta { */ #define MAX_GRANT_COPY_OPS (MAX_SKB_FRAGS * XEN_NETIF_RX_RING_SIZE)

Quoted 8 lines
Quoted 5 lines

-struct xenvif { - /* Unique identifier for this interface. */ -
domid_t domid; - unsigned int handle; +struct xenvif;
+ +struct xenvif_queue { /* Per-queue data for xenvif */ + unsigned
int number; /* Queue number, 0-based */ + char name[IFNAMSIZ+4];
/* DEVNAME-qN */

I wonder whether it would be neater to #define the name size here...

Absolutely. I'll do this in V2.

Quoted 11 lines

drivers/net/xen-

Quoted 8 lines
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +1 -0
+	struct xenvif *vif; /* Parent VIF */
 
   	/* Use NAPI for guest TX */ struct napi_struct napi; /* When
   	feature-split-event-channels = 0, tx_irq = rx_irq. */
   	unsigned int tx_irq; /* Only used when
   	feature-split-event-channels = 1 */ -	char
   	tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */ +	char
   	tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */

...and the IRQ name size here. It's kind of ugly to have + some_magic_value

in array definitions.

Quoted 1 line

As above.

Quoted 10 lines
Quoted 10 lines

struct xen_netif_tx_back_ring tx; struct sk_buff_head tx_queue; struct page *mmap_pages[MAX_PENDING_REQS]; @@ -140,7 +142,7 @@ struct xenvif { /* When feature-split-event-channels = 0, tx_irq = rx_irq. */ unsigned int rx_irq; /* Only used when
feature-split-event-channels = 1 */ - char
rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */ + char
rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */ struct xen_netif_rx_back_ring rx; struct sk_buff_head rx_queue;

Quoted 8 lines
Quoted 5 lines
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -1
@@ -150,14 +152,27 @@ struct xenvif { */ RING_IDX rx_req_cons_peek;
 
-	/* This array is allocated seperately as it is large */ -

struct gnttab_copy *grant_copy_op; + struct gnttab_copy
grant_copy_op[MAX_GRANT_COPY_OPS];

I see you brought this back in line, which is reasonable as the queue is now

a separately allocated struct.

Quoted 1 line

Indeed; trying to keep the number of separate allocs/frees to a minimum, for everybody's sanity!

Quoted 23 lines
Quoted 23 lines
   	/* We create one meta structure per ring request we consume,
   	so * the maximum number is the same as the ring size.  */
   	struct xenvif_rx_meta meta[XEN_NETIF_RX_RING_SIZE];
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +1 -0
+	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'.

*/ + unsigned long credit_bytes; + unsigned long credit_usec;

drivers/net/xen- renamed from drivers/net/xen-netback/common.h +1 -0
+	unsigned long   remaining_credit; +	struct timer_list

credit_timeout; + u64 credit_window_start; + +}; + +struct xenvif
{ + /* Unique identifier for this interface. */ + domid_t
domid; + unsigned int handle; + u8
fe_dev_addr[6];

/* Frontend feature information. */ @@ -171,12 +186,9 @@ struct xenvif { /* Internal feature information. */ u8
can_queue:1; /* can queue packets for receiver? */

drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -1
-	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'.

*/ - unsigned long credit_bytes; - unsigned long credit_usec;

drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -1
-	unsigned long   remaining_credit; -	struct timer_list

credit_timeout; - u64 credit_window_start; + /* Queues */ +
unsigned int num_queues; + struct xenvif_queue *queues;

Quoted 3 lines
Quoted 1 line
   	/* Statistics */

Do stats need to be per-queue (and then possibly aggregated at query

Quoted 7 lines

time)?

Quoted 1 line

Aside from the potential to see the stats for each queue, which may be useful in some limited circumstances for performance testing or debugging, I don't see what this buys us...

Quoted 4 lines

Well, if you have multiple queues running simultaneously, do you make sure global stats are atomically adjusted? I didn't see any code to that effect, and since atomic ops are expensive it's usually better to keep per queue stats and aggregate at the point of query.

Good point. I'll do per-queue stats in V2.

Andrew

#10 lore raw

RFC PATCH 2/4 xen-netback: Add support for multiple queues

In reply to Andrew J. Bennieston

From: "Andrew J. Bennieston" <[email protected]>

Builds on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Writes the maximum supported number of queues into XenStore, and reads the values written by the frontend to determine how many queues to use.

Ring references and event channels are read from XenStore on a per-queue basis and rings are connected accordingly.

---
 drivers/net/xen-netback/common.h    |    2 +
 drivers/net/xen-netback/interface.c |    8 +++-
 drivers/net/xen-netback/netback.c   |    3 ++
 drivers/net/xen-netback/xenbus.c    |   70 ++++++++++++++++++++++++++++++-----
 4 files changed, 72 insertions(+), 11 deletions(-)
drivers/net/xen-netback/common.h +2 -0
index 54d2eeb..97efd09 100644
@@ -254,4 +254,6 @@ void xenvif_carrier_on(struct xenvif *vif);
 
 extern bool separate_tx_rx_irq;
 
+extern unsigned int xenvif_max_queues;
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen-netback/interface.c +7 -1
index 0113324..0234ff0 100644
@@ -355,7 +355,13 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	char name[IFNAMSIZ] = {};
 
 	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
+	/*
+	 * Allocate a netdev with the max. supported number of queues.
+	 * When the guest selects the desired number, it will be updated
+	 * via netif_set_real_num_tx_queues().
+	 */
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup,
+			xenvif_max_queues);
 	if (dev == NULL) {
 		pr_warn("Could not allocate netdev for %s\n", name);
 		return ERR_PTR(-ENOMEM);
drivers/net/xen-netback/netback.c +3 -0
index 586e741..5d717d7 100644
@@ -55,6 +55,9 @@
 bool separate_tx_rx_irq = 1;
 module_param(separate_tx_rx_irq, bool, 0644);
 
+unsigned int xenvif_max_queues = 4;
+module_param(xenvif_max_queues, uint, 0644);
+
 /*
  * This is the maximum slots a skb can have. If a guest sends a skb
  * which exceeds this limit it is considered malicious.
drivers/net/xen-netback/xenbus.c +60 -10

126 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#11 lore raw

Re: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

On Wed, Jan 15, 2014 at 04:23:22PM +0000, Andrew J. Bennieston wrote:
[...]

Quoted 4 lines
drivers/net/xen-netback/interface.c +0 -0
@@ -355,7 +355,13 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	char name[IFNAMSIZ] = {};

drivers/net/xen-netback/interface.c struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 364

Quoted 10 lines
drivers/net/xen-netback/interface.c +7 -1
 
 	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
+	/*
+	 * Allocate a netdev with the max. supported number of queues.
+	 * When the guest selects the desired number, it will be updated
+	 * via netif_set_real_num_tx_queues().
+	 */
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup,
+			xenvif_max_queues);

Indentation.

Quoted 8 lines
drivers/net/xen-netback/interface.c +0 -0
 	if (dev == NULL) {
 		pr_warn("Could not allocate netdev for %s\n", name);
 		return ERR_PTR(-ENOMEM);
drivers/net/xen-netback/netback.c +0 -0
index 586e741..5d717d7 100644

drivers/net/xen-netback/netback.c line 60

Quoted 6 lines
drivers/net/xen-netback/netback.c +3 -0
@@ -55,6 +55,9 @@
 bool separate_tx_rx_irq = 1;
 module_param(separate_tx_rx_irq, bool, 0644);
 
+unsigned int xenvif_max_queues = 4;
+module_param(xenvif_max_queues, uint, 0644);
+

This looks a bit arbitrary. I guess it is better to set the default value to number of CPUs in Dom0?

Quoted 16 lines
drivers/net/xen-netback/netback.c +0 -0
 /*
  * This is the maximum slots a skb can have. If a guest sends a skb
  * which exceeds this limit it is considered malicious.
drivers/net/xen-netback/xenbus.c +1 -0
index c3332e2..ce7ca9a 100644
@@ -21,6 +21,7 @@
 
 #include "common.h"
 #include <linux/vmalloc.h>
+#include <linux/rtnetlink.h>
 
 struct backend_info {
 	struct xenbus_device *dev;

drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 168

Quoted 8 lines
drivers/net/xen-netback/xenbus.c +5 -0
@@ -160,6 +161,14 @@ static int netback_probe(struct xenbus_device *dev,
 	if (err)
 		pr_debug("Error writing feature-split-event-channels\n");
 
+	/*
+	 * Multi-queue support: This is an optional feature.
+	 */
+	err = xenbus_printf(XBT_NIL, dev->nodename,
+			"multi-queue-max-queues", "%u", xenvif_max_queues);

Should prefix this with "feature-".

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +3 -0
+	if (err)
+		pr_debug("Error writing multi-queue-max-queues\n");
+
 	err = xenbus_switch_state(dev, XenbusStateInitWait);
 	if (err)
 		goto fail;
@@ -491,6 +500,16 @@ static void connect(struct backend_info *be)
 	unsigned long credit_bytes, credit_usec;
 	unsigned int queue_index;
 	struct xenvif_queue *queue;

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 512

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+	unsigned int requested_num_queues;
+
+	/* Check whether the frontend requested multiple queues
+	 * and read the number requested.
+	 */
+	err = xenbus_scanf(XBT_NIL, dev->otherend,
+			"multi-queue-num-queues",
+			"%u", &requested_num_queues);
+	if (err < 0)
+		requested_num_queues = 1; /* Fall back to single queue */

You also need to check whether it gets back something larger than permitted -- guest can be buggy or malicious.

Quoted 21 lines
drivers/net/xen-netback/xenbus.c +5 -1
 	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
 	if (err) {
@@ -501,9 +520,13 @@ static void connect(struct backend_info *be)
 	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
 	read_xenbus_vif_flags(be);
 
-	be->vif->num_queues = 1;
+	/* Use the number of queues requested by the frontend */
+	be->vif->num_queues = requested_num_queues;
 	be->vif->queues = vzalloc(be->vif->num_queues *
 			sizeof(struct xenvif_queue));
+	rtnl_lock();
+	netif_set_real_num_tx_queues(be->vif->dev, be->vif->num_queues);
+	rtnl_unlock();
 
 	for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
 	{
@@ -549,29 +572,51 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)
 	unsigned long tx_ring_ref, rx_ring_ref;
 	unsigned int tx_evtchn, rx_evtchn;

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 583

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +9 -0
 	int err;
+	char *xspath = NULL;
+	size_t xspathsize;
+
+	/* If the frontend requested 1 queue, or we have fallen back
+	 * to single queue due to lack of frontend support for multi-
+	 * queue, expect the remaining XenStore keys in the toplevel
+	 * directory. Otherwise, expect them in a subdirectory called
+	 * queue-N.
+	 */

I think even if the frontend only requests 1 queue you can still put it under subdirectory? I don't have strong preference here though...

After the protocol is settled it needs to be documented in netif.h.

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 587

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+	if (queue->vif->num_queues == 1)
+		xspath = (char *)dev->otherend;
+	else {
+		xspathsize = strlen(dev->otherend) + 10;

Please avoid using magic number.

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 591

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+		xspath = kzalloc(xspathsize, GFP_KERNEL);
+		if (!xspath) {
+			xenbus_dev_fatal(dev, -ENOMEM,
+					"reading ring references");

"ring reference"?

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 595

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+			return -ENOMEM;
+		}
+		snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend,
+				queue->number);

Indentation.

Wei.

#12 lore raw

Re: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

Quoted 31 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:22PM +0000, Andrew J. Bennieston wrote:
[...]

Quoted 4 lines
drivers/net/xen-netback/interface.c +0 -0
@@ -355,7 +355,13 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
  	char name[IFNAMSIZ] = {};

drivers/net/xen-netback/interface.c struct xenvif *xenvif_alloc(struct device *parent, domid_t domid, · line 364

Quoted 10 lines
drivers/net/xen-netback/interface.c +7 -1
 
  	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
+	/*
+	 * Allocate a netdev with the max. supported number of queues.
+	 * When the guest selects the desired number, it will be updated
+	 * via netif_set_real_num_tx_queues().
+	 */
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup,
+			xenvif_max_queues);

Indentation.

Quoted 11 lines
drivers/net/xen-netback/interface.c +0 -0
  	if (dev == NULL) {
  		pr_warn("Could not allocate netdev for %s\n", name);
  		return ERR_PTR(-ENOMEM);
drivers/net/xen-netback/netback.c +0 -0
index 586e741..5d717d7 100644
@@ -55,6 +55,9 @@
  bool separate_tx_rx_irq = 1;
  module_param(separate_tx_rx_irq, bool, 0644);
 
Quoted 7 lines

drivers/net/xen-netback/netback.c line 60

Quoted 3 lines
drivers/net/xen-netback/netback.c +3 -0
+unsigned int xenvif_max_queues = 4;
+module_param(xenvif_max_queues, uint, 0644);
+

This looks a bit arbitrary. I guess it is better to set the default value to number of CPUs in Dom0?

It is quite arbitrary. A default of the number of dom0 CPUs makes sense. I'll change it.

Quoted 19 lines
Quoted 19 lines
drivers/net/xen-netback/netback.c +0 -0
  /*
   * This is the maximum slots a skb can have. If a guest sends a skb
   * which exceeds this limit it is considered malicious.
drivers/net/xen-netback/xenbus.c +1 -0
index c3332e2..ce7ca9a 100644
@@ -21,6 +21,7 @@
 
  #include "common.h"
  #include <linux/vmalloc.h>
+#include <linux/rtnetlink.h>
 
  struct backend_info {
  	struct xenbus_device *dev;
@@ -160,6 +161,14 @@ static int netback_probe(struct xenbus_device *dev,
  	if (err)
  		pr_debug("Error writing feature-split-event-channels\n");
 
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 168

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +5 -0
+	/*
+	 * Multi-queue support: This is an optional feature.
+	 */
+	err = xenbus_printf(XBT_NIL, dev->nodename,
+			"multi-queue-max-queues", "%u", xenvif_max_queues);

Should prefix this with "feature-".

This isn't a feature flag, it is a parameter specifying the maximum number of queues the backend will allow. It implies feature-multi-queue, which is not written. Way back in 2013 I posted an RFC for the XenStore keys to negotiate this and there was some disagreement on how to approach this particular bit...

One argument went that having a feature-multi-queue was redundant if you were also writing multi-queue-max-queues (regardless of the value that was specified). Another argument was that having feature-multi-queue allowed you to grep the xenstore-ls output for all supported features.

I decided to take this approach, but I'm not committed to it. Prefixing this with feature- probably isn't right, though; the feature-* keys all appear to be boolean flags indicating whether a feature is supported; this communicates a further value. A simple change would be to add the (redundant) feature-multi-queue = 1 flag...

Quoted 15 lines
Quoted 15 lines
drivers/net/xen-netback/xenbus.c +8 -0
+	if (err)
+		pr_debug("Error writing multi-queue-max-queues\n");
+
  	err = xenbus_switch_state(dev, XenbusStateInitWait);
  	if (err)
  		goto fail;
@@ -491,6 +500,16 @@ static void connect(struct backend_info *be)
  	unsigned long credit_bytes, credit_usec;
  	unsigned int queue_index;
  	struct xenvif_queue *queue;
+	unsigned int requested_num_queues;
+
+	/* Check whether the frontend requested multiple queues
+	 * and read the number requested.
+	 */
Quoted 9 lines

drivers/net/xen-netback/xenbus.c static void connect(struct backend_info *be) · line 512

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +5 -0
+	err = xenbus_scanf(XBT_NIL, dev->otherend,
+			"multi-queue-num-queues",
+			"%u", &requested_num_queues);
+	if (err < 0)
+		requested_num_queues = 1; /* Fall back to single queue */

You also need to check whether it gets back something larger than permitted -- guest can be buggy or malicious.

Ah, yes. I missed that.

Quoted 26 lines
Quoted 26 lines
drivers/net/xen-netback/xenbus.c +9 -1
  	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
  	if (err) {
@@ -501,9 +520,13 @@ static void connect(struct backend_info *be)
  	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
  	read_xenbus_vif_flags(be);
 
-	be->vif->num_queues = 1;
+	/* Use the number of queues requested by the frontend */
+	be->vif->num_queues = requested_num_queues;
  	be->vif->queues = vzalloc(be->vif->num_queues *
  			sizeof(struct xenvif_queue));
+	rtnl_lock();
+	netif_set_real_num_tx_queues(be->vif->dev, be->vif->num_queues);
+	rtnl_unlock();
 
  	for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
  	{
@@ -549,29 +572,51 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)
  	unsigned long tx_ring_ref, rx_ring_ref;
  	unsigned int tx_evtchn, rx_evtchn;
  	int err;
+	char *xspath = NULL;
+	size_t xspathsize;
+
+	/* If the frontend requested 1 queue, or we have fallen back
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 583

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +5 -0
+	 * to single queue due to lack of frontend support for multi-
+	 * queue, expect the remaining XenStore keys in the toplevel
+	 * directory. Otherwise, expect them in a subdirectory called
+	 * queue-N.
+	 */

I think even if the frontend only requests 1 queue you can still put it under subdirectory? I don't have strong preference here though...

There would still be some logic necessary to determine where to read
these values for old frontends vs new frontends, so having the 1-queue
case common to both made the most sense, to me. We'll always have to support new-backend/old-frontend and old-backend/new-frontend combinations so both will (always) have to check and do the appropriate thing here, whatever choice is made.

Quoted 3 lines

After the protocol is settled it needs to be documented in netif.h.

Indeed. I'll wait a couple of iterations of these patches so the protocol can stabilise before doing that.

Quoted 7 lines

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 587

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+	if (queue->vif->num_queues == 1)
+		xspath = (char *)dev->otherend;
+	else {
+		xspathsize = strlen(dev->otherend) + 10;

Please avoid using magic number.

Quoted 7 lines

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 591

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+		xspath = kzalloc(xspathsize, GFP_KERNEL);
+		if (!xspath) {
+			xenbus_dev_fatal(dev, -ENOMEM,
+					"reading ring references");

"ring reference"?

Hmm, I probably need to reword that.

Andrew.

Quoted 9 lines

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) · line 595

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +4 -0
+			return -ENOMEM;
+		}
+		snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend,
+				queue->number);

Indentation.

Wei.

#13 lore raw

Re: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

In reply to Andrew J. Bennieston
Quoted 89 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston
Subject: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

From: "Andrew J. Bennieston" <[email protected]>

Builds on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Writes the maximum supported number of queues into XenStore, and reads the values written by the frontend to determine how many queues to use.

Ring references and event channels are read from XenStore on a per-queue basis and rings are connected accordingly.

---
 drivers/net/xen-netback/common.h    |    2 +
 drivers/net/xen-netback/interface.c |    8 +++-
 drivers/net/xen-netback/netback.c   |    3 ++
 drivers/net/xen-netback/xenbus.c    |   70
++++++++++++++++++++++++++++++-----
 4 files changed, 72 insertions(+), 11 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h
index 54d2eeb..97efd09 100644

drivers/net/xen-netback/common.h +2 -0
@@ -254,4 +254,6 @@ void xenvif_carrier_on(struct xenvif *vif);
 
 extern bool separate_tx_rx_irq;
 
+extern unsigned int xenvif_max_queues;
+
 #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen- renamed from drivers/net/xen-netback/interface.c +0 -0

netback/interface.c
index 0113324..0234ff0 100644

drivers/net/xen-netback/interface.c +7 -1
@@ -355,7 +355,13 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
 	char name[IFNAMSIZ] = {};
 
 	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
+	/*
+	 * Allocate a netdev with the max. supported number of queues.
+	 * When the guest selects the desired number, it will be updated
+	 * via netif_set_real_num_tx_queues().
+	 */
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup,
+			xenvif_max_queues);
 	if (dev == NULL) {
 		pr_warn("Could not allocate netdev for %s\n", name);
drivers/net/xen-netback/interface.c +0 -0
 		return ERR_PTR(-ENOMEM);
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 586e741..5d717d7 100644

drivers/net/xen-netback/netback.c +3 -0
@@ -55,6 +55,9 @@
 bool separate_tx_rx_irq = 1;
 module_param(separate_tx_rx_irq, bool, 0644);
 
+unsigned int xenvif_max_queues = 4;
+module_param(xenvif_max_queues, uint, 0644);
+
 /*
  * This is the maximum slots a skb can have. If a guest sends a skb
  * which exceeds this limit it is considered malicious.
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c
index c3332e2..ce7ca9a 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -21,6 +21,7 @@
 
 #include "common.h"
 #include <linux/vmalloc.h>
+#include <linux/rtnetlink.h>
 
 struct backend_info {
 	struct xenbus_device *dev;

drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 166

Quoted 6 lines
drivers/net/xen-netback/xenbus.c +3 -0
@@ -160,6 +161,14 @@ static int netback_probe(struct xenbus_device *dev,
 	if (err)
 		pr_debug("Error writing feature-split-event-channels\n");
 
+	/*
+	 * Multi-queue support: This is an optional feature.
+	 */

Comment style. Did you run checkpatch?

Quoted 51 lines
drivers/net/xen-netback/xenbus.c +5 -0
+	err = xenbus_printf(XBT_NIL, dev->nodename,
+			"multi-queue-max-queues", "%u",
 xenvif_max_queues);
+	if (err)
+		pr_debug("Error writing multi-queue-max-queues\n");
+
 	err = xenbus_switch_state(dev, XenbusStateInitWait);
 	if (err)
drivers/net/xen-netback/xenbus.c +19 -1
 		goto fail;
@@ -491,6 +500,16 @@ static void connect(struct backend_info *be)
 	unsigned long credit_bytes, credit_usec;
 	unsigned int queue_index;
 	struct xenvif_queue *queue;
+	unsigned int requested_num_queues;
+
+	/* Check whether the frontend requested multiple queues
+	 * and read the number requested.
+	 */
+	err = xenbus_scanf(XBT_NIL, dev->otherend,
+			"multi-queue-num-queues",
+			"%u", &requested_num_queues);
+	if (err < 0)
+		requested_num_queues = 1; /* Fall back to single queue */
 
 	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
 	if (err) {
@@ -501,9 +520,13 @@ static void connect(struct backend_info *be)
 	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
 	read_xenbus_vif_flags(be);
 
-	be->vif->num_queues = 1;
+	/* Use the number of queues requested by the frontend */
+	be->vif->num_queues = requested_num_queues;
 	be->vif->queues = vzalloc(be->vif->num_queues *
 			sizeof(struct xenvif_queue));
+	rtnl_lock();
+	netif_set_real_num_tx_queues(be->vif->dev, be->vif-
 >num_queues);
+	rtnl_unlock();
 
 	for (queue_index = 0; queue_index < be->vif->num_queues;
++queue_index)
 	{
@@ -549,29 +572,51 @@ static int connect_rings(struct backend_info *be,
 struct xenvif_queue *queue)
 	unsigned long tx_ring_ref, rx_ring_ref;
 	unsigned int tx_evtchn, rx_evtchn;
 	int err;
+	char *xspath = NULL;
+	size_t xspathsize;
+

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, · line 588

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+	/* If the frontend requested 1 queue, or we have fallen back
+	 * to single queue due to lack of frontend support for multi-
+	 * queue, expect the remaining XenStore keys in the toplevel
+	 * directory. Otherwise, expect them in a subdirectory called
+	 * queue-N.
+	 */
+	if (queue->vif->num_queues == 1)
+		xspath = (char *)dev->otherend;
+	else {
+		xspathsize = strlen(dev->otherend) + 10;

Magic number.

Paul

Quoted 65 lines
drivers/net/xen-netback/xenbus.c +16 -7
+		xspath = kzalloc(xspathsize, GFP_KERNEL);
+		if (!xspath) {
+			xenbus_dev_fatal(dev, -ENOMEM,
+					"reading ring references");
+			return -ENOMEM;
+		}
+		snprintf(xspath, xspathsize, "%s/queue-%u", dev-
 >otherend,
+				queue->number);
+	}
 
-	err = xenbus_gather(XBT_NIL, dev->otherend,
+	err = xenbus_gather(XBT_NIL, xspath,
 			    "tx-ring-ref", "%lu", &tx_ring_ref,
 			    "rx-ring-ref", "%lu", &rx_ring_ref, NULL);
 	if (err) {
 		xenbus_dev_fatal(dev, err,
 				 "reading %s/ring-ref",
-				 dev->otherend);
-		return err;
+				 xspath);
+		goto err;
 	}
 
 	/* Try split event channels first, then single event channel. */
-	err = xenbus_gather(XBT_NIL, dev->otherend,
+	err = xenbus_gather(XBT_NIL, xspath,
 			    "event-channel-tx", "%u", &tx_evtchn,
 			    "event-channel-rx", "%u", &rx_evtchn, NULL);
 	if (err < 0) {
-		err = xenbus_scanf(XBT_NIL, dev->otherend,
+		err = xenbus_scanf(XBT_NIL, xspath,
 				   "event-channel", "%u", &tx_evtchn);
 		if (err < 0) {
 			xenbus_dev_fatal(dev, err,
 					 "reading %s/event-channel(-tx/rx)",
-					 dev->otherend);
-			return err;
+					 xspath);
+			goto err;
 		}
drivers/net/xen-netback/xenbus.c +7 -2
 		rx_evtchn = tx_evtchn;
 	}
@@ -584,10 +629,15 @@ static int connect_rings(struct backend_info *be,
 struct xenvif_queue *queue)
 				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
 				 tx_ring_ref, rx_ring_ref,
 				 tx_evtchn, rx_evtchn);
-		return err;
+		goto err;
 	}
 
-	return 0;
+	err = 0;
+err: /* Regular return falls through with err == 0 */
+	if (xspath != dev->otherend)
+		kfree(xspath);
+
+	return err;
 }

static int read_xenbus_vif_flags(struct backend_info *be)
--
1.7.10.4

#14 lore raw

Re: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

Quoted 162 lines · Paul Durrant
Quoted 89 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant; Andrew Bennieston
Subject: [PATCH RFC 2/4] xen-netback: Add support for multiple queues

From: "Andrew J. Bennieston" <[email protected]>

Builds on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Writes the maximum supported number of queues into XenStore, and reads the values written by the frontend to determine how many queues to use.

Ring references and event channels are read from XenStore on a per-queue basis and rings are connected accordingly.

---
  drivers/net/xen-netback/common.h    |    2 +
  drivers/net/xen-netback/interface.c |    8 +++-
  drivers/net/xen-netback/netback.c   |    3 ++
  drivers/net/xen-netback/xenbus.c    |   70
++++++++++++++++++++++++++++++-----
  4 files changed, 72 insertions(+), 11 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0 -0

netback/common.h
index 54d2eeb..97efd09 100644

drivers/net/xen-netback/common.h +2 -0
@@ -254,4 +254,6 @@ void xenvif_carrier_on(struct xenvif *vif);
 
  extern bool separate_tx_rx_irq;
 
+extern unsigned int xenvif_max_queues;
+
  #endif /* __XEN_NETBACK__COMMON_H__ */
drivers/net/xen- renamed from drivers/net/xen-netback/interface.c +0 -0

netback/interface.c
index 0113324..0234ff0 100644

drivers/net/xen-netback/interface.c +7 -1
@@ -355,7 +355,13 @@ struct xenvif *xenvif_alloc(struct device *parent,
 domid_t domid,
  	char name[IFNAMSIZ] = {};
 
  	snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
-	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 1);
+	/*
+	 * Allocate a netdev with the max. supported number of queues.
+	 * When the guest selects the desired number, it will be updated
+	 * via netif_set_real_num_tx_queues().
+	 */
+	dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup,
+			xenvif_max_queues);
  	if (dev == NULL) {
  		pr_warn("Could not allocate netdev for %s\n", name);
  		return ERR_PTR(-ENOMEM);
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 586e741..5d717d7 100644

drivers/net/xen-netback/netback.c +3 -0
@@ -55,6 +55,9 @@
  bool separate_tx_rx_irq = 1;
  module_param(separate_tx_rx_irq, bool, 0644);
 
+unsigned int xenvif_max_queues = 4;
+module_param(xenvif_max_queues, uint, 0644);
+
  /*
   * This is the maximum slots a skb can have. If a guest sends a skb
   * which exceeds this limit it is considered malicious.
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c
index c3332e2..ce7ca9a 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -21,6 +21,7 @@
 
  #include "common.h"
  #include <linux/vmalloc.h>
+#include <linux/rtnetlink.h>
 
  struct backend_info {
  	struct xenbus_device *dev;

drivers/net/xen-netback/xenbus.c static int netback_probe(struct xenbus_device *dev, · line 166

Quoted 6 lines
drivers/net/xen-netback/xenbus.c +3 -0
@@ -160,6 +161,14 @@ static int netback_probe(struct xenbus_device *dev,
  	if (err)
  		pr_debug("Error writing feature-split-event-channels\n");
 
+	/*
+	 * Multi-queue support: This is an optional feature.
+	 */

Comment style. Did you run checkpatch?

Quoted 51 lines
drivers/net/xen-netback/xenbus.c +5 -0
+	err = xenbus_printf(XBT_NIL, dev->nodename,
+			"multi-queue-max-queues", "%u",
 xenvif_max_queues);
+	if (err)
+		pr_debug("Error writing multi-queue-max-queues\n");
+
  	err = xenbus_switch_state(dev, XenbusStateInitWait);
  	if (err)

goto fail;

drivers/net/xen-netback/xenbus.c +19 -1
@@ -491,6 +500,16 @@ static void connect(struct backend_info *be)
  	unsigned long credit_bytes, credit_usec;
  	unsigned int queue_index;
  	struct xenvif_queue *queue;
+	unsigned int requested_num_queues;
+
+	/* Check whether the frontend requested multiple queues
+	 * and read the number requested.
+	 */
+	err = xenbus_scanf(XBT_NIL, dev->otherend,
+			"multi-queue-num-queues",
+			"%u", &requested_num_queues);
+	if (err < 0)
+		requested_num_queues = 1; /* Fall back to single queue */
 
  	err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
  	if (err) {
@@ -501,9 +520,13 @@ static void connect(struct backend_info *be)
  	xen_net_read_rate(dev, &credit_bytes, &credit_usec);
  	read_xenbus_vif_flags(be);
 
-	be->vif->num_queues = 1;
+	/* Use the number of queues requested by the frontend */
+	be->vif->num_queues = requested_num_queues;
  	be->vif->queues = vzalloc(be->vif->num_queues *
  			sizeof(struct xenvif_queue));
+	rtnl_lock();
+	netif_set_real_num_tx_queues(be->vif->dev, be->vif-
 > num_queues);
+	rtnl_unlock();
 
  	for (queue_index = 0; queue_index < be->vif->num_queues;
++queue_index)
  	{
@@ -549,29 +572,51 @@ static int connect_rings(struct backend_info *be,
 struct xenvif_queue *queue)
  	unsigned long tx_ring_ref, rx_ring_ref;
  	unsigned int tx_evtchn, rx_evtchn;
  	int err;
+	char *xspath = NULL;
+	size_t xspathsize;
+

drivers/net/xen-netback/xenbus.c static int connect_rings(struct backend_info *be, · line 588

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+	/* If the frontend requested 1 queue, or we have fallen back
+	 * to single queue due to lack of frontend support for multi-
+	 * queue, expect the remaining XenStore keys in the toplevel
+	 * directory. Otherwise, expect them in a subdirectory called
+	 * queue-N.
+	 */
+	if (queue->vif->num_queues == 1)
+		xspath = (char *)dev->otherend;
+	else {
+		xspathsize = strlen(dev->otherend) + 10;

Magic number.

Quoted 2 lines

Paul

Yes, I'll change this to a defined constant.

Andrew

Quoted 66 lines
Quoted 65 lines
drivers/net/xen-netback/xenbus.c +16 -7
+		xspath = kzalloc(xspathsize, GFP_KERNEL);
+		if (!xspath) {
+			xenbus_dev_fatal(dev, -ENOMEM,
+					"reading ring references");
+			return -ENOMEM;
+		}
+		snprintf(xspath, xspathsize, "%s/queue-%u", dev-
 > otherend,
+				queue->number);
+	}
 
-	err = xenbus_gather(XBT_NIL, dev->otherend,
+	err = xenbus_gather(XBT_NIL, xspath,
  			    "tx-ring-ref", "%lu", &tx_ring_ref,
  			    "rx-ring-ref", "%lu", &rx_ring_ref, NULL);
  	if (err) {
  		xenbus_dev_fatal(dev, err,
  				 "reading %s/ring-ref",
-				 dev->otherend);
-		return err;
+				 xspath);
+		goto err;
  	}
 
  	/* Try split event channels first, then single event channel. */
-	err = xenbus_gather(XBT_NIL, dev->otherend,
+	err = xenbus_gather(XBT_NIL, xspath,
  			    "event-channel-tx", "%u", &tx_evtchn,
  			    "event-channel-rx", "%u", &rx_evtchn, NULL);
  	if (err < 0) {
-		err = xenbus_scanf(XBT_NIL, dev->otherend,
+		err = xenbus_scanf(XBT_NIL, xspath,
  				   "event-channel", "%u", &tx_evtchn);
  		if (err < 0) {
  			xenbus_dev_fatal(dev, err,
  					 "reading %s/event-channel(-tx/rx)",
-					 dev->otherend);
-			return err;
+					 xspath);
+			goto err;
  		}
  		rx_evtchn = tx_evtchn;
  	}
drivers/net/xen-netback/xenbus.c +7 -2
@@ -584,10 +629,15 @@ static int connect_rings(struct backend_info *be,
 struct xenvif_queue *queue)
  				 "mapping shared-frames %lu/%lu port tx %u
 rx %u",
  				 tx_ring_ref, rx_ring_ref,
  				 tx_evtchn, rx_evtchn);
-		return err;
+		goto err;
  	}
 
-	return 0;
+	err = 0;
+err: /* Regular return falls through with err == 0 */
+	if (xspath != dev->otherend)
+		kfree(xspath);
+
+	return err;
  }

static int read_xenbus_vif_flags(struct backend_info *be)
--
1.7.10.4

#15 lore raw

RFC PATCH 3/4 xen-netfront: Factor queue-specific data into queue struct.

In reply to Andrew J. Bennieston

From: "Andrew J. Bennieston" <[email protected]>

In preparation for multi-queue support in xen-netfront, move the queue-specific data from struct netfront_info to struct netfront_queue, and update the rest of the code to use this.

Also adds loops over queues where appropriate, even though only one is configured at this point, and uses alloc_etherdev_mq() and the corresponding multi-queue netif wake/start/stop functions in preparation for multiple active queues.

Finally, implements a trivial queue selection function suitable for ndo_select_queue, which simply returns 0, selecting the first (and only) queue.

---
 drivers/net/xen-netfront.c |  931 +++++++++++++++++++++++++-------------------
 1 file changed, 541 insertions(+), 390 deletions(-)
drivers/net/xen-netfront.c +541 -390
index e59acb1..508ea96 100644
@@ -81,9 +81,12 @@ struct netfront_stats {
 	struct u64_stats_sync	syncp;
 };
 
-struct netfront_info {
-	struct list_head list;
-	struct net_device *netdev;
+struct netfront_info;
+
+struct netfront_queue {
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct netfront_info *info;
 
 	struct napi_struct napi;
 
@@ -93,10 +96,8 @@ struct netfront_info {
 	unsigned int tx_evtchn, rx_evtchn;
 	unsigned int tx_irq, rx_irq;
 	/* Only used when split event channels support is enabled */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
-
-	struct xenbus_device *xbdev;
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */
 
 	spinlock_t   tx_lock;
 	struct xen_netif_tx_front_ring tx;
@@ -139,6 +140,17 @@ struct netfront_info {
 	unsigned long rx_pfn_array[NET_RX_RING_SIZE];
 	struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
 	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
+};
+
+struct netfront_info {
+	struct list_head list;
+	struct net_device *netdev;
+
+	struct xenbus_device *xbdev;
+
+	/* Multi-queue support */
+	unsigned int num_queues;
+	struct netfront_queue *queues;
 
 	/* Statistics */
 	struct netfront_stats __percpu *stats;
@@ -186,21 +198,21 @@ static int xennet_rxidx(RING_IDX idx)
 	return idx & (NET_RX_RING_SIZE - 1);
 }
 
-static struct sk_buff *xennet_get_rx_skb(struct netfront_info *np,
+static struct sk_buff *xennet_get_rx_skb(struct netfront_queue *queue,
 					 RING_IDX ri)
 {
 	int i = xennet_rxidx(ri);
-	struct sk_buff *skb = np->rx_skbs[i];
-	np->rx_skbs[i] = NULL;
+	struct sk_buff *skb = queue->rx_skbs[i];
+	queue->rx_skbs[i] = NULL;
 	return skb;
 }
 
-static grant_ref_t xennet_get_rx_ref(struct netfront_info *np,
+static grant_ref_t xennet_get_rx_ref(struct netfront_queue *queue,
 					    RING_IDX ri)
 {
 	int i = xennet_rxidx(ri);
-	grant_ref_t ref = np->grant_rx_ref[i];
-	np->grant_rx_ref[i] = GRANT_INVALID_REF;
+	grant_ref_t ref = queue->grant_rx_ref[i];
+	queue->grant_rx_ref[i] = GRANT_INVALID_REF;
 	return ref;
 }
 
@@ -220,41 +232,39 @@ static bool xennet_can_sg(struct net_device *dev)
 
 static void rx_refill_timeout(unsigned long data)
 {
-	struct net_device *dev = (struct net_device *)data;
-	struct netfront_info *np = netdev_priv(dev);
-	napi_schedule(&np->napi);
+	struct netfront_queue *queue = (struct netfront_queue *)data;
+	napi_schedule(&queue->napi);
 }
 
-static int netfront_tx_slot_available(struct netfront_info *np)
+static int netfront_tx_slot_available(struct netfront_queue *queue)
 {
-	return (np->tx.req_prod_pvt - np->tx.rsp_cons) <
+	return (queue->tx.req_prod_pvt - queue->tx.rsp_cons) <
 		(TX_MAX_TARGET - MAX_SKB_FRAGS - 2);
 }
 
-static void xennet_maybe_wake_tx(struct net_device *dev)
+static void xennet_maybe_wake_tx(struct netfront_queue *queue)
 {
-	struct netfront_info *np = netdev_priv(dev);
+	struct net_device *dev = queue->info->netdev;
 
 	if (unlikely(netif_queue_stopped(dev)) &&
-	    netfront_tx_slot_available(np) &&
+	    netfront_tx_slot_available(queue) &&
 	    likely(netif_running(dev)))
-		netif_wake_queue(dev);
+		netif_tx_wake_queue(netdev_get_tx_queue(dev, queue->number));
 }
 
-static void xennet_alloc_rx_buffers(struct net_device *dev)
+static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
 {
 	unsigned short id;
-	struct netfront_info *np = netdev_priv(dev);
 	struct sk_buff *skb;
 	struct page *page;
 	int i, batch_target, notify;
-	RING_IDX req_prod = np->rx.req_prod_pvt;
+	RING_IDX req_prod = queue->rx.req_prod_pvt;
 	grant_ref_t ref;
 	unsigned long pfn;
 	void *vaddr;
 	struct xen_netif_rx_request *req;
 
-	if (unlikely(!netif_carrier_ok(dev)))
+	if (unlikely(!netif_carrier_ok(queue->info->netdev)))
 		return;
 
 	/*
@@ -263,9 +273,10 @@ static void xennet_alloc_rx_buffers(struct net_device *dev)
 	 * allocator, so should reduce the chance of failed allocation requests
 	 * both for ourself and for other kernel subsystems.
 	 */
-	batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
-	for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
-		skb = __netdev_alloc_skb(dev, RX_COPY_THRESHOLD + NET_IP_ALIGN,
+	batch_target = queue->rx_target - (req_prod - queue->rx.rsp_cons);
+	for (i = skb_queue_len(&queue->rx_batch); i < batch_target; i++) {
+		skb = __netdev_alloc_skb(queue->info->netdev,
+					 RX_COPY_THRESHOLD + NET_IP_ALIGN,
 					 GFP_ATOMIC | __GFP_NOWARN);
 		if (unlikely(!skb))
 			goto no_skb;
@@ -278,7 +289,7 @@ static void xennet_alloc_rx_buffers(struct net_device *dev)
 			kfree_skb(skb);
 no_skb:
 			/* Could not allocate any skbuffs. Try again later. */
-			mod_timer(&np->rx_refill_timer,
+			mod_timer(&queue->rx_refill_timer,
 				  jiffies + (HZ/10));
 
 			/* Any skbuffs queued for refill? Force them out. */
@@ -288,44 +299,44 @@ no_skb:
 		}
 
 		skb_add_rx_frag(skb, 0, page, 0, 0, PAGE_SIZE);
-		__skb_queue_tail(&np->rx_batch, skb);
+		__skb_queue_tail(&queue->rx_batch, skb);
 	}
 
 	/* Is the batch large enough to be worthwhile? */
-	if (i < (np->rx_target/2)) {
-		if (req_prod > np->rx.sring->req_prod)
+	if (i < (queue->rx_target/2)) {
+		if (req_prod > queue->rx.sring->req_prod)
 			goto push;
 		return;
 	}
 
 	/* Adjust our fill target if we risked running out of buffers. */
-	if (((req_prod - np->rx.sring->rsp_prod) < (np->rx_target / 4)) &&
-	    ((np->rx_target *= 2) > np->rx_max_target))
-		np->rx_target = np->rx_max_target;
+	if (((req_prod - queue->rx.sring->rsp_prod) < (queue->rx_target / 4)) &&
+	    ((queue->rx_target *= 2) > queue->rx_max_target))
+		queue->rx_target = queue->rx_max_target;
 
  refill:
 	for (i = 0; ; i++) {
-		skb = __skb_dequeue(&np->rx_batch);
+		skb = __skb_dequeue(&queue->rx_batch);
 		if (skb == NULL)
 			break;
 
-		skb->dev = dev;
+		skb->dev = queue->info->netdev;
 
 		id = xennet_rxidx(req_prod + i);
 
-		BUG_ON(np->rx_skbs[id]);
-		np->rx_skbs[id] = skb;
+		BUG_ON(queue->rx_skbs[id]);
+		queue->rx_skbs[id] = skb;
 
-		ref = gnttab_claim_grant_reference(&np->gref_rx_head);
+		ref = gnttab_claim_grant_reference(&queue->gref_rx_head);
 		BUG_ON((signed short)ref < 0);
-		np->grant_rx_ref[id] = ref;
+		queue->grant_rx_ref[id] = ref;
 
 		pfn = page_to_pfn(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 		vaddr = page_address(skb_frag_page(&skb_shinfo(skb)->frags[0]));
 
-		req = RING_GET_REQUEST(&np->rx, req_prod + i);
+		req = RING_GET_REQUEST(&queue->rx, req_prod + i);
 		gnttab_grant_foreign_access_ref(ref,
-						np->xbdev->otherend_id,
+						queue->info->xbdev->otherend_id,
 						pfn_to_mfn(pfn),
 						0);
 
@@ -336,71 +347,75 @@ no_skb:
 	wmb();		/* barrier so backend seens requests */
 
 	/* Above is a suitable barrier to ensure backend will see requests. */
-	np->rx.req_prod_pvt = req_prod + i;
+	queue->rx.req_prod_pvt = req_prod + i;
  push:
-	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->rx, notify);
+	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&queue->rx, notify);
 	if (notify)
-		notify_remote_via_irq(np->rx_irq);
+		notify_remote_via_irq(queue->rx_irq);
 }
 
 static int xennet_open(struct net_device *dev)
 {
 	struct netfront_info *np = netdev_priv(dev);
-
-	napi_enable(&np->napi);
-
-	spin_lock_bh(&np->rx_lock);
-	if (netif_carrier_ok(dev)) {
-		xennet_alloc_rx_buffers(dev);
-		np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
-		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
-			napi_schedule(&np->napi);
+	unsigned int i = 0;
+	struct netfront_queue *queue = NULL;
+
+	for (i = 0; i < np->num_queues; ++i) {
+		queue = &np->queues[i];
+		napi_enable(&queue->napi);
+
+		spin_lock_bh(&queue->rx_lock);
+		if (netif_carrier_ok(dev)) {
+			xennet_alloc_rx_buffers(queue);
+			queue->rx.sring->rsp_event = queue->rx.rsp_cons + 1;
+			if (RING_HAS_UNCONSUMED_RESPONSES(&queue->rx))
+				napi_schedule(&queue->napi);
+		}
+		spin_unlock_bh(&queue->rx_lock);
 	}
-	spin_unlock_bh(&np->rx_lock);
 
-	netif_start_queue(dev);
+	netif_tx_start_all_queues(dev);
 
 	return 0;
 }
 
-static void xennet_tx_buf_gc(struct net_device *dev)
+static void xennet_tx_buf_gc(struct netfront_queue *queue)
 {
 	RING_IDX cons, prod;
 	unsigned short id;
-	struct netfront_info *np = netdev_priv(dev);
 	struct sk_buff *skb;
 
-	BUG_ON(!netif_carrier_ok(dev));
+	BUG_ON(!netif_carrier_ok(queue->info->netdev));
 
 	do {
-		prod = np->tx.sring->rsp_prod;
+		prod = queue->tx.sring->rsp_prod;
 		rmb(); /* Ensure we see responses up to 'rp'. */
 
-		for (cons = np->tx.rsp_cons; cons != prod; cons++) {
+		for (cons = queue->tx.rsp_cons; cons != prod; cons++) {
 			struct xen_netif_tx_response *txrsp;
 
-			txrsp = RING_GET_RESPONSE(&np->tx, cons);
+			txrsp = RING_GET_RESPONSE(&queue->tx, cons);
 			if (txrsp->status == XEN_NETIF_RSP_NULL)
 				continue;
 
 			id  = txrsp->id;
-			skb = np->tx_skbs[id].skb;
+			skb = queue->tx_skbs[id].skb;
 			if (unlikely(gnttab_query_foreign_access(
-				np->grant_tx_ref[id]) != 0)) {
+				queue->grant_tx_ref[id]) != 0)) {
 				pr_alert("%s: warning -- grant still in use by backend domain\n",
 					 __func__);
 				BUG();
 			}
 			gnttab_end_foreign_access_ref(
-				np->grant_tx_ref[id], GNTMAP_readonly);
+				queue->grant_tx_ref[id], GNTMAP_readonly);
 			gnttab_release_grant_reference(
-				&np->gref_tx_head, np->grant_tx_ref[id]);
-			np->grant_tx_ref[id] = GRANT_INVALID_REF;
-			add_id_to_freelist(&np->tx_skb_freelist, np->tx_skbs, id);
+				&queue->gref_tx_head, queue->grant_tx_ref[id]);
+			queue->grant_tx_ref[id] = GRANT_INVALID_REF;
+			add_id_to_freelist(&queue->tx_skb_freelist, queue->tx_skbs, id);
 			dev_kfree_skb_irq(skb);
 		}
 
-		np->tx.rsp_cons = prod;
+		queue->tx.rsp_cons = prod;
 
 		/*
 		 * Set a new event, then check for race with update of tx_cons.
@@ -410,21 +425,20 @@ static void xennet_tx_buf_gc(struct net_device *dev)
 		 * data is outstanding: in such cases notification from Xen is
 		 * likely to be the only kick that we'll get.
 		 */
-		np->tx.sring->rsp_event =
-			prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
+		queue->tx.sring->rsp_event =
+			prod + ((queue->tx.sring->req_prod - prod) >> 1) + 1;
 		mb();		/* update shared area */
-	} while ((cons == prod) && (prod != np->tx.sring->rsp_prod));
+	} while ((cons == prod) && (prod != queue->tx.sring->rsp_prod));
 
-	xennet_maybe_wake_tx(dev);
+	xennet_maybe_wake_tx(queue);
 }
 
-static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
+static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
 			      struct xen_netif_tx_request *tx)
 {
-	struct netfront_info *np = netdev_priv(dev);
 	char *data = skb->data;
 	unsigned long mfn;
-	RING_IDX prod = np->tx.req_prod_pvt;
+	RING_IDX prod = queue->tx.req_prod_pvt;
 	int frags = skb_shinfo(skb)->nr_frags;
 	unsigned int offset = offset_in_page(data);
 	unsigned int len = skb_headlen(skb);
@@ -441,18 +455,18 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
 		data += tx->size;
 		offset = 0;
 
-		id = get_id_from_freelist(&np->tx_skb_freelist, np->tx_skbs);
-		np->tx_skbs[id].skb = skb_get(skb);
-		tx = RING_GET_REQUEST(&np->tx, prod++);
+		id = get_id_from_freelist(&queue->tx_skb_freelist, queue->tx_skbs);
+		queue->tx_skbs[id].skb = skb_get(skb);
+		tx = RING_GET_REQUEST(&queue->tx, prod++);
 		tx->id = id;
-		ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+		ref = gnttab_claim_grant_reference(&queue->gref_tx_head);
 		BUG_ON((signed short)ref < 0);
 
 		mfn = virt_to_mfn(data);
-		gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
+		gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
 						mfn, GNTMAP_readonly);
 
-		tx->gref = np->grant_tx_ref[id] = ref;
+		tx->gref = queue->grant_tx_ref[id] = ref;
 		tx->offset = offset;
 		tx->size = len;
 		tx->flags = 0;
@@ -484,20 +498,20 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
 
 			tx->flags |= XEN_NETTXF_more_data;
 
-			id = get_id_from_freelist(&np->tx_skb_freelist,
-						  np->tx_skbs);
-			np->tx_skbs[id].skb = skb_get(skb);
-			tx = RING_GET_REQUEST(&np->tx, prod++);
+			id = get_id_from_freelist(&queue->tx_skb_freelist,
+						  queue->tx_skbs);
+			queue->tx_skbs[id].skb = skb_get(skb);
+			tx = RING_GET_REQUEST(&queue->tx, prod++);
 			tx->id = id;
-			ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+			ref = gnttab_claim_grant_reference(&queue->gref_tx_head);
 			BUG_ON((signed short)ref < 0);
 
 			mfn = pfn_to_mfn(page_to_pfn(page));
 			gnttab_grant_foreign_access_ref(ref,
-							np->xbdev->otherend_id,
+							queue->info->xbdev->otherend_id,
 							mfn, GNTMAP_readonly);
 
-			tx->gref = np->grant_tx_ref[id] = ref;
+			tx->gref = queue->grant_tx_ref[id] = ref;
 			tx->offset = offset;
 			tx->size = bytes;
 			tx->flags = 0;
@@ -514,7 +528,7 @@ static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
 		}
 	}
 
-	np->tx.req_prod_pvt = prod;
+	queue->tx.req_prod_pvt = prod;
 }
 
 /*
@@ -540,6 +554,12 @@ static int xennet_count_skb_frag_slots(struct sk_buff *skb)
 	return pages;
 }
 
+static u16 xennet_select_queue(struct net_device *dev, struct sk_buff *skb)
+{
+	/* Stub for later implementation of queue selection */
+	return 0;
+}
+
 static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	unsigned short id;
@@ -555,6 +575,15 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	unsigned int offset = offset_in_page(data);
 	unsigned int len = skb_headlen(skb);
 	unsigned long flags;
+	struct netfront_queue *queue = NULL;
+	u16 queue_index;
+
+	/* Drop the packet if no queues are set up */
+	if (np->num_queues < 1 || np->queues == NULL)
+		goto drop;
+	/* Determine which queue to transmit this SKB on */
+	queue_index = skb_get_queue_mapping(skb);
+	queue = &np->queues[queue_index];
 
 	/* If skb->len is too big for wire format, drop skb and alert
 	 * user about misconfiguration.
@@ -574,29 +603,29 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		goto drop;
 	}
 
-	spin_lock_irqsave(&np->tx_lock, flags);
+	spin_lock_irqsave(&queue->tx_lock, flags);
 
 	if (unlikely(!netif_carrier_ok(dev) ||
 		     (slots > 1 && !xennet_can_sg(dev)) ||
 		     netif_needs_gso(skb, netif_skb_features(skb)))) {
-		spin_unlock_irqrestore(&np->tx_lock, flags);
+		spin_unlock_irqrestore(&queue->tx_lock, flags);
 		goto drop;
 	}
 
-	i = np->tx.req_prod_pvt;
+	i = queue->tx.req_prod_pvt;
 
-	id = get_id_from_freelist(&np->tx_skb_freelist, np->tx_skbs);
-	np->tx_skbs[id].skb = skb;
+	id = get_id_from_freelist(&queue->tx_skb_freelist, queue->tx_skbs);
+	queue->tx_skbs[id].skb = skb;
 
-	tx = RING_GET_REQUEST(&np->tx, i);
+	tx = RING_GET_REQUEST(&queue->tx, i);
 
 	tx->id   = id;
-	ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+	ref = gnttab_claim_grant_reference(&queue->gref_tx_head);
 	BUG_ON((signed short)ref < 0);
 	mfn = virt_to_mfn(data);
 	gnttab_grant_foreign_access_ref(
-		ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
-	tx->gref = np->grant_tx_ref[id] = ref;
+		ref, queue->info->xbdev->otherend_id, mfn, GNTMAP_readonly);
+	tx->gref = queue->grant_tx_ref[id] = ref;
 	tx->offset = offset;
 	tx->size = len;
 
@@ -612,7 +641,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		struct xen_netif_extra_info *gso;
 
 		gso = (struct xen_netif_extra_info *)
-			RING_GET_REQUEST(&np->tx, ++i);
+			RING_GET_REQUEST(&queue->tx, ++i);
 
 		tx->flags |= XEN_NETTXF_extra_info;
 
@@ -625,14 +654,14 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		gso->flags = 0;
 	}
 
-	np->tx.req_prod_pvt = i + 1;
+	queue->tx.req_prod_pvt = i + 1;
 
-	xennet_make_frags(skb, dev, tx);
+	xennet_make_frags(skb, queue, tx);
 	tx->size = skb->len;
 
-	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
+	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&queue->tx, notify);
 	if (notify)
-		notify_remote_via_irq(np->tx_irq);
+		notify_remote_via_irq(queue->tx_irq);
 
 	u64_stats_update_begin(&stats->syncp);
 	stats->tx_bytes += skb->len;
@@ -640,12 +669,12 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	u64_stats_update_end(&stats->syncp);
 
 	/* Note: It is not safe to access skb after xennet_tx_buf_gc()! */
-	xennet_tx_buf_gc(dev);
+	xennet_tx_buf_gc(queue);
 
-	if (!netfront_tx_slot_available(np))
-		netif_stop_queue(dev);
+	if (!netfront_tx_slot_available(queue))
+		netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->number));
 
-	spin_unlock_irqrestore(&np->tx_lock, flags);
+	spin_unlock_irqrestore(&queue->tx_lock, flags);
 
 	return NETDEV_TX_OK;
 
@@ -658,32 +687,37 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 static int xennet_close(struct net_device *dev)
 {
 	struct netfront_info *np = netdev_priv(dev);
-	netif_stop_queue(np->netdev);
-	napi_disable(&np->napi);
+	unsigned int i;
+	struct netfront_queue *queue;
+	netif_tx_stop_all_queues(np->netdev);
+	for (i = 0; i < np->num_queues; ++i) {
+		queue = &np->queues[i];
+		napi_disable(&queue->napi);
+	}
 	return 0;
 }
 
-static void xennet_move_rx_slot(struct netfront_info *np, struct sk_buff *skb,
+static void xennet_move_rx_slot(struct netfront_queue *queue, struct sk_buff *skb,
 				grant_ref_t ref)
 {
-	int new = xennet_rxidx(np->rx.req_prod_pvt);
-
-	BUG_ON(np->rx_skbs[new]);
-	np->rx_skbs[new] = skb;
-	np->grant_rx_ref[new] = ref;
-	RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
-	RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
-	np->rx.req_prod_pvt++;
+	int new = xennet_rxidx(queue->rx.req_prod_pvt);
+
+	BUG_ON(queue->rx_skbs[new]);
+	queue->rx_skbs[new] = skb;
+	queue->grant_rx_ref[new] = ref;
+	RING_GET_REQUEST(&queue->rx, queue->rx.req_prod_pvt)->id = new;
+	RING_GET_REQUEST(&queue->rx, queue->rx.req_prod_pvt)->gref = ref;
+	queue->rx.req_prod_pvt++;
 }
 
-static int xennet_get_extras(struct netfront_info *np,
+static int xennet_get_extras(struct netfront_queue *queue,
 			     struct xen_netif_extra_info *extras,
 			     RING_IDX rp)
 
 {
 	struct xen_netif_extra_info *extra;
-	struct device *dev = &np->netdev->dev;
-	RING_IDX cons = np->rx.rsp_cons;
+	struct device *dev = &queue->info->netdev->dev;
+	RING_IDX cons = queue->rx.rsp_cons;
 	int err = 0;
 
 	do {
@@ -698,7 +732,7 @@ static int xennet_get_extras(struct netfront_info *np,
 		}
 
 		extra = (struct xen_netif_extra_info *)
-			RING_GET_RESPONSE(&np->rx, ++cons);
+			RING_GET_RESPONSE(&queue->rx, ++cons);
 
 		if (unlikely(!extra->type ||
 			     extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
@@ -711,33 +745,33 @@ static int xennet_get_extras(struct netfront_info *np,
 			       sizeof(*extra));
 		}
 
-		skb = xennet_get_rx_skb(np, cons);
-		ref = xennet_get_rx_ref(np, cons);
-		xennet_move_rx_slot(np, skb, ref);
+		skb = xennet_get_rx_skb(queue, cons);
+		ref = xennet_get_rx_ref(queue, cons);
+		xennet_move_rx_slot(queue, skb, ref);
 	} while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
 
-	np->rx.rsp_cons = cons;
+	queue->rx.rsp_cons = cons;
 	return err;
 }
 
-static int xennet_get_responses(struct netfront_info *np,
+static int xennet_get_responses(struct netfront_queue *queue,
 				struct netfront_rx_info *rinfo, RING_IDX rp,
 				struct sk_buff_head *list)
 {
 	struct xen_netif_rx_response *rx = &rinfo->rx;
 	struct xen_netif_extra_info *extras = rinfo->extras;
-	struct device *dev = &np->netdev->dev;
-	RING_IDX cons = np->rx.rsp_cons;
-	struct sk_buff *skb = xennet_get_rx_skb(np, cons);
-	grant_ref_t ref = xennet_get_rx_ref(np, cons);
+	struct device *dev = &queue->info->netdev->dev;
+	RING_IDX cons = queue->rx.rsp_cons;
+	struct sk_buff *skb = xennet_get_rx_skb(queue, cons);
+	grant_ref_t ref = xennet_get_rx_ref(queue, cons);
 	int max = MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD);
 	int slots = 1;
 	int err = 0;
 	unsigned long ret;
 
 	if (rx->flags & XEN_NETRXF_extra_info) {
-		err = xennet_get_extras(np, extras, rp);
-		cons = np->rx.rsp_cons;
+		err = xennet_get_extras(queue, extras, rp);
+		cons = queue->rx.rsp_cons;
 	}
 
 	for (;;) {
@@ -746,7 +780,7 @@ static int xennet_get_responses(struct netfront_info *np,
 			if (net_ratelimit())
 				dev_warn(dev, "rx->offset: %x, size: %u\n",
 					 rx->offset, rx->status);
-			xennet_move_rx_slot(np, skb, ref);
+			xennet_move_rx_slot(queue, skb, ref);
 			err = -EINVAL;
 			goto next;
 		}
@@ -767,7 +801,7 @@ static int xennet_get_responses(struct netfront_info *np,
 		ret = gnttab_end_foreign_access_ref(ref, 0);
 		BUG_ON(!ret);
 
-		gnttab_release_grant_reference(&np->gref_rx_head, ref);
+		gnttab_release_grant_reference(&queue->gref_rx_head, ref);
 
 		__skb_queue_tail(list, skb);
 
@@ -782,9 +816,9 @@ next:
 			break;
 		}
 
-		rx = RING_GET_RESPONSE(&np->rx, cons + slots);
-		skb = xennet_get_rx_skb(np, cons + slots);
-		ref = xennet_get_rx_ref(np, cons + slots);
+		rx = RING_GET_RESPONSE(&queue->rx, cons + slots);
+		skb = xennet_get_rx_skb(queue, cons + slots);
+		ref = xennet_get_rx_ref(queue, cons + slots);
 		slots++;
 	}
 
@@ -795,7 +829,7 @@ next:
 	}
 
 	if (unlikely(err))
-		np->rx.rsp_cons = cons + slots;
+		queue->rx.rsp_cons = cons + slots;
 
 	return err;
 }
@@ -826,17 +860,17 @@ static int xennet_set_skb_gso(struct sk_buff *skb,
 	return 0;
 }
 
-static RING_IDX xennet_fill_frags(struct netfront_info *np,
+static RING_IDX xennet_fill_frags(struct netfront_queue *queue,
 				  struct sk_buff *skb,
 				  struct sk_buff_head *list)
 {
 	struct skb_shared_info *shinfo = skb_shinfo(skb);
-	RING_IDX cons = np->rx.rsp_cons;
+	RING_IDX cons = queue->rx.rsp_cons;
 	struct sk_buff *nskb;
 
 	while ((nskb = __skb_dequeue(list))) {
 		struct xen_netif_rx_response *rx =
-			RING_GET_RESPONSE(&np->rx, ++cons);
+			RING_GET_RESPONSE(&queue->rx, ++cons);
 		skb_frag_t *nfrag = &skb_shinfo(nskb)->frags[0];
 
 		if (shinfo->nr_frags == MAX_SKB_FRAGS) {
@@ -923,11 +957,10 @@ out:
 	return err;
 }
 
-static int handle_incoming_queue(struct net_device *dev,
+static int handle_incoming_queue(struct netfront_queue *queue,
 				 struct sk_buff_head *rxq)
 {
-	struct netfront_info *np = netdev_priv(dev);
-	struct netfront_stats *stats = this_cpu_ptr(np->stats);
+	struct netfront_stats *stats = this_cpu_ptr(queue->info->stats);
 	int packets_dropped = 0;
 	struct sk_buff *skb;
 
@@ -938,12 +971,12 @@ static int handle_incoming_queue(struct net_device *dev,
 			__pskb_pull_tail(skb, pull_to - skb_headlen(skb));
 
 		/* Ethernet work: Delayed to here as it peeks the header. */
-		skb->protocol = eth_type_trans(skb, dev);
+		skb->protocol = eth_type_trans(skb, queue->info->netdev);
 
-		if (checksum_setup(dev, skb)) {
+		if (checksum_setup(queue->info->netdev, skb)) {
 			kfree_skb(skb);
 			packets_dropped++;
-			dev->stats.rx_errors++;
+			queue->info->netdev->stats.rx_errors++;
 			continue;
 		}
 
@@ -953,7 +986,7 @@ static int handle_incoming_queue(struct net_device *dev,
 		u64_stats_update_end(&stats->syncp);
 
 		/* Pass it up. */
-		napi_gro_receive(&np->napi, skb);
+		napi_gro_receive(&queue->napi, skb);
 	}
 
 	return packets_dropped;
@@ -961,8 +994,8 @@ static int handle_incoming_queue(struct net_device *dev,
 
 static int xennet_poll(struct napi_struct *napi, int budget)
 {
-	struct netfront_info *np = container_of(napi, struct netfront_info, napi);
-	struct net_device *dev = np->netdev;
+	struct netfront_queue *queue = container_of(napi, struct netfront_queue, napi);
+	struct net_device *dev = queue->info->netdev;
 	struct sk_buff *skb;
 	struct netfront_rx_info rinfo;
 	struct xen_netif_rx_response *rx = &rinfo.rx;
@@ -975,29 +1008,29 @@ static int xennet_poll(struct napi_struct *napi, int budget)
 	unsigned long flags;
 	int err;
 
-	spin_lock(&np->rx_lock);
+	spin_lock(&queue->rx_lock);
 
 	skb_queue_head_init(&rxq);
 	skb_queue_head_init(&errq);
 	skb_queue_head_init(&tmpq);
 
-	rp = np->rx.sring->rsp_prod;
+	rp = queue->rx.sring->rsp_prod;
 	rmb(); /* Ensure we see queued responses up to 'rp'. */
 
-	i = np->rx.rsp_cons;
+	i = queue->rx.rsp_cons;
 	work_done = 0;
 	while ((i != rp) && (work_done < budget)) {
-		memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
+		memcpy(rx, RING_GET_RESPONSE(&queue->rx, i), sizeof(*rx));
 		memset(extras, 0, sizeof(rinfo.extras));
 
-		err = xennet_get_responses(np, &rinfo, rp, &tmpq);
+		err = xennet_get_responses(queue, &rinfo, rp, &tmpq);
 
 		if (unlikely(err)) {
 err:
 			while ((skb = __skb_dequeue(&tmpq)))
 				__skb_queue_tail(&errq, skb);
 			dev->stats.rx_errors++;
-			i = np->rx.rsp_cons;
+			i = queue->rx.rsp_cons;
 			continue;
 		}
 
@@ -1009,7 +1042,7 @@ err:
 
 			if (unlikely(xennet_set_skb_gso(skb, gso))) {
 				__skb_queue_head(&tmpq, skb);
-				np->rx.rsp_cons += skb_queue_len(&tmpq);
+				queue->rx.rsp_cons += skb_queue_len(&tmpq);
 				goto err;
 			}
 		}
@@ -1023,7 +1056,7 @@ err:
 		skb->data_len = rx->status;
 		skb->len += rx->status;
 
-		i = xennet_fill_frags(np, skb, &tmpq);
+		i = xennet_fill_frags(queue, skb, &tmpq);
 
 		if (rx->flags & XEN_NETRXF_csum_blank)
 			skb->ip_summed = CHECKSUM_PARTIAL;
@@ -1032,22 +1065,22 @@ err:
 
 		__skb_queue_tail(&rxq, skb);
 
-		np->rx.rsp_cons = ++i;
+		queue->rx.rsp_cons = ++i;
 		work_done++;
 	}
 
 	__skb_queue_purge(&errq);
 
-	work_done -= handle_incoming_queue(dev, &rxq);
+	work_done -= handle_incoming_queue(queue, &rxq);
 
 	/* If we get a callback with very few responses, reduce fill target. */
 	/* NB. Note exponential increase, linear decrease. */
-	if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
-	     ((3*np->rx_target) / 4)) &&
-	    (--np->rx_target < np->rx_min_target))
-		np->rx_target = np->rx_min_target;
+	if (((queue->rx.req_prod_pvt - queue->rx.sring->rsp_prod) >
+	     ((3*queue->rx_target) / 4)) &&
+	    (--queue->rx_target < queue->rx_min_target))
+		queue->rx_target = queue->rx_min_target;
 
-	xennet_alloc_rx_buffers(dev);
+	xennet_alloc_rx_buffers(queue);
 
 	if (work_done < budget) {
 		int more_to_do = 0;
@@ -1056,14 +1089,14 @@ err:
 
 		local_irq_save(flags);
 
-		RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, more_to_do);
+		RING_FINAL_CHECK_FOR_RESPONSES(&queue->rx, more_to_do);
 		if (!more_to_do)
 			__napi_complete(napi);
 
 		local_irq_restore(flags);
 	}
 
-	spin_unlock(&np->rx_lock);
+	spin_unlock(&queue->rx_lock);
 
 	return work_done;
 }
@@ -1111,56 +1144,56 @@ static struct rtnl_link_stats64 *xennet_get_stats64(struct net_device *dev,
 	return tot;
 }
 
-static void xennet_release_tx_bufs(struct netfront_info *np)
+static void xennet_release_tx_bufs(struct netfront_queue *queue)
 {
 	struct sk_buff *skb;
 	int i;
 
 	for (i = 0; i < NET_TX_RING_SIZE; i++) {
 		/* Skip over entries which are actually freelist references */
-		if (skb_entry_is_link(&np->tx_skbs[i]))
+		if (skb_entry_is_link(&queue->tx_skbs[i]))
 			continue;
 
-		skb = np->tx_skbs[i].skb;
-		gnttab_end_foreign_access_ref(np->grant_tx_ref[i],
+		skb = queue->tx_skbs[i].skb;
+		gnttab_end_foreign_access_ref(queue->grant_tx_ref[i],
 					      GNTMAP_readonly);
-		gnttab_release_grant_reference(&np->gref_tx_head,
-					       np->grant_tx_ref[i]);
-		np->grant_tx_ref[i] = GRANT_INVALID_REF;
-		add_id_to_freelist(&np->tx_skb_freelist, np->tx_skbs, i);
+		gnttab_release_grant_reference(&queue->gref_tx_head,
+					       queue->grant_tx_ref[i]);
+		queue->grant_tx_ref[i] = GRANT_INVALID_REF;
+		add_id_to_freelist(&queue->tx_skb_freelist, queue->tx_skbs, i);
 		dev_kfree_skb_irq(skb);
 	}
 }
 
-static void xennet_release_rx_bufs(struct netfront_info *np)
+static void xennet_release_rx_bufs(struct netfront_queue *queue)
 {
-	struct mmu_update      *mmu = np->rx_mmu;
-	struct multicall_entry *mcl = np->rx_mcl;
+	struct mmu_update      *mmu = queue->rx_mmu;
+	struct multicall_entry *mcl = queue->rx_mcl;
 	struct sk_buff_head free_list;
 	struct sk_buff *skb;
 	unsigned long mfn;
 	int xfer = 0, noxfer = 0, unused = 0;
 	int id, ref;
 
-	dev_warn(&np->netdev->dev, "%s: fix me for copying receiver.\n",
+	dev_warn(&queue->info->netdev->dev, "%s: fix me for copying receiver.\n",
 			 __func__);
 	return;
 
 	skb_queue_head_init(&free_list);
 
-	spin_lock_bh(&np->rx_lock);
+	spin_lock_bh(&queue->rx_lock);
 
 	for (id = 0; id < NET_RX_RING_SIZE; id++) {
-		ref = np->grant_rx_ref[id];
+		ref = queue->grant_rx_ref[id];
 		if (ref == GRANT_INVALID_REF) {
 			unused++;
 			continue;
 		}
 
-		skb = np->rx_skbs[id];
+		skb = queue->rx_skbs[id];
 		mfn = gnttab_end_foreign_transfer_ref(ref);
-		gnttab_release_grant_reference(&np->gref_rx_head, ref);
-		np->grant_rx_ref[id] = GRANT_INVALID_REF;
+		gnttab_release_grant_reference(&queue->gref_rx_head, ref);
+		queue->grant_rx_ref[id] = GRANT_INVALID_REF;
 
 		if (0 == mfn) {
 			skb_shinfo(skb)->nr_frags = 0;
@@ -1191,31 +1224,37 @@ static void xennet_release_rx_bufs(struct netfront_info *np)
 		xfer++;
 	}
 
-	dev_info(&np->netdev->dev, "%s: %d xfer, %d noxfer, %d unused\n",
+	dev_info(&queue->info->netdev->dev, "%s: %d xfer, %d noxfer, %d unused\n",
 		 __func__, xfer, noxfer, unused);
 
 	if (xfer) {
 		if (!xen_feature(XENFEAT_auto_translated_physmap)) {
 			/* Do all the remapping work and M2P updates. */
-			MULTI_mmu_update(mcl, np->rx_mmu, mmu - np->rx_mmu,
+			MULTI_mmu_update(mcl, queue->rx_mmu, mmu - queue->rx_mmu,
 					 NULL, DOMID_SELF);
 			mcl++;
-			HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
+			HYPERVISOR_multicall(queue->rx_mcl, mcl - queue->rx_mcl);
 		}
 	}
 
 	__skb_queue_purge(&free_list);
 
-	spin_unlock_bh(&np->rx_lock);
+	spin_unlock_bh(&queue->rx_lock);
 }
 
 static void xennet_uninit(struct net_device *dev)
 {
 	struct netfront_info *np = netdev_priv(dev);
-	xennet_release_tx_bufs(np);
-	xennet_release_rx_bufs(np);
-	gnttab_free_grant_references(np->gref_tx_head);
-	gnttab_free_grant_references(np->gref_rx_head);
+	struct netfront_queue *queue;
+	unsigned int i;
+
+	for (i = 0; i < np->num_queues; ++i) {
+		queue = &np->queues[i];
+		xennet_release_tx_bufs(queue);
+		xennet_release_rx_bufs(queue);
+		gnttab_free_grant_references(queue->gref_tx_head);
+		gnttab_free_grant_references(queue->gref_rx_head);
+	}
 }
 
 static netdev_features_t xennet_fix_features(struct net_device *dev,
@@ -1258,25 +1297,24 @@ static int xennet_set_features(struct net_device *dev,
 
 static irqreturn_t xennet_tx_interrupt(int irq, void *dev_id)
 {
-	struct netfront_info *np = dev_id;
-	struct net_device *dev = np->netdev;
+	struct netfront_queue *queue = dev_id;
 	unsigned long flags;
 
-	spin_lock_irqsave(&np->tx_lock, flags);
-	xennet_tx_buf_gc(dev);
-	spin_unlock_irqrestore(&np->tx_lock, flags);
+	spin_lock_irqsave(&queue->tx_lock, flags);
+	xennet_tx_buf_gc(queue);
+	spin_unlock_irqrestore(&queue->tx_lock, flags);
 
 	return IRQ_HANDLED;
 }
 
 static irqreturn_t xennet_rx_interrupt(int irq, void *dev_id)
 {
-	struct netfront_info *np = dev_id;
-	struct net_device *dev = np->netdev;
+	struct netfront_queue *queue = dev_id;
+	struct net_device *dev = queue->info->netdev;
 
 	if (likely(netif_carrier_ok(dev) &&
-		   RING_HAS_UNCONSUMED_RESPONSES(&np->rx)))
-			napi_schedule(&np->napi);
+		   RING_HAS_UNCONSUMED_RESPONSES(&queue->rx)))
+			napi_schedule(&queue->napi);
 
 	return IRQ_HANDLED;
 }
@@ -1291,7 +1329,12 @@ static irqreturn_t xennet_interrupt(int irq, void *dev_id)
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void xennet_poll_controller(struct net_device *dev)
 {
-	xennet_interrupt(0, dev);
+	/* Poll each queue */
+	struct netfront_info *info = netdev_priv(dev);
+	unsigned int i;
+	for (i = 0; i < info->num_queues; ++i) {
+		xennet_interrupt(0, &info->queues[i]);
+	}
 }
 #endif
 
@@ -1306,6 +1349,7 @@ static const struct net_device_ops xennet_netdev_ops = {
 	.ndo_validate_addr   = eth_validate_addr,
 	.ndo_fix_features    = xennet_fix_features,
 	.ndo_set_features    = xennet_set_features,
+	.ndo_select_queue    = xennet_select_queue,
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	.ndo_poll_controller = xennet_poll_controller,
 #endif
@@ -1317,24 +1361,15 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
 	struct net_device *netdev;
 	struct netfront_info *np;
 
-	netdev = alloc_etherdev(sizeof(struct netfront_info));
+	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), 1);
 	if (!netdev)
 		return ERR_PTR(-ENOMEM);
 
 	np                   = netdev_priv(netdev);
 	np->xbdev            = dev;
 
-	spin_lock_init(&np->tx_lock);
-	spin_lock_init(&np->rx_lock);
-
-	skb_queue_head_init(&np->rx_batch);
-	np->rx_target     = RX_DFL_MIN_TARGET;
-	np->rx_min_target = RX_DFL_MIN_TARGET;
-	np->rx_max_target = RX_MAX_TARGET;
-
-	init_timer(&np->rx_refill_timer);
-	np->rx_refill_timer.data = (unsigned long)netdev;
-	np->rx_refill_timer.function = rx_refill_timeout;
+	np->num_queues = 0;
+	np->queues = NULL;
 
 	err = -ENOMEM;
 	np->stats = alloc_percpu(struct netfront_stats);
@@ -1347,37 +1382,8 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
 		u64_stats_init(&xen_nf_stats->syncp);
 	}
 
-	/* Initialise tx_skbs as a free chain containing every entry. */
-	np->tx_skb_freelist = 0;
-	for (i = 0; i < NET_TX_RING_SIZE; i++) {
-		skb_entry_set_link(&np->tx_skbs[i], i+1);
-		np->grant_tx_ref[i] = GRANT_INVALID_REF;
-	}
-
-	/* Clear out rx_skbs */
-	for (i = 0; i < NET_RX_RING_SIZE; i++) {
-		np->rx_skbs[i] = NULL;
-		np->grant_rx_ref[i] = GRANT_INVALID_REF;
-	}
-
-	/* A grant for every tx ring slot */
-	if (gnttab_alloc_grant_references(TX_MAX_TARGET,
-					  &np->gref_tx_head) < 0) {
-		pr_alert("can't alloc tx grant refs\n");
-		err = -ENOMEM;
-		goto exit_free_stats;
-	}
-	/* A grant for every rx ring slot */
-	if (gnttab_alloc_grant_references(RX_MAX_TARGET,
-					  &np->gref_rx_head) < 0) {
-		pr_alert("can't alloc rx grant refs\n");
-		err = -ENOMEM;
-		goto exit_free_tx;
-	}
-
 	netdev->netdev_ops	= &xennet_netdev_ops;
 
-	netif_napi_add(netdev, &np->napi, xennet_poll, 64);
 	netdev->features        = NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
 				  NETIF_F_GSO_ROBUST;
 	netdev->hw_features	= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_TSO;
@@ -1401,10 +1407,6 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
 
 	return netdev;
 
- exit_free_tx:
-	gnttab_free_grant_references(np->gref_tx_head);
- exit_free_stats:
-	free_percpu(np->stats);
  exit:
 	free_netdev(netdev);
 	return ERR_PTR(err);
@@ -1462,30 +1464,35 @@ static void xennet_end_access(int ref, void *page)
 
 static void xennet_disconnect_backend(struct netfront_info *info)
 {
-	/* Stop old i/f to prevent errors whilst we rebuild the state. */
-	spin_lock_bh(&info->rx_lock);
-	spin_lock_irq(&info->tx_lock);
-	netif_carrier_off(info->netdev);
-	spin_unlock_irq(&info->tx_lock);
-	spin_unlock_bh(&info->rx_lock);
-
-	if (info->tx_irq && (info->tx_irq == info->rx_irq))
-		unbind_from_irqhandler(info->tx_irq, info);
-	if (info->tx_irq && (info->tx_irq != info->rx_irq)) {
-		unbind_from_irqhandler(info->tx_irq, info);
-		unbind_from_irqhandler(info->rx_irq, info);
-	}
-	info->tx_evtchn = info->rx_evtchn = 0;
-	info->tx_irq = info->rx_irq = 0;
+	unsigned int i = 0;
+	struct netfront_queue *queue = NULL;
+
+	for (i = 0; i < info->num_queues; ++i) {
+		/* Stop old i/f to prevent errors whilst we rebuild the state. */
+		spin_lock_bh(&queue->rx_lock);
+		spin_lock_irq(&queue->tx_lock);
+		netif_carrier_off(queue->info->netdev);
+		spin_unlock_irq(&queue->tx_lock);
+		spin_unlock_bh(&queue->rx_lock);
+
+		if (queue->tx_irq && (queue->tx_irq == queue->rx_irq))
+			unbind_from_irqhandler(queue->tx_irq, queue);
+		if (queue->tx_irq && (queue->tx_irq != queue->rx_irq)) {
+			unbind_from_irqhandler(queue->tx_irq, queue);
+			unbind_from_irqhandler(queue->rx_irq, queue);
+		}
+		queue->tx_evtchn = queue->rx_evtchn = 0;
+		queue->tx_irq = queue->rx_irq = 0;
 
-	/* End access and free the pages */
-	xennet_end_access(info->tx_ring_ref, info->tx.sring);
-	xennet_end_access(info->rx_ring_ref, info->rx.sring);
+		/* End access and free the pages */
+		xennet_end_access(queue->tx_ring_ref, queue->tx.sring);
+		xennet_end_access(queue->rx_ring_ref, queue->rx.sring);
 
-	info->tx_ring_ref = GRANT_INVALID_REF;
-	info->rx_ring_ref = GRANT_INVALID_REF;
-	info->tx.sring = NULL;
-	info->rx.sring = NULL;
+		queue->tx_ring_ref = GRANT_INVALID_REF;
+		queue->rx_ring_ref = GRANT_INVALID_REF;
+		queue->tx.sring = NULL;
+		queue->rx.sring = NULL;
+	}
 }
 
 /**
@@ -1526,100 +1533,86 @@ static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
 	return 0;
 }
 
-static int setup_netfront_single(struct netfront_info *info)
+static int setup_netfront_single(struct netfront_queue *queue)
 {
 	int err;
 
-	err = xenbus_alloc_evtchn(info->xbdev, &info->tx_evtchn);
+	err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->tx_evtchn);
 	if (err < 0)
 		goto fail;
 
-	err = bind_evtchn_to_irqhandler(info->tx_evtchn,
+	err = bind_evtchn_to_irqhandler(queue->tx_evtchn,
 					xennet_interrupt,
-					0, info->netdev->name, info);
+					0, queue->info->netdev->name, queue);
 	if (err < 0)
 		goto bind_fail;
-	info->rx_evtchn = info->tx_evtchn;
-	info->rx_irq = info->tx_irq = err;
+	queue->rx_evtchn = queue->tx_evtchn;
+	queue->rx_irq = queue->tx_irq = err;
 
 	return 0;
 
 bind_fail:
-	xenbus_free_evtchn(info->xbdev, info->tx_evtchn);
-	info->tx_evtchn = 0;
+	xenbus_free_evtchn(queue->info->xbdev, queue->tx_evtchn);
+	queue->tx_evtchn = 0;
 fail:
 	return err;
 }
 
-static int setup_netfront_split(struct netfront_info *info)
+static int setup_netfront_split(struct netfront_queue *queue)
 {
 	int err;
 
-	err = xenbus_alloc_evtchn(info->xbdev, &info->tx_evtchn);
+	err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->tx_evtchn);
 	if (err < 0)
 		goto fail;
-	err = xenbus_alloc_evtchn(info->xbdev, &info->rx_evtchn);
+	err = xenbus_alloc_evtchn(queue->info->xbdev, &queue->rx_evtchn);
 	if (err < 0)
 		goto alloc_rx_evtchn_fail;
 
-	snprintf(info->tx_irq_name, sizeof(info->tx_irq_name),
-		 "%s-tx", info->netdev->name);
-	err = bind_evtchn_to_irqhandler(info->tx_evtchn,
+	snprintf(queue->tx_irq_name, sizeof(queue->tx_irq_name),
+		 "%s-tx", queue->name);
+	err = bind_evtchn_to_irqhandler(queue->tx_evtchn,
 					xennet_tx_interrupt,
-					0, info->tx_irq_name, info);
+					0, queue->tx_irq_name, queue);
 	if (err < 0)
 		goto bind_tx_fail;
-	info->tx_irq = err;
+	queue->tx_irq = err;
 
-	snprintf(info->rx_irq_name, sizeof(info->rx_irq_name),
-		 "%s-rx", info->netdev->name);
-	err = bind_evtchn_to_irqhandler(info->rx_evtchn,
+	snprintf(queue->rx_irq_name, sizeof(queue->rx_irq_name),
+		 "%s-rx", queue->name);
+	err = bind_evtchn_to_irqhandler(queue->rx_evtchn,
 					xennet_rx_interrupt,
-					0, info->rx_irq_name, info);
+					0, queue->rx_irq_name, queue);
 	if (err < 0)
 		goto bind_rx_fail;
-	info->rx_irq = err;
+	queue->rx_irq = err;
 
 	return 0;
 
 bind_rx_fail:
-	unbind_from_irqhandler(info->tx_irq, info);
-	info->tx_irq = 0;
+	unbind_from_irqhandler(queue->tx_irq, queue);
+	queue->tx_irq = 0;
 bind_tx_fail:
-	xenbus_free_evtchn(info->xbdev, info->rx_evtchn);
-	info->rx_evtchn = 0;
+	xenbus_free_evtchn(queue->info->xbdev, queue->rx_evtchn);
+	queue->rx_evtchn = 0;
 alloc_rx_evtchn_fail:
-	xenbus_free_evtchn(info->xbdev, info->tx_evtchn);
-	info->tx_evtchn = 0;
+	xenbus_free_evtchn(queue->info->xbdev, queue->tx_evtchn);
+	queue->tx_evtchn = 0;
 fail:
 	return err;
 }
 
-static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
+static int setup_netfront(struct xenbus_device *dev,
+			struct netfront_queue *queue, unsigned int feature_split_evtchn)
 {
 	struct xen_netif_tx_sring *txs;
 	struct xen_netif_rx_sring *rxs;
 	int err;
-	struct net_device *netdev = info->netdev;
-	unsigned int feature_split_evtchn;
 
-	info->tx_ring_ref = GRANT_INVALID_REF;
-	info->rx_ring_ref = GRANT_INVALID_REF;
-	info->rx.sring = NULL;
-	info->tx.sring = NULL;
-	netdev->irq = 0;
-
-	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-			   "feature-split-event-channels", "%u",
-			   &feature_split_evtchn);
-	if (err < 0)
-		feature_split_evtchn = 0;
-
-	err = xen_net_read_mac(dev, netdev->dev_addr);
-	if (err) {
-		xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
-		goto fail;
-	}
+	queue->tx_ring_ref = GRANT_INVALID_REF;
+	queue->rx_ring_ref = GRANT_INVALID_REF;
+	queue->rx.sring = NULL;
+	queue->tx.sring = NULL;
 
 	txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
 	if (!txs) {
@@ -1628,13 +1621,13 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		goto fail;
 	}
 	SHARED_RING_INIT(txs);
-	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
+	FRONT_RING_INIT(&queue->tx, txs, PAGE_SIZE);
 
 	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
 	if (err < 0)
 		goto grant_tx_ring_fail;
+	queue->tx_ring_ref = err;
 
-	info->tx_ring_ref = err;
 	rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
 	if (!rxs) {
 		err = -ENOMEM;
@@ -1642,21 +1635,21 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 		goto alloc_rx_ring_fail;
 	}
 	SHARED_RING_INIT(rxs);
-	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
+	FRONT_RING_INIT(&queue->rx, rxs, PAGE_SIZE);
 
 	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
 	if (err < 0)
 		goto grant_rx_ring_fail;
-	info->rx_ring_ref = err;
+	queue->rx_ring_ref = err;
 
 	if (feature_split_evtchn)
-		err = setup_netfront_split(info);
+		err = setup_netfront_split(queue);
 	/* setup single event channel if
 	 *  a) feature-split-event-channels == 0
 	 *  b) feature-split-event-channels == 1 but failed to setup
 	 */
 	if (!feature_split_evtchn || (feature_split_evtchn && err))
-		err = setup_netfront_single(info);
+		err = setup_netfront_single(queue);
 
 	if (err)
 		goto alloc_evtchn_fail;
@@ -1667,17 +1660,77 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
 	 * granted pages because backend is not accessing it at this point.
 	 */
 alloc_evtchn_fail:
-	gnttab_end_foreign_access_ref(info->rx_ring_ref, 0);
+	gnttab_end_foreign_access_ref(queue->rx_ring_ref, 0);
 grant_rx_ring_fail:
 	free_page((unsigned long)rxs);
 alloc_rx_ring_fail:
-	gnttab_end_foreign_access_ref(info->tx_ring_ref, 0);
+	gnttab_end_foreign_access_ref(queue->tx_ring_ref, 0);
 grant_tx_ring_fail:
 	free_page((unsigned long)txs);
 fail:
 	return err;
 }
 
+/* Queue-specific initialisation
+ * This used to be done in xennet_create_dev() but must now
+ * be run per-queue.
+ */
+static int xennet_init_queue(struct netfront_queue *queue)
+{
+	unsigned short i;
+	int err = 0;
+
+	spin_lock_init(&queue->tx_lock);
+	spin_lock_init(&queue->rx_lock);
+
+	skb_queue_head_init(&queue->rx_batch);
+	queue->rx_target     = RX_DFL_MIN_TARGET;
+	queue->rx_min_target = RX_DFL_MIN_TARGET;
+	queue->rx_max_target = RX_MAX_TARGET;
+
+	init_timer(&queue->rx_refill_timer);
+	queue->rx_refill_timer.data = (unsigned long)queue;
+	queue->rx_refill_timer.function = rx_refill_timeout;
+
+	/* Initialise tx_skbs as a free chain containing every entry. */
+	queue->tx_skb_freelist = 0;
+	for (i = 0; i < NET_TX_RING_SIZE; i++) {
+		skb_entry_set_link(&queue->tx_skbs[i], i+1);
+		queue->grant_tx_ref[i] = GRANT_INVALID_REF;
+	}
+
+	/* Clear out rx_skbs */
+	for (i = 0; i < NET_RX_RING_SIZE; i++) {
+		queue->rx_skbs[i] = NULL;
+		queue->grant_rx_ref[i] = GRANT_INVALID_REF;
+	}
+
+	/* A grant for every tx ring slot */
+	if (gnttab_alloc_grant_references(TX_MAX_TARGET,
+					  &queue->gref_tx_head) < 0) {
+		pr_alert("can't alloc tx grant refs\n");
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	/* A grant for every rx ring slot */
+	if (gnttab_alloc_grant_references(RX_MAX_TARGET,
+					  &queue->gref_rx_head) < 0) {
+		pr_alert("can't alloc rx grant refs\n");
+		err = -ENOMEM;
+		goto exit_free_tx;
+	}
+
+	netif_napi_add(queue->info->netdev, &queue->napi, xennet_poll, 64);
+
+	return 0;
+
+ exit_free_tx:
+	gnttab_free_grant_references(queue->gref_tx_head);
+ exit:
+	return err;
+}
+
 /* Common code used when first setting up, and when resuming. */
 static int talk_to_netback(struct xenbus_device *dev,
 			   struct netfront_info *info)
@@ -1685,13 +1738,70 @@ static int talk_to_netback(struct xenbus_device *dev,
 	const char *message;
 	struct xenbus_transaction xbt;
 	int err;
+	unsigned int feature_split_evtchn;
+	unsigned int i = 0;
+	struct netfront_queue *queue = NULL;
 
-	/* Create shared ring, alloc event channel. */
-	err = setup_netfront(dev, info);
-	if (err)
+	info->netdev->irq = 0;
+
+	/* Check feature-split-event-channels */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			   "feature-split-event-channels", "%u",
+			   &feature_split_evtchn);
+	if (err < 0)
+		feature_split_evtchn = 0;
+
+	/* Read mac addr. */
+	err = xen_net_read_mac(dev, info->netdev->dev_addr);
+	if (err) {
+		xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
 		goto out;
+	}
+
+	/* Allocate array of queues */
+	info->queues = kcalloc(1, sizeof(struct netfront_queue), GFP_KERNEL);
+	if (!info->queues) {
+		err = -ENOMEM;
+		goto out;
+	}
+	info->num_queues = 1;
+
+	/* Create shared ring, alloc event channel -- for each queue */
+	for (i = 0; i < info->num_queues; ++i) {
+		queue = &info->queues[i];
+		queue->number = i;
+		queue->info = info;
+		err = xennet_init_queue(queue);
+		if (err) {
+			/* xennet_init_queue() cleans up after itself on failure,
+			 * but we still have to clean up any previously initialised
+			 * queues. If i > 0, set info->num_queues to i, then goto
+			 * destroy_ring, which calls xennet_disconnect_backend()
+			 * to tidy up.
+			 */
+			if (i > 0) {
+				info->num_queues = i;
+				goto destroy_ring;
+			}
+			else goto out;
+		}
+		err = setup_netfront(dev, queue, feature_split_evtchn);
+		if (err) {
+			/* As for xennet_init_queue(), setup_netfront() will tidy
+			 * up the current queue on error, but we need to clean up
+			 * those already allocated.
+			 */
+			if (i > 0) {
+				info->num_queues = i;
+				goto destroy_ring;
+			}
+			else goto out;
+		}
+	}
 
 again:
+	queue = &info->queues[0]; /* Use first queue only */
+
 	err = xenbus_transaction_start(&xbt);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "starting transaction");
@@ -1699,34 +1809,34 @@ again:
 	}
 
 	err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
-			    info->tx_ring_ref);
+			    queue->tx_ring_ref);
 	if (err) {
 		message = "writing tx ring-ref";
 		goto abort_transaction;
 	}
 	err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
-			    info->rx_ring_ref);
+			    queue->rx_ring_ref);
 	if (err) {
 		message = "writing rx ring-ref";
 		goto abort_transaction;
 	}
 
-	if (info->tx_evtchn == info->rx_evtchn) {
+	if (queue->tx_evtchn == queue->rx_evtchn) {
 		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel", "%u", info->tx_evtchn);
+				    "event-channel", "%u", queue->tx_evtchn);
 		if (err) {
 			message = "writing event-channel";
 			goto abort_transaction;
 		}
 	} else {
 		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-tx", "%u", info->tx_evtchn);
+				    "event-channel-tx", "%u", queue->tx_evtchn);
 		if (err) {
 			message = "writing event-channel-tx";
 			goto abort_transaction;
 		}
 		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-rx", "%u", info->rx_evtchn);
+				    "event-channel-rx", "%u", queue->rx_evtchn);
 		if (err) {
 			message = "writing event-channel-rx";
 			goto abort_transaction;
@@ -1773,6 +1883,9 @@ again:
 	xenbus_dev_fatal(dev, err, "%s", message);
  destroy_ring:
 	xennet_disconnect_backend(info);
+	kfree(info->queues);
+	info->queues = NULL;
+	info->num_queues = 0;
  out:
 	return err;
 }
@@ -1785,6 +1898,8 @@ static int xennet_connect(struct net_device *dev)
 	grant_ref_t ref;
 	struct xen_netif_rx_request *req;
 	unsigned int feature_rx_copy;
+	unsigned int j = 0;
+	struct netfront_queue *queue = NULL;
 
 	err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
 			   "feature-rx-copy", "%u", &feature_rx_copy);
@@ -1805,36 +1920,40 @@ static int xennet_connect(struct net_device *dev)
 	netdev_update_features(dev);
 	rtnl_unlock();
 
-	spin_lock_bh(&np->rx_lock);
-	spin_lock_irq(&np->tx_lock);
+	/* By now, the queue structures have been set up */
+	for (j = 0; j < np->num_queues; ++j) {
+		queue = &np->queues[j];
+		spin_lock_bh(&queue->rx_lock);
+		spin_lock_irq(&queue->tx_lock);
 
-	/* Step 1: Discard all pending TX packet fragments. */
-	xennet_release_tx_bufs(np);
+		/* Step 1: Discard all pending TX packet fragments. */
+		xennet_release_tx_bufs(queue);
 
-	/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
-	for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
-		skb_frag_t *frag;
-		const struct page *page;
-		if (!np->rx_skbs[i])
-			continue;
+		/* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
+		for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
+			skb_frag_t *frag;
+			const struct page *page;
+			if (!queue->rx_skbs[i])
+				continue;
 
-		skb = np->rx_skbs[requeue_idx] = xennet_get_rx_skb(np, i);
-		ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
-		req = RING_GET_REQUEST(&np->rx, requeue_idx);
+			skb = queue->rx_skbs[requeue_idx] = xennet_get_rx_skb(queue, i);
+			ref = queue->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(queue, i);
+			req = RING_GET_REQUEST(&queue->rx, requeue_idx);
 
-		frag = &skb_shinfo(skb)->frags[0];
-		page = skb_frag_page(frag);
-		gnttab_grant_foreign_access_ref(
-			ref, np->xbdev->otherend_id,
-			pfn_to_mfn(page_to_pfn(page)),
-			0);
-		req->gref = ref;
-		req->id   = requeue_idx;
+			frag = &skb_shinfo(skb)->frags[0];
+			page = skb_frag_page(frag);
+			gnttab_grant_foreign_access_ref(
+				ref, queue->info->xbdev->otherend_id,
+				pfn_to_mfn(page_to_pfn(page)),
+				0);
+			req->gref = ref;
+			req->id   = requeue_idx;
 
-		requeue_idx++;
-	}
+			requeue_idx++;
+		}
 
-	np->rx.req_prod_pvt = requeue_idx;
+		queue->rx.req_prod_pvt = requeue_idx;
+	}
 
 	/*
 	 * Step 3: All public and private state should now be sane.  Get
@@ -1843,14 +1962,17 @@ static int xennet_connect(struct net_device *dev)
 	 * packets.
 	 */
 	netif_carrier_on(np->netdev);
-	notify_remote_via_irq(np->tx_irq);
-	if (np->tx_irq != np->rx_irq)
-		notify_remote_via_irq(np->rx_irq);
-	xennet_tx_buf_gc(dev);
-	xennet_alloc_rx_buffers(dev);
-
-	spin_unlock_irq(&np->tx_lock);
-	spin_unlock_bh(&np->rx_lock);
+	for (j = 0; j < np->num_queues; ++j) {
+		queue = &np->queues[j];
+		notify_remote_via_irq(queue->tx_irq);
+		if (queue->tx_irq != queue->rx_irq)
+			notify_remote_via_irq(queue->rx_irq);
+		xennet_tx_buf_gc(queue);
+		xennet_alloc_rx_buffers(queue);
+
+		spin_unlock_irq(&queue->tx_lock);
+		spin_unlock_bh(&queue->rx_lock);
+	}
 
 	return 0;
 }
@@ -1952,7 +2074,10 @@ static ssize_t show_rxbuf_min(struct device *dev,
 	struct net_device *netdev = to_net_dev(dev);
 	struct netfront_info *info = netdev_priv(netdev);
 
-	return sprintf(buf, "%u\n", info->rx_min_target);
+	if (info->num_queues)
+		return sprintf(buf, "%u\n", info->queues[0].rx_min_target);
+	else
+		return sprintf(buf, "%u\n", RX_MIN_TARGET);
 }
 
 static ssize_t store_rxbuf_min(struct device *dev,
@@ -1963,6 +2088,8 @@ static ssize_t store_rxbuf_min(struct device *dev,
 	struct netfront_info *np = netdev_priv(netdev);
 	char *endp;
 	unsigned long target;
+	unsigned int i;
+	struct netfront_queue *queue;
 
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
@@ -1976,16 +2103,19 @@ static ssize_t store_rxbuf_min(struct device *dev,
 	if (target > RX_MAX_TARGET)
 		target = RX_MAX_TARGET;
 
-	spin_lock_bh(&np->rx_lock);
-	if (target > np->rx_max_target)
-		np->rx_max_target = target;
-	np->rx_min_target = target;
-	if (target > np->rx_target)
-		np->rx_target = target;
+	for (i = 0; i < np->num_queues; ++i) {
+		queue = &np->queues[i];
+		spin_lock_bh(&queue->rx_lock);
+		if (target > queue->rx_max_target)
+			queue->rx_max_target = target;
+		queue->rx_min_target = target;
+		if (target > queue->rx_target)
+			queue->rx_target = target;
 
-	xennet_alloc_rx_buffers(netdev);
+		xennet_alloc_rx_buffers(queue);
 
-	spin_unlock_bh(&np->rx_lock);
+		spin_unlock_bh(&queue->rx_lock);
+	}
 	return len;
 }
 
@@ -1995,7 +2125,10 @@ static ssize_t show_rxbuf_max(struct device *dev,
 	struct net_device *netdev = to_net_dev(dev);
 	struct netfront_info *info = netdev_priv(netdev);
 
-	return sprintf(buf, "%u\n", info->rx_max_target);
+	if (info->num_queues)
+		return sprintf(buf, "%u\n", info->queues[0].rx_max_target);
+	else
+		return sprintf(buf, "%u\n", RX_MAX_TARGET);
 }
 
 static ssize_t store_rxbuf_max(struct device *dev,
@@ -2006,6 +2139,8 @@ static ssize_t store_rxbuf_max(struct device *dev,
 	struct netfront_info *np = netdev_priv(netdev);
 	char *endp;
 	unsigned long target;
+	unsigned int i = 0;
+	struct netfront_queue *queue = NULL;
 
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
@@ -2019,16 +2154,19 @@ static ssize_t store_rxbuf_max(struct device *dev,
 	if (target > RX_MAX_TARGET)
 		target = RX_MAX_TARGET;
 
-	spin_lock_bh(&np->rx_lock);
-	if (target < np->rx_min_target)
-		np->rx_min_target = target;
-	np->rx_max_target = target;
-	if (target < np->rx_target)
-		np->rx_target = target;
+	for (i = 0; i < np->num_queues; ++i) {
+		queue = &np->queues[i];
+		spin_lock_bh(&queue->rx_lock);
+		if (target < queue->rx_min_target)
+			queue->rx_min_target = target;
+		queue->rx_max_target = target;
+		if (target < queue->rx_target)
+			queue->rx_target = target;
 
-	xennet_alloc_rx_buffers(netdev);
+		xennet_alloc_rx_buffers(queue);
 
-	spin_unlock_bh(&np->rx_lock);
+		spin_unlock_bh(&queue->rx_lock);
+	}
 	return len;
 }
 
@@ -2038,7 +2176,10 @@ static ssize_t show_rxbuf_cur(struct device *dev,
 	struct net_device *netdev = to_net_dev(dev);
 	struct netfront_info *info = netdev_priv(netdev);
 
-	return sprintf(buf, "%u\n", info->rx_target);
+	if (info->num_queues)
+		return sprintf(buf, "%u\n", info->queues[0].rx_target);
+	else
+		return sprintf(buf, "0\n");
 }
 
 static struct device_attribute xennet_attrs[] = {
@@ -2085,17 +2226,27 @@ static const struct xenbus_device_id netfront_ids[] = {
 static int xennet_remove(struct xenbus_device *dev)
 {
 	struct netfront_info *info = dev_get_drvdata(&dev->dev);
+	struct netfront_queue *queue = NULL;
+	unsigned int i = 0;
 
 	dev_dbg(&dev->dev, "%s\n", dev->nodename);
 
 	xennet_disconnect_backend(info);
 
+	for (i = 0; i < info->num_queues; ++i) {
+		queue = &info->queues[i];
+		del_timer_sync(&queue->rx_refill_timer);
+	}
+
+	if (info->num_queues) {
+		kfree(info->queues);
+		info->queues = NULL;
+	}
+
 	xennet_sysfs_delif(info->netdev);
 
 	unregister_netdev(info->netdev);
 
-	del_timer_sync(&info->rx_refill_timer);
-
 	free_percpu(info->stats);
 
 	free_netdev(info->netdev);
Signature · 1 line
1.7.10.4
#16 lore raw

Re: [PATCH RFC 3/4] xen-netfront: Factor queue-specific data into queue struct.

On Wed, Jan 15, 2014 at 04:23:23PM +0000, Andrew J. Bennieston wrote:
[...]

Quoted 9 lines
drivers/net/xen-netfront.c +5 -0
+
+struct netfront_queue {
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct netfront_info *info;
 
 	struct napi_struct napi;

drivers/net/xen-netfront.c struct netfront_info { · line 100

Quoted 9 lines
drivers/net/xen-netfront.c +2 -4
@@ -93,10 +96,8 @@ struct netfront_info {
 	unsigned int tx_evtchn, rx_evtchn;
 	unsigned int tx_irq, rx_irq;
 	/* Only used when split event channels support is enabled */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
-
-	struct xenbus_device *xbdev;
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */

Basically you're anticipating the maximum number of queues is below 10 here. I think leaving one more byte here won't hurt, just in case you will have more than 10 queues. The same goes to netback as well.

In your next patch you have max_queue as 16 by default, which has already broken your assumption here already. :-)

Quoted 9 lines
drivers/net/xen-netfront.c +2 -0
 	spinlock_t   tx_lock;
 	struct xen_netif_tx_front_ring tx;
@@ -139,6 +140,17 @@ struct netfront_info {
 	unsigned long rx_pfn_array[NET_RX_RING_SIZE];
 	struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
 	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
+};
+

[...]

drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 582

Quoted 12 lines

static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) {

drivers/net/xen-netfront.c +5 -0
 	unsigned short id;
@@ -555,6 +575,15 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	unsigned int offset = offset_in_page(data);
 	unsigned int len = skb_headlen(skb);
 	unsigned long flags;
+	struct netfront_queue *queue = NULL;
+	u16 queue_index;
+
+	/* Drop the packet if no queues are set up */
+	if (np->num_queues < 1 || np->queues == NULL)

Same as the comment in netback, you won't need both.

And the rest of the patch is basically replacing np with queue and putting things in loops. So I stopped here...

Wei.

#17 lore raw

Re: [PATCH RFC 3/4] xen-netfront: Factor queue-specific data into queue struct.

Quoted 25 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:23PM +0000, Andrew J. Bennieston wrote:
[...]

Quoted 9 lines
drivers/net/xen-netfront.c +5 -0
+
+struct netfront_queue {
+	unsigned int number; /* Queue number, 0-based */
+	char name[IFNAMSIZ+4]; /* DEVNAME-qN */
+	struct netfront_info *info;
 
  	struct napi_struct napi;

drivers/net/xen-netfront.c struct netfront_info { · line 100

Quoted 9 lines
drivers/net/xen-netfront.c +2 -4
@@ -93,10 +96,8 @@ struct netfront_info {
  	unsigned int tx_evtchn, rx_evtchn;
  	unsigned int tx_irq, rx_irq;
  	/* Only used when split event channels support is enabled */
-	char tx_irq_name[IFNAMSIZ+4]; /* DEVNAME-tx */
-	char rx_irq_name[IFNAMSIZ+4]; /* DEVNAME-rx */
-
-	struct xenbus_device *xbdev;
+	char tx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-tx */
+	char rx_irq_name[IFNAMSIZ+7]; /* DEVNAME-qN-rx */

Basically you're anticipating the maximum number of queues is below 10 here. I think leaving one more byte here won't hurt, just in case you will have more than 10 queues. The same goes to netback as well.

Quoted 3 lines

In your next patch you have max_queue as 16 by default, which has already broken your assumption here already. :-)

Yes, this should be fixed. I wouldn't expect more than 100 queues, so adding another byte here should be sufficient. In any case, I don't think the names are used for anything other than human readable output, so there won't be any functional impact to truncating them.

Quoted 10 lines
Quoted 9 lines
drivers/net/xen-netfront.c +2 -0
  	spinlock_t   tx_lock;
  	struct xen_netif_tx_front_ring tx;
@@ -139,6 +140,17 @@ struct netfront_info {
  	unsigned long rx_pfn_array[NET_RX_RING_SIZE];
  	struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
  	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
+};
+

[...]

Quoted 14 lines

drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 582

Quoted 12 lines
  static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  {
  	unsigned short id;
drivers/net/xen-netfront.c +5 -0
@@ -555,6 +575,15 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  	unsigned int offset = offset_in_page(data);
  	unsigned int len = skb_headlen(skb);
  	unsigned long flags;
+	struct netfront_queue *queue = NULL;
+	u16 queue_index;
+
+	/* Drop the packet if no queues are set up */
+	if (np->num_queues < 1 || np->queues == NULL)

Same as the comment in netback, you won't need both.

Agreed. I will switch to if (np->num_queues < 1) for the same reason I gave in the netback mail.

Andrew.

Quoted 6 lines

And the rest of the patch is basically replacing np with queue and putting things in loops. So I stopped here...

Wei.

#18 lore raw

RFC PATCH 4/4 xen-netfront: Add support for multiple queues

In reply to Andrew J. Bennieston

From: "Andrew J. Bennieston" <[email protected]>

Build on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Check XenStore for multi-queue support, and set up the rings and event channels accordingly.

Write ring references and event channels to XenStore in a queue hierarchy if appropriate, or flat when using only one queue.

Update the xennet_select_queue() function to choose the queue on which to transmit a packet based on the skb rxhash result.

---
 drivers/net/xen-netfront.c |  167 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 130 insertions(+), 37 deletions(-)
drivers/net/xen-netfront.c +130 -37
index 508ea96..9b08da5 100644
@@ -57,6 +57,10 @@
 #include <xen/interface/memory.h>
 #include <xen/interface/grant_table.h>
 
+/* Module parameters */
+unsigned int xennet_max_queues = 16;
+module_param(xennet_max_queues, uint, 0644);
+
 static const struct ethtool_ops xennet_ethtool_ops;
 
 struct netfront_cb {
@@ -556,8 +560,19 @@ static int xennet_count_skb_frag_slots(struct sk_buff *skb)
 
 static u16 xennet_select_queue(struct net_device *dev, struct sk_buff *skb)
 {
-	/* Stub for later implementation of queue selection */
-	return 0;
+	struct netfront_info *info = netdev_priv(dev);
+	u32 hash;
+	u16 queue_idx;
+
+	/* First, check if there is only one queue */
+	if (info->num_queues == 1)
+		queue_idx = 0;
+	else {
+		hash = skb_get_rxhash(skb);
+		queue_idx = (u16) (((u64)hash * info->num_queues) >> 32);
+	}
+
+	return queue_idx;
 }
 
 static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -1361,7 +1376,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
 	struct net_device *netdev;
 	struct netfront_info *np;
 
-	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), 1);
+	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), xennet_max_queues);
 	if (!netdev)
 		return ERR_PTR(-ENOMEM);
 
@@ -1731,6 +1746,89 @@ static int xennet_init_queue(struct netfront_queue *queue)
 	return err;
 }
 
+static int write_queue_xenstore_keys(struct netfront_queue *queue,
+			   struct xenbus_transaction *xbt, int write_hierarchical)
+{
+	/* Write the queue-specific keys into XenStore in the traditional
+	 * way for a single queue, or in a queue subkeys for multiple
+	 * queues.
+	 */
+	struct xenbus_device *dev = queue->info->xbdev;
+	int err;
+	const char *message;
+	char *path;
+	size_t pathsize;
+
+	/* Choose the correct place to write the keys */
+	if (write_hierarchical) {
+		pathsize = strlen(dev->nodename) + 10;
+		path = kzalloc(pathsize, GFP_KERNEL);
+		if (!path) {
+			err = -ENOMEM;
+			message = "writing ring references";
+			goto error;
+		}
+		snprintf(path, pathsize, "%s/queue-%u",
+				dev->nodename, queue->number);
+	}
+	else
+		path = (char *)dev->nodename;
+
+	/* Write ring references */
+	err = xenbus_printf(*xbt, path, "tx-ring-ref", "%u",
+			queue->tx_ring_ref);
+	if (err) {
+		message = "writing tx-ring-ref";
+		goto error;
+	}
+
+	err = xenbus_printf(*xbt, path, "rx-ring-ref", "%u",
+			queue->rx_ring_ref);
+	if (err) {
+		message = "writing rx-ring-ref";
+		goto error;
+	}
+
+	/* Write event channels; taking into account both shared
+	 * and split event channel scenarios.
+	 */
+	if (queue->tx_evtchn == queue->rx_evtchn) {
+		/* Shared event channel */
+		err = xenbus_printf(*xbt, path,
+				"event-channel", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel";
+			goto error;
+		}
+	}
+	else {
+		/* Split event channels */
+		err = xenbus_printf(*xbt, path,
+				"event-channel-tx", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel-tx";
+			goto error;
+		}
+
+		err = xenbus_printf(*xbt, path,
+				"event-channel-rx", "%u", queue->rx_evtchn);
+		if (err) {
+			message = "writing event-channel-rx";
+			goto error;
+		}
+	}
+
+	if (write_hierarchical)
+		kfree(path);
+	return 0;
+
+error:
+	if (write_hierarchical)
+		kfree(path);
+	xenbus_dev_fatal(dev, err, "%s", message);
+	return err;
+}
+
 /* Common code used when first setting up, and when resuming. */
 static int talk_to_netback(struct xenbus_device *dev,
 			   struct netfront_info *info)
@@ -1740,10 +1838,17 @@ static int talk_to_netback(struct xenbus_device *dev,
 	int err;
 	unsigned int feature_split_evtchn;
 	unsigned int i = 0;
+	unsigned int max_queues = 0;
 	struct netfront_queue *queue = NULL;
 
 	info->netdev->irq = 0;
 
+	/* Check if backend supports multiple queues */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			"multi-queue-max-queues", "%u", &max_queues);
+	if (err < 0)
+		max_queues = 1;
+
 	/* Check feature-split-event-channels */
 	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
 			   "feature-split-event-channels", "%u",
@@ -1759,12 +1864,12 @@ static int talk_to_netback(struct xenbus_device *dev,
 	}
 
 	/* Allocate array of queues */
-	info->queues = kcalloc(1, sizeof(struct netfront_queue), GFP_KERNEL);
+	info->queues = kcalloc(max_queues, sizeof(struct netfront_queue), GFP_KERNEL);
 	if (!info->queues) {
 		err = -ENOMEM;
 		goto out;
 	}
-	info->num_queues = 1;
+	info->num_queues = max_queues;
 
 	/* Create shared ring, alloc event channel -- for each queue */
 	for (i = 0; i < info->num_queues; ++i) {
@@ -1800,49 +1905,36 @@ static int talk_to_netback(struct xenbus_device *dev,
 	}
 
 again:
-	queue = &info->queues[0]; /* Use first queue only */
-
 	err = xenbus_transaction_start(&xbt);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "starting transaction");
 		goto destroy_ring;
 	}
 
-	err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
-			    queue->tx_ring_ref);
-	if (err) {
-		message = "writing tx ring-ref";
-		goto abort_transaction;
-	}
-	err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
-			    queue->rx_ring_ref);
-	if (err) {
-		message = "writing rx ring-ref";
-		goto abort_transaction;
+	if (info->num_queues == 1) {
+		err = write_queue_xenstore_keys(&info->queues[0], &xbt, 0); /* flat */
+		if (err)
+			goto abort_transaction_no_dev_fatal;
 	}
-
-	if (queue->tx_evtchn == queue->rx_evtchn) {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel", "%u", queue->tx_evtchn);
+	else {
+		/* Write the number of queues */
+		err = xenbus_printf(xbt, dev->nodename, "multi-queue-num-queues",
+				"%u", info->num_queues);
 		if (err) {
-			message = "writing event-channel";
-			goto abort_transaction;
+			message = "writing multi-queue-num-queues";
+			goto abort_transaction_no_dev_fatal;
 		}
-	} else {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-tx", "%u", queue->tx_evtchn);
-		if (err) {
-			message = "writing event-channel-tx";
-			goto abort_transaction;
-		}
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-rx", "%u", queue->rx_evtchn);
-		if (err) {
-			message = "writing event-channel-rx";
-			goto abort_transaction;
+
+		/* Write the keys for each queue */
+		for (i = 0; i < info->num_queues; ++i) {
+			queue = &info->queues[i];
+			err = write_queue_xenstore_keys(queue, &xbt, 1); /* hierarchical */
+			if (err)
+				goto abort_transaction_no_dev_fatal;
 		}
 	}
 
+	/* The remaining keys are not queue-specific */
 	err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
 			    1);
 	if (err) {
@@ -1879,8 +1971,9 @@ again:
 	return 0;
 
  abort_transaction:
-	xenbus_transaction_end(xbt, 1);
 	xenbus_dev_fatal(dev, err, "%s", message);
+abort_transaction_no_dev_fatal:
+	xenbus_transaction_end(xbt, 1);
  destroy_ring:
 	xennet_disconnect_backend(info);
 	kfree(info->queues);
Signature · 1 line
1.7.10.4
#19 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

On Wed, Jan 15, 2014 at 04:23:24PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netfront.c line 63

Quoted 4 lines
drivers/net/xen-netfront.c +4 -0
+/* Module parameters */
+unsigned int xennet_max_queues = 16;
+module_param(xennet_max_queues, uint, 0644);
+

This looks quite arbitrary as well.

Quoted 2 lines

static const struct ethtool_ops xennet_ethtool_ops;

[...]

Quoted 10 lines
drivers/net/xen-netfront.c +10 -0
+static int write_queue_xenstore_keys(struct netfront_queue *queue,
+			   struct xenbus_transaction *xbt, int write_hierarchical)
+{
+	/* Write the queue-specific keys into XenStore in the traditional
+	 * way for a single queue, or in a queue subkeys for multiple
+	 * queues.
+	 */
+	struct xenbus_device *dev = queue->info->xbdev;
+	int err;
+	const char *message;

drivers/net/xen-netfront.c static int xennet_init_queue(struct netfront_queue *queue) · line 1768

Quoted 10 lines
drivers/net/xen-netfront.c +10 -0
+	char *path;
+	size_t pathsize;
+
+	/* Choose the correct place to write the keys */
+	if (write_hierarchical) {
+		pathsize = strlen(dev->nodename) + 10;
+		path = kzalloc(pathsize, GFP_KERNEL);
+		if (!path) {
+			err = -ENOMEM;
+			message = "writing ring references";

This error message doesn't sound right.

drivers/net/xen-netfront.c static int xennet_init_queue(struct netfront_queue *queue) · line 1775

Quoted 7 lines
drivers/net/xen-netfront.c +7 -0
+			goto error;
+		}
+		snprintf(path, pathsize, "%s/queue-%u",
+				dev->nodename, queue->number);
+	}
+	else
+		path = (char *)dev->nodename;

Coding style. Should be surounded by {};

Quoted 1 line

+

[...]

Quoted 5 lines
drivers/net/xen-netfront.c +1 -0
@@ -1740,10 +1838,17 @@ static int talk_to_netback(struct xenbus_device *dev,
 	int err;
 	unsigned int feature_split_evtchn;
 	unsigned int i = 0;
+	unsigned int max_queues = 0;

drivers/net/xen-netfront.c static int talk_to_netback(struct xenbus_device *dev, · line 1851

Quoted 10 lines
drivers/net/xen-netfront.c +6 -0
 	struct netfront_queue *queue = NULL;
 
 	info->netdev->irq = 0;
 
+	/* Check if backend supports multiple queues */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			"multi-queue-max-queues", "%u", &max_queues);
+	if (err < 0)
+		max_queues = 1;
+

Need to check if backend provide too big a number for frontend.

Wei.

#20 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

Quoted 8 lines · Wei Liu

On Wed, Jan 15, 2014 at 04:23:24PM +0000, Andrew J. Bennieston wrote:
[...]

drivers/net/xen-netfront.c line 63

Quoted 4 lines
drivers/net/xen-netfront.c +4 -0
+/* Module parameters */
+unsigned int xennet_max_queues = 16;
+module_param(xennet_max_queues, uint, 0644);
+

This looks quite arbitrary as well.

Arbitrary, but less arbitrary than the netback parameter. I wanted to pick a value that was large enough to accommodate most sensible backend-provided limits, but not so large that it wasted resources. It is necessary only because I have to call alloc_etherdev_mq() long before I can read the maximum number of queues from XenStore. This value gets used there, so I wanted it to be at least as big as anything sensible that a backend might provide.

Quoted 17 lines
Quoted 2 lines

static const struct ethtool_ops xennet_ethtool_ops;

[...]

Quoted 14 lines
drivers/net/xen-netfront.c +14 -0
+static int write_queue_xenstore_keys(struct netfront_queue *queue,
+			   struct xenbus_transaction *xbt, int write_hierarchical)
+{
+	/* Write the queue-specific keys into XenStore in the traditional
+	 * way for a single queue, or in a queue subkeys for multiple
+	 * queues.
+	 */
+	struct xenbus_device *dev = queue->info->xbdev;
+	int err;
+	const char *message;
+	char *path;
+	size_t pathsize;
+
+	/* Choose the correct place to write the keys */
Quoted 9 lines

drivers/net/xen-netfront.c static int xennet_init_queue(struct netfront_queue *queue) · line 1768

Quoted 6 lines
drivers/net/xen-netfront.c +6 -0
+	if (write_hierarchical) {
+		pathsize = strlen(dev->nodename) + 10;
+		path = kzalloc(pathsize, GFP_KERNEL);
+		if (!path) {
+			err = -ENOMEM;
+			message = "writing ring references";

This error message doesn't sound right.

I'll reword it.

Quoted 10 lines

drivers/net/xen-netfront.c static int xennet_init_queue(struct netfront_queue *queue) · line 1775

Quoted 7 lines
drivers/net/xen-netfront.c +7 -0
+			goto error;
+		}
+		snprintf(path, pathsize, "%s/queue-%u",
+				dev->nodename, queue->number);
+	}
+	else
+		path = (char *)dev->nodename;

Coding style. Should be surounded by {};

OK.

Quoted 11 lines
Quoted 1 line

+

[...]

Quoted 9 lines
drivers/net/xen-netfront.c +1 -0
@@ -1740,10 +1838,17 @@ static int talk_to_netback(struct xenbus_device *dev,
  	int err;
  	unsigned int feature_split_evtchn;
  	unsigned int i = 0;
+	unsigned int max_queues = 0;
  	struct netfront_queue *queue = NULL;
 
  	info->netdev->irq = 0;
 
Quoted 8 lines

drivers/net/xen-netfront.c static int talk_to_netback(struct xenbus_device *dev, · line 1851

Quoted 6 lines
drivers/net/xen-netfront.c +6 -0
+	/* Check if backend supports multiple queues */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			"multi-queue-max-queues", "%u", &max_queues);
+	if (err < 0)
+		max_queues = 1;
+

Need to check if backend provide too big a number for frontend.

Yes, I'll add that check.

Andrew.

Quoted 3 lines

Wei.

#21 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

Quoted 11 lines · Andrew Bennieston
Quoted 10 lines · Wei Liu
Quoted 7 lines · Andrew J. Bennieston
drivers/net/xen-netfront.c +7 -0
+            goto error;
+        }
+        snprintf(path, pathsize, "%s/queue-%u",
+                dev->nodename, queue->number);
+    }
+    else
+        path = (char *)dev->nodename;
Quoted 3 lines
Quoted 1 line

Coding style. Should be surounded by {};

OK.

Linux style is single line blocks are not surrounded by braces. You should have the else on the same line as the preceeding } though.

i.e.,

if (...) {
one_line()
two_line()
red_line()
blue_line()
} else
a_line()

David

#22 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

Quoted 29 lines · David Vrabel
Quoted 11 lines · Andrew Bennieston
Quoted 10 lines · Wei Liu
Quoted 7 lines · Andrew J. Bennieston
drivers/net/xen-netfront.c +7 -0
+            goto error;
+        }
+        snprintf(path, pathsize, "%s/queue-%u",
+                dev->nodename, queue->number);
+    }
+    else
+        path = (char *)dev->nodename;
Quoted 3 lines
Quoted 1 line

Coding style. Should be surounded by {};

OK.

Linux style is single line blocks are not surrounded by braces. You should have the else on the same line as the preceeding } though.

i.e.,

if (...) {
    one_line()
    two_line()
    red_line()
    blue_line()
} else
    a_line()
Quoted 2 lines

David

Right; I'll make sure this consistently done throughout.

Andrew

#23 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

Quoted 30 lines · Andrew Bennieston
Quoted 29 lines · David Vrabel
Quoted 11 lines · Andrew Bennieston
Quoted 10 lines · Wei Liu
Quoted 7 lines · Andrew J. Bennieston
drivers/net/xen-netfront.c +7 -0
+            goto error;
+        }
+        snprintf(path, pathsize, "%s/queue-%u",
+                dev->nodename, queue->number);
+    }
+    else
+        path = (char *)dev->nodename;
Quoted 3 lines
Quoted 1 line

Coding style. Should be surounded by {};

OK.

Linux style is single line blocks are not surrounded by braces. You should have the else on the same line as the preceeding } though.

i.e.,

if (...) {
    one_line()
    two_line()
    red_line()
    blue_line()
} else
    a_line()
Quoted 3 lines
Quoted 2 lines

David

Right; I'll make sure this consistently done throughout.

Nope. Turns out I'm wrong.

In my defense, the last time I read CodingStyle (which was a considerable time ago!) it didn't say this.

David

#24 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

In reply to David Vrabel
Quoted 12 lines · David Vrabel
Quoted 11 lines · Andrew Bennieston
Quoted 10 lines · Wei Liu
Quoted 7 lines · Andrew J. Bennieston
drivers/net/xen-netfront.c +7 -0
+            goto error;
+        }
+        snprintf(path, pathsize, "%s/queue-%u",
+                dev->nodename, queue->number);
+    }
+    else
+        path = (char *)dev->nodename;
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Coding style. Should be surounded by {};

OK.

Linux style is single line blocks are not surrounded by braces. You

Not if the other branch contains multiple statements and is surounded by braces. See Documentation/CodingStyle line 169. ;-)

Wei.

Quoted 13 lines

should have the else on the same line as the preceeding } though.

i.e.,

if (...) {
   one_line()
   two_line()
   red_line()
   blue_line()
} else

a_line()

David

#25 lore raw

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

In reply to Andrew J. Bennieston
Quoted 24 lines · Andrew J. Bennieston

From: "Andrew J. Bennieston" <[email protected]>

Build on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Check XenStore for multi-queue support, and set up the rings and event channels accordingly.

Write ring references and event channels to XenStore in a queue hierarchy if appropriate, or flat when using only one queue.

Update the xennet_select_queue() function to choose the queue on which to transmit a packet based on the skb rxhash result.

---
 drivers/net/xen-netfront.c |  167 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 130 insertions(+), 37 deletions(-)
drivers/net/xen-netfront.c +0 -0
index 508ea96..9b08da5 100644

drivers/net/xen-netfront.c line 61

Quoted 5 lines
drivers/net/xen-netfront.c +2 -0
@@ -57,6 +57,10 @@
 #include <xen/interface/memory.h>
 #include <xen/interface/grant_table.h>
 
+/* Module parameters */
+unsigned int xennet_max_queues = 16;

Should this be based on some for of num_online_cpus() ?

drivers/net/xen-netfront.c line 62

Quoted 1 line
drivers/net/xen-netfront.c +1 -0
+module_param(xennet_max_queues, uint, 0644);

How about just 'max_queues' ? Without the 'xennet'?

Quoted 245 lines
drivers/net/xen-netfront.c +127 -37
+
 static const struct ethtool_ops xennet_ethtool_ops;
 
 struct netfront_cb {
@@ -556,8 +560,19 @@ static int xennet_count_skb_frag_slots(struct sk_buff *skb)
 
 static u16 xennet_select_queue(struct net_device *dev, struct sk_buff *skb)
 {
-	/* Stub for later implementation of queue selection */
-	return 0;
+	struct netfront_info *info = netdev_priv(dev);
+	u32 hash;
+	u16 queue_idx;
+
+	/* First, check if there is only one queue */
+	if (info->num_queues == 1)
+		queue_idx = 0;
+	else {
+		hash = skb_get_rxhash(skb);
+		queue_idx = (u16) (((u64)hash * info->num_queues) >> 32);
+	}
+
+	return queue_idx;
 }
 
 static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -1361,7 +1376,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
 	struct net_device *netdev;
 	struct netfront_info *np;
 
-	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), 1);
+	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), xennet_max_queues);
 	if (!netdev)
 		return ERR_PTR(-ENOMEM);
 
@@ -1731,6 +1746,89 @@ static int xennet_init_queue(struct netfront_queue *queue)
 	return err;
 }
 
+static int write_queue_xenstore_keys(struct netfront_queue *queue,
+			   struct xenbus_transaction *xbt, int write_hierarchical)
+{
+	/* Write the queue-specific keys into XenStore in the traditional
+	 * way for a single queue, or in a queue subkeys for multiple
+	 * queues.
+	 */
+	struct xenbus_device *dev = queue->info->xbdev;
+	int err;
+	const char *message;
+	char *path;
+	size_t pathsize;
+
+	/* Choose the correct place to write the keys */
+	if (write_hierarchical) {
+		pathsize = strlen(dev->nodename) + 10;
+		path = kzalloc(pathsize, GFP_KERNEL);
+		if (!path) {
+			err = -ENOMEM;
+			message = "writing ring references";
+			goto error;
+		}
+		snprintf(path, pathsize, "%s/queue-%u",
+				dev->nodename, queue->number);
+	}
+	else
+		path = (char *)dev->nodename;
+
+	/* Write ring references */
+	err = xenbus_printf(*xbt, path, "tx-ring-ref", "%u",
+			queue->tx_ring_ref);
+	if (err) {
+		message = "writing tx-ring-ref";
+		goto error;
+	}
+
+	err = xenbus_printf(*xbt, path, "rx-ring-ref", "%u",
+			queue->rx_ring_ref);
+	if (err) {
+		message = "writing rx-ring-ref";
+		goto error;
+	}
+
+	/* Write event channels; taking into account both shared
+	 * and split event channel scenarios.
+	 */
+	if (queue->tx_evtchn == queue->rx_evtchn) {
+		/* Shared event channel */
+		err = xenbus_printf(*xbt, path,
+				"event-channel", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel";
+			goto error;
+		}
+	}
+	else {
+		/* Split event channels */
+		err = xenbus_printf(*xbt, path,
+				"event-channel-tx", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel-tx";
+			goto error;
+		}
+
+		err = xenbus_printf(*xbt, path,
+				"event-channel-rx", "%u", queue->rx_evtchn);
+		if (err) {
+			message = "writing event-channel-rx";
+			goto error;
+		}
+	}
+
+	if (write_hierarchical)
+		kfree(path);
+	return 0;
+
+error:
+	if (write_hierarchical)
+		kfree(path);
+	xenbus_dev_fatal(dev, err, "%s", message);
+	return err;
+}
+
 /* Common code used when first setting up, and when resuming. */
 static int talk_to_netback(struct xenbus_device *dev,
 			   struct netfront_info *info)
@@ -1740,10 +1838,17 @@ static int talk_to_netback(struct xenbus_device *dev,
 	int err;
 	unsigned int feature_split_evtchn;
 	unsigned int i = 0;
+	unsigned int max_queues = 0;
 	struct netfront_queue *queue = NULL;
 
 	info->netdev->irq = 0;
 
+	/* Check if backend supports multiple queues */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			"multi-queue-max-queues", "%u", &max_queues);
+	if (err < 0)
+		max_queues = 1;
+
 	/* Check feature-split-event-channels */
 	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
 			   "feature-split-event-channels", "%u",
@@ -1759,12 +1864,12 @@ static int talk_to_netback(struct xenbus_device *dev,
 	}
 
 	/* Allocate array of queues */
-	info->queues = kcalloc(1, sizeof(struct netfront_queue), GFP_KERNEL);
+	info->queues = kcalloc(max_queues, sizeof(struct netfront_queue), GFP_KERNEL);
 	if (!info->queues) {
 		err = -ENOMEM;
 		goto out;
 	}
-	info->num_queues = 1;
+	info->num_queues = max_queues;
 
 	/* Create shared ring, alloc event channel -- for each queue */
 	for (i = 0; i < info->num_queues; ++i) {
@@ -1800,49 +1905,36 @@ static int talk_to_netback(struct xenbus_device *dev,
 	}
 
 again:
-	queue = &info->queues[0]; /* Use first queue only */
-
 	err = xenbus_transaction_start(&xbt);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "starting transaction");
 		goto destroy_ring;
 	}
 
-	err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
-			    queue->tx_ring_ref);
-	if (err) {
-		message = "writing tx ring-ref";
-		goto abort_transaction;
-	}
-	err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
-			    queue->rx_ring_ref);
-	if (err) {
-		message = "writing rx ring-ref";
-		goto abort_transaction;
+	if (info->num_queues == 1) {
+		err = write_queue_xenstore_keys(&info->queues[0], &xbt, 0); /* flat */
+		if (err)
+			goto abort_transaction_no_dev_fatal;
 	}
-
-	if (queue->tx_evtchn == queue->rx_evtchn) {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel", "%u", queue->tx_evtchn);
+	else {
+		/* Write the number of queues */
+		err = xenbus_printf(xbt, dev->nodename, "multi-queue-num-queues",
+				"%u", info->num_queues);
 		if (err) {
-			message = "writing event-channel";
-			goto abort_transaction;
+			message = "writing multi-queue-num-queues";
+			goto abort_transaction_no_dev_fatal;
 		}
-	} else {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-tx", "%u", queue->tx_evtchn);
-		if (err) {
-			message = "writing event-channel-tx";
-			goto abort_transaction;
-		}
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-rx", "%u", queue->rx_evtchn);
-		if (err) {
-			message = "writing event-channel-rx";
-			goto abort_transaction;
+
+		/* Write the keys for each queue */
+		for (i = 0; i < info->num_queues; ++i) {
+			queue = &info->queues[i];
+			err = write_queue_xenstore_keys(queue, &xbt, 1); /* hierarchical */
+			if (err)
+				goto abort_transaction_no_dev_fatal;
 		}
 	}
 
+	/* The remaining keys are not queue-specific */
 	err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
 			    1);
 	if (err) {
@@ -1879,8 +1971,9 @@ again:
 	return 0;
 
  abort_transaction:
-	xenbus_transaction_end(xbt, 1);
 	xenbus_dev_fatal(dev, err, "%s", message);
+abort_transaction_no_dev_fatal:
+	xenbus_transaction_end(xbt, 1);
  destroy_ring:
 	xennet_disconnect_backend(info);
 	kfree(info->queues);
Signature · 7 lines
1.7.10.4


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

Re: [PATCH RFC 4/4] xen-netfront: Add support for multiple queues

Quoted 28 lines · Konrad Rzeszutek Wilk
Quoted 27 lines · Andrew J. Bennieston

From: "Andrew J. Bennieston" <[email protected]>

Build on the refactoring of the previous patch to implement multiple queues between xen-netfront and xen-netback.

Check XenStore for multi-queue support, and set up the rings and event channels accordingly.

Write ring references and event channels to XenStore in a queue hierarchy if appropriate, or flat when using only one queue.

Update the xennet_select_queue() function to choose the queue on which to transmit a packet based on the skb rxhash result.

---
  drivers/net/xen-netfront.c |  167 ++++++++++++++++++++++++++++++++++----------
  1 file changed, 130 insertions(+), 37 deletions(-)
drivers/net/xen-netfront.c +0 -0
index 508ea96..9b08da5 100644
@@ -57,6 +57,10 @@
  #include <xen/interface/memory.h>
  #include <xen/interface/grant_table.h>
 
Quoted 4 lines

drivers/net/xen-netfront.c line 61

Quoted 2 lines
drivers/net/xen-netfront.c +2 -0
+/* Module parameters */
+unsigned int xennet_max_queues = 16;

Should this be based on some for of num_online_cpus() ?

Perhaps. This would have the effect of setting the number of queues to min(num dom0 cpus, num domU cpus). The logical argument behind this is that if you have more than one queue per CPU you're potentially overloading the CPUs, but the more queues you have, the more opportunity there is to split traffic and load balance across the available resources, with the kernel scheduler taking care of which CPUs to run which threads on.

Either way, num_online_cpus() certainly makes for a sensible default, and I'll make that change in the V2 series.

Quoted 5 lines

drivers/net/xen-netfront.c line 62

Quoted 2 lines
drivers/net/xen-netfront.c +1 -0
+module_param(xennet_max_queues, uint, 0644);

How about just 'max_queues' ? Without the 'xennet'?

Yes, I can remove the 'xennet' part.

Thanks for the feedback.
-Andrew

Quoted 246 lines
Quoted 246 lines
drivers/net/xen-netfront.c +127 -38
+
  static const struct ethtool_ops xennet_ethtool_ops;
 
  struct netfront_cb {
@@ -556,8 +560,19 @@ static int xennet_count_skb_frag_slots(struct sk_buff *skb)
 
  static u16 xennet_select_queue(struct net_device *dev, struct sk_buff *skb)
  {
-	/* Stub for later implementation of queue selection */
-	return 0;
+	struct netfront_info *info = netdev_priv(dev);
+	u32 hash;
+	u16 queue_idx;
+
+	/* First, check if there is only one queue */
+	if (info->num_queues == 1)
+		queue_idx = 0;
+	else {
+		hash = skb_get_rxhash(skb);
+		queue_idx = (u16) (((u64)hash * info->num_queues) >> 32);
+	}
+
+	return queue_idx;
  }
 
  static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -1361,7 +1376,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
  	struct net_device *netdev;
  	struct netfront_info *np;
 
-	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), 1);
+	netdev = alloc_etherdev_mq(sizeof(struct netfront_info), xennet_max_queues);
  	if (!netdev)
  		return ERR_PTR(-ENOMEM);
 
@@ -1731,6 +1746,89 @@ static int xennet_init_queue(struct netfront_queue *queue)
  	return err;
  }
 
+static int write_queue_xenstore_keys(struct netfront_queue *queue,
+			   struct xenbus_transaction *xbt, int write_hierarchical)
+{
+	/* Write the queue-specific keys into XenStore in the traditional
+	 * way for a single queue, or in a queue subkeys for multiple
+	 * queues.
+	 */
+	struct xenbus_device *dev = queue->info->xbdev;
+	int err;
+	const char *message;
+	char *path;
+	size_t pathsize;
+
+	/* Choose the correct place to write the keys */
+	if (write_hierarchical) {
+		pathsize = strlen(dev->nodename) + 10;
+		path = kzalloc(pathsize, GFP_KERNEL);
+		if (!path) {
+			err = -ENOMEM;
+			message = "writing ring references";
+			goto error;
+		}
+		snprintf(path, pathsize, "%s/queue-%u",
+				dev->nodename, queue->number);
+	}
+	else
+		path = (char *)dev->nodename;
+
+	/* Write ring references */
+	err = xenbus_printf(*xbt, path, "tx-ring-ref", "%u",
+			queue->tx_ring_ref);
+	if (err) {
+		message = "writing tx-ring-ref";
+		goto error;
+	}
+
+	err = xenbus_printf(*xbt, path, "rx-ring-ref", "%u",
+			queue->rx_ring_ref);
+	if (err) {
+		message = "writing rx-ring-ref";
+		goto error;
+	}
+
+	/* Write event channels; taking into account both shared
+	 * and split event channel scenarios.
+	 */
+	if (queue->tx_evtchn == queue->rx_evtchn) {
+		/* Shared event channel */
+		err = xenbus_printf(*xbt, path,
+				"event-channel", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel";
+			goto error;
+		}
+	}
+	else {
+		/* Split event channels */
+		err = xenbus_printf(*xbt, path,
+				"event-channel-tx", "%u", queue->tx_evtchn);
+		if (err) {
+			message = "writing event-channel-tx";
+			goto error;
+		}
+
+		err = xenbus_printf(*xbt, path,
+				"event-channel-rx", "%u", queue->rx_evtchn);
+		if (err) {
+			message = "writing event-channel-rx";
+			goto error;
+		}
+	}
+
+	if (write_hierarchical)
+		kfree(path);
+	return 0;
+
+error:
+	if (write_hierarchical)
+		kfree(path);
+	xenbus_dev_fatal(dev, err, "%s", message);
+	return err;
+}
+
  /* Common code used when first setting up, and when resuming. */
  static int talk_to_netback(struct xenbus_device *dev,
  			   struct netfront_info *info)
@@ -1740,10 +1838,17 @@ static int talk_to_netback(struct xenbus_device *dev,
  	int err;
  	unsigned int feature_split_evtchn;
  	unsigned int i = 0;
+	unsigned int max_queues = 0;
  	struct netfront_queue *queue = NULL;
 
  	info->netdev->irq = 0;
 
+	/* Check if backend supports multiple queues */
+	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+			"multi-queue-max-queues", "%u", &max_queues);
+	if (err < 0)
+		max_queues = 1;
+
  	/* Check feature-split-event-channels */
  	err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
  			   "feature-split-event-channels", "%u",
@@ -1759,12 +1864,12 @@ static int talk_to_netback(struct xenbus_device *dev,
  	}
 
  	/* Allocate array of queues */
-	info->queues = kcalloc(1, sizeof(struct netfront_queue), GFP_KERNEL);
+	info->queues = kcalloc(max_queues, sizeof(struct netfront_queue), GFP_KERNEL);
  	if (!info->queues) {
  		err = -ENOMEM;
  		goto out;
  	}
-	info->num_queues = 1;
+	info->num_queues = max_queues;
 
  	/* Create shared ring, alloc event channel -- for each queue */
  	for (i = 0; i < info->num_queues; ++i) {
@@ -1800,49 +1905,36 @@ static int talk_to_netback(struct xenbus_device *dev,
  	}
 
  again:
-	queue = &info->queues[0]; /* Use first queue only */
-
  	err = xenbus_transaction_start(&xbt);
  	if (err) {
  		xenbus_dev_fatal(dev, err, "starting transaction");
  		goto destroy_ring;
  	}
 
-	err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref", "%u",
-			    queue->tx_ring_ref);
-	if (err) {
-		message = "writing tx ring-ref";
-		goto abort_transaction;
-	}
-	err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref", "%u",
-			    queue->rx_ring_ref);
-	if (err) {
-		message = "writing rx ring-ref";
-		goto abort_transaction;
+	if (info->num_queues == 1) {
+		err = write_queue_xenstore_keys(&info->queues[0], &xbt, 0); /* flat */
+		if (err)
+			goto abort_transaction_no_dev_fatal;
  	}
-
-	if (queue->tx_evtchn == queue->rx_evtchn) {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel", "%u", queue->tx_evtchn);
+	else {
+		/* Write the number of queues */
+		err = xenbus_printf(xbt, dev->nodename, "multi-queue-num-queues",
+				"%u", info->num_queues);
  		if (err) {
-			message = "writing event-channel";
-			goto abort_transaction;
+			message = "writing multi-queue-num-queues";
+			goto abort_transaction_no_dev_fatal;
  		}
-	} else {
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-tx", "%u", queue->tx_evtchn);
-		if (err) {
-			message = "writing event-channel-tx";
-			goto abort_transaction;
-		}
-		err = xenbus_printf(xbt, dev->nodename,
-				    "event-channel-rx", "%u", queue->rx_evtchn);
-		if (err) {
-			message = "writing event-channel-rx";
-			goto abort_transaction;
+
+		/* Write the keys for each queue */
+		for (i = 0; i < info->num_queues; ++i) {
+			queue = &info->queues[i];
+			err = write_queue_xenstore_keys(queue, &xbt, 1); /* hierarchical */
+			if (err)
+				goto abort_transaction_no_dev_fatal;
  		}
  	}
 
+	/* The remaining keys are not queue-specific */
  	err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
  			    1);
  	if (err) {
@@ -1879,8 +1971,9 @@ again:
  	return 0;
 
   abort_transaction:
-	xenbus_transaction_end(xbt, 1);
  	xenbus_dev_fatal(dev, err, "%s", message);
+abort_transaction_no_dev_fatal:
+	xenbus_transaction_end(xbt, 1);
   destroy_ring:
  	xennet_disconnect_backend(info);
  	kfree(info->queues);
--

1.7.10.4

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

#27 lore raw
In reply to Andrew J. Bennieston

Cool! Finally!

Quoted 31 lines · Andrew J. Bennieston

This patch series implements multiple transmit and receive queues (i.e. multiple shared rings) for the xen virtual network interfaces.

The series is split up as follows:
- Patches 1 and 3 factor out the queue-specific data for netback and netfront respectively, and modify the rest of the code to use these as appropriate.
- Patches 2 and 4 introduce new XenStore keys to negotiate and use multiple shared rings and event channels, and code to connect these as appropriate.

All other transmit and receive processing remains unchanged, i.e. there is a kthread per queue and a NAPI context per queue.

The performance of these patches has been analysed in detail, with results available at:

http://wiki.xenproject.org/wiki/Xen-netback_and_xen-netfront_multi-queue_performance_testing

To summarise:
* Using multiple queues allows a VM to transmit at line rate on a 10 Gbit/s NIC, compared with a maximum aggregate throughput of 6 Gbit/s with a single queue.
* For intra-host VM--VM traffic, eight queues provide 171% of the throughput of a single queue; almost 12 Gbit/s instead of 6 Gbit/s.
* There is a corresponding increase in total CPU usage, i.e. this is a scaling out over available resources, not an efficiency improvement.
* Results depend on the availability of sufficient CPUs, as well as the distribution of interrupts and the distribution of TCP streams across the queues.

Quoted 11 lines

One open issue is how to deal with the tx_credit data for rate limiting. This used to exist on a per-VIF basis, and these patches move it to per-queue to avoid contention on concurrent access to the tx_credit data from multiple threads. This has the side effect of breaking the tx_credit accounting across the VIF as a whole. I cannot see a situation in which people would want to use both rate limiting and a high-performance multi-queue mode, but if this is problematic then it can be brought back to the VIF level, with appropriate protection. Obviously, it continues to work identically in the case where there is only one queue.

I would go for per-queue limit at the stage as it simplifies things and keep you focus on core functionality.

Wei.

Quoted 16 lines

Queue selection is currently achieved via an L4 hash on the packet (i.e. TCP src/dst port, IP src/dst address) and is not negotiated between the frontend and backend, since only one option exists. Future patches to support other frontends (particularly Windows) will need to add some capability to negotiate not only the hash algorithm selection, but also allow the frontend to specify some parameters to this.

Queue-specific XenStore entries for ring references and event channels are stored hierarchically, i.e. under .../queue-N/... where N varies from 0 to one less than the requested number of queues (inclusive). If only one queue is requested, it falls back to the flat structure where the ring references and event channels are written at the same level as other vif information.

--
Andrew J. Bennieston

#28 lore raw
Quoted 46 lines · Wei Liu

Cool! Finally!

Quoted 31 lines · Andrew J. Bennieston

This patch series implements multiple transmit and receive queues (i.e. multiple shared rings) for the xen virtual network interfaces.

The series is split up as follows:
- Patches 1 and 3 factor out the queue-specific data for netback and netfront respectively, and modify the rest of the code to use these as appropriate.
- Patches 2 and 4 introduce new XenStore keys to negotiate and use multiple shared rings and event channels, and code to connect these as appropriate.

All other transmit and receive processing remains unchanged, i.e. there is a kthread per queue and a NAPI context per queue.

The performance of these patches has been analysed in detail, with results available at:

http://wiki.xenproject.org/wiki/Xen-netback_and_xen-netfront_multi-queue_performance_testing

To summarise:
* Using multiple queues allows a VM to transmit at line rate on a 10 Gbit/s NIC, compared with a maximum aggregate throughput of 6 Gbit/s with a single queue.
* For intra-host VM--VM traffic, eight queues provide 171% of the throughput of a single queue; almost 12 Gbit/s instead of 6 Gbit/s.
* There is a corresponding increase in total CPU usage, i.e. this is a scaling out over available resources, not an efficiency improvement.
* Results depend on the availability of sufficient CPUs, as well as the distribution of interrupts and the distribution of TCP streams across the queues.

Quoted 11 lines

One open issue is how to deal with the tx_credit data for rate limiting. This used to exist on a per-VIF basis, and these patches move it to per-queue to avoid contention on concurrent access to the tx_credit data from multiple threads. This has the side effect of breaking the tx_credit accounting across the VIF as a whole. I cannot see a situation in which people would want to use both rate limiting and a high-performance multi-queue mode, but if this is problematic then it can be brought back to the VIF level, with appropriate protection. Obviously, it continues to work identically in the case where there is only one queue.

Quoted 2 lines

I would go for per-queue limit at the stage as it simplifies things and keep you focus on core functionality.

Agreed - that's how I saw it at the time; it seems unlikely that people would want to use both features, anyway.

Andrew.

Quoted 19 lines

Wei.

Quoted 16 lines

Queue selection is currently achieved via an L4 hash on the packet (i.e. TCP src/dst port, IP src/dst address) and is not negotiated between the frontend and backend, since only one option exists. Future patches to support other frontends (particularly Windows) will need to add some capability to negotiate not only the hash algorithm selection, but also allow the frontend to specify some parameters to this.

Queue-specific XenStore entries for ring references and event channels are stored hierarchically, i.e. under .../queue-N/... where N varies from 0 to one less than the requested number of queues (inclusive). If only one queue is requested, it falls back to the flat structure where the ring references and event channels are written at the same level as other vif information.

--
Andrew J. Bennieston

#29 lore raw
In reply to Andrew J. Bennieston
Quoted 19 lines

-----Original Message-----
From: Andrew J. Bennieston [mailto:[email protected]]
Sent: 15 January 2014 16:23
To: [email protected]
Cc: Ian Campbell; Wei Liu; Paul Durrant
Subject: [PATCH RFC 0/4]: xen-net{back,front}: Multiple transmit and receive queues

This patch series implements multiple transmit and receive queues (i.e. multiple shared rings) for the xen virtual network interfaces.

The series is split up as follows:
- Patches 1 and 3 factor out the queue-specific data for netback and netfront respectively, and modify the rest of the code to use these as appropriate.
- Patches 2 and 4 introduce new XenStore keys to negotiate and use multiple shared rings and event channels, and code to connect these as appropriate.

Quoted 9 lines

All other transmit and receive processing remains unchanged, i.e. there is a kthread per queue and a NAPI context per queue.

The performance of these patches has been analysed in detail, with results available at:

http://wiki.xenproject.org/wiki/Xen-netback_and_xen-netfront_multi-
queue_performance_testing

Nice numbers!

Quoted 23 lines

To summarise:
* Using multiple queues allows a VM to transmit at line rate on a 10 Gbit/s NIC, compared with a maximum aggregate throughput of 6 Gbit/s with a single queue.
* For intra-host VM--VM traffic, eight queues provide 171% of the throughput of a single queue; almost 12 Gbit/s instead of 6 Gbit/s.
* There is a corresponding increase in total CPU usage, i.e. this is a scaling out over available resources, not an efficiency improvement.
* Results depend on the availability of sufficient CPUs, as well as the distribution of interrupts and the distribution of TCP streams across the queues.

One open issue is how to deal with the tx_credit data for rate limiting. This used to exist on a per-VIF basis, and these patches move it to per-queue to avoid contention on concurrent access to the tx_credit data from multiple threads. This has the side effect of breaking the tx_credit accounting across the VIF as a whole. I cannot see a situation in which people would want to use both rate limiting and a high-performance multi-queue mode, but if this is problematic then it can be brought back to the VIF level, with appropriate protection. Obviously, it continues to work identically in the case where there is only one queue.

Quoted 7 lines

Queue selection is currently achieved via an L4 hash on the packet (i.e. TCP src/dst port, IP src/dst address) and is not negotiated between the frontend and backend, since only one option exists. Future patches to support other frontends (particularly Windows) will need to add some capability to negotiate not only the hash algorithm selection, but also allow the frontend to specify some parameters to this.

Yes, Windows RSS stipulates a Toeplitz hash and specifies a hash key and mapping table. There's further awkwardness in the need to pass the actual hash value to the frontend too - but we could use an 'extra' seg for that, analogous to passing the GSO mss value through.

Paul

Quoted 9 lines

Queue-specific XenStore entries for ring references and event channels are stored hierarchically, i.e. under .../queue-N/... where N varies from 0 to one less than the requested number of queues (inclusive). If only one queue is requested, it falls back to the flat structure where the ring references and event channels are written at the same level as other vif information.

--
Andrew J. Bennieston

#30 lore raw
Subject:   Re: [PATCH RFC 0/4]: xen-net{back,front}: Multiple transmit
and receive queues To:        Paul Durrant

<[email protected]>,"[email protected]"
<[email protected]> Cc: Ian Campbell
<[email protected]>,Wei Liu <[email protected]> Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=- On

Quoted 57 lines · Paul Durrant
Quoted 15 lines

-----Original Message----- From: Andrew J. Bennieston [mailto:[email protected]] Sent: 15 January 2014 16:23 To:
[email protected] Cc: Ian Campbell; Wei Liu; Paul Durrant Subject: [PATCH RFC 0/4]: xen-net{back,front}: Multiple transmit and receive queues

This patch series implements multiple transmit and receive queues (i.e. multiple shared rings) for the xen virtual network interfaces.

The series is split up as follows: - Patches 1 and 3 factor out the queue-specific data for netback and netfront respectively, and modify the rest of the code to use these as appropriate. - Patches 2 and 4 introduce new XenStore keys to negotiate and use multiple shared rings and event channels, and code to connect these as appropriate.

Quoted 9 lines

All other transmit and receive processing remains unchanged, i.e. there is a kthread per queue and a NAPI context per queue.

The performance of these patches has been analysed in detail, with results available at:

http://wiki.xenproject.org/wiki/Xen-netback_and_xen-netfront_multi-
queue_performance_testing

Nice numbers!

Quoted 21 lines

To summarise: * Using multiple queues allows a VM to transmit at line rate on a 10 Gbit/s NIC, compared with a maximum aggregate throughput of 6 Gbit/s with a single queue. * For intra-host VM--VM traffic, eight queues provide 171% of the throughput of a single queue; almost 12 Gbit/s instead of 6 Gbit/s. * There is a corresponding increase in total CPU usage, i.e. this is a scaling out over available resources, not an efficiency improvement. * Results depend on the availability of sufficient CPUs, as well as the distribution of interrupts and the distribution of TCP streams across the queues.

One open issue is how to deal with the tx_credit data for rate limiting. This used to exist on a per-VIF basis, and these patches move it to per-queue to avoid contention on concurrent access to the tx_credit data from multiple threads. This has the side effect of breaking the tx_credit accounting across the VIF as a whole. I cannot see a situation in which people would want to use both rate limiting and a high-performance multi-queue mode, but if this is problematic then it can be brought back to the VIF level, with appropriate protection. Obviously, it continues to work identically in the case where there is only one queue.

Quoted 8 lines

Queue selection is currently achieved via an L4 hash on the packet (i.e. TCP src/dst port, IP src/dst address) and is not negotiated between the frontend and backend, since only one option exists. Future patches to support other frontends (particularly Windows) will need to add some capability to negotiate not only the hash algorithm selection, but also allow the frontend to specify some parameters to this.

Quoted 4 lines

Yes, Windows RSS stipulates a Toeplitz hash and specifies a hash key and mapping table. There's further awkwardness in the need to pass the actual hash value to the frontend too - but we could use an 'extra' seg for that, analogous to passing the GSO mss value through.

Yes, I was hoping we might be able to play tricks like that when it came to implementing Toeplitz support.

Andrew

Quoted 11 lines

Paul

Quoted 8 lines

Queue-specific XenStore entries for ring references and event channels are stored hierarchically, i.e. under .../queue-N/... where N varies from 0 to one less than the requested number of queues (inclusive). If only one queue is requested, it falls back to the flat structure where the ring references and event channels are written at the same level as other vif information.

-- Andrew J. Bennieston