From 71086617a056a44bd6d202cb10b0ea4ceb83cfba Mon Sep 17 00:00:00 2001
From: Dmitry Fleytman <dmitry@daynix.com>
Date: Mon, 23 Dec 2013 17:38:56 +0200
Subject: [PATCH] netinet: Fix broken checksum verification in LRO mechanism

This patch applies bugfix published on FreeBSD list at Feb 2013:
http://lists.freebsd.org/pipermail/svn-src-stable-9/2013-February/003928.html

LRO mechanism is broken on systems without IP checksum verification offload.
Due to improper checksum verification RX packets omit LRO path and go
directly to TCP stack which is not good for performance.

EC2 Xen is one example of such a system.
This bug is one of the reasons we see bad performance on Amazon.

Some test results w/ and w/o the fix:

Buffer size    Before         After          Improvement %
TCP TX
32             557.52         1386.28        149
64             552.38         1385.99        151
128            546.43         1401.46        156
256            565.25         1382.28        145
512            557.32         1375.23        147
1024           549.71         1356.69        147
2048           551.11         1371.92        149
4096           556.13         1383.67        149
8192           559.49         1364.05        144
16384          567.25         1366.48        141
32768          546.18         1366.63        150
65536          553.4          1353.87        145

TCP RX
32             107.37         105.48         -2
64             187.56         179.9          -4
128            297.16         301.71         2
256            300.47         503.92         68
512            294.76         826.13         180
1024           299.95         1916.69        539
2048           287.04         1924.44        570
4096           300.78         1929.37        541
8192           304.52         1934.02        535
16384          305.04         1957.54        542
32768          309            1921.84        522
65536          296.48         1935.41        553

Still we are pretty far from Linux, there are other problems to be fixed.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
---
 bsd/sys/netinet/tcp_lro.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bsd/sys/netinet/tcp_lro.cc b/bsd/sys/netinet/tcp_lro.cc
index 50b953715..9706b8cb1 100644
--- a/bsd/sys/netinet/tcp_lro.cc
+++ b/bsd/sys/netinet/tcp_lro.cc
@@ -335,7 +335,7 @@ tcp_lro_rx_ipv4(struct lro_ctrl *lc, struct mbuf *m, struct ip *ip4,
 		}
 	} else {
 		csum = in_cksum_hdr(ip4);
-		if (__predict_false((csum ^ 0xffff) != 0)) {
+		if (__predict_false((csum) != 0)) {
 			lc->lro_bad_csum++;
 			return (TCP_LRO_CANNOT);
 		}
-- 
GitLab