* [dpdk-stable] [PATCH] bugfix: rte_raw_checksum @ 2020-05-27 13:40 guohongzhi 2020-05-27 14:58 ` [dpdk-stable] [dpdk-dev] " Morten Brørup 2020-06-24 12:21 ` [dpdk-stable] " Thomas Monjalon 0 siblings, 2 replies; 8+ messages in thread From: guohongzhi @ 2020-05-27 13:40 UTC (permalink / raw) To: dev Cc: stable, olivier.matz, mb, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin, guohongzhi1 From: Hongzhi Guo <guohongzhi1@huawei.com> __rte_raw_cksum should consider Big Endian. Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> --- lib/librte_net/rte_ip.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h index 1ceb7b7..eb863d4 100644 --- a/lib/librte_net/rte_ip.h +++ b/lib/librte_net/rte_ip.h @@ -140,7 +140,11 @@ __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) /* if length is in odd bytes */ if (len == 1) +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) + sum += *((const uint8_t *)u16_buf) << 8; +#else sum += *((const uint8_t *)u16_buf); +#endif return sum; } -- 2.21.0.windows.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH] bugfix: rte_raw_checksum 2020-05-27 13:40 [dpdk-stable] [PATCH] bugfix: rte_raw_checksum guohongzhi @ 2020-05-27 14:58 ` Morten Brørup 2020-06-24 12:21 ` [dpdk-stable] " Thomas Monjalon 1 sibling, 0 replies; 8+ messages in thread From: Morten Brørup @ 2020-05-27 14:58 UTC (permalink / raw) To: guohongzhi, dev Cc: stable, olivier.matz, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of guohongzhi > Sent: Wednesday, May 27, 2020 3:40 PM > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > __rte_raw_cksum should consider Big Endian. > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > --- > lib/librte_net/rte_ip.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h > index 1ceb7b7..eb863d4 100644 > --- a/lib/librte_net/rte_ip.h > +++ b/lib/librte_net/rte_ip.h > @@ -140,7 +140,11 @@ __rte_raw_cksum(const void *buf, size_t len, > uint32_t sum) > > /* if length is in odd bytes */ > if (len == 1) > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > + sum += *((const uint8_t *)u16_buf) << 8; > +#else > sum += *((const uint8_t *)u16_buf); > +#endif > > return sum; > } > -- > 2.21.0.windows.1 > > Acked-by: Morten Brørup <mb@smartsharesystems.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [PATCH] bugfix: rte_raw_checksum 2020-05-27 13:40 [dpdk-stable] [PATCH] bugfix: rte_raw_checksum guohongzhi 2020-05-27 14:58 ` [dpdk-stable] [dpdk-dev] " Morten Brørup @ 2020-06-24 12:21 ` Thomas Monjalon 2020-06-24 13:00 ` Morten Brørup 1 sibling, 1 reply; 8+ messages in thread From: Thomas Monjalon @ 2020-06-24 12:21 UTC (permalink / raw) To: guohongzhi1 Cc: dev, stable, olivier.matz, mb, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin 27/05/2020 15:40, guohongzhi: > From: Hongzhi Guo <guohongzhi1@huawei.com> > > __rte_raw_cksum should consider Big Endian. We need to explain the logic in the commit log. > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > --- > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > + sum += *((const uint8_t *)u16_buf) << 8; > +#else > sum += *((const uint8_t *)u16_buf); > +#endif *((const uint8_t *)u16_buf) should be an uint8_t. What is the expected behaviour of shifting 8 bits of a byte? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [PATCH] bugfix: rte_raw_checksum 2020-06-24 12:21 ` [dpdk-stable] " Thomas Monjalon @ 2020-06-24 13:00 ` Morten Brørup 2020-06-24 15:04 ` Thomas Monjalon 0 siblings, 1 reply; 8+ messages in thread From: Morten Brørup @ 2020-06-24 13:00 UTC (permalink / raw) To: Thomas Monjalon, guohongzhi1 Cc: dev, stable, olivier.matz, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Wednesday, June 24, 2020 2:22 PM > > 27/05/2020 15:40, guohongzhi: > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > > > __rte_raw_cksum should consider Big Endian. > > We need to explain the logic in the commit log. Having grown up with big endian CPUs, reading the final byte like this is obvious to me. I struggle understanding the little endian way of reading the last byte. (Not really anymore, but back when little endian was unfamiliar to me I would have struggled.) An RFC (I can't remember which) describes why the same checksum calculation code works on both big and little endian CPUs. Is it this explanation you are asking for? > > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > > --- > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > + sum += *((const uint8_t *)u16_buf) << 8; > > +#else > > sum += *((const uint8_t *)u16_buf); > > +#endif > > *((const uint8_t *)u16_buf) should be an uint8_t. > What is the expected behaviour of shifting 8 bits of a byte? Yes, the value will be an uint8_t type. But the shift operation will cause the compiler to promote the type to int before shifting it. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [PATCH] bugfix: rte_raw_checksum 2020-06-24 13:00 ` Morten Brørup @ 2020-06-24 15:04 ` Thomas Monjalon 2020-06-24 15:11 ` [dpdk-stable] [dpdk-dev] " Morten Brørup 0 siblings, 1 reply; 8+ messages in thread From: Thomas Monjalon @ 2020-06-24 15:04 UTC (permalink / raw) To: guohongzhi1 Cc: Morten Brørup, dev, stable, olivier.matz, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin 24/06/2020 15:00, Morten Brørup: > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > Sent: Wednesday, June 24, 2020 2:22 PM > > > > 27/05/2020 15:40, guohongzhi: > > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > > __rte_raw_cksum should consider Big Endian. > > > > We need to explain the logic in the commit log. > > Having grown up with big endian CPUs, reading the final byte like this is obvious to me. I struggle understanding the little endian way of reading the last byte. (Not really anymore, but back when little endian was unfamiliar to me I would have struggled.) > > An RFC (I can't remember which) describes why the same checksum calculation code works on both big and little endian CPUs. Is it this explanation you are asking for? This explanation may be interesting. > > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > > > --- > > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > > + sum += *((const uint8_t *)u16_buf) << 8; > > > +#else > > > sum += *((const uint8_t *)u16_buf); > > > +#endif > > > > *((const uint8_t *)u16_buf) should be an uint8_t. > > What is the expected behaviour of shifting 8 bits of a byte? > > Yes, the value will be an uint8_t type. But the shift operation will cause the compiler to promote the type to int before shifting it. This is the explanation I was looking for :-) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH] bugfix: rte_raw_checksum 2020-06-24 15:04 ` Thomas Monjalon @ 2020-06-24 15:11 ` Morten Brørup 2020-07-06 7:36 ` Olivier Matz 0 siblings, 1 reply; 8+ messages in thread From: Morten Brørup @ 2020-06-24 15:11 UTC (permalink / raw) To: Thomas Monjalon, guohongzhi1 Cc: dev, stable, olivier.matz, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon > Sent: Wednesday, June 24, 2020 5:04 PM > > 24/06/2020 15:00, Morten Brørup: > > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > > Sent: Wednesday, June 24, 2020 2:22 PM > > > > > > 27/05/2020 15:40, guohongzhi: > > > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > > > > __rte_raw_cksum should consider Big Endian. > > > > > > We need to explain the logic in the commit log. > > > > Having grown up with big endian CPUs, reading the final byte like > this is obvious to me. I struggle understanding the little endian way > of reading the last byte. (Not really anymore, but back when little > endian was unfamiliar to me I would have struggled.) > > > > An RFC (I can't remember which) describes why the same checksum > calculation code works on both big and little endian CPUs. Is it this > explanation you are asking for? > > This explanation may be interesting. > RFC 1071, especially chapter 3. Please note that big endian is considered "Normal" order in the RFC. :-) > > > > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > > > > --- > > > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > > > + sum += *((const uint8_t *)u16_buf) << 8; > > > > +#else > > > > sum += *((const uint8_t *)u16_buf); > > > > +#endif > > > > > > *((const uint8_t *)u16_buf) should be an uint8_t. > > > What is the expected behaviour of shifting 8 bits of a byte? > > > > Yes, the value will be an uint8_t type. But the shift operation will > cause the compiler to promote the type to int before shifting it. > > This is the explanation I was looking for :-) > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH] bugfix: rte_raw_checksum 2020-06-24 15:11 ` [dpdk-stable] [dpdk-dev] " Morten Brørup @ 2020-07-06 7:36 ` Olivier Matz 2020-07-06 7:46 ` Olivier Matz 0 siblings, 1 reply; 8+ messages in thread From: Olivier Matz @ 2020-07-06 7:36 UTC (permalink / raw) To: Morten Brørup Cc: Thomas Monjalon, guohongzhi1, dev, stable, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin Hi Hongzhi, I suggest the following title instead: net: fix checksum on big endian CPUs On Wed, Jun 24, 2020 at 05:11:19PM +0200, Morten Brørup wrote: > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon > > Sent: Wednesday, June 24, 2020 5:04 PM > > > > 24/06/2020 15:00, Morten Brørup: > > > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > > > Sent: Wednesday, June 24, 2020 2:22 PM > > > > > > > > 27/05/2020 15:40, guohongzhi: > > > > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > > > > > > __rte_raw_cksum should consider Big Endian. > > > > > > > > We need to explain the logic in the commit log. Here is a suggestion of commit log: 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. Can you please submit a new version with the 2 changes above? > > > > > > Having grown up with big endian CPUs, reading the final byte like > > this is obvious to me. I struggle understanding the little endian way > > of reading the last byte. (Not really anymore, but back when little > > endian was unfamiliar to me I would have struggled.) > > > > > > An RFC (I can't remember which) describes why the same checksum > > calculation code works on both big and little endian CPUs. Is it this > > explanation you are asking for? > > > > This explanation may be interesting. > > > > RFC 1071, especially chapter 3. > > Please note that big endian is considered "Normal" order in the RFC. :-) There is an errata for this RFC about the C code: see https://www.rfc-editor.org/errata/eid3133 > > > > > > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > --- > > > > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > > > > + sum += *((const uint8_t *)u16_buf) << 8; > > > > > +#else > > > > > sum += *((const uint8_t *)u16_buf); > > > > > +#endif > > > > > > > > *((const uint8_t *)u16_buf) should be an uint8_t. > > > > What is the expected behaviour of shifting 8 bits of a byte? > > > > > > Yes, the value will be an uint8_t type. But the shift operation will > > cause the compiler to promote the type to int before shifting it. > > > > This is the explanation I was looking for :-) > > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH] bugfix: rte_raw_checksum 2020-07-06 7:36 ` Olivier Matz @ 2020-07-06 7:46 ` Olivier Matz 0 siblings, 0 replies; 8+ messages in thread From: Olivier Matz @ 2020-07-06 7:46 UTC (permalink / raw) To: Morten Brørup Cc: Thomas Monjalon, guohongzhi1, dev, stable, konstantin.ananyev, jiayu.hu, ferruh.yigit, nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu, jerry.lilijun, haifeng.lin On Mon, Jul 06, 2020 at 09:36:25AM +0200, Olivier Matz wrote: > Hi Hongzhi, > > I suggest the following title instead: > > net: fix checksum on big endian CPUs > > On Wed, Jun 24, 2020 at 05:11:19PM +0200, Morten Brørup wrote: > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon > > > Sent: Wednesday, June 24, 2020 5:04 PM > > > > > > 24/06/2020 15:00, Morten Brørup: > > > > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > > > > Sent: Wednesday, June 24, 2020 2:22 PM > > > > > > > > > > 27/05/2020 15:40, guohongzhi: > > > > > > From: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > > > > > > > > __rte_raw_cksum should consider Big Endian. > > > > > > > > > > We need to explain the logic in the commit log. > > Here is a suggestion of commit log: > > 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. > > Can you please submit a new version with the 2 changes above? One more thing, please also add: Fixes: 6006818cfb26 ("net: new checksum functions") Cc: stable@dpdk.org Thanks Olivier > > > > > > > > > Having grown up with big endian CPUs, reading the final byte like > > > this is obvious to me. I struggle understanding the little endian way > > > of reading the last byte. (Not really anymore, but back when little > > > endian was unfamiliar to me I would have struggled.) > > > > > > > > An RFC (I can't remember which) describes why the same checksum > > > calculation code works on both big and little endian CPUs. Is it this > > > explanation you are asking for? > > > > > > This explanation may be interesting. > > > > > > > RFC 1071, especially chapter 3. > > > > Please note that big endian is considered "Normal" order in the RFC. :-) > > There is an errata for this RFC about the C code: > see https://www.rfc-editor.org/errata/eid3133 > > > > > > > > > > Signed-off-by: Hongzhi Guo <guohongzhi1@huawei.com> > > > > > > --- > > > > > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > > > > > + sum += *((const uint8_t *)u16_buf) << 8; > > > > > > +#else > > > > > > sum += *((const uint8_t *)u16_buf); > > > > > > +#endif > > > > > > > > > > *((const uint8_t *)u16_buf) should be an uint8_t. > > > > > What is the expected behaviour of shifting 8 bits of a byte? > > > > > > > > Yes, the value will be an uint8_t type. But the shift operation will > > > cause the compiler to promote the type to int before shifting it. > > > > > > This is the explanation I was looking for :-) > > > > > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-07-06 7:46 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-05-27 13:40 [dpdk-stable] [PATCH] bugfix: rte_raw_checksum guohongzhi 2020-05-27 14:58 ` [dpdk-stable] [dpdk-dev] " Morten Brørup 2020-06-24 12:21 ` [dpdk-stable] " Thomas Monjalon 2020-06-24 13:00 ` Morten Brørup 2020-06-24 15:04 ` Thomas Monjalon 2020-06-24 15:11 ` [dpdk-stable] [dpdk-dev] " Morten Brørup 2020-07-06 7:36 ` Olivier Matz 2020-07-06 7:46 ` Olivier Matz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).