[net,v2] openvswitch: meter: fix the incorrect calculation of max delta_t

Message ID 20180309020850.55325-1-zhanglkk1990@163.com
State Accepted
Delegated to: David Miller
Headers show
Series
  • [net,v2] openvswitch: meter: fix the incorrect calculation of max delta_t
Related show

Commit Message

zhangliping March 9, 2018, 2:08 a.m.
From: zhangliping <zhangliping02@baidu.com>

Max delat_t should be the full_bucket/rate instead of the full_bucket.
Also report EINVAL if the rate is zero.

Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure")
Cc: Andy Zhou <azhou@ovn.org>
Signed-off-by: zhangliping <zhangliping02@baidu.com>
---
 V2: report EINVAL if the rate is 0 to avoid divide by zero error.

 net/openvswitch/meter.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Pravin Shelar March 10, 2018, 10:06 p.m. | #1
On Thu, Mar 8, 2018 at 6:08 PM, zhangliping <zhanglkk1990@163.com> wrote:
> From: zhangliping <zhangliping02@baidu.com>
>
> Max delat_t should be the full_bucket/rate instead of the full_bucket.
> Also report EINVAL if the rate is zero.
>
> Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure")
> Cc: Andy Zhou <azhou@ovn.org>
> Signed-off-by: zhangliping <zhangliping02@baidu.com>
> ---
>  V2: report EINVAL if the rate is 0 to avoid divide by zero error.
>

Looks good.

Acked-by: Pravin B Shelar <pshelar@ovn.org>
David Miller March 12, 2018, 2:50 a.m. | #2
From: zhangliping <zhanglkk1990@163.com>
Date: Fri,  9 Mar 2018 10:08:50 +0800

> From: zhangliping <zhangliping02@baidu.com>
> 
> Max delat_t should be the full_bucket/rate instead of the full_bucket.
> Also report EINVAL if the rate is zero.
> 
> Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure")
> Cc: Andy Zhou <azhou@ovn.org>
> Signed-off-by: zhangliping <zhangliping02@baidu.com>
> ---
>  V2: report EINVAL if the rate is 0 to avoid divide by zero error.

Applied and queued up for -stable, thanks.

Patch

diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index 04b94281a30b..b891a91577f8 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -242,14 +242,20 @@  static struct dp_meter *dp_meter_create(struct nlattr **a)
 
 		band->type = nla_get_u32(attr[OVS_BAND_ATTR_TYPE]);
 		band->rate = nla_get_u32(attr[OVS_BAND_ATTR_RATE]);
+		if (band->rate == 0) {
+			err = -EINVAL;
+			goto exit_free_meter;
+		}
+
 		band->burst_size = nla_get_u32(attr[OVS_BAND_ATTR_BURST]);
 		/* Figure out max delta_t that is enough to fill any bucket.
 		 * Keep max_delta_t size to the bucket units:
 		 * pkts => 1/1000 packets, kilobits => bits.
+		 *
+		 * Start with a full bucket.
 		 */
-		band_max_delta_t = (band->burst_size + band->rate) * 1000;
-		/* Start with a full bucket. */
-		band->bucket = band_max_delta_t;
+		band->bucket = (band->burst_size + band->rate) * 1000;
+		band_max_delta_t = band->bucket / band->rate;
 		if (band_max_delta_t > meter->max_delta_t)
 			meter->max_delta_t = band_max_delta_t;
 		band++;