Skip to contentSkip to conversation

xen-netback: use skb to determine number of required guest Rx requests

PATCH In review David Vrabel 2 participants 7 messages Jan 14, 2016 – Jan 15, 2016

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

PATCH 1/1 xen-netback: use skb to determine number of required guest Rx requests

Using the MTU or GSO size to determine the number of required guest Rx requests for an skb was subtly broken since these value may change at runtime.

---
 drivers/net/xen-netback/netback.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/net/xen-netback/netback.c +9 -11
index 1049c34..61b97c3 100644
@@ -149,20 +149,19 @@ static inline pending_ring_idx_t pending_index(unsigned i)
 	return i & (MAX_PENDING_REQS-1);
 }
 
-static int xenvif_rx_ring_slots_needed(struct xenvif *vif)
-{
-	if (vif->gso_mask)
-		return DIV_ROUND_UP(vif->dev->gso_max_size, XEN_PAGE_SIZE) + 1;
-	else
-		return DIV_ROUND_UP(vif->dev->mtu, XEN_PAGE_SIZE);
-}
-
 static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue)
 {
 	RING_IDX prod, cons;
+	struct sk_buff *skb;
 	int needed;
 
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;
 
 	do {
 		prod = queue->rx.sring->req_prod;
@@ -2005,8 +2004,7 @@ static bool xenvif_rx_queue_ready(struct xenvif_queue *queue)
 
 static bool xenvif_have_rx_work(struct xenvif_queue *queue)
 {
-	return (!skb_queue_empty(&queue->rx_queue)
-		&& xenvif_rx_ring_slots_available(queue))
+	return xenvif_rx_ring_slots_available(queue)
 		|| (queue->vif->stall_timeout &&
 		    (xenvif_rx_queue_stalled(queue)
 		     || xenvif_rx_queue_ready(queue)))
Signature · 1 line
2.1.4
maintainer
#1 lore raw

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);

calculation doesn't cut it.

maintainer
#6 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);

calculation doesn't cut it.

#2 lore raw
In reply to David Miller
Quoted 15 lines · David Miller

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

Quoted 5 lines

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);

calculation doesn't cut it.

After 1650d5455bd2dc6b5ee134bd6fc1a3236c266b5b (xen-netback: always fully coalesce guest Rx packets) we always fully pack a packet into its guest Rx slots. Each slot has space for XEN_PAGE_SIZE bytes so this calculation for the number of slots is correct.

Shall I resend with a more description changelog?

David

#5 lore raw
In reply to David Miller
Quoted 15 lines · David Miller

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

Quoted 5 lines

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);

calculation doesn't cut it.

After 1650d5455bd2dc6b5ee134bd6fc1a3236c266b5b (xen-netback: always fully coalesce guest Rx packets) we always fully pack a packet into its guest Rx slots. Each slot has space for XEN_PAGE_SIZE bytes so this calculation for the number of slots is correct.

Shall I resend with a more description changelog?

David

maintainer
#3 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Fri, 15 Jan 2016 10:31:57 +0000

Quoted 20 lines · David Miller
Quoted 19 lines

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
Quoted 8 lines
Quoted 1 line

calculation doesn't cut it.

After 1650d5455bd2dc6b5ee134bd6fc1a3236c266b5b (xen-netback: always fully coalesce guest Rx packets) we always fully pack a packet into its guest Rx slots. Each slot has space for XEN_PAGE_SIZE bytes so this calculation for the number of slots is correct.

Shall I resend with a more description changelog?

Yeah that would help a lot.

maintainer
#4 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Fri, 15 Jan 2016 10:31:57 +0000

Quoted 20 lines · David Miller
Quoted 19 lines

From: David Vrabel <[email protected]>
Date: Thu, 14 Jan 2016 15:18:30 +0000

drivers/net/xen-netback/netback.c static inline pending_ring_idx_t pending_index(unsigned i) · line 164

Quoted 8 lines
drivers/net/xen-netback/netback.c +7 -1
-	needed = xenvif_rx_ring_slots_needed(queue->vif);
+	skb = skb_peek(&queue->rx_queue);
+	if (!skb)
+		return false;
+
+	needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
+	if (skb_is_gso(skb))
+		needed++;

If I am not mistaken, we moved away from this kind of test exactly because it is inaccurate and may under-estimate the needs.

It is possible for an N byte SKB to require N segments. Therefore, the:

	DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE);
Quoted 8 lines
Quoted 1 line

calculation doesn't cut it.

After 1650d5455bd2dc6b5ee134bd6fc1a3236c266b5b (xen-netback: always fully coalesce guest Rx packets) we always fully pack a packet into its guest Rx slots. Each slot has space for XEN_PAGE_SIZE bytes so this calculation for the number of slots is correct.

Shall I resend with a more description changelog?

Yeah that would help a lot.