[v3,01/16] gso: remove logtype

Message ID 20230210010724.890413-2-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Replace use of static logtypes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 10, 2023, 1:07 a.m. UTC
  If a large packet is passed into GSO routines of unknown protocol
then library would log a message and pass it through. This is incorrect
behaviour on many levels:
  - it allows oversize packet to get passed on to NIC driver
  - no direct return is visible to applications
  - if it happens once, many more will follow and log will fill.
  - bonus it is only log message with GSO type.

The fix is to just return -EINVAL which is what this library
does in many other places when looking at headers.

Fixes: 119583797b6a ("gso: support TCP/IPv4 GSO")
Cc: jiayu.hu@intel.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_log.c | 2 +-
 lib/eal/include/rte_log.h       | 1 -
 lib/gso/rte_gso.c               | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)
  

Comments

fengchengwen Feb. 10, 2023, 1:47 a.m. UTC | #1
On 2023/2/10 9:07, Stephen Hemminger wrote:
> If a large packet is passed into GSO routines of unknown protocol
> then library would log a message and pass it through. This is incorrect
> behaviour on many levels:
>   - it allows oversize packet to get passed on to NIC driver
>   - no direct return is visible to applications
>   - if it happens once, many more will follow and log will fill.
>   - bonus it is only log message with GSO type.
> 
> The fix is to just return -EINVAL which is what this library
> does in many other places when looking at headers.

Hi Stephen,

1. this patch do two thing (remove logtype and return -EINVAL), suggest seperate them.
2. I think we should keep rte_gso_segment return 0 when unmatch:
   a. the rte_gso_segment API requirement input mbuf set right ol_flags:
       * Before calling rte_gso_segment(), applications must set proper ol_flags
       * for the packet. The GSO library uses the same macros as that of TSO.
       * For example, set RTE_MBUF_F_TX_TCP_SEG and RTE_MBUF_F_TX_IPV4 in ol_flags to segment
       * a TCP/IPv4 packet. If rte_gso_segment() succeeds, the RTE_MBUF_F_TX_TCP_SEG
       * flag is removed for all GSO segments and the input packet.
   b. the rte_gso_segment filter and process mbuf according "struct rte_gso_ctx", for one
      stream which combine with udp and vxlan-tcp, we could only segment vxlan-tcp.

Thanks.

> 
> Fixes: 119583797b6a ("gso: support TCP/IPv4 GSO")
> Cc: jiayu.hu@intel.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/eal/common/eal_common_log.c | 2 +-
>  lib/eal/include/rte_log.h       | 1 -
>  lib/gso/rte_gso.c               | 3 +--
>  3 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
> index bd7b188ceb4a..c369154cb1ea 100644
> --- a/lib/eal/common/eal_common_log.c
> +++ b/lib/eal/common/eal_common_log.c
> @@ -368,7 +368,7 @@ static const struct logtype logtype_strings[] = {
>  	{RTE_LOGTYPE_CRYPTODEV,  "lib.cryptodev"},
>  	{RTE_LOGTYPE_EFD,        "lib.efd"},
>  	{RTE_LOGTYPE_EVENTDEV,   "lib.eventdev"},
> -	{RTE_LOGTYPE_GSO,        "lib.gso"},
> +
>  	{RTE_LOGTYPE_USER1,      "user1"},
>  	{RTE_LOGTYPE_USER2,      "user2"},
>  	{RTE_LOGTYPE_USER3,      "user3"},
> diff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h
> index 6d2b0856a565..97d6b26a9967 100644
> --- a/lib/eal/include/rte_log.h
> +++ b/lib/eal/include/rte_log.h
> @@ -46,7 +46,6 @@ extern "C" {
>  #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
>  #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
>  #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
> -#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
>  
>  /* these log types can be used in an application */
>  #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
> diff --git a/lib/gso/rte_gso.c b/lib/gso/rte_gso.c
> index 4b59217c16ee..19c351769fcc 100644
> --- a/lib/gso/rte_gso.c
> +++ b/lib/gso/rte_gso.c
> @@ -81,8 +81,7 @@ rte_gso_segment(struct rte_mbuf *pkt,
>  				indirect_pool, pkts_out, nb_pkts_out);
>  	} else {
>  		/* unsupported packet, skip */
> -		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
> -		ret = 0;
> +		ret = -EINVAL;
>  	}
>  
>  	if (ret < 0) {
>
  
Hu, Jiayu Feb. 10, 2023, 2:29 a.m. UTC | #2
Hi Stephen,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Friday, February 10, 2023 9:07 AM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Hu, Jiayu
> <jiayu.hu@intel.com>; Konstantin Ananyev
> <konstantin.v.ananyev@yandex.ru>; Mark Kavanagh
> <mark.b.kavanagh@intel.com>
> Subject: [PATCH v3 01/16] gso: remove logtype
> 
> If a large packet is passed into GSO routines of unknown protocol then library
> would log a message and pass it through. This is incorrect behaviour on many
> levels:
>   - it allows oversize packet to get passed on to NIC driver

Applications use SW GSO only if NIC segmentation is not
supported. For a burst of packets mixed with different packet
types, GSO doesn't process the packet with unsupported types,
and the oversize packets go to NIC and get dropped finally.
I presume this case frequently happen in real cases.

>   - no direct return is visible to applications
>   - if it happens once, many more will follow and log will fill.
>   - bonus it is only log message with GSO type.
> 
> The fix is to just return -EINVAL which is what this library does in many other
> places when looking at headers.
> 
> Fixes: 119583797b6a ("gso: support TCP/IPv4 GSO")
> Cc: jiayu.hu@intel.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/eal/common/eal_common_log.c | 2 +-
>  lib/eal/include/rte_log.h       | 1 -
>  lib/gso/rte_gso.c               | 3 +--
>  3 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/eal/common/eal_common_log.c
> b/lib/eal/common/eal_common_log.c index bd7b188ceb4a..c369154cb1ea
> 100644
> --- a/lib/eal/common/eal_common_log.c
> +++ b/lib/eal/common/eal_common_log.c
> @@ -368,7 +368,7 @@ static const struct logtype logtype_strings[] = {
>  	{RTE_LOGTYPE_CRYPTODEV,  "lib.cryptodev"},
>  	{RTE_LOGTYPE_EFD,        "lib.efd"},
>  	{RTE_LOGTYPE_EVENTDEV,   "lib.eventdev"},
> -	{RTE_LOGTYPE_GSO,        "lib.gso"},
> +
>  	{RTE_LOGTYPE_USER1,      "user1"},
>  	{RTE_LOGTYPE_USER2,      "user2"},
>  	{RTE_LOGTYPE_USER3,      "user3"},
> diff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h index
> 6d2b0856a565..97d6b26a9967 100644
> --- a/lib/eal/include/rte_log.h
> +++ b/lib/eal/include/rte_log.h
> @@ -46,7 +46,6 @@ extern "C" {
>  #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
>  #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
>  #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
> -#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
> 
>  /* these log types can be used in an application */
>  #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
> diff --git a/lib/gso/rte_gso.c b/lib/gso/rte_gso.c index
> 4b59217c16ee..19c351769fcc 100644
> --- a/lib/gso/rte_gso.c
> +++ b/lib/gso/rte_gso.c
> @@ -81,8 +81,7 @@ rte_gso_segment(struct rte_mbuf *pkt,
>  				indirect_pool, pkts_out, nb_pkts_out);
>  	} else {
>  		/* unsupported packet, skip */
> -		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
> -		ret = 0;
> +		ret = -EINVAL;

If applications want to know that the packet is failed on SW GSO,
I think ENOTSUP is better than EINVAL, as it is not invalid input
from users.

Thanks,
Jiayu

>  	}
> 
>  	if (ret < 0) {
> --
> 2.39.1
  
Stephen Hemminger Feb. 10, 2023, 2:46 a.m. UTC | #3
On Fri, 10 Feb 2023 02:29:44 +0000
"Hu, Jiayu" <jiayu.hu@intel.com> wrote:

> Hi Stephen,
> 
> > -----Original Message-----
> > From: Stephen Hemminger <stephen@networkplumber.org>
> > Sent: Friday, February 10, 2023 9:07 AM
> > To: dev@dpdk.org
> > Cc: Stephen Hemminger <stephen@networkplumber.org>; Hu, Jiayu
> > <jiayu.hu@intel.com>; Konstantin Ananyev
> > <konstantin.v.ananyev@yandex.ru>; Mark Kavanagh
> > <mark.b.kavanagh@intel.com>
> > Subject: [PATCH v3 01/16] gso: remove logtype
> > 
> > If a large packet is passed into GSO routines of unknown protocol then library
> > would log a message and pass it through. This is incorrect behaviour on many
> > levels:
> >   - it allows oversize packet to get passed on to NIC driver  
> 
> Applications use SW GSO only if NIC segmentation is not
> supported. For a burst of packets mixed with different packet
> types, GSO doesn't process the packet with unsupported types,
> and the oversize packets go to NIC and get dropped finally.
> I presume this case frequently happen in real cases.
> 
> >   - no direct return is visible to applications
> >   - if it happens once, many more will follow and log will fill.
> >   - bonus it is only log message with GSO type.
> > 
> > The fix is to just return -EINVAL which is what this library does in many other
> > places when looking at headers.
> > 
> > Fixes: 119583797b6a ("gso: support TCP/IPv4 GSO")
> > Cc: jiayu.hu@intel.com
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  lib/eal/common/eal_common_log.c | 2 +-
> >  lib/eal/include/rte_log.h       | 1 -
> >  lib/gso/rte_gso.c               | 3 +--
> >  3 files changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/lib/eal/common/eal_common_log.c
> > b/lib/eal/common/eal_common_log.c index bd7b188ceb4a..c369154cb1ea
> > 100644
> > --- a/lib/eal/common/eal_common_log.c
> > +++ b/lib/eal/common/eal_common_log.c
> > @@ -368,7 +368,7 @@ static const struct logtype logtype_strings[] = {
> >  	{RTE_LOGTYPE_CRYPTODEV,  "lib.cryptodev"},
> >  	{RTE_LOGTYPE_EFD,        "lib.efd"},
> >  	{RTE_LOGTYPE_EVENTDEV,   "lib.eventdev"},
> > -	{RTE_LOGTYPE_GSO,        "lib.gso"},
> > +
> >  	{RTE_LOGTYPE_USER1,      "user1"},
> >  	{RTE_LOGTYPE_USER2,      "user2"},
> >  	{RTE_LOGTYPE_USER3,      "user3"},
> > diff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h index
> > 6d2b0856a565..97d6b26a9967 100644
> > --- a/lib/eal/include/rte_log.h
> > +++ b/lib/eal/include/rte_log.h
> > @@ -46,7 +46,6 @@ extern "C" {
> >  #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
> >  #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
> >  #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
> > -#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
> > 
> >  /* these log types can be used in an application */
> >  #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
> > diff --git a/lib/gso/rte_gso.c b/lib/gso/rte_gso.c index
> > 4b59217c16ee..19c351769fcc 100644
> > --- a/lib/gso/rte_gso.c
> > +++ b/lib/gso/rte_gso.c
> > @@ -81,8 +81,7 @@ rte_gso_segment(struct rte_mbuf *pkt,
> >  				indirect_pool, pkts_out, nb_pkts_out);
> >  	} else {
> >  		/* unsupported packet, skip */
> > -		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
> > -		ret = 0;
> > +		ret = -EINVAL;  
> 
> If applications want to know that the packet is failed on SW GSO,
> I think ENOTSUP is better than EINVAL, as it is not invalid input
> from users.

Ok, just wanted to do the same thing as what would happen
earlier in the code path for cases where the arguments are incorrect.
Doing -ENOTSUP makes sense.
  

Patch

diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index bd7b188ceb4a..c369154cb1ea 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -368,7 +368,7 @@  static const struct logtype logtype_strings[] = {
 	{RTE_LOGTYPE_CRYPTODEV,  "lib.cryptodev"},
 	{RTE_LOGTYPE_EFD,        "lib.efd"},
 	{RTE_LOGTYPE_EVENTDEV,   "lib.eventdev"},
-	{RTE_LOGTYPE_GSO,        "lib.gso"},
+
 	{RTE_LOGTYPE_USER1,      "user1"},
 	{RTE_LOGTYPE_USER2,      "user2"},
 	{RTE_LOGTYPE_USER3,      "user3"},
diff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h
index 6d2b0856a565..97d6b26a9967 100644
--- a/lib/eal/include/rte_log.h
+++ b/lib/eal/include/rte_log.h
@@ -46,7 +46,6 @@  extern "C" {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
-#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
diff --git a/lib/gso/rte_gso.c b/lib/gso/rte_gso.c
index 4b59217c16ee..19c351769fcc 100644
--- a/lib/gso/rte_gso.c
+++ b/lib/gso/rte_gso.c
@@ -81,8 +81,7 @@  rte_gso_segment(struct rte_mbuf *pkt,
 				indirect_pool, pkts_out, nb_pkts_out);
 	} else {
 		/* unsupported packet, skip */
-		RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
-		ret = 0;
+		ret = -EINVAL;
 	}
 
 	if (ret < 0) {