From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: "Petr Machata" <petrm@nvidia.com>,
"Menglong Dong" <imagedong@tencent.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
netdev@vger.kernel.org,
"John Fastabend" <john.fastabend@gmail.com>,
"Björn Töpel" <bjorn@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Kuniyuki Iwashima" <kuniyu@amazon.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Jonathan Lemon" <jonathan.lemon@gmail.com>,
"Jakub Kicinski" <kuba@kernel.org>,
bpf@vger.kernel.org, "Paolo Abeni" <pabeni@redhat.com>,
virtualization@lists.linux-foundation.org,
"David S. Miller" <davem@davemloft.net>,
"Magnus Karlsson" <magnus.karlsson@intel.com>
Subject: Re: [PATCH 16/33] virtio_net: introduce virtnet_xdp_handler() to seprate the logic of run xdp
Date: Fri, 3 Feb 2023 03:55:26 -0500 [thread overview]
Message-ID: <20230203035416-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230202110058.130695-17-xuanzhuo@linux.alibaba.com>
On Thu, Feb 02, 2023 at 07:00:41PM +0800, Xuan Zhuo wrote:
> At present, we have two long similar logic to perform XDP Progs. And in
> the implementation of XSK, we will have this need.
>
> Therefore, this PATCH separates the code of executing XDP, which is
> conducive to later maintenance and facilitates subsequent XSK for reuse.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
So you first add a new function then move users over.
This means that it's hard during review to make sure
nothing is lost in translation.
Do the refactoring in a single patch instead.
> ---
> drivers/net/virtio/main.c | 53 +++++++++++++++++++++++++++++++++
> drivers/net/virtio/virtio_net.h | 11 +++++++
> 2 files changed, 64 insertions(+)
>
> diff --git a/drivers/net/virtio/main.c b/drivers/net/virtio/main.c
> index 5683cb576474..9d4b84b23ef7 100644
> --- a/drivers/net/virtio/main.c
> +++ b/drivers/net/virtio/main.c
> @@ -478,6 +478,59 @@ static int virtnet_xdp_xmit(struct net_device *dev,
> return ret;
> }
>
> +int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
> + struct net_device *dev,
> + unsigned int *xdp_xmit,
> + struct virtnet_rq_stats *stats)
> +{
> + struct xdp_frame *xdpf;
> + int err;
> + u32 act;
> +
> + act = bpf_prog_run_xdp(xdp_prog, xdp);
> + stats->xdp_packets++;
> +
> + switch (act) {
> + case XDP_PASS:
> + return VIRTNET_XDP_RES_PASS;
> +
> + case XDP_TX:
> + stats->xdp_tx++;
> + xdpf = xdp_convert_buff_to_frame(xdp);
> + if (unlikely(!xdpf))
> + return VIRTNET_XDP_RES_DROP;
> +
> + err = virtnet_xdp_xmit(dev, 1, &xdpf, 0);
> + if (unlikely(!err)) {
> + xdp_return_frame_rx_napi(xdpf);
> + } else if (unlikely(err < 0)) {
> + trace_xdp_exception(dev, xdp_prog, act);
> + return VIRTNET_XDP_RES_DROP;
> + }
> +
> + *xdp_xmit |= VIRTIO_XDP_TX;
> + return VIRTNET_XDP_RES_CONSUMED;
> +
> + case XDP_REDIRECT:
> + stats->xdp_redirects++;
> + err = xdp_do_redirect(dev, xdp, xdp_prog);
> + if (err)
> + return VIRTNET_XDP_RES_DROP;
> +
> + *xdp_xmit |= VIRTIO_XDP_REDIR;
> + return VIRTNET_XDP_RES_CONSUMED;
> +
> + default:
> + bpf_warn_invalid_xdp_action(dev, xdp_prog, act);
> + fallthrough;
> + case XDP_ABORTED:
> + trace_xdp_exception(dev, xdp_prog, act);
> + fallthrough;
> + case XDP_DROP:
> + return VIRTNET_XDP_RES_DROP;
> + }
> +}
> +
> static unsigned int virtnet_get_headroom(struct virtnet_info *vi)
> {
> return vi->xdp_enabled ? VIRTIO_XDP_HEADROOM : 0;
> diff --git a/drivers/net/virtio/virtio_net.h b/drivers/net/virtio/virtio_net.h
> index 8bf31429ae28..af3e7e817f9e 100644
> --- a/drivers/net/virtio/virtio_net.h
> +++ b/drivers/net/virtio/virtio_net.h
> @@ -22,6 +22,12 @@
> #include <net/net_failover.h>
> #include <net/xdp_sock_drv.h>
>
> +enum {
> + VIRTNET_XDP_RES_PASS,
> + VIRTNET_XDP_RES_DROP,
> + VIRTNET_XDP_RES_CONSUMED,
> +};
> +
> #define VIRTIO_XDP_FLAG BIT(0)
>
> struct virtnet_info {
> @@ -262,4 +268,9 @@ static void __free_old_xmit(struct send_queue *sq, bool in_napi,
> stats->packets++;
> }
> }
> +
> +int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
> + struct net_device *dev,
> + unsigned int *xdp_xmit,
> + struct virtnet_rq_stats *stats);
> #endif
> --
> 2.32.0.3.g01195cf9f
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2023-02-03 8:55 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 11:00 [PATCH 00/33] virtio-net: support AF_XDP zero copy Xuan Zhuo
2023-02-02 11:00 ` [PATCH 01/33] virtio_ring: virtqueue_add() support premapped Xuan Zhuo
2023-02-02 11:00 ` [PATCH 02/33] virtio_ring: split: virtqueue_add_split() " Xuan Zhuo
2023-02-02 11:00 ` [PATCH 03/33] virtio_ring: packed: virtqueue_add_packed() " Xuan Zhuo
2023-02-03 9:16 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 04/33] virtio_ring: introduce virtqueue_add_outbuf_premapped() Xuan Zhuo
2023-02-02 11:00 ` [PATCH 05/33] virtio_ring: introduce virtqueue_add_inbuf_premapped() Xuan Zhuo
2023-02-02 11:00 ` [PATCH 06/33] virtio_ring: introduce virtqueue_reset() Xuan Zhuo
2023-02-03 9:05 ` Michael S. Tsirkin
2023-02-03 9:09 ` Xuan Zhuo
2023-02-13 12:15 ` Michael S. Tsirkin
2023-02-14 1:53 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 07/33] virtio_ring: add api virtio_dma_map() for advance dma Xuan Zhuo
2023-02-03 9:07 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 08/33] virtio_ring: introduce dma sync api for virtio Xuan Zhuo
2023-02-03 9:24 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 09/33] xsk: xsk_buff_pool add callback for dma_sync Xuan Zhuo
[not found] ` <CAJ8uoz2+4+wUFYF1GjF51DFBV8ZsBRtTEVWpu_2fBmFUEQzOLQ@mail.gmail.com>
2023-02-03 7:01 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 10/33] xsk: support virtio DMA map Xuan Zhuo
2023-02-05 22:04 ` kernel test robot
2023-02-02 11:00 ` [PATCH 11/33] virtio_net: rename free_old_xmit_skbs to free_old_xmit Xuan Zhuo
2023-02-02 11:00 ` [PATCH 12/33] virtio_net: unify the code for recycling the xmit ptr Xuan Zhuo
2023-02-02 11:00 ` [PATCH 13/33] virtio_net: virtnet_poll_tx support rescheduled Xuan Zhuo
2023-02-02 11:00 ` [PATCH 14/33] virtio_net: independent directory Xuan Zhuo
2023-02-02 11:00 ` [PATCH 15/33] virtio_net: move to virtio_net.h Xuan Zhuo
2023-02-03 8:53 ` Michael S. Tsirkin
2023-02-03 9:04 ` Xuan Zhuo
2023-02-03 9:26 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 16/33] virtio_net: introduce virtnet_xdp_handler() to seprate the logic of run xdp Xuan Zhuo
2023-02-03 8:55 ` Michael S. Tsirkin [this message]
2023-02-03 9:01 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 17/33] virtio_net: receive_small() use virtnet_xdp_handler() Xuan Zhuo
2023-02-02 11:00 ` [PATCH 18/33] virtio_net: receive_merageable() " Xuan Zhuo
2023-02-02 17:16 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 19/33] virtio_net: introduce virtnet_tx_reset() Xuan Zhuo
2023-02-02 17:23 ` Michael S. Tsirkin
2023-02-03 4:35 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 20/33] virtio_net: xsk: introduce virtnet_rq_bind_xsk_pool() Xuan Zhuo
2023-02-03 8:48 ` Michael S. Tsirkin
2023-02-03 8:52 ` Xuan Zhuo
2023-02-03 9:28 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 21/33] virtio_net: xsk: introduce virtnet_xsk_pool_enable() Xuan Zhuo
2023-02-02 11:00 ` [PATCH 22/33] virtio_net: xsk: introduce xsk disable Xuan Zhuo
2023-02-02 23:02 ` kernel test robot
2023-02-12 7:56 ` kernel test robot
2023-02-02 11:00 ` [PATCH 23/33] virtio_net: xsk: support xsk setup Xuan Zhuo
2023-02-02 11:00 ` [PATCH 24/33] virtio_net: xsk: stop disable tx napi Xuan Zhuo
2023-02-02 17:25 ` Michael S. Tsirkin
2023-02-03 3:24 ` Xuan Zhuo
2023-02-03 8:33 ` Michael S. Tsirkin
2023-02-03 8:49 ` Xuan Zhuo
2023-02-03 9:29 ` Michael S. Tsirkin
2023-02-02 11:00 ` [PATCH 25/33] virtio_net: xsk: __free_old_xmit distinguishes xsk buffer Xuan Zhuo
2023-02-02 11:00 ` [PATCH 26/33] virtio_net: virtnet_sq_free_unused_buf() check " Xuan Zhuo
2023-02-02 11:00 ` [PATCH 27/33] virtio_net: virtnet_rq_free_unused_buf() " Xuan Zhuo
2023-02-02 11:00 ` [PATCH 28/33] net: introduce napi_tx_raise() Xuan Zhuo
2023-02-02 11:00 ` [PATCH 29/33] virtio_net: xsk: tx: support tx Xuan Zhuo
[not found] ` <Y9zIPdKmTvXqyuYS@boxer>
2023-02-03 8:55 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 30/33] virtio_net: xsk: tx: support wakeup Xuan Zhuo
2023-02-02 11:00 ` [PATCH 31/33] virtio_net: xsk: tx: auto wakeup when free old xmit Xuan Zhuo
2023-02-02 11:00 ` [PATCH 32/33] virtio_net: xsk: rx: introduce add_recvbuf_xsk() Xuan Zhuo
[not found] ` <Y9zJS+ugeY9qEMt9@boxer>
2023-02-03 8:56 ` Xuan Zhuo
2023-02-02 11:00 ` [PATCH 33/33] virtio_net: xsk: rx: introduce receive_xsk() to recv xsk buffer Xuan Zhuo
2023-02-02 11:08 ` [PATCH 00/33] virtio-net: support AF_XDP zero copy Xuan Zhuo
2023-02-02 11:08 ` Michael S. Tsirkin
2023-02-02 11:11 ` Xuan Zhuo
2023-02-02 11:44 ` Xuan Zhuo
2023-02-03 9:08 ` Michael S. Tsirkin
2023-02-03 9:09 ` Xuan Zhuo
2023-02-02 14:41 ` Paolo Abeni
2023-02-03 3:33 ` Xuan Zhuo
2023-02-03 8:37 ` Michael S. Tsirkin
[not found] ` <Y9zJ9j0GthvRSFHL@boxer>
2023-02-03 9:09 ` Michael S. Tsirkin
2023-02-03 9:17 ` Michael S. Tsirkin
2023-02-06 2:41 ` Xuan Zhuo
2023-02-13 12:14 ` 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=20230203035416-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=imagedong@tencent.com \
--cc=john.fastabend@gmail.com \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xuanzhuo@linux.alibaba.com \
/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).