Skip to contentSkip to conversation

virtio-net: remove unnecessary parameter of virtnet_xdp_xmit()

PATCH Applied Jason Wang 3 participants 13 messages Sep 19, 2017 – Sep 22, 2017

Subsystems (4)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/3 virtio-net: remove unnecessary parameter of virtnet_xdp_xmit()

CC John Fastabend <[email protected]>
---
 drivers/net/virtio_net.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +2 -3
index 511f833..a0ef4b0 100644
@@ -373,7 +373,6 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
 }
 
 static bool virtnet_xdp_xmit(struct virtnet_info *vi,
-			     struct receive_queue *rq,
 			     struct xdp_buff *xdp)
 {
 	struct virtio_net_hdr_mrg_rxbuf *hdr;
@@ -542,7 +541,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
 			delta = orig_data - xdp.data;
 			break;
 		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, rq, &xdp)))
+			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);
 			rcu_read_unlock();
 			goto xdp_xmit;
@@ -677,7 +676,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			break;
 		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, rq, &xdp)))
+			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);
 			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 			if (unlikely(xdp_page != page))
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/3 virtio-net: add packet len average only when needed during XDP

There's no need to add packet len average in the case of XDP_PASS since it will be done soon after skb is created.

Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +3 -3
index a0ef4b0..db5924c 100644
@@ -656,6 +656,9 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		xdp.data_end = xdp.data + (len - vi->hdr_len);
 		act = bpf_prog_run_xdp(xdp_prog, &xdp);
 
+		if (act != XDP_PASS)
+			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
+
 		switch (act) {
 		case XDP_PASS:
 			/* recalculate offset to account for any header
@@ -671,14 +674,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 				put_page(page);
 				head_skb = page_to_skb(vi, rq, xdp_page,
 						       offset, len, PAGE_SIZE);
-				ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 				return head_skb;
 			}
 			break;
 		case XDP_TX:
 			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);
-			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 			if (unlikely(xdp_page != page))
 				goto err_xdp;
 			rcu_read_unlock();
@@ -690,7 +691,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		case XDP_DROP:
 			if (unlikely(xdp_page != page))
 				__free_pages(xdp_page, 0);
-			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 			goto err_xdp;
 		}
 	}
Signature · 1 line
2.7.4
maintainer Applied
#2 lore raw

Re: [PATCH net-next 2/3] virtio-net: add packet len average only when needed during XDP

From: Jason Wang <[email protected]>
Date: Tue, 19 Sep 2017 17:42:42 +0800

Quoted 5 lines

There's no need to add packet len average in the case of XDP_PASS since it will be done soon after skb is created.

Cc John Fastabend <[email protected]>

Applied.

author
#3 lore raw

PATCH 2/3 virtio-net: add packet len average only when needed during XDP

In reply to Jason Wang

There's no need to add packet len average in the case of XDP_PASS since it will be done soon after skb is created.

Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +3 -3
index a0ef4b0..db5924c 100644
@@ -656,6 +656,9 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		xdp.data_end = xdp.data + (len - vi->hdr_len);
 		act = bpf_prog_run_xdp(xdp_prog, &xdp);
 
+		if (act != XDP_PASS)
+			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
+
 		switch (act) {
 		case XDP_PASS:
 			/* recalculate offset to account for any header
@@ -671,14 +674,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 				put_page(page);
 				head_skb = page_to_skb(vi, rq, xdp_page,
 						       offset, len, PAGE_SIZE);
-				ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 				return head_skb;
 			}
 			break;
 		case XDP_TX:
 			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);
-			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 			if (unlikely(xdp_page != page))
 				goto err_xdp;
 			rcu_read_unlock();
@@ -690,7 +691,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		case XDP_DROP:
 			if (unlikely(xdp_page != page))
 				__free_pages(xdp_page, 0);
-			ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
 			goto err_xdp;
 		}
 	}
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH 3/3 virtio-net: support XDP_REDIRECT

In reply to Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.  |  0
 drivers/net/virtio_net.c | 77 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 62 insertions(+), 15 deletions(-)
 create mode 100644 drivers/net/virtio_net.
drivers/net/virtio_net. new file +0 -0
new file mode 100644
index 0000000..e69de29
drivers/net/virtio_net.c +62 -15

192 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Applied
#5 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

From: Jason Wang <[email protected]>
Date: Tue, 19 Sep 2017 17:42:43 +0800

Quoted 7 lines

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

Applied.

maintainer Applied
#6 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Tue, 19 Sep 2017 17:42:43 +0800

Quoted 7 lines

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

Applied.

#7 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

In reply to Jason Wang
Quoted 8 lines · Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

---

[...]

Quoted 7 lines
drivers/net/virtio_net.c +1 -1
@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			break;
 		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
+			if (unlikely(!__virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 10 lines
drivers/net/virtio_net.c +6 -0
+			else
+				*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
 				goto err_xdp;
 			rcu_read_unlock();
 			goto xdp_xmit;
+		case XDP_REDIRECT:
+			err = xdp_do_redirect(dev, &xdp, xdp_prog);
+			if (err)
+				*xdp_xmit = true;

Is this a typo? Should above be

			if (!err)
				*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 830

Quoted 8 lines
drivers/net/virtio_net.c +2 -0
+			rcu_read_unlock();
+			goto xdp_xmit;
 		default:
 			bpf_warn_invalid_xdp_action(act);
 		case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 }
 

[...]

Otherwise looks good to me thanks for doing this.

.John

author
#8 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

Quoted 30 lines · John Fastabend
Quoted 8 lines · Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

---

[...]

Quoted 7 lines
drivers/net/virtio_net.c +1 -1
@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  			}
  			break;
  		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
+			if (unlikely(!__virtnet_xdp_xmit(vi, &xdp)))
  				trace_xdp_exception(vi->dev, xdp_prog, act);

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 10 lines
drivers/net/virtio_net.c +6 -0
+			else
+				*xdp_xmit = true;
  			if (unlikely(xdp_page != page))
  				goto err_xdp;
  			rcu_read_unlock();
  			goto xdp_xmit;
+		case XDP_REDIRECT:
+			err = xdp_do_redirect(dev, &xdp, xdp_prog);
+			if (err)
+				*xdp_xmit = true;

Is this a typo? Should above be

Quoted 4 lines
			if (!err)
				*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.

Right, will post a fix.

Quoted 11 lines
Quoted 9 lines
drivers/net/virtio_net.c +2 -0
+			rcu_read_unlock();
+			goto xdp_xmit;
  		default:
  			bpf_warn_invalid_xdp_action(act);
  		case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  }
 

[...]

Quoted 4 lines

Otherwise looks good to me thanks for doing this.

.John

Thanks for the reviewing.

author
#9 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

In reply to John Fastabend
Quoted 30 lines · John Fastabend
Quoted 8 lines · Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

---

[...]

Quoted 7 lines
drivers/net/virtio_net.c +1 -1
@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  			}
  			break;
  		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
+			if (unlikely(!__virtnet_xdp_xmit(vi, &xdp)))
  				trace_xdp_exception(vi->dev, xdp_prog, act);

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 10 lines
drivers/net/virtio_net.c +6 -0
+			else
+				*xdp_xmit = true;
  			if (unlikely(xdp_page != page))
  				goto err_xdp;
  			rcu_read_unlock();
  			goto xdp_xmit;
+		case XDP_REDIRECT:
+			err = xdp_do_redirect(dev, &xdp, xdp_prog);
+			if (err)
+				*xdp_xmit = true;

Is this a typo? Should above be

Quoted 4 lines
			if (!err)
				*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.

Right, will post a fix.

Quoted 11 lines
Quoted 9 lines
drivers/net/virtio_net.c +2 -0
+			rcu_read_unlock();
+			goto xdp_xmit;
  		default:
  			bpf_warn_invalid_xdp_action(act);
  		case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  }
 

[...]

Quoted 4 lines

Otherwise looks good to me thanks for doing this.

.John

Thanks for the reviewing.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#10 lore raw

Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

In reply to Jason Wang
Quoted 8 lines · Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>

---

[...]

Quoted 7 lines
drivers/net/virtio_net.c +1 -1
@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			break;
 		case XDP_TX:
-			if (unlikely(!virtnet_xdp_xmit(vi, &xdp)))
+			if (unlikely(!__virtnet_xdp_xmit(vi, &xdp)))
 				trace_xdp_exception(vi->dev, xdp_prog, act);

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 10 lines
drivers/net/virtio_net.c +6 -0
+			else
+				*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
 				goto err_xdp;
 			rcu_read_unlock();
 			goto xdp_xmit;
+		case XDP_REDIRECT:
+			err = xdp_do_redirect(dev, &xdp, xdp_prog);
+			if (err)
+				*xdp_xmit = true;

Is this a typo? Should above be

			if (!err)
				*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 830

Quoted 8 lines
drivers/net/virtio_net.c +2 -0
+			rcu_read_unlock();
+			goto xdp_xmit;
 		default:
 			bpf_warn_invalid_xdp_action(act);
 		case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 }
 

[...]

Otherwise looks good to me thanks for doing this.

.John

author
#11 lore raw

PATCH 3/3 virtio-net: support XDP_REDIRECT

In reply to Jason Wang

This patch tries to add XDP_REDIRECT for virtio-net. The changes are not complex as we could use exist XDP_TX helpers for most of the work. The rest is passing the XDP_TX to NAPI handler for implementing batching.

Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.  |  0
 drivers/net/virtio_net.c | 77 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 62 insertions(+), 15 deletions(-)
 create mode 100644 drivers/net/virtio_net.
drivers/net/virtio_net. new file +0 -0
new file mode 100644
index 0000000..e69de29
drivers/net/virtio_net.c +62 -15

192 lines not on this page · raw message

Signature · 1 line
2.7.4