diff mbox series

[1/2] net/i40e: compilation fix for GCC-12

Message ID 20220824140339.2581716-1-amitprakashs@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series [1/2] net/i40e: compilation fix for GCC-12 | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Amit Prakash Shukla Aug. 24, 2022, 2:03 p.m. UTC
GCC 12 raises the following warning:

meson --werror --buildtype=debugoptimized
	--cross-file config/x86/cross-mingw -Dexamples=helloworld build
ninja -C build

In function 'i40e_hash_get_pattern_type',
    inlined from 'i40e_hash_get_pattern_pctypes' at
../drivers/net/i40e/i40e_hash.c:520:8,
    inlined from 'i40e_hash_parse_pattern_act' at
../drivers/net/i40e/i40e_hash.c:1147:9,
    inlined from 'i40e_hash_parse' at
../drivers/net/i40e/i40e_hash.c:1181:9:
../drivers/net/i40e/i40e_hash.c:389:47:
	error: array subscript 53 is above array
	bounds of 'const uint64_t[53]'
	{aka 'const long long unsigned int[53]'} [-Werror=array-bounds]
  389 |                 item_hdr = pattern_item_header[last_item_type];
      |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
../drivers/net/i40e/i40e_hash.c: In function 'i40e_hash_parse':
../drivers/net/i40e/i40e_hash.c:182:23: note: while referencing
'pattern_item_header'
  182 | static const uint64_t pattern_item_header[] = {
      |                       ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Fixes: ef4c16fd9148 (net/i40e: refactor RSS flow)
Cc: stable@dpdk.org

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
v2:
- Removed "examples/ipsec-secgw" patch from this series and posted it as
seperate patch.

 drivers/net/i40e/i40e_hash.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Morten Brørup Aug. 25, 2022, 7:21 a.m. UTC | #1
> From: Amit Prakash Shukla [mailto:amitprakashs@marvell.com]
> Sent: Wednesday, 24 August 2022 16.04
> 
> GCC 12 raises the following warning:
> 
> meson --werror --buildtype=debugoptimized
> 	--cross-file config/x86/cross-mingw -Dexamples=helloworld build
> ninja -C build
> 
> In function 'i40e_hash_get_pattern_type',
>     inlined from 'i40e_hash_get_pattern_pctypes' at
> ../drivers/net/i40e/i40e_hash.c:520:8,
>     inlined from 'i40e_hash_parse_pattern_act' at
> ../drivers/net/i40e/i40e_hash.c:1147:9,
>     inlined from 'i40e_hash_parse' at
> ../drivers/net/i40e/i40e_hash.c:1181:9:
> ../drivers/net/i40e/i40e_hash.c:389:47:
> 	error: array subscript 53 is above array
> 	bounds of 'const uint64_t[53]'
> 	{aka 'const long long unsigned int[53]'} [-Werror=array-bounds]
>   389 |                 item_hdr = pattern_item_header[last_item_type];
>       |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
> ../drivers/net/i40e/i40e_hash.c: In function 'i40e_hash_parse':
> ../drivers/net/i40e/i40e_hash.c:182:23: note: while referencing
> 'pattern_item_header'
>   182 | static const uint64_t pattern_item_header[] = {
>       |                       ^~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Fixes: ef4c16fd9148 (net/i40e: refactor RSS flow)
> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> ---
> v2:
> - Removed "examples/ipsec-secgw" patch from this series and posted it
> as
> seperate patch.
> 
>  drivers/net/i40e/i40e_hash.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/i40e/i40e_hash.c
> b/drivers/net/i40e/i40e_hash.c
> index 8962e9d97a..a1ff85fceb 100644
> --- a/drivers/net/i40e/i40e_hash.c
> +++ b/drivers/net/i40e/i40e_hash.c
> @@ -384,8 +384,10 @@ i40e_hash_get_pattern_type(const struct
> rte_flow_item pattern[],
>  		}
> 
>  		prev_item_type = last_item_type;
> -		assert(last_item_type < (enum rte_flow_item_type)
> -				RTE_DIM(pattern_item_header));
> +		if (last_item_type >= (enum rte_flow_item_type)
> +				RTE_DIM(pattern_item_header))

Does this compile with the correct static branch prediction? If not, please add unlikely() to error checks like this.

> +			goto not_sup;
> +
>  		item_hdr = pattern_item_header[last_item_type];
>  		assert(item_hdr);
> 
> --
> 2.25.1
>
Amit Prakash Shukla Aug. 26, 2022, 9:45 a.m. UTC | #2
Thanks Morten for the review comment. 

As the change is not in datapath, branch prediction optimization was not done.

> -----Original Message-----
> From: Amit Prakash Shukla <amitprakashs@marvell.com>
> Sent: Wednesday, August 24, 2022 7:34 PM
> To: Yuying Zhang <Yuying.Zhang@intel.com>; Beilei Xing
> <beilei.xing@intel.com>
> Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> stable@dpdk.org; Amit Prakash Shukla <amitprakashs@marvell.com>
> Subject: [PATCH 1/2] net/i40e: compilation fix for GCC-12
> 
> GCC 12 raises the following warning:
> 
> meson --werror --buildtype=debugoptimized
> 	--cross-file config/x86/cross-mingw -Dexamples=helloworld build
> ninja -C build
> 
> In function 'i40e_hash_get_pattern_type',
>     inlined from 'i40e_hash_get_pattern_pctypes' at
> ../drivers/net/i40e/i40e_hash.c:520:8,
>     inlined from 'i40e_hash_parse_pattern_act' at
> ../drivers/net/i40e/i40e_hash.c:1147:9,
>     inlined from 'i40e_hash_parse' at
> ../drivers/net/i40e/i40e_hash.c:1181:9:
> ../drivers/net/i40e/i40e_hash.c:389:47:
> 	error: array subscript 53 is above array
> 	bounds of 'const uint64_t[53]'
> 	{aka 'const long long unsigned int[53]'} [-Werror=array-bounds]
>   389 |                 item_hdr = pattern_item_header[last_item_type];
>       |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
> ../drivers/net/i40e/i40e_hash.c: In function 'i40e_hash_parse':
> ../drivers/net/i40e/i40e_hash.c:182:23: note: while referencing
> 'pattern_item_header'
>   182 | static const uint64_t pattern_item_header[] = {
>       |                       ^~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Fixes: ef4c16fd9148 (net/i40e: refactor RSS flow)
> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> ---
> v2:
> - Removed "examples/ipsec-secgw" patch from this series and posted it as
> seperate patch.
> 
>  drivers/net/i40e/i40e_hash.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/i40e/i40e_hash.c b/drivers/net/i40e/i40e_hash.c
> index 8962e9d97a..a1ff85fceb 100644
> --- a/drivers/net/i40e/i40e_hash.c
> +++ b/drivers/net/i40e/i40e_hash.c
> @@ -384,8 +384,10 @@ i40e_hash_get_pattern_type(const struct
> rte_flow_item pattern[],
>  		}
> 
>  		prev_item_type = last_item_type;
> -		assert(last_item_type < (enum rte_flow_item_type)
> -				RTE_DIM(pattern_item_header));
> +		if (last_item_type >= (enum rte_flow_item_type)
> +				RTE_DIM(pattern_item_header))
> +			goto not_sup;
> +
>  		item_hdr = pattern_item_header[last_item_type];
>  		assert(item_hdr);
> 
> --
> 2.25.1
Morten Brørup Aug. 26, 2022, 10:32 a.m. UTC | #3
> From: Amit Prakash Shukla [mailto:amitprakashs@marvell.com]
> Sent: Friday, 26 August 2022 11.45
> 
> Thanks Morten for the review comment.
> 
> As the change is not in datapath, branch prediction optimization was
> not done.

OK. Then I agree that it is not required.

> 
> > -----Original Message-----
> > From: Amit Prakash Shukla <amitprakashs@marvell.com>
> > Sent: Wednesday, August 24, 2022 7:34 PM
> >
> > GCC 12 raises the following warning:
> >
> > meson --werror --buildtype=debugoptimized
> > 	--cross-file config/x86/cross-mingw -Dexamples=helloworld build
> > ninja -C build
> >
> > In function 'i40e_hash_get_pattern_type',
> >     inlined from 'i40e_hash_get_pattern_pctypes' at
> > ../drivers/net/i40e/i40e_hash.c:520:8,
> >     inlined from 'i40e_hash_parse_pattern_act' at
> > ../drivers/net/i40e/i40e_hash.c:1147:9,
> >     inlined from 'i40e_hash_parse' at
> > ../drivers/net/i40e/i40e_hash.c:1181:9:
> > ../drivers/net/i40e/i40e_hash.c:389:47:
> > 	error: array subscript 53 is above array
> > 	bounds of 'const uint64_t[53]'
> > 	{aka 'const long long unsigned int[53]'} [-Werror=array-bounds]
> >   389 |                 item_hdr =
> pattern_item_header[last_item_type];
> >       |
> ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
> > ../drivers/net/i40e/i40e_hash.c: In function 'i40e_hash_parse':
> > ../drivers/net/i40e/i40e_hash.c:182:23: note: while referencing
> > 'pattern_item_header'
> >   182 | static const uint64_t pattern_item_header[] = {
> >       |                       ^~~~~~~~~~~~~~~~~~~
> > cc1: all warnings being treated as errors
> >
> > Fixes: ef4c16fd9148 (net/i40e: refactor RSS flow)
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> > ---
> > v2:
> > - Removed "examples/ipsec-secgw" patch from this series and posted it
> as
> > seperate patch.
> >
> >  drivers/net/i40e/i40e_hash.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/i40e/i40e_hash.c
> b/drivers/net/i40e/i40e_hash.c
> > index 8962e9d97a..a1ff85fceb 100644
> > --- a/drivers/net/i40e/i40e_hash.c
> > +++ b/drivers/net/i40e/i40e_hash.c
> > @@ -384,8 +384,10 @@ i40e_hash_get_pattern_type(const struct
> > rte_flow_item pattern[],
> >  		}
> >
> >  		prev_item_type = last_item_type;
> > -		assert(last_item_type < (enum rte_flow_item_type)
> > -				RTE_DIM(pattern_item_header));
> > +		if (last_item_type >= (enum rte_flow_item_type)
> > +				RTE_DIM(pattern_item_header))
> > +			goto not_sup;
> > +
> >  		item_hdr = pattern_item_header[last_item_type];
> >  		assert(item_hdr);
> >
> > --
> > 2.25.1
>
Thomas Monjalon Oct. 6, 2022, 9:51 a.m. UTC | #4
24/08/2022 16:03, Amit Prakash Shukla:
> GCC 12 raises the following warning:
> 
> meson --werror --buildtype=debugoptimized
> 	--cross-file config/x86/cross-mingw -Dexamples=helloworld build
> ninja -C build
> 
> In function 'i40e_hash_get_pattern_type',
>     inlined from 'i40e_hash_get_pattern_pctypes' at
> ../drivers/net/i40e/i40e_hash.c:520:8,
>     inlined from 'i40e_hash_parse_pattern_act' at
> ../drivers/net/i40e/i40e_hash.c:1147:9,
>     inlined from 'i40e_hash_parse' at
> ../drivers/net/i40e/i40e_hash.c:1181:9:
> ../drivers/net/i40e/i40e_hash.c:389:47:
> 	error: array subscript 53 is above array
> 	bounds of 'const uint64_t[53]'
> 	{aka 'const long long unsigned int[53]'} [-Werror=array-bounds]
>   389 |                 item_hdr = pattern_item_header[last_item_type];
>       |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
> ../drivers/net/i40e/i40e_hash.c: In function 'i40e_hash_parse':
> ../drivers/net/i40e/i40e_hash.c:182:23: note: while referencing
> 'pattern_item_header'
>   182 | static const uint64_t pattern_item_header[] = {
>       |                       ^~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Fixes: ef4c16fd9148 (net/i40e: refactor RSS flow)
> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>

Sorry I did not notice this patch and I recently submitted one
which I will abandon.
It seems there was no reply from i40e maintainers after 6 weeks,
but I will apply anyway.

I will use my commit message:

    net/i40e: fix build with MinGW GCC 12
    
    When compiling with MinGW GCC 12,
    the rte_flow_item array is seen as read out of bound:
    
    net/i40e/i40e_hash.c:389:47: error:
    	array subscript 50 is above array bounds of ‘const uint64_t[50]’
    	{aka ‘const long long unsigned int[50]’} [-Werror=array-bounds]
    	389 | item_hdr = pattern_item_header[last_item_type];
    	    |            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
    
    It seems the assert check done above this line has no impact.
    A real check is added to make the compiler happy.
    
    Fixes: ef4c16fd9148 ("net/i40e: refactor RSS flow")
    Cc: stable@dpdk.org
diff mbox series

Patch

diff --git a/drivers/net/i40e/i40e_hash.c b/drivers/net/i40e/i40e_hash.c
index 8962e9d97a..a1ff85fceb 100644
--- a/drivers/net/i40e/i40e_hash.c
+++ b/drivers/net/i40e/i40e_hash.c
@@ -384,8 +384,10 @@  i40e_hash_get_pattern_type(const struct rte_flow_item pattern[],
 		}
 
 		prev_item_type = last_item_type;
-		assert(last_item_type < (enum rte_flow_item_type)
-				RTE_DIM(pattern_item_header));
+		if (last_item_type >= (enum rte_flow_item_type)
+				RTE_DIM(pattern_item_header))
+			goto not_sup;
+
 		item_hdr = pattern_item_header[last_item_type];
 		assert(item_hdr);