🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21187

[PATCH net-next 06/15] batman-adv: tt: refresh local entry in single flags_lock section

#21187
From: Simon Wunderlich
Date: Mon, 23 Nov 2026 17:18
215 lines
17227 bytes
From: Sven Eckelmann <sven@narfation.org>

batadv_tt_local_add() modifies the flags of a local entry in two steps.
batadv_tt_local_add_existing() cancels a pending removal and
batadv_tt_local_update_flags() updates the dynamic flags. Each of them has
its own flags_lock section and the ADD events are queued by
batadv_tt_local_add() with a snapshot of the flags which is taken after the
lock was released.

Merge both helpers into batadv_tt_local_refresh(). It modifies the flags
and queues the (single) ADD event in the same flags_lock section. The
announced flags are therefore always the ones which were just stored in the
entry.

The initial ADD of a new entry is requested via the announce parameter
after the entry was added to the hash.

This is a preparation for the validation of the entry under the hash bucket
list_lock, which then only needs to cover a single region.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-7602d89e-b2cd-43ca-8aca-c165e5d674b2
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/translation-table.c | 129 ++++++++++++-----------------
 1 file changed, 55 insertions(+), 74 deletions(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 1c784a0e8c9b..63eac1e1c65e 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -903,57 +903,6 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex)
 	return batadv_is_wifi(wifi_flags);
 }
 
-/**
- * batadv_tt_local_add_existing() - refresh an already known local TT entry
- * @bat_priv: the bat priv with all the mesh interface information
- * @tt_local: the local TT entry which was found in the local table
- * @roamed_back: set to true when the client returned to its original location
- *
- * Return: true when the client has to be announced to the mesh again, false
- * otherwise.
- */
-static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv,
-					 struct batadv_tt_local_entry *tt_local,
-					 bool *roamed_back)
-{
-	struct batadv_tt_common_entry *common = &tt_local->common;
-	bool readded = false;
-
-	WRITE_ONCE(tt_local->last_seen, jiffies);
-
-	scoped_guard(spinlock_bh, &common->flags_lock) {
-		if (common->flags & BATADV_TT_CLIENT_PENDING) {
-			batadv_dbg(BATADV_DBG_TT, bat_priv,
-				   "Re-adding pending client %pM (vid: %d)\n",
-				   common->key.addr,
-				   batadv_print_vid(common->key.vid));
-			/* whatever the reason why the PENDING flag was set,
-			 * this is a client which was enqueued to be removed in
-			 * this orig_interval. Since it popped up again, the
-			 * flag can be reset like it was never enqueued
-			 */
-			common->flags &= ~BATADV_TT_CLIENT_PENDING;
-			readded = true;
-		}
-
-		if (common->flags & BATADV_TT_CLIENT_ROAM) {
-			batadv_dbg(BATADV_DBG_TT, bat_priv,
-				   "Roaming client %pM (vid: %d) came back to its original location\n",
-				   common->key.addr,
-				   batadv_print_vid(common->key.vid));
-			/* the ROAM flag is set because this client roamed away
-			 * and the node got a roaming_advertisement message. Now
-			 * that the client popped up again at its original
-			 * location such flag can be unset
-			 */
-			common->flags &= ~BATADV_TT_CLIENT_ROAM;
-			*roamed_back = true;
-		}
-	}
-
-	return readded;
-}
-
 /**
  * batadv_tt_local_create() - allocate and initialize a local TT entry
  * @mesh_iface: netdev struct of the mesh interface
@@ -1028,27 +977,63 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
 }
 
 /**
- * batadv_tt_local_update_flags() - update the dynamic flags of a local entry
+ * batadv_tt_local_refresh() - refresh a local TT entry of an active client
  * @bat_priv: the bat priv with all the mesh interface information
- * @tt_local: the local TT entry to update
+ * @tt_local: the local TT entry to refresh
  * @iif_is_wifi: whether the client is connected via a wifi interface
  * @mark: the value contained in the skb->mark field of the received packet (if
  *  any)
+ * @announce: whether an ADD event has to be queued even when no announced
+ *  flag was modified
+ * @roamed_back: set to true when the client returned to its original location
  *
- * Return: true if a flag announced to the other nodes was modified, false
- * otherwise.
+ * A pending removal of the entry is cancelled and its dynamic flags are
+ * updated. An ADD event is queued when @announce is set, the pending removal
+ * was cancelled or a flag announced to the other nodes was modified.
+ *
+ * All checks and modifications of the flags and the queueing of the ADD event
+ * happen in a single flags_lock section. The announced flags are therefore the
+ * ones which were just stored in the entry.
  */
-static bool
-batadv_tt_local_update_flags(struct batadv_priv *bat_priv,
-			     struct batadv_tt_local_entry *tt_local,
-			     bool iif_is_wifi, u32 mark)
+static void
+batadv_tt_local_refresh(struct batadv_priv *bat_priv,
+			struct batadv_tt_local_entry *tt_local,
+			bool iif_is_wifi, u32 mark, bool announce,
+			bool *roamed_back)
 {
 	struct batadv_tt_common_entry *common = &tt_local->common;
 	u8 remote_flags;
 	u32 match_mark;
-	bool modified;
 
 	scoped_guard(spinlock_bh, &common->flags_lock) {
+		if (common->flags & BATADV_TT_CLIENT_PENDING) {
+			batadv_dbg(BATADV_DBG_TT, bat_priv,
+				   "Re-adding pending client %pM (vid: %d)\n",
+				   common->key.addr,
+				   batadv_print_vid(common->key.vid));
+			/* whatever the reason why the PENDING flag was set,
+			 * this is a client which was enqueued to be removed in
+			 * this orig_interval. Since it popped up again, the
+			 * flag can be reset like it was never enqueued
+			 */
+			common->flags &= ~BATADV_TT_CLIENT_PENDING;
+			announce = true;
+		}
+
+		if (common->flags & BATADV_TT_CLIENT_ROAM) {
+			batadv_dbg(BATADV_DBG_TT, bat_priv,
+				   "Roaming client %pM (vid: %d) came back to its original location\n",
+				   common->key.addr,
+				   batadv_print_vid(common->key.vid));
+			/* the ROAM flag is set because this client roamed away
+			 * and the node got a roaming_advertisement message. Now
+			 * that the client popped up again at its original
+			 * location such flag can be unset
+			 */
+			common->flags &= ~BATADV_TT_CLIENT_ROAM;
+			*roamed_back = true;
+		}
+
 		/* store the current remote flags before altering them. This
 		 * helps understanding is flags are changing or not
 		 */
@@ -1070,10 +1055,13 @@ batadv_tt_local_update_flags(struct batadv_priv *bat_priv,
 		else
 			common->flags &= ~BATADV_TT_CLIENT_ISOLA;
 
-		modified = remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK);
-	}
+		if (remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK))
+			announce = true;
 
-	return modified;
+		if (announce)
+			__batadv_tt_local_event(bat_priv, common,
+						common->flags);
+	}
 }
 
 /**
@@ -1109,8 +1097,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 		tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
 
 	if (tt_local) {
-		added = batadv_tt_local_add_existing(bat_priv, tt_local,
-						     &roamed_back);
+		WRITE_ONCE(tt_local->last_seen, jiffies);
 	} else {
 		tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi);
 		if (!tt_local)
@@ -1130,18 +1117,12 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
 		added = true;
 	}
 
-	/* announce the (re-)added client to the mesh */
-	if (added)
-		batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
+	/* announce the (re-)added client or its modified flags to the mesh */
+	batadv_tt_local_refresh(bat_priv, tt_local, iif_is_wifi, mark, added,
+				&roamed_back);
 
 	batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back);
 
-	/* if any "dynamic" flag has been modified, resend an ADD event for this
-	 * entry so that all the nodes can get the new flags
-	 */
-	if (batadv_tt_local_update_flags(bat_priv, tt_local, iif_is_wifi, mark))
-		batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
-
 	ret = true;
 out:
 	batadv_tt_local_entry_put(tt_local);
-- 
2.47.3
Technical Details
Message-ID: <20261123171827.3294525-7-sw@simonwunderlich.de>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369605-linux-kernel-netdev=dewy.ru
References: <20261123171827.3294525-1-sw@simonwunderlich.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369605-linux-kernel-netdev=dewy.ru
From: sw@simonwunderlich.de (Simon Wunderlich)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 06/15] batman-adv: tt: refresh local entry in single flags_lock section
Date: Mon, 23 Nov 2026 18:18:18 +0100
Organization: Usenet Network
Message-ID: <20261123171827.3294525-7-sw@simonwunderlich.de>
References: <20261123171827.3294525-1-sw@simonwunderlich.de>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3939678"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:EFms3yOOzz4xcFZFsDQnS1Z8RuA= sha256:g0HdbMpTwNXUsoKKYQICaQZBGbIFmQ0pK76c6KIkhK8=
	sha1:/3jFkPGZ63aFf3thV8fGgoMgF58= sha256:4MaB9k57fIDVw9CwqlrP8DgzsTwemUlCpiC9HpAr5U8=
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 87F38125DC0; Mon, 23 Nov 2026 20:25:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=simonwunderlich.de
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 im6f48IZoCiZ;
	Mon, 23 Nov 2026 20:25:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369605-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=simonwunderlich.de
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 8C25D125DC5; Mon, 23 Nov 2026 20:25:36 +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 B4C9E3B784; Mon, 23 Nov 2026 17:18:46 +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=1795454323;
	b=BnLPwtdz6Fw1yQ49tQCZayq9f+zDNVAbiaWXvh2hdLpiIjCoVOdD0aIS32NnwYyZFngp
	 Dk064F8FTWIeG/BdLXx6dJL/pq5gt7jx0LcgC4OOwLb8Z4bJ+jILi5eXxVzKEr1UvCkxC
	 YWXNjh5UVOH2B8yWj07ByUZCSlRkbnpfexGTTLXhAt/7qgEqdwwjmmqJbJicWsKmEua1x
	 1SflsmIaadgSEvFGFlx71+kTCEfMDSWcwydsA0ZyOFdH4G+pO3qS3BFYXPV7u1+bn0FPm
	 OKY7kWW72yCERGZ7XNHLIzesrqJE5YS9N38OsHQhMr85Xbype1Ike6z6Hjdak1pOGwg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795454323;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=9m8KFjyLBuEGWvkUX+zuLasC9JtQT3T+Xo3Iyb1Jbik=;
	b=3TGo7HGk6tSX278GZeMuadcWTM252mjH9g3PMcoytUgPRwC6hxQ+ryc/Gwbn5lAc3eaq
	 wU4nWflOayZ8cVkSNZ04KKrjjlrOV5fK7X7P7+jcwYfw9Xul79qrkqFCH8shA4nc00e0Y
	 6bgDyYR7WO4H5ypwwLzdEyP1dLu5qRf3dsXhJaMOaQzSri4G7rY7Fhdg/sc51btYp1ejd
	 0hX598fYgkbosKSnXmHrMNmUUoXZ8hSuVAR8QEpBAUca5CiR9jRQj2rpi3Wbd0T35X82f
	 1BO9u1Juy6PsZk4PqEpGQrbsbPBpAD1ErcELLCXVhRHvhOA9UHCJBGZdawgVs25SI2w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=h+CzS7Ze;
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	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 321CE606A69E;
	Mon, 23 Nov 2026 17:18:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=h+CzS7Ze
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.88.38.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795454322;
	b=ltmO8PL+JgxiOlOw+iY9JSa/cNwX7tGrnz7zIWtgQ50CX14Y+F70ghWY76QLv8/OuBzl
	 hHBbA8UzzxpUR/qpqc2IWpLgCxSRILGVel4dDkQ3PF7VgM4OxlpMu4fkn8bhwO3/d8Kov
	 CQoLnPXz4X5ivZMOjKmlgJ9krJy8kKUv2B2Jw0xvagxQWX433QJDMk5l7HxSc7v9GUe93
	 EFbwpnrKw+vz7WZ0LKdtVFXImKJtEaYLCOYG5SeLyVA7+GU6OVZD+ZN3x46kMILhdg5ee
	 kF6B9x+BY9FG1bvtfnqkE0QhWpzFGshBYxP6i2Mq4+U1JxqCnPv4WmC3h49zPTN0cYA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795454322;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=9m8KFjyLBuEGWvkUX+zuLasC9JtQT3T+Xo3Iyb1Jbik=;
	b=Vp7KXOiWxqCKYbuMDGNNWTvW78MW2yjVo3PjnbV1LDVJSePfg7/6RgJMeFoSEdMLEKc2
	 IM6rvTZC3sQ1JJ+Kn9LiPJvU8fkhZKCL2v6ykB/8PeCumCKqQGYuP1cac9j7CRBqnL6ks
	 I1y54o4Gf8ckHJOut0WHio9MQsg8xWJodRu+2mBl/wzpNhDLjHq61WgRTbyhE0Dl+A1tD
	 htD8fgsyyZfB9+qa4nezUYBpXdhl9zaxzuUS5CxWzD8/gGSjylfS4OjXtO216VSumLXo4
	 OQSWl2gcoH3cHBOFjty/NHieJRxqP8W8jRfTaCDkcLmlKUDX2tgShVNHUwvayGSVQww==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=h+CzS7Ze;
	arc=none smtp.remote-ip=23.88.38.48
X-Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id B090C606A33E
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 17:18:41 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B090C606A33E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de
X-Received: from kero.packetmixer.de (p200300C59714C2E05A704819B6ba2dB4.dip0.t-ipconnect.de [IPv6:2003:c5:9714:c2e0:5a70:4819:b6ba:2db4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mail.simonwunderlich.de (Postfix) with UTF8SMTPSA id 3F4A4FA3DF;
	Mon, 23 Nov 2026 18:18:37 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de;
	s=09092022; t=1795454317;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=9m8KFjyLBuEGWvkUX+zuLasC9JtQT3T+Xo3Iyb1Jbik=;
	b=h+CzS7Zeg4SrAgyhXb5EYaIW3fxAdHGe4dgbyg1g/zRqMNVT4A7E6QBL7IQMlTVQZs0Ggj
	GhLLUWoxlCMcGdEBWV9ddQV9GSQaKQg+NIjkKJYZmX40f0eyr+I6bulKdlFPRW/A7pbHWj
	s6QpFJ4JpwaNhZPj52A+pVzwtEfm9YMloVWMRDpXaQChZpVs9D0XZkNi/M2GnJVMnsg3Kb
	GzHMMAzoYaXScVdkB4g0l4AqBItMxncT9iy4NXl2LmAQIpD5rO2wKZCSGuJKNdmfonXBzi
	zJsNj8A4sY1U9eyqI9oMuVcMY77fXlSN8GdHgEfQbW76dzqyPuOHkoUiLjBUkg==
X-Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	b.a.t.m.a.n@lists.open-mesh.org,
	Sven Eckelmann <sven@narfation.org>,
	Sashiko <sashiko-bot@kernel.org>,
	Simon Wunderlich <sw@simonwunderlich.de>
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de>
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