Skip to contentSkip to conversation

xen-netback: fix abuse of napi budget

PATCH In review Paul Durrant 2 participants 7 messages Dec 10, 2013

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

PATCH v2 1/1 xen-netback: fix abuse of napi budget

netback seemed to be somewhat confused about the napi budget parameter. The parameter is supposed to limit the number of skgs process in each poll, but netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the shared ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS as the former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen-netback/netback.c +8 -9
index 43341b8..0c8ca76 100644
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];
 		struct page *page;
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
 
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int budget)
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;
 }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 17 lines

-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 10 December 2013 11:28
To: [email protected]; [email protected]
Cc: Paul Durrant; Wei Liu; Ian Campbell; David Vrabel
Subject: [PATCH net v2] xen-netback: fix abuse of napi budget

netback seemed to be somewhat confused about the napi budget parameter. The
parameter is supposed to limit the number of skgs process in each poll, but netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the shared ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

Quoted 8 lines

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS as the
former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Sorry, this patch is incomplete. I need to remove the decrement of the work_to_do variable in xenvif_tx_build_gops too.

Paul

Quoted 86 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 43341b8..0c8ca76 100644

drivers/net/xen-netback/netback.c +3 -2
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif *vif,
 unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];

drivers/net/xen-netback/netback.c +1 -2
 		struct page *page;
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif)
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,
 work_to_do);
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
drivers/net/xen-netback/netback.c +2 -3
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif)
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
drivers/net/xen-netback/netback.c +2 -2
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int
 budget)
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;

}
--
1.7.10.4

#2 lore raw
In reply to Paul Durrant
Quoted 17 lines

-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 10 December 2013 11:28
To: [email protected]; [email protected]
Cc: Paul Durrant; Wei Liu; Ian Campbell; David Vrabel
Subject: [PATCH net v2] xen-netback: fix abuse of napi budget

netback seemed to be somewhat confused about the napi budget parameter. The
parameter is supposed to limit the number of skgs process in each poll, but netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the shared ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

Quoted 8 lines

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS as the
former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Sorry, this patch is incomplete. I need to remove the decrement of the work_to_do variable in xenvif_tx_build_gops too.

Paul

Quoted 86 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c
index 43341b8..0c8ca76 100644

drivers/net/xen-netback/netback.c +3 -2
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif *vif,
 unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];

drivers/net/xen-netback/netback.c +1 -2
 		struct page *page;
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif
 *vif)
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,
 work_to_do);
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
drivers/net/xen-netback/netback.c +2 -3
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct
 xenvif *vif)
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
drivers/net/xen-netback/netback.c +2 -2
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int
 budget)
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;

}
--
1.7.10.4

#3 lore raw
In reply to Paul Durrant
Quoted 2 lines · Paul Durrant

netback seemed to be somewhat confused about the napi budget parameter. The parameter is supposed to limit the number of skgs process in each poll, but

skbs

Quoted 7 lines

netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the shared ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

Quoted 5 lines

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS as the former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Can you add a reminder of when/where the ring event pointer is eventually advanced now please.

This seems like a slightly subtle change, especially when mixed in with the budget handling changes. Please can we do it in a separate patch.

Quoted 36 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen-netback/netback.c +3 -2
index 43341b8..0c8ca76 100644
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];
 		struct page *page;

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct xenvif *vif) · line 1383

Quoted 4 lines
drivers/net/xen-netback/netback.c +0 -1
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);

Is work_to_do now used uninitialised at various subsequent points? (in your next reply you mentioned the decrease, but what about e.g. the call to xenvif_get_extras?)

Quoted 39 lines
drivers/net/xen-netback/netback.c +5 -6
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
 
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int budget)
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;
 }
#4 lore raw
In reply to Paul Durrant
Quoted 2 lines · Paul Durrant

netback seemed to be somewhat confused about the napi budget parameter. The parameter is supposed to limit the number of skgs process in each poll, but

skbs

Quoted 7 lines

netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the shared ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

Quoted 5 lines

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS as the former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Can you add a reminder of when/where the ring event pointer is eventually advanced now please.

This seems like a slightly subtle change, especially when mixed in with the budget handling changes. Please can we do it in a separate patch.

Quoted 36 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen-netback/netback.c +3 -2
index 43341b8..0c8ca76 100644
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];
 		struct page *page;

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct xenvif *vif) · line 1383

Quoted 4 lines
drivers/net/xen-netback/netback.c +0 -1
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);

Is work_to_do now used uninitialised at various subsequent points? (in your next reply you mentioned the decrease, but what about e.g. the call to xenvif_get_extras?)

Quoted 39 lines
drivers/net/xen-netback/netback.c +5 -6
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
 
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int budget)
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;
 }
#5 lore raw
Quoted 29 lines

-----Original Message-----
From: Ian Campbell
Sent: 10 December 2013 11:44
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v2] xen-netback: fix abuse of napi budget

Quoted 1 line · Paul Durrant

netback seemed to be somewhat confused about the napi budget

parameter. The

Quoted 1 line

parameter is supposed to limit the number of skgs process in each poll, but

skbs

Quoted 4 lines

netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the

shared

Quoted 5 lines

ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS

as the

Quoted 3 lines

former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Quoted 6 lines

Can you add a reminder of when/where the ring event pointer is eventually advanced now please.

This seems like a slightly subtle change, especially when mixed in with the budget handling changes. Please can we do it in a separate patch.

Ok. Given I also spotted the mistake with work_to_do, I'll make this a 2 patch series.

Paul

Quoted 92 lines

drivers/net/xen-

Quoted 14 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c

drivers/net/xen-netback/netback.c static bool tx_credit_exceeded(struct xenvif

Quoted 4 lines

index 43341b8..0c8ca76 100644

drivers/net/xen-netback/netback.c +0 -0
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif

*vif, unsigned size)

Quoted 6 lines
drivers/net/xen-netback/netback.c +1 -1
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {

drivers/net/xen-netback/netback.c static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)

Quoted 10 lines
drivers/net/xen-netback/netback.c +2 -1
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct

Quoted 2 lines
drivers/net/xen-netback/netback.c +0 -0
 		struct page *page;
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct

xenvif *vif)

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct xenvif *vif)

Quoted 4 lines
drivers/net/xen-netback/netback.c +0 -1
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,

work_to_do);

Is work_to_do now used uninitialised at various subsequent points? (in your next reply you mentioned the decrease, but what about e.g. the call to xenvif_get_extras?)

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct

Quoted 6 lines
drivers/net/xen-netback/netback.c +1 -1
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
 
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct

xenvif *vif)

drivers/net/xen-netback/netback.c int xenvif_tx_action(struct xenvif *vif, int

Quoted 17 lines
drivers/net/xen-netback/netback.c +2 -3
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int

budget)

Quoted 16 lines
drivers/net/xen-netback/netback.c +2 -2
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;
 }
#6 lore raw
In reply to Ian Campbell
Quoted 29 lines

-----Original Message-----
From: Ian Campbell
Sent: 10 December 2013 11:44
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v2] xen-netback: fix abuse of napi budget

Quoted 1 line · Paul Durrant

netback seemed to be somewhat confused about the napi budget

parameter. The

Quoted 1 line

parameter is supposed to limit the number of skgs process in each poll, but

skbs

Quoted 4 lines

netback had this confused with grant operations.

This patch fixes that, properly limiting the work done in each poll. Note that this limit makes sure we do not process any more data from the

shared

Quoted 5 lines

ring than we intend to pass back from the poll. This is important to prevent tx_queue potentially growing without bound.

This patch also changes the RING_FINAL_CHECK_FOR_REQUESTS in xenvif_build_tx_gops to a check for RING_HAS_UNCONSUMED_REQUESTS

as the

Quoted 3 lines

former call has the side effect of advancing the ring event pointer and therefore inviting another interrupt from the frontend before the napi poll has actually finished, thereby defeating the point of napi.

Quoted 6 lines

Can you add a reminder of when/where the ring event pointer is eventually advanced now please.

This seems like a slightly subtle change, especially when mixed in with the budget handling changes. Please can we do it in a separate patch.

Ok. Given I also spotted the mistake with work_to_do, I'll make this a 2 patch series.

Paul

Quoted 92 lines

drivers/net/xen-

Quoted 14 lines
Cc Wei Liu <[email protected]>
Cc Ian Campbell <[email protected]>
Cc David Vrabel <[email protected]>

---
v2:
- More elaborate description of the problem and the fix in the comment.
- Modified the check in xenvif_build_tx_gops.

 drivers/net/xen-netback/netback.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/netback.c +0 -0

netback/netback.c

drivers/net/xen-netback/netback.c static bool tx_credit_exceeded(struct xenvif

Quoted 4 lines

index 43341b8..0c8ca76 100644

drivers/net/xen-netback/netback.c +0 -0
@@ -1351,14 +1351,15 @@ static bool tx_credit_exceeded(struct xenvif

*vif, unsigned size)

Quoted 6 lines
drivers/net/xen-netback/netback.c +1 -1
 	return false;
 }
 
-static unsigned xenvif_tx_build_gops(struct xenvif *vif)
+static unsigned xenvif_tx_build_gops(struct xenvif *vif, int budget)
 {

drivers/net/xen-netback/netback.c static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)

Quoted 10 lines
drivers/net/xen-netback/netback.c +2 -1
 	struct gnttab_copy *gop = vif->tx_copy_ops, *request_gop;
 	struct sk_buff *skb;
 	int ret;
 
 	while ((nr_pending_reqs(vif) + XEN_NETBK_LEGACY_SLOTS_MAX
-		< MAX_PENDING_REQS)) {
+		< MAX_PENDING_REQS) &&
+	       (skb_queue_len(&vif->tx_queue) < budget)) {
 		struct xen_netif_tx_request txreq;
 		struct xen_netif_tx_request

txfrags[XEN_NETBK_LEGACY_SLOTS_MAX];

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct

Quoted 2 lines
drivers/net/xen-netback/netback.c +0 -0
 		struct page *page;
@@ -1380,8 +1381,7 @@ static unsigned xenvif_tx_build_gops(struct

xenvif *vif)

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct xenvif *vif)

Quoted 4 lines
drivers/net/xen-netback/netback.c +0 -1
 			continue;
 		}
 
-		RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx,

work_to_do);

Is work_to_do now used uninitialised at various subsequent points? (in your next reply you mentioned the decrease, but what about e.g. the call to xenvif_get_extras?)

drivers/net/xen-netback/netback.c static unsigned xenvif_tx_build_gops(struct

Quoted 6 lines
drivers/net/xen-netback/netback.c +1 -1
-		if (!work_to_do)
+		if (!RING_HAS_UNCONSUMED_REQUESTS(&vif->tx))
 			break;
 
 		idx = vif->tx.req_cons;
@@ -1520,14 +1520,13 @@ static unsigned xenvif_tx_build_gops(struct

xenvif *vif)

drivers/net/xen-netback/netback.c int xenvif_tx_action(struct xenvif *vif, int

Quoted 17 lines
drivers/net/xen-netback/netback.c +2 -3
 }
 
 
-static int xenvif_tx_submit(struct xenvif *vif, int budget)
+static int xenvif_tx_submit(struct xenvif *vif)
 {
 	struct gnttab_copy *gop = vif->tx_copy_ops;
 	struct sk_buff *skb;
 	int work_done = 0;
 
-	while (work_done < budget &&
-	       (skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
+	while ((skb = __skb_dequeue(&vif->tx_queue)) != NULL) {
 		struct xen_netif_tx_request *txp;
 		u16 pending_idx;
 		unsigned data_len;
@@ -1602,14 +1601,14 @@ int xenvif_tx_action(struct xenvif *vif, int

budget)

Quoted 16 lines
drivers/net/xen-netback/netback.c +2 -2
 	if (unlikely(!tx_work_todo(vif)))
 		return 0;
 
-	nr_gops = xenvif_tx_build_gops(vif);
+	nr_gops = xenvif_tx_build_gops(vif, budget);
 
 	if (nr_gops == 0)
 		return 0;
 
 	gnttab_batch_copy(vif->tx_copy_ops, nr_gops);
 
-	work_done = xenvif_tx_submit(vif, nr_gops);
+	work_done = xenvif_tx_submit(vif);
 
 	return work_done;
 }