All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] virtio: VirtualBox GSO workaround
@ 2026-12-02 20:10 Morten Brørup
  2026-12-02 20:22 ` Stephen Hemminger
  0 siblings, 1 reply; 5+ 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] 5+ 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
  0 siblings, 1 reply; 5+ 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] 5+ 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; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread

* Re: [RFC] virtio: VirtualBox GSO workaround
  2026-12-02 20:44     ` Maxime Coquelin
@ 2026-12-02 20:51       ` Maxime Coquelin
  0 siblings, 0 replies; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2026-12-02 20:51 UTC | newest]

Thread overview: 5+ 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

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.