All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
@ 2018-10-30  7:57 Eric Dumazet
  2018-10-30 18:09 ` Cong Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30  7:57 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Eran Ben Elisha,
	Saeed Mahameed, Dimitris Michailidis, Cong Wang,
	Paweł Staszewski

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 <pstaszewski@itcare.pl>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Eran Ben Elisha <eranbe@mellanox.com>
Cc: Saeed Mahameed <saeedm@mellanox.com>
Cc: Dimitris Michailidis <dmichail@google.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Paweł Staszewski <pstaszewski@itcare.pl>
---
 .../net/ethernet/mellanox/mlx5/core/en_rx.c   | 45 ++++---------------
 1 file changed, 9 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 94224c22ecc310a87b6715051e335446f29bec03..79638dcbae78395fb723c9bf3fa877e7a42d91cd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -713,43 +713,15 @@ static inline void mlx5e_enable_ecn(struct mlx5e_rq *rq, struct sk_buff *skb)
 	rq->stats->ecn_mark += !!rc;
 }
 
-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;
+	const void *fcs_bytes;
+	u32 _fcs_bytes;
 
-	if (!skb_is_nonlinear(skb))
-		return *(__be32 *)(skb->data + skb->len - ETH_FCS_LEN);
+	fcs_bytes = skb_header_pointer(skb, skb->len - ETH_FCS_LEN,
+				       ETH_FCS_LEN, &_fcs_bytes);
 
-	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];
-
-		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);
-
-	return fcs_bytes;
+	return __get_unaligned_cpu32(fcs_bytes);
 }
 
 static u8 get_ip_proto(struct sk_buff *skb, __be16 proto)
@@ -797,8 +769,9 @@ static inline void mlx5e_handle_csum(struct net_device *netdev,
 						 network_depth - ETH_HLEN,
 						 skb->csum);
 		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);
 		stats->csum_complete++;
 		return;
 	}
-- 
2.19.1.568.g152ad8e336-goog

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30  7:57 [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS Eric Dumazet
@ 2018-10-30 18:09 ` Cong Wang
  2018-10-30 18:42   ` Eric Dumazet
  2018-10-30 18:43   ` David Miller
  2018-10-31 11:27 ` Eran Ben Elisha
  2018-10-31 19:41 ` David Miller
  2 siblings, 2 replies; 8+ messages in thread
From: Cong Wang @ 2018-10-30 18:09 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, Linux Kernel Network Developers, Eric Dumazet,
	eranbe, Saeed Mahameed, dmichail, Paweł Staszewski

On Tue, Oct 30, 2018 at 12:57 AM Eric Dumazet <edumazet@google.com> wrote:
> -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;
> +       const void *fcs_bytes;
> +       u32 _fcs_bytes;
>
> -       if (!skb_is_nonlinear(skb))
> -               return *(__be32 *)(skb->data + skb->len - ETH_FCS_LEN);
> +       fcs_bytes = skb_header_pointer(skb, skb->len - ETH_FCS_LEN,
> +                                      ETH_FCS_LEN, &_fcs_bytes);

At least skb_header_pointer() is marked as __must_check, I don't see
you check its return value here.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30 18:09 ` Cong Wang
@ 2018-10-30 18:42   ` Eric Dumazet
  2018-10-30 18:59     ` Cong Wang
  2018-10-30 18:43   ` David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30 18:42 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, netdev, Eric Dumazet, Eran Ben Elisha,
	Saeed Mahameed, Dimitris Michailidis, Paweł Staszewski

On Tue, Oct 30, 2018 at 11:09 AM Cong Wang <xiyou.wangcong@gmail.com> wrote:

> At least skb_header_pointer() is marked as __must_check, I don't see
> you check its return value here.

This can not fail here.

skb->length must be above 14+4 at this point.

My compiler seems to be okay with that.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30 18:09 ` Cong Wang
  2018-10-30 18:42   ` Eric Dumazet
@ 2018-10-30 18:43   ` David Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David Miller @ 2018-10-30 18:43 UTC (permalink / raw)
  To: xiyou.wangcong
  Cc: edumazet, netdev, eric.dumazet, eranbe, saeedm, dmichail, pstaszewski

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Tue, 30 Oct 2018 11:09:21 -0700

> On Tue, Oct 30, 2018 at 12:57 AM Eric Dumazet <edumazet@google.com> wrote:
>> -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;
>> +       const void *fcs_bytes;
>> +       u32 _fcs_bytes;
>>
>> -       if (!skb_is_nonlinear(skb))
>> -               return *(__be32 *)(skb->data + skb->len - ETH_FCS_LEN);
>> +       fcs_bytes = skb_header_pointer(skb, skb->len - ETH_FCS_LEN,
>> +                                      ETH_FCS_LEN, &_fcs_bytes);
> 
> At least skb_header_pointer() is marked as __must_check, I don't see
> you check its return value here.

In this case we reasonably know it is guaranteed to succeed though.

We know skb->len is non-zero and we are asking for the skb->len - 1
byte or something like that.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30 18:42   ` Eric Dumazet
@ 2018-10-30 18:59     ` Cong Wang
  2018-10-30 19:03       ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Cong Wang @ 2018-10-30 18:59 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, Linux Kernel Network Developers, Eric Dumazet,
	eranbe, Saeed Mahameed, dmichail, Paweł Staszewski

On Tue, Oct 30, 2018 at 11:42 AM Eric Dumazet <edumazet@google.com> wrote:
>
> On Tue, Oct 30, 2018 at 11:09 AM Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> > At least skb_header_pointer() is marked as __must_check, I don't see
> > you check its return value here.
>
> This can not fail here.
>
> skb->length must be above 14+4 at this point.

Never say it is wrong, just saying what compiler thinks.

>
> My compiler seems to be okay with that.

I wonder how compiler recognizes it as "never fail" when marked with
__must_check.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30 18:59     ` Cong Wang
@ 2018-10-30 19:03       ` Eric Dumazet
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30 19:03 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, netdev, Eric Dumazet, Eran Ben Elisha,
	Saeed Mahameed, Dimitris Michailidis, Paweł Staszewski

On Tue, Oct 30, 2018 at 11:59 AM Cong Wang <xiyou.wangcong@gmail.com> wrote:

> I wonder how compiler recognizes it as "never fail" when marked with
> __must_check.

__must_check means that you can not ignore the return value of a function.

Here we do use the return value.

Also prior code was not checking skb->length so really my patch does
add explicit
check if in the future skb->len gets wrong after a bug is added in this driver.

(A NULL deref will trap the bug, instead of potentially reading
garbage from skb->data)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30  7:57 [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS Eric Dumazet
  2018-10-30 18:09 ` Cong Wang
@ 2018-10-31 11:27 ` Eran Ben Elisha
  2018-10-31 19:41 ` David Miller
  2 siblings, 0 replies; 8+ messages in thread
From: Eran Ben Elisha @ 2018-10-31 11:27 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller
  Cc: netdev, Eric Dumazet, Saeed Mahameed, Dimitris Michailidis,
	Cong Wang, Paweł Staszewski, Maria Pasechnik



On 10/30/2018 9:57 AM, Eric Dumazet wrote:
> 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 <pstaszewski@itcare.pl>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Eran Ben Elisha <eranbe@mellanox.com>
> Cc: Saeed Mahameed <saeedm@mellanox.com>
> Cc: Dimitris Michailidis <dmichail@google.com>
> Cc: Cong Wang <xiyou.wangcong@gmail.com>
> Cc: Paweł Staszewski <pstaszewski@itcare.pl>
> ---
>   .../net/ethernet/mellanox/mlx5/core/en_rx.c   | 45 ++++---------------
>   1 file changed, 9 insertions(+), 36 deletions(-)

Thanks for the modification!
We run a direct test we had for this scenario and it passed.

Reviewed-by: Eran Ben Elisha <eranbe@mellanox.com>
Tested-By: Maria Pasechnik <mariap@mellanox.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS
  2018-10-30  7:57 [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS Eric Dumazet
  2018-10-30 18:09 ` Cong Wang
  2018-10-31 11:27 ` Eran Ben Elisha
@ 2018-10-31 19:41 ` David Miller
  2 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2018-10-31 19:41 UTC (permalink / raw)
  To: edumazet
  Cc: netdev, eric.dumazet, eranbe, saeedm, dmichail, xiyou.wangcong,
	pstaszewski

From: Eric Dumazet <edumazet@google.com>
Date: Tue, 30 Oct 2018 00:57:25 -0700

> 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 <pstaszewski@itcare.pl>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-11-01  4:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-30  7:57 [PATCH net] net/mlx5e: fix csum adjustments caused by RXFCS Eric Dumazet
2018-10-30 18:09 ` Cong Wang
2018-10-30 18:42   ` Eric Dumazet
2018-10-30 18:59     ` Cong Wang
2018-10-30 19:03       ` Eric Dumazet
2018-10-30 18:43   ` David Miller
2018-10-31 11:27 ` Eran Ben Elisha
2018-10-31 19:41 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.