🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21378

Re: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable

#21378
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 23:57
173 lines
14560 bytes
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
Technical Details
Message-ID: <179547826432.3135.16263442399696125291@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369851-linux-kernel-netdev=dewy.ru
References: <20261122235724.2898320-4-omar@blockcast.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369851-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source
 limits configurable
Date: Mon, 23 Nov 2026 23:57:44 +0000
Organization: Usenet Network
Message-ID: <179547826432.3135.16263442399696125291@kernel.org>
References: <20261122235724.2898320-4-omar@blockcast.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4011036"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:46L6oIz8kVwJQwO07CbLWesIJUY= sha256:TgQtIDbn0DLFI+pegLGWippXBpfTTy5W2xNmrArUkH8=
	sha1:NKAi+UoU+j+n/VWgmeYGM0y/8eg= sha256:GZPOxg16H/hHH0TzKRJBGmWq5HSHNl2MNUaJwbTLkeQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CB948125DCA; Tue, 24 Nov 2026 02:58:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id GanPW6S1yjoC;
	Tue, 24 Nov 2026 02:58:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369851-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E3275125DC9; Tue, 24 Nov 2026 02:58:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id D27AF32A80; Mon, 23 Nov 2026 23:57:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795478271;
	b=wkjtSJMos1AnLKM0DhPlVjmaQestfVLrMmR+X08fwUiVEVi/P0PSl/xLahdTiWkKVQNQ
	 So/j/56gwd9Zi6DKpemzITgmxqlaTALcdXkRLqfbdoYEyaQlkjPf5XbG3pDUiUeTJUpzK
	 r7aGsA647bGirBcrZVqmWgk3Xp9wj+54HiIrSm9u6Gua2jNoCLTT5qLdM8jC9L4nF4hHc
	 5jTNAfveRJ2m54Oe9eZr6z2NwQb7jH5zVWo3HpLXSUtfpwf198tY/MsZj22bbMZ/jZgZY
	 GCsL88hMfVjbwBkVx22fa/CplaeideFBCSKQLwgp0+ZBrgpx/H6FK0Jg4rHQYXl6uUg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795478271;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=2pNP0xtV5aWCIviAsDqRtjaXnEC3csJaqGq9fEWnUoQ=;
	b=EtuEmmJaCEfPbA+kyNF5pQcX0Iy8MfwnrgRUh2+ll0iLNC/IByHjUybVLvwgrypw03OF
	 h/knaiypF/yFHipEXZ/XHWMRrFio/9zGV/+XwamIVbSmi1x1eW76wmFGTlBIzyXfEG8QQ
	 DYDe1INjhaU7Bnddql+JLd+/XW5zQGpLI/30E9ZnSHzKQUQR6G4enAqiJU4yCfQpNOWBF
	 kml8NwP+3ytIpbRU27Yyumxb2/rnrLCPTSA/qsSjnrpn9z19NKjfPd2M10fyjJGhOP0zI
	 UY+FpsHoJ4z/HeVXeukWLEmJ8l5xmd0qIDFkMFSn5t8jsqvzdXPZGYpjpl7rnd8L7Jg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HiIOp2m9;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 96E8A606A31E;
	Mon, 23 Nov 2026 23:57:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HiIOp2m9
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795478265;
	b=CpptuiKlASRgSl4HKxKO8dI6oW+71y0eUt+iBmBYfZ+i3czg0Y0cb6GP7Q5EpSkRN217
	 l2FDGj6P2a5TSsqUfA+JmK3BdNh/qsYyw+FvDnEWwbJXhgtjpcDexAy/4UfebnZMCTGmO
	 ZkOkirX56yrsHY4iG/jyTWD1pHaNesJd5cphoJSY1qWSbC1cTebliiu/c7/n+Ztn/RIt7
	 KKaNgrHB9i5b/pw0JhMsKg5ZrN8Q76o6kg4tsxc7gmB2wg9GKjUgN6Dx2oKX+yMBX3zS0
	 i+SW44N7v2yiu/4swOrJyz04Ov3EzF9nYUHNJhlENh4X3qyUx6nTCrIxoQCmvBCk/9w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795478265;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=2pNP0xtV5aWCIviAsDqRtjaXnEC3csJaqGq9fEWnUoQ=;
	b=vPiQV2/BBlyp+tILopDOYBCYL+/zaSAEv/0/5a0NaD5knmwSWZFgbqu/MWWesCenGors
	 n5Ik5vOwemItJfKpnStl/GVejCzLrWkK4aCgrMN3+uJwQckhFb/OPZIoM52XqoHZqGjKP
	 5+4f5nIgAfVDEpfGhLcMGCuRamqBDhyhTmFn9JWMkR//h9o4x/FvOusQ4bqxrsUDgmue3
	 QC82BR7Bq5ZOlD32oYR2FVJl9lolXuTVtdtxbujKBqk0VxPrFaQFYupgimFNp3gJHtMwt
	 gawJk6IVm+MWxviBpHTyPnJzN3AZwN8dv1W3ccHPIyWQlAL7plbYG+QKarVoWmpQYpg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HiIOp2m9;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B71DF606A32D;
	Mon, 23 Nov 2026 23:57:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C21151F000CF;
	Mon, 23 Nov 2026 23:57:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795478265;
	bh=2pNP0xtV5aWCIviAsDqRtjaXnEC3csJaqGq9fEWnUoQ=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=HiIOp2m92zZVi8i8k0xVdMxuWNaLj5PDR3caWsrVbY+wpIblim7VYqGBfCFaJIf2e
	 lsidAgvvbq74a06buReUuU+ssF5FIMh1Pb/NE8yArkTNjVvigamA28wYXZSwz/BR9U
	 WlkUfed8Sz731n/7RRGItqs9i3EwbUwqhi/BGmSTMOYLnNWK6v3TkWXxNRt6mNJpgx
	 MY98XuwQ5eA7Jaxn8bi3r+ptKr1rXQ9BVZhahi7fvdT0HSJjn6o50KkMj2QGC9G3E+
	 pYgZJ95iCSMt/8BJxgNMLm3q597hc/rWr6m0+MWscHvhgPX3EONND5pj8A0/gPrzl6
	 dDPiMoI2GzU+w==
X-Cc: ap420073@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org
X-In-Reply-To: <20261122235724.2898320-4-omar@blockcast.net>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list