]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vhost-net: fix TX stall when vhost owns virtio-net header
authorEnrico Zanda <enrico.zanda@arm.com>
Wed, 8 Jul 2026 15:22:42 +0000 (16:22 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 21 Jul 2026 11:25:34 +0000 (13:25 +0200)
When vhost owns the virtio-net header, i.e. when
VHOST_NET_F_VIRTIO_NET_HDR is negotiated, sock_hlen is 0,
meaning that no header will be forwarded to the TAP device.

In the current vhost_net_build_xdp() implementation,
when sock_hlen == 0, the gso pointer can point at the start of the
Ethernet frame instead of a virtio-net header.
This results in a wrong interpretation of the destination MAC address
bytes as struct virtio_net_hdr fields.

This can, for some MAC addresses, trigger -EINVAL and return early
before the TX descriptor is completed, which can stall vhost-net TX.

Before 97b2409f28e0, the gso pointer was set to the zeroed padding area,
using it as a synthetic virtio-net header. Restore that behavior.

Fixes: 97b2409f28e0 ("vhost-net: reduce one userspace copy when building XDP buff")
Signed-off-by: Enrico Zanda <enrico.zanda@arm.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20260708152242.2268848-1-enrico.zanda@arm.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/vhost/net.c

index 77b59f49bddb3d79c956a93dc0d360475a71d220..3e72b9c6af0ca4aab74add2dcfa72c903f84e67a 100644 (file)
@@ -731,10 +731,12 @@ static int vhost_net_build_xdp(struct vhost_net_virtqueue *nvq,
                goto err;
        }
 
-       gso = buf + pad - sock_hlen;
-
-       if (!sock_hlen)
+       if (!sock_hlen) {
                memset(buf, 0, pad);
+               gso = buf;
+       } else {
+               gso = buf + pad - sock_hlen;
+       }
 
        if ((gso->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
            vhost16_to_cpu(vq, gso->csum_start) +