提交 239b06c6 编写于 作者: T Tao Liu 提交者: Yang Yingliang

openvswitch: meter: fix race when getting now_ms.

[ Upstream commit e4df1b0c ]

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.

OpenVswitch userspace datapath has fixed the same issue[1] some
time ago, and we port the implementation to kernel datapath.

[1] https://patchwork.ozlabs.org/project/openvswitch/patch/20191025114436.9746-1-i.maximets@ovn.org/

Fixes: 96fbc13d ("openvswitch: Add meter infrastructure")
Signed-off-by: NTao Liu <thomas.liu@ucloud.cn>
Suggested-by: NIlya Maximets <i.maximets@ovn.org>
Reviewed-by: NIlya Maximets <i.maximets@ovn.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 e4334c83
...@@ -464,6 +464,14 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb, ...@@ -464,6 +464,14 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
spin_lock(&meter->lock); spin_lock(&meter->lock);
long_delta_ms = (now_ms - meter->used); /* ms */ long_delta_ms = (now_ms - meter->used); /* ms */
if (long_delta_ms < 0) {
/* This condition means that we have several threads fighting
* for a meter lock, and the one who received the packets a
* bit later wins. Assuming that all racing threads received
* packets at the same time to avoid overflow.
*/
long_delta_ms = 0;
}
/* Make sure delta_ms will not be too large, so that bucket will not /* Make sure delta_ms will not be too large, so that bucket will not
* wrap around below. * wrap around below.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册