patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] net/ena: fix L4 cksum flags condition for TX
@ 2019-08-01 11:45 Maciej Bielski
  2019-08-01 12:08 ` Michał Krawczyk
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej Bielski @ 2019-08-01 11:45 UTC (permalink / raw)
  To: dev
  Cc: Maciej Bielski, Michal Krawczyk, Marcin Wojtas, Guy Tzalik,
	Evgeny Schemeilin, Eduard Serra, igorc.mail, stable

During an if-condition evaluation, a 2-bit flag evaluates to 'true' for
'0x1', '0x2' and '0x3'. Thus, from this perspective these flags are
indistinguishable. To make them distinct, respective bits must be
extracted with a mask and then checked for strict equality.

Specifically here, even if `PKT_TX_UDP_CKSUM` (value '0x3') was set, the
expression `mbuf->ol_flags & PKT_TX_TCP` (the second flag of value
'0x1') is evaluated first and the result is 'true'. In consequence, for
UDP packets the execution flow enters an incorrect branch.

Fixes: 56b8b9b7e5d2 (net/ena: convert to new Tx offloads API)
Cc: stable@dpdk.org

Signed-off-by: Maciej Bielski <mba@semihalf.com>
Reported-by: Eduard Serra <eduser25@gmail.com>
---
 drivers/net/ena/ena_ethdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index f58334080..eb9d643f0 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -330,12 +330,13 @@ static inline void ena_tx_mbuf_prepare(struct rte_mbuf *mbuf,
 		}
 
 		/* check if L4 checksum is needed */
-		if ((mbuf->ol_flags & PKT_TX_TCP_CKSUM) &&
+		if (((mbuf->ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM) &&
 		    (queue_offloads & DEV_TX_OFFLOAD_TCP_CKSUM)) {
 			ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_TCP;
 			ena_tx_ctx->l4_csum_enable = true;
-		} else if ((mbuf->ol_flags & PKT_TX_UDP_CKSUM) &&
-			   (queue_offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
+		} else if (((mbuf->ol_flags & PKT_TX_L4_MASK) ==
+				PKT_TX_UDP_CKSUM) &&
+				(queue_offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
 			ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_UDP;
 			ena_tx_ctx->l4_csum_enable = true;
 		} else {
-- 
2.20.1


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

* Re: [dpdk-stable] [PATCH] net/ena: fix L4 cksum flags condition for TX
  2019-08-01 11:45 [dpdk-stable] [PATCH] net/ena: fix L4 cksum flags condition for TX Maciej Bielski
@ 2019-08-01 12:08 ` Michał Krawczyk
  2019-08-05 17:44   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Michał Krawczyk @ 2019-08-01 12:08 UTC (permalink / raw)
  To: Maciej Bielski
  Cc: dev, Marcin Wojtas, Guy Tzalik, Evgeny Schemeilin, Eduard Serra,
	igorc.mail, stable

czw., 1 sie 2019 o 13:45 Maciej Bielski <mba@semihalf.com> napisał(a):
>
> During an if-condition evaluation, a 2-bit flag evaluates to 'true' for
> '0x1', '0x2' and '0x3'. Thus, from this perspective these flags are
> indistinguishable. To make them distinct, respective bits must be
> extracted with a mask and then checked for strict equality.
>
> Specifically here, even if `PKT_TX_UDP_CKSUM` (value '0x3') was set, the
> expression `mbuf->ol_flags & PKT_TX_TCP` (the second flag of value
> '0x1') is evaluated first and the result is 'true'. In consequence, for
> UDP packets the execution flow enters an incorrect branch.
>
> Fixes: 56b8b9b7e5d2 (net/ena: convert to new Tx offloads API)
> Cc: stable@dpdk.org
>
> Signed-off-by: Maciej Bielski <mba@semihalf.com>
> Reported-by: Eduard Serra <eduser25@gmail.com>
Acked-by: Michal Krawczyk <mk@semihalf.com>
> ---
>  drivers/net/ena/ena_ethdev.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
> index f58334080..eb9d643f0 100644
> --- a/drivers/net/ena/ena_ethdev.c
> +++ b/drivers/net/ena/ena_ethdev.c
> @@ -330,12 +330,13 @@ static inline void ena_tx_mbuf_prepare(struct rte_mbuf *mbuf,
>                 }
>
>                 /* check if L4 checksum is needed */
> -               if ((mbuf->ol_flags & PKT_TX_TCP_CKSUM) &&
> +               if (((mbuf->ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM) &&
>                     (queue_offloads & DEV_TX_OFFLOAD_TCP_CKSUM)) {
>                         ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_TCP;
>                         ena_tx_ctx->l4_csum_enable = true;
> -               } else if ((mbuf->ol_flags & PKT_TX_UDP_CKSUM) &&
> -                          (queue_offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
> +               } else if (((mbuf->ol_flags & PKT_TX_L4_MASK) ==
> +                               PKT_TX_UDP_CKSUM) &&
> +                               (queue_offloads & DEV_TX_OFFLOAD_UDP_CKSUM)) {
>                         ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_UDP;
>                         ena_tx_ctx->l4_csum_enable = true;
>                 } else {
> --
> 2.20.1
>

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

* Re: [dpdk-stable] [PATCH] net/ena: fix L4 cksum flags condition for TX
  2019-08-01 12:08 ` Michał Krawczyk
@ 2019-08-05 17:44   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2019-08-05 17:44 UTC (permalink / raw)
  To: Michał Krawczyk
  Cc: stable, Maciej Bielski, dev, Marcin Wojtas, Guy Tzalik,
	Evgeny Schemeilin, Eduard Serra, igorc.mail

01/08/2019 14:08, Michał Krawczyk:
> czw., 1 sie 2019 o 13:45 Maciej Bielski <mba@semihalf.com> napisał(a):
> >
> > During an if-condition evaluation, a 2-bit flag evaluates to 'true' for
> > '0x1', '0x2' and '0x3'. Thus, from this perspective these flags are
> > indistinguishable. To make them distinct, respective bits must be
> > extracted with a mask and then checked for strict equality.
> >
> > Specifically here, even if `PKT_TX_UDP_CKSUM` (value '0x3') was set, the
> > expression `mbuf->ol_flags & PKT_TX_TCP` (the second flag of value
> > '0x1') is evaluated first and the result is 'true'. In consequence, for
> > UDP packets the execution flow enters an incorrect branch.
> >
> > Fixes: 56b8b9b7e5d2 (net/ena: convert to new Tx offloads API)
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Maciej Bielski <mba@semihalf.com>
> > Reported-by: Eduard Serra <eduser25@gmail.com>
> Acked-by: Michal Krawczyk <mk@semihalf.com>

Applied, thanks




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

end of thread, other threads:[~2019-08-05 17:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 11:45 [dpdk-stable] [PATCH] net/ena: fix L4 cksum flags condition for TX Maciej Bielski
2019-08-01 12:08 ` Michał Krawczyk
2019-08-05 17:44   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).