Bug 165059 - vtnet(4): Networking breaks with a router using virtio net driver on KVM host
Summary: vtnet(4): Networking breaks with a router using virtio net driver on KVM host
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 9.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Michael Tuexen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-12 21:20 UTC by bfo2608
Modified: 2025-10-12 02:58 UTC (History)
50 users (show)

See Also:
koobs: maintainer-feedback? (bryanv)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bfo2608 2012-02-12 21:20:11 UTC
When the router for a FreeBSD guest on KVM is also a FreeBSD guest on
the same KVM host, and which is using the virtio network driver from
virtio_kmod, ping will work between guests on different subnets, but
no userland network daemons will respond. If I switch to the e1000
driver on the router, but change nothing else, everything works correctly.

Fix: 

Unknown.
How-To-Repeat: I created three FreeBSD guests on one Linux KVM host. I am using bridged
networking on the KVM host, as br0 and br1. One of the guests has two
network interfaces and acts as a router between two subnets, as follows:

router1: br0, 192.168.1.1; br1, 192.168.2.1
client1: br0, 192.168.1.100; default route 192.168.1.1
client2: br1, 192.168.2.100; default route 192.168.2.1

I configured virtio network interfaces on all three hosts. I enabled
forwarding on router1, but no packet filtering. No NAT is in use.

Result:

    * client1 can ping client2, and vice versa.
    * ssh works from router1 to client1 and vice versa, and from router1
      to client2 and vice versa.
    * ssh from client1 to client2 will fail (and vice versa); the client
      simply hangs indefinitely while trying to connect. 
    * tcpdump on client2 will show that the SYN is arriving at client2
      port 22, but client2 never replies, nor generates any debug or log
      output that suggests it ever saw the connection attempt.
    * any other userland network service I try (both tcp and udp) will
      show the same thing -- packets arrive at client2 from client1, but
      the daemon seems to never see them. Since ping works, I know the
      kernel is getting them.
    * If I switch back to the e1000 driver on router1, but make no other
      changes, and make no changes at all to client1 and client2, then
      ssh will work properly from client1 to client2 and the problem is resolved.
    * If I let router1 continue to use virtio interfaces, but move router1
      onto a different KVM host -- so that the traffic from client1 to client2
      must leave the KVM host via the bridged interface and then return on a
      different interface - then ssh will work properly from client1 to
      client2 and the problem is resolved.

KVM guests: FreeBSD 9
virtio-kmod: 0.228301
KVM host: Ubuntu 11.10
qemu-kvm: 0.14.1
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2012-04-05 02:43:24 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-ports-bugs

reclassify.
Comment 2 Edwin Groothuis freebsd_committer freebsd_triage 2012-05-28 03:17:30 UTC
Responsible Changed
From-To: freebsd-ports-bugs->kuriyama

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 3 Chris Rees freebsd_committer freebsd_triage 2013-08-07 20:33:18 UTC
Responsible Changed
From-To: kuriyama->bryanv

Hi Bryan, 

Is this something you may be acquainted with, as the virtio maintainer? 
Do you have any recommendations? 

Please accept my apologies if this isn't something for you... 

Chris
Comment 4 jmealo 2013-08-07 20:46:18 UTC
I wanted to confirm that this bug is present in FreeBSD 8.3-RELEASE_p9
running on SmartOS KVM (a different implementation than the linux KVM).
Comment 5 Chris Rees freebsd_committer freebsd_triage 2013-08-07 21:22:58 UTC
State Changed
From-To: open->feedback

Fantastic, thanks for your quick response. 

Jeffrey, does disabling checksum offloading work for you?
Comment 6 jmealo 2013-08-13 01:30:53 UTC
This did not resolve my issue.

Thanks,
Jeff
Comment 7 Phil Regnauld 2013-10-22 00:22:30 UTC
Env:
	Host OS: Debian 7.1 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux
	KVMM: QEMU emulator version 1.1.2 (qemu-kvm-1.1.2+dfsg-6, Debian)
	Guest: FreeBSD 9.2-R amd64

Disabling checksum offload with ifconfig vtnetX -rxcsum -txcsum on both
interfaces (this is a router) solves the issue, but performance becomes
terrible (150 KB/sec uses 100% CPU on host).

vtnet interfaces are, Host side, bridged to VLANs.

Problem does not appear if the traffic is to/from the router itself. Only
forwarded traffic is a problem.

Can provide more info/feedback if needed.
Comment 8 Phil Regnauld 2014-01-07 14:54:53 UTC
Phil Regnauld (regnauld) writes:
> Env:
> 	Host OS: Debian 7.1 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux
> 	KVMM: QEMU emulator version 1.1.2 (qemu-kvm-1.1.2+dfsg-6, Debian)
> 	Guest: FreeBSD 9.2-R amd64
> 
> Disabling checksum offload with ifconfig vtnetX -rxcsum -txcsum on both
> interfaces (this is a router) solves the issue, but performance becomes
> terrible (150 KB/sec uses 100% CPU on host).
> 
> vtnet interfaces are, Host side, bridged to VLANs.
> 
> Problem does not appear if the traffic is to/from the router itself. Only
> forwarded traffic is a problem.
> 
> Can provide more info/feedback if needed.

	Same problem has been observed with 10.0-RC4.

	kern/166645 may be related.

	This is causing FreeBSD (and pfSense) to be unusable as a network
	appliance / router on KVM platforms.

	Phil
Comment 9 elico 2015-08-27 21:06:53 UTC
Still present on 10.1.
Environment:
Ubuntu 14.04 KVM hypervisor
A FreeBSD 10.01 gateway between the world to three networks.
The FreeBSD has a VYOS default gateway with NATTING it.
When I remove the txcsum and rxcsum from the interface the packets doesn't get corrupted.

The VYOS router blocks INVALID packets ICMP packets are not malformed while TCP do.

I had the same issue with OpenBSD 5.7 and it got fixed on current(5.8).

Examples of the setup rc.conf and pf rules at:
http://wiki.squid-cache.org/ConfigExamples/Intercept/PfPolicyRoute#rc.conf_example_for_a_router
Comment 10 elico 2015-08-28 15:13:29 UTC
(In reply to elico from comment #9)
My testing topology:
http://ngtech.co.il/squidblocker/topology1.png
Comment 11 amvandemore 2015-09-13 14:25:29 UTC
I've seen the same issue on linux kvm guest(w/ FBSD router virtio guest w/ tso) worked around by:

pre-up /sbin/ethtool --offload eth0 tx off

so I am curious as to how this is identified as a FreeBSD bug.  Seems to more like something within the kvm stack.

Ubuntu 14.04.3 LTS
qemu-kvm                            2.0.0+dfsg-2ubuntu1.16

Seems to also be the same issue here:

https://forum.pfsense.org/index.php?topic=88467.0

However it's not a PF issue as ipfw kernel nat also did the same.
Comment 12 elico 2015-09-13 14:31:02 UTC
(In reply to amvandemore from comment #11)
My assumption is that if it works with Linux, OpenBSD in many versions then it's not an hypervisor issue.
What and how exactly I do not know but maybe the OpenBSD virtio changes can help to understand what was changed.

Notice that it's affecting only routing\gateway mode and not regular traffic so it's something special and it's not related at all to FW but to the GW\routing related code.
Comment 13 elico 2015-09-21 01:13:30 UTC
I do not "need" this since my systems works fine with e1000 and with Linux hosts but I was wondering if there is any progress with it?
Comment 14 Sydney Meyer 2016-01-24 00:59:12 UTC
(In reply to elico from comment #12)

I doubt too that this is a KVM issue as there seem to be similar problems (forwarding tcp packets) on Xen.

E.g: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=188261
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202199
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197344
Comment 15 elico 2017-06-14 23:59:05 UTC
(In reply to Sydney Meyer from comment #14)
I had a chance to verify the subject with a special setup which includes debian and found out that the issue is only in a specific scenario:
The KVM hypervisor hosting two VM's and sharing the same interfae such as bridge.
The bug is that the hypervisor virtio driver doesn't write a checksum for packets which are directed towards an internal interface.
The Hypervisor should either write the checksome or the VM should not check it.
It's an issue that is partially in the driver and the hypervisor.
I am running now on both CentOS and Ubuntu KVM hypervisor sharing the same issue.
The solution for my case was to use iptables checksum fill option on the gateway machine.
The first step is to allow DHCP traffic pass between VM's and that the DHCP client(ISC) will not drop the packets using:
iptables -A POSTROUTING -t mangle -p udp --dport 68 -j CHECKSUM --checksum-fill

I will try to test with FreeBSD 11 since with OpenBSD 5.X it didn't but with 5.Y(tip) it was working fine.
Comment 16 Bryan Venteicher freebsd_committer freebsd_triage 2017-06-15 14:51:43 UTC
This has been a long standing and unfortunate issue. My memory is somewhat fuzzy, but generally speaking the host doesn't need to compute a checksum because it is basically just a memory copy into the guest, but FreeBSD doesn't have a flag (at least at the time I was originally working on the VirtIO drivers) to denote "recompute this checksum if forwarding" the packet.
Comment 17 elico 2017-06-15 15:40:26 UTC
(In reply to Bryan Venteicher from comment #16)
OK So the test environment should be the next:
- 1 KVM Hypervier(CentOS 7)
- 1 VYOS EDGE GW(eth0=192.168.89.200/24, eth1=192.168.7.254/24, GW=192.168.89.1)
- 1 FreeBSD (10.3+11.0) GW for 2 networks(eth0=192.168.7.1/24,eth1=192.168.6.254/24,eth2=192.168.7.254/24, GW=192.168.7.254/23)
- Windows+Linux+FreeBSD clients on networks 192.168.6.0/24+192.168.7.0/24 with GW 192.168.6.254 or 192.168.7.254

The expected result should be a working connection from the end user(Win\Lin\BSD) to the local networks and Internet.
Comment 18 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:40:45 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 19 elico 2018-05-28 20:04:21 UTC
(In reply to Eitan Adler from comment #18)
With what version of FreeBSD? Latest stable?
Comment 20 andcycle-bugs.freebsd.org 2019-02-28 09:34:18 UTC
I am probably hit similar issue with Gentoo Linux Host KVM and FreeBSD 9~12 Guest with virtio network adapter,

my environment is 
Linux bacztwo 4.14.101-gentoo
libvirt-4.9.0
qemu-3.1.0

under default setting
with e1000 series the guest sometimes raising interrupt storm over it
with virtio it won't receive any packet and unable to communicate through network.


the following option for qemu that just disable all checksum for virtio-net works on my FreeBSD guest

-device virtio-net-pci,csum=off,guest_csum=off
Comment 21 Jakub Chromy 2019-06-09 07:02:26 UTC
(In reply to andcycle-bugs.freebsd.org from comment #20)

here are the options for "virsh edit" on the KVM host:

    <interface type='network'>
      <source network='private'/>
      <model type='virtio'/>
      <driver>
        <host csum='off'/>
        <guest csum='off'/>
      </driver>
    </interface>

eg. "virsh edit freebsd-host" and put this into the config.

Jakub
Comment 22 zain david 2019-07-23 04:33:30 UTC
MARKED AS SPAM
Comment 23 elico 2020-01-21 11:33:16 UTC
(In reply to zain david from comment #22)
Why Spam?
Comment 24 Greg A. 2020-02-14 21:33:18 UTC
Hello FreeBSD maintainers,

This bug is still present on 11.3-RELEASE and 12.0-RELEASE
Maybe it could be a good idea to upgrade version in the ticket description.

Maybe somebody will consider it :)

It's so sad that FreeBSD run better on vmware than on linux KVM :/


Thanks in advance for the good job on FreeBSD
BR,
Grégory
Comment 25 Charlie Root 2020-04-17 16:25:26 UTC
(In reply to Greg A. from comment #24)

FreeBsd 12.1 workaround

# Gateway Host

Ifconfig for WAN interface vtnet0 (vtnet uplink 10g)

----
ifconfig_vtnet0="inet WAN_IP netmask WAN_MASK vlanmtu vlanhwtag vlanhwfilter vlanhwcsum vlanhwtso -rxcsum -txcsum -rxcsum6 -txcsum6 tso6 tso4 lro"
----

disable only -rxcsum -txcsum -rxcsum6 -txcsum6


Ifconfig for LAN interface vtnet1 (vtnet uplink 10g)

---
ifconfig_vtnet1="inet 192.168.1.1 netmask 255.255.255.0 vlanmtu vlanhwtag vlanhwfilter vlanhwcsum vlanhwtso rxcsum -txcsum rxcsum6 -txcsum6 tso6 tso4 lro"
---

disable only -txcsum -txcsum6


pf.conf - simple nat rule for LAN (scrub rules not need)

---
nat on vtnet0 from 192.168.1.0/24 to any -> WAN_IP
---


######################################################################

# LAN Client Host (vtnet uplink 10g)

Ifconfig for LAN interface vtnet0

---
ifconfig_vtnet0="inet 10.66.1.2 netmask 255.255.255.0 vlanmtu vlanhwtag vlanhwfilter vlanhwcsum vlanhwtso rxcsum -txcsum rxcsum6 -txcsum6 tso6 tso4 lro"
---

disable only -txcsum -txcsum6


######################################################################

All traffic test passed normal.

1) Gateway LAN -> Client LAN - iperf3 result 14Gbit/s

2) Client Lan -> Gateway Lan - iperf result 14Gbit/s

3) Client Lan download Gateway Lan (NAT) from External source - result max download speed

3) External iperf client -> to Gateway WAN (iperf port) -> redirect to LAN Client iperf server - result max External iperf client speed

Please check workaround
Comment 26 Kubilay Kocak freebsd_committer freebsd_triage 2022-11-11 20:55:22 UTC
^Triage: 

This issue needs a reproduction on currently supported FreeBSD versions and steps to reproduce (minimum test case).

Ideally reproduction confirmation against CURRENT, 13.1 and 12.4

(re)confirmation that disabling RX/TX checksumming works around the issue, or not, would also be great.
Comment 27 elico 2022-11-13 19:07:42 UTC
(In reply to Kubilay Kocak from comment #26)
I will try to test later on.
Since Ubuntu 14.04 is not supported anymore I will try to reproduce on later versions of Ubuntu 20.04/22.04 and Oracle Linux 8.
I will try to verify with 12.3 and 12.4
Comment 28 elico 2022-11-13 22:13:14 UTC
(In reply to elico from comment #27)
OK so just to mention the NAT related documents are at:
http://draft.scyphus.co.jp/freebsd/nat.html

and ontop of Oracle Enterprise Linux 8 KVM host the issue exists on 12.3
the setup is very simple:
* Alpine 3.16 with ip 192.168.111.1/24 gw 192.168.111.254 DNS 8.8.8.8
* FreeBSD 12.3 with two interfaces: vtnet0 192.168.110.1/24 GW 192.168.110.254
 vtnet1 192.168.111.254/24
 pf rules to nat on $ext_inf
* VyOS 1.3.2 with two interfaces: eth0 192.168.122.183/24 GW 192.168.122.1
  eth1: 192.168.110.254/24

ping from Alpine to 8.8.8.8 via FreeBSD (NAT) -> VyOS (NAT) = works (ICMP_
wget from Alpine to 8.8.8.8 via FreeBSD (NAT) -> VyOS (NAT) = doesn't work (TCP)


When I am running the next on the vtnet0 and vtnet1 interfaces the TCP works:
ifconfig vtnet0 -rxcsum
ifconfig vtnet1 -rxcsum

It was resolved long ago in OpenBSD so now there only should be a fix and a text.
Comment 29 Tristin Stagg 2023-02-23 20:37:39 UTC
(In reply to elico from comment #28)

Hello,

I created a FreeBSD 13.1 STABLE virtual router in a Proxmox 7.1 testing environment and was encountering this issue with my FreeBSD VM. I can confirm that running the following helped me to resolve the issue:

ifconfig vtnet0 -rxcsum
ifconfig vtnet1 -rxcsum

Thank you for helping with my virtual router's NAT not working. 

Previous to resolution, I was able to ping things, which tells me that ICMP was working fine (I could also see this in my pflogging) - however, I could not say the same for TCP
Comment 30 José Zadir 2023-04-27 01:01:01 UTC
Hello,

I created a FreeBSD 12.3 STABLE virtual router in a Proxmox 7.1 environment and was encountering this issue with my FreeBSD VM. 
I can confirm that running the following helped to work arround the issue, but the performance is terrible.

ifconfig vtnet0 -rxcsum
ifconfig vtnet1 -rxcsum
Comment 31 Karel Krýda 2023-12-09 14:49:31 UTC
Hello,
I came across this bug report while troubleshooting an OPNsense throughput issue when using a VirtIO network card on Proxmox 8. Unfortunately the only way to achieve 10Gbps speed is to enable the HW Checksum Offloading option. Unfortunately, after activating it, access to servers on the same Proxmox server stops working and not only to them, but also for example to the TrueNAS Core server (NOT on the same Proxmox server).
I see that this issue has not been resolved since 2012. Is there ever a plan to fix this? This behavior is still present on OPNsense 23.7.9 and therefore FreeBSD 13.2.
Thanks
Comment 32 Igor Raschetov 2024-01-29 11:49:41 UTC
Hello
Adding parameters to /boot/loader.conf

hw.vtnet.X.tso_disable="1"
hw.vtnet.tso_disable="1"
hw.vtnet.lro_disable="1"
hw.vtnet.X.lro_disable="1"
hw.vtnet.csum_disable="1"
hw.vtnet.X.csum_disable="1"

Solved the problem
Comment 33 Mark Linimon freebsd_committer freebsd_triage 2024-10-04 14:36:23 UTC
^Triage: clear unneeded flags.  Nothing has yet been committed to be merged.
Comment 34 Tom Jones freebsd_committer freebsd_triage 2024-12-19 09:06:03 UTC
Hi,

This was highlighted to me as a long standing issue that the foundation might look at. There is a decade of discussion here and it isn't super clear if there are several symptoms that are addressed by disabling checksum offload or if there are multiple issues.

I think there are two different cases (if I were writing tests, which I will try to).

FreeBSD as a router on Linux KVM incorrectly skips checksum calculations breaking forwarding.

FreeBSD as a router with checksum offload disabled is unable to forward suitable traffic rates.

can someone confirm by reading of the thread and suggest other failure cases?

My preference would be to write tests for issues we can identify, close this bug and track fixing the tests in their own bugs. 10 years of comments is hard to reason about :).

Ideally someone(s) running FreeBSD on KVM would help me populate a wiki page with exemplar use cases, that would allow me to find someone to help write tests and put together a test environment.
Comment 35 John Nielsen 2024-12-19 18:19:33 UTC
I run a FreeBSD 14-STABLE router with vtnet under KVM on Arch Linux. I don't disable any checksums or do any other special configuration. I have NOT encountered this issue. The router uses IPFW and does NAT for several subnets (each of which is a different VLAN+bridge on the host and a distinct vtnet interface on the FreeBSD guest). That said if someone has specific failure cases or ways to reproduce I can help test.
Comment 36 John Nielsen 2024-12-19 18:20:36 UTC
(I do have other FreeBSD guests on the same KVM host which rely on the router VM for Internet access.)
Comment 37 Aleksandr Fedorov freebsd_committer freebsd_triage 2024-12-20 20:28:42 UTC
This is simply because FreeBSD does not know how to forward and NAT packets with offload.
KVM forwards packets to a virtual machine that can be up to 64 kilobytes in size and without checksums.

This is optimization!!!

Just read the virtio specification:

struct virtio_net_hdr {
#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1
#define VIRTIO_NET_HDR_F_DATA_VALID 2
#define VIRTIO_NET_HDR_F_RSC_INFO 4
u8 flags;
#define VIRTIO_NET_HDR_GSO_NONE 0
#define VIRTIO_NET_HDR_GSO_TCPV4 1
#define VIRTIO_NET_HDR_GSO_UDP 3
#define VIRTIO_NET_HDR_GSO_TCPV6 4
#define VIRTIO_NET_HDR_GSO_UDP_L4 5
#define VIRTIO_NET_HDR_GSO_ECN 0x80
 u8 gso_type;
 le16 hdr_len;
 le16 gso_size;
 le16 csum_start;
 le16 csum_offset;
 le16 num_buffers;
 le32 hash_value; (Only if VIRTIO_NET_F_HASH_REPORT negotiated)
 le16 hash_report; (Only if VIRTIO_NET_F_HASH_REPORT negotiated)
 le16 padding_reserved; (Only if VIRTIO_NET_F_HASH_REPORT negotiated)
};

https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html#x1-2170001
Comment 38 Mike Steele 2024-12-20 22:27:51 UTC
(In reply to Aleksandr Fedorov from comment #37)


Could the following linked comment be related to this issue? It seems to be saying about the same thing.

https://github.com/freebsd/freebsd-src/blob/9efd215411bb5ead2bc0ab208b4c19e46da0d2c9/sys/dev/virtio/network/if_vtnet.c#L1761-L1777
Comment 39 John Nielsen 2025-01-02 02:52:59 UTC
(In reply to John Nielsen from comment #36)
I was mistaken, my KVM-hosted router does suffer from this issue. So even more happy to test patches than previously stated.

What needs to happen in terms of fixing (or ignoring) the bad checksums for the NAT case and where? In the firewall/NAT code? vtnet driver? Somewhere else?
Comment 40 Tom Jones freebsd_committer freebsd_triage 2025-02-10 09:41:01 UTC
Some extra info from demido via irc


https://termbin.com/et91 is my wireguard setup that works (but has tiny throughput down to wg client) including iperf tests from wg client to wg server over tunnel, wg client to wg server over inet, and wg server to wg client over tunnel. https://termbin.com/07dl is networking info on wg client. FIXED: i isolated the 'solution' to being adding 'hw.vtnet.csum_disable="1"' to /boot/loader.conf. nothing else needed, and download speed of freebsd (and debian) install isos from wg client became nearly as fast as wg server. this seems related but separate from similar suggestions of disabling tso and lro as i /only/ needed to disable csum.

keywords: nat, checksum, vtnet. related bugs: 
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235607, 
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263229, 
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=165059,
 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=259249, 
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=170081 

other links: 
https://lists.freebsd.org/pipermail/freebsd-questions/2021-January/292565.html,
https://forums.freebsd.org/threads/wireguard-vpn-slow-speed.73490/page-2#post-584231, https://sourceopen.com/index.php/howto-fix-slow-networking-with-a-wireguard-server-in-a-freebsd-jail-on-a-vps-and-slow-downloads-in-a-jail-on-a-vps/, 
https://forums.freebsd.org/threads/nat-low-speed-outside-of-local-subnet.49498/, 
https://serverfault.com/questions/817664/slow-network-fixed-adding-hw-vtnet-csum-disable-1-what-are-the-posible-side-effe, 
https://imil.net/blog/posts/2019/freebsd-networking-issues-disable-offloading-and-checksum/,
https://www.mail-archive.com/freebsd-jail@freebsd.org/msg03651.html, more https://search.brave.com/search?q=freebsd+nat+vtnet+disable+checksum
Comment 41 Chris Collins 2025-07-09 18:35:16 UTC
Is anyone going to just crack on with it? 10 years of people repeatedly saying they having to disable a very basic feature checksum offloading, following by devs asking for one more confirmation before they want to look at it.

Ironically I dont know if I have the issue as I have always routinely disabled checksum offloading on vtnet since day 1 following advice from pfSense developers, luckily performance is ok.

But it is only today I think I have discovered the reason for this advice.
Comment 42 Mark Linimon freebsd_committer freebsd_triage 2025-07-10 11:56:32 UTC
^Triage: as bugmeister, I'm sorry that this one has fallen through the cracks.
Let me try to reassign it to the net@ group to see if the subscribers there
can comment.

NB for net@: the believed workaround is to disable hw checksum offloading.  There
are multiple submitters who have reported this.

Comment 16 from bryanv@ may be a good place to start.
Comment 43 Michael Tuexen freebsd_committer freebsd_triage 2025-07-10 13:11:47 UTC
Timo Völker (who is working with me) is looking at supporting checksum offloading / TS) for bhyve VMs. I guess this problem is at least in this area. So we can look at it. Don't know how simple it is to fix before we understand to code...
Comment 44 void 2025-07-14 12:40:24 UTC
(In reply to Mark Linimon from comment #42)

In terms of iperf3, i.e. throughput, it's not really a workaround.

Setting
hw.vtnet.tso_disable="1"
hw.vtnet.lro_disable="1"
hw.vtnet.csum_disable="1"

in the freebsd guest increases throughput by 5-20% but it's never linespeed for *any*
version of freebsd guest. It *is* near linespeed for linux guests.

The context here is freebsd host.
Comment 45 Timo Voelker 2025-07-18 13:22:14 UTC
As Michael wrote, my focus is more on bhyve. However, I have a setup with KVM and qemu to compare behavior.

This is my current setup:

FreeBSD VM1    FreeBSD VM2 (router)
  vtnet0       vtnet0      vtnet1
1.1.1.1/24   1.1.1.2/24  2.2.2.2/24
     *          *           *
      \        /            |
       \      /             |
        \    /              |
Linux    *  *               *
Host    bridge0           bridge1
                         2.2.2.3/24

Ping from VM1 (1.1.1.1) to host's bridge1 (2.2.2.3) works, TCP does not. This is my understanding of what happens, when VM1 sends a TCP segment to Host's bridge1.

1. VM1 TCP/IP Stack: Outgoing interface vtnet0 has txcsum -> do not calculate correct TCP checksum, set flag CSUM_IP_TCP and send with incorrect checksum value.
2. VM1 vtnet0: Outgoing packet still needs a correct checksum (CSUM_IP_TCP set) -> set virtio-net header flag VIRTIO_NET_HDR_F_NEEDS_CSUM.
3. VM2 vtnet0: Incoming packet has VIRTIO_NET_HDR_F_NEEDS_CSUM set -> packet is likely from another VM on the same host -> trust the packet and set flag CSUM_DATA_VALID (basically lie that the checksum has been validated).
4. VM2 TCP/IP Stack: Forward packet out over vtnet1. This is on IP layer, no need to touch the TCP checksum.
5. VM2 vtnet1: Outgoing packet seems to have a correct checksum. No need to set virtio-net header flag VIRTIO_NET_HDR_F_NEEDS_CSUM.
6. Host bridge1: Incoming packet without virtio-net header flag VIRTIO_NET_HDR_F_NEEDS_CSUM set -> pass packet without setting CSUM flags.
7. Host TCP/IP: Incoming TCP segment with incorrect checksum. Drop segment.

The problem is the lie at point 3. That's works if the packet is for VM2, but breaks in this case where VM2 only forwards the IP packet. Right now, I don't have a good idea for a fix, but I'm working on it.

By the way, the behavior at point 3 is configurable. With `hw.vtnet.fixup_needs_csum=1` set in /boot/loader.conf (and after a restart), VM2 vtnet0 calculates the checksum and write the correct checksum into the TCP header. With that, TCP from VM1 to host's bridge1 works, but this is not better than disabling txcsum on VM1 vtnet0 because the checksum calculation is still done in software, only on another VM.
Comment 46 Timo Voelker 2025-08-01 19:46:38 UTC
Code changes that should fix this bug are in review.

https://reviews.freebsd.org/D51686
Comment 47 commit-hook freebsd_committer freebsd_triage 2025-09-04 11:27:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1c23d8f9f39870951c1d0dfbb112fc4e53237737

commit 1c23d8f9f39870951c1d0dfbb112fc4e53237737
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2025-09-04 11:16:46 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-09-04 11:16:46 +0000

    vtnet: improve checksum offloading

    When transmitting a packet over the vtnet interface, map the
    csum flags CSUM_DATA_VALID | CSUM_PSEUDO_HDR to the virtio
    flag VIRTIO_NET_HDR_F_DATA_VALID.
    When receiving a packet over the virtio network channel, translate
    the virtio flag VIRTIO_NET_HDR_F_NEEDS_CSUM not to CSUM_DATA_VALID |
    CSUM_PSEUDO_HDR, but to CSUM_TCP, CSUM_TCP_IPV6, CSUM_UDP, or
    CSUM_UDP_IPV6.
    The second change fixes a series of issue related to checksum
    offloading for if_vtnet.
    While there, improve the stats counters to allow a detailed view
    on what is going on in relation to checksum offloading.

    PR:                     165059
    Reviewed by:            tuexen, manpages
    MFC after:              1 week
    Differential Revision:  https://reviews.freebsd.org/D51686

 share/man/man4/vtnet.4               |  28 +++--
 sys/dev/virtio/network/if_vtnet.c    | 220 ++++++++++++++++++-----------------
 sys/dev/virtio/network/if_vtnetvar.h |   2 +-
 3 files changed, 132 insertions(+), 118 deletions(-)
Comment 48 Michael Tuexen freebsd_committer freebsd_triage 2025-09-04 12:19:34 UTC
Please retest and report.
Comment 49 commit-hook freebsd_committer freebsd_triage 2025-09-08 20:43:59 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3008f30d2c2cabdd7e17f7fb922139da8681ffbd

commit 3008f30d2c2cabdd7e17f7fb922139da8681ffbd
Author:     Timo Völker <timo.voelker@fh-muenster.de>
AuthorDate: 2025-09-08 20:38:49 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-09-08 20:38:49 +0000

    vtnet: improve checksum offloading

    When transmitting a packet over the vtnet interface, map the
    csum flags CSUM_DATA_VALID | CSUM_PSEUDO_HDR to the virtio
    flag VIRTIO_NET_HDR_F_DATA_VALID.
    When receiving a packet over the virtio network channel, translate
    the virtio flag VIRTIO_NET_HDR_F_NEEDS_CSUM not to CSUM_DATA_VALID |
    CSUM_PSEUDO_HDR, but to CSUM_TCP, CSUM_TCP_IPV6, CSUM_UDP, or
    CSUM_UDP_IPV6.
    The second change fixes a series of issue related to checksum
    offloading for if_vtnet.
    While there, improve the stats counters to allow a detailed view
    on what is going on in relation to checksum offloading.

    PR:                     165059
    Reviewed by:            tuexen, manpages
    MFC after:              3 days
    Differential Revision:  https://reviews.freebsd.org/D51686

 share/man/man4/vtnet.4               |  28 +++--
 sys/dev/virtio/network/if_vtnet.c    | 220 ++++++++++++++++++-----------------
 sys/dev/virtio/network/if_vtnetvar.h |   2 +-
 3 files changed, 132 insertions(+), 118 deletions(-)
Comment 50 commit-hook freebsd_committer freebsd_triage 2025-09-11 06:20:57 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5a8f33f52ae38bbf12f8f45b8e0f75166805c386

commit 5a8f33f52ae38bbf12f8f45b8e0f75166805c386
Author:     Timo Völker <timo.voelker@fh-muenster.de>
AuthorDate: 2025-09-08 20:38:49 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-09-11 06:17:12 +0000

    vtnet: improve checksum offloading

    When transmitting a packet over the vtnet interface, map the
    csum flags CSUM_DATA_VALID | CSUM_PSEUDO_HDR to the virtio
    flag VIRTIO_NET_HDR_F_DATA_VALID.
    When receiving a packet over the virtio network channel, translate
    the virtio flag VIRTIO_NET_HDR_F_NEEDS_CSUM not to CSUM_DATA_VALID |
    CSUM_PSEUDO_HDR, but to CSUM_TCP, CSUM_TCP_IPV6, CSUM_UDP, or
    CSUM_UDP_IPV6.
    The second change fixes a series of issue related to checksum
    offloading for if_vtnet.
    While there, improve the stats counters to allow a detailed view
    on what is going on in relation to checksum offloading.

    PR:                     165059
    Reviewed by:            tuexen, manpages
    Differential Revision:  https://reviews.freebsd.org/D51686

    (cherry picked from commit 3008f30d2c2cabdd7e17f7fb922139da8681ffbd)

 share/man/man4/vtnet.4               |  28 +++--
 sys/dev/virtio/network/if_vtnet.c    | 220 ++++++++++++++++++-----------------
 sys/dev/virtio/network/if_vtnetvar.h |   2 +-
 3 files changed, 132 insertions(+), 118 deletions(-)
Comment 51 commit-hook freebsd_committer freebsd_triage 2025-09-11 06:38:15 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=07625c420dc30cc484018c269bb7a212436ded8a

commit 07625c420dc30cc484018c269bb7a212436ded8a
Author:     Timo Völker <timo.voelker@fh-muenster.de>
AuthorDate: 2025-09-08 20:38:49 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-09-11 06:35:43 +0000

    vtnet: improve checksum offloading

    When transmitting a packet over the vtnet interface, map the
    csum flags CSUM_DATA_VALID | CSUM_PSEUDO_HDR to the virtio
    flag VIRTIO_NET_HDR_F_DATA_VALID.
    When receiving a packet over the virtio network channel, translate
    the virtio flag VIRTIO_NET_HDR_F_NEEDS_CSUM not to CSUM_DATA_VALID |
    CSUM_PSEUDO_HDR, but to CSUM_TCP, CSUM_TCP_IPV6, CSUM_UDP, or
    CSUM_UDP_IPV6.
    The second change fixes a series of issue related to checksum
    offloading for if_vtnet.
    While there, improve the stats counters to allow a detailed view
    on what is going on in relation to checksum offloading.

    PR:                     165059
    Reviewed by:            tuexen, manpages
    Differential Revision:  https://reviews.freebsd.org/D51686

    (cherry picked from commit 3008f30d2c2cabdd7e17f7fb922139da8681ffbd)

 share/man/man4/vtnet.4               |  28 +++--
 sys/dev/virtio/network/if_vtnet.c    | 220 ++++++++++++++++++-----------------
 sys/dev/virtio/network/if_vtnetvar.h |   2 +-
 3 files changed, 132 insertions(+), 118 deletions(-)