* [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM
@ 2026-03-23 18:01 Laurent Vivier
2026-03-23 18:15 ` Laurent Vivier
2026-03-23 22:40 ` David Gibson
0 siblings, 2 replies; 4+ messages in thread
From: Laurent Vivier @ 2026-03-23 18:01 UTC (permalink / raw)
To: passt-dev; +Cc: Laurent Vivier
According to the virtio-net specification, when the VIRTIO_NET_F_GUEST_CSUM
is negotiated, the device can set VIRTIO_NET_HDR_F_DATA_VALID in the
virtio-net header to indicate that packet checksums have been validated,
allowing the guest to skip verification. Without this feature, the device
must provide fully checksummed packets.
The vhost-user TCP and UDP paths were unconditionally skipping checksum
computation, regardless of whether GUEST_CSUM was negotiated. This
went undetected with Linux guests because Linux's virtio-net driver
honours VIRTIO_NET_HDR_F_DATA_VALID regardless of whether
VIRTIO_NET_F_GUEST_CSUM was negotiated, marking such packets as
CHECKSUM_UNNECESSARY and skipping verification.
iPXE, however, does not negotiate GUEST_CSUM, ignores the DATA_VALID
flag entirely, and always verifies checksums. This caused TCP
connections to fail: the SYN-ACK had a zero TCP checksum, iPXE rejected
it, and the connection timed out in SYN_RCVD.
Adding --pcap happened to mask the bug, because the pcap code path
forces checksum computation to ensure correct captures.
Offer VIRTIO_NET_F_GUEST_CSUM in the device features, and only skip
checksum computation when the guest has actually negotiated it. When
GUEST_CSUM is not negotiated, always compute valid checksums as required
by the specification.
We keep setting VIRTIO_NET_HDR_F_DATA_VALID unconditionally in
VU_HEADER: when GUEST_CSUM is negotiated, the flag lets the guest skip
checksum verification; when it is not, the spec says the guest should
ignore the flags field, so setting it is harmless.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
Notes:
Based-on: 20260323165259.1253482-1-lvivier@redhat.com
tcp_vu.c | 8 ++++++--
udp_vu.c | 6 ++++--
vhost_user.c | 1 +
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/tcp_vu.c b/tcp_vu.c
index 776b47aea18c..2ab56f25a9be 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -172,7 +172,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
seq--;
payload = IOV_TAIL(flags_elem[0].in_sg, iov_cnt, VNET_HLEN);
- tcp_fill_headers(c, conn, CONN_V4(conn), &payload, -1, seq, !*c->pcap);
+ tcp_fill_headers(c, conn, CONN_V4(conn), &payload, -1, seq,
+ vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) &&
+ !*c->pcap);
if (*c->pcap)
pcap_iov(flags_elem[0].in_sg, iov_cnt, VNET_HLEN);
@@ -512,7 +514,9 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
check = -1;
previous_dlen = dlen;
- tcp_vu_prepare(c, conn, iov, iov_cnt, &check, !*c->pcap, push);
+ tcp_vu_prepare(c, conn, iov, iov_cnt, &check,
+ vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) &&
+ !*c->pcap, push);
if (*c->pcap)
pcap_iov(iov, iov_cnt, VNET_HLEN);
diff --git a/udp_vu.c b/udp_vu.c
index 80391b4f8788..7ed271403481 100644
--- a/udp_vu.c
+++ b/udp_vu.c
@@ -223,10 +223,12 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx)
vu_set_vnethdr(iov_vu[0].iov_base, elem_used);
iov_drop_header(&data, VNET_HLEN);
udp_vu_prepare(c, &data, toside);
- if (*c->pcap) {
+ if (!vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) ||
+ *c->pcap) {
udp_vu_csum(toside, &data);
- pcap_iov(data.iov, data.cnt, data.off);
}
+ if (*c->pcap)
+ pcap_iov(data.iov, data.cnt, data.off);
vu_flush(vdev, vq, elem, elem_used);
}
}
diff --git a/vhost_user.c b/vhost_user.c
index 75665ec6522f..08a7b2d74099 100644
--- a/vhost_user.c
+++ b/vhost_user.c
@@ -322,6 +322,7 @@ static bool vu_get_features_exec(struct vu_dev *vdev,
{
uint64_t features =
1ULL << VIRTIO_F_VERSION_1 |
+ 1ULL << VIRTIO_NET_F_GUEST_CSUM |
1ULL << VIRTIO_NET_F_MRG_RXBUF |
1ULL << VHOST_F_LOG_ALL |
1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM
2026-03-23 18:01 [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM Laurent Vivier
@ 2026-03-23 18:15 ` Laurent Vivier
2026-03-23 22:41 ` David Gibson
2026-03-23 22:40 ` David Gibson
1 sibling, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2026-03-23 18:15 UTC (permalink / raw)
To: passt-dev
On 3/23/26 19:01, Laurent Vivier wrote:
> iPXE, however, does not negotiate GUEST_CSUM, ignores the DATA_VALID
> flag entirely, and always verifies checksums. This caused TCP
> connections to fail: the SYN-ACK had a zero TCP checksum, iPXE rejected
> it, and the connection timed out in SYN_RCVD.
And if you're wondering who's behind this laziness, check the author's name...
https://gitlab.com/qemu-project/ipxe/-/blob/master/src/drivers/net/virtio-net.c?ref_type=heads#L8
Thanks,
Laurent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM
2026-03-23 18:01 [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM Laurent Vivier
2026-03-23 18:15 ` Laurent Vivier
@ 2026-03-23 22:40 ` David Gibson
1 sibling, 0 replies; 4+ messages in thread
From: David Gibson @ 2026-03-23 22:40 UTC (permalink / raw)
To: Laurent Vivier; +Cc: passt-dev
[-- Attachment #1: Type: text/plain, Size: 4441 bytes --]
On Mon, Mar 23, 2026 at 07:01:49PM +0100, Laurent Vivier wrote:
> According to the virtio-net specification, when the VIRTIO_NET_F_GUEST_CSUM
> is negotiated, the device can set VIRTIO_NET_HDR_F_DATA_VALID in the
> virtio-net header to indicate that packet checksums have been validated,
> allowing the guest to skip verification. Without this feature, the device
> must provide fully checksummed packets.
>
> The vhost-user TCP and UDP paths were unconditionally skipping checksum
> computation, regardless of whether GUEST_CSUM was negotiated. This
> went undetected with Linux guests because Linux's virtio-net driver
> honours VIRTIO_NET_HDR_F_DATA_VALID regardless of whether
> VIRTIO_NET_F_GUEST_CSUM was negotiated, marking such packets as
> CHECKSUM_UNNECESSARY and skipping verification.
>
> iPXE, however, does not negotiate GUEST_CSUM, ignores the DATA_VALID
> flag entirely, and always verifies checksums. This caused TCP
> connections to fail: the SYN-ACK had a zero TCP checksum, iPXE rejected
> it, and the connection timed out in SYN_RCVD.
>
> Adding --pcap happened to mask the bug, because the pcap code path
> forces checksum computation to ensure correct captures.
>
> Offer VIRTIO_NET_F_GUEST_CSUM in the device features, and only skip
> checksum computation when the guest has actually negotiated it. When
> GUEST_CSUM is not negotiated, always compute valid checksums as required
> by the specification.
>
> We keep setting VIRTIO_NET_HDR_F_DATA_VALID unconditionally in
> VU_HEADER: when GUEST_CSUM is negotiated, the flag lets the guest skip
> checksum verification; when it is not, the spec says the guest should
> ignore the flags field, so setting it is harmless.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>
> Notes:
> Based-on: 20260323165259.1253482-1-lvivier@redhat.com
>
> tcp_vu.c | 8 ++++++--
> udp_vu.c | 6 ++++--
> vhost_user.c | 1 +
> 3 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/tcp_vu.c b/tcp_vu.c
> index 776b47aea18c..2ab56f25a9be 100644
> --- a/tcp_vu.c
> +++ b/tcp_vu.c
> @@ -172,7 +172,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
> seq--;
>
> payload = IOV_TAIL(flags_elem[0].in_sg, iov_cnt, VNET_HLEN);
> - tcp_fill_headers(c, conn, CONN_V4(conn), &payload, -1, seq, !*c->pcap);
> + tcp_fill_headers(c, conn, CONN_V4(conn), &payload, -1, seq,
> + vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) &&
> + !*c->pcap);
>
> if (*c->pcap)
> pcap_iov(flags_elem[0].in_sg, iov_cnt, VNET_HLEN);
> @@ -512,7 +514,9 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
> check = -1;
> previous_dlen = dlen;
>
> - tcp_vu_prepare(c, conn, iov, iov_cnt, &check, !*c->pcap, push);
> + tcp_vu_prepare(c, conn, iov, iov_cnt, &check,
> + vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) &&
> + !*c->pcap, push);
>
> if (*c->pcap)
> pcap_iov(iov, iov_cnt, VNET_HLEN);
> diff --git a/udp_vu.c b/udp_vu.c
> index 80391b4f8788..7ed271403481 100644
> --- a/udp_vu.c
> +++ b/udp_vu.c
> @@ -223,10 +223,12 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx)
> vu_set_vnethdr(iov_vu[0].iov_base, elem_used);
> iov_drop_header(&data, VNET_HLEN);
> udp_vu_prepare(c, &data, toside);
> - if (*c->pcap) {
> + if (!vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM) ||
> + *c->pcap) {
> udp_vu_csum(toside, &data);
> - pcap_iov(data.iov, data.cnt, data.off);
> }
> + if (*c->pcap)
> + pcap_iov(data.iov, data.cnt, data.off);
> vu_flush(vdev, vq, elem, elem_used);
> }
> }
> diff --git a/vhost_user.c b/vhost_user.c
> index 75665ec6522f..08a7b2d74099 100644
> --- a/vhost_user.c
> +++ b/vhost_user.c
> @@ -322,6 +322,7 @@ static bool vu_get_features_exec(struct vu_dev *vdev,
> {
> uint64_t features =
> 1ULL << VIRTIO_F_VERSION_1 |
> + 1ULL << VIRTIO_NET_F_GUEST_CSUM |
> 1ULL << VIRTIO_NET_F_MRG_RXBUF |
> 1ULL << VHOST_F_LOG_ALL |
> 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;
> --
> 2.53.0
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM
2026-03-23 18:15 ` Laurent Vivier
@ 2026-03-23 22:41 ` David Gibson
0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2026-03-23 22:41 UTC (permalink / raw)
To: Laurent Vivier; +Cc: passt-dev
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
On Mon, Mar 23, 2026 at 07:15:36PM +0100, Laurent Vivier wrote:
> On 3/23/26 19:01, Laurent Vivier wrote:
> > iPXE, however, does not negotiate GUEST_CSUM, ignores the DATA_VALID
> > flag entirely, and always verifies checksums. This caused TCP
> > connections to fail: the SYN-ACK had a zero TCP checksum, iPXE rejected
> > it, and the connection timed out in SYN_RCVD.
>
> And if you're wondering who's behind this laziness, check the author's name...
>
> https://gitlab.com/qemu-project/ipxe/-/blob/master/src/drivers/net/virtio-net.c?ref_type=heads#L8
Aw man, not that guy!
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-23 22:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-23 18:01 [PATCH] vhost_user: Offer VIRTIO_NET_F_GUEST_CSUM Laurent Vivier
2026-03-23 18:15 ` Laurent Vivier
2026-03-23 22:41 ` David Gibson
2026-03-23 22:40 ` David Gibson
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).