From nobody Tue Nov 24 11:17:54 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795391851; b=OIS0j1Kf5OPMOyjM4waH5V2HDtkAFAVcQJO+V+eoFKIjtYwZKAs+iVlvtXEbkCBE7MlR HgJOoj8ruNAs9B8f/PgcZPXAs/5RB1pUt1bHi1k5P1ylzYW9aUX1vftOuL6uzC/89InpQ tP9xGr4pz4BGR2Z3XbnlkXKcB2iL7FVOfyW5fPc/TqR6VJ17W8OgtE0fPTL63kalg3Lu5 8oEuSDqgq9q1xqNDyQd+RbMvCVVoZsj3wWW59urpyCupz2uVhvery3RSpRx5oSBpMWSt5 VLm8FKHQrXJNAHpf/T+VsusSXdJ7H+dVGmMqLSRFFjHXZUJ4PxXXfrnjux6nZgVgklQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795391851; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=3ZhQvCCp11cyui2gzdA+4jeQS6r4tc4Xix/KVK/fQc0=; b=efmNN46FADxG7tbICGR1yTn/JyrfWlYmB4zn0WMd1uZAOwHchxER7X4Hwu12T8INJG3L w5dq8FfR6c9SluPiQhpKs4Dz9ZewgvtTYYbb10JDai9pSxPR50J6SW+VhslrjStVJdxCg rmQTR7Tazas8Tkeu1wuZVa6RiFOAEKuQxAu7R3y3AbWgtnZVnp9hBb3ya8/ETYWJ4By1S UfQzzE146Iz37A9n9xpqpUNzwwkxULv6mB7o3RYjpBnxeKZys79ca/I44ho4Su+VAiwlD 0QGqqdnX25LdYUn1qeMM02nJ38o/dBym0N4YeYwjb2lS98zWuKzcbe663rbKEG9z+ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b="I3i/PlYm"; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F8AD606A337 for ; Sun, 22 Nov 2026 23:57:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4F8AD606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=I3i/PlYm Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-386ab9ab619so1134801eec.1 for ; Sun, 22 Nov 2026 15:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1795391850; x=1795996650; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3ZhQvCCp11cyui2gzdA+4jeQS6r4tc4Xix/KVK/fQc0=; b=I3i/PlYmvH4nq8usn6zSpiJtrQCHo8mtU3SWKpQE/ln9jU3tcy9VlPnC9lH2RRCNgx Aa1pzAKrhVoVKR3dGWiglYDJanmgiMlcCwk5mhS7dM/KaUNYi1tqi1fYhgTh4iVxK2Ht Wt8/L9EekuNk1cB+sZUvqiXh35kmmMMZPsNLjyaTx+eyLDnyrBsZcZuAF+ByVJKbOCRp tYamfeCjgThb7mrDMLnIb8gmlnoeYeH/AkQ85GlfJgHizZXikl1B/O4DRyFLfOntBjCI fesx0lZFBkEfU05Wzg6mvns0H85RIZc6Sp/KqQjCS5sB+7AvyCZXm1BK4gIA+TZQ8ZGm dCGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795391850; x=1795996650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3ZhQvCCp11cyui2gzdA+4jeQS6r4tc4Xix/KVK/fQc0=; b=Fy/2BW62vuBSte7N/fNBan7qFfwwbJXjtG59c+WEDvm8URJ3XhQi7tz/0yrJvio050 Z5NOiws7o/3GfY9EPCz1Z0klvKunFBuksuQAqHnmZV7cp34fjPABmE/C9qVDro1pWecx dvzfERO5bKSTJxZcXyMxYhbj2FULewUmFqEQvBy8rTt15xIkLmbRC7HGak6q31PGyd/0 hAiF87xAf/MHMPp9LJINpYkgxv8jNaWNgqh0S8NSQVN5RwZUz0sBcQ9PpsAzOmTiGyDv Tynqc9+q8YlDdxMN8fkA2lTJKBG2KZ2P5TcLUXBIbT4t9g4fJU2SCXGOwH7CxutY+XYm WUDA== X-Forwarded-Encrypted: i=1; AL+hErESagxoJ18AK+QX7sTawaC9KpFyaux/kslL+XclgubjZsV6S22wDrQeVHb2oSdK9FwgEBYDGiuPsgrPrWI=@vger.kernel.org X-Gm-Message-State: APuU4Z/nReNMuiT/UzvCHFY0cpFo+Vmhfuccz3vHrd35cEQ4cTtc9cqH 8TGT13ZpKqEeTujE3d+wAvQ//k4MidiJWFveTUhptOgQ9XZn7qH2hkQD9YNWbbCgfoY= X-Gm-Gg: AZFdTZfF+mYGUnLVaJIkHqgN+EHIxCG2kOz1acmFRAGUylmvkOeOQWNZrJuCk5mnxpp 25r8cQoZ/fSqNk2YWUAPaHpDd55vbF0TyL7CQvZVy8vv+hdwieXZaMPcc+Nj+NLrZGfkd3NLrua t/UDb4iA3u381G/LW4HlUHXHWYlarAgL/Q23XBiTIfxpRT6XXkrk1wU1OnOT8H5e11L582wKhjD 9SKNerGAN+piT71C3CdFeg416PTm4Dllslfrm10d8VmMG/l9o4vOrTQHpm3tzIQIi0YuC3ZK8+A XVmyv06pUlkrHuZqQeTrdsxD+WgokayEn4fWIchsSCfBq2HbrYsvd6AyEnqUgAzs6CAez3d79gF FAAHAzrZ0W7uMJZbO8S7FD/wA5NRWBrB/Rkdb2g5vtFiHg9TSoMSsFpX/s2+O7SUJWgY+rjNoVv 0MPrWz4HUY7tGoWGBe81zR2i4zMCF1d9S2Q+9kFajtiPoICwcq2uIm5CZiHF2ldAi7YzVFyPbDX 57TwfsisllGoPimj2oPzGBars6QYCzcHN6JA2+w66BxcOm9Ndv0VlW2bC8j5hnLavO8CIh/U18u RdjSZH3befMVvUUFwB7gzLfCbr3ciILpR0VE78wxZZzpYU3lg5tLhXQG0W733NtrT6JBIQXrGdj zA2KHUo97w9gK6PMMg2Ud/MLKfsg+CGAfsr56Tbgncic67TxR21I= X-Received: by 2002:a05:7301:7e07:b0:36f:9d8:4a33 with SMTP id 5a478bee46e88-38570e21c39mr10880754eec.31.1795391850306; Sun, 22 Nov 2026 15:57:30 -0800 (PST) Received: from devbox.ts.blockcast.net ([69.25.95.32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567cafec4sm34289386eec.26.2026.11.22.15.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 15:57:29 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman Subject: [PATCH net-next v3 1/3] amt: make the A-B source walk linear Date: Sun, 22 Nov 2026 23:57:22 +0000 Message-ID: <20261122235724.2898320-2-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261122235724.2898320-1-omar@blockcast.net> References: <20261122235724.2898320-1-omar@blockcast.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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_lis= t *tunnel, union amt_addr src =3D {0,}; struct hlist_node *t; u16 nsrcs; - int i, j; + int i; =20 if (!v6) { igmp_grec =3D grec; @@ -1705,28 +1705,29 @@ static void amt_lookup_act_srcs(struct amt_tunnel_l= ist *tunnel, } break; case AMT_OPS_SUB: - /* A-B */ - for (i =3D 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 =3D 0; j < nsrcs; j++) { - if (!v6) - src.ip4 =3D 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 =3D 0; i < nsrcs; i++) { + if (!v6) + src.ip4 =3D 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 =3D amt_lookup_src(tunnel, gnode, AMT_FILTER_ALL, + &src); + if (snode) + snode->sub_mark =3D true; + } + for (i =3D 0; i < amt->hash_buckets; i++) { + hlist_for_each_entry(snode, &gnode->sources[i], node) { + if (snode->sub_mark) + snode->sub_mark =3D 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; --=20 2.43.0 From nobody Tue Nov 24 11:17:54 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795391853; b=EYEcY/e2WMtW+Zh4cjS6kPPCXx8Zk/A+sWkks94+pmbyg5TSxQz4bLS128+T+p7le4K+ y6PskxocVYEinmwbepJHkZ7zSXLJ6tJEdOPOvPS1YF6toK99nO72PvtpRIKslyNcmAA+4 n8KUh9/J2MUeHmiczmZIjLFkH87yqOGoVOkR0AWoDeO3wg3f4NBEaxCwTlajm59XMfzIf CCRLd7OYZmqdek57YtInJCzyyXRWpGfAYxef67r5TYWTCsqHTYROHzPRS3EAAZ2vklfWA MsdPTGxp8W/M9lDddJVsaUbE02P4KKxr3+WAUKKLsmhXnxRu2QhXYaeSVVL7SNtsm0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795391853; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=twwsbhNrEyvlcTQgdiEiAI2kQlmXcclrqaF8/FbQJhQ=; b=huDfTzrBGFHFWvUpCKFnwIG1kIMdymQIy0aBgpa2ZcyPO6X3HLhNfjQeHb/LwbWoWZ8n d2nEbUO2BE5bK4SDgcjOtl9YquDwP40LbXXJ4MCksGvbQrziyKHv4FOIqRscBsDmCPR1D iAJRAQwDS0fc28PdGfkB9rJ2FwTywiXcBU2dLZ+PhF8fJb0oRSRJKNeKbvnGgJjXslDvW 3IAPAcx7Q1eYT8vsVh2dp9O10JIkHFhB12mNDtfYeiBHk3vrVAxb3NaxuwHSaJxhQaTLc 6B+ZbPqgfN0PWFGj18iScGgHbbyBn5cWFIcZf1OuFri98ZOG+tmhk4wMWTCpSo2mTgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=Pb2Oilg7; arc=none smtp.remote-ip=74.125.82.49 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB518606A69B for ; Sun, 22 Nov 2026 23:57:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB518606A69B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=Pb2Oilg7 Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1a2761c69fbso955478c88.0 for ; Sun, 22 Nov 2026 15:57:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1795391852; x=1795996652; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=twwsbhNrEyvlcTQgdiEiAI2kQlmXcclrqaF8/FbQJhQ=; b=Pb2Oilg7pSU+FcXuYQsHj5y2eCCaT7hcox/M/7+2XQfZUkqwrk8U7rHEHGz0KWG4YU K+TpC4flg9W6+buOW7ybhrq1Yoz75+qRnwUNqq7qgm5BSH+pknOz80JVzX0fURvdluW/ /a7RBJV+xkMENyFFgoGPASLHLgfbXy9u+fIwbT4bpe6M6/u5+NyBXAfzA17JHXcXOzwz Hlde7X+LcNlZvtyhTxuCJpuDBu7+CEEO5HWtGt7mXR5n/aMyJGimYepexwF98QwQs+kk 9Ww5KOf6BmYqyuXMTtN1cs8fGzSDcbg0VLE4PweqpQqvOTJuo86PiyGQNEzIv9taCTJ0 Mx9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795391852; x=1795996652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=twwsbhNrEyvlcTQgdiEiAI2kQlmXcclrqaF8/FbQJhQ=; b=wnJ+mav1QN9/Pm6l/BItvW8inYX16AaTjXuTRqKGsut96lce8hY0MivpaZeCEjEBeZ KjtWE6kWKG3ZJu418suA4NhrXMwsIsHpij1zvfjbzdDk28EY84OaFE5SWq7e6SqdBCPB teSNFAHakiXQAeKzdElFifi3sW6izPitcNeWTkcfGJ8p9J/sMBG+j5a6072BpjPOghMX Rerv40Y07X4TENYSWuGONwjXEXvBxRctZh8VVYzrgLBginudi0ARPNGVizb41HoB37u/ uGU1QsQmIegGxgkGWzQiWS94hvFNlYHi8ddZqx+p5pf/Wcey152GT2/zXPqWm3r3lChr 2nlA== X-Forwarded-Encrypted: i=1; AL+hErF6y6tZqKKWSm3vKCh3YsxxpOJcySccvhNXbXYMRF5DjKH+OafgP0Kpeow7Efd0WShbJ18zLCV/z8V5Vy8=@vger.kernel.org X-Gm-Message-State: APuU4Z+5tJkZZORTz5Mi6bi7JkDbR3Ks3nP5PnYdmIqM4RXQr8VxDrWJ k077d/eRA0BWNfPaSSBt97Qpog0Mo83utPuFVZFzgnrOvSs1VV3NDEgRHTaUdKL7k20= X-Gm-Gg: AZFdTZfGs/Gf36a2iF+BoeFwiFV5fVs2dRJXMKHL12J55EL6LCZlcp7/U+CFbQJi+Fq 4SK10oCD38HL3zzH8NaZ8zsMBdC6wC7Bqm0rgBbIXENTrvdLKyATYKOocMZXKVpPArXqfD8HIR+ o+A8IVDNckSmOPP8EsrSzegOGWJQoImMF0fMZysxtDikziFKFGeJGKQ3HtRN3RJnFBrye0DDiC8 PLNQxgcM437gB66Fz6VjMy2UM0Gw+cyPVIvagCKObFjdpofbO4UpmkHugog9rQsqkte8Upv+hrS pIMC8VLO7aPd2eiIti7Yby2UT5v5Y0/ap5uPHbF28i/bcrynsbrGciJX5PW0g85L8hzdBeFzcVz 204cgSCnkHaynzUtODd/LLD2ZITlTgqDKpmdy0ahLcdt0qE9TgancfOq3k2DP6ufIKdE6t8796O Yepi/tfKjNXVm21Gnf/oAZxWzoXgAVRHK88Db0NQUXqP7gH+ZjKWF59L9x35D0X9NvOOQy8En4x 8MO6KpAGqxvn3EDNzMTlE/6+KSTkT+79r0D0Q0Mp23/CIaYpuczU/WveyBhIwhlEgUCt6aNd2qk M3j/NcUWYQxnPWoYt8I8twikdCJ75RloBjnZGJDe3+7J+wqYD1XVVNnfkDETdVvc7SRzAwKu8rY c9BFELxgiYTx8Lu6mKaQ12UcZ9LRXSGWdbeKELK/HUbH9pIT63zN3Ih6zqf8tMqB1aNIC8Tqc X-Received: by 2002:a05:701b:2616:b0:1b3:ba92:145a with SMTP id a92af1059eb24-1b5568e0a27mr9374716c88.19.1795391851945; Sun, 22 Nov 2026 15:57:31 -0800 (PST) Received: from devbox.ts.blockcast.net ([69.25.95.32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567cafec4sm34289386eec.26.2026.11.22.15.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 15:57:31 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman Subject: [PATCH net-next v3 2/3] amt: bound the source-state work of one Membership Update Date: Sun, 22 Nov 2026 23:57:23 +0000 Message-ID: <20261122235724.2898320-3-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261122235724.2898320-1-omar@blockcast.net> References: <20261122235724.2898320-1-omar@blockcast.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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); } =20 +/* 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 nsr= cs) +{ + 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 =3D amt_report_budget(amt), work =3D 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 =3D saddr; gnode =3D 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 >=3D amt->max_groups) + continue; + work +=3D 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 =3D 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 =3D amt_report_budget(amt), work =3D 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 =3D saddr; gnode =3D 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 >=3D amt->max_groups) + continue; + work +=3D 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 =3D 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) =20 --=20 2.43.0 From nobody Tue Nov 24 11:17:54 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795391854; b=A4vnALjSfX15yOX0Ut/cXu18rsb4j435t4kv7U4ezamLe2QMbktUgJJwIzt927j8Sz7T Y4gXqxEcfZKIAN+MwC3z/WKTOcfOH9Lo0nEH+MJHcMBr5K6yWYq+cVkeUCv/rbcrRnzVd M1xgxVQEfpMrU9F7HY/Bn9Hveu9zitRps/ERp9FzwWlbgaOhRNfVWf3kS3M6+xWpZHn/X R68DwcIdWnA1ImdXDFPt68084hUhx1BID/r0yrPmrCJzLCZeVSHj5xyuR6f0+cjozd+Hq I02ncOPBazPnbd3E2cVIdL4JvSDTKSik1oCJin7V0ouS0OgynQajtABi3C4H/sknkTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795391854; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=NW/1Frfb7mXCSDL0SysKw7qO5sxKBEHZ2YmPtDESfGU=; b=gg4p3rWroXFP0k8shH2wI6FrZgCJFmJ0rvuZTq2hwMp3fTZ1JhHGyCwOdL4FFxYhBnxW 4ahS/r94y/ZOeiW0fqvo3cdcwrLtsDUnCAR0H7USYFSnIBbNKcGyzMwYQNu1Mmbwv+lYS cCG5vwcEM2sZk580UGgWmxVA2nVK29WCjhdziNg4QZG80ZPuMrakUcNx3JYfR6zXyG19R E+h84BJPe3UmQrPhd7X9o1P8Nt2ZiUKFIDqI9s4nySw4kaAk1L/Kz/A7yVGDkx+SFSwDn aw50/qClvUVJtUKazLnN5slCc5c5X06OcC/H7zVYZoZ9EKiuppY3+ahEskSX7n4gMKw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=kl79WiDc; arc=none smtp.remote-ip=74.125.82.44 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C26D606A6B4 for ; Sun, 22 Nov 2026 23:57:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C26D606A6B4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=kl79WiDc Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-15dd124bbe7so814806c88.1 for ; Sun, 22 Nov 2026 15:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1795391853; x=1795996653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NW/1Frfb7mXCSDL0SysKw7qO5sxKBEHZ2YmPtDESfGU=; b=kl79WiDcKoleDENYg2th4u+H4KlC8X/WaKf7NV5o30pnE9MXZHo4kVNTvlE+rOsZYf d8VS65fzY+jQVwnUb6Qxg0XXUOBjfWJpO66SsHiEJR1Z3eOErnUUaEnojaJFAwL/NUXJ VX3Ahu/cTn4yqMCApiMumU6mu5kjsMbiHMtqvweFmyBd3INyibP8HH+866OdvXpZNMJl MzMDUPjBsywWKhuX2pS7Z217H9PNXDkO6dHNdXtBX5t2Qb99e6tHIl2wYnXQKHFDJIN6 0jAZ6gn4ssajloAp4bgRxOU8sXSWLpYqQ7uzs0D3IuR3usYMDaqvGRZAlO2Vrf2tuvgU RMzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795391853; x=1795996653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NW/1Frfb7mXCSDL0SysKw7qO5sxKBEHZ2YmPtDESfGU=; b=SHvfYFNYfyRjCwWw1yvKHC94ZXQUz/pz9Ys+qwuLEdutYWrsLqxHUPvmgIPZfO/TQZ KtBNWARiQoxGUDC9wfpjrjxlRP1XpYv8WEuvMmnjURDgfb8kzpwDu/3PFt1O7onHA0kt gYfem2OUL+YpMp1StLszVanLBHG5qEP6m2xXSk2MAoSS5NUsNkaZLECfX/Jc4vjyrbKf HCWqMiZF8S4C8shEpsbP0q/jq/2h8Cs3OP3Mq0NkHsNpCa+z0RsZIKwKwvhvmUuqiGNy pfyZuW4ycOdLiNbQ3ayvB+vQ4EiTrcul/vf/Ll5kH7ZrY1G+vuKAyOTf1tgcFEAJuuHw qFIw== X-Forwarded-Encrypted: i=1; AL+hErG8Dmrubqb3CfpJ3Fknnrk5Y1Ng2fEaCpFwPvsirsvgxh2WGM3wNqCce85ciFmL9j8G3miUW5MCR2R32C8=@vger.kernel.org X-Gm-Message-State: APuU4Z9xZijlNVLTMe0KXlXuRUvqvD9AOmMSFqamCfOxvCxC8Zs+aXFj nvBN6LceYiuf1IDNcaCVUCStT8xMkvyfQm5id8tBxmRROo2RVIL08RK87YTeFV1fOTw= X-Gm-Gg: AZFdTZe5IsWg8XezfcmEBayoUhrXxnHWzz8N9epfTAB8sJyhOj2ThT2D0C3JYnkAJ7Z WcoPai27QqDvp/n0XDxUqjUydEF1GSY3KQje1IGPBWgg+5uwrAfQGQWK475L2A+q2wKDaMG6aGt 7sHDAbirkV2ThXLVWibubfBd6PVoldxOZvBC/EpAIFhuaiWzyMBtGpPoQruZV+fpZF9R9y3ITXe yTJpQJU9fxJVYsLn9OFVU/c+2q3zOScir3mHE6wiIbDaCRERtvMS5wY2ILxmuOpw+DwUu7VJoEr 1T9QFc7tLDlm2glRBjLfoTXaHtNTh8SUOtJC6kXhPi+6/jXpqrRCuxNSM6U9XAvShrw3PgIVErT ohfslvwFy+SBzseYYEo4iulk5j3x0pYnu9UXRcBQCvgsxoH/0nrj1Rc8sN+tT48+mKq3FZkTWpm hNtq/mF4OpuiBDpaKXrmZKStrHeGo145RyXnYnWE9TkZ2lVB38RfFzPtNqpSAwwEqihTFgvKEW1 8mTLbFIgaxibHZp/r0gELrs2arfL511q2zd9DUjRRvihOimPphXexwLXq6pbzqcoY+qBCPJRSfu qYLPcjJGVQ7aLIvOCsHuYMLbM/Fa+2BdMbl8LuDMoVoqFowd45jhdBh0uzR9xKffvYgf7/LJ7zF siVQzWFKcWZ4JKkLScLwZNF3G6iDEVpTNwqVEgodfFOHs+SQC4lo= X-Received: by 2002:a05:701b:2313:b0:151:d6e5:596b with SMTP id a92af1059eb24-1b5568b31admr9709668c88.9.1795391853529; Sun, 22 Nov 2026 15:57:33 -0800 (PST) Received: from devbox.ts.blockcast.net ([69.25.95.32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567cafec4sm34289386eec.26.2026.11.22.15.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 15:57:32 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman Subject: [PATCH net-next v3 3/3] amt: make the per-tunnel group and source limits configurable Date: Sun, 22 Nov 2026 23:57:24 +0000 Message-ID: <20261122235724.2898320-4-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261122235724.2898320-1-omar@blockcast.net> References: <20261122235724.2898320-1-omar@blockcast.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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) } =20 static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] =3D { + [IFLA_AMT_UNSPEC] =3D { .strict_start_type =3D IFLA_AMT_MAX_GROUPS }, [IFLA_AMT_MODE] =3D { .type =3D NLA_U32 }, [IFLA_AMT_RELAY_PORT] =3D { .type =3D NLA_U16 }, [IFLA_AMT_GATEWAY_PORT] =3D { .type =3D NLA_U16 }, @@ -3591,6 +3592,8 @@ static const struct nla_policy amt_policy[IFLA_AMT_MA= X + 1] =3D { [IFLA_AMT_REMOTE_IP] =3D { .len =3D sizeof_field(struct iphdr, daddr) }, [IFLA_AMT_DISCOVERY_IP] =3D NLA_POLICY_EXACT_LEN(sizeof(__be32)), [IFLA_AMT_MAX_TUNNELS] =3D { .type =3D NLA_U32 }, + [IFLA_AMT_MAX_GROUPS] =3D NLA_POLICY_MAX(NLA_U32, AMT_MAX_GROUP_LIMIT), + [IFLA_AMT_MAX_SOURCES] =3D NLA_POLICY_MAX(NLA_U32, AMT_MAX_SOURCE_LIMIT), }; =20 static int amt_validate(struct nlattr *tb[], struct nlattr *data[], @@ -3657,9 +3660,15 @@ static int amt_newlink(struct net_device *dev, =20 spin_lock_init(&amt->lock); seqcount_spinlock_init(&amt->key_seq, &amt->lock); - amt->max_groups =3D AMT_MAX_GROUP; - amt->max_sources =3D AMT_MAX_SOURCE; - amt->hash_buckets =3D AMT_HSIZE; + amt->max_groups =3D nla_get_u32_default(data[IFLA_AMT_MAX_GROUPS], 0) ?: + AMT_MAX_GROUP; + amt->max_sources =3D 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 =3D clamp_t(u32, roundup_pow_of_two(amt->max_sources) /= 8, + AMT_HSIZE, AMT_HSIZE_MAX); amt->nr_tunnels =3D 0; get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed)); amt->stream_dev =3D dev_get_by_index(link_net, @@ -3774,6 +3783,8 @@ static size_t amt_get_size(const struct net_device *d= ev) 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; =20 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 =20 #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, }; =20 --=20 2.43.0