答复: [dpdk-users] DPDK RX TCP checksum failed

jiangheng (H) jiangheng12 at huawei.com
Mon Mar 28 03:50:16 CEST 2022


> On Sat, 26 Mar 2022 08:13:21 +0000
> "jiangheng (H)" <jiangheng12 at huawei.com> wrote:
> 
> > Hi all,
> >
> > I tried using the checksum offloads feature in DPDK and it did not see
> working under virtual machine.
> >
> > Port only support TCP checksum and do not support IP checksum:
> > rx_offload_capa = DEV_RX_OFFLOAD_TCP_CKSUM tx_offload_capa =
> > DEV_TX_OFFLOAD_TCP_CKSUM
> >
> > so I config rxmode.offload txmode.offloads as below:
> > rxmode.offloads = DEV_RX_OFFLOAD_TCP_CKSUM txmode.offloads =
> > DEV_TX_OFFLOAD_TCP_CKSUM
> >
> > 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
> 
> 
> Virtio does not support IP checksum offload.  Because Virtio passes
> packets to Linux kernel, and Linux kernel does not do IP checksum offload.
> The IP checksum is so trivial it is faster for most things to just do it in
> software; the header is only 20 bytes and it will be in cache.
> 
> You should always check device capability before enabling an offload.
> 
> 
> > For RX, It will execute the following code:
> > In drivers/net/virtio/virtio_rxtx.c  virtio_rx_offload function :
> >     if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> >         hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len;
> >         if (hdr->csum_start <= hdrlen && l4_supported) {
> >             m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_NONE;
> >         } else {
> >
> > m->ol_flags set to RTE_MBUF_F_RX_L4_CKSUM_NONE, causing the TCP
> RX checksum failed.
> > How do I avoid the above code going into this branch?
> >
> 
> If you want TCP checksum offload you have to set
> RTE_ETH_RX_OFFLOAD_TCP_CKSUM in the rxmode when port is
> configured.  This will tell virtio to ask the host to do rx offload. Again,
> virtio does not do IP checksum offload and you should always query
> device capability first.

I have queried device capability and it tell me it supports tcp checksum, not supports ip checksum. 
So I have set RTE_ETH_RX_OFFLOAD_TCP_CKSUM(DEV_RX_OFFLOAD_TCP_CKSUM) flag when port is configured(use rte_eth_dev_configure function)
But RX checksum still failed in below branch:
drivers/net/virtio/virtio_rxtx.c  virtio_rx_offload function:
if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
	hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len;
	if (hdr->csum_start <= hdrlen && l4_supported) {
		if (hdr->csum_start <= hdrlen && l4_supported) {
			m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_NONE;
		} else {
Hdr->csum_start <= hdrlen, m->ol_flags will set to RTE_MBUF_F_RX_L4_CKSUM_NONE, causing RX checksum failed.


More information about the users mailing list