From: Jason Wang <jasowang@redhat.com>
To: John Fastabend <john.fastabend@gmail.com>,
kubakici@wp.pl, ast@fb.com, mst@redhat.com
Cc: john.r.fastabend@intel.com, netdev@vger.kernel.org
Subject: Re: [net-next PATCH v2 2/5] virtio_net: factor out xdp handler for readability
Date: Mon, 6 Feb 2017 14:49:09 +0800 [thread overview]
Message-ID: <7eb3b18d-7c1c-9808-e37e-2dd458aac655@redhat.com> (raw)
In-Reply-To: <20170203031501.23054.61223.stgit@john-Precision-Tower-5810>
On 2017年02月03日 11:15, John Fastabend wrote:
> At this point the do_xdp_prog is mostly if/else branches handling
> the different modes of virtio_net. So remove it and handle running
> the program in the per mode handlers.
>
> Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> drivers/net/virtio_net.c | 86 +++++++++++++++++++---------------------------
> 1 file changed, 35 insertions(+), 51 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index f8ba586..3b49363 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -399,52 +399,6 @@ static bool virtnet_xdp_xmit(struct virtnet_info *vi,
> return true;
> }
>
> -static u32 do_xdp_prog(struct virtnet_info *vi,
> - struct receive_queue *rq,
> - struct bpf_prog *xdp_prog,
> - void *data, int len)
> -{
> - int hdr_padded_len;
> - struct xdp_buff xdp;
> - void *buf;
> - unsigned int qp;
> - u32 act;
> -
> - if (vi->mergeable_rx_bufs) {
> - hdr_padded_len = sizeof(struct virtio_net_hdr_mrg_rxbuf);
> - xdp.data = data + hdr_padded_len;
> - xdp.data_end = xdp.data + (len - vi->hdr_len);
> - buf = data;
> - } else { /* small buffers */
> - struct sk_buff *skb = data;
> -
> - xdp.data = skb->data;
> - xdp.data_end = xdp.data + len;
> - buf = skb->data;
> - }
> -
> - act = bpf_prog_run_xdp(xdp_prog, &xdp);
> - switch (act) {
> - case XDP_PASS:
> - return XDP_PASS;
> - case XDP_TX:
> - qp = vi->curr_queue_pairs -
> - vi->xdp_queue_pairs +
> - smp_processor_id();
> - xdp.data = buf;
> - if (unlikely(!virtnet_xdp_xmit(vi, rq, &vi->sq[qp], &xdp,
> - data)))
> - trace_xdp_exception(vi->dev, xdp_prog, act);
> - return XDP_TX;
> - default:
> - bpf_warn_invalid_xdp_action(act);
> - case XDP_ABORTED:
> - trace_xdp_exception(vi->dev, xdp_prog, act);
> - case XDP_DROP:
> - return XDP_DROP;
> - }
> -}
> -
> static struct sk_buff *receive_small(struct net_device *dev,
> struct virtnet_info *vi,
> struct receive_queue *rq,
> @@ -460,19 +414,34 @@ static struct sk_buff *receive_small(struct net_device *dev,
> xdp_prog = rcu_dereference(rq->xdp_prog);
> if (xdp_prog) {
> struct virtio_net_hdr_mrg_rxbuf *hdr = buf;
> + struct xdp_buff xdp;
> + unsigned int qp;
> u32 act;
>
> if (unlikely(hdr->hdr.gso_type || hdr->hdr.flags))
> goto err_xdp;
> - act = do_xdp_prog(vi, rq, xdp_prog, skb, len);
> +
> + xdp.data = skb->data;
> + xdp.data_end = xdp.data + len;
> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
> +
> switch (act) {
> case XDP_PASS:
> break;
> case XDP_TX:
> + qp = vi->curr_queue_pairs -
> + vi->xdp_queue_pairs +
> + smp_processor_id();
> + if (unlikely(!virtnet_xdp_xmit(vi, rq, &vi->sq[qp],
> + &xdp, skb)))
> + trace_xdp_exception(vi->dev, xdp_prog, act);
> rcu_read_unlock();
> goto xdp_xmit;
> - case XDP_DROP:
> default:
> + bpf_warn_invalid_xdp_action(act);
> + case XDP_ABORTED:
> + trace_xdp_exception(vi->dev, xdp_prog, act);
> + case XDP_DROP:
> goto err_xdp;
> }
> }
> @@ -590,6 +559,9 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
> xdp_prog = rcu_dereference(rq->xdp_prog);
> if (xdp_prog) {
> struct page *xdp_page;
> + struct xdp_buff xdp;
> + unsigned int qp;
> + void *data;
> u32 act;
>
> /* This happens when rx buffer size is underestimated */
> @@ -612,8 +584,11 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
> if (unlikely(hdr->hdr.gso_type))
> goto err_xdp;
>
> - act = do_xdp_prog(vi, rq, xdp_prog,
> - page_address(xdp_page) + offset, len);
> + data = page_address(xdp_page) + offset;
> + xdp.data = data + vi->hdr_len;
> + xdp.data_end = xdp.data + (len - vi->hdr_len);
> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
> +
> switch (act) {
> case XDP_PASS:
> /* We can only create skb based on xdp_page. */
> @@ -627,13 +602,22 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
> }
> break;
> case XDP_TX:
> + qp = vi->curr_queue_pairs -
> + vi->xdp_queue_pairs +
> + smp_processor_id();
> + if (unlikely(!virtnet_xdp_xmit(vi, rq, &vi->sq[qp],
> + &xdp, data)))
> + 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();
> goto xdp_xmit;
> - case XDP_DROP:
> default:
> + bpf_warn_invalid_xdp_action(act);
> + case XDP_ABORTED:
> + trace_xdp_exception(vi->dev, xdp_prog, act);
> + case XDP_DROP:
> if (unlikely(xdp_page != page))
> __free_pages(xdp_page, 0);
> ewma_pkt_len_add(&rq->mrg_avg_pkt_len, len);
>
next prev parent reply other threads:[~2017-02-06 6:49 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 3:14 [net-next PATCH v2 0/5] XDP adjust head support for virtio John Fastabend
2017-02-03 3:14 ` [net-next PATCH v2 1/5] virtio_net: wrap rtnl_lock in test for calling with lock already held John Fastabend
2017-02-06 6:48 ` Jason Wang
2017-02-03 3:15 ` [net-next PATCH v2 2/5] virtio_net: factor out xdp handler for readability John Fastabend
2017-02-06 6:49 ` Jason Wang [this message]
2017-02-03 3:15 ` [net-next PATCH v2 3/5] virtio_net: remove duplicate queue pair binding in XDP John Fastabend
2017-02-06 7:06 ` Jason Wang
2017-02-03 3:16 ` [net-next PATCH v2 4/5] virtio_net: refactor freeze/restore logic into virtnet reset logic John Fastabend
2017-02-06 7:07 ` Jason Wang
2017-02-03 3:16 ` [net-next PATCH v2 5/5] virtio_net: XDP support for adjust_head John Fastabend
2017-02-03 4:04 ` Michael S. Tsirkin
2017-02-06 7:08 ` Jason Wang
2017-02-06 19:29 ` John Fastabend
2017-02-07 2:23 ` Jason Wang
2017-02-03 3:29 ` [net-next PATCH v2 0/5] XDP adjust head support for virtio Alexei Starovoitov
2017-02-03 3:55 ` Jakub Kicinski
2017-02-05 22:36 ` David Miller
2017-02-06 4:39 ` Michael S. Tsirkin
2017-02-06 7:12 ` Jason Wang
2017-02-06 16:37 ` David Miller
2017-02-07 4:15 ` Michael S. Tsirkin
2017-02-07 15:05 ` David Miller
2017-02-08 16:39 ` John Fastabend
2017-02-08 16:50 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7eb3b18d-7c1c-9808-e37e-2dd458aac655@redhat.com \
--to=jasowang@redhat.com \
--cc=ast@fb.com \
--cc=john.fastabend@gmail.com \
--cc=john.r.fastabend@intel.com \
--cc=kubakici@wp.pl \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).