[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210513100300.22735-1-thomas.liu@ucloud.cn>
Date: Thu, 13 May 2021 18:03:00 +0800
From: Tao Liu <thomas.liu@...oud.cn>
To: pshelar@....org
Cc: dev@...nvswitch.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, i.maximets@....org,
jean.tourrilhes@....com, kuba@...nel.org, davem@...emloft.net,
thomas.liu@...oud.cn
Subject: [ovs-dev] [PATCH net] openvswitch: meter: fix race when getting now_ms.
We have observed meters working unexpected if traffic is 3+Gbit/s
with multiple connections.
now_ms is not pretected by meter->lock, we may get a negative
long_delta_ms when another cpu updated meter->used, then:
delta_ms = (u32)long_delta_ms;
which will be a large value.
band->bucket += delta_ms * band->rate;
then we get a wrong band->bucket.
Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure")
Signed-off-by: Tao Liu <thomas.liu@...oud.cn>
---
net/openvswitch/meter.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index 96b524c..c50ab7f 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -593,7 +593,7 @@ static int ovs_meter_cmd_del(struct sk_buff *skb, struct genl_info *info)
bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *key, u32 meter_id)
{
- long long int now_ms = div_u64(ktime_get_ns(), 1000 * 1000);
+ long long int now_ms;
long long int long_delta_ms;
struct dp_meter_band *band;
struct dp_meter *meter;
@@ -610,6 +610,7 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
/* Lock the meter while using it. */
spin_lock(&meter->lock);
+ now_ms = div_u64(ktime_get_ns(), 1000 * 1000);
long_delta_ms = (now_ms - meter->used); /* ms */
/* Make sure delta_ms will not be too large, so that bucket will not
--
1.8.3.1
Powered by blists - more mailing lists