Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/mlx4_en: don't set CHECKSUM_COMPLETE on SCTP packets

if the NIC fails to validate the checksum on TCP/UDP, and validation of IP
checksum is successful, the driver subtracts the pseudo-header checksum
from the value obtained by the hardware and sets CHECKSUM_COMPLETE. Don't
do that if protocol is IPPROTO_SCTP, otherwise CRC32c validation fails.

V2: don't test MLX4_CQE_STATUS_IPV6 if MLX4_CQE_STATUS_IPV4 is set

Reported-by: Shuang Li <shuali@redhat.com>
Fixes: f8c6455bb04b ("net/mlx4_en: Extend checksum offloading by CHECKSUM COMPLETE")
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Acked-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Davide Caratti and committed by
David S. Miller
e718fe45 eb2a6b80

+18 -11
+18 -11
drivers/net/ethernet/mellanox/mlx4/en_rx.c
··· 574 574 * header, the HW adds it. To address that, we are subtracting the pseudo 575 575 * header checksum from the checksum value provided by the HW. 576 576 */ 577 - static void get_fixed_ipv4_csum(__wsum hw_checksum, struct sk_buff *skb, 578 - struct iphdr *iph) 577 + static int get_fixed_ipv4_csum(__wsum hw_checksum, struct sk_buff *skb, 578 + struct iphdr *iph) 579 579 { 580 580 __u16 length_for_csum = 0; 581 581 __wsum csum_pseudo_header = 0; 582 + __u8 ipproto = iph->protocol; 583 + 584 + if (unlikely(ipproto == IPPROTO_SCTP)) 585 + return -1; 582 586 583 587 length_for_csum = (be16_to_cpu(iph->tot_len) - (iph->ihl << 2)); 584 588 csum_pseudo_header = csum_tcpudp_nofold(iph->saddr, iph->daddr, 585 - length_for_csum, iph->protocol, 0); 589 + length_for_csum, ipproto, 0); 586 590 skb->csum = csum_sub(hw_checksum, csum_pseudo_header); 591 + return 0; 587 592 } 588 593 589 594 #if IS_ENABLED(CONFIG_IPV6) ··· 599 594 static int get_fixed_ipv6_csum(__wsum hw_checksum, struct sk_buff *skb, 600 595 struct ipv6hdr *ipv6h) 601 596 { 597 + __u8 nexthdr = ipv6h->nexthdr; 602 598 __wsum csum_pseudo_hdr = 0; 603 599 604 - if (unlikely(ipv6h->nexthdr == IPPROTO_FRAGMENT || 605 - ipv6h->nexthdr == IPPROTO_HOPOPTS)) 600 + if (unlikely(nexthdr == IPPROTO_FRAGMENT || 601 + nexthdr == IPPROTO_HOPOPTS || 602 + nexthdr == IPPROTO_SCTP)) 606 603 return -1; 607 - hw_checksum = csum_add(hw_checksum, (__force __wsum)htons(ipv6h->nexthdr)); 604 + hw_checksum = csum_add(hw_checksum, (__force __wsum)htons(nexthdr)); 608 605 609 606 csum_pseudo_hdr = csum_partial(&ipv6h->saddr, 610 607 sizeof(ipv6h->saddr) + sizeof(ipv6h->daddr), 0); 611 608 csum_pseudo_hdr = csum_add(csum_pseudo_hdr, (__force __wsum)ipv6h->payload_len); 612 - csum_pseudo_hdr = csum_add(csum_pseudo_hdr, (__force __wsum)ntohs(ipv6h->nexthdr)); 609 + csum_pseudo_hdr = csum_add(csum_pseudo_hdr, 610 + (__force __wsum)htons(nexthdr)); 613 611 614 612 skb->csum = csum_sub(hw_checksum, csum_pseudo_hdr); 615 613 skb->csum = csum_add(skb->csum, csum_partial(ipv6h, sizeof(struct ipv6hdr), 0)); ··· 635 627 } 636 628 637 629 if (cqe->status & cpu_to_be16(MLX4_CQE_STATUS_IPV4)) 638 - get_fixed_ipv4_csum(hw_checksum, skb, hdr); 630 + return get_fixed_ipv4_csum(hw_checksum, skb, hdr); 639 631 #if IS_ENABLED(CONFIG_IPV6) 640 - else if (cqe->status & cpu_to_be16(MLX4_CQE_STATUS_IPV6)) 641 - if (unlikely(get_fixed_ipv6_csum(hw_checksum, skb, hdr))) 642 - return -1; 632 + if (cqe->status & cpu_to_be16(MLX4_CQE_STATUS_IPV6)) 633 + return get_fixed_ipv6_csum(hw_checksum, skb, hdr); 643 634 #endif 644 635 return 0; 645 636 }