From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796032264; b=zMo62SR00Tlnth/6TcgnGELtkvRdAm8cpavZURibpeLYpAWUU2e6ZAJD5bXjKGk2yWRZ oJVUnjd88rUYhpIMTeauk9LOKImaNjWdBWI+Xct/a2vvk1t9tvnmubfl7VbVKiF4FnWuQ 0S2tMeYZSMB4ZlKEepVCFZ5M+3D81SZmmHsVBLGyAf3svjtmcBN59Lb43qHYZhdzIIpLH zfxqiRG/CQzKLAP+zQZzF7HbUrbEkeZqiD3bQvzZsggl2fmrhTpLLQVIyFFcIK5DLPsN/ ElnqB15pektlDzPXbLAZzPe9mrc+nStvjBWt/0AvqjOErvVHwTxl2YU9SWGVtEh8X6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796032264; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=q12aewuFoTy0dk2dv4t/MgwcA+nU0jlWjuOsjuZ/Sr8=; b=tA3Z7ieJ2vtX76jcwpSTWZ0ovz0yzrDSaH9wIVD7zdKiFCJc1A99x5jaBP7a3emtnwBX TBIdvYtqbPXo9JI0rLZBHed6tT7V0esSFTQ5MYqRZEKGnGZAUwV0Qw+75DB57yBVTAu4z 0BXZ900NgmmbFWLzLlaeT2mp44HMG+vg+hSK2rYLZ/fJUTapkNx7Vp9JsYchjN1OuypYj 59UPBxR9wkJBDGQRyVkdvkzEr8xJPtzXKpStcwLO4ojOFM1uKGv0jp0KDqF1E8sBE0xl3 T0uxigpdrpYLugzJ8o6U6sf9a5xap22ZqbIF2N102KrMV2r9B1qOmM/gpZmvDwSeAHg== 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=VMpVDq8+; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 ECCB8606A69B for ; Mon, 30 Nov 2026 09:51:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECCB8606A69B 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=VMpVDq8+ Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-14394530ec6so5013148c88.1 for ; Mon, 30 Nov 2026 01:51:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796032263; x=1796637063; 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=q12aewuFoTy0dk2dv4t/MgwcA+nU0jlWjuOsjuZ/Sr8=; b=VMpVDq8+efbfXV5qNja0GJ5ucSTUpokQQ/ylkUZcJb9scHTuGdkkfZlDa/+/rc9AwA Fay0T7h0Jb/EIPE5KwfGr9g1nOp11jHiQG05Ovgy9MP0zFys8J5YoOdL33l19keXLjb5 wxRvkC34asSNo/5nTk6ZcOPTU3Lf8Cu68CCj3ie1IsdLK6onnuoinCUavixuuwuBifgl oGi5X1P4OmWTkfETMBXzJYOd4fS2Jffq7wpW2LNhpL+FO87mpHksn61nJCJdOJu+6jHo f5ngXSeoKtbBgCLyGoL0GTwTaYx/Y/7m6rXKcBYUSyJP8CPX/MBI2aRMScGJOivu4MJv wfvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796032263; x=1796637063; 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=q12aewuFoTy0dk2dv4t/MgwcA+nU0jlWjuOsjuZ/Sr8=; b=CMRJYhNNXo7FJ7NaAiaTfggXw1WiTomPGspLTeWcQSULxbYLppvgx3SzoCxUGwtxlI Jg0W0akmTrY2wrZb1Hvl/Fd/LGOTNbARHTNIIM/ZP6J9ly5bhdvrQMvq3H8CquCr+yEW Nr0pATg0uLPV+B5FpBzrzfQm9o+l/+G32qaGPXvwdQFqBiW3fwVYVZZWnQHKHO0iM9mG fFbMgXTitSEvoStdq4Z8Izh2l0cWoLVZLwX/jejQsi+wDftdqMDSV6NdXEaX758Po4pV oTSkn6WpodaAlgN5qXxIc+Sw6w6uHQfa+Umo5b1H8FBXPESSFJ6nhgRX+uVvJ/eqijxM 0DAw== X-Gm-Message-State: APuU4Z+311tkxOKXvvtympENR4hmNxjBWysU7/R/Zl9p3og4MGHwCWVx UEbDtIoobXmnYcneDK8B9DK9q0ol7lOVSxlMOV3MaY+WzBhjg9bVDGyrLwz1T8+Wnfw= X-Gm-Gg: AZFdTZc9sXbaDboJGcfKPozuxj3ERJ6cMUR62zfXTg5lx2zEXMKex6z1U2bCiTXbJdz N7u6jWgiqaVABazNepunMnsz+fibPbqgomx82reZ4M0sMj5XhGl8tAMIKBS8jVtDt7YCIelO1bU /Lb6VXG3C9xHmE1GSPTrXm+g/XxLqmPaKXz9lOuXeoxYOA/CWlnt5ilT47l1C3pDyGIkU1fLseS sG/QYlijEXaKu/GiroRkoIyec8kXRldjLvmSdyT/gymal3TMxbuU2bJWIM+KvwEfjPJHEMaMVN4 QHYlO8ZDwIB7yrR34mSiOSLRZbhhZZtcLKq62xfyljBfzNiUv1pSP7DOetT7gKLPTQJelq75wKR AvWS7JyjMfCrfjte2zAVISpie5Z2mLYpU8hNqyY9Z3u+WC4tP5DV7TX8b9CkKONhpRsKXcPIquu AlAcmGMHk62UeFnbsAFOXctNYQ+RxsJO81AT48TFAlWSofWbug/tnyNU/CJhgUWUGLP4h6dHmKc ccEbA11o12OywhQT9cWDJ27EExZ9HTxs2BfC/lLsX3dKHh7OvMU3a5+UKF7HrPAAwNnzYVq1/jy MaAafwT4WAKsZAU2BfX/4jm0fsjBQ+TihR2M8C0zG8FWlMRY3rQukXbRRWebCNuiiOEqhJJ8/7D 7KG63YSruUSqx1v7GCrLs5iIQSSg= X-Received: by 2002:a05:7022:3c07:b0:1b5:514:6a23 with SMTP id a92af1059eb24-1b55689e9b5mr27504914c88.13.1796032263075; Mon, 30 Nov 2026 01:51:03 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm93595422c88.5.2026.11.30.01.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 01:51:02 -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 , Willem de Bruijn Subject: [PATCH net-next v5 1/3] amt: make the A-B source walk linear Date: Mon, 30 Nov 2026 09:50:57 +0000 Message-ID: <20261130095059.1301582-2-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130095059.1301582-1-omar@blockcast.net> References: <20261130095059.1301582-1-omar@blockcast.net> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_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; base-commit: ccb81d5e317b0ae2cc66ca1c628c0ca907928f94