Skip to contentSkip to conversation

xen-netback: remove guest RX path dependence on MAX_SKB_FRAGS

RFC PATCH Superseded Wei Liu 2 participants 4 messages Jul 2, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

RFC PATCH 1/1 xen-netback: remove guest RX path dependence on MAX_SKB_FRAGS

This dependence is undesirable and logically incorrect.

It's undesirable because Xen network protocol should not depend on a OS-specific constant.

It's incorrect because the ring slots required doesn't correspond to the number of frags a SKB has (consider compound page frags).

This patch removes this dependence by correctly counting the ring slots required.

---
 drivers/net/xen-netback/interface.c |   12 +++++++---
 drivers/net/xen-netback/netback.c   |   41 +++++++++++++----------------------
 2 files changed, 24 insertions(+), 29 deletions(-)
drivers/net/xen-netback/interface.c +9 -3
index 087d2db..5c10e87 100644
@@ -96,18 +96,24 @@ static irqreturn_t xenvif_interrupt(int irq, void *dev_id)
 static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xenvif *vif = netdev_priv(dev);
+	unsigned int ring_slots_required;
 
 	BUG_ON(skb->dev != dev);
 
 	if (vif->netbk == NULL)
 		goto drop;
 
+	ring_slots_required = xen_netbk_count_skb_slots(vif, skb);
+
+	/* Reserve ring slots for the worst-case number of fragments. */
+	vif->rx_req_cons_peek += ring_slots_required;
+
 	/* Drop the packet if the target domain has no receive buffers. */
-	if (!xenvif_rx_schedulable(vif))
+	if (!xenvif_rx_schedulable(vif)) {
+		vif->rx_req_cons_peek -= ring_slots_required;
 		goto drop;
+	}
 
-	/* Reserve ring slots for the worst-case number of fragments. */
-	vif->rx_req_cons_peek += xen_netbk_count_skb_slots(vif, skb);
 	xenvif_get(vif);
 
 	if (vif->can_queue && xen_netbk_must_stop_queue(vif))
drivers/net/xen-netback/netback.c +15 -26

74 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Wei Liu

This dependence is undesirable and logically incorrect.

It's undesirable because Xen network protocol should not depend on a OS-specific constant.

But this is not making the protocol dependent upon the constant; at least in one case the check is merely used as a worst case estimation (there can't possibly be an skb with more than MAX_SKB_FRAGS, and hence having as many slots available implies that at least one more skb can be processed).

drivers/net/xen-netback/netback.c static void xen_netbk_kick_thread(struct xen_netbk *netbk) · line 297

Quoted 10 lines

int xen_netbk_rx_ring_full(struct xenvif *vif)
{

drivers/net/xen-netback/netback.c +3 -4
-	RING_IDX peek   = vif->rx_req_cons_peek;
-	RING_IDX needed = max_required_rx_slots(vif);
+	RING_IDX peek = vif->rx_req_cons_peek;
 
-	return ((vif->rx.sring->req_prod - peek) < needed) ||
-	       ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) < needed);
+	return ((vif->rx.sring->req_prod < peek) ||
+		(vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE < peek));

This transformation is definitely wrong: You need to retain the code's capability of dealing with the indexes wrapping, i.e. simple comparisons won't do.

Quoted 10 lines
drivers/net/xen-netback/netback.c +1 -2
@@ -690,20 +676,23 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk)
 	count = 0;
 
 	while ((skb = skb_dequeue(&netbk->rx_queue)) != NULL) {
+		unsigned int ring_slots_required;
 		vif = netdev_priv(skb->dev);
-		nr_frags = skb_shinfo(skb)->nr_frags;
 
 		sco = (struct skb_cb_overlay *)skb->cb;
-		sco->meta_slots_used = netbk_gop_skb(skb, &npo);

drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 686

Quoted 10 lines
drivers/net/xen-netback/netback.c +2 -6
-
-		count += nr_frags + 1;
 
-		__skb_queue_tail(&rxq, skb);
+		ring_slots_required = xen_netbk_count_skb_slots(vif, skb);
 
-		/* Filled the batch queue? */
-		/* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */
-		if (count + MAX_SKB_FRAGS >= XEN_NETIF_RX_RING_SIZE)
+		if (count + ring_slots_required >= XEN_NETIF_RX_RING_SIZE) {

Is this really still >= here? The old code, iiuc, used >= as being equivalent to count + MAX_SKB_FRAGS + 1 > XEN_NETIF_RX_RING_SIZE.

Jan

author
#2 lore raw
Quoted 12 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Wei Liu

This dependence is undesirable and logically incorrect.

It's undesirable because Xen network protocol should not depend on a OS-specific constant.

But this is not making the protocol dependent upon the constant; at least in one case the check is merely used as a worst case estimation (there can't possibly be an skb with more than MAX_SKB_FRAGS, and hence having as many slots available implies that at least one more skb can be processed).

The "worst case" is a wrong estimation -- consider compound page frags and RX coalescing, a frag can take up multiple ring slots.

The assumption seems to work at the moment because we haven't hit the corner cases, we should probably not rely on that.

Quoted 6 lines
Quoted 6 lines

int xen_netbk_rx_ring_full(struct xenvif *vif)
{

drivers/net/xen-netback/netback.c +1 -2
-	RING_IDX peek   = vif->rx_req_cons_peek;
-	RING_IDX needed = max_required_rx_slots(vif);
+	RING_IDX peek = vif->rx_req_cons_peek;
Quoted 9 lines

drivers/net/xen-netback/netback.c static void xen_netbk_kick_thread(struct xen_netbk *netbk) · line 297

Quoted 4 lines
drivers/net/xen-netback/netback.c +2 -2
-	return ((vif->rx.sring->req_prod - peek) < needed) ||
-	       ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) < needed);
+	return ((vif->rx.sring->req_prod < peek) ||
+		(vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE < peek));

This transformation is definitely wrong: You need to retain the code's capability of dealing with the indexes wrapping, i.e. simple comparisons won't do.

Hmm... so I don't quite understand this wrapping around thing and I have a question here, what if req_prod < peek so that (req_prod - peek) results in a very large number. In that case the ring is actually full (cannot accommodate that packet), however "needed" is only like 20-ish something, so the first comparision would fail. Are we relying on the second comparion to tell the ring is full?

The only thing I need to do here is to tell whether rep_prod is ahead of peek in the first comparison and in the second case there is enough slots between rsp_prod_pvt and peek, what's the correct line?

Quoted 16 lines
Quoted 16 lines
drivers/net/xen-netback/netback.c +2 -5
@@ -690,20 +676,23 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk)
 	count = 0;
 
 	while ((skb = skb_dequeue(&netbk->rx_queue)) != NULL) {
+		unsigned int ring_slots_required;
 		vif = netdev_priv(skb->dev);
-		nr_frags = skb_shinfo(skb)->nr_frags;
 
 		sco = (struct skb_cb_overlay *)skb->cb;
-		sco->meta_slots_used = netbk_gop_skb(skb, &npo);
-
-		count += nr_frags + 1;
 
-		__skb_queue_tail(&rxq, skb);
+		ring_slots_required = xen_netbk_count_skb_slots(vif, skb);
 
Quoted 8 lines

drivers/net/xen-netback/netback.c static void xen_netbk_rx_action(struct xen_netbk *netbk) · line 686

Quoted 4 lines
drivers/net/xen-netback/netback.c +1 -3
-		/* Filled the batch queue? */
-		/* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */
-		if (count + MAX_SKB_FRAGS >= XEN_NETIF_RX_RING_SIZE)
+		if (count + ring_slots_required >= XEN_NETIF_RX_RING_SIZE) {

Is this really still >= here? The old code, iiuc, used >= as being equivalent to count + MAX_SKB_FRAGS + 1 > XEN_NETIF_RX_RING_SIZE.

Yes I should use > here.

Wei.

Quoted 1 line

Jan

#3 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Wei Liu

int xen_netbk_rx_ring_full(struct xenvif *vif)
{

drivers/net/xen-netback/netback.c +1 -2
-	RING_IDX peek   = vif->rx_req_cons_peek;
-	RING_IDX needed = max_required_rx_slots(vif);
+	RING_IDX peek = vif->rx_req_cons_peek;
Quoted 8 lines

drivers/net/xen-netback/netback.c static void xen_netbk_kick_thread(struct xen_netbk *netbk) · line 297

Quoted 4 lines
drivers/net/xen-netback/netback.c +2 -2
-	return ((vif->rx.sring->req_prod - peek) < needed) ||
-	       ((vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE - peek) < needed);
+	return ((vif->rx.sring->req_prod < peek) ||
+		(vif->rx.rsp_prod_pvt + XEN_NETIF_RX_RING_SIZE < peek));

This transformation is definitely wrong: You need to retain the code's capability of dealing with the indexes wrapping, i.e. simple comparisons won't do.

Quoted 6 lines

Hmm... so I don't quite understand this wrapping around thing and I have a question here, what if req_prod < peek so that (req_prod - peek) results in a very large number. In that case the ring is actually full (cannot accommodate that packet), however "needed" is only like 20-ish something, so the first comparision would fail. Are we relying on the second comparion to tell the ring is full?

Yes, and I'm struggling to understand what the first one actually checked for. Your new first one in any case doesn't check whether the ring is full, but whether there's enough slots available on the ring to consume all the way up to "peek" (plus is having a wrap around issue just like the second half).

Quoted 3 lines

The only thing I need to do here is to tell whether rep_prod is ahead of peek in the first comparison and in the second case there is enough slots between rsp_prod_pvt and peek, what's the correct line?

Not sure - in any event, as said above, the first part isn't really matching the name of the function anymore (so would at least deserve a comment, to save future readers from struggling to understand the purpose just like I do with the original one now).

Jan