From: Stephen Hemminger <stephen@networkplumber.org>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: "Maxime Coquelin" <maxime.coquelin@redhat.com>,
"Chenbo Xia" <chenbox@nvidia.com>, <dev@dpdk.org>,
"Robin Jarry" <rjarry@redhat.com>,
"David Marchand" <david.marchand@redhat.com>
Subject: Re: [RFC] virtio: VirtualBox GSO workaround
Date: Wed, 2 Dec 2026 17:30:12 -0800 [thread overview]
Message-ID: <20261202173012.55d5cac0@phoenix.local> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35F65B61@smartserver.smartshare.dk>
[-- 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
prev parent reply other threads:[~2026-12-03 1:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202173012.55d5cac0@phoenix.local \
--to=stephen@networkplumber.org \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=mb@smartsharesystems.com \
--cc=rjarry@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox