[4/4] net/tap: fix build with gcc11

Message ID 20210510150319.1496105-4-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series [1/4] net/bnx2x: fix build with gcc11 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS
ci/github-robot success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Ferruh Yigit May 10, 2021, 3:03 p.m. UTC
  Reproduced with '--buildtype=debugoptimized' config,
compiler version: gcc (GCC) 12.0.0 20210509 (experimental)

There are multiple build errors, like:
In file included from ../drivers/net/tap/tap_flow.c:13:
In function ‘rte_jhash_2hashes’,
    inlined from ‘rte_jhash’ at ../lib/hash/rte_jhash.h:284:2,
    inlined from ‘tap_flow_set_handle’ at
	../drivers/net/tap/tap_flow.c:1306:12,
    inlined from ‘rss_enable’ at ../drivers/net/tap/tap_flow.c:1909:3,
    inlined from ‘priv_flow_process’ at
	../drivers/net/tap/tap_flow.c:1228:11:
../lib/hash/rte_jhash.h:238:9:
	warning: ‘flow’ may be used uninitialized [-Wmaybe-uninitialized]
  238 |         __rte_jhash_2hashes(key, length, pc, pb, 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/net/tap/tap_flow.c: In function ‘priv_flow_process’:
../lib/hash/rte_jhash.h:81:1: note: by argument 1 of type ‘const void *’
	to ‘__rte_jhash_2hashes.constprop’ declared here
 81 | __rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc,
    | ^~~~~~~~~~~~~~~~~~~
../drivers/net/tap/tap_flow.c:1028:1: note: ‘flow’ declared here
 1028 | priv_flow_process(struct pmd_internals *pmd,
      | ^~~~~~~~~~~~~~~~~

Fix strict aliasing rule by using union.

Fixes: de96fe68ae95 ("net/tap: add basic flow API patterns and actions")
Cc: stable@dpdk.org

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: pascal.mazon@6wind.com
---
 drivers/net/tap/tap_flow.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Kevin Traynor May 11, 2021, 12:28 p.m. UTC | #1
On 10/05/2021 16:03, Ferruh Yigit wrote:
> Reproduced with '--buildtype=debugoptimized' config,
> compiler version: gcc (GCC) 12.0.0 20210509 (experimental)
> 
> There are multiple build errors, like:
> In file included from ../drivers/net/tap/tap_flow.c:13:
> In function ‘rte_jhash_2hashes’,
>     inlined from ‘rte_jhash’ at ../lib/hash/rte_jhash.h:284:2,
>     inlined from ‘tap_flow_set_handle’ at
> 	../drivers/net/tap/tap_flow.c:1306:12,
>     inlined from ‘rss_enable’ at ../drivers/net/tap/tap_flow.c:1909:3,
>     inlined from ‘priv_flow_process’ at
> 	../drivers/net/tap/tap_flow.c:1228:11:
> ../lib/hash/rte_jhash.h:238:9:
> 	warning: ‘flow’ may be used uninitialized [-Wmaybe-uninitialized]
>   238 |         __rte_jhash_2hashes(key, length, pc, pb, 1);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../drivers/net/tap/tap_flow.c: In function ‘priv_flow_process’:
> ../lib/hash/rte_jhash.h:81:1: note: by argument 1 of type ‘const void *’
> 	to ‘__rte_jhash_2hashes.constprop’ declared here
>  81 | __rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc,
>     | ^~~~~~~~~~~~~~~~~~~
> ../drivers/net/tap/tap_flow.c:1028:1: note: ‘flow’ declared here
>  1028 | priv_flow_process(struct pmd_internals *pmd,
>       | ^~~~~~~~~~~~~~~~~
> 
> Fix strict aliasing rule by using union.
> 

Bugzilla ID: 690

> Fixes: de96fe68ae95 ("net/tap: add basic flow API patterns and actions")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Acked-by: Kevin Traynor <ktraynor@redhat.com>

> ---
> Cc: pascal.mazon@6wind.com
> ---
>  drivers/net/tap/tap_flow.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
> index 1ee6fb30ab2d..c4f60ce98e5e 100644
> --- a/drivers/net/tap/tap_flow.c
> +++ b/drivers/net/tap/tap_flow.c
> @@ -1300,10 +1300,16 @@ tap_flow_validate(struct rte_eth_dev *dev,
>  static void
>  tap_flow_set_handle(struct rte_flow *flow)
>  {
> +	union {
> +		struct rte_flow *flow;
> +		const void *key;
> +	} tmp;
>  	uint32_t handle = 0;
>  
> +	tmp.flow = flow;
> +
>  	if (sizeof(flow) > 4)
> -		handle = rte_jhash(&flow, sizeof(flow), 1);
> +		handle = rte_jhash(tmp.key, sizeof(flow), 1);
>  	else
>  		handle = (uintptr_t)flow;
>  	/* must be at least 1 to avoid letting the kernel choose one for us */
>
  

Patch

diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
index 1ee6fb30ab2d..c4f60ce98e5e 100644
--- a/drivers/net/tap/tap_flow.c
+++ b/drivers/net/tap/tap_flow.c
@@ -1300,10 +1300,16 @@  tap_flow_validate(struct rte_eth_dev *dev,
 static void
 tap_flow_set_handle(struct rte_flow *flow)
 {
+	union {
+		struct rte_flow *flow;
+		const void *key;
+	} tmp;
 	uint32_t handle = 0;
 
+	tmp.flow = flow;
+
 	if (sizeof(flow) > 4)
-		handle = rte_jhash(&flow, sizeof(flow), 1);
+		handle = rte_jhash(tmp.key, sizeof(flow), 1);
 	else
 		handle = (uintptr_t)flow;
 	/* must be at least 1 to avoid letting the kernel choose one for us */