* [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t
@ 2018-03-09 2:08 zhangliping
2018-03-10 22:06 ` Pravin Shelar
2018-03-12 2:50 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: zhangliping @ 2018-03-09 2:08 UTC (permalink / raw)
To: pshelar, davem, netdev; +Cc: zhangliping, Andy Zhou
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(-)
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++;
--
2.13.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t
2018-03-09 2:08 [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t zhangliping
@ 2018-03-10 22:06 ` Pravin Shelar
2018-03-12 2:50 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Pravin Shelar @ 2018-03-10 22:06 UTC (permalink / raw)
To: zhangliping
Cc: David S. Miller, Linux Kernel Network Developers, zhangliping,
Andy Zhou
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t
2018-03-09 2:08 [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t zhangliping
2018-03-10 22:06 ` Pravin Shelar
@ 2018-03-12 2:50 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-03-12 2:50 UTC (permalink / raw)
To: zhanglkk1990; +Cc: pshelar, netdev, zhangliping02, azhou
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-12 2:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-09 2:08 [PATCH net v2] openvswitch: meter: fix the incorrect calculation of max delta_t zhangliping
2018-03-10 22:06 ` Pravin Shelar
2018-03-12 2:50 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).