[3/3] ethdev: fix build warning on 64-bit value

Message ID 20200427132341.27681-4-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series 20.05-rc1 fixes for OVS |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot warning Travis build: failed
ci/Intel-compilation success Compilation OK

Commit Message

David Marchand April 27, 2020, 1:23 p.m. UTC
  Building OVS with dpdk, sparse complains about 64-bit constant being
passed as a normal integer that can't fit it:
error: constant 0xffffffffffffffff is so big it is unsigned long

Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/librte_ethdev/rte_flow.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Rybchenko April 27, 2020, 1:33 p.m. UTC | #1
On 4/27/20 4:23 PM, David Marchand wrote:
> Building OVS with dpdk, sparse complains about 64-bit constant being
> passed as a normal integer that can't fit it:
> error: constant 0xffffffffffffffff is so big it is unsigned long
> 
> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/librte_ethdev/rte_flow.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index 132b44edc6..1fb94f35e8 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
>  #ifndef __cplusplus
>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
>  	.s_field = 0x01,
> -	.seid = RTE_BE64(0xffffffffffffffff),
> +	.seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
>  };
>  #endif
>  
> 

Reviewed-by: Andrew Rybchenko <arybchenko@solarflare.com>
  
Bruce Richardson April 27, 2020, 1:34 p.m. UTC | #2
On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> Building OVS with dpdk, sparse complains about 64-bit constant being
> passed as a normal integer that can't fit it:
> error: constant 0xffffffffffffffff is so big it is unsigned long
> 
> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/librte_ethdev/rte_flow.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index 132b44edc6..1fb94f35e8 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
>  #ifndef __cplusplus
>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
>  	.s_field = 0x01,
> -	.seid = RTE_BE64(0xffffffffffffffff),
> +	.seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),

Rather than cast, why not put "ULL" at the end. If we are going to cast,
why not just put "-1" in to save some digits.

/Bruce
  
David Marchand April 27, 2020, 1:36 p.m. UTC | #3
On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > Building OVS with dpdk, sparse complains about 64-bit constant being
> > passed as a normal integer that can't fit it:
> > error: constant 0xffffffffffffffff is so big it is unsigned long
> >
> > Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> >  lib/librte_ethdev/rte_flow.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> > index 132b44edc6..1fb94f35e8 100644
> > --- a/lib/librte_ethdev/rte_flow.h
> > +++ b/lib/librte_ethdev/rte_flow.h
> > @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> >  #ifndef __cplusplus
> >  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> >       .s_field = 0x01,
> > -     .seid = RTE_BE64(0xffffffffffffffff),
> > +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
>
> Rather than cast, why not put "ULL" at the end. If we are going to cast,
> why not just put "-1" in to save some digits.

I preferred this form in the hope future developers who want
0x0fffffffffffffff will copy/paste this.
  
Andrew Rybchenko April 27, 2020, 1:39 p.m. UTC | #4
On 4/27/20 4:34 PM, Bruce Richardson wrote:
> On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
>> Building OVS with dpdk, sparse complains about 64-bit constant being
>> passed as a normal integer that can't fit it:
>> error: constant 0xffffffffffffffff is so big it is unsigned long
>>
>> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
>>
>> Signed-off-by: David Marchand <david.marchand@redhat.com>
>> ---
>>  lib/librte_ethdev/rte_flow.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
>> index 132b44edc6..1fb94f35e8 100644
>> --- a/lib/librte_ethdev/rte_flow.h
>> +++ b/lib/librte_ethdev/rte_flow.h
>> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
>>  #ifndef __cplusplus
>>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
>>  	.s_field = 0x01,
>> -	.seid = RTE_BE64(0xffffffffffffffff),
>> +	.seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> Rather than cast, why not put "ULL" at the end.

It is not a cast as far as I can see, it is exactly ULL (or UL):
/usr/include/stdint.h
# if __WORDSIZE == 64
#  define UINT64_C(c)   c ## UL
# else
#  define UINT64_C(c)   c ## ULL
# endif

> If we are going to cast, why not just put "-1" in to save some digits.
>
> /Bruce
  
David Marchand April 27, 2020, 1:40 p.m. UTC | #5
On Mon, Apr 27, 2020 at 3:39 PM Andrew Rybchenko
<arybchenko@solarflare.com> wrote:
>
> On 4/27/20 4:34 PM, Bruce Richardson wrote:
> > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> >> Building OVS with dpdk, sparse complains about 64-bit constant being
> >> passed as a normal integer that can't fit it:
> >> error: constant 0xffffffffffffffff is so big it is unsigned long
> >>
> >> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> >>
> >> Signed-off-by: David Marchand <david.marchand@redhat.com>
> >> ---
> >>  lib/librte_ethdev/rte_flow.h | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> >> index 132b44edc6..1fb94f35e8 100644
> >> --- a/lib/librte_ethdev/rte_flow.h
> >> +++ b/lib/librte_ethdev/rte_flow.h
> >> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> >>  #ifndef __cplusplus
> >>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> >>      .s_field = 0x01,
> >> -    .seid = RTE_BE64(0xffffffffffffffff),
> >> +    .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> > Rather than cast, why not put "ULL" at the end.
>
> It is not a cast as far as I can see, it is exactly ULL (or UL):
> /usr/include/stdint.h
> # if __WORDSIZE == 64
> #  define UINT64_C(c)   c ## UL
> # else
> #  define UINT64_C(c)   c ## ULL
> # endif

Yes.
  
Bruce Richardson April 27, 2020, 1:43 p.m. UTC | #6
On Mon, Apr 27, 2020 at 03:40:30PM +0200, David Marchand wrote:
> On Mon, Apr 27, 2020 at 3:39 PM Andrew Rybchenko
> <arybchenko@solarflare.com> wrote:
> >
> > On 4/27/20 4:34 PM, Bruce Richardson wrote:
> > > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > >> Building OVS with dpdk, sparse complains about 64-bit constant being
> > >> passed as a normal integer that can't fit it:
> > >> error: constant 0xffffffffffffffff is so big it is unsigned long
> > >>
> > >> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> > >>
> > >> Signed-off-by: David Marchand <david.marchand@redhat.com>
> > >> ---
> > >>  lib/librte_ethdev/rte_flow.h | 2 +-
> > >>  1 file changed, 1 insertion(+), 1 deletion(-)
> > >>
> > >> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> > >> index 132b44edc6..1fb94f35e8 100644
> > >> --- a/lib/librte_ethdev/rte_flow.h
> > >> +++ b/lib/librte_ethdev/rte_flow.h
> > >> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> > >>  #ifndef __cplusplus
> > >>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> > >>      .s_field = 0x01,
> > >> -    .seid = RTE_BE64(0xffffffffffffffff),
> > >> +    .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> > > Rather than cast, why not put "ULL" at the end.
> >
> > It is not a cast as far as I can see, it is exactly ULL (or UL):
> > /usr/include/stdint.h
> > # if __WORDSIZE == 64
> > #  define UINT64_C(c)   c ## UL
> > # else
> > #  define UINT64_C(c)   c ## ULL
> > # endif
> 
> Yes.
> 
Thanks. I'd prefer just sticking on the "ULL" myself as it's shorter, but
this is ok.
  
Ananyev, Konstantin April 27, 2020, 1:46 p.m. UTC | #7
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> Sent: Monday, April 27, 2020 2:37 PM
> To: Richardson, Bruce <bruce.richardson@intel.com>
> Cc: dev <dev@dpdk.org>; Ori Kam <orika@mellanox.com>; Thomas Monjalon <thomas@monjalon.net>; Yigit, Ferruh
> <ferruh.yigit@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Zhang, Xiao <xiao.zhang@intel.com>
> Subject: Re: [dpdk-dev] [PATCH 3/3] ethdev: fix build warning on 64-bit value
> 
> On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> >
> > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > > Building OVS with dpdk, sparse complains about 64-bit constant being
> > > passed as a normal integer that can't fit it:
> > > error: constant 0xffffffffffffffff is so big it is unsigned long
> > >
> > > Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> > >
> > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > ---
> > >  lib/librte_ethdev/rte_flow.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> > > index 132b44edc6..1fb94f35e8 100644
> > > --- a/lib/librte_ethdev/rte_flow.h
> > > +++ b/lib/librte_ethdev/rte_flow.h
> > > @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> > >  #ifndef __cplusplus
> > >  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> > >       .s_field = 0x01,
> > > -     .seid = RTE_BE64(0xffffffffffffffff),
> > > +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> >
> > Rather than cast, why not put "ULL" at the end. If we are going to cast,
> > why not just put "-1" in to save some digits.
> 
> I preferred this form in the hope future developers who want
> 0x0fffffffffffffff will copy/paste this.
> 

As I remember there should be UINT64_MAX in stdint.h.
  
David Marchand April 27, 2020, 2 p.m. UTC | #8
On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin
<konstantin.ananyev@intel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> > Sent: Monday, April 27, 2020 2:37 PM
> > To: Richardson, Bruce <bruce.richardson@intel.com>
> > Cc: dev <dev@dpdk.org>; Ori Kam <orika@mellanox.com>; Thomas Monjalon <thomas@monjalon.net>; Yigit, Ferruh
> > <ferruh.yigit@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Zhang, Xiao <xiao.zhang@intel.com>
> > Subject: Re: [dpdk-dev] [PATCH 3/3] ethdev: fix build warning on 64-bit value
> >
> > On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
> > <bruce.richardson@intel.com> wrote:
> > >
> > > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > > > Building OVS with dpdk, sparse complains about 64-bit constant being
> > > > passed as a normal integer that can't fit it:
> > > > error: constant 0xffffffffffffffff is so big it is unsigned long
> > > >
> > > > Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> > > >
> > > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > > ---
> > > >  lib/librte_ethdev/rte_flow.h | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> > > > index 132b44edc6..1fb94f35e8 100644
> > > > --- a/lib/librte_ethdev/rte_flow.h
> > > > +++ b/lib/librte_ethdev/rte_flow.h
> > > > @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> > > >  #ifndef __cplusplus
> > > >  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> > > >       .s_field = 0x01,
> > > > -     .seid = RTE_BE64(0xffffffffffffffff),
> > > > +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> > >
> > > Rather than cast, why not put "ULL" at the end. If we are going to cast,
> > > why not just put "-1" in to save some digits.
> >
> > I preferred this form in the hope future developers who want
> > 0x0fffffffffffffff will copy/paste this.
> >
>
> As I remember there should be UINT64_MAX in stdint.h.

Yes, we could go with:
+     .seid = RTE_BE64(UINT64_MAX),

And then next time, for any value like 0x0fff ffff ffff ffff (had to
group the digits of what I had written), pretty sure we will miss this
and I will catch it only when building ovs.


--
David Marchand
  
Ferruh Yigit April 27, 2020, 2:07 p.m. UTC | #9
On 4/27/2020 3:00 PM, David Marchand wrote:
> On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin
> <konstantin.ananyev@intel.com> wrote:
>>
>>
>>
>>> -----Original Message-----
>>> From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
>>> Sent: Monday, April 27, 2020 2:37 PM
>>> To: Richardson, Bruce <bruce.richardson@intel.com>
>>> Cc: dev <dev@dpdk.org>; Ori Kam <orika@mellanox.com>; Thomas Monjalon <thomas@monjalon.net>; Yigit, Ferruh
>>> <ferruh.yigit@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Zhang, Xiao <xiao.zhang@intel.com>
>>> Subject: Re: [dpdk-dev] [PATCH 3/3] ethdev: fix build warning on 64-bit value
>>>
>>> On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
>>> <bruce.richardson@intel.com> wrote:
>>>>
>>>> On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
>>>>> Building OVS with dpdk, sparse complains about 64-bit constant being
>>>>> passed as a normal integer that can't fit it:
>>>>> error: constant 0xffffffffffffffff is so big it is unsigned long
>>>>>
>>>>> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
>>>>>
>>>>> Signed-off-by: David Marchand <david.marchand@redhat.com>
>>>>> ---
>>>>>  lib/librte_ethdev/rte_flow.h | 2 +-
>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
>>>>> index 132b44edc6..1fb94f35e8 100644
>>>>> --- a/lib/librte_ethdev/rte_flow.h
>>>>> +++ b/lib/librte_ethdev/rte_flow.h
>>>>> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
>>>>>  #ifndef __cplusplus
>>>>>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
>>>>>       .s_field = 0x01,
>>>>> -     .seid = RTE_BE64(0xffffffffffffffff),
>>>>> +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
>>>>
>>>> Rather than cast, why not put "ULL" at the end. If we are going to cast,
>>>> why not just put "-1" in to save some digits.
>>>
>>> I preferred this form in the hope future developers who want
>>> 0x0fffffffffffffff will copy/paste this.
>>>
>>
>> As I remember there should be UINT64_MAX in stdint.h.
> 
> Yes, we could go with:
> +     .seid = RTE_BE64(UINT64_MAX),

This is something else but if the value is 'UINT64_MAX', do we need 'RTE_BE64'
macro?

> 
> And then next time, for any value like 0x0fff ffff ffff ffff (had to
> group the digits of what I had written), pretty sure we will miss this
> and I will catch it only when building ovs.
> 
> 
> --
> David Marchand
>
  
David Marchand April 27, 2020, 2:12 p.m. UTC | #10
On Mon, Apr 27, 2020 at 4:07 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 4/27/2020 3:00 PM, David Marchand wrote:
> > On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin
> > <konstantin.ananyev@intel.com> wrote:
> >>
> >>
> >>
> >>> -----Original Message-----
> >>> From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> >>> Sent: Monday, April 27, 2020 2:37 PM
> >>> To: Richardson, Bruce <bruce.richardson@intel.com>
> >>> Cc: dev <dev@dpdk.org>; Ori Kam <orika@mellanox.com>; Thomas Monjalon <thomas@monjalon.net>; Yigit, Ferruh
> >>> <ferruh.yigit@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Zhang, Xiao <xiao.zhang@intel.com>
> >>> Subject: Re: [dpdk-dev] [PATCH 3/3] ethdev: fix build warning on 64-bit value
> >>>
> >>> On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
> >>> <bruce.richardson@intel.com> wrote:
> >>>>
> >>>> On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> >>>>> Building OVS with dpdk, sparse complains about 64-bit constant being
> >>>>> passed as a normal integer that can't fit it:
> >>>>> error: constant 0xffffffffffffffff is so big it is unsigned long
> >>>>>
> >>>>> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> >>>>>
> >>>>> Signed-off-by: David Marchand <david.marchand@redhat.com>
> >>>>> ---
> >>>>>  lib/librte_ethdev/rte_flow.h | 2 +-
> >>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>>
> >>>>> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> >>>>> index 132b44edc6..1fb94f35e8 100644
> >>>>> --- a/lib/librte_ethdev/rte_flow.h
> >>>>> +++ b/lib/librte_ethdev/rte_flow.h
> >>>>> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
> >>>>>  #ifndef __cplusplus
> >>>>>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> >>>>>       .s_field = 0x01,
> >>>>> -     .seid = RTE_BE64(0xffffffffffffffff),
> >>>>> +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> >>>>
> >>>> Rather than cast, why not put "ULL" at the end. If we are going to cast,
> >>>> why not just put "-1" in to save some digits.
> >>>
> >>> I preferred this form in the hope future developers who want
> >>> 0x0fffffffffffffff will copy/paste this.
> >>>
> >>
> >> As I remember there should be UINT64_MAX in stdint.h.
> >
> > Yes, we could go with:
> > +     .seid = RTE_BE64(UINT64_MAX),
>
> This is something else but if the value is 'UINT64_MAX', do we need 'RTE_BE64'
> macro?

In OVS case, sparse validates that a rte_be64_t value (mapped to
ovs_be64_t) is passed to .seid.

.../build/install/usr/local/include/rte_flow.h:1537:17: error:
incorrect type in initializer (different base types)
.../build/install/usr/local/include/rte_flow.h:1537:17:    expected
restricted ovs_be64 [usertype] seid
.../build/install/usr/local/include/rte_flow.h:1537:17:    got unsigned long
  
Ferruh Yigit April 27, 2020, 2:14 p.m. UTC | #11
On 4/27/2020 3:12 PM, David Marchand wrote:
> On Mon, Apr 27, 2020 at 4:07 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>>
>> On 4/27/2020 3:00 PM, David Marchand wrote:
>>> On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin
>>> <konstantin.ananyev@intel.com> wrote:
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
>>>>> Sent: Monday, April 27, 2020 2:37 PM
>>>>> To: Richardson, Bruce <bruce.richardson@intel.com>
>>>>> Cc: dev <dev@dpdk.org>; Ori Kam <orika@mellanox.com>; Thomas Monjalon <thomas@monjalon.net>; Yigit, Ferruh
>>>>> <ferruh.yigit@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Zhang, Xiao <xiao.zhang@intel.com>
>>>>> Subject: Re: [dpdk-dev] [PATCH 3/3] ethdev: fix build warning on 64-bit value
>>>>>
>>>>> On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
>>>>> <bruce.richardson@intel.com> wrote:
>>>>>>
>>>>>> On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
>>>>>>> Building OVS with dpdk, sparse complains about 64-bit constant being
>>>>>>> passed as a normal integer that can't fit it:
>>>>>>> error: constant 0xffffffffffffffff is so big it is unsigned long
>>>>>>>
>>>>>>> Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
>>>>>>>
>>>>>>> Signed-off-by: David Marchand <david.marchand@redhat.com>
>>>>>>> ---
>>>>>>>  lib/librte_ethdev/rte_flow.h | 2 +-
>>>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>>
>>>>>>> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
>>>>>>> index 132b44edc6..1fb94f35e8 100644
>>>>>>> --- a/lib/librte_ethdev/rte_flow.h
>>>>>>> +++ b/lib/librte_ethdev/rte_flow.h
>>>>>>> @@ -1534,7 +1534,7 @@ struct rte_flow_item_pfcp {
>>>>>>>  #ifndef __cplusplus
>>>>>>>  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
>>>>>>>       .s_field = 0x01,
>>>>>>> -     .seid = RTE_BE64(0xffffffffffffffff),
>>>>>>> +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
>>>>>>
>>>>>> Rather than cast, why not put "ULL" at the end. If we are going to cast,
>>>>>> why not just put "-1" in to save some digits.
>>>>>
>>>>> I preferred this form in the hope future developers who want
>>>>> 0x0fffffffffffffff will copy/paste this.
>>>>>
>>>>
>>>> As I remember there should be UINT64_MAX in stdint.h.
>>>
>>> Yes, we could go with:
>>> +     .seid = RTE_BE64(UINT64_MAX),
>>
>> This is something else but if the value is 'UINT64_MAX', do we need 'RTE_BE64'
>> macro?
> 
> In OVS case, sparse validates that a rte_be64_t value (mapped to
> ovs_be64_t) is passed to .seid.
> 
> .../build/install/usr/local/include/rte_flow.h:1537:17: error:
> incorrect type in initializer (different base types)
> .../build/install/usr/local/include/rte_flow.h:1537:17:    expected
> restricted ovs_be64 [usertype] seid
> .../build/install/usr/local/include/rte_flow.h:1537:17:    got unsigned long
> 
> 

Got it, thanks for clarification.
  
Thomas Monjalon April 28, 2020, 9:27 a.m. UTC | #12
27/04/2020 16:00, David Marchand:
> On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin wrote:
> > From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> > > On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
> > > <bruce.richardson@intel.com> wrote:
> > > > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > > > > Building OVS with dpdk, sparse complains about 64-bit constant being
> > > > > passed as a normal integer that can't fit it:
> > > > > error: constant 0xffffffffffffffff is so big it is unsigned long
> > > > >
> > > > > Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> > > > >
> > > > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > > > ---
> > > > > --- a/lib/librte_ethdev/rte_flow.h
> > > > > +++ b/lib/librte_ethdev/rte_flow.h
> > > > >  static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
> > > > >       .s_field = 0x01,
> > > > > -     .seid = RTE_BE64(0xffffffffffffffff),
> > > > > +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> > > >
> > > > Rather than cast, why not put "ULL" at the end. If we are going to cast,
> > > > why not just put "-1" in to save some digits.
> > >
> > > I preferred this form in the hope future developers who want
> > > 0x0fffffffffffffff will copy/paste this.
> > >
> >
> > As I remember there should be UINT64_MAX in stdint.h.
> 
> Yes, we could go with:
> +     .seid = RTE_BE64(UINT64_MAX),
> 
> And then next time, for any value like 0x0fff ffff ffff ffff (had to
> group the digits of what I had written), pretty sure we will miss this
> and I will catch it only when building ovs.

I agree with David (in general and especially here).

RTE_BE64 is required for static analyzers and is an explicit info.

UINT64_C is better than ULL suffix because it
	- is generic
	- gives size explicitly

UINT64_C(0xffffffffffffffff) is better than UINT64_MAX because
	- rte_flow.h has a lot of bitmasks
	- it is copy/paste safe

Acked-by: Thomas Monjalon <thomas@monjalon.net>
  
Morten Brørup May 6, 2020, 2:37 p.m. UTC | #13
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> Sent: Tuesday, April 28, 2020 11:28 AM
> 
> 27/04/2020 16:00, David Marchand:
> > On Mon, Apr 27, 2020 at 3:47 PM Ananyev, Konstantin wrote:
> > > From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> > > > On Mon, Apr 27, 2020 at 3:34 PM Bruce Richardson
> > > > <bruce.richardson@intel.com> wrote:
> > > > > On Mon, Apr 27, 2020 at 03:23:41PM +0200, David Marchand wrote:
> > > > > > Building OVS with dpdk, sparse complains about 64-bit
> constant being
> > > > > > passed as a normal integer that can't fit it:
> > > > > > error: constant 0xffffffffffffffff is so big it is unsigned
> long
> > > > > >
> > > > > > Fixes: ecbc8570131d ("ethdev: add PFCP header to flow API")
> > > > > >
> > > > > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > > > > ---
> > > > > > --- a/lib/librte_ethdev/rte_flow.h
> > > > > > +++ b/lib/librte_ethdev/rte_flow.h
> > > > > >  static const struct rte_flow_item_pfcp
> rte_flow_item_pfcp_mask = {
> > > > > >       .s_field = 0x01,
> > > > > > -     .seid = RTE_BE64(0xffffffffffffffff),
> > > > > > +     .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
> > > > >
> > > > > Rather than cast, why not put "ULL" at the end. If we are going
> to cast,
> > > > > why not just put "-1" in to save some digits.
> > > >
> > > > I preferred this form in the hope future developers who want
> > > > 0x0fffffffffffffff will copy/paste this.
> > > >
> > >
> > > As I remember there should be UINT64_MAX in stdint.h.
> >
> > Yes, we could go with:
> > +     .seid = RTE_BE64(UINT64_MAX),
> >
> > And then next time, for any value like 0x0fff ffff ffff ffff (had to
> > group the digits of what I had written), pretty sure we will miss
> this
> > and I will catch it only when building ovs.
> 
> I agree with David (in general and especially here).
> 
> RTE_BE64 is required for static analyzers and is an explicit info.
> 
> UINT64_C is better than ULL suffix because it
> 	- is generic
> 	- gives size explicitly

Certainly. Explicit is preferred in code for embedded systems.
"unsigned long long" means 64 bit or more, which also applies to the "ULL" postfix.
"uint64_t" and "UINT64_C" means exactly 64 bit.

> 
> UINT64_C(0xffffffffffffffff) is better than UINT64_MAX because
> 	- rte_flow.h has a lot of bitmasks
> 	- it is copy/paste safe
> 
> Acked-by: Thomas Monjalon <thomas@monjalon.net>
> 

And shouldn't the struct rte_flow_item_pfcp be packed? I would expect the compiler to add 32 bit padding before seid to ensure its 64 bit alignment.


Med venlig hilsen / kind regards
- Morten Brørup
  

Patch

diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 132b44edc6..1fb94f35e8 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1534,7 +1534,7 @@  struct rte_flow_item_pfcp {
 #ifndef __cplusplus
 static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
 	.s_field = 0x01,
-	.seid = RTE_BE64(0xffffffffffffffff),
+	.seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
 };
 #endif