diff mbox

[ovs-dev] netdev-dpdk: use 64-bit arithmetic when converting rates

Message ID 20170824131625.30635-1-lrichard@redhat.com
State Accepted
Headers show

Commit Message

Lance Richardson Aug. 24, 2017, 1:16 p.m. UTC
Force 64-bit arithmetic to be used when converting uint32_t rate
and burst parameters from kilobits per second to bytes per second,
avoiding incorrect behavior for rates exceeding UINT_MAX bits
per second.

Reported-by: "王志克" <wangzhike@jd.com>
Fixes: 9509913aa722 ("netdev-dpdk.c: Add ingress-policing functionality.")
Signed-off-by: Lance Richardson <lrichard@redhat.com>
---
Note: Found by inspection, untested.

 lib/netdev-dpdk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mark Michelson Aug. 24, 2017, 1:44 p.m. UTC | #1
LGTM

Acked-By: Mark Michelson <mmichels@redhat.com>

On Thu, Aug 24, 2017 at 8:17 AM Lance Richardson <lrichard@redhat.com>
wrote:

> Force 64-bit arithmetic to be used when converting uint32_t rate
> and burst parameters from kilobits per second to bytes per second,
> avoiding incorrect behavior for rates exceeding UINT_MAX bits
> per second.
>
> Reported-by: "王志克" <wangzhike@jd.com>
> Fixes: 9509913aa722 ("netdev-dpdk.c: Add ingress-policing functionality.")
> Signed-off-by: Lance Richardson <lrichard@redhat.com>
> ---
> Note: Found by inspection, untested.
>
>  lib/netdev-dpdk.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
> index 1aaf6f7e2..4e8aaa3d8 100644
> --- a/lib/netdev-dpdk.c
> +++ b/lib/netdev-dpdk.c
> @@ -2229,8 +2229,8 @@ netdev_dpdk_policer_construct(uint32_t rate,
> uint32_t burst)
>      rte_spinlock_init(&policer->policer_lock);
>
>      /* rte_meter requires bytes so convert kbits rate and burst to bytes.
> */
> -    rate_bytes = rate * 1000/8;
> -    burst_bytes = burst * 1000/8;
> +    rate_bytes = rate * 1000ULL / 8;
> +    burst_bytes = burst * 1000ULL / 8;
>
>      policer->app_srtcm_params.cir = rate_bytes;
>      policer->app_srtcm_params.cbs = burst_bytes;
> --
> 2.13.4
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Kevin Traynor Aug. 24, 2017, 11:42 p.m. UTC | #2
On 08/24/2017 02:44 PM, Mark Michelson wrote:
> LGTM
> 
> Acked-By: Mark Michelson <mmichels@redhat.com>
> 
> On Thu, Aug 24, 2017 at 8:17 AM Lance Richardson <lrichard@redhat.com>
> wrote:
> 
>> Force 64-bit arithmetic to be used when converting uint32_t rate
>> and burst parameters from kilobits per second to bytes per second,
>> avoiding incorrect behavior for rates exceeding UINT_MAX bits
>> per second.
>>

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

>> Reported-by: "王志克" <wangzhike@jd.com>
>> Fixes: 9509913aa722 ("netdev-dpdk.c: Add ingress-policing functionality.")
>> Signed-off-by: Lance Richardson <lrichard@redhat.com>
>> ---
>> Note: Found by inspection, untested.
>>
>>  lib/netdev-dpdk.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
>> index 1aaf6f7e2..4e8aaa3d8 100644
>> --- a/lib/netdev-dpdk.c
>> +++ b/lib/netdev-dpdk.c
>> @@ -2229,8 +2229,8 @@ netdev_dpdk_policer_construct(uint32_t rate,
>> uint32_t burst)
>>      rte_spinlock_init(&policer->policer_lock);
>>
>>      /* rte_meter requires bytes so convert kbits rate and burst to bytes.
>> */
>> -    rate_bytes = rate * 1000/8;
>> -    burst_bytes = burst * 1000/8;
>> +    rate_bytes = rate * 1000ULL / 8;
>> +    burst_bytes = burst * 1000ULL / 8;
>>
>>      policer->app_srtcm_params.cir = rate_bytes;
>>      policer->app_srtcm_params.cbs = burst_bytes;
>> --
>> 2.13.4
>>
>> _______________________________________________
>> dev mailing list
>> dev@openvswitch.org
>> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Darrell Ball Aug. 25, 2017, 10:02 p.m. UTC | #3
I applied the patch to dpdk_merge here

https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_darball_ovs_commits_dpdk-5Fmerge&d=DwIGaQ&c=uilaK90D4TOVoH58JNXRgQ&r=BVhFA09CGX7JQ5Ih-uZnsw&m=A2_FCacqbp2moAo3HGFlTuxsjONUGhlN42OBcAuQQ6w&s=b6btPKhgvOFr2GOUYvktND6kaC6jc3fXI-mXfvNgXOU&e=

This looks like it could go back as far as 2.6.


On 8/24/17, 6:16 AM, "ovs-dev-bounces@openvswitch.org on behalf of Lance Richardson" <ovs-dev-bounces@openvswitch.org on behalf of lrichard@redhat.com> wrote:

    Force 64-bit arithmetic to be used when converting uint32_t rate
    and burst parameters from kilobits per second to bytes per second,
    avoiding incorrect behavior for rates exceeding UINT_MAX bits
    per second.
    
    Reported-by: "王志克" <wangzhike@jd.com>
    Fixes: 9509913aa722 ("netdev-dpdk.c: Add ingress-policing functionality.")
    Signed-off-by: Lance Richardson <lrichard@redhat.com>

    ---
    Note: Found by inspection, untested.
    
     lib/netdev-dpdk.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
    index 1aaf6f7e2..4e8aaa3d8 100644
    --- a/lib/netdev-dpdk.c
    +++ b/lib/netdev-dpdk.c
    @@ -2229,8 +2229,8 @@ netdev_dpdk_policer_construct(uint32_t rate, uint32_t burst)
         rte_spinlock_init(&policer->policer_lock);
     
         /* rte_meter requires bytes so convert kbits rate and burst to bytes. */
    -    rate_bytes = rate * 1000/8;
    -    burst_bytes = burst * 1000/8;
    +    rate_bytes = rate * 1000ULL / 8;
    +    burst_bytes = burst * 1000ULL / 8;
     
         policer->app_srtcm_params.cir = rate_bytes;
         policer->app_srtcm_params.cbs = burst_bytes;
    -- 
    2.13.4
    
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_mailman_listinfo_ovs-2Ddev&d=DwIGaQ&c=uilaK90D4TOVoH58JNXRgQ&r=BVhFA09CGX7JQ5Ih-uZnsw&m=iazIwQBuiSqzVKtRDEW1WScuv043H7CJeF9RmwU9SA4&s=Eo5tR-W5L7RCCoJLUTEIvo3UaqihU1thE1jB95icvNA&e=
Stokes, Ian Aug. 28, 2017, 4:46 p.m. UTC | #4
> Force 64-bit arithmetic to be used when converting uint32_t rate and burst

> parameters from kilobits per second to bytes per second, avoiding

> incorrect behavior for rates exceeding UINT_MAX bits per second.

> 


Good catch Lance, thanks for the fix.

Acked-by: Ian.Stokes@intel.com

Tested-by: Ian.Stokes@intel.com


> Reported-by: "王志克" <wangzhike@jd.com>

> Fixes: 9509913aa722 ("netdev-dpdk.c: Add ingress-policing functionality.")

> Signed-off-by: Lance Richardson <lrichard@redhat.com>

> ---

> Note: Found by inspection, untested.

> 

>  lib/netdev-dpdk.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index

> 1aaf6f7e2..4e8aaa3d8 100644

> --- a/lib/netdev-dpdk.c

> +++ b/lib/netdev-dpdk.c

> @@ -2229,8 +2229,8 @@ netdev_dpdk_policer_construct(uint32_t rate,

> uint32_t burst)

>      rte_spinlock_init(&policer->policer_lock);

> 

>      /* rte_meter requires bytes so convert kbits rate and burst to bytes.

> */

> -    rate_bytes = rate * 1000/8;

> -    burst_bytes = burst * 1000/8;

> +    rate_bytes = rate * 1000ULL / 8;

> +    burst_bytes = burst * 1000ULL / 8;

> 

>      policer->app_srtcm_params.cir = rate_bytes;

>      policer->app_srtcm_params.cbs = burst_bytes;

> --

> 2.13.4
diff mbox

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 1aaf6f7e2..4e8aaa3d8 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2229,8 +2229,8 @@  netdev_dpdk_policer_construct(uint32_t rate, uint32_t burst)
     rte_spinlock_init(&policer->policer_lock);
 
     /* rte_meter requires bytes so convert kbits rate and burst to bytes. */
-    rate_bytes = rate * 1000/8;
-    burst_bytes = burst * 1000/8;
+    rate_bytes = rate * 1000ULL / 8;
+    burst_bytes = burst * 1000ULL / 8;
 
     policer->app_srtcm_params.cir = rate_bytes;
     policer->app_srtcm_params.cbs = burst_bytes;