From patchwork Fri Jul 10 11:43:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hongzhi Guo X-Patchwork-Id: 73740 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 904D9A052A; Fri, 10 Jul 2020 13:43:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1DC5D1DADD; Fri, 10 Jul 2020 13:43:29 +0200 (CEST) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 633611DA02; Fri, 10 Jul 2020 13:43:27 +0200 (CEST) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C30329E9776C20B22BEC; Fri, 10 Jul 2020 19:43:24 +0800 (CST) Received: from DESKTOP-ORJPOMD.china.huawei.com (10.174.185.183) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 10 Jul 2020 19:43:18 +0800 From: Hongzhi Guo To: CC: , , , , , , , , , , , , Date: Fri, 10 Jul 2020 19:43:13 +0800 Message-ID: <20200710114313.7412-1-guohongzhi1@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.185.183] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] net: fix checksum on big endian CPUs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" With current code, the checksum of odd-length buffers is wrong on big endian CPUs: the last byte is not properly summed to the accumulator. Fix this by left-shifting the remaining byte by 8. For instance, if the last byte is 0x42, we should add 0x4200 to the accumulator on big endian CPUs. This change is similar to what is suggested in Errata 3133 of RFC 1071. Fixes: 6006818cfb26("net: new checksum functions") Cc: stable@dpdk.org Signed-off-by: Hongzhi Guo Reviewed-by: Morten Brørup Acked-by: Olivier Matz --- v2: * Explain the logic in the commit log * Fixed commit title --- --- lib/librte_net/rte_ip.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index 292f63fd7..4fb0e314a 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -139,8 +139,11 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) } /* if length is in odd bytes */ - if (len == 1) - sum += *((const uint8_t *)u16_buf); + if (len == 1) { + uint16_t left = 0; + *(uint8_t *)&left = *(const uint8_t *)u16_buf; + sum += left; + } return sum; }