[PATCH nf-next v1 4/5] openvswitch: conntrack: do not record connections above the zone limit

From: Vladimir Vdovin

Date: Tue Nov 17 2026 - 06:54:32 EST


ovs_ct_check_limit() records every new connection in nf_conncount and
only then rejects it when the zone is above its limit. Recording means
taking the zone's list_lock and walking the list for gc, so above the
limit every rx cpu serializes on that lock for every packet, to add an
entry that is rejected right after and that gc has to evict later.

Look the count up first. nf_conncount_count_skb() without an skb does
a lockless rbtree lookup, runs gc on the list if it has not been done
during this jiffy, and returns the count without recording anything.
When the zone has no room for another connection, reject on that
count and never touch list_lock. Below the limit the connection is
recorded as before, at the cost of one extra lockless lookup.

Signed-off-by: Vladimir Vdovin <deliran@xxxxxxxxxx>
---
net/openvswitch/conntrack.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index d3326edcabf7..e78a62cec051 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -955,6 +955,17 @@ static int ovs_ct_check_limit(struct net *net,
if (per_zone_limit == OVS_CT_LIMIT_UNLIMITED)
return 0;

+ /* Nothing is recorded while the zone has no room for another
+ * connection: a lookup without an skb is lockless and only runs gc
+ * on the list, so the count keeps following the real number of
+ * connections while new ones are being rejected.
+ */
+ connections = nf_conncount_count_skb(net, NULL, info->family,
+ ct_limit_info->data,
+ &conncount_key);
+ if (connections >= per_zone_limit)
+ return -ENOMEM;
+
connections = nf_conncount_count_skb(net, skb, info->family,
ct_limit_info->data,
&conncount_key);
--
2.56.0