Bug 254366 - Severe IPv6 TCP transfer issues on 13.0-RC2 with virtio network adapter
Summary: Severe IPv6 TCP transfer issues on 13.0-RC2 with virtio network adapter
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Michael Tuexen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-17 18:07 UTC by Michael Tratz
Modified: 2021-03-18 20:52 UTC (History)
6 users (show)

See Also:
tuexen: mfc-stable13+


Attachments
default virtio iperf3 speed ipv6 FreeBSD 13.0-RC2 (1.38 KB, text/plain)
2021-03-17 18:07 UTC, Michael Tratz
no flags Details
iperf3 transfer speed ipv4 on FreeBSD 13.0-RC2 (1.26 KB, text/plain)
2021-03-17 18:09 UTC, Michael Tratz
no flags Details
iperf3 ipv6 with ifconfig vtnet0 -tso6 FreeBSD 13.0-RC2 (1.37 KB, text/plain)
2021-03-17 18:10 UTC, Michael Tratz
no flags Details
ifconfig defaults on FreeBSD 13.0-RC2 virtio (958 bytes, text/plain)
2021-03-17 18:11 UTC, Michael Tratz
no flags Details
dmesg (10.30 KB, text/plain)
2021-03-17 18:25 UTC, Michael Tratz
no flags Details
sysctl dev.vtnet (slow) (5.59 KB, text/plain)
2021-03-18 18:45 UTC, Michael Tratz
no flags Details
Fast iperf3 without 475a60aec7e (5.51 KB, text/plain)
2021-03-18 18:46 UTC, Michael Tratz
no flags Details
Proposed fix (1.26 KB, text/plain)
2021-03-18 19:07 UTC, Michael Tuexen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Tratz 2021-03-17 18:07:23 UTC
Created attachment 223365 [details]
default virtio iperf3 speed ipv6 FreeBSD 13.0-RC2

I installed FreeBSD 13.0-RC2 on some of my database virtual machines using the VirtIO network adapter. The VMs only use IPv6. After the upgrade MySQL threads kept filling up with data waiting to be sent. The same setup worked flawlessly with 12.2. Upon investigation I noticed that the IPv6 transfer speed from the VM to any other device is in the range of 46Kbps. Usually it is 15-20Gbps from VM to VM on the same bare metal machine. If IPv4 is used no issues at all on FreeBSD 13.0-RC2.

This issue was also recently discussed on the freebsd-net list under the "severe ipv6 tcp transfer issues" subject.

The problem can be easily reproduced by setting up two virtual machines running the default FreeBSD 13.0-RC2 release candidate. (Note the problem already exists in BETA4). Configure the network device using virtio and setup IPv6. Run a simple iperf3 session from VM to VM on IPv6 and the slowness shows up every time in both directions. I tested it with virt-manager as well as using Proxmox and both show that issue.

A quick fix was to issue ifconfig vtnet0 -tso6. That brings transfer speeds back to acceptable levels in the Gbps range. However it is still much slower for vm-vm-same-host than IPv4. About 4Gbps on IPv6 vs 15-20Gbps IPv4. FreeBSD 12.2 has the same 15-20Gbps speed IPv4/IPv6.

My thoughts were that the recent virtio changes committed by Bryan Venteicher were the culprit. I started bisecting the changes submitted 2021-01-19.

After building a few kernels it is the following commit causing the issue: 475a60aec7e if_vtnet: Misc Tx path cleanup

review D27926

Building a kernel without that commit brings back IPv4/IPv6 on the same level as before. Not much of kernel geek so I'm not sure what part of the code is causing the problem to show up in IPv6 only.

Attached are a couple iperf3 & ifconfig commands to show the slowness. If anything else is needed, please let me know, but all you need is stock FreeBSD 13.0-RC2 VM using virtio and ipv6.
Comment 1 Michael Tratz 2021-03-17 18:09:07 UTC
Created attachment 223366 [details]
iperf3 transfer speed ipv4 on FreeBSD 13.0-RC2
Comment 2 Michael Tratz 2021-03-17 18:10:31 UTC
Created attachment 223367 [details]
iperf3 ipv6 with ifconfig vtnet0 -tso6 FreeBSD 13.0-RC2
Comment 3 Michael Tratz 2021-03-17 18:11:27 UTC
Created attachment 223368 [details]
ifconfig defaults on FreeBSD 13.0-RC2 virtio
Comment 4 Michael Tratz 2021-03-17 18:25:55 UTC
Created attachment 223369 [details]
dmesg

Also it doesn't matter if the machine configuration is q35 or i440fx.
Comment 5 Aleksandr Fedorov freebsd_committer freebsd_triage 2021-03-18 17:01:54 UTC
>After building a few kernels it is the following commit causing the issue: 475a60aec7e if_vtnet: Misc Tx path cleanup

Did you just remove this commit, or rolled back the branch to the commit before 475a60aec7e?

I tried to reproduce this bug with bhyve - no success.

FreeBSD-13-RC1 <-> FreeBSD-13-RC1 - 10-20 Gbit/s.
FreeBSD-13-Rc1 <-> Ubuntu - 10-20 Gbit/s.
Comment 6 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 17:12:11 UTC
What is the output of

sysctl dev.vtnet

after you did a transfer showing the problem?
Comment 7 Michael Tratz 2021-03-18 17:25:08 UTC
I only removed that single 475a60aec7e commit. I haven't tried it with bhyve.

Maybe the issue only shows up if the hypervisor runs on a Linux system?

I got a copy of Ubuntu Desktop 20.04.2.0 (and updated) and setup FreeBSD 13 using virt-manager. Same thing happens with a copy of the latest Proxmox setting up FreeBSD 13.

I'll run another test and get the sysctl dev.vtnet output. I'll get two outputs one with the regular RC2 kernel and the other with the 475a60aec7e commit removed.
Comment 8 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 17:47:25 UTC
 guess the same issue was reported on freebsd-net@ by Blake Hartshorn. The .pcap files provided (privately) indicated that all segments sent larger than the MTU were dropped by the host OS. So it is a TSO issue...
Comment 9 Michael Tratz 2021-03-18 17:55:58 UTC
I guess so too. That's why also

ifconfig vtnet0 -tso6

brings back acceptable speeds. But without the TSO the vm-to-vm throughput on the same host is not anywhere near IPv4 or what it was on FreeBSD 12 for IPv6.
Comment 10 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 18:15:55 UTC
(In reply to Michael Tratz from comment #9)
I'm not arguing that there is a bug. I'm just trying to figure out what is wrong with the patch. Also trying to reproduce this locally...
Comment 11 Michael Tratz 2021-03-18 18:45:20 UTC
Created attachment 223398 [details]
sysctl dev.vtnet (slow)

No worries Michael! Note: vtnet1 is the interface I'm using for testing. So look at that output. The VM was freshly started for the test. The iperf3 was run for 30 seconds.
Comment 12 Michael Tratz 2021-03-18 18:46:36 UTC
Created attachment 223399 [details]
Fast iperf3 without 475a60aec7e

Here is the same output running the kernel without the 475a60aec7e commit.
Comment 13 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 18:59:15 UTC
OK, I know what the problem is. I can reproduce it locally. Thanks for the information. Will post a patch soon.
Comment 14 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 19:07:34 UTC
Created attachment 223401 [details]
Proposed fix
Comment 15 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 19:09:08 UTC
(In reply to Michael Tratz from comment #12)
Can you try the Proposed fix?
Comment 16 Michael Tratz 2021-03-18 19:45:16 UTC
Thank you so much Michael for the quick fix. Everything is back to normal. IPv6 is speedy again.
Comment 17 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 20:00:54 UTC
(In reply to Michael Tratz from comment #16)
Thanks for reporting back!

The path is under review: https://reviews.freebsd.org/D29331
Comment 18 commit-hook freebsd_committer freebsd_triage 2021-03-18 20:33:19 UTC
A commit in branch main references this bug:

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

commit d4697a6b56168876fc0ffec1a0bb1b24d25b198e
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-03-18 20:25:47 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-03-18 20:32:20 +0000

    vtnet: fix TSO for TCP/IPv6

    The decision whether a TCP packet is sent over IPv4 or IPv6 was
    based on ethertype, which works correctly. In D27926 the criteria
    was changed to checking if the CSUM_IP_TSO flag is set in the
    csum-flags and then considering it to be TCP/IPv4.
    However, the TCP stack sets the flag to CSUM_TSO for IPv4 and IPv6,
    where CSUM_TSO is defined as CSUM_IP_TSO|CSUM_IP6_TSO.
    Therefore TCP/IPv6 packets gets mis-classified as TCP/IPv4,
    which breaks TSO for TCP/IPv6.
    This patch bases the check again on the ethertype.
    This fix will be MFC instantly as discussed with re(gjb).

    MFC after:              instantly
    PR:                     254366
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D29331

 sys/dev/virtio/network/if_vtnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Comment 19 commit-hook freebsd_committer freebsd_triage 2021-03-18 20:35:21 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6064ea8172f078c54954bc6e8865625feb7979fe

commit 6064ea8172f078c54954bc6e8865625feb7979fe
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-03-18 20:25:47 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-03-18 20:33:32 +0000

    vtnet: fix TSO for TCP/IPv6

    The decision whether a TCP packet is sent over IPv4 or IPv6 was
    based on ethertype, which works correctly. In D27926 the criteria
    was changed to checking if the CSUM_IP_TSO flag is set in the
    csum-flags and then considering it to be TCP/IPv4.
    However, the TCP stack sets the flag to CSUM_TSO for IPv4 and IPv6,
    where CSUM_TSO is defined as CSUM_IP_TSO|CSUM_IP6_TSO.
    Therefore TCP/IPv6 packets gets mis-classified as TCP/IPv4,
    which breaks TSO for TCP/IPv6.
    This patch bases the check again on the ethertype.
    This fix is instantly MFCed.

    Approved by:            re(gjb)
    PR:                     254366
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D29331

    (cherry picked from commit d4697a6b56168876fc0ffec1a0bb1b24d25b198e)

 sys/dev/virtio/network/if_vtnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Comment 20 commit-hook freebsd_committer freebsd_triage 2021-03-18 20:41:24 UTC
A commit in branch releng/13.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=11660fa28fd39a644cb7d30a4378cf4751b89f15

commit 11660fa28fd39a644cb7d30a4378cf4751b89f15
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-03-18 20:25:47 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-03-18 20:35:49 +0000

    vtnet: fix TSO for TCP/IPv6

    The decision whether a TCP packet is sent over IPv4 or IPv6 was
    based on ethertype, which works correctly. In D27926 the criteria
    was changed to checking if the CSUM_IP_TSO flag is set in the
    csum-flags and then considering it to be TCP/IPv4.
    However, the TCP stack sets the flag to CSUM_TSO for IPv4 and IPv6,
    where CSUM_TSO is defined as CSUM_IP_TSO|CSUM_IP6_TSO.
    Therefore TCP/IPv6 packets gets mis-classified as TCP/IPv4,
    which breaks TSO for TCP/IPv6.
    This patch bases the check again on the ethertype.
    This fix is instantly MFCed.

    Approved by:            re(gjb)
    PR:                     254366
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D29331

    (cherry picked from commit d4697a6b56168876fc0ffec1a0bb1b24d25b198e)
    (cherry picked from commit 6064ea8172f078c54954bc6e8865625feb7979fe)

 sys/dev/virtio/network/if_vtnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Comment 21 Michael Tuexen freebsd_committer freebsd_triage 2021-03-18 20:50:19 UTC
This will be in the upcoming RC3.