From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 35813A052A; Fri, 10 Jul 2020 14:37:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E2BA71DB66; Fri, 10 Jul 2020 14:37:25 +0200 (CEST) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 88C581D9AB for ; Fri, 10 Jul 2020 14:37:24 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id r12so5744184wrj.13 for ; Fri, 10 Jul 2020 05:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=o8NiTHFC+TMtWSVDqAM+8VvbE09EuvWhrwYRToxsQwI=; b=IgCwu29MBEWgkVO7F4kmnPOXPjQravpviOc6N3hXCuOybJyCKIT9EfCmd+QxjQgFq+ nM6avwMYR209ZpyeteNKqsvEkvBlZRPnxs2me80js/lbqJVCS0ZfjV2FyPDaabIwihd/ ZELJ6exQRIsWn7Uo1RfNZDs85zSq8/PGANYzvwQ5PGOhmk4baR4Xq7eZ+iFep89msi7I nA17makDxkPTxhgNrTquTqRboVjnu4ErT8cVWFBk2pgtAyJUSEAdOF41HHLR/Q6ngCbn 9jz/gOIXvujjk00tqx8HalVvDenT5Xhi0Im7tcKFROc4604AAJ7RD2L2IJMQhyTIRLEi sOwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=o8NiTHFC+TMtWSVDqAM+8VvbE09EuvWhrwYRToxsQwI=; b=XoI/Ktzl9/ae8AYz/uXuC109A8HqXIlaJIrx6nLH71CXBsztgjc8Shd1RXUrAIpp5C G3oR+TCuW6g12ewCjfwMbLMr9m/KfwDqFjT+r0CpXTrlzuBQnQl0Gc8W7LOpd5VxfjBp J4kzRmaDdMzm2nMWBpwZSQF00tmFQZVNFD5hwdbgG0hGz/RKN2PXYGnN8frDksvoRpmA 4HwWs/yUsrnoHqAFddfTIyrm8dkH5qQbE9eNgAecfgwwhRsrUkKi4Sjy4cpURi/QDmn1 De17EX0wqplDoKbTMY0HylJUTkGq+fNsctnzXIPAKoFaIC62JXQfHxDfBYT3UP5JR96M aUPw== X-Gm-Message-State: AOAM5310HierPmY5p1vORz27kPEksX4XRWgw2F9eoB0kmMyVocQtoZTq VOyX1lOkGpxe7zPlbDNG2wkttw== X-Google-Smtp-Source: ABdhPJyTrOuBgsYfKuqrVJqIO/rJYX6Gk1MXUrnCkVWnIB6Q0ulyOj58NK+NLylUA2rEqlG2b53H9w== X-Received: by 2002:adf:ce85:: with SMTP id r5mr75068025wrn.157.1594384644220; Fri, 10 Jul 2020 05:37:24 -0700 (PDT) Received: from 6wind.com (2a01cb0c0005a600345636f7e65ed1a0.ipv6.abo.wanadoo.fr. [2a01:cb0c:5:a600:3456:36f7:e65e:d1a0]) by smtp.gmail.com with ESMTPSA id t15sm9301401wmj.14.2020.07.10.05.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 05:37:23 -0700 (PDT) Date: Fri, 10 Jul 2020 14:37:22 +0200 From: Olivier Matz To: Morten =?iso-8859-1?Q?Br=F8rup?= Cc: Hongzhi Guo , dev@dpdk.org, stable@dpdk.org, stephen@networkplumber.org, thomas@monjalon.net, konstantin.ananyev@intel.com, ferruh.yigit@intel.com, nicolas.chautru@intel.com, zhoujingbin@huawei.com, chenchanghu@huawei.com, jerry.lilijun@huawei.com, haifeng.lin@huawei.com Message-ID: <20200710123722.GX5869@platinum> References: <20200710114313.7412-1-guohongzhi1@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35C61117@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35C61117@smartserver.smartshare.dk> User-Agent: Mutt/1.10.1 (2018-07-13) Subject: Re: [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" On Fri, Jul 10, 2020 at 02:20:08PM +0200, Morten Brørup wrote: > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Hongzhi Guo > > Sent: Friday, July 10, 2020 1:43 PM > > > > 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 > > --- > > 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; > > } > > -- > > 2.21.0.windows.1 > > > > This is correct for both big and little endian CPUs. > > Reviewed-by: Morten Brørup Acked-by: Olivier Matz Thanks!