Re: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable
From: netdev-bot+sashiko
Date: Mon Nov 23 2026 - 18:57:50 EST
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