[PATCH v3] net/vhost: fix SW checksum when zero
Maxime Coquelin
maxime.coquelin at redhat.com
Tue Oct 20 13:19:21 CEST 2026
On 10/18/26 11:20 AM, Morten Brørup wrote:
> There is a special rule for UDP, where a checksum of zero is as 0xffff
> instead of zero.
>
> Identifying packet types requires masking with the mask, not the value,
> before comparing to the value.
> Identifying by masking with the L4 UDP packet type value (0x00000200)
> instead of the L4 packet type mask caused other L4 packet types to match;
> specifically IP fragments, IGMP packets, and certain non-fragments.
> This meant that some non-UDP packets followed the special UDP checksum
> rule, which they should not.
>
> Updated to mask the packet type with the L4 packet type mask and then
> compare to the L4 UDP packet type value, so only UDP packets follow the
> special UDP checksum rule.
>
> Furthermore, according to the mbuf documentation, Tx checksum offload
> requires that "ol_flags" is set, and only mentions "packet_type" for Rx,
> so use "ol_flags" instead of "packet_type" for checking the packet type
> at Tx.
>
> Furthermore, writing the checksum needs room for 2 bytes, not 1 byte.
>
> Note:
> Using "if (unlikely(cksum == 0) && PTYPE_MATCH)" to advise the optimizer
> about the need to evaluate PTYPE_MATCH being unlikely.
> The probability of cksum being zero is only 1/65536, so it's better to
> branch early.
>
> Fixes: 8ba1723783b2 ("net/vhost: perform SW checksum in Tx path")
> Fixes: 8f1750f42e2d ("net/vhost: perform SW checksum in Rx path")
> Cc: stable at dpdk.org
>
> Signed-off-by: Morten Brørup <mb at smartsharesystems.com>
> ---
> v3:
> * Writing the checksum needs room for 2 bytes, not 1 byte.
> v2:
> * Use ol_flags instead of packet_type for Tx.
> * Added note about the use of unlikely().
> ---
> drivers/net/vhost/rte_eth_vhost.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
Applied to next-virtio/for-next-net.
Thanks,
Maxime
More information about the stable
mailing list