Skip to contentSkip to conversation

xen-netback: guest Rx queue drain and stall fixes

PATCH In review David Vrabel 3 participants 23 messages Oct 22, 2014 – Oct 25, 2014

Subsystems (3)
lore
Share & tools
lore
#17 lore raw

PATCH 3/3 xen-netback: reintroduce guest Rx stall detection

In reply to David Vrabel

If a frontend not receiving packets it is useful to detect this and turn off the carrier so packets are dropped early instead of being queued and drained when they expire.

A to-guest queue is stalled if it doesn't have enough free slots for a an extended period of time (default 60 s).

If at least one queue is stalled, the carrier is turned off (in the expectation that the other queues will soon stall as well). The carrier is only turned on once all queues are ready.

When the frontend connects, all the queues start in the stalled state and only become ready once the frontend queues enough Rx requests.

---
 drivers/net/xen-netback/common.h    |    5 +++
 drivers/net/xen-netback/interface.c |    5 ++-
 drivers/net/xen-netback/netback.c   |   76 +++++++++++++++++++++++++++++++++++
 drivers/net/xen-netback/xenbus.c    |    1 +
 4 files changed, 86 insertions(+), 1 deletion(-)
drivers/net/xen-netback/common.h +5 -0
index c264240..083ecc9 100644
@@ -179,6 +179,8 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 
 	unsigned int rx_queue_max;
 	unsigned int rx_queue_len;
+	unsigned long last_rx_time;
+	bool stalled;
 
 	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
 
@@ -232,6 +234,9 @@ struct xenvif {
 	/* Queues */
 	struct xenvif_queue *queues;
 	unsigned int num_queues; /* active queues, resource allocated */
+	unsigned int stalled_queues;
+
+	spinlock_t lock;
 
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *xenvif_dbg_root;
drivers/net/xen-netback/interface.c +4 -1
index a134d52..895fe84 100644
@@ -419,6 +419,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	vif->queues = NULL;
 	vif->num_queues = 0;
 
+	spin_lock_init(&vif->lock);
+
 	dev->netdev_ops	= &xenvif_netdev_ops;
 	dev->hw_features = NETIF_F_SG |
 		NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
@@ -505,7 +507,6 @@ void xenvif_carrier_on(struct xenvif *vif)
 		dev_set_mtu(vif->dev, ETH_DATA_LEN);
 	netdev_update_features(vif->dev);
 	set_bit(VIF_STATUS_CONNECTED, &vif->status);
-	netif_carrier_on(vif->dev);
 	if (netif_running(vif->dev))
 		xenvif_up(vif);
 	rtnl_unlock();
@@ -565,6 +566,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		disable_irq(queue->rx_irq);
 	}
 
+	queue->stalled = true;
+
 	task = kthread_create(xenvif_kthread_guest_rx,
 			      (void *)queue, "%s-guest-rx", queue->name);
 	if (IS_ERR(task)) {
drivers/net/xen-netback/netback.c +76 -0

110 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +1 -0
index 96a754d..4e56a27 100644
@@ -711,6 +711,7 @@ static void connect(struct backend_info *be)
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
 	be->vif->num_queues = requested_num_queues;
+	be->vif->stalled_queues = requested_num_queues;
 
 	for (queue_index = 0; queue_index < requested_num_queues; ++queue_index) {
 		queue = &be->vif->queues[queue_index];
Signature · 1 line
1.7.10.4
#0 lore raw

cover xen-netback: guest Rx queue drain and stall fixes

This series fixes two critical xen-netback bugs.

1. Netback may consume all of host memory by queuing an unlimited number of skb on the internal guest Rx queue. This behaviour is guest triggerable.

2. Carrier flapping under high traffic rates which reduces performance.

The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode.

David

#13 lore raw

PATCH 2/3 xen-netback: fix unlimited guest Rx internal queue and carrier flapping

Netback needs to discard old to-guest skb's (guest Rx queue drain) and it needs detect guest Rx stalls (to disable the carrier so packets are discarded earlier), but the current implementation is very broken.

1. The check in hard_start_xmit of the slot availability did not consider the number of packets that were already in the guest Rx queue. This could allow the queue to grow without bound.

The guest stops consuming packets and the ring was allowed to fill leaving S slot free. Netback queues a packet requiring more than S slots (ensuring that the ring stays with S slots free). Netback queue indefinately packets provided that then require S or fewer slots.

2. The Rx stall detection is not triggered in this case since the (host) Tx queue is not stopped.

3. If the Tx queue is stopped and a guest Rx interrupt occurs, netback will consider this an Rx purge event which may result in it taking the carrier down unnecessarily. It also considers a queue with only 1 slot free as unstalled (even though the next packet might not fit in this).

The internal guest Rx queue is limited by a byte length (to 512 Kib, enough for half the ring). The (host) Tx queue is stopped and started based on this limit. This sets an upper bound on the amount of memory used by packets on the internal queue.

This allows the estimatation of the number of slots for an skb to be removed (it wasn't a very good estimate anyway). Instead, the guest Rx thread just waits for enough free slots for a maximum sized packet.

skbs queued on the internal queue have an 'expires' time (set to the current time plus the drain timeout). The guest Rx thread will detect when the skb at the head of the queue has expired and discard expired skbs. This sets a clear upper bound on the length of time an skb can be queued for. For a guest being destroyed the maximum time needed to wait for all the packets it sent to be dropped is still the drain timeout (10 s) since it will not be sending new packets.

Rx stall detection is reintroduced in a later commit.

---
 drivers/net/xen-netback/common.h    |   29 +++--
 drivers/net/xen-netback/interface.c |   59 ++-------
 drivers/net/xen-netback/netback.c   |  243 ++++++++++++++++++-----------------
 drivers/net/xen-netback/xenbus.c    |    8 ++
 4 files changed, 161 insertions(+), 178 deletions(-)
drivers/net/xen-netback/common.h +17 -12
index 93ca77c..c264240 100644
@@ -176,10 +176,9 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */
 	struct xen_netif_rx_back_ring rx;
 	struct sk_buff_head rx_queue;
-	RING_IDX rx_last_skb_slots;
-	unsigned long status;
 
-	struct timer_list rx_stalled;
+	unsigned int rx_queue_max;
+	unsigned int rx_queue_len;
 
 	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
 
@@ -199,18 +198,14 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	struct xenvif_stats stats;
 };
 
+/* Maximum number of Rx slots a to-guest packet may use, including the
+ * slot needed for GSO meta-data.
+ */
+#define XEN_NETBK_RX_SLOTS_MAX (MAX_SKB_FRAGS + 1)
+
 enum state_bit_shift {
 	/* This bit marks that the vif is connected */
 	VIF_STATUS_CONNECTED,
-	/* This bit signals the RX thread that queuing was stopped (in
-	 * start_xmit), and either the timer fired or an RX interrupt came
-	 */
-	QUEUE_STATUS_RX_PURGE_EVENT,
-	/* This bit tells the interrupt handler that this queue was the reason
-	 * for the carrier off, so it should kick the thread. Only queues which
-	 * brought it down can turn on the carrier.
-	 */
-	QUEUE_STATUS_RX_STALLED
 };
 
 struct xenvif {
@@ -246,6 +241,14 @@ struct xenvif {
 	struct net_device *dev;
 };
 
+struct xenvif_rx_cb {
+	unsigned long expires;
+	int meta_slots_used;
+	bool full_coalesce;
+};
+
+#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb)
+
 static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
 {
 	return to_xenbus_device(vif->dev->dev.parent);
@@ -291,6 +294,8 @@ void xenvif_kick_thread(struct xenvif_queue *queue);
 
 int xenvif_dealloc_kthread(void *data);
 
+void xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb);
+
 /* Determine whether the needed number of slots (req) are available,
  * and set req_event if not.
  */
drivers/net/xen-netback/interface.c +11 -48

115 lines not on this page · raw message

drivers/net/xen-netback/netback.c +125 -118

320 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +8 -0
index 9060857..96a754d 100644
@@ -52,6 +52,7 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v)
 	struct xenvif_queue *queue = m->private;
 	struct xen_netif_tx_back_ring *tx_ring = &queue->tx;
 	struct xen_netif_rx_back_ring *rx_ring = &queue->rx;
+	struct netdev_queue *dev_queue;
 
 	if (tx_ring->sring) {
 		struct xen_netif_tx_sring *sring = tx_ring->sring;
@@ -112,6 +113,13 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v)
 		   queue->credit_timeout.expires,
 		   jiffies);
 
+	dev_queue = netdev_get_tx_queue(queue->vif->dev, queue->id);
+
+	seq_printf(m, "\nRx internal queue: len %u max %u pkts %u %s\n",
+		   queue->rx_queue_len, queue->rx_queue_max,
+		   skb_queue_len(&queue->rx_queue),
+		   netif_tx_queue_stopped(dev_queue) ? "stopped" : "running");
+
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

---
 drivers/net/xen-netback/common.h    |    5 -----
 drivers/net/xen-netback/interface.c |   12 +-----------
 drivers/net/xen-netback/xenbus.c    |   13 ++++---------
 3 files changed, 5 insertions(+), 25 deletions(-)
drivers/net/xen-netback/common.h +0 -5
index d4eb8d2..93ca77c 100644
@@ -228,9 +228,6 @@ struct xenvif {
 	u8 ip_csum:1;
 	u8 ipv6_csum:1;
 
-	/* Internal feature information. */
-	u8 can_queue:1;	    /* can queue packets for receiver? */
-
 	/* Is this interface disabled? True when backend discovers
 	 * frontend is rogue.
 	 */
@@ -272,8 +269,6 @@ void xenvif_xenbus_fini(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
-int xenvif_must_stop_queue(struct xenvif_queue *queue);
-
 int xenvif_queue_stopped(struct xenvif_queue *queue);
 void xenvif_wake_queue(struct xenvif_queue *queue);
 
drivers/net/xen-netback/interface.c +1 -11
index f379689..c6759b1 100644
@@ -60,16 +60,6 @@ void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue)
 	atomic_dec(&queue->inflight_packets);
 }
 
-static inline void xenvif_stop_queue(struct xenvif_queue *queue)
-{
-	struct net_device *dev = queue->vif->dev;
-
-	if (!queue->vif->can_queue)
-		return;
-
-	netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id));
-}
-
 int xenvif_schedulable(struct xenvif *vif)
 {
 	return netif_running(vif->dev) &&
@@ -209,7 +199,7 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) {
 		queue->rx_stalled.function = xenvif_rx_stalled;
 		queue->rx_stalled.data = (unsigned long)queue;
-		xenvif_stop_queue(queue);
+		netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id));
 		mod_timer(&queue->rx_stalled,
 			  jiffies + rx_drain_timeout_jiffies);
 	}
drivers/net/xen-netback/xenbus.c +4 -9
index 8079c31..9060857 100644
@@ -873,15 +873,10 @@ static int read_xenbus_vif_flags(struct backend_info *be)
 	if (!rx_copy)
 		return -EOPNOTSUPP;
 
-	if (vif->dev->tx_queue_len != 0) {
-		if (xenbus_scanf(XBT_NIL, dev->otherend,
-				 "feature-rx-notify", "%d", &val) < 0)
-			val = 0;
-		if (val)
-			vif->can_queue = 1;
-		else
-			/* Must be non-zero for pfifo_fast to work. */
-			vif->dev->tx_queue_len = 1;
+	if (xenbus_scanf(XBT_NIL, dev->otherend,
+			 "feature-rx-notify", "%d", &val) < 0 || val == 0) {
+		xenbus_dev_fatal(dev, -EINVAL, "feature-rx-notify is mandatory");
+		return -EINVAL;
 	}
 
 	if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
Signature · 1 line
1.7.10.4
#20 lore raw

PATCH 3/3 xen-netback: reintroduce guest Rx stall detection

In reply to David Vrabel

If a frontend not receiving packets it is useful to detect this and turn off the carrier so packets are dropped early instead of being queued and drained when they expire.

A to-guest queue is stalled if it doesn't have enough free slots for a an extended period of time (default 60 s).

If at least one queue is stalled, the carrier is turned off (in the expectation that the other queues will soon stall as well). The carrier is only turned on once all queues are ready.

When the frontend connects, all the queues start in the stalled state and only become ready once the frontend queues enough Rx requests.

---
 drivers/net/xen-netback/common.h    |    5 +++
 drivers/net/xen-netback/interface.c |    5 ++-
 drivers/net/xen-netback/netback.c   |   76 +++++++++++++++++++++++++++++++++++
 drivers/net/xen-netback/xenbus.c    |    1 +
 4 files changed, 86 insertions(+), 1 deletion(-)
drivers/net/xen-netback/common.h +5 -0
index c264240..083ecc9 100644
@@ -179,6 +179,8 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 
 	unsigned int rx_queue_max;
 	unsigned int rx_queue_len;
+	unsigned long last_rx_time;
+	bool stalled;
 
 	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
 
@@ -232,6 +234,9 @@ struct xenvif {
 	/* Queues */
 	struct xenvif_queue *queues;
 	unsigned int num_queues; /* active queues, resource allocated */
+	unsigned int stalled_queues;
+
+	spinlock_t lock;
 
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *xenvif_dbg_root;
drivers/net/xen-netback/interface.c +4 -1
index a134d52..895fe84 100644
@@ -419,6 +419,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
 	vif->queues = NULL;
 	vif->num_queues = 0;
 
+	spin_lock_init(&vif->lock);
+
 	dev->netdev_ops	= &xenvif_netdev_ops;
 	dev->hw_features = NETIF_F_SG |
 		NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
@@ -505,7 +507,6 @@ void xenvif_carrier_on(struct xenvif *vif)
 		dev_set_mtu(vif->dev, ETH_DATA_LEN);
 	netdev_update_features(vif->dev);
 	set_bit(VIF_STATUS_CONNECTED, &vif->status);
-	netif_carrier_on(vif->dev);
 	if (netif_running(vif->dev))
 		xenvif_up(vif);
 	rtnl_unlock();
@@ -565,6 +566,8 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		disable_irq(queue->rx_irq);
 	}
 
+	queue->stalled = true;
+
 	task = kthread_create(xenvif_kthread_guest_rx,
 			      (void *)queue, "%s-guest-rx", queue->name);
 	if (IS_ERR(task)) {
drivers/net/xen-netback/netback.c +76 -0

110 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +1 -0
index 96a754d..4e56a27 100644
@@ -711,6 +711,7 @@ static void connect(struct backend_info *be)
 	be->vif->queues = vzalloc(requested_num_queues *
 				  sizeof(struct xenvif_queue));
 	be->vif->num_queues = requested_num_queues;
+	be->vif->stalled_queues = requested_num_queues;
 
 	for (queue_index = 0; queue_index < requested_num_queues; ++queue_index) {
 		queue = &be->vif->queues[queue_index];
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 1/3 xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

---
 drivers/net/xen-netback/common.h    |    5 -----
 drivers/net/xen-netback/interface.c |   12 +-----------
 drivers/net/xen-netback/xenbus.c    |   13 ++++---------
 3 files changed, 5 insertions(+), 25 deletions(-)
drivers/net/xen-netback/common.h +0 -5
index d4eb8d2..93ca77c 100644
@@ -228,9 +228,6 @@ struct xenvif {
 	u8 ip_csum:1;
 	u8 ipv6_csum:1;
 
-	/* Internal feature information. */
-	u8 can_queue:1;	    /* can queue packets for receiver? */
-
 	/* Is this interface disabled? True when backend discovers
 	 * frontend is rogue.
 	 */
@@ -272,8 +269,6 @@ void xenvif_xenbus_fini(void);
 
 int xenvif_schedulable(struct xenvif *vif);
 
-int xenvif_must_stop_queue(struct xenvif_queue *queue);
-
 int xenvif_queue_stopped(struct xenvif_queue *queue);
 void xenvif_wake_queue(struct xenvif_queue *queue);
 
drivers/net/xen-netback/interface.c +1 -11
index f379689..c6759b1 100644
@@ -60,16 +60,6 @@ void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue)
 	atomic_dec(&queue->inflight_packets);
 }
 
-static inline void xenvif_stop_queue(struct xenvif_queue *queue)
-{
-	struct net_device *dev = queue->vif->dev;
-
-	if (!queue->vif->can_queue)
-		return;
-
-	netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id));
-}
-
 int xenvif_schedulable(struct xenvif *vif)
 {
 	return netif_running(vif->dev) &&
@@ -209,7 +199,7 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) {
 		queue->rx_stalled.function = xenvif_rx_stalled;
 		queue->rx_stalled.data = (unsigned long)queue;
-		xenvif_stop_queue(queue);
+		netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id));
 		mod_timer(&queue->rx_stalled,
 			  jiffies + rx_drain_timeout_jiffies);
 	}
drivers/net/xen-netback/xenbus.c +4 -9
index 8079c31..9060857 100644
@@ -873,15 +873,10 @@ static int read_xenbus_vif_flags(struct backend_info *be)
 	if (!rx_copy)
 		return -EOPNOTSUPP;
 
-	if (vif->dev->tx_queue_len != 0) {
-		if (xenbus_scanf(XBT_NIL, dev->otherend,
-				 "feature-rx-notify", "%d", &val) < 0)
-			val = 0;
-		if (val)
-			vif->can_queue = 1;
-		else
-			/* Must be non-zero for pfifo_fast to work. */
-			vif->dev->tx_queue_len = 1;
+	if (xenbus_scanf(XBT_NIL, dev->otherend,
+			 "feature-rx-notify", "%d", &val) < 0 || val == 0) {
+		xenbus_dev_fatal(dev, -EINVAL, "feature-rx-notify is mandatory");
+		return -EINVAL;
 	}
 
 	if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH 2/3 xen-netback: fix unlimited guest Rx internal queue and carrier flapping

In reply to David Vrabel

Netback needs to discard old to-guest skb's (guest Rx queue drain) and it needs detect guest Rx stalls (to disable the carrier so packets are discarded earlier), but the current implementation is very broken.

1. The check in hard_start_xmit of the slot availability did not consider the number of packets that were already in the guest Rx queue. This could allow the queue to grow without bound.

The guest stops consuming packets and the ring was allowed to fill leaving S slot free. Netback queues a packet requiring more than S slots (ensuring that the ring stays with S slots free). Netback queue indefinately packets provided that then require S or fewer slots.

2. The Rx stall detection is not triggered in this case since the (host) Tx queue is not stopped.

3. If the Tx queue is stopped and a guest Rx interrupt occurs, netback will consider this an Rx purge event which may result in it taking the carrier down unnecessarily. It also considers a queue with only 1 slot free as unstalled (even though the next packet might not fit in this).

The internal guest Rx queue is limited by a byte length (to 512 Kib, enough for half the ring). The (host) Tx queue is stopped and started based on this limit. This sets an upper bound on the amount of memory used by packets on the internal queue.

This allows the estimatation of the number of slots for an skb to be removed (it wasn't a very good estimate anyway). Instead, the guest Rx thread just waits for enough free slots for a maximum sized packet.

skbs queued on the internal queue have an 'expires' time (set to the current time plus the drain timeout). The guest Rx thread will detect when the skb at the head of the queue has expired and discard expired skbs. This sets a clear upper bound on the length of time an skb can be queued for. For a guest being destroyed the maximum time needed to wait for all the packets it sent to be dropped is still the drain timeout (10 s) since it will not be sending new packets.

Rx stall detection is reintroduced in a later commit.

---
 drivers/net/xen-netback/common.h    |   29 +++--
 drivers/net/xen-netback/interface.c |   59 ++-------
 drivers/net/xen-netback/netback.c   |  243 ++++++++++++++++++-----------------
 drivers/net/xen-netback/xenbus.c    |    8 ++
 4 files changed, 161 insertions(+), 178 deletions(-)
drivers/net/xen-netback/common.h +17 -12
index 93ca77c..c264240 100644
@@ -176,10 +176,9 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */
 	struct xen_netif_rx_back_ring rx;
 	struct sk_buff_head rx_queue;
-	RING_IDX rx_last_skb_slots;
-	unsigned long status;
 
-	struct timer_list rx_stalled;
+	unsigned int rx_queue_max;
+	unsigned int rx_queue_len;
 
 	struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
 
@@ -199,18 +198,14 @@ struct xenvif_queue { /* Per-queue data for xenvif */
 	struct xenvif_stats stats;
 };
 
+/* Maximum number of Rx slots a to-guest packet may use, including the
+ * slot needed for GSO meta-data.
+ */
+#define XEN_NETBK_RX_SLOTS_MAX (MAX_SKB_FRAGS + 1)
+
 enum state_bit_shift {
 	/* This bit marks that the vif is connected */
 	VIF_STATUS_CONNECTED,
-	/* This bit signals the RX thread that queuing was stopped (in
-	 * start_xmit), and either the timer fired or an RX interrupt came
-	 */
-	QUEUE_STATUS_RX_PURGE_EVENT,
-	/* This bit tells the interrupt handler that this queue was the reason
-	 * for the carrier off, so it should kick the thread. Only queues which
-	 * brought it down can turn on the carrier.
-	 */
-	QUEUE_STATUS_RX_STALLED
 };
 
 struct xenvif {
@@ -246,6 +241,14 @@ struct xenvif {
 	struct net_device *dev;
 };
 
+struct xenvif_rx_cb {
+	unsigned long expires;
+	int meta_slots_used;
+	bool full_coalesce;
+};
+
+#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb)
+
 static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
 {
 	return to_xenbus_device(vif->dev->dev.parent);
@@ -291,6 +294,8 @@ void xenvif_kick_thread(struct xenvif_queue *queue);
 
 int xenvif_dealloc_kthread(void *data);
 
+void xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb);
+
 /* Determine whether the needed number of slots (req) are available,
  * and set req_event if not.
  */
drivers/net/xen-netback/interface.c +11 -48

115 lines not on this page · raw message

drivers/net/xen-netback/netback.c +125 -118

320 lines not on this page · raw message

drivers/net/xen-netback/xenbus.c +8 -0
index 9060857..96a754d 100644
@@ -52,6 +52,7 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v)
 	struct xenvif_queue *queue = m->private;
 	struct xen_netif_tx_back_ring *tx_ring = &queue->tx;
 	struct xen_netif_rx_back_ring *rx_ring = &queue->rx;
+	struct netdev_queue *dev_queue;
 
 	if (tx_ring->sring) {
 		struct xen_netif_tx_sring *sring = tx_ring->sring;
@@ -112,6 +113,13 @@ static int xenvif_read_io_ring(struct seq_file *m, void *v)
 		   queue->credit_timeout.expires,
 		   jiffies);
 
+	dev_queue = netdev_get_tx_queue(queue->vif->dev, queue->id);
+
+	seq_printf(m, "\nRx internal queue: len %u max %u pkts %u %s\n",
+		   queue->rx_queue_len, queue->rx_queue_max,
+		   skb_queue_len(&queue->rx_queue),
+		   netif_tx_queue_stopped(dev_queue) ? "stopped" : "running");
+
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

Acked-by on v1 1/3
#11 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

#3 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Wei.

#10 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Wei.

#4 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 11 lines · Wei Liu
Quoted 10 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

Quoted 7 lines
Quoted 1 line

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

The other patches do not meet the stable kernel requirements (they're too long one thing).

David

#9 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 11 lines · Wei Liu
Quoted 10 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

Quoted 7 lines
Quoted 1 line

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

The other patches do not meet the stable kernel requirements (they're too long one thing).

David

Reviewed-by on v1 2/3
#14 lore raw

Re: [PATCH 2/3] xen-netback: fix unlimited guest Rx internal queue and carrier flapping

In reply to David Vrabel
Quoted 23 lines · David Vrabel

Netback needs to discard old to-guest skb's (guest Rx queue drain) and it needs detect guest Rx stalls (to disable the carrier so packets are discarded earlier), but the current implementation is very broken.

1. The check in hard_start_xmit of the slot availability did not consider the number of packets that were already in the guest Rx queue. This could allow the queue to grow without bound.

The guest stops consuming packets and the ring was allowed to fill leaving S slot free. Netback queues a packet requiring more than S slots (ensuring that the ring stays with S slots free). Netback queue indefinately packets provided that then require S or fewer slots.

2. The Rx stall detection is not triggered in this case since the (host) Tx queue is not stopped.

3. If the Tx queue is stopped and a guest Rx interrupt occurs, netback will consider this an Rx purge event which may result in it taking the carrier down unnecessarily. It also considers a queue with only 1 slot free as unstalled (even though the next packet might not fit in this).

Quoted 7 lines

The internal guest Rx queue is limited by a byte length (to 512 Kib, enough for half the ring). The (host) Tx queue is stopped and started based on this limit. This sets an upper bound on the amount of memory used by packets on the internal queue.

This allows the estimatation of the number of slots for an skb to be removed (it wasn't a very good estimate anyway). Instead, the guest

+1 for this.

Quoted 10 lines

Rx thread just waits for enough free slots for a maximum sized packet.

skbs queued on the internal queue have an 'expires' time (set to the current time plus the drain timeout). The guest Rx thread will detect when the skb at the head of the queue has expired and discard expired skbs. This sets a clear upper bound on the length of time an skb can be queued for. For a guest being destroyed the maximum time needed to wait for all the packets it sent to be dropped is still the drain timeout (10 s) since it will not be sending new packets.

Quoted 3 lines

Rx stall detection is reintroduced in a later commit.

Reviewed-by on v1 2/3
#15 lore raw

Re: [PATCH 2/3] xen-netback: fix unlimited guest Rx internal queue and carrier flapping

In reply to David Vrabel
Quoted 23 lines · David Vrabel

Netback needs to discard old to-guest skb's (guest Rx queue drain) and it needs detect guest Rx stalls (to disable the carrier so packets are discarded earlier), but the current implementation is very broken.

1. The check in hard_start_xmit of the slot availability did not consider the number of packets that were already in the guest Rx queue. This could allow the queue to grow without bound.

The guest stops consuming packets and the ring was allowed to fill leaving S slot free. Netback queues a packet requiring more than S slots (ensuring that the ring stays with S slots free). Netback queue indefinately packets provided that then require S or fewer slots.

2. The Rx stall detection is not triggered in this case since the (host) Tx queue is not stopped.

3. If the Tx queue is stopped and a guest Rx interrupt occurs, netback will consider this an Rx purge event which may result in it taking the carrier down unnecessarily. It also considers a queue with only 1 slot free as unstalled (even though the next packet might not fit in this).

Quoted 7 lines

The internal guest Rx queue is limited by a byte length (to 512 Kib, enough for half the ring). The (host) Tx queue is stopped and started based on this limit. This sets an upper bound on the amount of memory used by packets on the internal queue.

This allows the estimatation of the number of slots for an skb to be removed (it wasn't a very good estimate anyway). Instead, the guest

+1 for this.

Quoted 10 lines

Rx thread just waits for enough free slots for a maximum sized packet.

skbs queued on the internal queue have an 'expires' time (set to the current time plus the drain timeout). The guest Rx thread will detect when the skb at the head of the queue has expired and discard expired skbs. This sets a clear upper bound on the length of time an skb can be queued for. For a guest being destroyed the maximum time needed to wait for all the packets it sent to be dropped is still the drain timeout (10 s) since it will not be sending new packets.

Quoted 3 lines

Rx stall detection is reintroduced in a later commit.

#5 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel
Quoted 18 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Quoted 7 lines
Quoted 1 line

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

I saw that.

I think you should make it a little bit clearer.

The queue is not guaranteed to stop if we keep this feature.

Quoted 3 lines

The other patches do not meet the stable kernel requirements (they're too long one thing).

Does length matter? I surely had written long patch for stable.

Wei.

Quoted 1 line

David

#8 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to David Vrabel
Quoted 18 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Quoted 7 lines
Quoted 1 line

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

I saw that.

I think you should make it a little bit clearer.

The queue is not guaranteed to stop if we keep this feature.

Quoted 3 lines

The other patches do not meet the stable kernel requirements (they're too long one thing).

Does length matter? I surely had written long patch for stable.

Wei.

Quoted 1 line

David

Reviewed-by on v1 3/3
#18 lore raw

Re: [PATCH 3/3] xen-netback: reintroduce guest Rx stall detection

In reply to David Vrabel
Quoted 7 lines · David Vrabel

If a frontend not receiving packets it is useful to detect this and turn off the carrier so packets are dropped early instead of being queued and drained when they expire.

A to-guest queue is stalled if it doesn't have enough free slots for a an extended period of time (default 60 s).

Quoted 8 lines

If at least one queue is stalled, the carrier is turned off (in the expectation that the other queues will soon stall as well). The carrier is only turned on once all queues are ready.

When the frontend connects, all the queues start in the stalled state and only become ready once the frontend queues enough Rx requests.

Reviewed-by on v1 3/3
#19 lore raw

Re: [PATCH 3/3] xen-netback: reintroduce guest Rx stall detection

In reply to David Vrabel
Quoted 7 lines · David Vrabel

If a frontend not receiving packets it is useful to detect this and turn off the carrier so packets are dropped early instead of being queued and drained when they expire.

A to-guest queue is stalled if it doesn't have enough free slots for a an extended period of time (default 60 s).

Quoted 8 lines

If at least one queue is stalled, the carrier is turned off (in the expectation that the other queues will soon stall as well). The carrier is only turned on once all queues are ready.

When the frontend connects, all the queues start in the stalled state and only become ready once the frontend queues enough Rx requests.

#6 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 27 lines · Wei Liu
Quoted 18 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Quoted 7 lines
Quoted 1 line

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

Quoted 3 lines

I saw that.

I think you should make it a little bit clearer.

I'm not sure how I can make this any clearer. Perhaps you should wander over to my desk to discuss this in person?

Quoted 9 lines

The queue is not guaranteed to stop if we keep this feature.

Quoted 3 lines

The other patches do not meet the stable kernel requirements (they're too long one thing).

Does length matter? I surely had written long patch for stable.

From Documentation/stable_kernel_rules.txt:

"- It cannot be bigger than 100 lines, with context."

David

#7 lore raw

Re: [PATCH 1/3] xen-netback: make feature-rx-notify mandatory

In reply to Wei Liu
Quoted 27 lines · Wei Liu
Quoted 18 lines · David Vrabel
Quoted 16 lines · Wei Liu
Quoted 11 lines · Wei Liu
Quoted 8 lines · David Vrabel

Frontends that do not provide feature-rx-notify may stall because netback depends on the notification from frontend to wake the guest Rx thread (even if can_queue is false).

This could be fixed but feature-rx-notify was introduced in 2006 and I am not aware of any frontends that do not implement this.

While I can understand this patch by itself, can you elaborate a little bit on how it affects later patches? Because what I'm thinking is that this patch is not for stable while other two should go to stable.

Quoted 7 lines
Quoted 1 line

From the cover letter:

"The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode."

Quoted 3 lines

I saw that.

I think you should make it a little bit clearer.

I'm not sure how I can make this any clearer. Perhaps you should wander over to my desk to discuss this in person?

Quoted 9 lines

The queue is not guaranteed to stop if we keep this feature.

Quoted 3 lines

The other patches do not meet the stable kernel requirements (they're too long one thing).

Does length matter? I surely had written long patch for stable.

From Documentation/stable_kernel_rules.txt:

"- It cannot be bigger than 100 lines, with context."

David

maintainer
#21 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Wed, 22 Oct 2014 14:08:52 +0100

Quoted 6 lines

This series fixes two critical xen-netback bugs.

1. Netback may consume all of host memory by queuing an unlimited number of skb on the internal guest Rx queue. This behaviour is guest triggerable.

Quoted 7 lines

2. Carrier flapping under high traffic rates which reduces performance.

The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode.

Series applied to net-next, thanks.

maintainer
#22 lore raw

From: David Miller <[email protected]>
Date: Sat, 25 Oct 2014 14:14:01 -0400 (EDT)

Quoted 12 lines

From: David Vrabel <[email protected]>
Date: Wed, 22 Oct 2014 14:08:52 +0100

Quoted 9 lines

This series fixes two critical xen-netback bugs.

1. Netback may consume all of host memory by queuing an unlimited number of skb on the internal guest Rx queue. This behaviour is guest triggerable.

2. Carrier flapping under high traffic rates which reduces performance.

Quoted 6 lines
Quoted 4 lines

The first patch is a prerequite. Removing support for frontends with feature-rx-notify makes it easier to reason about the correctness of netback since it no longer has to support this outdated and broken mode.

Series applied to net-next, thanks.

Correction, as these are critical bug fixes, I applied the series to 'net'.

Sorry for the confusion.