[PATCH v4] net: fix checksum with unaligned buffer

Emil Berg emil.berg at ericsson.com
Fri Jul 1 06:11:17 CEST 2022



> -----Original Message-----
> From: Stephen Hemminger <stephen at networkplumber.org>
> Sent: den 30 juni 2022 19:46
> To: Morten Brørup <mb at smartsharesystems.com>
> Cc: Emil Berg <emil.berg at ericsson.com>; bruce.richardson at intel.com;
> dev at dpdk.org; stable at dpdk.org; bugzilla at dpdk.org; hofors at lysator.liu.se;
> olivier.matz at 6wind.com
> Subject: Re: [PATCH v4] net: fix checksum with unaligned buffer
> 
> On Thu, 23 Jun 2022 14:39:00 +0200
> Morten Brørup <mb at smartsharesystems.com> wrote:
> 
> > +	/* if buffer is unaligned, keeping it byte order independent */
> > +	if (unlikely(unaligned)) {
> > +		uint16_t first = 0;
> > +		if (unlikely(len == 0))
> > +			return 0;
> 
> Why is length == 0 unique to unaligned case?
> 
> > +		((unsigned char *)&first)[1] = *(const unsigned
> char *)buf;
> 
> Use a proper union instead of casting to avoid aliasing warnings.
> 
> > +		bsum += first;
> > +		buf = RTE_PTR_ADD(buf, 1);
> > +		len--;
> > +	}
> 
> Many CPU's (such as x86) won't care about alignment and therefore the
> extra code to handle this is not worth doing.
> 

x86 does care about alignment. An example is the vmovdqa instruction, where 'a' stands for 'aligned'. The description in the link below says: "When the source or destination operand is a memory operand, the operand must be aligned on a 16-byte boundary or a general-protection exception (#GP) will be generated. "

https://www.felixcloutier.com/x86/movdqa:vmovdqa32:vmovdqa64

> Perhaps DPDK needs a macro (like Linux kernel) for efficient unaligned
> access.
> 
> In Linux kernel it is CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS


More information about the stable mailing list