mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v4 0/3] amt: configurable per-tunnel limits, with bounded report work
Date: Tue, 24 Nov 2026 21:04:58 +0000	[thread overview]
Message-ID: <20261124210501.70394-1-omar@blockcast.net> (raw)

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 series 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 group ceiling lowered from 1024 to 512. The hashes
    keep their 256 buckets, so one tunnel at the ceilings holds about
    2.75 MiB [estimated, from pahole sizes]. Since twice a full refresh
    grows with the limits, it also caps the budget of 2/3 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.

The work one Membership Update may cause, in bucket and source visits
[estimated, from the code], at 32 groups / 128 sources and at the
ceilings of 512 groups / 4096 sources:

                          defaults    ceilings
  v3                       120,320   3,850,240
  this version             120,320     416,256 (1500-byte stream link)

The largest legitimate report at the ceilings, on that link, costs
about 348,000.

Measured cost of one Membership Update under tunnel->lock, in a UML
guest (KASAN off, so slower than native; compare the columns only), with
the relay at the ceilings. v3 and this version were built from the same
base and booted alternately on one machine, five rounds each
[measured]:

  one Update, relay at the ceilings           v3, ms        v4, ms
  attack, stream MTU 1500 (64 KiB of empty
  records naming one 4,096-source group)      8.2 - 8.9     1.3 - 1.6
    records applied before the budget stops   119           13
  the same attack, stream MTU 65535           8.4 - 8.9     5.3 - 5.7
    records applied                           119           66
  refresh of 512 groups x 8 sources in
  1,400-byte reports, slowest report          0.14 - 0.15   0.11 - 0.13
  the same refresh in one 64 KiB report       1.5           1.1 - 1.2

Without 2/3 (v2), the attack report held tunnel->lock for about two
seconds (measured for v3's cover letter, on another machine).

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 is in net-next; 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 budget is covered by
the measurements above. Each patch builds with W=1 C=1, with IPv6=y and
IPv6=n, with no warnings in amt. pahole gives 200 bytes for
amt_group_node and 168 for amt_tunnel_list, so with 256 bucket heads
both stay within 4 KiB.

[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/
[4] https://lore.kernel.org/netdev/179547826432.3135.16263442399696125291@kernel.org/

v4:
- 3/3: keep hash_buckets at AMT_HSIZE (256). Growing it to 512 put
  every group and tunnel node in kmalloc-8k and doubled their memory [4].
- 3/3: cap the 2/3 budget at the cost of one MTU-sized report. At the
  ceilings v3 allowed 3.85M visits per Update, 32 times the default [4].
- 2/3: AMT_REC_WALKS and AMT_REC_LOOKUPS are an upper bound, not the
  exact maxima; say so (Sashiko).
v3: https://lore.kernel.org/netdev/20261122235724.2898320-1-omar@blockcast.net/
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        | 127 ++++++++++++++++++++++++++++++++-------
 include/net/amt.h        |  19 ++++++
 include/uapi/linux/amt.h |   8 +++
 3 files changed, 131 insertions(+), 23 deletions(-)


base-commit: 24630ff92eff08500ec4772728d4b1fa08c28f47
-- 
2.43.0


             reply	other threads:[~2026-11-24 21:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 21:04 Omar Ramadan [this message]
2026-11-24 21:04 ` [PATCH net-next v4 1/3] amt: make the A-B source walk linear Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 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=20261124210501.70394-1-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

all inboxes | Powered by JetHome®