From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796032264; b=gJLoepl3Oh5XJ1NWdoRwihZRVnSKwh3bsMxCuJz0YuPija3eD1Ck2Y3+uB1n4c5XKdi4 f2LlTMlvBtykt1E8hEN/mxJhoLdtIr/3AOhgkET9ENdifY3ywbUzUOu3fY2cds6DdQDlU p3wjbUrpkkf838LlOTC96Mq5gdLn5DFNoLx5yL7mMzlrFbe5UufuwCX7Wi2ntdlRAJ4VQ T9Pjjh2mUHWg8anfK93+M0yrdBKfHCiVTYvrEQ4XXFi0oCTeIacx/USNGSlnUVd7tyayE tlS8lvv2p8Wu04sMIXd4U8hf94FagM0VrJzQp/fVf+9Tr/temifLJX5yCiyk/Gnnaww== 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-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=q12aewuFoTy0dk2dv4t/MgwcA+nU0jlWjuOsjuZ/Sr8=; b=of4UYFDJTYHEhzVOWVBieP7/CyVWOJ0Xy3j37CkS+NMpD2tIq5Z++IAiyAGgf99atD0W SauXiYe2xdMv1lNPfuIDWR04aWW7MN0VTk55N/9BrgCyBUgz6bJgcnK3lj7fIersJGMkF PKGK9PAQ4n7iLaEh+fm9ycj0sO/LXls/n1yWgYptLFlwHGNk28qwQT4taOrjWQq2ssiYI EoCPLjzbCkRbT+vdMacXZUeTFU/QW1wgL81nJ7dWsqfAECabGhY9IBNcjCsVzCIvI4KnL WgNAms22Ww2byc5FA5YjR3QayDzX/SNNmVal0Ldo08BeLotTKEZQV+YXVpI51kHMH1g== 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.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 F3074606A69C for ; Mon, 30 Nov 2026 09:51:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3074606A69C 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-f44.google.com with SMTP id a92af1059eb24-14394530ec6so5013149c88.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=YZj0kjmMtL0otvwpwhUSKVUEy8lrcTY50MQzxxeOyOswdVVJkS2bxMC+TSlAosELM9 U79djcF1aUwBtJeAXtEPdiTykkn1AgjxXpqfhpdu4ln5J5ucyZxfU5yrPyrpM5fFUKZU neUz3U+aGkROvSSiOptrj8BYF6NS67FwXFDXclYtqiV5omTAbj2+deex3rVa89fw5T63 OJ5KMl198L+o8f8HIOnseSBf3sBgWbldiO1mKuVm9/TjJkoPDE499YPPoSfUscGh/NOL Q0vD8aO2U7NzjAkLIyqJpZG2cPtfd9waITN3bahppzYcTLoUWeLFkB3ZCUxKsbcV11NW CPtw== X-Forwarded-Encrypted: i=1; AL+hErHByd2A6kzF5wCcjGyLomlXVFVnkutC9p7uJJBbArUCaW0HRFBcVd1i4TsI2GxP25g06jtw++UgTzw39sE=@vger.kernel.org X-Gm-Message-State: APuU4Z9VqRIqL0NmfqJqCAeZlJ+GK32uRAQVCNinSTc3opA6LP7cXBtQ qP18RTtB7nBIqS0pgESBFzMfQCrSMmopiA0jrywyKR2TZiWRE7/uAV/xsh1pYFHuhrY= X-Gm-Gg: AZFdTZc39lQM4kAFfaGGNgEm/sz81Xvt0kTwqEI42Sy6FnTrWtKNc/JB8xnhmGlpxcJ GuwilNEq4SL6XE54qzu8ykKKP26g4pmE6jFoKAawqY0FnfUz6QtOUmwd3WsVM9KA+GtbMTXyuOf vFqKP6e8QCB006bwFy2dz3wCMH8j9Tml9wR3eSIdRJsv0ADzWzxD/9/kBuvpJdZBLJYz6we985d OG/+dhlCeGtu2TGPD6VrLYU5P2eY1Z38gOWPwDB1JW7n6fCwEzIb/qgcqJPbCcmD5/sp7jsPSqm zGCX4WVnk2HCJdfICew0gj2DIAKn9uE5wSv8NPI1043DHw/9Ph9LoeCbYZ6fcf5Z5NY+2kdXgnB 5lrX4kSIunTqFc7MMpCByXoNa6v3e7yGdCfDaZ6/D6TUc/CwMTc5r72LRinwK/4UYkyzXIFvc4h yD2Dkb6DdRYQJ8axXy5fz0zqwx5TDl8vtYR1ST28GRoxOBgDHnQEMMVFK3d6vwv9MJc1wpLWF9q Nc6C6XP5rErR1sGIHh7YDxFi76MHyH5W0bWcspP2ee0+MpYF/XKoGBoIaXxEYmnzpg2ZNyFhQR1 mNraHUBB7arhSdwKTsr9b8k4kjPKi01mkZLjFPRtcqun4OsmivDcbAO5yM0k96p1vfeJCxEphWn hnmqsdCxZT5A/HTVlzKx7VxwCmXc= 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: 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: 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