* [PATCH net-next v3 0/3] amt: configurable per-tunnel limits, with bounded report work
@ 2026-11-22 23:57 Omar Ramadan
2026-11-22 23:57 ` [PATCH net-next v3 1/3] amt: make the A-B source walk linear Omar Ramadan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Omar Ramadan @ 2026-11-22 23:57 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
A relay caps one gateway tunnel at 32 group and 128 source records, both
compile-time constants. v2 made them configurable [1]. Sashiko and Paolo
pointed out that at the new ceilings a single Membership Update can
livelock the host: records are applied under tunnel->lock in softirq,
and only the packet length bounds them [2].
This version keeps the processing in the RX path and bounds it instead:
1/3 makes the A-B case of amt_lookup_act_srcs() linear. It used to
compare every source in the group with every source in the record.
2/3 charges every group record for the passes it makes over its group
and stops applying records once a report exceeds twice the cost of
refreshing the tunnel's whole state. A record for a group the
tunnel has no room for does no walk and is not charged, so a host
joined to more groups than max_groups keeps its refreshes.
3/3 is v2, with the source hash sized from max_sources and the group
ceiling lowered from 1024 to 512, which keeps one tunnel's worst
case at about 4.75 MiB.
Measured cost of one Membership Update, in a UML guest (KASAN off, so
these are slower than native and only comparable with each other), at
the ceilings, three runs each. These were taken on 734bef548a96 with
v5 of the net series (an earlier version of [3]), before this series
was rebased onto net-next, and with an earlier 2/3 that also charged
records the tunnel refuses, a path neither row reaches. They have not
been re-run since [measured]:
report v2 ceilings this series
512 groups x 8 sources, full refresh 5.0 - 11.9 ms 4.9 - 10.3 ms
~7,500 empty records naming one group
that holds 4,096 sources (64 KiB) 1.74 - 2.32 s 26 - 45 ms
The second row is the livelock: one datagram held tunnel->lock for about
two seconds. With 2/3 the report stops after its budget of 3.85M bucket
and source visits [estimated, from the code], about 120K at the default
limits. I did not manage to drive the quadratic A-B walk itself into a
measurement; its old worst case is |A| x |B|, up to 4,096 x 14,998
compares for one record [estimated].
Deferring report processing to a per-tunnel work item would also take
the work out of softirq. I have not done that here: with the work
bounded, the deferral would add a queue and its own limits without
changing the worst case much. Happy to do it if you prefer.
This depends on the net series "amt: relay tunnel lifetime, validation
and request-path hardening" [3], which fixes the source-timer vs.
teardown race Sashiko also flagged: 3/3 touches amt_newlink() next to
a line that series adds. That series is now in net-next, and this is
based on 24630ff92eff, the net-next merge of net that brought it in.
Testing: tools/testing/selftests/net/amt.sh, unmodified, on net-next
24630ff92eff with this series applied, x86_64 under virtme-ng/KVM (4
vCPUs, 4 GiB) with generic KASAN (inline), PROVE_LOCKING, PROVE_RCU and
AMT=y: all six tests pass, amt.sh exits 0, and no KASAN, lockdep or
WARNING report appeared during the run. amt.sh does not reach the new
limits, so this covers the normal paths only; the over-budget path of
2/3 is covered only by the measurements above, taken before the rebase.
Each patch builds with W=1 C=1, with IPv6=y and IPv6=n, with no new
warnings.
[1] https://lore.kernel.org/netdev/20261015231825.2852054-1-omar@blockcast.net/
[2] https://lore.kernel.org/netdev/361bbccf-6ce7-4b1f-bd55-4d8270423320@redhat.com/
[3] https://lore.kernel.org/netdev/20261110210538.217936-1-omar@blockcast.net/
v3:
- New 1/3 and 2/3.
- Based on net-next after the net series [3] was merged; 3/3 rebased
onto it.
- 3/3: size hash_buckets from max_sources, at most 8 sources per
bucket, 256..512; lower AMT_MAX_GROUP_LIMIT from 1024 to 512.
v2: https://lore.kernel.org/netdev/20261015231825.2852054-1-omar@blockcast.net/
v1: https://lore.kernel.org/netdev/20261014221334.2443184-1-omar@blockcast.net/
Assisted-by: LLM
Omar Ramadan (3):
amt: make the A-B source walk linear
amt: bound the source-state work of one Membership Update
amt: make the per-tunnel group and source limits configurable
drivers/net/amt.c | 118 +++++++++++++++++++++++++++++++--------
include/net/amt.h | 15 +++++
include/uapi/linux/amt.h | 8 +++
3 files changed, 117 insertions(+), 24 deletions(-)
base-commit: 24630ff92eff08500ec4772728d4b1fa08c28f47
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v3 1/3] amt: make the A-B source walk linear
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
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
2 siblings, 0 replies; 7+ messages in thread
From: Omar Ramadan @ 2026-11-22 23:57 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v3 2/3] amt: bound the source-state work of one Membership Update
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 ` [PATCH net-next v3 1/3] amt: make the A-B source walk linear Omar Ramadan
@ 2026-11-22 23:57 ` Omar Ramadan
2026-11-23 23:57 ` netdev-bot+sashiko
2026-11-22 23:57 ` [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
2 siblings, 1 reply; 7+ messages in thread
From: Omar Ramadan @ 2026-11-22 23:57 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
The relay applies every group record in a Membership Update under
tunnel->lock in softirq, and ip_mc_may_pull() is the only bound on how
many records it applies. Each record walks its group's hash buckets and
sources several times, so a report that names the same full group in
many short records costs far more than one that refreshes the whole
tunnel. At the current defaults a 1.5 KB Update of about 180 empty
records against one group already walks the group's 256 buckets over a
thousand times.
Charge each record for the passes the mode handlers and
amt_cleanup_srcs() make over its group and for its per-source lookups,
and stop applying records once the total exceeds twice what refreshing
every group the tunnel may hold, with every source, would cost. A report
that refreshes the tunnel's whole state uses half the budget; one that
exceeds it is truncated, as a lost report would be, and the next
periodic report restores the state. A record for a group the tunnel has
no room for does no walk and is not charged, so records the relay
refuses cannot use up the budget and truncate the same records from
every report.
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 | 54 +++++++++++++++++++++++++++++++++++++++++++++++
include/net/amt.h | 6 ++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 79d68bcc7..177bc0b7c 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -2157,6 +2157,30 @@ static void amt_igmpv2_leave_handler(struct amt_dev *amt, struct sk_buff *skb,
amt_del_group(amt, gnode);
}
+/* 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.
+ */
+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;
+}
+
+/* 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.
+ */
+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);
+}
+
static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
struct amt_tunnel_list *tunnel)
{
@@ -2167,6 +2191,7 @@ static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
union amt_addr group, host;
struct igmpv3_grec *grec;
__be32 saddr;
+ u64 budget = amt_report_budget(amt), work = 0;
u16 nsrcs;
u16 ngrec;
int i;
@@ -2194,6 +2219,20 @@ static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
memset(&host, 0, sizeof(union amt_addr));
host.ip4 = saddr;
gnode = amt_lookup_group(tunnel, &group, &host, false);
+ /* A record for a group the tunnel has no room for does no
+ * walk, so it is not charged. Charging it would let a host
+ * joined to more than max_groups groups lose the same tail
+ * records from every report.
+ */
+ if (!gnode && tunnel->nr_groups >= amt->max_groups)
+ continue;
+ work += amt_rec_cost(amt, gnode ? gnode->nr_sources : 0, nsrcs);
+ if (work > budget) {
+ netdev_dbg(amt->dev,
+ "Membership Update over work budget, %u of %u records ignored\n",
+ ngrec - i, ngrec);
+ break;
+ }
if (!gnode) {
gnode = amt_add_group(amt, tunnel, &group, &host,
false);
@@ -2335,6 +2374,7 @@ static void amt_mldv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,
union amt_addr group, host;
struct mld2_grec *grec;
struct in6_addr saddr;
+ u64 budget = amt_report_budget(amt), work = 0;
u16 nsrcs;
u16 ngrec;
int i;
@@ -2362,6 +2402,20 @@ static void amt_mldv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,
memset(&host, 0, sizeof(union amt_addr));
host.ip6 = saddr;
gnode = amt_lookup_group(tunnel, &group, &host, true);
+ /* A record for a group the tunnel has no room for does no
+ * walk, so it is not charged. Charging it would let a host
+ * joined to more than max_groups groups lose the same tail
+ * records from every report.
+ */
+ if (!gnode && tunnel->nr_groups >= amt->max_groups)
+ continue;
+ work += amt_rec_cost(amt, gnode ? gnode->nr_sources : 0, nsrcs);
+ if (work > budget) {
+ netdev_dbg(amt->dev,
+ "Membership Update over work budget, %u of %u records ignored\n",
+ ngrec - i, ngrec);
+ break;
+ }
if (!gnode) {
gnode = amt_add_group(amt, tunnel, &group, &host,
ETH_P_IPV6);
diff --git a/include/net/amt.h b/include/net/amt.h
index f36efcdd9..96357b3e3 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -392,6 +392,12 @@ struct amt_dev {
#define AMT_GC_KICK 2048
#define AMT_MAX_GROUP 32
#define AMT_MAX_SOURCE 128
+/* Per group record, the most passes the mode handlers plus
+ * amt_cleanup_srcs() make over a group's sources, and the most hash
+ * lookups they make per record source. See amt_rec_cost().
+ */
+#define AMT_REC_WALKS 7
+#define AMT_REC_LOOKUPS 8
#define AMT_HSIZE_SHIFT 8
#define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable
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 ` [PATCH net-next v3 1/3] amt: make the A-B source walk linear Omar Ramadan
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 ` Omar Ramadan
2026-11-23 23:57 ` netdev-bot+sashiko
2 siblings, 1 reply; 7+ messages in thread
From: Omar Ramadan @ 2026-11-22 23:57 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
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().
Size the group and source hashes from max_sources instead of the fixed
AMT_HSIZE: one group may hold every source of its tunnel, so at 4096
sources 256 buckets would mean chains of 16. Grow hash_buckets to keep
at most eight sources per bucket, from 256 up to 512 at the ceiling.
The defaults are unchanged.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 21 ++++++++++++++++++---
include/net/amt.h | 7 +++++++
include/uapi/linux/amt.h | 8 ++++++++
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 177bc0b7c..01b3a8cab 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -3583,6 +3583,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 },
@@ -3591,6 +3592,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[],
@@ -3657,9 +3660,15 @@ 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->hash_buckets = AMT_HSIZE;
+ 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;
+ /* Keep source chains short when one group holds every source:
+ * at most eight sources per bucket up to AMT_MAX_SOURCE_LIMIT.
+ */
+ amt->hash_buckets = clamp_t(u32, roundup_pow_of_two(amt->max_sources) / 8,
+ AMT_HSIZE, AMT_HSIZE_MAX);
amt->nr_tunnels = 0;
get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed));
amt->stream_dev = dev_get_by_index(link_net,
@@ -3774,6 +3783,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 */
@@ -3804,6 +3815,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 96357b3e3..296570fec 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -392,6 +392,11 @@ 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, so keep one tunnel's worst case to a few MiB.
+ */
+#define AMT_MAX_GROUP_LIMIT 512
+#define AMT_MAX_SOURCE_LIMIT 4096
/* Per group record, the most passes the mode handlers plus
* amt_cleanup_srcs() make over a group's sources, and the most hash
* lookups they make per record source. See amt_rec_cost().
@@ -400,6 +405,8 @@ struct amt_dev {
#define AMT_REC_LOOKUPS 8
#define AMT_HSIZE_SHIFT 8
#define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
+/* hash_buckets grows with max_sources up to this, see amt_newlink(). */
+#define AMT_HSIZE_MAX 512
#define AMT_DISCOVERY_TIMEOUT 5000
#define AMT_INIT_REQ_TIMEOUT 1
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,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 2/3] amt: bound the source-state work of one Membership Update
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-23 23:57 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 23:57 UTC (permalink / raw)
To: omar
Cc: ap420073, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The constants that size the new work budget are documented as
exact maxima, but the code never reaches them.
- [Low] The patch fixes a long-standing CPU amplification but carries no
Fixes: tag.
--
amt: bound the source-state work of one Membership Update
This commit charges each group record in an IGMPv3 or MLDv2 Membership
Update for the bucket walks and per-source lookups it causes. It stops
applying records once the total exceeds twice the cost of refreshing every
group and source the tunnel may hold. Records for groups the tunnel has no
room for are skipped and not charged.
> Found by review (Sashiko, on the limits patch); not triggered at runtime.
>
> Assisted-by: LLM
> Signed-off-by: Omar Ramadan <omar@blockcast.net>
[Severity: Low]
Should this patch carry a Fixes: tag?
Before this patch, ip_mc_may_pull() was the only limit on how many records
amt_igmpv3_report_handler() and amt_mldv2_report_handler() applied under
tunnel->lock in softirq. A reassembled UDP Update of up to about 64 KB can
carry thousands of 8-byte records against one full group.
That behaviour seems to go back to bc54e49c140b ("amt: add multicast(IGMP)
report message handler") and the matching MLDv2 report handler commit.
An earlier fix in this area, 5931fd2440de ("amt: fix use-after-free when a
Membership Update re-arms a freed tunnel"), also addressed a theoretical
issue. It carries Fixes: tags against bc54e49c140b and cbc21dc1cfe9. With no
tag here, backport tooling can't tell which trees need this limit.
The "on the limits patch" note seems to refer to a later patch in this
series, "amt: make the per-tunnel group and source limits configurable".
That note does not take the place of a Fixes: tag. The series adds UAPI, so
it may be net-next material either way, and this could be treated as
hardening.
[ ... ]
> diff --git a/include/net/amt.h b/include/net/amt.h
> index f36efcdd92d0b..96357b3e32fc9 100644
> --- a/include/net/amt.h
> +++ b/include/net/amt.h
> @@ -392,6 +392,12 @@ struct amt_dev {
> #define AMT_GC_KICK 2048
> #define AMT_MAX_GROUP 32
> #define AMT_MAX_SOURCE 128
> +/* Per group record, the most passes the mode handlers plus
> + * amt_cleanup_srcs() make over a group's sources, and the most hash
> + * lookups they make per record source. See amt_rec_cost().
> + */
> +#define AMT_REC_WALKS 7
> +#define AMT_REC_LOOKUPS 8
[Severity: Low]
Are 7 and 8 really the maximum counts this comment describes?
In amt_lookup_act_srcs(), only AMT_OPS_UNI and AMT_OPS_SUB walk every bucket
of gnode->sources[]. AMT_OPS_INT does one amt_lookup_src() per record
source, and AMT_OPS_SUB_REV does up to two.
The most full passes seem to come from amt_mcast_to_in_handler() in EXCLUDE
mode, which makes three AMT_OPS_UNI calls:
drivers/net/amt.c:amt_mcast_to_in_handler() {
...
} else {
amt_lookup_act_srcs(tunnel, gnode, grec, AMT_OPS_UNI,
AMT_FILTER_NONE_NEW, ...
amt_lookup_act_srcs(tunnel, gnode, grec, AMT_OPS_UNI,
AMT_FILTER_FWD, ...
amt_lookup_act_srcs(tunnel, gnode, zero_grec, AMT_OPS_UNI,
AMT_FILTER_D_FWD, ...
amt_lookup_act_srcs(tunnel, gnode, grec, AMT_OPS_INT,
AMT_FILTER_FWD_NEW, ...
}
}
The two bucket loops in amt_cleanup_srcs() bring that to 5 passes.
The most lookups per source seem to come from amt_mcast_block_handler() in
EXCLUDE mode. That is SUB_REV (2) + UNI (1) + SUB_REV (2) + UNI (1) = 6,
plus one in amt_add_srcs(), for 7. amt_act_src() starts no further walks.
The commit message figure also seems to rely on the higher pass count:
"At the current defaults a 1.5 KB Update of about 180 empty records
against one group already walks the group's 256 buckets over a thousand
times."
At 5 passes per record, that would be about 178 x 5, or roughly 890.
amt_rec_cost() and amt_report_budget() use the same constants, so behaviour
does not change and the budget is still conservative.
Should the constants be 5 and 7? Or should the comment say they are
deliberately rounded-up bounds? The later patch "amt: make the per-tunnel
group and source limits configurable" leaves both constants and their
comment unchanged.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122235724.2898320-1-omar%40blockcast.net
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable
2026-11-22 23:57 ` [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
@ 2026-11-23 23:57 ` netdev-bot+sashiko
2026-11-24 7:25 ` Omar Ramadan
0 siblings, 1 reply; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 23:57 UTC (permalink / raw)
To: omar
Cc: ap420073, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new IFLA_AMT_MAX_GROUPS/IFLA_AMT_MAX_SOURCES ceilings,
together with the automatic growth of hash_buckets from max_sources in…
- [Medium] When max_sources > 2048, amt_newlink() sets hash_buckets to
AMT_HSIZE_MAX (512).
--
amt: make the per-tunnel group and source limits configurable
This adds IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES so a relay operator
can raise the per-tunnel group and source limits, capped at 512 and 4096.
It also sizes the group and source hashes from max_sources, growing
hash_buckets from 256 up to 512, and reports both limits in
amt_fill_info().
> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 177bc0b7cb1fd..01b3a8cabef37 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c
[ ... ]
> @@ -3657,9 +3660,15 @@ 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->hash_buckets = AMT_HSIZE;
> + 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;
> + /* Keep source chains short when one group holds every source:
> + * at most eight sources per bucket up to AMT_MAX_SOURCE_LIMIT.
> + */
> + amt->hash_buckets = clamp_t(u32, roundup_pow_of_two(amt->max_sources) / 8,
> + AMT_HSIZE, AMT_HSIZE_MAX);
[Severity: Medium]
Do these new ceilings also raise the per-packet work a remote gateway can
cause under tunnel->lock by roughly 32x?
amt_report_budget() scales with max_groups * hash_buckets:
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);
}
At the defaults (32 groups, 128 sources, 256 buckets) this comes to
120,320 units. At the new ceilings (512 groups, 4096 sources,
hash_buckets clamped to AMT_HSIZE_MAX) it comes to 3,850,240.
The charge from amt_rec_cost() matches real work. Every record, even one
for an empty group, pays AMT_REC_WALKS * hash_buckets. amt_cleanup_srcs()
walks every bucket of gnode->sources twice, and the UNI/SUB paths of
amt_lookup_act_srcs() walk them again.
All of this runs in softirq with the tunnel lock held:
amt_rcv()
amt_update_handler()
amt_update_tunnel()
spin_lock_bh(&tunnel->lock)
amt_igmp_report_handler() / amt_mld_report_handler()
Once a relay is created with limits near 512/4096, any remote host that
completes the Request/Query/Update handshake can send Membership Updates
whose records keep naming existing, even empty, groups. Each such packet
can then use the whole budget walking bucket heads.
Could that hold the BH-disabled lock for milliseconds per packet? While
it is held, amt_source_work, amt_group_work, amt_tunnel_expire and
amt_dev_stop would spin on it.
Teardown grows the same way. amt_clear_groups() is called from
amt_tunnel_expire() with amt->lock held. Through amt_del_group() it walks
about max_groups * hash_buckets = 262,144 bucket heads under
spin_lock_bh(&tunnel->lock).
The AMT_MAX_GROUP_LIMIT comment and the commit message justify the caps
only by memory ("keep one tunnel's worst case to a few MiB"). Should
these ceilings also account for the CPU and lock-hold bound that
amt_report_budget() is meant to limit?
> amt->nr_tunnels = 0;
> get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed));
> amt->stream_dev = dev_get_by_index(link_net,
[ ... ]
> diff --git a/include/net/amt.h b/include/net/amt.h
> index 96357b3e32fc9..296570feccef9 100644
> --- a/include/net/amt.h
> +++ b/include/net/amt.h
> @@ -392,6 +392,11 @@ 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, so keep one tunnel's worst case to a few MiB.
> + */
> +#define AMT_MAX_GROUP_LIMIT 512
> +#define AMT_MAX_SOURCE_LIMIT 4096
[ ... ]
> @@ -400,6 +405,8 @@ struct amt_dev {
> #define AMT_REC_LOOKUPS 8
> #define AMT_HSIZE_SHIFT 8
> #define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
> +/* hash_buckets grows with max_sources up to this, see amt_newlink(). */
> +#define AMT_HSIZE_MAX 512
[Severity: Medium]
With hash_buckets at AMT_HSIZE_MAX, do the per-group and per-tunnel
allocations end up just over 4 KiB?
amt_add_group() allocates:
gnode = kzalloc(sizeof(*gnode) +
(sizeof(struct hlist_head) * amt->hash_buckets),
GFP_ATOMIC);
struct amt_group_node is about 200 bytes on 64-bit. With 512 buckets
the request is about 4296 bytes and comes from kmalloc-8k. With 256
buckets it was about 2248 bytes and fit in kmalloc-4k.
amt_tunnel_get_or_create() uses the same layout for the tunnel and rounds
up the same way.
So once max_sources is above 2048, the bucket scaling alone doubles
per-group slab memory: 512 groups * 8 KiB = 4 MiB per tunnel, against
2 MiB. Every group's source table is sized from the tunnel-wide
max_sources, so a group holding a single source still gets 512 heads.
reciprocal_scale() does not need a power of two. Would a bucket count of
around 480, which keeps the node within 4 KiB, work here instead?
These GFP_ATOMIC allocations are driven by remote gateways in softirq,
are not memcg charged, and are bounded per device only by max_tunnels.
max_tunnels defaults to 128 and is an unbounded NLA_U32.
The worst case is roughly 128 * (4 MiB of groups + about 0.75 MiB of
sources), around 600 MiB per AMT device. Nodes parked on the GC lists
are not counted against max_groups/max_sources, so transient use can be
higher.
kmalloc-8k objects also need at least an order-1 page, while kmalloc-4k
can fall back to order-0. Under fragmentation these atomic allocations,
and the joins that depend on them, are therefore a bit more likely to
fail.
Is "a few MiB" in the comment above still accurate once slab rounding
and the number of tunnels per device are counted?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122235724.2898320-1-omar%40blockcast.net
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable
2026-11-23 23:57 ` netdev-bot+sashiko
@ 2026-11-24 7:25 ` Omar Ramadan
0 siblings, 0 replies; 7+ messages in thread
From: Omar Ramadan @ 2026-11-24 7:25 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: ap420073, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms
On Mon, 23 Nov 2026 23:57:44 +0000, netdev-bot+sashiko@kernel.org wrote:
> Do these new ceilings also raise the per-packet work a remote gateway can
> cause under tunnel->lock by roughly 32x?
Yes. At 512 groups and 4096 sources the budget of 2/3 allowed 3,850,240
bucket and source visits per Update, 32 times the 120,320 at the
defaults, and the caps were argued from memory only.
v4 caps the budget at what one report as large as the device's MTU can
cost: a host splits its report to the MTU, so a report names at most
mtu / 8 groups. On a 1500-byte stream link (relay MTU 1460) that is
416,256 visits at the ceilings, 3.5 times the default; the largest
legitimate report there costs about 348,000. The defaults keep the 120,320. 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; the commit message says so.
Measured in a UML guest (KASAN off, so only the ratio means anything),
v3 and v4 booted alternately on one machine, at the ceilings: the
report you describe, ~7,500 empty records naming one group that holds
4,096 sources, takes 8.2-8.9 ms in v3 and 1.3-1.6 ms in v4 on a
1500-byte stream link (119 records applied against 13), and 5.3-5.7 ms
with the stream link at 65535. A full refresh is not slower.
Teardown at the ceilings walks 512 * 256 bucket heads in v4, once per
tunnel.
> With hash_buckets at AMT_HSIZE_MAX, do the per-group and per-tunnel
> allocations end up just over 4 KiB?
Yes. v4 keeps hash_buckets at AMT_HSIZE (256): pahole gives 200 bytes
for amt_group_node and 168 for amt_tunnel_list, so with 256 heads both
stay in kmalloc-4k. At 4096 sources in one group a chain averages 16
entries, which only makes a lookup longer. One tunnel at the ceilings
then holds about 2 MiB of group nodes and 0.75 MiB of source nodes, and
max_tunnels multiplies that; v4's comment on the caps says so instead
of "a few MiB".
I will send v4.
pw-bot: cr
--
Omar
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 7:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net-next v3 1/3] amt: make the A-B source walk linear Omar Ramadan
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-23 23:57 ` netdev-bot+sashiko
2026-11-22 23:57 ` [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
2026-11-23 23:57 ` netdev-bot+sashiko
2026-11-24 7:25 ` Omar Ramadan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox