From: Tao Liu <thomas.liu@ucloud.cn>
To: pshelar@ovn.org
Cc: dev@openvswitch.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, i.maximets@ovn.org,
jean.tourrilhes@hpe.com, kuba@kernel.org, davem@davemloft.net,
thomas.liu@ucloud.cn
Subject: [ovs-dev] [PATCH net] openvswitch: meter: fix race when getting now_ms.
Date: Thu, 13 May 2021 18:03:00 +0800 [thread overview]
Message-ID: <20210513100300.22735-1-thomas.liu@ucloud.cn> (raw)
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@ucloud.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
next reply other threads:[~2021-05-13 10:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-13 10:03 Tao Liu [this message]
2021-05-13 10:21 ` [ovs-dev] [PATCH net] openvswitch: meter: fix race when getting now_ms Ilya Maximets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210513100300.22735-1-thomas.liu@ucloud.cn \
--to=thomas.liu@ucloud.cn \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=i.maximets@ovn.org \
--cc=jean.tourrilhes@hpe.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pshelar@ovn.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).