Netdev List
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>,
	Daniel Borkmann <borkmann@iogearbox.net>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	netdev@vger.kernel.org,
	virtualization@lists.linux-foundation.org, dsahern@gmail.com,
	gospo@broadcom.com, bjorn.topel@intel.com,
	michael.chan@broadcom.com
Subject: Re: [bpf-next V3 PATCH 11/14] virtio_net: setup xdp_rxq_info
Date: Tue, 2 Jan 2018 11:38:48 +0800	[thread overview]
Message-ID: <373fdca0-0f3e-af4b-536b-b0d30c3f20fc@redhat.com> (raw)
In-Reply-To: <151471811006.30703.5247549257959215999.stgit@firesoul>



On 2017年12月31日 19:01, Jesper Dangaard Brouer wrote:
> The virtio_net driver doesn't dynamically change the RX-ring queue
> layout and backing pages, but instead reject XDP setup if all the
> conditions for XDP is not meet.  Thus, the xdp_rxq_info also remains
> fairly static.  This allow us to simply add the reg/unreg to
> net_device open/close functions.
>
> Driver hook points for xdp_rxq_info:
>   * reg  : virtnet_open
>   * unreg: virtnet_close
>
> V3:
>   - bugfix, also setup xdp.rxq in receive_mergeable()
>   - Tested bpf-sample prog inside guest on a virtio_net device
>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: virtualization@lists.linux-foundation.org
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---
>   drivers/net/virtio_net.c |   14 +++++++++++++-
>   1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6fb7b658a6cc..ed8299343728 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -31,6 +31,7 @@
>   #include <linux/average.h>
>   #include <linux/filter.h>
>   #include <net/route.h>
> +#include <net/xdp.h>
>   
>   static int napi_weight = NAPI_POLL_WEIGHT;
>   module_param(napi_weight, int, 0444);
> @@ -115,6 +116,8 @@ struct receive_queue {
>   
>   	/* Name of this receive queue: input.$index */
>   	char name[40];
> +
> +	struct xdp_rxq_info xdp_rxq;
>   };
>   
>   struct virtnet_info {
> @@ -559,6 +562,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
>   		xdp.data = xdp.data_hard_start + xdp_headroom;
>   		xdp_set_data_meta_invalid(&xdp);
>   		xdp.data_end = xdp.data + len;
> +		xdp.rxq = &rq->xdp_rxq;
>   		orig_data = xdp.data;
>   		act = bpf_prog_run_xdp(xdp_prog, &xdp);
>   
> @@ -692,6 +696,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
>   		xdp.data = data + vi->hdr_len;
>   		xdp_set_data_meta_invalid(&xdp);
>   		xdp.data_end = xdp.data + (len - vi->hdr_len);
> +		xdp.rxq = &rq->xdp_rxq;
> +
>   		act = bpf_prog_run_xdp(xdp_prog, &xdp);
>   
>   		if (act != XDP_PASS)
> @@ -1225,13 +1231,18 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
>   static int virtnet_open(struct net_device *dev)
>   {
>   	struct virtnet_info *vi = netdev_priv(dev);
> -	int i;
> +	int i, err;
>   
>   	for (i = 0; i < vi->max_queue_pairs; i++) {
>   		if (i < vi->curr_queue_pairs)
>   			/* Make sure we have some buffers: if oom use wq. */
>   			if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL))
>   				schedule_delayed_work(&vi->refill, 0);
> +
> +		err = xdp_rxq_info_reg(&vi->rq[i].xdp_rxq, dev, i);
> +		if (err < 0)
> +			return err;
> +
>   		virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
>   		virtnet_napi_tx_enable(vi, vi->sq[i].vq, &vi->sq[i].napi);
>   	}
> @@ -1560,6 +1571,7 @@ static int virtnet_close(struct net_device *dev)
>   	cancel_delayed_work_sync(&vi->refill);
>   
>   	for (i = 0; i < vi->max_queue_pairs; i++) {
> +		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
>   		napi_disable(&vi->rq[i].napi);
>   		virtnet_napi_tx_disable(&vi->sq[i].napi);
>   	}
>

Reviewed-by: Jason Wang <jasowang@redhat.com>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2018-01-02  3:38 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-31 11:00 [bpf-next V3 PATCH 00/14] xdp: new XDP rx-queue info concept Jesper Dangaard Brouer
2017-12-31 11:00 ` [bpf-next V3 PATCH 01/14] xdp: base API for " Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 02/14] xdp/mlx5: setup xdp_rxq_info Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 03/14] i40e: " Jesper Dangaard Brouer
2017-12-31 12:33   ` [Intel-wired-lan] " Paul Menzel
2017-12-31 11:01 ` [bpf-next V3 PATCH 04/14] ixgbe: " Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 05/14] xdp/qede: setup xdp_rxq_info and intro xdp_rxq_info_is_reg Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 06/14] mlx4: setup xdp_rxq_info Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 07/14] bnxt_en: " Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 08/14] nfp: " Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 09/14] thunderx: " Jesper Dangaard Brouer
2017-12-31 11:01 ` [bpf-next V3 PATCH 10/14] tun: " Jesper Dangaard Brouer
2018-01-02  3:38   ` Jason Wang
2017-12-31 11:01 ` [bpf-next V3 PATCH 11/14] virtio_net: " Jesper Dangaard Brouer
2018-01-02  3:38   ` Jason Wang [this message]
2017-12-31 11:01 ` [bpf-next V3 PATCH 12/14] xdp: generic XDP handling of xdp_rxq_info Jesper Dangaard Brouer
2017-12-31 11:02 ` [bpf-next V3 PATCH 13/14] bpf: finally expose xdp_rxq_info to XDP bpf-programs Jesper Dangaard Brouer
2018-01-02 17:47   ` David Ahern
2017-12-31 11:02 ` [bpf-next V3 PATCH 14/14] samples/bpf: program demonstrating access to xdp_rxq_info Jesper Dangaard Brouer

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=373fdca0-0f3e-af4b-536b-b0d30c3f20fc@redhat.com \
    --to=jasowang@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=borkmann@iogearbox.net \
    --cc=brouer@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=gospo@broadcom.com \
    --cc=michael.chan@broadcom.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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