aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netback/interface.c
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@citrix.com>2014-10-22 09:08:54 -0400
committerDavid S. Miller <davem@davemloft.net>2014-10-25 14:15:20 -0400
commitf48da8b14d04ca87ffcffe68829afd45f926ec6a (patch)
tree0311447e90c3bfd85d2177637031dc3d1e81a054 /drivers/net/xen-netback/interface.c
parentbc96f648df1bbc2729abbb84513cf4f64273a1f1 (diff)
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. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Reviewed-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/xen-netback/interface.c')
-rw-r--r--drivers/net/xen-netback/interface.c59
1 files changed, 11 insertions, 48 deletions
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index c6759b1ec18d..a134d52f55b4 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -43,6 +43,9 @@
43#define XENVIF_QUEUE_LENGTH 32 43#define XENVIF_QUEUE_LENGTH 32
44#define XENVIF_NAPI_WEIGHT 64 44#define XENVIF_NAPI_WEIGHT 64
45 45
46/* Number of bytes allowed on the internal guest Rx queue. */
47#define XENVIF_RX_QUEUE_BYTES (XEN_NETIF_RX_RING_SIZE/2 * PAGE_SIZE)
48
46/* This function is used to set SKBTX_DEV_ZEROCOPY as well as 49/* This function is used to set SKBTX_DEV_ZEROCOPY as well as
47 * increasing the inflight counter. We need to increase the inflight 50 * increasing the inflight counter. We need to increase the inflight
48 * counter because core driver calls into xenvif_zerocopy_callback 51 * counter because core driver calls into xenvif_zerocopy_callback
@@ -63,7 +66,8 @@ void xenvif_skb_zerocopy_complete(struct xenvif_queue *queue)
63int xenvif_schedulable(struct xenvif *vif) 66int xenvif_schedulable(struct xenvif *vif)
64{ 67{
65 return netif_running(vif->dev) && 68 return netif_running(vif->dev) &&
66 test_bit(VIF_STATUS_CONNECTED, &vif->status); 69 test_bit(VIF_STATUS_CONNECTED, &vif->status) &&
70 !vif->disabled;
67} 71}
68 72
69static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id) 73static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id)
@@ -104,16 +108,7 @@ int xenvif_poll(struct napi_struct *napi, int budget)
104static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id) 108static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
105{ 109{
106 struct xenvif_queue *queue = dev_id; 110 struct xenvif_queue *queue = dev_id;
107 struct netdev_queue *net_queue =
108 netdev_get_tx_queue(queue->vif->dev, queue->id);
109 111
110 /* QUEUE_STATUS_RX_PURGE_EVENT is only set if either QDisc was off OR
111 * the carrier went down and this queue was previously blocked
112 */
113 if (unlikely(netif_tx_queue_stopped(net_queue) ||
114 (!netif_carrier_ok(queue->vif->dev) &&
115 test_bit(QUEUE_STATUS_RX_STALLED, &queue->status))))
116 set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status);
117 xenvif_kick_thread(queue); 112 xenvif_kick_thread(queue);
118 113
119 return IRQ_HANDLED; 114 return IRQ_HANDLED;
@@ -141,24 +136,13 @@ void xenvif_wake_queue(struct xenvif_queue *queue)
141 netif_tx_wake_queue(netdev_get_tx_queue(dev, id)); 136 netif_tx_wake_queue(netdev_get_tx_queue(dev, id));
142} 137}
143 138
144/* Callback to wake the queue's thread and turn the carrier off on timeout */
145static void xenvif_rx_stalled(unsigned long data)
146{
147 struct xenvif_queue *queue = (struct xenvif_queue *)data;
148
149 if (xenvif_queue_stopped(queue)) {
150 set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status);
151 xenvif_kick_thread(queue);
152 }
153}
154
155static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev) 139static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
156{ 140{
157 struct xenvif *vif = netdev_priv(dev); 141 struct xenvif *vif = netdev_priv(dev);
158 struct xenvif_queue *queue = NULL; 142 struct xenvif_queue *queue = NULL;
159 unsigned int num_queues = vif->num_queues; 143 unsigned int num_queues = vif->num_queues;
160 u16 index; 144 u16 index;
161 int min_slots_needed; 145 struct xenvif_rx_cb *cb;
162 146
163 BUG_ON(skb->dev != dev); 147 BUG_ON(skb->dev != dev);
164 148
@@ -181,30 +165,10 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
181 !xenvif_schedulable(vif)) 165 !xenvif_schedulable(vif))
182 goto drop; 166 goto drop;
183 167
184 /* At best we'll need one slot for the header and one for each 168 cb = XENVIF_RX_CB(skb);
185 * frag. 169 cb->expires = jiffies + rx_drain_timeout_jiffies;
186 */
187 min_slots_needed = 1 + skb_shinfo(skb)->nr_frags;
188 170
189 /* If the skb is GSO then we'll also need an extra slot for the 171 xenvif_rx_queue_tail(queue, skb);
190 * metadata.
191 */
192 if (skb_is_gso(skb))
193 min_slots_needed++;
194
195 /* If the skb can't possibly fit in the remaining slots
196 * then turn off the queue to give the ring a chance to
197 * drain.
198 */
199 if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) {
200 queue->rx_stalled.function = xenvif_rx_stalled;
201 queue->rx_stalled.data = (unsigned long)queue;
202 netif_tx_stop_queue(netdev_get_tx_queue(dev, queue->id));
203 mod_timer(&queue->rx_stalled,
204 jiffies + rx_drain_timeout_jiffies);
205 }
206
207 skb_queue_tail(&queue->rx_queue, skb);
208 xenvif_kick_thread(queue); 172 xenvif_kick_thread(queue);
209 173
210 return NETDEV_TX_OK; 174 return NETDEV_TX_OK;
@@ -498,6 +462,8 @@ int xenvif_init_queue(struct xenvif_queue *queue)
498 init_timer(&queue->credit_timeout); 462 init_timer(&queue->credit_timeout);
499 queue->credit_window_start = get_jiffies_64(); 463 queue->credit_window_start = get_jiffies_64();
500 464
465 queue->rx_queue_max = XENVIF_RX_QUEUE_BYTES;
466
501 skb_queue_head_init(&queue->rx_queue); 467 skb_queue_head_init(&queue->rx_queue);
502 skb_queue_head_init(&queue->tx_queue); 468 skb_queue_head_init(&queue->tx_queue);
503 469
@@ -529,8 +495,6 @@ int xenvif_init_queue(struct xenvif_queue *queue)
529 queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE; 495 queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE;
530 } 496 }
531 497
532 init_timer(&queue->rx_stalled);
533
534 return 0; 498 return 0;
535} 499}
536 500
@@ -664,7 +628,6 @@ void xenvif_disconnect(struct xenvif *vif)
664 netif_napi_del(&queue->napi); 628 netif_napi_del(&queue->napi);
665 629
666 if (queue->task) { 630 if (queue->task) {
667 del_timer_sync(&queue->rx_stalled);
668 kthread_stop(queue->task); 631 kthread_stop(queue->task);
669 queue->task = NULL; 632 queue->task = NULL;
670 } 633 }