Message ID | 1531788961-46115-2-git-send-email-yihung.wei@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | Kernel backports from net-next | expand |
On 7/16/2018 5:55 PM, Yi-Hung Wei wrote: > From: zhangliping <zhangliping02@baidu.com> > > Upstream commit: > commit ddc502dfed600bff0b61d899f70d95b76223fdfc > Author: zhangliping <zhangliping02@baidu.com> > Date: Fri Mar 9 10:08:50 2018 +0800 > > openvswitch: meter: fix the incorrect calculation of max delta_t > > 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> > Acked-by: Pravin B Shelar <pshelar@ovn.org> > Signed-off-by: David S. Miller <davem@davemloft.net> > > Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> > --- > datapath/meter.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/datapath/meter.c b/datapath/meter.c > index f9e8f124b411..1c2ed4626c2a 100644 > --- a/datapath/meter.c > +++ b/datapath/meter.c > @@ -252,14 +252,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++; I had the patch queued up submission myself but you beat me to it. Thanks!!! Reviewed-by: Greg Rose <gvrose8192@gmail.com> Tested-by: Greg Rose <gvrose8192@gmail.com
diff --git a/datapath/meter.c b/datapath/meter.c index f9e8f124b411..1c2ed4626c2a 100644 --- a/datapath/meter.c +++ b/datapath/meter.c @@ -252,14 +252,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++;