* [RFC] virtio: VirtualBox GSO workaround
@ 2026-12-02 20:10 Morten Brørup
2026-12-02 20:22 ` Stephen Hemminger
2026-12-03 1:30 ` Stephen Hemminger
0 siblings, 2 replies; 7+ messages in thread
From: Morten Brørup @ 2026-12-02 20:10 UTC (permalink / raw)
To: Maxime Coquelin, Chenbo Xia; +Cc: dev, Robin Jarry, David Marchand
VirtIO PMD maintainers,
VirtualBox has a well known issue:
When a packet is received in a VirtualBox host by a physical interface using GSO, VirtualBox bridges that packet as-is (i.e. with VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into the guest, even when the guest's virtio port is configured without any RX offload.
When the application has configured the port without RX offload, the application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it expects the hardware/driver has not checked the TCP checksum), and when it checks the TCP checksum, it discards the packet as being invalid. (Or if the application forwards the packet with an incremental TCP checksum update, the packet will remain invalid, and will be discarded by an on-path router with TCP checksum validation or when reaching its ultimate destination.)
The virtio driver doesn't do any RX offload if RX offload is disabled.
As a workaround, I propose that the virtio driver calculates the TCP checksum and sets the TCP checksum field for GSO packets when RX offload is disabled. The host should have done that, but VirtualBox doesn't.
What do you think about such a workaround?
Note: The workaround has only been applied to virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio.
Diff for DPDK 25.11.2 below. Work in progress, code not yet tested.
Venlig hilsen / Kind regards,
-Morten Brørup
diff -wup virtio_rxtx.c.orig virtio_rxtx.c
--- virtio_rxtx.c.orig 2026-12-02 17:54:35.010252966 +0000
+++ virtio_rxtx.c 2026-12-02 19:53:51.924504527 +0000
@@ -916,7 +916,7 @@ virtio_rx_update_hash_report(struct rte_
/* Optionally fill offload information in structure */
static inline int
-virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)
+virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr, const uint8_t has_rx_offload)
{
struct rte_net_hdr_lens hdr_lens;
uint32_t hdrlen, ptype;
@@ -937,9 +937,9 @@ virtio_rx_offload(struct rte_mbuf *m, st
if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len;
- if (hdr->csum_start <= hdrlen && l4_supported) {
+ if (has_rx_offload && hdr->csum_start <= hdrlen && l4_supported) {
m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_NONE;
- } else {
+ } else if (has_rx_offload || (hdr->csum_start <= hdrlen && l4_supported)) {
/* Unknown proto or tunnel, do sw cksum. We can assume
* the cksum field is in the first segment since the
* buffers we provided to the host are large enough.
@@ -976,8 +976,9 @@ virtio_rx_offload(struct rte_mbuf *m, st
switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
case VIRTIO_NET_HDR_GSO_TCPV4:
case VIRTIO_NET_HDR_GSO_TCPV6:
- m->ol_flags |= RTE_MBUF_F_RX_LRO |
- RTE_MBUF_F_RX_L4_CKSUM_NONE;
+ m->ol_flags |= has_rx_offload ?
+ RTE_MBUF_F_RX_LRO | RTE_MBUF_F_RX_L4_CKSUM_NONE :
+ RTE_MBUF_F_RX_LRO;
break;
default:
return -EINVAL;
@@ -1048,7 +1049,7 @@ virtio_recv_pkts(void *rx_queue, struct
if (hw->vlan_strip)
rte_vlan_strip(rxm);
- if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) {
+ if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr, 1) < 0) {
virtio_discard_rxbuf(vq, rxm);
rxvq->stats.errors++;
continue;
@@ -1153,7 +1154,7 @@ virtio_recv_pkts_packed(void *rx_queue,
if (hw->vlan_strip)
rte_vlan_strip(rxm);
- if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) {
+ if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr, 1) < 0) {
virtio_discard_rxbuf(vq, rxm);
rxvq->stats.errors++;
continue;
@@ -1275,7 +1276,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
prev = rxm;
if (vq->hw->has_rx_offload &&
- virtio_rx_offload(rxm, &header->hdr) < 0) {
+ virtio_rx_offload(rxm, &header->hdr, 1) < 0) {
virtio_discard_rxbuf_inorder(vq, rxm);
rxvq->stats.errors++;
continue;
@@ -1452,8 +1453,9 @@ virtio_recv_mergeable_pkts(void *rx_queu
rx_pkts[nb_rx] = rxm;
prev = rxm;
- if (hw->has_rx_offload &&
- virtio_rx_offload(rxm, &header->hdr) < 0) {
+ /* Workaround for VirtualBox unconditional GSO: Check seg_num too. */
+ if ((hw->has_rx_offload || seg_num > 1) &&
+ virtio_rx_offload(rxm, &header->hdr, hw->has_rx_offload) < 0) {
virtio_discard_rxbuf(vq, rxm);
rxvq->stats.errors++;
continue;
@@ -1624,7 +1626,7 @@ virtio_recv_mergeable_pkts_packed(void *
prev = rxm;
if (hw->has_rx_offload &&
- virtio_rx_offload(rxm, &header->hdr) < 0) {
+ virtio_rx_offload(rxm, &header->hdr, 1) < 0) {
virtio_discard_rxbuf(vq, rxm);
rxvq->stats.errors++;
continue;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:10 [RFC] virtio: VirtualBox GSO workaround Morten Brørup @ 2026-12-02 20:22 ` Stephen Hemminger 2026-12-02 20:31 ` Morten Brørup 2026-12-03 1:30 ` Stephen Hemminger 1 sibling, 1 reply; 7+ messages in thread From: Stephen Hemminger @ 2026-12-02 20:22 UTC (permalink / raw) To: Morten Brørup Cc: Maxime Coquelin, Chenbo Xia, dev, Robin Jarry, David Marchand On Wed, 2 Dec 2026 21:10:42 +0100 Morten Brørup <mb@smartsharesystems.com> wrote: > VirtIO PMD maintainers, > > VirtualBox has a well known issue: > When a packet is received in a VirtualBox host by a physical interface using GSO, VirtualBox bridges that packet as-is (i.e. with VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into the guest, even when the guest's virtio port is configured without any RX offload. > When the application has configured the port without RX offload, the application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it expects the hardware/driver has not checked the TCP checksum), and when it checks the TCP checksum, it discards the packet as being invalid. (Or if the application forwards the packet with an incremental TCP checksum update, the packet will remain invalid, and will be discarded by an on-path router with TCP checksum validation or when reaching its ultimate destination.) > The virtio driver doesn't do any RX offload if RX offload is disabled. > > As a workaround, I propose that the virtio driver calculates the TCP checksum and sets the TCP checksum field for GSO packets when RX offload is disabled. The host should have done that, but VirtualBox doesn't. > What do you think about such a workaround? > > Note: The workaround has only been applied to virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio. > > Diff for DPDK 25.11.2 below. Work in progress, code not yet tested. Seems to me that virtio already supports negotiation with host about offloads. Maybe add a check in the negotiation and mask off those bits if virtualbox is detected. It is a case of host lying about support then. ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:22 ` Stephen Hemminger @ 2026-12-02 20:31 ` Morten Brørup 2026-12-02 20:44 ` Maxime Coquelin 0 siblings, 1 reply; 7+ messages in thread From: Morten Brørup @ 2026-12-02 20:31 UTC (permalink / raw) To: Stephen Hemminger Cc: Maxime Coquelin, Chenbo Xia, dev, Robin Jarry, David Marchand > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > Sent: Wednesday, 2 December 2026 21.22 > > On Wed, 2 Dec 2026 21:10:42 +0100 > Morten Brørup <mb@smartsharesystems.com> wrote: > > > VirtIO PMD maintainers, > > > > VirtualBox has a well known issue: > > When a packet is received in a VirtualBox host by a physical > interface using GSO, VirtualBox bridges that packet as-is (i.e. with > VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into > the guest, even when the guest's virtio port is configured without any > RX offload. > > When the application has configured the port without RX offload, the > application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it > expects the hardware/driver has not checked the TCP checksum), and when > it checks the TCP checksum, it discards the packet as being invalid. > (Or if the application forwards the packet with an incremental TCP > checksum update, the packet will remain invalid, and will be discarded > by an on-path router with TCP checksum validation or when reaching its > ultimate destination.) > > The virtio driver doesn't do any RX offload if RX offload is > disabled. > > > > As a workaround, I propose that the virtio driver calculates the TCP > checksum and sets the TCP checksum field for GSO packets when RX > offload is disabled. The host should have done that, but VirtualBox > doesn't. > > What do you think about such a workaround? > > > > Note: The workaround has only been applied to > virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio. > > > > Diff for DPDK 25.11.2 below. Work in progress, code not yet tested. > > > Seems to me that virtio already supports negotiation with host about > offloads. > Maybe add a check in the negotiation and mask off those bits if > virtualbox is detected. > It is a case of host lying about support then. This workaround is for guest applications NOT requesting any RX offloads from the virtio ports. The VirtualBox host passes "incomplete" packets to the guest, expecting the guest's virtio driver to do the RX offloads, which the virtio driver doesn't when RX offload is disabled. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:31 ` Morten Brørup @ 2026-12-02 20:44 ` Maxime Coquelin 2026-12-02 20:51 ` Maxime Coquelin 0 siblings, 1 reply; 7+ messages in thread From: Maxime Coquelin @ 2026-12-02 20:44 UTC (permalink / raw) To: Morten Brørup Cc: Stephen Hemminger, Chenbo Xia, dev, Robin Jarry, David Marchand On Wed, Dec 2, 2026 at 9:32 PM Morten Brørup <mb@smartsharesystems.com> wrote: > > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > Sent: Wednesday, 2 December 2026 21.22 > > > > On Wed, 2 Dec 2026 21:10:42 +0100 > > Morten Brørup <mb@smartsharesystems.com> wrote: > > > > > VirtIO PMD maintainers, > > > > > > VirtualBox has a well known issue: > > > When a packet is received in a VirtualBox host by a physical > > interface using GSO, VirtualBox bridges that packet as-is (i.e. with > > VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into > > the guest, even when the guest's virtio port is configured without any > > RX offload. > > > When the application has configured the port without RX offload, the > > application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it > > expects the hardware/driver has not checked the TCP checksum), and when > > it checks the TCP checksum, it discards the packet as being invalid. > > (Or if the application forwards the packet with an incremental TCP > > checksum update, the packet will remain invalid, and will be discarded > > by an on-path router with TCP checksum validation or when reaching its > > ultimate destination.) > > > The virtio driver doesn't do any RX offload if RX offload is > > disabled. > > > > > > As a workaround, I propose that the virtio driver calculates the TCP > > checksum and sets the TCP checksum field for GSO packets when RX > > offload is disabled. The host should have done that, but VirtualBox > > doesn't. > > > What do you think about such a workaround? > > > > > > Note: The workaround has only been applied to > > virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio. > > > > > > Diff for DPDK 25.11.2 below. Work in progress, code not yet tested. > > > > > > Seems to me that virtio already supports negotiation with host about > > offloads. > > Maybe add a check in the negotiation and mask off those bits if > > virtualbox is detected. > > It is a case of host lying about support then. > > This workaround is for guest applications NOT requesting any RX offloads from the virtio ports. > > The VirtualBox host passes "incomplete" packets to the guest, expecting the guest's virtio driver to do the RX offloads, which the virtio driver doesn't when RX offload is disabled. > Ok, but it's going to have a performance impact for other hosts than VirtualBox properly implementing the feature they advertise, right? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:44 ` Maxime Coquelin @ 2026-12-02 20:51 ` Maxime Coquelin 2026-12-03 1:21 ` Stephen Hemminger 0 siblings, 1 reply; 7+ messages in thread From: Maxime Coquelin @ 2026-12-02 20:51 UTC (permalink / raw) To: Morten Brørup Cc: Stephen Hemminger, Chenbo Xia, dev, Robin Jarry, David Marchand On Wed, Dec 2, 2026 at 9:44 PM Maxime Coquelin <maxime.coquelin@redhat.com> wrote: > > On Wed, Dec 2, 2026 at 9:32 PM Morten Brørup <mb@smartsharesystems.com> wrote: > > > > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > > Sent: Wednesday, 2 December 2026 21.22 > > > > > > On Wed, 2 Dec 2026 21:10:42 +0100 > > > Morten Brørup <mb@smartsharesystems.com> wrote: > > > > > > > VirtIO PMD maintainers, > > > > > > > > VirtualBox has a well known issue: > > > > When a packet is received in a VirtualBox host by a physical > > > interface using GSO, VirtualBox bridges that packet as-is (i.e. with > > > VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into > > > the guest, even when the guest's virtio port is configured without any > > > RX offload. > > > > When the application has configured the port without RX offload, the > > > application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it > > > expects the hardware/driver has not checked the TCP checksum), and when > > > it checks the TCP checksum, it discards the packet as being invalid. > > > (Or if the application forwards the packet with an incremental TCP > > > checksum update, the packet will remain invalid, and will be discarded > > > by an on-path router with TCP checksum validation or when reaching its > > > ultimate destination.) > > > > The virtio driver doesn't do any RX offload if RX offload is > > > disabled. > > > > > > > > As a workaround, I propose that the virtio driver calculates the TCP > > > checksum and sets the TCP checksum field for GSO packets when RX > > > offload is disabled. The host should have done that, but VirtualBox > > > doesn't. > > > > What do you think about such a workaround? > > > > > > > > Note: The workaround has only been applied to > > > virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio. > > > > > > > > Diff for DPDK 25.11.2 below. Work in progress, code not yet tested. > > > > > > > > > Seems to me that virtio already supports negotiation with host about > > > offloads. > > > Maybe add a check in the negotiation and mask off those bits if > > > virtualbox is detected. > > > It is a case of host lying about support then. > > > > This workaround is for guest applications NOT requesting any RX offloads from the virtio ports. > > > > The VirtualBox host passes "incomplete" packets to the guest, expecting the guest's virtio driver to do the RX offloads, which the virtio driver doesn't when RX offload is disabled. > > > > Ok, but it's going to have a performance impact for other hosts than > VirtualBox properly implementing the feature they advertise, right? By the way, it seems VirtualBox is opensource, maybe better to fix the issue there? https://github.com/VirtualBox/virtualbox/blob/main/src/VBox/Devices/Network/DevVirtioNet.cpp ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:51 ` Maxime Coquelin @ 2026-12-03 1:21 ` Stephen Hemminger 0 siblings, 0 replies; 7+ messages in thread From: Stephen Hemminger @ 2026-12-03 1:21 UTC (permalink / raw) To: Maxime Coquelin Cc: Morten Brørup, Chenbo Xia, dev, Robin Jarry, David Marchand On Wed, 2 Dec 2026 21:51:08 +0100 Maxime Coquelin <maxime.coquelin@redhat.com> wrote: > By the way, it seems VirtualBox is opensource, maybe better to fix the > issue there? > https://github.com/VirtualBox/virtualbox/blob/main/src/VBox/Devices/Network/DevVirtioNet.cpp AI says it is a bug fixed by: --- a/src/VBox/Devices/Network/DevVirtioNet.cpp 2026-12-02 17:05:24.097479346 -0800 +++ b/src/VBox/Devices/Network/DevVirtioNet.cpp 2026-12-02 17:05:24.169379356 -0800 @@ -2190,6 +2190,22 @@ { LogFunc(("[%s] (%RTmac) \n", pThis->szInst, pvBuf)); + /* + * VirtIO 1.1, 5.1.6.4.1: gso_type and NEEDS_CSUM may only be used if the + * guest negotiated the matching GUEST_xxx feature. Otherwise fail, the + * driver below then segments and checksums in software. + */ + bool fGuestCanRecv; + switch (pGso->u8Type) + { + case PDMNETWORKGSOTYPE_IPV4_TCP: fGuestCanRecv = FEATURE_ENABLED(GUEST_TSO4); break; + case PDMNETWORKGSOTYPE_IPV6_TCP: fGuestCanRecv = FEATURE_ENABLED(GUEST_TSO6); break; + case PDMNETWORKGSOTYPE_IPV4_UDP: fGuestCanRecv = FEATURE_ENABLED(GUEST_UFO); break; + default: fGuestCanRecv = false; break; + } + if (!fGuestCanRecv || FEATURE_DISABLED(GUEST_CSUM)) + return VERR_NOT_SUPPORTED; + rxPktHdr.uFlags = VIRTIONET_HDR_F_NEEDS_CSUM; rxPktHdr.uHdrLen = pGso->cbHdrsTotal; rxPktHdr.uGsoSize = pGso->cbMaxSeg; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] virtio: VirtualBox GSO workaround 2026-12-02 20:10 [RFC] virtio: VirtualBox GSO workaround Morten Brørup 2026-12-02 20:22 ` Stephen Hemminger @ 2026-12-03 1:30 ` Stephen Hemminger 1 sibling, 0 replies; 7+ messages in thread From: Stephen Hemminger @ 2026-12-03 1:30 UTC (permalink / raw) To: Morten Brørup Cc: Maxime Coquelin, Chenbo Xia, dev, Robin Jarry, David Marchand [-- Attachment #1: Type: text/plain, Size: 2378 bytes --] On Wed, 2 Dec 2026 21:10:42 +0100 Morten Brørup <mb@smartsharesystems.com> wrote: > VirtIO PMD maintainers, > > VirtualBox has a well known issue: > When a packet is received in a VirtualBox host by a physical interface using GSO, VirtualBox bridges that packet as-is (i.e. with VIRTIO_NET_HDR_F_NEEDS_CSUM and invalid TCP checksum field value) into the guest, even when the guest's virtio port is configured without any RX offload. > When the application has configured the port without RX offload, the application doesn't consider RTE_MBUF_F_RX_L4_CKSUM_NONE (because it expects the hardware/driver has not checked the TCP checksum), and when it checks the TCP checksum, it discards the packet as being invalid. (Or if the application forwards the packet with an incremental TCP checksum update, the packet will remain invalid, and will be discarded by an on-path router with TCP checksum validation or when reaching its ultimate destination.) > The virtio driver doesn't do any RX offload if RX offload is disabled. > > As a workaround, I propose that the virtio driver calculates the TCP checksum and sets the TCP checksum field for GSO packets when RX offload is disabled. The host should have done that, but VirtualBox doesn't. > What do you think about such a workaround? > > Note: The workaround has only been applied to virtio_recv_mergeable_pkts(), which is used for VirtualBox virtio. > > Diff for DPDK 25.11.2 below. Work in progress, code not yet tested. > > Venlig hilsen / Kind regards, > -Morten Brørup AI review with Fable says this is wrong and incomplete: On the RFC itself, I would NAK it as posted: * Checksum is only half the problem. With LRO off, the app still gets a 64K GSO packet it never asked for. A forwarder will then exceed the egress MTU. A real driver workaround has to segment (rte_gso), not just checksum. * seg_num > 1 is the wrong test. A small GSO packet fits in one mbuf, and a jumbo frame is multi-seg without GSO. Test hdr->flags and hdr->gso_type instead. * It sets RTE_MBUF_F_RX_LRO with LRO not configured, which breaks the ethdev contract. * The else if condition is backwards. With has_rx_offload == 0 it skips the software checksum in exactly the unknown-proto/tunnel case the original else existed for. * Only one of five RX paths is covered. It proposes the two attached instead: [-- Attachment #2: 0001-net-virtio-fix-drop-of-multi-buffer-packet-on-offloa.patch --] [-- Type: text/x-patch, Size: 6157 bytes --] From 7f7fbf9188700d01f1d00c049b48afa74e2ce36c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger <stephen@networkplumber.org> Date: Wed, 2 Dec 2026 17:25:38 -0800 Subject: [PATCH 1/2] net/virtio: fix drop of multi-buffer packet on offload error When virtio_rx_offload() fails in the mergeable and in-order receive paths, only the first buffer of the packet is discarded. The remaining num_buffers - 1 buffers are still in the used ring and get parsed as new packets, with packet payload interpreted as virtio_net_hdr. This happens for any GSO packet the driver rejects: ECN bit set, gso_size of zero, or a gso_type other than TCPv4/TCPv6 (for example UFO from a device that sends it without GUEST_UFO being negotiated). Collect all the buffers of the packet first, then free the chain and count one error. Cc: stable@dpdk.org Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F2mfDETH9cBBVF3tcqkwcH --- drivers/net/virtio/virtio_rxtx.c | 87 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 1afb68b..7cdab4b 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -987,6 +987,24 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) return 0; } +/* + * A mergeable packet is complete: pass it up or drop it. + * The drop has to wait until here, the remaining buffers of the + * packet must be consumed first or they get parsed as new packets. + */ +static inline uint16_t +virtio_rx_mergeable_done(struct virtnet_rx *rxvq, struct rte_mbuf *m, bool drop) +{ + if (unlikely(drop)) { + rte_pktmbuf_free(m); + rxvq->stats.errors++; + return 0; + } + + virtio_rx_stats_updated(rxvq, m); + return 1; +} + #define DESC_PER_CACHELINE (RTE_CACHE_LINE_SIZE / sizeof(struct vring_desc)) uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) @@ -1207,6 +1225,7 @@ virtio_recv_pkts_inorder(void *rx_queue, struct virtio_hw *hw = vq->hw; struct rte_mbuf *rxm; struct rte_mbuf *prev = NULL; + bool drop = false; uint16_t nb_used, num, nb_rx; uint32_t len[VIRTIO_MBUF_BURST_SZ]; struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ]; @@ -1274,12 +1293,8 @@ virtio_recv_pkts_inorder(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - if (vq->hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0) { - virtio_discard_rxbuf_inorder(vq, rxm); - rxvq->stats.errors++; - continue; - } + drop = hw->has_rx_offload && + virtio_rx_offload(rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1302,10 +1317,9 @@ virtio_recv_pkts_inorder(void *rx_queue, seg_res -= 1; } - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } /* Last packet still need merge segments */ @@ -1332,10 +1346,9 @@ virtio_recv_pkts_inorder(void *rx_queue, }; seg_res -= rcv_cnt; - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } else { PMD_RX_LOG(ERR, "No enough segments for packet."); @@ -1390,6 +1403,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, struct virtio_hw *hw = vq->hw; struct rte_mbuf *rxm; struct rte_mbuf *prev = NULL; + bool drop = false; uint16_t nb_used, num, nb_rx = 0; uint32_t len[VIRTIO_MBUF_BURST_SZ]; struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ]; @@ -1452,12 +1466,8 @@ virtio_recv_mergeable_pkts(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - if (hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0) { - virtio_discard_rxbuf(vq, rxm); - rxvq->stats.errors++; - continue; - } + drop = hw->has_rx_offload && + virtio_rx_offload(rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1480,10 +1490,9 @@ virtio_recv_mergeable_pkts(void *rx_queue, seg_res -= 1; } - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } /* Last packet still need merge segments */ @@ -1510,10 +1519,9 @@ virtio_recv_mergeable_pkts(void *rx_queue, }; seg_res -= rcv_cnt; - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } else { PMD_RX_LOG(ERR, "No enough segments for packet."); @@ -1567,6 +1575,7 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, struct virtio_hw *hw = vq->hw; struct rte_mbuf *rxm; struct rte_mbuf *prev = NULL; + bool drop = false; uint16_t num, nb_rx = 0; uint32_t len[VIRTIO_MBUF_BURST_SZ]; struct rte_mbuf *rcv_pkts[VIRTIO_MBUF_BURST_SZ]; @@ -1623,12 +1632,8 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - if (hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0) { - virtio_discard_rxbuf(vq, rxm); - rxvq->stats.errors++; - continue; - } + drop = hw->has_rx_offload && + virtio_rx_offload(rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1655,10 +1660,9 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, seg_res -= 1; } - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } /* Last packet still need merge segments */ @@ -1689,10 +1693,9 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, extra_idx += 1; } seg_res -= rcv_cnt; - if (!seg_res) { - virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]); - nb_rx++; - } + if (!seg_res) + nb_rx += virtio_rx_mergeable_done(rxvq, + rx_pkts[nb_rx], drop); } rxvq->stats.packets += nb_rx; -- 2.43.0 [-- Attachment #3: 0002-net-virtio-drop-offload-packets-sent-without-negotia.patch --] [-- Type: text/x-patch, Size: 4333 bytes --] From c4c0f0a489045622360fffab0fdb06067209c01f Mon Sep 17 00:00:00 2001 From: Stephen Hemminger <stephen@networkplumber.org> Date: Wed, 2 Dec 2026 17:27:31 -0800 Subject: [PATCH 2/2] net/virtio: drop offload packets sent without negotiation If GUEST_CSUM and GUEST_TSO4/6 are not negotiated, the device must not set VIRTIO_NET_HDR_F_NEEDS_CSUM or a gso_type in the receive header. VirtualBox does it anyway when the host interface uses GRO. The driver ignores the header when no receive offload is enabled, so the application gets a packet with a partial checksum and larger than the MTU, with nothing in the mbuf to say so. It then fails checksum validation, or gets forwarded and dropped further down the path. Check the header in the non-vector receive paths. If the device violates the negotiation, drop the packet, count it in the error statistics and log the reason once. A compliant device never triggers this, so no hypervisor detection is needed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F2mfDETH9cBBVF3tcqkwcH --- drivers/net/virtio/virtio_rxtx.c | 53 +++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 7cdab4b..4ce9162 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -987,6 +987,46 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) return 0; } +/* Report once that the device ignores feature negotiation */ +static __rte_cold __rte_noinline void +virtio_rx_hdr_unexpected(const struct virtio_hw *hw, + const struct virtio_net_hdr *hdr) +{ + static bool warned; + + if (warned) + return; + warned = true; + + PMD_DRV_LOG(ERR, + "port %u: device sent flags %#x gso_type %#x without GUEST_CSUM/GUEST_TSO negotiated, dropping such packets", + hw->port_id, hdr->flags, hdr->gso_type); +} + +/* + * Process the receive header. + * + * If no receive offload feature was negotiated, the device is required + * to set neither NEEDS_CSUM nor a gso_type. Some devices do it anyway. + * The application did not ask for packets with a partial checksum or + * larger than MTU, so do not pass them up. + */ +static inline int +virtio_rx_hdr(const struct virtio_hw *hw, struct rte_mbuf *m, + struct virtio_net_hdr *hdr) +{ + if (hw->has_rx_offload) + return virtio_rx_offload(m, hdr); + + if (unlikely((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) || + hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)) { + virtio_rx_hdr_unexpected(hw, hdr); + return -EINVAL; + } + + return 0; +} + /* * A mergeable packet is complete: pass it up or drop it. * The drop has to wait until here, the remaining buffers of the @@ -1066,7 +1106,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) if (hw->vlan_strip) rte_vlan_strip(rxm); - if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) { + if (virtio_rx_hdr(hw, rxm, hdr) < 0) { virtio_discard_rxbuf(vq, rxm); rxvq->stats.errors++; continue; @@ -1171,7 +1211,7 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, if (hw->vlan_strip) rte_vlan_strip(rxm); - if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) { + if (virtio_rx_hdr(hw, rxm, hdr) < 0) { virtio_discard_rxbuf(vq, rxm); rxvq->stats.errors++; continue; @@ -1293,8 +1333,7 @@ virtio_recv_pkts_inorder(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1466,8 +1505,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); @@ -1632,8 +1670,7 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, rx_pkts[nb_rx] = rxm; prev = rxm; - drop = hw->has_rx_offload && - virtio_rx_offload(rxm, &header->hdr) < 0; + drop = virtio_rx_hdr(hw, rxm, &header->hdr) < 0; if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-03 1:30 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 20:10 [RFC] virtio: VirtualBox GSO workaround Morten Brørup 2026-12-02 20:22 ` Stephen Hemminger 2026-12-02 20:31 ` Morten Brørup 2026-12-02 20:44 ` Maxime Coquelin 2026-12-02 20:51 ` Maxime Coquelin 2026-12-03 1:21 ` Stephen Hemminger 2026-12-03 1:30 ` Stephen Hemminger
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.