diff mbox series

[2/3] mempool/octeontx2: fix build for gcc O1 optimization

Message ID 20200507120259.2197813-2-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Headers show
Series [1/3] ring: fix build for gcc O1 optimization | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit May 7, 2020, 12:02 p.m. UTC
Can be reproduced with "make EXTRA_CFLAGS='-O1'" command using
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)

Build error:
In file included from .../drivers/mempool/octeontx2/otx2_mempool.h:13,
                from .../drivers/mempool/octeontx2/otx2_mempool_ops.c:8:
.../drivers/mempool/octeontx2/otx2_mempool_ops.c:
	In function ‘otx2_npa_alloc’:
.../drivers/common/octeontx2/otx2_common.h:94:2:
    error: ‘aura_handle’ may be used uninitialized in this function
           [-Werror=maybe-uninitialized]
   94 |  rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,  \
      |  ^~~~~~~
.../drivers/mempool/octeontx2/otx2_mempool_ops.c:643:11:
    note: ‘aura_handle’ was declared here
  643 |  uint64_t aura_handle;
      |           ^~~~~~~~~~~

This looks like false positive, assigning an initial value to
'aura_handle' to fix the build error.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
This is assuming assigning initial value won't have a performance affect
if it does, we need to find another fix.
And overall not sure why this false positive warning is generated.
---
 drivers/mempool/octeontx2/otx2_mempool_ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Konstantin Ananyev May 7, 2020, 2:05 p.m. UTC | #1
Hi Ferruh, Jerin

> Can be reproduced with "make EXTRA_CFLAGS='-O1'" command using
> gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
> 
> Build error:
> In file included from .../drivers/mempool/octeontx2/otx2_mempool.h:13,
>                 from .../drivers/mempool/octeontx2/otx2_mempool_ops.c:8:
> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:
> 	In function ‘otx2_npa_alloc’:
> .../drivers/common/octeontx2/otx2_common.h:94:2:
>     error: ‘aura_handle’ may be used uninitialized in this function
>            [-Werror=maybe-uninitialized]
>    94 |  rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,  \
>       |  ^~~~~~~
> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:643:11:
>     note: ‘aura_handle’ was declared here
>   643 |  uint64_t aura_handle;
>       |           ^~~~~~~~~~~
> 
> This looks like false positive, assigning an initial value to
> 'aura_handle' to fix the build error.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> This is assuming assigning initial value won't have a performance affect
> if it does, we need to find another fix.
> And overall not sure why this false positive warning is generated.
> ---
>  drivers/mempool/octeontx2/otx2_mempool_ops.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mempool/octeontx2/otx2_mempool_ops.c b/drivers/mempool/octeontx2/otx2_mempool_ops.c
> index 162b7f01da..078ffac3e2 100644
> --- a/drivers/mempool/octeontx2/otx2_mempool_ops.c
> +++ b/drivers/mempool/octeontx2/otx2_mempool_ops.c
> @@ -640,7 +640,7 @@ otx2_npa_alloc(struct rte_mempool *mp)
>  	struct otx2_npa_lf *lf;
>  	struct npa_aura_s aura;
>  	struct npa_pool_s pool;
> -	uint64_t aura_handle;
> +	uint64_t aura_handle = 0;
>  	size_t padding;
>  	int rc;
> 
> --


Confirm that it helps, though I am seeing one more issue with EXTRA_CFLAGS='-O1' (gcc 7.3.0).
This time with drivers/event/octeontx2/otx2_evdev_stats.h:

In file included from /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/ot
x2_evdev.c:15:0:
/local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h: In function ‘otx2_sso_xstats_get’:
/local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h:124:9: error: ‘xstats’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   xstat = &xstats[ids[i] - start_offset];
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev.c: At top level:
cc1: error: unrecognized command line option ‘-Wno-address-of-packed-member’ [-Werror]
cc1: all warnings being treated as errors

As I can see xtstats is not set for RTE_EVENT_DEV_XSTATS_DEVICE case.
Just to make gcc quiet, I added:
--- a/drivers/event/octeontx2/otx2_evdev_stats.h
+++ b/drivers/event/octeontx2/otx2_evdev_stats.h
@@ -67,6 +67,7 @@ otx2_sso_xstats_get(const struct rte_eventdev *event_dev,

        switch (mode) {
        case RTE_EVENT_DEV_XSTATS_DEVICE:
+               xstats = NULL;
                break;
        case RTE_EVENT_DEV_XSTATS_PORT:
                if (queue_port_id >= (signed int)dev->nb_event_ports)

Konstantin
Ferruh Yigit May 8, 2020, 4:20 p.m. UTC | #2
On 5/7/2020 3:05 PM, Ananyev, Konstantin wrote:
> Hi Ferruh, Jerin
> 
>> Can be reproduced with "make EXTRA_CFLAGS='-O1'" command using
>> gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
>>
>> Build error:
>> In file included from .../drivers/mempool/octeontx2/otx2_mempool.h:13,
>>                 from .../drivers/mempool/octeontx2/otx2_mempool_ops.c:8:
>> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:
>> In function ‘otx2_npa_alloc’:
>> .../drivers/common/octeontx2/otx2_common.h:94:2:
>>     error: ‘aura_handle’ may be used uninitialized in this function
>>            [-Werror=maybe-uninitialized]
>>    94 |  rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,  \
>>       |  ^~~~~~~
>> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:643:11:
>>     note: ‘aura_handle’ was declared here
>>   643 |  uint64_t aura_handle;
>>       |           ^~~~~~~~~~~
>>
>> This looks like false positive, assigning an initial value to
>> 'aura_handle' to fix the build error.
>>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> ---
>> This is assuming assigning initial value won't have a performance affect
>> if it does, we need to find another fix.
>> And overall not sure why this false positive warning is generated.
>> ---
>>  drivers/mempool/octeontx2/otx2_mempool_ops.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/mempool/octeontx2/otx2_mempool_ops.c b/drivers/mempool/octeontx2/otx2_mempool_ops.c
>> index 162b7f01da..078ffac3e2 100644
>> --- a/drivers/mempool/octeontx2/otx2_mempool_ops.c
>> +++ b/drivers/mempool/octeontx2/otx2_mempool_ops.c
>> @@ -640,7 +640,7 @@ otx2_npa_alloc(struct rte_mempool *mp)
>>  struct otx2_npa_lf *lf;
>>  struct npa_aura_s aura;
>>  struct npa_pool_s pool;
>> -uint64_t aura_handle;
>> +uint64_t aura_handle = 0;
>>  size_t padding;
>>  int rc;
>>
>> --
> 
> 
> Confirm that it helps, though I am seeing one more issue with EXTRA_CFLAGS='-O1' (gcc 7.3.0).
> This time with drivers/event/octeontx2/otx2_evdev_stats.h:
> 
> In file included from /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/ot
> x2_evdev.c:15:0:
> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h: In function ‘otx2_sso_xstats_get’:
> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h:124:9: error: ‘xstats’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>    xstat = &xstats[ids[i] - start_offset];
>    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev.c: At top level:
> cc1: error: unrecognized command line option ‘-Wno-address-of-packed-member’ [-Werror]
> cc1: all warnings being treated as errors
> 
> As I can see xtstats is not set for RTE_EVENT_DEV_XSTATS_DEVICE case.
> Just to make gcc quiet, I added:
> --- a/drivers/event/octeontx2/otx2_evdev_stats.h
> +++ b/drivers/event/octeontx2/otx2_evdev_stats.h
> @@ -67,6 +67,7 @@ otx2_sso_xstats_get(const struct rte_eventdev *event_dev,
> 
>         switch (mode) {
>         case RTE_EVENT_DEV_XSTATS_DEVICE:
> +               xstats = NULL;
>                 break;
>         case RTE_EVENT_DEV_XSTATS_PORT:
>                 if (queue_port_id >= (signed int)dev->nb_event_ports)
> 
> Konstantin
> 
> 
> 
Thanks Konstantin,

I will make a v2 including above as you suggested.
Ferruh Yigit May 8, 2020, 4:39 p.m. UTC | #3
On 5/8/2020 5:20 PM, Ferruh Yigit wrote:
> On 5/7/2020 3:05 PM, Ananyev, Konstantin wrote:
>> Hi Ferruh, Jerin
>>
>>> Can be reproduced with "make EXTRA_CFLAGS='-O1'" command using
>>> gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
>>>
>>> Build error:
>>> In file included from .../drivers/mempool/octeontx2/otx2_mempool.h:13,
>>>                 from .../drivers/mempool/octeontx2/otx2_mempool_ops.c:8:
>>> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:
>>> In function ‘otx2_npa_alloc’:
>>> .../drivers/common/octeontx2/otx2_common.h:94:2:
>>>     error: ‘aura_handle’ may be used uninitialized in this function
>>>            [-Werror=maybe-uninitialized]
>>>    94 |  rte_log(RTE_LOG_DEBUG, otx2_logtype_ ## subsystem,  \
>>>       |  ^~~~~~~
>>> .../drivers/mempool/octeontx2/otx2_mempool_ops.c:643:11:
>>>     note: ‘aura_handle’ was declared here
>>>   643 |  uint64_t aura_handle;
>>>       |           ^~~~~~~~~~~
>>>
>>> This looks like false positive, assigning an initial value to
>>> 'aura_handle' to fix the build error.
>>>
>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>> ---
>>> This is assuming assigning initial value won't have a performance affect
>>> if it does, we need to find another fix.
>>> And overall not sure why this false positive warning is generated.
>>> ---
>>>  drivers/mempool/octeontx2/otx2_mempool_ops.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/mempool/octeontx2/otx2_mempool_ops.c b/drivers/mempool/octeontx2/otx2_mempool_ops.c
>>> index 162b7f01da..078ffac3e2 100644
>>> --- a/drivers/mempool/octeontx2/otx2_mempool_ops.c
>>> +++ b/drivers/mempool/octeontx2/otx2_mempool_ops.c
>>> @@ -640,7 +640,7 @@ otx2_npa_alloc(struct rte_mempool *mp)
>>>  struct otx2_npa_lf *lf;
>>>  struct npa_aura_s aura;
>>>  struct npa_pool_s pool;
>>> -uint64_t aura_handle;
>>> +uint64_t aura_handle = 0;
>>>  size_t padding;
>>>  int rc;
>>>
>>> --
>>
>>
>> Confirm that it helps, though I am seeing one more issue with EXTRA_CFLAGS='-O1' (gcc 7.3.0).
>> This time with drivers/event/octeontx2/otx2_evdev_stats.h:
>>
>> In file included from /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/ot
>> x2_evdev.c:15:0:
>> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h: In function ‘otx2_sso_xstats_get’:
>> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev_stats.h:124:9: error: ‘xstats’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>>    xstat = &xstats[ids[i] - start_offset];
>>    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> /local/kananye1/dpdk.2005.rngf1/drivers/event/octeontx2/otx2_evdev.c: At top level:
>> cc1: error: unrecognized command line option ‘-Wno-address-of-packed-member’ [-Werror]
>> cc1: all warnings being treated as errors
>>
>> As I can see xtstats is not set for RTE_EVENT_DEV_XSTATS_DEVICE case.
>> Just to make gcc quiet, I added:
>> --- a/drivers/event/octeontx2/otx2_evdev_stats.h
>> +++ b/drivers/event/octeontx2/otx2_evdev_stats.h
>> @@ -67,6 +67,7 @@ otx2_sso_xstats_get(const struct rte_eventdev *event_dev,
>>
>>         switch (mode) {
>>         case RTE_EVENT_DEV_XSTATS_DEVICE:
>> +               xstats = NULL;
>>                 break;
>>         case RTE_EVENT_DEV_XSTATS_PORT:
>>                 if (queue_port_id >= (signed int)dev->nb_event_ports)
>>
>> Konstantin
>>
>>
>>
> Thanks Konstantin,
> 
> I will make a v2 including above as you suggested.
> 

Thinking twice, if compiler thinks 'xstats' may be used uninitialized, when is
assigned to NULL it should complain about null pointer de-reference.

Btw, this is also false positive, 'xstats_mode_count' prevents taking the loop
and accessing to 'xstats'. Not sure what is the problem with "-O1" option ...

But for the 'RTE_EVENT_DEV_XSTATS_DEVICE' case, the loop is skipped and
functions returns '0', I will update as following to get more close to the
intention, also this is less work for function.
Can you please test below when I send the patch, I can't reproduce this?


@@ -67,7 +67,7 @@ otx2_sso_xstats_get(const struct rte_eventdev *event_dev,

        switch (mode) {
        case RTE_EVENT_DEV_XSTATS_DEVICE:
-               break;
+               return 0;
        case RTE_EVENT_DEV_XSTATS_PORT:
                if (queue_port_id >= (signed int)dev->nb_event_ports)
                        goto invalid_value;
diff mbox series

Patch

diff --git a/drivers/mempool/octeontx2/otx2_mempool_ops.c b/drivers/mempool/octeontx2/otx2_mempool_ops.c
index 162b7f01da..078ffac3e2 100644
--- a/drivers/mempool/octeontx2/otx2_mempool_ops.c
+++ b/drivers/mempool/octeontx2/otx2_mempool_ops.c
@@ -640,7 +640,7 @@  otx2_npa_alloc(struct rte_mempool *mp)
 	struct otx2_npa_lf *lf;
 	struct npa_aura_s aura;
 	struct npa_pool_s pool;
-	uint64_t aura_handle;
+	uint64_t aura_handle = 0;
 	size_t padding;
 	int rc;