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>,
Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next v5 3/3] amt: make the per-tunnel group and source limits configurable
Date: Mon, 30 Nov 2026 09:50:59 +0000 [thread overview]
Message-ID: <20261130095059.1301582-4-omar@blockcast.net> (raw)
In-Reply-To: <20261130095059.1301582-1-omar@blockcast.net>
A relay caps the state one gateway tunnel can hold at AMT_MAX_GROUP (32)
group records and AMT_MAX_SOURCE (128) source records, counted across
all of the tunnel's groups. Both are compile-time constants. An SSM
receiver uses a source record for every (S,G) it joins, so a gateway that
needs more than 32 groups or 128 channels through one tunnel has the
excess joins dropped, and the relay operator cannot raise either limit.
Add IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES, read when the link is
created, like IFLA_AMT_MAX_TUNNELS. Zero or an absent attribute keeps the
current defaults. Gateways drive these allocations, so the policy caps
them at 512 groups and 4096 sources per tunnel, and strict_start_type
has it validate them, and any attribute added after them, strictly.
Report both limits in amt_fill_info().
The group and source hashes keep their AMT_HSIZE (256) buckets. Sizing
them from max_sources would push every group node and tunnel node into
kmalloc-8k once max_sources passed 2048, doubling per-group memory; at
4096 sources in one group a chain averages 16 entries, which only makes
a lookup longer.
Raising the limits also raises the previous patch's bound on the work of
one Membership Update, twice what refreshing every group the tunnel may
hold costs. A lookup that misses walks the whole chain of its bucket,
which averages max_sources / hash_buckets entries, so the cost now
counts each lookup for that many visits: one at the defaults, 16 at 4096
sources. The bound is then about 3.0 million bucket, source and chain
visits at 512 groups and 4096 sources, 25 times the default 120,320. Cap
it at what one legitimate report can cost. A host splits its report to
the MTU, so a report names at most mtu / 8 groups, IGMPv3 records being
the smallest, and at most mtu / 4 sources, which caps the lookups it may
charge. On a 1500-byte stream link that caps one Update at about 440,000
visits at the ceilings, 3.7 times the default, above the roughly 357,000
that the largest legitimate report costs. A gateway sizes its reports to
its own MTU, not to the relay's, so the cap assumes at least an Ethernet
link so a relay whose own MTU was lowered does not truncate a legitimate
refresh. At the defaults that covers all 32 groups: the previous bound
stays unless that MTU is below 528, which lowers it to no less than the
60,160 that refreshing 32 groups costs. A report larger than the relay's
own MTU, from a gateway on a jumbo link to a relay on a standard one,
has the records past the bound ignored at high limits, as an over-budget
report already does.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 68 +++++++++++++++++++++++++++++++++-------
include/net/amt.h | 9 ++++++
include/uapi/linux/amt.h | 8 +++++
3 files changed, 73 insertions(+), 12 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 125db76e0..b3e43fc1e 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -2157,6 +2157,15 @@ static void amt_igmpv2_leave_handler(struct amt_dev *amt, struct sk_buff *skb,
amt_del_group(amt, gnode);
}
+/* What one source lookup can cost: a miss walks the whole chain of its
+ * bucket, which holds max_sources / hash_buckets entries on average once
+ * the tunnel may hold more sources than the group has buckets.
+ */
+static u32 amt_lookup_cost(const struct amt_dev *amt)
+{
+ return DIV_ROUND_UP(amt->max_sources, amt->hash_buckets);
+}
+
/* The source-state work one group record can cause: AMT_REC_WALKS passes
* over the group's buckets and sources, which add_srcs may grow by nsrcs,
* plus AMT_REC_LOOKUPS hash lookups per record source.
@@ -2164,21 +2173,45 @@ static void amt_igmpv2_leave_handler(struct amt_dev *amt, struct sk_buff *skb,
static u64 amt_rec_cost(const struct amt_dev *amt, u32 nr_sources, u16 nsrcs)
{
return (u64)AMT_REC_WALKS * (amt->hash_buckets + nr_sources + nsrcs) +
- (u64)AMT_REC_LOOKUPS * nsrcs;
+ (u64)AMT_REC_LOOKUPS * amt_lookup_cost(amt) * nsrcs;
+}
+
+/* The work of a report naming @recs groups, each walked in full, plus two
+ * passes over every source the tunnel may hold and @lookups source lookups.
+ */
+static u64 amt_report_cost(const struct amt_dev *amt, u64 recs, u64 lookups)
+{
+ return (u64)AMT_REC_WALKS *
+ (recs * amt->hash_buckets + 2 * (u64)amt->max_sources) +
+ (u64)AMT_REC_LOOKUPS * amt_lookup_cost(amt) * lookups;
}
-/* The most work one Membership Update may cause: twice what refreshing
- * every group the tunnel may hold, with every source, costs. The packet
- * length used to be the only bound, and a report that names one full
- * group many times costs far more than one that refreshes the whole
- * tunnel.
+/* The most work one Membership Update may cause. The packet length used
+ * to be the only bound, and a report that names one full group many times
+ * costs far more than one that refreshes the whole tunnel.
+ *
+ * Twice what refreshing every group the tunnel may hold costs, but never
+ * more than a report as large as this device's MTU can legitimately cost:
+ * a host splits its report to the MTU (RFC 3376 s4.2.16, RFC 3810
+ * s5.2.15), so one report names at most mtu / 8 groups, IGMPv3 records
+ * being the smallest, or mtu / 4 sources. The second bound is what limits
+ * the work at high IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES; at the
+ * defaults the first is the smaller, unless the device's MTU is below 528.
+ * A gateway sizes its reports to its own MTU, not to this device's, so the
+ * second bound assumes at least an Ethernet link: it never covers fewer
+ * than min(max_groups, 187) groups.
*/
static u64 amt_report_budget(const struct amt_dev *amt)
{
- return 2 * ((u64)AMT_REC_WALKS *
- ((u64)amt->max_groups * amt->hash_buckets +
- 2 * amt->max_sources) +
- (u64)AMT_REC_LOOKUPS * amt->max_sources);
+ u64 mtu = max_t(u64, READ_ONCE(amt->dev->mtu), ETH_DATA_LEN);
+ u64 recs = max_t(u64, READ_ONCE(amt->dev->mtu) /
+ sizeof(struct igmpv3_grec),
+ min_t(u32, amt->max_groups,
+ ETH_DATA_LEN / sizeof(struct igmpv3_grec)));
+ u64 srcs = min_t(u64, amt->max_sources, mtu / sizeof(__be32));
+
+ return min(2 * amt_report_cost(amt, amt->max_groups, amt->max_sources),
+ amt_report_cost(amt, recs, srcs));
}
static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
@@ -3599,6 +3632,7 @@ static void amt_link_setup(struct net_device *dev)
}
static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
+ [IFLA_AMT_UNSPEC] = { .strict_start_type = IFLA_AMT_MAX_GROUPS },
[IFLA_AMT_MODE] = { .type = NLA_U32 },
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
@@ -3607,6 +3641,8 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
[IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
+ [IFLA_AMT_MAX_GROUPS] = NLA_POLICY_MAX(NLA_U32, AMT_MAX_GROUP_LIMIT),
+ [IFLA_AMT_MAX_SOURCES] = NLA_POLICY_MAX(NLA_U32, AMT_MAX_SOURCE_LIMIT),
};
static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -3673,8 +3709,10 @@ static int amt_newlink(struct net_device *dev,
spin_lock_init(&amt->lock);
seqcount_spinlock_init(&amt->key_seq, &amt->lock);
- amt->max_groups = AMT_MAX_GROUP;
- amt->max_sources = AMT_MAX_SOURCE;
+ amt->max_groups = nla_get_u32_default(data[IFLA_AMT_MAX_GROUPS], 0) ?:
+ AMT_MAX_GROUP;
+ amt->max_sources = nla_get_u32_default(data[IFLA_AMT_MAX_SOURCES], 0) ?:
+ AMT_MAX_SOURCE;
amt->hash_buckets = AMT_HSIZE;
amt->nr_tunnels = 0;
get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed));
@@ -3790,6 +3828,8 @@ static size_t amt_get_size(const struct net_device *dev)
nla_total_size(sizeof(__u16)) + /* IFLA_AMT_GATEWAY_PORT */
nla_total_size(sizeof(__u32)) + /* IFLA_AMT_LINK */
nla_total_size(sizeof(__u32)) + /* IFLA_MAX_TUNNELS */
+ nla_total_size(sizeof(__u32)) + /* IFLA_AMT_MAX_GROUPS */
+ nla_total_size(sizeof(__u32)) + /* IFLA_AMT_MAX_SOURCES */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_DISCOVERY_IP */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_REMOTE_IP */
nla_total_size(sizeof(__be32)); /* IFLA_AMT_LOCAL_IP */
@@ -3820,6 +3860,10 @@ static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_AMT_MAX_TUNNELS, amt->max_tunnels))
goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_AMT_MAX_GROUPS, amt->max_groups))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_AMT_MAX_SOURCES, amt->max_sources))
+ goto nla_put_failure;
rcu_read_unlock();
return 0;
diff --git a/include/net/amt.h b/include/net/amt.h
index f4ccc871c..f1a2293bf 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -392,6 +392,15 @@ struct amt_dev {
#define AMT_GC_KICK 2048
#define AMT_MAX_GROUP 32
#define AMT_MAX_SOURCE 128
+/* Upper bounds for IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES. Gateways
+ * drive these allocations: at the bounds one tunnel holds about 2 MiB of
+ * group nodes (each a kmalloc-4k object with AMT_HSIZE bucket heads) and
+ * under 1 MiB of source nodes, and max_tunnels multiplies that. The work
+ * one Membership Update may cause is bounded separately, by
+ * amt_report_budget().
+ */
+#define AMT_MAX_GROUP_LIMIT 512
+#define AMT_MAX_SOURCE_LIMIT 4096
/* Per group record, an upper bound on the passes the mode handlers plus
* amt_cleanup_srcs() make over a group's buckets and sources, and on the
* hash lookups they make per record source. The handlers need at most 5
diff --git a/include/uapi/linux/amt.h b/include/uapi/linux/amt.h
index 2dccff417..a106d7a07 100644
--- a/include/uapi/linux/amt.h
+++ b/include/uapi/linux/amt.h
@@ -54,6 +54,14 @@ enum {
IFLA_AMT_DISCOVERY_IP,
/* This attribute specify number of maximum tunnel. */
IFLA_AMT_MAX_TUNNELS,
+ /* Maximum number of group records one tunnel may hold.
+ * Zero or absent means the default of 32.
+ */
+ IFLA_AMT_MAX_GROUPS,
+ /* Maximum number of source records one tunnel may hold, counted
+ * across all of its groups. Zero or absent means the default of 128.
+ */
+ IFLA_AMT_MAX_SOURCES,
__IFLA_AMT_MAX,
};
prev parent reply other threads:[~2026-11-30 9:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:50 [PATCH net-next v5 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-30 9:50 ` [PATCH net-next v5 1/3] amt: make the A-B source walk linear Omar Ramadan
2026-11-30 9:50 ` [PATCH net-next v5 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-30 9:50 ` Omar Ramadan [this message]
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=20261130095059.1301582-4-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 \
--cc=willemb@google.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
all inboxes | Powered by JetHome®