aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netback/common.h
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/common.h
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/common.h')
-rw-r--r--drivers/net/xen-netback/common.h29
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 93ca77c129c3..c2642402b7a1 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -176,10 +176,9 @@ struct xenvif_queue { /* Per-queue data for xenvif */
176 char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */ 176 char rx_irq_name[IRQ_NAME_SIZE]; /* DEVNAME-qN-rx */
177 struct xen_netif_rx_back_ring rx; 177 struct xen_netif_rx_back_ring rx;
178 struct sk_buff_head rx_queue; 178 struct sk_buff_head rx_queue;
179 RING_IDX rx_last_skb_slots;
180 unsigned long status;
181 179
182 struct timer_list rx_stalled; 180 unsigned int rx_queue_max;
181 unsigned int rx_queue_len;
183 182
184 struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS]; 183 struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
185 184
@@ -199,18 +198,14 @@ struct xenvif_queue { /* Per-queue data for xenvif */
199 struct xenvif_stats stats; 198 struct xenvif_stats stats;
200}; 199};
201 200
201/* Maximum number of Rx slots a to-guest packet may use, including the
202 * slot needed for GSO meta-data.
203 */
204#define XEN_NETBK_RX_SLOTS_MAX (MAX_SKB_FRAGS + 1)
205
202enum state_bit_shift { 206enum state_bit_shift {
203 /* This bit marks that the vif is connected */ 207 /* This bit marks that the vif is connected */
204 VIF_STATUS_CONNECTED, 208 VIF_STATUS_CONNECTED,
205 /* This bit signals the RX thread that queuing was stopped (in
206 * start_xmit), and either the timer fired or an RX interrupt came
207 */
208 QUEUE_STATUS_RX_PURGE_EVENT,
209 /* This bit tells the interrupt handler that this queue was the reason
210 * for the carrier off, so it should kick the thread. Only queues which
211 * brought it down can turn on the carrier.
212 */
213 QUEUE_STATUS_RX_STALLED
214}; 209};
215 210
216struct xenvif { 211struct xenvif {
@@ -246,6 +241,14 @@ struct xenvif {
246 struct net_device *dev; 241 struct net_device *dev;
247}; 242};
248 243
244struct xenvif_rx_cb {
245 unsigned long expires;
246 int meta_slots_used;
247 bool full_coalesce;
248};
249
250#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb)
251
249static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif) 252static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
250{ 253{
251 return to_xenbus_device(vif->dev->dev.parent); 254 return to_xenbus_device(vif->dev->dev.parent);
@@ -291,6 +294,8 @@ void xenvif_kick_thread(struct xenvif_queue *queue);
291 294
292int xenvif_dealloc_kthread(void *data); 295int xenvif_dealloc_kthread(void *data);
293 296
297void xenvif_rx_queue_tail(struct xenvif_queue *queue, struct sk_buff *skb);
298
294/* Determine whether the needed number of slots (req) are available, 299/* Determine whether the needed number of slots (req) are available,
295 * and set req_event if not. 300 * and set req_event if not.
296 */ 301 */