[PATCH v4] net: fix checksum with unaligned buffer
Stephen Hemminger
stephen at networkplumber.org
Thu Jun 30 19:45:45 CEST 2022
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.
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