Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2468111imd; Fri, 2 Nov 2018 11:56:34 -0700 (PDT) X-Google-Smtp-Source: AJdET5fwXK76UosSKnwpiM04VT6XHMS987xI3MTAjxMG2gsyBrBLTEJbhZ27E/HzwbxpaL0qyoWA X-Received: by 2002:a17:902:8689:: with SMTP id g9-v6mr12458784plo.44.1541184994290; Fri, 02 Nov 2018 11:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184994; cv=none; d=google.com; s=arc-20160816; b=q8PyVHfUhFQhlpJ4qKetQ9Zyb+Uow2dGuAHb04jEUv0K010h8I60meXcnZFu7S3b0W MtTMRFJBnZ9BrVUhRjG19OdPKIe0HAF9nuvExPRZzZBpjeQm/XpAbKRKPvnocz9Ip5A/ k0BYNJ9+KYfcY3WyD6aE5Xpb2hRSSt4Kz0wtq/JXuQNjNjdoIUU+5hSnSr1aQEIuuwQx Sb4xQXSfJ15B+K4/njGBAOjSReX3nul8SRrUWOXgVOSdwNSXv4HLzhHc77UUyDe/SZEN e7ykTQRXJ2ru35k6L3V9ZvSoQj1ufemUnlsKSK9n4qbc0JcKPFdZOzjHp8ozOcAeGFfj 5lcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6zmRgUxvQf0kl2cv1XZMe2yi14LPrAO5Gvxouw3+h6o=; b=z6fwNPFnepAauUV1le7RdKP6maPf/eOyFftb0wuRGzFqpvxGmRwEAb6Y6aRe58tXD8 S9v/CLbg06U6dWqbdt0JjKkunX9dj2RiC0VoVxbz/RxKNnYWz2+HeH0jHbA0frfoi4/P BcuSwEn3Z94d0yslGqOaAAVbv3GA5mbkG1Oo/Ah7ofgTYfDXuqE5w4845nCSlK1jUhYo 5qCHFLHhNvR50lHgPlkjtf0z1hLLC2bHNZlZDPxZEW07mBymJ9qBmm9TOw/yuqJYKZow Fe6Wr/ZbguMpfV4P3L/otfSgkktV1kmbkVS/sWc0K35ogbJEJYcimhc0t9gdmXJGt1OV JGZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xBZYoVfB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si7217057plk.397.2018.11.02.11.56.20; Fri, 02 Nov 2018 11:56:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xBZYoVfB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731528AbeKCEEM (ORCPT + 99 others); Sat, 3 Nov 2018 00:04:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726051AbeKCEEL (ORCPT ); Sat, 3 Nov 2018 00:04:11 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5CD2B2084D; Fri, 2 Nov 2018 18:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184954; bh=XAmiSXpO+pjfXfYlK5fit4q4my7lFuz7Thl1PkscpiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xBZYoVfBJVNMUSh8TDETIioHLXXJnQ93b6jzE3DcgGsiNAFLmO6PYmA2LE99b6jzI 4pFIb/1pNGFpFZ4U0xjrQ/TGTi7YAibE/s6Sj97ApFTVvLz5cbXxVi6ksZ5QNCrwsF fqPMv4FNX1r2fKb8tTFvoPCjQw9byxbzQ0W+Q0XA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pawe=C5=82=20Staszewski?= , Eric Dumazet , Eran Ben Elisha , Saeed Mahameed , Dimitris Michailidis , Cong Wang , Maria Pasechnik , "David S. Miller" Subject: [PATCH 4.14 139/143] net/mlx5e: fix csum adjustments caused by RXFCS Date: Fri, 2 Nov 2018 19:35:24 +0100 Message-Id: <20181102182908.816507452@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182857.064326086@linuxfoundation.org> References: <20181102182857.064326086@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit d48051c5b8376038c2b287c3b1bd55b8d391d567 ] As shown by Dmitris, we need to use csum_block_add() instead of csum_add() when adding the FCS contribution to skb csum. Before 4.18 (more exactly commit 88078d98d1bb "net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends"), the whole skb csum was thrown away, so RXFCS changes were ignored. Then before commit d55bef5059dd ("net: fix pskb_trim_rcsum_slow() with odd trim offset") both mlx5 and pskb_trim_rcsum_slow() bugs were canceling each other. Now we fixed pskb_trim_rcsum_slow() we need to fix mlx5. Note that this patch also rewrites mlx5e_get_fcs() to : - Use skb_header_pointer() instead of reinventing it. - Use __get_unaligned_cpu32() to avoid possible non aligned accesses as Dmitris pointed out. Fixes: 902a545904c7 ("net/mlx5e: When RXFCS is set, add FCS data into checksum calculation") Reported-by: Paweł Staszewski Signed-off-by: Eric Dumazet Cc: Eran Ben Elisha Cc: Saeed Mahameed Cc: Dimitris Michailidis Cc: Cong Wang Cc: Paweł Staszewski Reviewed-by: Eran Ben Elisha Tested-By: Maria Pasechnik Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 45 ++++-------------------- 1 file changed, 9 insertions(+), 36 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -635,43 +635,15 @@ static inline bool is_first_ethertype_ip return (ethertype == htons(ETH_P_IP) || ethertype == htons(ETH_P_IPV6)); } -static __be32 mlx5e_get_fcs(struct sk_buff *skb) +static u32 mlx5e_get_fcs(const struct sk_buff *skb) { - int last_frag_sz, bytes_in_prev, nr_frags; - u8 *fcs_p1, *fcs_p2; - skb_frag_t *last_frag; - __be32 fcs_bytes; - - if (!skb_is_nonlinear(skb)) - return *(__be32 *)(skb->data + skb->len - ETH_FCS_LEN); - - nr_frags = skb_shinfo(skb)->nr_frags; - last_frag = &skb_shinfo(skb)->frags[nr_frags - 1]; - last_frag_sz = skb_frag_size(last_frag); - - /* If all FCS data is in last frag */ - if (last_frag_sz >= ETH_FCS_LEN) - return *(__be32 *)(skb_frag_address(last_frag) + - last_frag_sz - ETH_FCS_LEN); - - fcs_p2 = (u8 *)skb_frag_address(last_frag); - bytes_in_prev = ETH_FCS_LEN - last_frag_sz; - - /* Find where the other part of the FCS is - Linear or another frag */ - if (nr_frags == 1) { - fcs_p1 = skb_tail_pointer(skb); - } else { - skb_frag_t *prev_frag = &skb_shinfo(skb)->frags[nr_frags - 2]; + const void *fcs_bytes; + u32 _fcs_bytes; - fcs_p1 = skb_frag_address(prev_frag) + - skb_frag_size(prev_frag); - } - fcs_p1 -= bytes_in_prev; - - memcpy(&fcs_bytes, fcs_p1, bytes_in_prev); - memcpy(((u8 *)&fcs_bytes) + bytes_in_prev, fcs_p2, last_frag_sz); + fcs_bytes = skb_header_pointer(skb, skb->len - ETH_FCS_LEN, + ETH_FCS_LEN, &_fcs_bytes); - return fcs_bytes; + return __get_unaligned_cpu32(fcs_bytes); } static inline void mlx5e_handle_csum(struct net_device *netdev, @@ -693,8 +665,9 @@ static inline void mlx5e_handle_csum(str skb->ip_summed = CHECKSUM_COMPLETE; skb->csum = csum_unfold((__force __sum16)cqe->check_sum); if (unlikely(netdev->features & NETIF_F_RXFCS)) - skb->csum = csum_add(skb->csum, - (__force __wsum)mlx5e_get_fcs(skb)); + skb->csum = csum_block_add(skb->csum, + (__force __wsum)mlx5e_get_fcs(skb), + skb->len - ETH_FCS_LEN); rq->stats.csum_complete++; return; }