Skip to content

Commit

Permalink
vhost: fix missing enqueue pseudo-header calculation
Browse files Browse the repository at this point in the history
[ upstream commit 7316b4fd610fe945a0bc20054ba5ab61b98bb155 ]

The Virtio specification requires that in case of checksum
offloading, the pseudo-header checksum must be set in the
L4 header.

When received from another Vhost-user port, the packet
checksum might already contain the pseudo-header checksum
but we have no way to know it. So we have no other choice
than doing the pseudo-header checksum systematically.

This patch handles this using the rte_net_intel_cksum_prepare()
helper.

Fixes: 859b480 ("vhost: add guest offload setting")

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
mcoquelin authored and cpaelzer committed Jul 7, 2022
1 parent faaab06 commit bf77b58
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/librte_vhost/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <rte_mbuf.h>
#include <rte_memcpy.h>
#include <rte_net.h>
#include <rte_ether.h>
#include <rte_ip.h>
#include <rte_vhost.h>
Expand Down Expand Up @@ -402,6 +403,16 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
csum_l4 |= PKT_TX_TCP_CKSUM;

if (csum_l4) {
/*
* Pseudo-header checksum must be set as per Virtio spec.
*
* Note: We don't propagate rte_net_intel_cksum_prepare()
* errors, as it would have an impact on performance, and an
* error would mean the packet is dropped by the guest instead
* of being dropped here.
*/
rte_net_intel_cksum_prepare(m_buf);

net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len;

Expand Down

0 comments on commit bf77b58

Please sign in to comment.