From nobody@FreeBSD.org  Mon Jul 21 23:21:50 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 88AD31065670
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Jul 2008 23:21:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 6F9098FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Jul 2008 23:21:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m6LNLo36019017
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Jul 2008 23:21:50 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m6LNLobv019016;
	Mon, 21 Jul 2008 23:21:50 GMT
	(envelope-from nobody)
Message-Id: <200807212321.m6LNLobv019016@www.freebsd.org>
Date: Mon, 21 Jul 2008 23:21:50 GMT
From: Navdeep Parhar <nparhar@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tcp_lro_rx() should make use of hardware IP cksum assistance when available
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         125845
>Category:       kern
>Synopsis:       [netinet] [patch] tcp_lro_rx() should make use of hardware IP cksum assistance when available
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 21 23:30:02 UTC 2008
>Closed-Date:    
>Last-Modified:  Tue Jul 22 02:37:24 UTC 2008
>Originator:     Navdeep Parhar
>Release:        HEAD 8-CURRENT
>Organization:
Chelsio Communications
>Environment:
FreeBSD pepper 8.0-CURRENT FreeBSD 8.0-CURRENT #29: Mon Jul 21 15:31:40 PDT 2008     root@pepper:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
tcp_lro_rx() in sys/netinet/tcp_lro.c calculates the IP checksum of all
non-fragmented TCP packets while determining whether they can be queued for LRO.

Some optimization is possible here if the hardware has already verified the IP
checksum - just take CSUM_IP_CHECKED and CSUM_IP_VALID into account before doing
the checksum in software.
>How-To-Repeat:
N/A.  Problem was discovered while reading the code.
>Fix:
Patch attached.

Patch attached with submission follows:

diff -r cdbabca8841b sys/netinet/tcp_lro.c
--- a/sys/netinet/tcp_lro.c	Mon Jul 21 14:29:19 2008 -0700
+++ b/sys/netinet/tcp_lro.c	Mon Jul 21 16:19:38 2008 -0700
@@ -186,6 +186,7 @@
 	int hlen, ip_len, tcp_hdr_len, tcp_data_len, tot_len;
 	int opt_bytes, trim;
 	uint32_t seq, tmp_csum, device_mtu;
+	int csum_flags;
 
 
 	eh = mtod(m_head, struct ether_header *);
@@ -204,10 +205,18 @@
 		return -1;
 
 	/* verify that the IP header checksum is correct */
-	tmp_csum = do_csum_data((uint16_t *)ip, sizeof (*ip));
-	if (__predict_false((tmp_csum ^ 0xffff) != 0)) {
-		cntl->lro_bad_csum++;
-		return -1;
+	csum_flags = m_head->m_pkthdr.csum_flags;
+	if (csum_flags & CSUM_IP_CHECKED) {
+		if (__predict_false((csum_flags & CSUM_IP_VALID) == 0)) {
+			cntl->lro_bad_csum++;
+			return -1;
+		}
+	} else {
+		tmp_csum = do_csum_data((uint16_t *)ip, sizeof (*ip));
+		if (__predict_false((tmp_csum ^ 0xffff) != 0)) {
+			cntl->lro_bad_csum++;
+			return -1;
+		}
 	}
 
 	/* find the TCP header */


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jul 22 02:37:07 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125845 
>Unformatted:
