From: Omar Ramadan <omar@blockcast.net>
To: Taehee Yoo <ap420073@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Simon Horman <horms@kernel.org>
Subject: [PATCH net-next v3 1/3] amt: make the A-B source walk linear
Date: Sun, 22 Nov 2026 23:57:22 +0000 [thread overview]
Message-ID: <20261122235724.2898320-2-omar@blockcast.net> (raw)
In-Reply-To: <20261122235724.2898320-1-omar@blockcast.net>
amt_lookup_act_srcs() computes A-B, the sources of the group's state that
a received record does not name, by comparing every source in the group
with every source in the record. That runs under tunnel->lock in
softirq, and only the packet length bounds the record, so a single
Membership Update can already cost |A| * |B| address compares at the
current 128-source default.
Mark the group's sources that the record names with one hash lookup per
record source, then act on the unmarked ones in a single pass over the
group, clearing the marks as it goes. The cost becomes O(|A| + |B|) and
the result is unchanged: a marked source is skipped whatever its filter
state, exactly as the pairwise compare skipped it.
Found by review (Sashiko, on the limits patch); not triggered at runtime.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 43 ++++++++++++++++++++++---------------------
include/net/amt.h | 2 ++
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b145ed3ca..79d68bcc7 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -1649,7 +1649,7 @@ static void amt_lookup_act_srcs(struct amt_tunnel_list *tunnel,
union amt_addr src = {0,};
struct hlist_node *t;
u16 nsrcs;
- int i, j;
+ int i;
if (!v6) {
igmp_grec = grec;
@@ -1705,28 +1705,29 @@ static void amt_lookup_act_srcs(struct amt_tunnel_list *tunnel,
}
break;
case AMT_OPS_SUB:
- /* A-B */
- for (i = 0; i < amt->hash_buckets; i++) {
- hlist_for_each_entry_safe(snode, t, &gnode->sources[i],
- node) {
- if (!amt_status_filter(snode, filter))
- continue;
- for (j = 0; j < nsrcs; j++) {
- if (!v6)
- src.ip4 = igmp_grec->grec_src[j];
+ /* A-B: mark every source of A that B names, then act on the
+ * unmarked ones in a single pass over the group, clearing the
+ * marks as we go. This is O(|A| + |B|) rather than |A| * |B|.
+ */
+ for (i = 0; i < nsrcs; i++) {
+ if (!v6)
+ src.ip4 = igmp_grec->grec_src[i];
#if IS_ENABLED(CONFIG_IPV6)
- else
- memcpy(&src.ip6,
- &mld_grec->grec_src[j],
- sizeof(struct in6_addr));
+ else
+ memcpy(&src.ip6, &mld_grec->grec_src[i],
+ sizeof(struct in6_addr));
#endif
- if (amt_addr_equal(&snode->source_addr,
- &src))
- goto out_sub;
- }
- amt_act_src(tunnel, gnode, snode, act);
- continue;
-out_sub:;
+ snode = amt_lookup_src(tunnel, gnode, AMT_FILTER_ALL,
+ &src);
+ if (snode)
+ snode->sub_mark = true;
+ }
+ for (i = 0; i < amt->hash_buckets; i++) {
+ hlist_for_each_entry(snode, &gnode->sources[i], node) {
+ if (snode->sub_mark)
+ snode->sub_mark = false;
+ else if (amt_status_filter(snode, filter))
+ amt_act_src(tunnel, gnode, snode, act);
}
}
break;
diff --git a/include/net/amt.h b/include/net/amt.h
index 9ba097127..f36efcdd9 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -287,6 +287,8 @@ struct amt_source_node {
struct delayed_work source_timer;
union amt_addr source_addr;
enum amt_source_status status;
+ /* Scratch mark for the A-B source walk, under tunnel_list->lock. */
+ bool sub_mark;
#define AMT_SOURCE_OLD 0
#define AMT_SOURCE_NEW 1
u8 flags;
--
2.43.0
next prev parent reply other threads:[~2026-11-22 23:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 23:57 [PATCH net-next v3 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-22 23:57 ` Omar Ramadan [this message]
2026-11-22 23:57 ` [PATCH net-next v3 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-22 23:57 ` [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
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=20261122235724.2898320-2-omar@blockcast.net \
--to=omar@blockcast.net \
--cc=andrew+netdev@lunn.ch \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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