[PATCH nf-next v1 5/5] openvswitch: conntrack: warn about a zone above its limit without a lock
From: Vladimir Vdovin
Date: Tue Nov 17 2026 - 06:54:28 EST
ovs_ct_commit() warns through net_warn_ratelimited() for every new
connection a zone above its limit refuses. The rate limiting itself
costs: every call serializes on the shared ratelimit state, and with
a zone at its limit under flood that is every rx cpu for every packet.
Keep one timestamp per netns instead: a caller that finds it in the
future returns at once, the first one past it moves it a second ahead
and warns. Two cpus racing past it in the same jiffy may both warn,
which is harmless, and nothing is serialized.
Signed-off-by: Vladimir Vdovin <deliran@xxxxxxxxxx>
---
net/openvswitch/conntrack.c | 20 +++++++++++++++++---
net/openvswitch/datapath.h | 1 +
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index e78a62cec051..ee90af14ac81 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -936,6 +936,21 @@ static u32 ct_limit_get(const struct ovs_ct_limit_info *info, u16 zone)
return info->default_limit;
}
+/* At most one warning per second. net_warn_ratelimited() would do, but it
+ * serializes its callers on the ratelimit state, and when a zone is above
+ * its limit every rx cpu is a caller for every packet.
+ */
+static void ovs_ct_limit_warn(struct net *net, u16 zone)
+{
+ struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
+
+ if (time_before(jiffies, READ_ONCE(ovs_net->ct_limit_warn_next)))
+ return;
+
+ WRITE_ONCE(ovs_net->ct_limit_warn_next, jiffies + HZ);
+ pr_warn("openvswitch: zone: %u exceeds conntrack limit\n", zone);
+}
+
static int ovs_ct_check_limit(struct net *net,
const struct sk_buff *skb,
const struct ovs_conntrack_info *info)
@@ -999,9 +1014,7 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
if (!nf_ct_is_confirmed(ct)) {
err = ovs_ct_check_limit(net, skb, info);
if (err) {
- net_warn_ratelimited("openvswitch: zone: %u "
- "exceeds conntrack limit\n",
- info->zone.id);
+ ovs_ct_limit_warn(net, info->zone.id);
return err;
}
}
@@ -1638,6 +1651,7 @@ static int ovs_ct_limit_init(struct net *net, struct ovs_net *ovs_net)
pr_err("openvswitch: failed to init nf_conncount %d\n", err);
return err;
}
+ ovs_net->ct_limit_warn_next = jiffies;
rcu_assign_pointer(ovs_net->ct_limit_info, info);
return 0;
}
diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h
index 7a7afaeceee5..9c6a5b5a8939 100644
--- a/net/openvswitch/datapath.h
+++ b/net/openvswitch/datapath.h
@@ -177,6 +177,7 @@ struct ovs_net {
#if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
struct ovs_ct_limit_info __rcu *ct_limit_info;
struct ovs_ct_limit_info *ct_limit_exit_data;
+ unsigned long ct_limit_warn_next;
#endif
bool xt_label;
};
--
2.56.0