Skip to content

Commit 59ae9fc

Browse files
Zoltan Kissdavem330
authored andcommitted
xen-netback: Fix handling of skbs requiring too many slots
A recent commit (a02eb4 "xen-netback: worse-case estimate in xenvif_rx_action is underestimating") capped the slot estimation to MAX_SKB_FRAGS, but that triggers the next BUG_ON a few lines down, as the packet consumes more slots than estimated. This patch introduces full_coalesce on the skb callback buffer, which is used in start_new_rx_buffer() to decide whether netback needs coalescing more aggresively. By doing that, no packet should need more than (XEN_NETIF_MAX_TX_SIZE + 1) / PAGE_SIZE data slots (excluding the optional GSO slot, it doesn't carry data, therefore irrelevant in this case), as the provided buffers are fully utilized. Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com> Cc: Paul Durrant <paul.durrant@citrix.com> Cc: Wei Liu <wei.liu2@citrix.com> Cc: Ian Campbell <ian.campbell@citrix.com> Cc: David Vrabel <david.vrabel@citrix.com> Reviewed-by: Paul Durrant <paul.durrant@gmail.com> Acked-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c531692 commit 59ae9fc

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎drivers/net/xen-netback/netback.c‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ bool xenvif_rx_ring_slots_available(struct xenvif *vif, int needed)
163163
* adding 'size' bytes to a buffer which currently contains 'offset'
164164
* bytes.
165165
*/
166-
static bool start_new_rx_buffer(int offset, unsigned long size, int head)
166+
static bool start_new_rx_buffer(int offset, unsigned long size, int head,
167+
bool full_coalesce)
167168
{
168169
/* simple case: we have completely filled the current buffer. */
169170
if (offset == MAX_BUFFER_OFFSET)
@@ -175,6 +176,7 @@ static bool start_new_rx_buffer(int offset, unsigned long size, int head)
175176
* (i) this frag would fit completely in the next buffer
176177
* and (ii) there is already some data in the current buffer
177178
* and (iii) this is not the head buffer.
179+
* and (iv) there is no need to fully utilize the buffers
178180
*
179181
* Where:
180182
* - (i) stops us splitting a frag into two copies
@@ -185,14 +187,17 @@ static bool start_new_rx_buffer(int offset, unsigned long size, int head)
185187
* by (ii) but is explicitly checked because
186188
* netfront relies on the first buffer being
187189
* non-empty and can crash otherwise.
190+
* - (iv) is needed for skbs which can use up more than MAX_SKB_FRAGS
191+
* slot
188192
*
189193
* This means we will effectively linearise small
190194
* frags but do not needlessly split large buffers
191195
* into multiple copies tend to give large frags their
192196
* own buffers as before.
193197
*/
194198
BUG_ON(size > MAX_BUFFER_OFFSET);
195-
if ((offset + size > MAX_BUFFER_OFFSET) && offset && !head)
199+
if ((offset + size > MAX_BUFFER_OFFSET) && offset && !head &&
200+
!full_coalesce)
196201
return true;
197202

198203
return false;
@@ -227,6 +232,13 @@ static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif *vif,
227232
return meta;
228233
}
229234

235+
struct xenvif_rx_cb {
236+
int meta_slots_used;
237+
bool full_coalesce;
238+
};
239+
240+
#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb)
241+
230242
/*
231243
* Set up the grant operations for this fragment. If it's a flipping
232244
* interface, we also set up the unmap request from here.
@@ -261,7 +273,10 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
261273
if (bytes > size)
262274
bytes = size;
263275

264-
if (start_new_rx_buffer(npo->copy_off, bytes, *head)) {
276+
if (start_new_rx_buffer(npo->copy_off,
277+
bytes,
278+
*head,
279+
XENVIF_RX_CB(skb)->full_coalesce)) {
265280
/*
266281
* Netfront requires there to be some data in the head
267282
* buffer.
@@ -541,12 +556,6 @@ static void xenvif_add_frag_responses(struct xenvif *vif, int status,
541556
}
542557
}
543558

544-
struct xenvif_rx_cb {
545-
int meta_slots_used;
546-
};
547-
548-
#define XENVIF_RX_CB(skb) ((struct xenvif_rx_cb *)(skb)->cb)
549-
550559
void xenvif_kick_thread(struct xenvif *vif)
551560
{
552561
wake_up(&vif->wq);
@@ -602,10 +611,15 @@ static void xenvif_rx_action(struct xenvif *vif)
602611

603612
/* To avoid the estimate becoming too pessimal for some
604613
* frontends that limit posted rx requests, cap the estimate
605-
* at MAX_SKB_FRAGS.
614+
* at MAX_SKB_FRAGS. In this case netback will fully coalesce
615+
* the skb into the provided slots.
606616
*/
607-
if (max_slots_needed > MAX_SKB_FRAGS)
617+
if (max_slots_needed > MAX_SKB_FRAGS) {
608618
max_slots_needed = MAX_SKB_FRAGS;
619+
XENVIF_RX_CB(skb)->full_coalesce = true;
620+
} else {
621+
XENVIF_RX_CB(skb)->full_coalesce = false;
622+
}
609623

610624
/* We may need one more slot for GSO metadata */
611625
if (skb_is_gso(skb) &&

0 commit comments

Comments
 (0)