public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH net] virtio-net: correct DMA unmap vq mismatch in virtnet_xsk_pool_enable()
@ 2026-03-20  1:35 Xuan Zhuo
  2026-03-20  9:45 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: Xuan Zhuo @ 2026-03-20  1:35 UTC (permalink / raw)
  To: netdev
  Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, virtualization

When enabling the XSK pool, the header DMA address is mapped against
the send queue's virtqueue (sq->vq). However, the error handling path
incorrectly attempts to unmap it against the receive queue's virtqueue
(rq->vq).

Ensure the unmap operation uses the same virtqueue used for mapping to
maintain DMA API consistency.

Fixes: 21a4e3ce6dc7 ("virtio_net: xsk: bind/unbind xsk for tx")
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 72d6a9c6a5a2..7c6f304b7be5 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -5917,7 +5917,7 @@ static int virtnet_xsk_pool_enable(struct net_device *dev,
 err_rq:
 	xsk_pool_dma_unmap(pool, 0);
 err_xsk_map:
-	virtqueue_unmap_single_attrs(rq->vq, hdr_dma, vi->hdr_len,
+	virtqueue_unmap_single_attrs(sq->vq, hdr_dma, vi->hdr_len,
 				     DMA_TO_DEVICE, 0);
 err_free_buffs:
 	kvfree(rq->xsk_buffs);
-- 
2.32.0.3.g01195cf9f


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] virtio-net: correct DMA unmap vq mismatch in virtnet_xsk_pool_enable()
  2026-03-20  1:35 [PATCH net] virtio-net: correct DMA unmap vq mismatch in virtnet_xsk_pool_enable() Xuan Zhuo
@ 2026-03-20  9:45 ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2026-03-20  9:45 UTC (permalink / raw)
  To: Xuan Zhuo
  Cc: netdev, Jason Wang, Eugenio Pérez, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	virtualization

Patch itself is fine, thanks!
Yet something to improve in the log:

On Fri, Mar 20, 2026 at 09:35:31AM +0800, Xuan Zhuo wrote:
> When enabling the XSK pool, the header DMA address is mapped against
> the send queue's virtqueue (sq->vq). However, the error handling path
> incorrectly attempts to unmap it against the receive queue's virtqueue
> (rq->vq).
> 
> Ensure the unmap operation uses the same virtqueue used for mapping to
> maintain DMA API consistency.


DMA API is fine: we end up with:

void virtqueue_unmap_page_attrs(const struct virtqueue *_vq,
                                dma_addr_t map_handle,
                                size_t size, enum dma_data_direction dir,
                                unsigned long attrs)
{
        const struct vring_virtqueue *vq = to_vvq(_vq);
        struct virtio_device *vdev = _vq->vdev;

        if (vdev->map)
                vdev->map->unmap_page(vq->map,
                                      map_handle, size, dir, attrs);
        else
                dma_unmap_page_attrs(vring_dma_dev(vq), map_handle,
                                     size, dir, attrs);
}
EXPORT_SYMBOL_GPL(virtqueue_unmap_page_attrs);


So what matters is the device and it's the same for all vqs.
A better way to put it:



	While harmless (both vqs share the same device for DMA) it is cleaner
	to map and unmap using the same vq.


> Fixes: 21a4e3ce6dc7 ("virtio_net: xsk: bind/unbind xsk for tx")


And I'd drop the fixes tag.


> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>





> ---
>  drivers/net/virtio_net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 72d6a9c6a5a2..7c6f304b7be5 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -5917,7 +5917,7 @@ static int virtnet_xsk_pool_enable(struct net_device *dev,
>  err_rq:
>  	xsk_pool_dma_unmap(pool, 0);
>  err_xsk_map:
> -	virtqueue_unmap_single_attrs(rq->vq, hdr_dma, vi->hdr_len,
> +	virtqueue_unmap_single_attrs(sq->vq, hdr_dma, vi->hdr_len,
>  				     DMA_TO_DEVICE, 0);
>  err_free_buffs:
>  	kvfree(rq->xsk_buffs);
> -- 
> 2.32.0.3.g01195cf9f


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-20  9:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20  1:35 [PATCH net] virtio-net: correct DMA unmap vq mismatch in virtnet_xsk_pool_enable() Xuan Zhuo
2026-03-20  9:45 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox