From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
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>
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 [thread overview]
Message-ID: <20261123171827.3294525-7-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de>
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
next prev parent reply other threads:[~2026-11-23 17:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:18 [PATCH net-next 00/15] pull request for net-next: batman-adv 2026-11-23 Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 01/15] batman-adv: document refcount of returned objects Simon Wunderlich
2026-11-23 17:23 ` netdev-bot+sinfo
2026-11-23 17:18 ` [PATCH net-next 02/15] batman-adv: mcast: use mla_lock also during mcast_free Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 03/15] batman-adv: mark functions inheriting critical sections Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 04/15] batman-adv: bla: register own backbone gw when claiming for local node Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 05/15] batman-adv: tt: unhash local entries with hlist_del_init_rcu() Simon Wunderlich
2026-11-23 17:18 ` Simon Wunderlich [this message]
2026-11-23 17:18 ` [PATCH net-next 07/15] batman-adv: tt: don't remove unhashed local entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 08/15] batman-adv: tt: don't queue local events for unhashed entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 09/15] batman-adv: tt: remove unannounced local entries via pending state Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 10/15] batman-adv: tt: keep local entry unchanged when ADD can't be queued Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 11/15] batman-adv: tt: requeue DEL of pending local entry after failed allocation Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 12/15] batman-adv: tt: extract removal of pending local entry Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 13/15] batman-adv: tt: commit only the announced local changes Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 14/15] batman-adv: tt: avoid list_lock for unchanged local clients Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 15/15] batman-adv: tt: drop ADD+DEL events of never announced clients Simon Wunderlich
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=20261123171827.3294525-7-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=sven@narfation.org \
/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