Search code examples
dpdk

dpdk Rx TCP checksum failed


I am using the checksum offloads feature in DPDK and it did not working under virtual macine. virtual port only support TCP checksum and do not support IP checksum.

so I config rxmode.offload txmode.offloads as below:

rxmode.offloads = DEV_RX_OFFLOAD_TCP_CKSUM 
txmode.offloads = DEV_TX_OFFLOAD_TCP_CKSUM
... ...
rte_eth_dev_configure()

For TX, I set the following parameters, it works good.

mbuf->l2_len = sizeof(*ethhdr)
mbuf->l3_len = ip header len
mbuf-ol_flags = RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_TCP_CKSUM

For RX, It will execute the following code:

 In drivers/net/virtio/virtio_rxtx.c  virtio_rx_offload function :
 929     if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
 930         hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len;
 931         if (hdr->csum_start <= hdrlen && l4_supported) {
 932             m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_NONE;
 933         } else {
                ...  ...
 952         }
 953     } else if (hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID && l4_supported) {
 954         m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
 955     }

hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM is true(line 929)

hdrlen = 54

hdr->csum_start = 34

so m->ol_flags = RTE_MBUF_F_RX_L4_CKSUM_NONE(line 932)

This cause rx checksum failed.

I think the code should enter line 953 not line 929, but I don’t know where hdr->flags be set to VIRTIO_NET_HDR_F_NEEDS_CSUM.

dpdk version is 21.11


Solution

  • According to the original commit, RX_L4_CKSUM_NONE helps to cover the virtio / vhost use case and indicates that "the checksum in packet may be wrong, but data integrity is valid".

    My takeaway from this explanation is that confirming the "data integrity" might be possible because of the very nature of this specific use case, but, since no checksum validation is done (the value is not recalculated), one cannot set RX_L4_CKSUM_GOOD or RX_L4_CKSUM_BAD. Hence RX_L4_CKSUM_NONE.

    Perhaps it pays to add a printout of rte_ipv4_udptcp_cksum_verify() invocation (temporarily) to the application. If it reports that the checksum is valid, then above explanation should prove correct (no checksum failure).