Re: [PATCH net-next v2 17/21] virtio_net: xsk: rx: skip dma unmap when rq is bind with AF_XDP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 07, 2023 at 11:12:23AM +0800, Xuan Zhuo wrote:
> When rq is bound with AF_XDP, the buffer dma is managed
> by the AF_XDP APIs. So the buffer got from the virtio core should
> skip the dma unmap operation.
> 
> Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx>


I don't get it - is this like a bugfix?
And why do we need our own flag and checks?
Doesn't virtio core DTRT?

> ---
>  drivers/net/virtio/main.c       | 8 +++++---
>  drivers/net/virtio/virtio_net.h | 3 +++
>  drivers/net/virtio/xsk.c        | 1 +
>  3 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio/main.c b/drivers/net/virtio/main.c
> index 15943a22e17d..a318b2533b94 100644
> --- a/drivers/net/virtio/main.c
> +++ b/drivers/net/virtio/main.c
> @@ -430,7 +430,7 @@ static void *virtnet_rq_get_buf(struct virtnet_rq *rq, u32 *len, void **ctx)
>  	void *buf;
>  
>  	buf = virtqueue_get_buf_ctx(rq->vq, len, ctx);
> -	if (buf && rq->do_dma)
> +	if (buf && rq->do_dma_unmap)
>  		virtnet_rq_unmap(rq, buf, *len);
>  
>  	return buf;
> @@ -561,8 +561,10 @@ static void virtnet_set_premapped(struct virtnet_info *vi)
>  
>  		/* disable for big mode */
>  		if (vi->mergeable_rx_bufs || !vi->big_packets) {
> -			if (!virtqueue_set_dma_premapped(vi->rq[i].vq))
> +			if (!virtqueue_set_dma_premapped(vi->rq[i].vq)) {
>  				vi->rq[i].do_dma = true;
> +				vi->rq[i].do_dma_unmap = true;
> +			}
>  		}
>  	}
>  }
> @@ -3944,7 +3946,7 @@ void virtnet_rq_free_unused_buf(struct virtqueue *vq, void *buf)
>  
>  	rq = &vi->rq[i];
>  
> -	if (rq->do_dma)
> +	if (rq->do_dma_unmap)
>  		virtnet_rq_unmap(rq, buf, 0);
>  
>  	virtnet_rq_free_buf(vi, rq, buf);
> diff --git a/drivers/net/virtio/virtio_net.h b/drivers/net/virtio/virtio_net.h
> index 1242785e311e..2005d0cd22e2 100644
> --- a/drivers/net/virtio/virtio_net.h
> +++ b/drivers/net/virtio/virtio_net.h
> @@ -135,6 +135,9 @@ struct virtnet_rq {
>  	/* Do dma by self */
>  	bool do_dma;
>  
> +	/* Do dma unmap after getting buf from virtio core. */
> +	bool do_dma_unmap;
> +
>  	struct {
>  		struct xsk_buff_pool *pool;
>  
> diff --git a/drivers/net/virtio/xsk.c b/drivers/net/virtio/xsk.c
> index e737c3353212..b09c473c29fb 100644
> --- a/drivers/net/virtio/xsk.c
> +++ b/drivers/net/virtio/xsk.c
> @@ -210,6 +210,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct virtnet_rq *
>  		xdp_rxq_info_unreg(&rq->xsk.xdp_rxq);
>  
>  	rq->xsk.pool = pool;
> +	rq->do_dma_unmap = !pool;
>  
>  	virtnet_rx_resume(vi, rq);
>  
> -- 
> 2.32.0.3.g01195cf9f





[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux