From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B563841CB1; Thu, 16 Feb 2023 13:36:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A3B9B42D51; Thu, 16 Feb 2023 13:36:12 +0100 (CET) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id D2F7D42D4F for ; Thu, 16 Feb 2023 13:36:10 +0100 (CET) Received: from finrod.oktetlabs.ru (finrod.oktetlabs.ru [192.168.38.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 5E80E7B; Thu, 16 Feb 2023 15:36:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 5E80E7B DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1676550970; bh=JlMgAIuJGTbXN+24/3C8tF97QVCqsiqwSiL5jqYW6bY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YSv4ImV2QX2IlVfsD5KaDc2qYjnSgik0cj6gaeCxjwvn+nnaStby26DeeBtY84Dzz AZ6qsOMS2d0tQPeaTDJvUkxn0OgBVPmq/yW8E/KUjSaeyvWMLX/12YPkllBYHW8DWI N2YYz4LFjzzSY2on+dES4AQV+l42AOdpv0Z/JLtI= From: Boleslav Stankevich To: dev@dpdk.org Cc: Boleslav Stankevich , Andrew Rybchenko , Maxime Coquelin , Chenbo Xia Subject: [PATCH] net/virtio: deduce IP length for Virtio TSO checksum Date: Thu, 16 Feb 2023 15:35:54 +0300 Message-Id: <20230216123554.2628837-2-boleslav.stankevich@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230216123554.2628837-1-boleslav.stankevich@oktetlabs.ru> References: <20230216123554.2628837-1-boleslav.stankevich@oktetlabs.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The length of TSO payload could not fit into 16 bits provided by the IPv4 total length and IPv6 payload length fields. Thus, deduce it from the length of the packet. Signed-off-by: Boleslav Stankevich Reviewed-by: Andrew Rybchenko --- drivers/net/virtio/virtio_rxtx.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 2d0afd3302..e48ff3cca7 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -404,29 +404,36 @@ virtio_tso_fix_cksum(struct rte_mbuf *m) if (likely(rte_pktmbuf_data_len(m) >= m->l2_len + m->l3_len + m->l4_len)) { struct rte_ipv4_hdr *iph; - struct rte_ipv6_hdr *ip6h; struct rte_tcp_hdr *th; - uint16_t prev_cksum, new_cksum, ip_len, ip_paylen; + uint16_t prev_cksum, new_cksum; + uint32_t ip_paylen; uint32_t tmp; iph = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, m->l2_len); th = RTE_PTR_ADD(iph, m->l3_len); + + /* + * Calculate IPv4 header checksum with current total length value + * (whatever it is) to have correct checksum after update on edits + * done by TSO. + */ if ((iph->version_ihl >> 4) == 4) { iph->hdr_checksum = 0; iph->hdr_checksum = rte_ipv4_cksum(iph); - ip_len = iph->total_length; - ip_paylen = rte_cpu_to_be_16(rte_be_to_cpu_16(ip_len) - - m->l3_len); - } else { - ip6h = (struct rte_ipv6_hdr *)iph; - ip_paylen = ip6h->payload_len; } + /* + * Do not use IPv4 total length and IPv6 payload length fields to get + * TSO payload length since it could not fit into 16 bits. + */ + ip_paylen = rte_cpu_to_be_32(rte_pktmbuf_pkt_len(m) - m->l2_len - + m->l3_len); + /* calculate the new phdr checksum not including ip_paylen */ prev_cksum = th->cksum; tmp = prev_cksum; - tmp += ip_paylen; + tmp += (ip_paylen & 0xffff) + (ip_paylen >> 16); tmp = (tmp & 0xffff) + (tmp >> 16); new_cksum = tmp; -- 2.30.2