<div dir="ltr"><a href="https://github.com/rodgarrison/reinvent">https://github.com/rodgarrison/reinvent</a><br>demonstrates ether/UDP chec-kum offload running on AWS which uses virtio. I don't think TCP offload<div>is substantially different. Look here:<br><br><a href="https://github.com/rodgarrison/reinvent/blob/main/integration_tests/reinvent_dpdk_udp/reinvent_dpdk_udp_integration_test.cpp#L345">https://github.com/rodgarrison/reinvent/blob/main/integration_tests/reinvent_dpdk_udp/reinvent_dpdk_udp_integration_test.cpp#L345</a><br><br>for where the mbuf needs to be setup.<br><br>But I kind of agree with Stephan, although I haven't tested it, avoiding more sets into mbuf which might involve cache misses it might be faster to do by hand since the data is already in cache.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 26, 2022 at 2:59 PM Stephen Hemminger <<a href="mailto:stephen@networkplumber.org">stephen@networkplumber.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, 26 Mar 2022 08:13:21 +0000<br>
"jiangheng (H)" <<a href="mailto:jiangheng12@huawei.com" target="_blank">jiangheng12@huawei.com</a>> wrote:<br>
<br>
> Hi all,<br>
> <br>
> I tried using the checksum offloads feature in DPDK and it did not see working under virtual machine.<br>
> <br>
> Port only support TCP checksum and do not support IP checksum:<br>
> rx_offload_capa = DEV_RX_OFFLOAD_TCP_CKSUM<br>
> tx_offload_capa = DEV_TX_OFFLOAD_TCP_CKSUM<br>
> <br>
> so I config rxmode.offload txmode.offloads as below:<br>
> rxmode.offloads = DEV_RX_OFFLOAD_TCP_CKSUM<br>
> txmode.offloads = DEV_TX_OFFLOAD_TCP_CKSUM<br>
> <br>
> For TX, I set the following parameters, it works good.<br>
> mbuf->l2_len = sizeof(*ethhdr)<br>
> mbuf->l3_len = ip header len<br>
> mbuf-ol_flags = RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_TCP_CKSUM<br>
<br>
<br>
Virtio does not support IP checksum offload.  Because Virtio passes<br>
packets to Linux kernel, and Linux kernel does not do IP checksum offload.<br>
The IP checksum is so trivial it is faster for most things to just<br>
do it in software; the header is only 20 bytes and it will be in cache.<br>
<br>
You should always check device capability before enabling an offload.<br>
<br>
<br>
> For RX, It will execute the following code:<br>
> In drivers/net/virtio/virtio_rxtx.c  virtio_rx_offload function :<br>
>     if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {<br>
>         hdrlen = hdr_lens.l2_len + hdr_lens.l3_len + hdr_lens.l4_len;<br>
>         if (hdr->csum_start <= hdrlen && l4_supported) {<br>
>             m->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_NONE;<br>
>         } else {<br>
> <br>
> m->ol_flags set to RTE_MBUF_F_RX_L4_CKSUM_NONE, causing the TCP RX checksum failed.<br>
> How do I avoid the above code going into this branch?<br>
> <br>
<br>
If you want TCP checksum offload you have to set RTE_ETH_RX_OFFLOAD_TCP_CKSUM<br>
in the rxmode when port is configured.  This will tell virtio to ask the<br>
host to do rx offload. Again, virtio does not do IP checksum offload and<br>
you should always query device capability first.<br>
<br>
</blockquote></div>