RE: [PATCH net-next v2 2/3] vhost_net: Call peek_len when using xdp
> -Original Message- > From: Paolo Abeni [mailto:pab...@redhat.com] > Sent: Thursday, February 29, 2024 6:49 PM > To: wangyunjian ; m...@redhat.com; > willemdebruijn.ker...@gmail.com; jasow...@redhat.com; k...@kernel.org; > bj...@kernel.org; magnus.karls...@intel.com; maciej.fijalkow...@intel.com; > jonathan.le...@gmail.com; da...@davemloft.net > Cc: b...@vger.kernel.org; net...@vger.kernel.org; > linux-kernel@vger.kernel.org; k...@vger.kernel.org; > virtualizat...@lists.linux.dev; xudingke ; liwei (DT) > > Subject: Re: [PATCH net-next v2 2/3] vhost_net: Call peek_len when using xdp > > On Wed, 2024-02-28 at 19:05 +0800, Yunjian Wang wrote: > > If TUN supports AF_XDP TX zero-copy, the XDP program will enqueue > > packets to the XDP ring and wake up the vhost worker. This requires > > the vhost worker to call peek_len(), which can be used to consume XDP > > descriptors. > > > > Signed-off-by: Yunjian Wang > > --- > > drivers/vhost/net.c | 17 - > > 1 file changed, 12 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index > > f2ed7167c848..077e74421558 100644 > > --- a/drivers/vhost/net.c > > +++ b/drivers/vhost/net.c > > @@ -207,6 +207,11 @@ static int vhost_net_buf_peek_len(void *ptr) > > return __skb_array_len_with_tag(ptr); } > > > > +static bool vhost_sock_xdp(struct socket *sock) { > > + return sock_flag(sock->sk, SOCK_XDP); } > > + > > static int vhost_net_buf_peek(struct vhost_net_virtqueue *nvq) { > > struct vhost_net_buf *rxq = >rxq; @@ -214,6 +219,13 @@ static > > int vhost_net_buf_peek(struct vhost_net_virtqueue *nvq) > > if (!vhost_net_buf_is_empty(rxq)) > > goto out; > > > > + if (ptr_ring_empty(nvq->rx_ring)) { > > + struct socket *sock = vhost_vq_get_backend(>vq); > > + /* Call peek_len to consume XSK descriptors, when using xdp */ > > + if (vhost_sock_xdp(sock) && sock->ops->peek_len) > > + sock->ops->peek_len(sock); > > This really looks like a socket API misuse. Why can't you use ptr-ring > primitives > to consume XSK descriptors? peek_len could be constified some day, this code > will prevent such (good) thing. Thank you for your suggestion. I will consider that with Patch 3/3. > > Cheers, > > Paolo
Re: [PATCH net-next v2 2/3] vhost_net: Call peek_len when using xdp
On Wed, 2024-02-28 at 19:05 +0800, Yunjian Wang wrote: > If TUN supports AF_XDP TX zero-copy, the XDP program will enqueue > packets to the XDP ring and wake up the vhost worker. This requires > the vhost worker to call peek_len(), which can be used to consume > XDP descriptors. > > Signed-off-by: Yunjian Wang > --- > drivers/vhost/net.c | 17 - > 1 file changed, 12 insertions(+), 5 deletions(-) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index f2ed7167c848..077e74421558 100644 > --- a/drivers/vhost/net.c > +++ b/drivers/vhost/net.c > @@ -207,6 +207,11 @@ static int vhost_net_buf_peek_len(void *ptr) > return __skb_array_len_with_tag(ptr); > } > > +static bool vhost_sock_xdp(struct socket *sock) > +{ > + return sock_flag(sock->sk, SOCK_XDP); > +} > + > static int vhost_net_buf_peek(struct vhost_net_virtqueue *nvq) > { > struct vhost_net_buf *rxq = >rxq; > @@ -214,6 +219,13 @@ static int vhost_net_buf_peek(struct vhost_net_virtqueue > *nvq) > if (!vhost_net_buf_is_empty(rxq)) > goto out; > > + if (ptr_ring_empty(nvq->rx_ring)) { > + struct socket *sock = vhost_vq_get_backend(>vq); > + /* Call peek_len to consume XSK descriptors, when using xdp */ > + if (vhost_sock_xdp(sock) && sock->ops->peek_len) > + sock->ops->peek_len(sock); This really looks like a socket API misuse. Why can't you use ptr-ring primitives to consume XSK descriptors? peek_len could be constified some day, this code will prevent such (good) thing. Cheers, Paolo
[PATCH net-next v2 2/3] vhost_net: Call peek_len when using xdp
If TUN supports AF_XDP TX zero-copy, the XDP program will enqueue packets to the XDP ring and wake up the vhost worker. This requires the vhost worker to call peek_len(), which can be used to consume XDP descriptors. Signed-off-by: Yunjian Wang --- drivers/vhost/net.c | 17 - 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index f2ed7167c848..077e74421558 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -207,6 +207,11 @@ static int vhost_net_buf_peek_len(void *ptr) return __skb_array_len_with_tag(ptr); } +static bool vhost_sock_xdp(struct socket *sock) +{ + return sock_flag(sock->sk, SOCK_XDP); +} + static int vhost_net_buf_peek(struct vhost_net_virtqueue *nvq) { struct vhost_net_buf *rxq = >rxq; @@ -214,6 +219,13 @@ static int vhost_net_buf_peek(struct vhost_net_virtqueue *nvq) if (!vhost_net_buf_is_empty(rxq)) goto out; + if (ptr_ring_empty(nvq->rx_ring)) { + struct socket *sock = vhost_vq_get_backend(>vq); + /* Call peek_len to consume XSK descriptors, when using xdp */ + if (vhost_sock_xdp(sock) && sock->ops->peek_len) + sock->ops->peek_len(sock); + } + if (!vhost_net_buf_produce(nvq)) return 0; @@ -346,11 +358,6 @@ static bool vhost_sock_zcopy(struct socket *sock) sock_flag(sock->sk, SOCK_ZEROCOPY); } -static bool vhost_sock_xdp(struct socket *sock) -{ - return sock_flag(sock->sk, SOCK_XDP); -} - /* In case of DMA done not in order in lower device driver for some reason. * upend_idx is used to track end of used idx, done_idx is used to track head * of used idx. Once lower device DMA done contiguously, we will signal KVM -- 2.41.0