net/virtio: handle Tx checksums correctly for tunnel packets

Message ID 20210830142655.18373-1-ivan.malov@oktetlabs.ru (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: handle Tx checksums correctly for tunnel packets |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing fail Testing issues

Commit Message

Ivan Malov Aug. 30, 2021, 2:26 p.m. UTC
  Tx prepare method calls rte_net_intel_cksum_prepare(), which
handles tunnel packets correctly, but Tx burst path does not
take tunnel presence into account when computing the offsets.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/net/virtio/virtqueue.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
  

Comments

Maxime Coquelin Sept. 13, 2021, 8:06 p.m. UTC | #1
On 8/30/21 4:26 PM, Ivan Malov wrote:
> Tx prepare method calls rte_net_intel_cksum_prepare(), which
> handles tunnel packets correctly, but Tx burst path does not
> take tunnel presence into account when computing the offsets.
> 
> Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  drivers/net/virtio/virtqueue.h | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> index 03957b2bd0..b83ff32efb 100644
> --- a/drivers/net/virtio/virtqueue.h
> +++ b/drivers/net/virtio/virtqueue.h
> @@ -620,19 +620,21 @@ static inline void
>  virtqueue_xmit_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *cookie)
>  {
>  	uint64_t csum_l4 = cookie->ol_flags & PKT_TX_L4_MASK;
> +	uint16_t o_l23_len = (cookie->ol_flags & PKT_TX_TUNNEL_MASK) ?
> +			     cookie->outer_l2_len + cookie->outer_l3_len : 0;
>  
>  	if (cookie->ol_flags & PKT_TX_TCP_SEG)
>  		csum_l4 |= PKT_TX_TCP_CKSUM;
>  
>  	switch (csum_l4) {
>  	case PKT_TX_UDP_CKSUM:
> -		hdr->csum_start = cookie->l2_len + cookie->l3_len;
> +		hdr->csum_start = o_l23_len + cookie->l2_len + cookie->l3_len;
>  		hdr->csum_offset = offsetof(struct rte_udp_hdr, dgram_cksum);
>  		hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
>  		break;
>  
>  	case PKT_TX_TCP_CKSUM:
> -		hdr->csum_start = cookie->l2_len + cookie->l3_len;
> +		hdr->csum_start = o_l23_len + cookie->l2_len + cookie->l3_len;
>  		hdr->csum_offset = offsetof(struct rte_tcp_hdr, cksum);
>  		hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
>  		break;
> @@ -650,7 +652,8 @@ virtqueue_xmit_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *cookie)
>  			VIRTIO_NET_HDR_GSO_TCPV6 :
>  			VIRTIO_NET_HDR_GSO_TCPV4;
>  		hdr->gso_size = cookie->tso_segsz;
> -		hdr->hdr_len = cookie->l2_len + cookie->l3_len + cookie->l4_len;
> +		hdr->hdr_len = o_l23_len + cookie->l2_len + cookie->l3_len +
> +			       cookie->l4_len;
>  	} else {
>  		ASSIGN_UNLESS_EQUAL(hdr->gso_type, 0);
>  		ASSIGN_UNLESS_EQUAL(hdr->gso_size, 0);
> 

It looks good to me, only thing missing the the fixes line so that it is
backported.

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index 03957b2bd0..b83ff32efb 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -620,19 +620,21 @@  static inline void
 virtqueue_xmit_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *cookie)
 {
 	uint64_t csum_l4 = cookie->ol_flags & PKT_TX_L4_MASK;
+	uint16_t o_l23_len = (cookie->ol_flags & PKT_TX_TUNNEL_MASK) ?
+			     cookie->outer_l2_len + cookie->outer_l3_len : 0;
 
 	if (cookie->ol_flags & PKT_TX_TCP_SEG)
 		csum_l4 |= PKT_TX_TCP_CKSUM;
 
 	switch (csum_l4) {
 	case PKT_TX_UDP_CKSUM:
-		hdr->csum_start = cookie->l2_len + cookie->l3_len;
+		hdr->csum_start = o_l23_len + cookie->l2_len + cookie->l3_len;
 		hdr->csum_offset = offsetof(struct rte_udp_hdr, dgram_cksum);
 		hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
 		break;
 
 	case PKT_TX_TCP_CKSUM:
-		hdr->csum_start = cookie->l2_len + cookie->l3_len;
+		hdr->csum_start = o_l23_len + cookie->l2_len + cookie->l3_len;
 		hdr->csum_offset = offsetof(struct rte_tcp_hdr, cksum);
 		hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
 		break;
@@ -650,7 +652,8 @@  virtqueue_xmit_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *cookie)
 			VIRTIO_NET_HDR_GSO_TCPV6 :
 			VIRTIO_NET_HDR_GSO_TCPV4;
 		hdr->gso_size = cookie->tso_segsz;
-		hdr->hdr_len = cookie->l2_len + cookie->l3_len + cookie->l4_len;
+		hdr->hdr_len = o_l23_len + cookie->l2_len + cookie->l3_len +
+			       cookie->l4_len;
 	} else {
 		ASSIGN_UNLESS_EQUAL(hdr->gso_type, 0);
 		ASSIGN_UNLESS_EQUAL(hdr->gso_size, 0);