* [PATCH batadv v5 01/11] batman-adv: tt: unhash local entries with hlist_del_init_rcu()
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 02/11] batman-adv: tt: refresh local entry in single flags_lock section Sven Eckelmann
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
A context which looked up a local TT entry via RCU has no way to find out
whether the entry was removed from the local hash in the meantime.
hlist_del_rcu() leaves the pprev pointer of the node untouched and
hlist_unhashed() therefore still reports the entry as hashed.
Use hlist_del_init_rcu() when a local entry is unhashed by
batadv_tt_local_purge_pending_clients() and batadv_tt_local_table_free().
hlist_unhashed() can then be used under the hash bucket list_lock to check
whether an entry is still part of the local table.
batadv_tt_local_remove_now() still unhashes via batadv_hash_remove(). It is
converted when it is merged into the locked removal path.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index b9407ad5..fabc4879 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1940,7 +1940,7 @@ static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_common_entry, node_tmp,
head, hash_entry) {
- hlist_del_rcu(&tt_common_entry->hash_entry);
+ hlist_del_init_rcu(&tt_common_entry->hash_entry);
tt_local = container_of(tt_common_entry,
struct batadv_tt_local_entry,
common);
@@ -4517,7 +4517,7 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
tt_common->key.addr,
batadv_print_vid(tt_common->key.vid));
- hlist_del_rcu(&tt_common->hash_entry);
+ hlist_del_init_rcu(&tt_common->hash_entry);
atomic_inc(&hash->generation);
/* An entry which still carries BATADV_TT_CLIENT_NEW was
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 02/11] batman-adv: tt: refresh local entry in single flags_lock section
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 01/11] batman-adv: tt: unhash local entries with hlist_del_init_rcu() Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 03/11] batman-adv: tt: don't remove unhashed local entries Sven Eckelmann
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
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.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
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 fabc4879..a86a4d70 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -956,57 +956,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
@@ -1081,27 +1030,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
*/
@@ -1123,10 +1108,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);
+ }
}
/**
@@ -1162,8 +1150,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)
@@ -1183,18 +1170,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
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 03/11] batman-adv: tt: don't remove unhashed local entries
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 01/11] batman-adv: tt: unhash local entries with hlist_del_init_rcu() Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 02/11] batman-adv: tt: refresh local entry in single flags_lock section Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 04/11] batman-adv: tt: don't queue local events for unhashed entries Sven Eckelmann
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
batadv_tt_local_remove() looks up the local entry via RCU only.
batadv_tt_local_purge_pending_clients() can unhash it before
batadv_tt_local_mark_removed() acquired the hash bucket list_lock. The DEL
is then queued for a client which is no longer part of the local table (and
its CRC). And it might replace the queued ADD of a new entry which was
added for the same client in the meantime.
The removal of an entry which still carries BATADV_TT_CLIENT_NEW has a
similar problem. The flag is checked by batadv_tt_local_mark_removed() but
the entry is only unhashed by batadv_tt_local_remove_now() after the
list_lock was released. batadv_tt_local_transition_new() can commit the
entry between both steps.
Merge batadv_tt_local_mark_removed() and batadv_tt_local_remove_now() into
batadv_tt_local_remove_entry() to get a single region which is protected by
the list_lock and the flags_lock of the entry:
* An entry which was unhashed after it was looked up is ignored: no DEL is
queued and BATADV_NO_FLAGS is reported as previous flags.
* An entry which still carries BATADV_TT_CLIENT_NEW is unhashed under the
list_lock which was used to check this flag.
batadv_tt_local_transition_new() can therefore no longer commit the entry
between the check and the removal. The workaround for the local table
size is no longer needed.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 144 ++++++++++++++++---------------------
1 file changed, 62 insertions(+), 82 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index a86a4d70..dd277c01 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -705,10 +705,14 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
*
* Only a single change per client is queued. It describes the latest state of
* the client and a new event therefore replaces an already queued one.
+ *
+ * The caller must hold the flags_lock of @common. The events of an entry are
+ * then queued in the same order in which its flags were modified.
*/
static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
const struct batadv_tt_common_entry *common,
u8 flags)
+ __must_hold(&common->flags_lock)
{
struct batadv_tt_change_node *tt_change_node;
struct batadv_tt_change_node *entry;
@@ -716,6 +720,8 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
bool del_op_requested;
size_t changes;
+ lockdep_assert_held(&common->flags_lock);
+
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
if (!tt_change_node)
return;
@@ -767,23 +773,6 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
}
-/**
- * batadv_tt_local_event() - store a local TT event (ADD/DEL)
- * @bat_priv: the bat priv with all the mesh interface information
- * @tt_local_entry: the TT entry involved in the event
- * @event_flags: flags to store in the event structure
- */
-static void batadv_tt_local_event(struct batadv_priv *bat_priv,
- struct batadv_tt_local_entry *tt_local_entry,
- u8 event_flags)
-{
- struct batadv_tt_common_entry *common = &tt_local_entry->common;
- u8 flags;
-
- flags = batadv_tt_flags_get(common) | event_flags;
- __batadv_tt_local_event(bat_priv, common, flags);
-}
-
/**
* batadv_tt_entries() - compute the number of entries fitting in tt_len bytes
* @tt_len: available space
@@ -1667,10 +1656,14 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
* entry. The entry is kept in the local table until the next TTVN increment
* so that a consistency-check response can still be answered.
*
- * Next to the flags_lock of the entry, the caller must hold the hash bucket
- * list_lock of @tt_local_entry. Otherwise
- * batadv_tt_local_purge_pending_clients() could remove the entry before its
- * change was queued.
+ * The caller must hold the flags_lock of @tt_local_entry and must not have
+ * released it since it checked that the entry has to be removed. Both the
+ * queue-then-mark order and this single flags_lock section are required.
+ *
+ * The caller must also hold the hash bucket list_lock of @tt_local_entry and
+ * must have ensured that the entry is still part of the local table. A DEL for
+ * an entry which was already purged could otherwise cancel the ADD of a new
+ * entry for the same client.
*/
static void
batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
@@ -1696,31 +1689,39 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
}
/**
- * batadv_tt_local_mark_removed() - mark a local entry as removed and queue DEL
+ * batadv_tt_local_remove_entry() - logically remove a local entry
* @bat_priv: the bat priv with all the mesh interface information
- * @tt_local_entry: local TT entry to mark
+ * @tt_local_entry: local TT entry to remove
* @message: message to append to the log on deletion
* @roaming: true if the deletion is due to a roaming event
- * @curr_flags: pointer to store the flags of the entry before it was marked
+ * @curr_flags: pointer to store the flags of the entry before it was removed
*
- * An already announced entry is marked as BATADV_TT_CLIENT_PENDING and the
- * (roamed) DEL change is queued. Both happen under the hash bucket list_lock
- * of the entry to prevent concurrent batadv_tt_local_purge_pending_clients()
- * from removing the entry and batadv_tt_local_transition_new() from clearing
- * BATADV_TT_CLIENT_NEW after it was checked.
+ * For an already announced entry, the (roamed) DEL change is queued and the
+ * entry is marked as BATADV_TT_CLIENT_PENDING by batadv_tt_local_set_pending().
+ * It stays in the local table until the next ttvn increment.
*
- * Return: true if the entry has to be kept in the local table until the next
- * ttvn increment, false if it can be purged immediately.
+ * An entry which still carries BATADV_TT_CLIENT_NEW was added right after the
+ * last ttvn increment and was not (yet) announced. It is therefore removed
+ * from the local table immediately.
+ *
+ * An entry which was already removed from the local table after it was looked
+ * up is ignored and BATADV_NO_FLAGS is stored in @curr_flags.
+ *
+ * All checks and modifications happen under the hash bucket list_lock and the
+ * flags_lock of the entry. This prevents a concurrent
+ * batadv_tt_local_purge_pending_clients() from removing the entry,
+ * batadv_tt_local_transition_new() from clearing BATADV_TT_CLIENT_NEW and
+ * batadv_tt_local_refresh() from modifying the entry after it was checked.
*/
-static bool
-batadv_tt_local_mark_removed(struct batadv_priv *bat_priv,
+static void
+batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
const char *message, bool roaming, u16 *curr_flags)
{
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
- bool pending = false;
+ bool unhashed = false;
u16 flags;
u32 i;
@@ -1729,6 +1730,12 @@ batadv_tt_local_mark_removed(struct batadv_priv *bat_priv,
spin_lock_bh(list_lock);
+ if (hlist_unhashed(&common->hash_entry)) {
+ *curr_flags = BATADV_NO_FLAGS;
+ spin_unlock_bh(list_lock);
+ return;
+ }
+
scoped_guard(spinlock_bh, &common->flags_lock) {
*curr_flags = common->flags;
@@ -1739,8 +1746,23 @@ batadv_tt_local_mark_removed(struct batadv_priv *bat_priv,
if (roaming)
common->flags |= BATADV_TT_CLIENT_ROAM;
- if (common->flags & BATADV_TT_CLIENT_NEW)
+ if (common->flags & BATADV_TT_CLIENT_NEW) {
+ batadv_dbg(BATADV_DBG_TT, bat_priv,
+ "Deleting local tt entry (%pM, vid: %d): %s\n",
+ common->key.addr,
+ batadv_print_vid(common->key.vid), message);
+
+ hlist_del_init_rcu(&common->hash_entry);
+ atomic_inc(&hash->generation);
+
+ /* The entry was never announced and was therefore
+ * never counted in the local table size.
+ */
+ __batadv_tt_local_event(bat_priv, common,
+ common->flags | BATADV_TT_CLIENT_DEL);
+ unhashed = true;
break;
+ }
flags = BATADV_TT_CLIENT_DEL;
if (roaming)
@@ -1748,51 +1770,13 @@ batadv_tt_local_mark_removed(struct batadv_priv *bat_priv,
batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
message);
- pending = true;
}
spin_unlock_bh(list_lock);
- return pending;
-}
-
-/**
- * batadv_tt_local_remove_now() - purge a local entry which was not (yet) announced
- * @bat_priv: the bat priv with all the mesh interface information
- * @tt_local_entry: local TT entry to purge
- *
- * A client which was added right after the last ttvn increment was not (yet)
- * sent to the other nodes. It can therefore be dropped from the local table
- * without waiting for the next ttvn increment.
- *
- * If it was still announced by a parallel context before it was removed from
- * the hash, then the local TT size adjustment will be handled automatically.
- */
-static void
-batadv_tt_local_remove_now(struct batadv_priv *bat_priv,
- struct batadv_tt_local_entry *tt_local_entry)
-{
- struct batadv_tt_common_entry *common = &tt_local_entry->common;
- struct hlist_node *tt_removed_node;
-
- /* remove exactly this object when still present in hash */
- tt_removed_node = batadv_hash_remove(bat_priv->tt.local_hash,
- batadv_compare_tt_entry,
- batadv_choose_tt, &common->key);
- if (!tt_removed_node)
- return;
-
- batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
-
- /* batadv_tt_local_transition_new() may have committed the entry and
- * thus counted it in the local table size since the
- * BATADV_TT_CLIENT_NEW check in batadv_tt_local_mark_removed().
- */
- if (!(batadv_tt_flags_get(common) & BATADV_TT_CLIENT_NEW))
- batadv_tt_local_size_dec(bat_priv, common->key.vid);
-
- /* drop reference of remove hash entry */
- batadv_tt_local_entry_put(tt_local_entry);
+ /* drop reference of removed hash entry */
+ if (unhashed)
+ batadv_tt_local_entry_put(tt_local_entry);
}
/**
@@ -1816,12 +1800,8 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,
if (!tt_local_entry)
return BATADV_NO_FLAGS;
- /* if this client has been added right now, it is possible to
- * immediately purge it
- */
- if (!batadv_tt_local_mark_removed(bat_priv, tt_local_entry, message,
- roaming, &curr_flags))
- batadv_tt_local_remove_now(bat_priv, tt_local_entry);
+ batadv_tt_local_remove_entry(bat_priv, tt_local_entry, message,
+ roaming, &curr_flags);
batadv_tt_local_entry_put(tt_local_entry);
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 04/11] batman-adv: tt: don't queue local events for unhashed entries
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (2 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 03/11] batman-adv: tt: don't remove unhashed local entries Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 05/11] batman-adv: tt: remove unannounced local entries via pending state Sven Eckelmann
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Sashiko
batadv_tt_local_add() looks up the local entry via RCU only.
batadv_tt_local_purge_pending_clients() or batadv_tt_local_remove() can
unhash it before the entry is modified and an event is queued for it:
CPU0 CPU1
/* DEL#1 queued, PENDING set */
batadv_tt_local_hash_find()
batadv_tt_local_commit_changes()
..._purge_pending_clients()
hlist_del_rcu(&...->hash_entry);
/* DEL#1 announced */
batadv_tt_local_refresh()
flags &= ~..._PENDING;
/* ADD queued for unhashed entry */
The queued event will then be announced for a client which is not part
anymore of the table (+ its CRC). A full table request in this and similar
scenarios is required to fix the inconsistency.
Only the hash bucket list_lock can ensure that an entry is still part of
the local table. batadv_tt_local_refresh() therefore checks with
hlist_unhashed() under this lock whether the entry is still hashed. An
entry which is no longer hashed is not refreshed and batadv_tt_local_add()
creates a new entry instead. batadv_tt_local_insert() adds this entry to
the hash and queues its initial ADD under the same list_lock. Otherwise
batadv_tt_local_commit_changes() could count the entry in the CRC of a ttvn
before its ADD was queued or batadv_tt_local_remove() could unhash it
before the ADD was queued.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930094558.3723766-2-sw%40simonwunderlich.de?part=7
Closes: https://sashiko.dev/#/bug/linux-557fd001-5041-4b0a-a2ea-cdf22526ee84
Closes: https://sashiko.dev/#/bug/linux-c7f17a4b-620f-4307-a058-be6523cc6fa2
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 156 ++++++++++++++++++++++++++++++-------
1 file changed, 129 insertions(+), 27 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index dd277c01..a5b34095 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1019,7 +1019,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
}
/**
- * batadv_tt_local_refresh() - refresh a local TT entry of an active client
+ * batadv_tt_local_refresh_locked() - refresh a hashed local TT entry
* @bat_priv: the bat priv with all the mesh interface information
* @tt_local: the local TT entry to refresh
* @iif_is_wifi: whether the client is connected via a wifi interface
@@ -1033,19 +1033,23 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
* 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.
+ * The caller must hold the hash bucket list_lock of the entry and must have
+ * checked that the entry is still part of the local table.
*/
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)
+batadv_tt_local_refresh_locked(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;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
u8 remote_flags;
u32 match_mark;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ lockdep_assert_held(&hash->list_locks[i]);
scoped_guard(spinlock_bh, &common->flags_lock) {
if (common->flags & BATADV_TT_CLIENT_PENDING) {
@@ -1106,6 +1110,109 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
}
}
+/**
+ * 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 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)
+ * @roamed_back: set to true when the client returned to its original location
+ *
+ * See batadv_tt_local_refresh_locked() for the actual refresh.
+ *
+ * Return: 0 if the entry was refreshed, -ENOENT if the entry is no longer part
+ * of the local table.
+ */
+static int
+batadv_tt_local_refresh(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ bool iif_is_wifi, u32 mark, bool *roamed_back)
+{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_tt_common_entry *common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ list_lock = &hash->list_locks[i];
+
+ WRITE_ONCE(tt_local->last_seen, jiffies);
+
+ spin_lock_bh(list_lock);
+
+ /* the entry was removed from the local table after it was looked up */
+ if (hlist_unhashed(&common->hash_entry)) {
+ spin_unlock_bh(list_lock);
+ return -ENOENT;
+ }
+
+ batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
+ false, roamed_back);
+
+ spin_unlock_bh(list_lock);
+
+ return 0;
+}
+
+/**
+ * batadv_tt_local_insert() - add a new local TT entry to the local table
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local: the new local TT entry (not yet hashed)
+ * @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)
+ * @roamed_back: set to true when the client returned to its original location
+ *
+ * The entry is inserted into the local hash and its initial ADD event is
+ * queued under the same hash bucket list_lock. A concurrent
+ * batadv_tt_local_commit_changes() can therefore not count the entry in the
+ * CRC of a ttvn before its ADD was queued and a concurrent
+ * batadv_tt_local_remove() can not unhash it before the ADD was queued.
+ *
+ * Return: true if the entry was added, false if the client already has an
+ * entry in the local table.
+ */
+static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ bool iif_is_wifi, u32 mark,
+ bool *roamed_back)
+{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_tt_common_entry *common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ struct hlist_head *head;
+ struct hlist_node *node;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+
+ spin_lock_bh(list_lock);
+
+ hlist_for_each(node, head) {
+ if (!batadv_compare_tt(node, &common->key))
+ continue;
+
+ spin_unlock_bh(list_lock);
+ return false;
+ }
+
+ /* reference for the hash */
+ kref_get(&common->refcount);
+ hlist_add_head_rcu(&common->hash_entry, head);
+ atomic_inc(&hash->generation);
+
+ /* announce the added client to the mesh */
+ batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
+ true, roamed_back);
+
+ spin_unlock_bh(list_lock);
+
+ return true;
+}
+
/**
* batadv_tt_local_add() - add a new client to the local table or update an
* existing client
@@ -1126,10 +1233,9 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
struct batadv_tt_global_entry *tt_global = NULL;
struct batadv_tt_local_entry *tt_local;
bool roamed_back = false;
- bool added = false;
bool iif_is_wifi;
bool ret = false;
- int hash_added;
+ int err;
iif_is_wifi = batadv_tt_iif_is_wifi(dev_net(mesh_iface), ifindex);
@@ -1139,30 +1245,26 @@ 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) {
- WRITE_ONCE(tt_local->last_seen, jiffies);
- } else {
+ err = batadv_tt_local_refresh(bat_priv, tt_local, iif_is_wifi,
+ mark, &roamed_back);
+ if (err == -ENOENT) {
+ /* stale entry which has to be replaced by a new one */
+ batadv_tt_local_entry_put(tt_local);
+ tt_local = NULL;
+ }
+ }
+
+ if (!tt_local) {
tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi);
if (!tt_local)
goto out;
- kref_get(&tt_local->common.refcount);
- hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
- batadv_choose_tt, &tt_local->common.key,
- &tt_local->common.hash_entry);
-
- if (unlikely(hash_added != 0)) {
- /* remove the reference for the hash */
- batadv_tt_local_entry_put(tt_local);
+ if (unlikely(!batadv_tt_local_insert(bat_priv, tt_local,
+ iif_is_wifi, mark,
+ &roamed_back)))
goto out;
- }
-
- added = true;
}
- /* 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);
ret = true;
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 05/11] batman-adv: tt: remove unannounced local entries via pending state
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (3 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 04/11] batman-adv: tt: don't queue local events for unhashed entries Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 06/11] batman-adv: tt: keep local entry unchanged when ADD can't be queued Sven Eckelmann
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
batadv_tt_local_remove_entry() unhashes an entry which still carries
BATADV_TT_CLIENT_NEW immediately because it was not yet announced to the
other nodes. But the flag is only cleared at the end of the commit. The ADD
of the entry might therefore already have been taken for the next TTVN when
the flag is checked.
Handle such an entry like an already announced one: queue the DEL and mark
the entry as BATADV_TT_CLIENT_PENDING. It is then removed from the local
table when the pending entries are purged by the next commit.
batadv_tt_local_purge_pending_clients() already takes care of not
uncounting an entry which was never counted.
This also leaves the commit as the only place which finishes the removal of
a local entry. A follow-up change relies on this to apply exactly the
announced changes to the local table.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 35 +++++------------------------------
1 file changed, 5 insertions(+), 30 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index a5b34095..ab8b9699 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1798,13 +1798,11 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
* @roaming: true if the deletion is due to a roaming event
* @curr_flags: pointer to store the flags of the entry before it was removed
*
- * For an already announced entry, the (roamed) DEL change is queued and the
- * entry is marked as BATADV_TT_CLIENT_PENDING by batadv_tt_local_set_pending().
- * It stays in the local table until the next ttvn increment.
- *
- * An entry which still carries BATADV_TT_CLIENT_NEW was added right after the
- * last ttvn increment and was not (yet) announced. It is therefore removed
- * from the local table immediately.
+ * The (roamed) DEL change is queued and the entry is marked as
+ * BATADV_TT_CLIENT_PENDING by batadv_tt_local_set_pending(). It stays in the
+ * local table until the DEL is committed with the next ttvn increment. This
+ * also applies to an entry which still carries BATADV_TT_CLIENT_NEW because its
+ * ADD might already have been taken for the next ttvn.
*
* An entry which was already removed from the local table after it was looked
* up is ignored and BATADV_NO_FLAGS is stored in @curr_flags.
@@ -1823,7 +1821,6 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
- bool unhashed = false;
u16 flags;
u32 i;
@@ -1848,24 +1845,6 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
if (roaming)
common->flags |= BATADV_TT_CLIENT_ROAM;
- if (common->flags & BATADV_TT_CLIENT_NEW) {
- batadv_dbg(BATADV_DBG_TT, bat_priv,
- "Deleting local tt entry (%pM, vid: %d): %s\n",
- common->key.addr,
- batadv_print_vid(common->key.vid), message);
-
- hlist_del_init_rcu(&common->hash_entry);
- atomic_inc(&hash->generation);
-
- /* The entry was never announced and was therefore
- * never counted in the local table size.
- */
- __batadv_tt_local_event(bat_priv, common,
- common->flags | BATADV_TT_CLIENT_DEL);
- unhashed = true;
- break;
- }
-
flags = BATADV_TT_CLIENT_DEL;
if (roaming)
flags |= BATADV_TT_CLIENT_ROAM;
@@ -1875,10 +1854,6 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
}
spin_unlock_bh(list_lock);
-
- /* drop reference of removed hash entry */
- if (unhashed)
- batadv_tt_local_entry_put(tt_local_entry);
}
/**
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 06/11] batman-adv: tt: keep local entry unchanged when ADD can't be queued
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (4 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 05/11] batman-adv: tt: remove unannounced local entries via pending state Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 07/11] batman-adv: tt: requeue DEL of pending local entry after failed allocation Sven Eckelmann
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
The allocation of a local TT change can fail. __batadv_tt_local_event()
drops the event silently in this case. But the local entry was already
modified at this point: a new entry was inserted, the removal of a pending
entry was cancelled or the flags of the entry were changed. The other nodes
are never informed about this new state and the local table no longer
matches the announced one.
Let __batadv_tt_local_event() report whether the event was stored and only
modify the entry afterwards:
* batadv_tt_local_refresh_locked() prepares the new flags, queues the ADD
and only then stores the flags in the entry. The entry stays untouched
when the ADD could not be queued and the refresh is retried with the next
packet of the client.
* batadv_tt_local_insert() queues the initial ADD before it inserts the
entry in the hash. Both still happen under the same hash bucket
list_lock. A new entry is not inserted when its ADD could not be queued
and batadv_tt_local_add() fails.
* batadv_tt_local_refresh() reports the failed refresh to
batadv_tt_local_add() which fails too. The caller would otherwise
continue with an entry which is still in its previous state: the
multicast code would stop to retry the add of a listener whose entry is
still pending to be removed and batadv_interface_tx() would forward a
packet of a client with outdated flags. A client which came back is also
still marked as BATADV_TT_CLIENT_ROAM. batadv_tt_local_add_roam() is
therefore skipped. It would otherwise treat the client as newly roamed
instead of cancelling the roaming.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 139 ++++++++++++++++++++++++++-----------
1 file changed, 98 insertions(+), 41 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index ab8b9699..3bb74e05 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -706,10 +706,18 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
* Only a single change per client is queued. It describes the latest state of
* the client and a new event therefore replaces an already queued one.
*
+ * The other nodes only learn about the modification of a local entry through
+ * the queued change. The caller must therefore not modify the entry in a way
+ * which depends on this change (e.g. hash it as BATADV_TT_CLIENT_NEW or mark it
+ * as BATADV_TT_CLIENT_PENDING) when the event could not be stored.
+ *
* The caller must hold the flags_lock of @common. The events of an entry are
* then queued in the same order in which its flags were modified.
+ *
+ * Return: true if the event was stored, false if the memory for it could not
+ * be allocated.
*/
-static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
+static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
const struct batadv_tt_common_entry *common,
u8 flags)
__must_hold(&common->flags_lock)
@@ -724,7 +732,7 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
if (!tt_change_node)
- return;
+ return false;
memset(tt_change_node->change.reserved, 0,
sizeof(tt_change_node->change.reserved));
@@ -771,6 +779,8 @@ static void __batadv_tt_local_event(struct batadv_priv *bat_priv,
update_changes:
WRITE_ONCE(bat_priv->tt.local_changes, changes);
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
+
+ return true;
}
/**
@@ -1019,7 +1029,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
}
/**
- * batadv_tt_local_refresh_locked() - refresh a hashed local TT entry
+ * batadv_tt_local_refresh_locked() - refresh a local TT entry
* @bat_priv: the bat priv with all the mesh interface information
* @tt_local: the local TT entry to refresh
* @iif_is_wifi: whether the client is connected via a wifi interface
@@ -1033,10 +1043,19 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
* 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.
*
+ * The entry is left untouched when the ADD event could not be queued. The
+ * other nodes would otherwise never be informed about the new state. An already
+ * hashed entry is simply refreshed again when the next packet of the client is
+ * received.
+ *
* The caller must hold the hash bucket list_lock of the entry and must have
- * checked that the entry is still part of the local table.
+ * checked that the entry is still part of the local table or is inserting it
+ * under this list_lock.
+ *
+ * Return: true if the entry was refreshed, false if the required ADD event
+ * could not be queued.
*/
-static void
+static bool
batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local,
bool iif_is_wifi, u32 mark, bool announce,
@@ -1044,51 +1063,49 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool readded = false;
+ bool roamed = false;
u8 remote_flags;
u32 match_mark;
+ u16 flags;
u32 i;
i = batadv_choose_tt(&common->key, hash->size);
lockdep_assert_held(&hash->list_locks[i]);
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));
+ flags = common->flags;
+
+ if (flags & BATADV_TT_CLIENT_PENDING) {
/* 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;
+ flags &= ~BATADV_TT_CLIENT_PENDING;
+ readded = true;
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));
+ if (flags & BATADV_TT_CLIENT_ROAM) {
/* 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;
+ flags &= ~BATADV_TT_CLIENT_ROAM;
+ roamed = true;
}
/* store the current remote flags before altering them. This
* helps understanding is flags are changing or not
*/
- remote_flags = common->flags & BATADV_TT_REMOTE_MASK;
+ remote_flags = flags & BATADV_TT_REMOTE_MASK;
if (iif_is_wifi)
- common->flags |= BATADV_TT_CLIENT_WIFI;
+ flags |= BATADV_TT_CLIENT_WIFI;
else
- common->flags &= ~BATADV_TT_CLIENT_WIFI;
+ flags &= ~BATADV_TT_CLIENT_WIFI;
/* check the mark in the skb: if it's equal to the configured
* isolation_mark, it means the packet is coming from an
@@ -1097,17 +1114,38 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
match_mark = (mark & bat_priv->isolation_mark_mask);
if (bat_priv->isolation_mark_mask &&
match_mark == bat_priv->isolation_mark)
- common->flags |= BATADV_TT_CLIENT_ISOLA;
+ flags |= BATADV_TT_CLIENT_ISOLA;
else
- common->flags &= ~BATADV_TT_CLIENT_ISOLA;
+ flags &= ~BATADV_TT_CLIENT_ISOLA;
- if (remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK))
+ if (remote_flags ^ (flags & BATADV_TT_REMOTE_MASK))
announce = true;
- if (announce)
- __batadv_tt_local_event(bat_priv, common,
- common->flags);
+ /* queue-then-modify: the new state must not become visible
+ * without a queued change which commits/announces it
+ */
+ if (announce &&
+ !__batadv_tt_local_event(bat_priv, common, flags))
+ return false;
+
+ common->flags = flags;
}
+
+ if (readded)
+ batadv_dbg(BATADV_DBG_TT, bat_priv,
+ "Re-adding pending client %pM (vid: %d)\n",
+ common->key.addr,
+ batadv_print_vid(common->key.vid));
+
+ if (roamed) {
+ 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));
+ *roamed_back = true;
+ }
+
+ return true;
}
/**
@@ -1121,8 +1159,11 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
*
* See batadv_tt_local_refresh_locked() for the actual refresh.
*
+ * An entry whose modification could not be announced stays in its previous
+ * state. The refresh is then retried with the next packet of the client.
+ *
* Return: 0 if the entry was refreshed, -ENOENT if the entry is no longer part
- * of the local table.
+ * of the local table, -ENOMEM if the required ADD event could not be queued.
*/
static int
batadv_tt_local_refresh(struct batadv_priv *bat_priv,
@@ -1132,6 +1173,7 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ int ret = 0;
u32 i;
i = batadv_choose_tt(&common->key, hash->size);
@@ -1147,12 +1189,13 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
return -ENOENT;
}
- batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
- false, roamed_back);
+ if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi,
+ mark, false, roamed_back))
+ ret = -ENOMEM;
spin_unlock_bh(list_lock);
- return 0;
+ return ret;
}
/**
@@ -1164,14 +1207,17 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
* any)
* @roamed_back: set to true when the client returned to its original location
*
- * The entry is inserted into the local hash and its initial ADD event is
- * queued under the same hash bucket list_lock. A concurrent
- * batadv_tt_local_commit_changes() can therefore not count the entry in the
- * CRC of a ttvn before its ADD was queued and a concurrent
- * batadv_tt_local_remove() can not unhash it before the ADD was queued.
+ * The initial ADD event is queued and the entry is inserted into the local
+ * hash under the same hash bucket list_lock. A concurrent
+ * batadv_tt_local_commit_changes() can therefore not commit the entry without
+ * its ADD (or the ADD without the entry) and a concurrent
+ * batadv_tt_local_remove() can not unhash the entry before the ADD was queued.
+ *
+ * The entry is not inserted when its ADD could not be queued. The other nodes
+ * would otherwise never be informed about the new client.
*
* Return: true if the entry was added, false if the client already has an
- * entry in the local table.
+ * entry in the local table or the ADD event could not be queued.
*/
static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local,
@@ -1199,15 +1245,18 @@ static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
return false;
}
+ /* announce the added client to the mesh */
+ if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi,
+ mark, true, roamed_back)) {
+ spin_unlock_bh(list_lock);
+ return false;
+ }
+
/* reference for the hash */
kref_get(&common->refcount);
hlist_add_head_rcu(&common->hash_entry, head);
atomic_inc(&hash->generation);
- /* announce the added client to the mesh */
- batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
- true, roamed_back);
-
spin_unlock_bh(list_lock);
return true;
@@ -1251,6 +1300,14 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
/* stale entry which has to be replaced by a new one */
batadv_tt_local_entry_put(tt_local);
tt_local = NULL;
+ } else if (err) {
+ /* The entry is still in its previous state (e.g.
+ * pending to be removed). The caller must not treat
+ * the client as added and the roaming is handled
+ * together with the refresh which is retried with the
+ * next packet of the client.
+ */
+ goto out;
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 07/11] batman-adv: tt: requeue DEL of pending local entry after failed allocation
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (5 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 06/11] batman-adv: tt: keep local entry unchanged when ADD can't be queued Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 08/11] batman-adv: tt: extract removal of pending local entry Sven Eckelmann
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
batadv_tt_local_set_pending() marks a local entry as
BATADV_TT_CLIENT_PENDING even when the DEL could not be queued because the
allocation of the change failed. The other nodes are then never informed
about the removal of the client. And nothing queues the DEL again because
an already pending entry is skipped by the purge.
The removal can also not simply be rejected. The callers of
batadv_tt_local_remove() don't retry it and a BATADV_TT_CLIENT_NOPURGE
entry would never be removed by the purge. And a roamed client must be
marked as BATADV_TT_CLIENT_ROAM right away to get its packets rerouted to
the new originator.
The entry is therefore still marked as before. But a pending entry whose
DEL could not be queued is now marked as del_unqueued:
* batadv_tt_local_purge_list() queues the DEL of such an entry again. This
is retried every BATADV_TT_WORK_PERIOD until it succeeds.
* batadv_tt_local_purge_pending_clients() keeps such an entry in the local
table until its DEL was queued. The local table then still matches the
table which was announced to the other nodes.
* batadv_tt_local_refresh_locked() drops the mark when the client was
detected again and the ADD for it was queued.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 63 ++++++++++++++++++++++++++++++--------
net/batman-adv/types.h | 7 +++++
2 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 3bb74e05..674b5c38 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -708,8 +708,10 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
*
* The other nodes only learn about the modification of a local entry through
* the queued change. The caller must therefore not modify the entry in a way
- * which depends on this change (e.g. hash it as BATADV_TT_CLIENT_NEW or mark it
- * as BATADV_TT_CLIENT_PENDING) when the event could not be stored.
+ * which depends on this change (e.g. hash it as BATADV_TT_CLIENT_NEW) when the
+ * event could not be stored. The only exception is the DEL of
+ * batadv_tt_local_set_pending(). Its entry is marked as del_unqueued to get the
+ * DEL requeued by batadv_tt_local_purge_list().
*
* The caller must hold the flags_lock of @common. The events of an entry are
* then queued in the same order in which its flags were modified.
@@ -1008,6 +1010,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
kref_init(&tt_local->common.refcount);
last_seen = jiffies;
WRITE_ONCE(tt_local->last_seen, last_seen);
+ tt_local->del_unqueued = false;
tt_local->common.added_at = last_seen;
tt_local->vlan = vlan;
spin_lock_init(&tt_local->common.flags_lock);
@@ -1129,6 +1132,12 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
return false;
common->flags = flags;
+
+ /* the queued ADD replaces the DEL which still had to be
+ * queued for the no longer pending entry
+ */
+ if (readded)
+ tt_local->del_unqueued = false;
}
if (readded)
@@ -1815,6 +1824,11 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
* entry. The entry is kept in the local table until the next TTVN increment
* so that a consistency-check response can still be answered.
*
+ * The entry is also marked as BATADV_TT_CLIENT_PENDING when the DEL could not
+ * be queued. The removal must not be lost because not all callers are able to
+ * retry it. Such an entry is marked as del_unqueued instead. It stays in the
+ * local table until batadv_tt_local_purge_list() was able to queue its DEL.
+ *
* The caller must hold the flags_lock of @tt_local_entry and must not have
* released it since it checked that the entry has to be removed. Both the
* queue-then-mark order and this single flags_lock section are required.
@@ -1832,13 +1846,24 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool queued;
u32 i;
i = batadv_choose_tt(&common->key, hash->size);
lockdep_assert_held(&hash->list_locks[i]);
lockdep_assert_held(&common->flags_lock);
- __batadv_tt_local_event(bat_priv, common, common->flags | flags);
+ queued = __batadv_tt_local_event(bat_priv, common,
+ common->flags | flags);
+
+ /* a failed attempt must not hide the still queued DEL of an already
+ * pending entry
+ */
+ if (queued)
+ tt_local_entry->del_unqueued = false;
+ else if (!(common->flags & BATADV_TT_CLIENT_PENDING))
+ tt_local_entry->del_unqueued = true;
+
common->flags |= BATADV_TT_CLIENT_PENDING;
batadv_dbg(BATADV_DBG_TT, bat_priv,
@@ -1964,11 +1989,18 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
common);
scoped_guard(spinlock_bh, &tt_local_entry->common.flags_lock) {
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
- break;
-
/* entry already marked for deletion */
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
+ if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) {
+ /* but its removal must still be announced */
+ if (tt_local_entry->del_unqueued)
+ batadv_tt_local_set_pending(bat_priv,
+ tt_local_entry,
+ BATADV_TT_CLIENT_DEL,
+ "requeued");
+ break;
+ }
+
+ if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
break;
if (!batadv_has_timed_out(READ_ONCE(tt_local_entry->last_seen),
@@ -4577,7 +4609,8 @@ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)
* @bat_priv: the bat priv with all the mesh interface information
*
* Iterate over the local TT and physically remove every entry that has been
- * marked as BATADV_TT_CLIENT_PENDING.
+ * marked as BATADV_TT_CLIENT_PENDING and whose DEL was queued. An entry which
+ * still waits for its DEL (del_unqueued) stays in the local table.
*/
static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
{
@@ -4601,12 +4634,22 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
hash_entry) {
bool cont = false;
+ tt_local = container_of(tt_common,
+ struct batadv_tt_local_entry,
+ common);
+
scoped_guard(spinlock_bh, &tt_common->flags_lock) {
if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING)) {
cont = true;
break;
}
+ /* the removal must be announced first */
+ if (tt_local->del_unqueued) {
+ cont = true;
+ break;
+ }
+
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Deleting local tt entry (%pM, vid: %d): pending\n",
tt_common->key.addr,
@@ -4625,10 +4668,6 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
if (cont)
continue;
- tt_local = container_of(tt_common,
- struct batadv_tt_local_entry,
- common);
-
batadv_tt_local_entry_put(tt_local);
}
spin_unlock_bh(list_lock);
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 8e590f19..d443143f 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1939,6 +1939,13 @@ struct batadv_tt_local_entry {
/** @last_seen: timestamp used for purging stale tt local entries */
unsigned long last_seen;
+ /**
+ * @del_unqueued: the DEL of this BATADV_TT_CLIENT_PENDING entry could
+ * not be queued and must be queued by the next purge. Protected by
+ * common.flags_lock
+ */
+ bool del_unqueued;
+
/** @vlan: mesh-interface vlan of the entry */
struct batadv_meshif_vlan *vlan;
};
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 08/11] batman-adv: tt: extract removal of pending local entry
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (6 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 07/11] batman-adv: tt: requeue DEL of pending local entry after failed allocation Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:41 ` [PATCH batadv v5 09/11] batman-adv: tt: commit only the announced local changes Sven Eckelmann
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
batadv_tt_local_purge_pending_clients() removes the entries which are
marked as BATADV_TT_CLIENT_PENDING from the local table. The actual removal
of a single entry has to follow some rules: an entry whose DEL still has to
be queued must stay in the local table and an entry which still carries
BATADV_TT_CLIENT_NEW was never counted and must not be uncounted.
Move the removal of a single entry to batadv_tt_local_unhash_pending(). It
can then be shared with the upcoming code which removes only the entry of a
committed DEL. The actual unhash steps are placed in
batadv_tt_local_unhash() because they will also be needed for entries which
are removed without going through the pending state. There is no functional
change.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 108 +++++++++++++++++++++++++++----------
1 file changed, 80 insertions(+), 28 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 674b5c38..89fed26b 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1813,6 +1813,44 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
return ret;
}
+/**
+ * batadv_tt_local_unhash() - remove an entry from the local table
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local: the local TT entry to remove
+ * @message: message to append to the log on deletion
+ *
+ * The caller must hold the hash bucket list_lock and the flags_lock of the
+ * entry. It must have checked that the entry is still part of the local table
+ * and has to drop the reference of the hash after it released the flags_lock.
+ */
+static void batadv_tt_local_unhash(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ const char *message)
+ __must_hold(&tt_local->common.flags_lock)
+{
+ struct batadv_tt_common_entry *tt_common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ u32 i;
+
+ i = batadv_choose_tt(&tt_common->key, hash->size);
+ lockdep_assert_held(&hash->list_locks[i]);
+ lockdep_assert_held(&tt_common->flags_lock);
+
+ batadv_dbg(BATADV_DBG_TT, bat_priv,
+ "Deleting local tt entry (%pM, vid: %d): %s\n",
+ tt_common->key.addr, batadv_print_vid(tt_common->key.vid),
+ message);
+
+ hlist_del_init_rcu(&tt_common->hash_entry);
+ atomic_inc(&hash->generation);
+
+ /* An entry which still carries BATADV_TT_CLIENT_NEW was never counted
+ * and must not be uncounted here.
+ */
+ if (!(tt_common->flags & BATADV_TT_CLIENT_NEW))
+ batadv_tt_local_size_dec(bat_priv, tt_common->key.vid);
+}
+
/**
* batadv_tt_local_set_pending() - mark local TT entry as pending removal
* @bat_priv: the bat priv with all the mesh interface information
@@ -4603,6 +4641,43 @@ static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)
}
}
+/**
+ * batadv_tt_local_unhash_pending() - remove a pending entry from the local table
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local: the local TT entry to remove
+ *
+ * Only an entry which is marked as BATADV_TT_CLIENT_PENDING and whose DEL was
+ * queued is removed. An entry which still waits for its DEL (del_unqueued) must
+ * stay in the local table until batadv_tt_local_purge_list() was able to queue
+ * it.
+ *
+ * The caller must hold the hash bucket list_lock and the flags_lock of the
+ * entry.
+ *
+ * Return: true if the entry was unhashed and the caller has to drop the
+ * reference of the hash, false otherwise.
+ */
+static bool
+batadv_tt_local_unhash_pending(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local)
+ __must_hold(&tt_local->common.flags_lock)
+{
+ struct batadv_tt_common_entry *tt_common = &tt_local->common;
+
+ lockdep_assert_held(&tt_common->flags_lock);
+
+ if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
+ return false;
+
+ /* the removal must be announced first */
+ if (tt_local->del_unqueued)
+ return false;
+
+ batadv_tt_local_unhash(bat_priv, tt_local, "pending");
+
+ return true;
+}
+
/**
* batadv_tt_local_purge_pending_clients() - finalise removal of pending local
* clients
@@ -4632,40 +4707,17 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_common, node_tmp, head,
hash_entry) {
- bool cont = false;
+ bool unhashed;
tt_local = container_of(tt_common,
struct batadv_tt_local_entry,
common);
- scoped_guard(spinlock_bh, &tt_common->flags_lock) {
- if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING)) {
- cont = true;
- break;
- }
+ scoped_guard(spinlock_bh, &tt_common->flags_lock)
+ unhashed = batadv_tt_local_unhash_pending(bat_priv,
+ tt_local);
- /* the removal must be announced first */
- if (tt_local->del_unqueued) {
- cont = true;
- break;
- }
-
- batadv_dbg(BATADV_DBG_TT, bat_priv,
- "Deleting local tt entry (%pM, vid: %d): pending\n",
- tt_common->key.addr,
- batadv_print_vid(tt_common->key.vid));
-
- hlist_del_init_rcu(&tt_common->hash_entry);
- atomic_inc(&hash->generation);
-
- /* An entry which still carries BATADV_TT_CLIENT_NEW was
- * never counted and must not be uncounted here.
- */
- if (!(tt_common->flags & BATADV_TT_CLIENT_NEW))
- batadv_tt_local_size_dec(bat_priv, tt_common->key.vid);
- }
-
- if (cont)
+ if (!unhashed)
continue;
batadv_tt_local_entry_put(tt_local);
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 09/11] batman-adv: tt: commit only the announced local changes
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (7 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 08/11] batman-adv: tt: extract removal of pending local entry Sven Eckelmann
@ 2026-11-18 11:41 ` Sven Eckelmann
2026-11-18 11:42 ` [PATCH batadv v5 10/11] batman-adv: tt: avoid list_lock for unchanged local clients Sven Eckelmann
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:41 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Sashiko
batadv_tt_local_commit_changes_nolock() takes the queued changes for the
new TTVN and then scans the complete local table: every
BATADV_TT_CLIENT_NEW entry is committed and every BATADV_TT_CLIENT_PENDING
entry is removed. But the local table is modified in parallel by
batadv_tt_local_add() and batadv_tt_local_remove(). An entry which was
added or marked for removal after the changes were taken is then already
part of the CRC (or already missing from it) of the new TTVN although its
ADD/DEL is only announced with the next one. The other nodes detect the CRC
mismatch and have to request the full table.
But there is already the list of batadv_tvlv_tt_change which belong to the
TTVN which is currently committed. Since its state it atomically extracted
by batadv_tt_local_commit_changes_nolock(), it can be used as stable source
for the operations which need to be applied on the local TT. The changes
are applied similar to the patching done for the global TT table after
receiving a TTVN changeset - but with the local TT specific flags state in
mind:
The ADD of an entry finishes its NEW state and the DEL of an entry removes
it from the local table.
An entry which was marked for removal after the changes were taken stays in
the table until its DEL is committed. This also applies to entries which
still carry BATADV_TT_CLIENT_NEW. But batadv_tt_local_resize_to_mtu() still
drops the pending entries directly. It holds the commit_lock and commits
the queued changes right away. The DEL of each dropped entry is therefore
announced with this commit.
The scan of the complete table also finished the entries whose ADD or DEL
was never queued because the allocation of the change failed. This is no
longer needed: an entry is not brought into the BATADV_TT_CLIENT_NEW state
without a queued ADD anymore and the DEL of a BATADV_TT_CLIENT_PENDING
entry is requeued by the purge until it was stored.
The client of a committed DEL might have been detected again after the
changes were taken. Its entry is then no longer pending or it was marked
for removal again but the new DEL could not be queued. Such an entry is not
removed because its ADD is queued for the next TTVN. But the other nodes
remove the client with the DEL of the current TTVN. The entry is therefore
brought back into the BATADV_TT_CLIENT_NEW state. It is then not part of
the CRC and of the full table responses until its ADD is committed.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-0de54f93-3f78-4500-b5ea-3c6973e51bf3
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 176 +++++++++++++++++++++++++++----------
1 file changed, 128 insertions(+), 48 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 89fed26b..c2f5b8a5 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -588,6 +588,12 @@ static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv,
* was removed from bat_priv->tt.local_hash (under the specific
* list_locks[i]) or when it is ensured that it is not accessible
* in this list.
+ *
+ * The only exception is an entry which stays in bat_priv->tt.local_hash but is
+ * brought back into the NEW state by batadv_tt_local_commit_change(). The NEW
+ * flag must then be set under the same list_locks[i] and the flags_lock of the
+ * entry. batadv_tt_local_size_inc() counts the entry again when its NEW flag
+ * is removed.
*/
static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv,
unsigned short vid)
@@ -1929,9 +1935,8 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
*
* All checks and modifications happen under the hash bucket list_lock and the
* flags_lock of the entry. This prevents a concurrent
- * batadv_tt_local_purge_pending_clients() from removing the entry,
- * batadv_tt_local_transition_new() from clearing BATADV_TT_CLIENT_NEW and
- * batadv_tt_local_refresh() from modifying the entry after it was checked.
+ * batadv_tt_local_commit_change() from removing the entry and
+ * batadv_tt_local_refresh() from modifying it after it was checked.
*/
static void
batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
@@ -4598,49 +4603,6 @@ void batadv_tt_free(struct batadv_priv *bat_priv)
kfree(bat_priv->tt.last_changeset);
}
-/**
- * batadv_tt_local_transition_new() - unset the NEW flag on the local
- * table and count them in the TT size
- * @bat_priv: the bat priv with all the mesh interface information
- */
-static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)
-{
- spinlock_t *list_lock; /* protects write access to the hash lists */
- struct batadv_hashtable *hash = bat_priv->tt.local_hash;
- struct batadv_tt_common_entry *tt_common_entry;
- struct hlist_head *head;
- u32 i;
-
- if (!hash)
- return;
-
- for (i = 0; i < hash->size; i++) {
- head = &hash->table[i];
- list_lock = &hash->list_locks[i];
-
- spin_lock_bh(list_lock);
- hlist_for_each_entry(tt_common_entry, head, hash_entry) {
- bool cont = false;
-
- scoped_guard(spinlock_bh, &tt_common_entry->flags_lock) {
- if (!(tt_common_entry->flags & BATADV_TT_CLIENT_NEW)) {
- cont = true;
- break;
- }
-
- tt_common_entry->flags &= ~BATADV_TT_CLIENT_NEW;
- }
-
- if (cont)
- continue;
-
- batadv_tt_local_size_inc(bat_priv,
- tt_common_entry->key.vid);
- }
- spin_unlock_bh(list_lock);
- }
-}
-
/**
* batadv_tt_local_unhash_pending() - remove a pending entry from the local table
* @bat_priv: the bat priv with all the mesh interface information
@@ -4678,6 +4640,112 @@ batadv_tt_local_unhash_pending(struct batadv_priv *bat_priv,
return true;
}
+/**
+ * batadv_tt_local_commit_change() - apply a committed change to the local table
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @change: the change which is announced with the new ttvn
+ *
+ * The CRC and the full table responses of a ttvn must reflect exactly the
+ * changes announced with it. Only the entry affected by a committed change is
+ * therefore modified. An entry which was added or marked for removal after the
+ * change set was taken stays in its current state until its own change is
+ * committed with a later ttvn.
+ *
+ * An ADD finishes the BATADV_TT_CLIENT_NEW state of the entry and it is counted
+ * as part of the local table from now on. A DEL removes the entry which is
+ * marked as BATADV_TT_CLIENT_PENDING from the local table.
+ *
+ * The entry is not protected by bat_priv->tt.commit_lock against a concurrent
+ * refresh and removal. The client of a committed DEL can therefore be detected
+ * again after the change set was taken. Its entry is then no longer
+ * BATADV_TT_CLIENT_PENDING or it was marked for removal again without a queued
+ * DEL (del_unqueued). Such an entry must stay hashed because its ADD is queued
+ * for a later ttvn. But the other nodes remove the client with the new ttvn.
+ * The entry is therefore brought back into the BATADV_TT_CLIENT_NEW state and
+ * is not counted as part of the local table until its ADD is committed.
+ *
+ * The caller must hold tt->commit_lock. It is the one which took @change from
+ * the queued changes of the new ttvn.
+ */
+static void
+batadv_tt_local_commit_change(struct batadv_priv *bat_priv,
+ const struct batadv_tvlv_tt_change *change)
+ __must_hold(&bat_priv->tt.commit_lock)
+{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ struct batadv_tt_local_entry *tt_local = NULL;
+ struct batadv_tt_common_entry *tt_common;
+ struct batadv_tt_common_entry_key key;
+ struct hlist_head *head;
+ bool committed = false;
+ bool del_op;
+ u32 i;
+
+ lockdep_assert_held(&bat_priv->tt.commit_lock);
+
+ if (!hash)
+ return;
+
+ ether_addr_copy(key.addr, change->addr);
+ key.vid = ntohs(change->vid);
+ del_op = change->flags & BATADV_TT_CLIENT_DEL;
+
+ i = batadv_choose_tt(&key, hash->size);
+ head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+
+ spin_lock_bh(list_lock);
+
+ hlist_for_each_entry(tt_common, head, hash_entry) {
+ if (!batadv_compare_tt(&tt_common->hash_entry, &key))
+ continue;
+
+ scoped_guard(spinlock_bh, &tt_common->flags_lock) {
+ if (!del_op) {
+ /* an ADD of an already committed entry only
+ * announces new flags or cancels its removal
+ */
+ if (!(tt_common->flags & BATADV_TT_CLIENT_NEW))
+ break;
+
+ tt_common->flags &= ~BATADV_TT_CLIENT_NEW;
+ committed = true;
+ break;
+ }
+
+ tt_local = container_of(tt_common,
+ struct batadv_tt_local_entry,
+ common);
+ if (batadv_tt_local_unhash_pending(bat_priv, tt_local))
+ break;
+
+ tt_local = NULL;
+
+ /* The client was detected again after its DEL was
+ * taken. The other nodes remove it with this ttvn and
+ * only add it again with the still queued ADD. The
+ * entry must be hidden from the CRC and the full table
+ * responses until this ADD is committed.
+ */
+ if (!(tt_common->flags & BATADV_TT_CLIENT_NEW)) {
+ tt_common->flags |= BATADV_TT_CLIENT_NEW;
+ batadv_tt_local_size_dec(bat_priv, key.vid);
+ }
+ }
+
+ if (committed)
+ batadv_tt_local_size_inc(bat_priv, key.vid);
+
+ break;
+ }
+
+ spin_unlock_bh(list_lock);
+
+ /* drop reference of removed hash entry */
+ batadv_tt_local_entry_put(tt_local);
+}
+
/**
* batadv_tt_local_purge_pending_clients() - finalise removal of pending local
* clients
@@ -4686,8 +4754,14 @@ batadv_tt_local_unhash_pending(struct batadv_priv *bat_priv,
* Iterate over the local TT and physically remove every entry that has been
* marked as BATADV_TT_CLIENT_PENDING and whose DEL was queued. An entry which
* still waits for its DEL (del_unqueued) stays in the local table.
+ *
+ * The caller must hold tt->commit_lock and has to commit the queued changes
+ * right away. The DEL of each removed entry is still queued because no commit
+ * could have taken it since the entry was marked. All removals are therefore
+ * announced with the next ttvn.
*/
static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
+ __must_hold(&bat_priv->tt.commit_lock)
{
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
@@ -4697,6 +4771,8 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
struct hlist_head *head;
u32 i;
+ lockdep_assert_held(&bat_priv->tt.commit_lock);
+
if (!hash)
return;
@@ -4736,6 +4812,7 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
__must_hold(&bat_priv->tt.commit_lock)
{
+ struct batadv_tt_change_node *tt_change_node;
LIST_HEAD(changes_list);
int changes_num;
@@ -4758,9 +4835,12 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
return;
}
- batadv_tt_local_transition_new(bat_priv);
+ /* bring the affected local entries into the state announced with the
+ * new ttvn
+ */
+ list_for_each_entry(tt_change_node, &changes_list, list)
+ batadv_tt_local_commit_change(bat_priv, &tt_change_node->change);
- batadv_tt_local_purge_pending_clients(bat_priv);
batadv_tt_local_update_crc(bat_priv);
/* Increment the TTVN only once per OGM interval */
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 10/11] batman-adv: tt: avoid list_lock for unchanged local clients
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (8 preceding siblings ...)
2026-11-18 11:41 ` [PATCH batadv v5 09/11] batman-adv: tt: commit only the announced local changes Sven Eckelmann
@ 2026-11-18 11:42 ` Sven Eckelmann
2026-11-18 11:42 ` [PATCH batadv v5 11/11] batman-adv: tt: drop ADD+DEL events of never announced clients Sven Eckelmann
2026-11-18 11:45 ` [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:42 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
batadv_tt_local_add() is called for every packet transmitted by a local
client. batadv_tt_local_refresh() takes the hash bucket list_lock for each
of them, although this lock is shared by all entries of the bucket and is
only needed when the entry has to be modified or announced.
For the common case, the entry is neither BATADV_TT_CLIENT_PENDING nor
BATADV_TT_CLIENT_ROAM, the dynamic flags (BATADV_TT_CLIENT_WIFI and
BATADV_TT_CLIENT_ISOLA) are unchanged and the entry is still hashed. Only
last_seen has to be refreshed then.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 117 ++++++++++++++++++++++++++++---------
1 file changed, 90 insertions(+), 27 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index c2f5b8a5..6102bdf6 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1037,13 +1037,77 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
return tt_local;
}
+/* flags of a local TT entry which depend on the packets of the client */
+#define BATADV_TT_LOCAL_DYNAMIC_MASK \
+ (BATADV_TT_CLIENT_WIFI | BATADV_TT_CLIENT_ISOLA)
+
+/**
+ * batadv_tt_local_dynamic_flags() - get the dynamic flags of a local client
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @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)
+ *
+ * Return: the BATADV_TT_CLIENT_WIFI and BATADV_TT_CLIENT_ISOLA flags which the
+ * local entry of the client has to carry.
+ */
+static u16 batadv_tt_local_dynamic_flags(struct batadv_priv *bat_priv,
+ bool iif_is_wifi, u32 mark)
+{
+ u32 match_mark;
+ u16 flags = 0;
+
+ if (iif_is_wifi)
+ flags |= BATADV_TT_CLIENT_WIFI;
+
+ /* check the mark in the skb: if it's equal to the configured
+ * isolation_mark, it means the packet is coming from an
+ * isolated non-mesh client
+ */
+ match_mark = (mark & bat_priv->isolation_mark_mask);
+ if (bat_priv->isolation_mark_mask &&
+ match_mark == bat_priv->isolation_mark)
+ flags |= BATADV_TT_CLIENT_ISOLA;
+
+ return flags;
+}
+
+/**
+ * batadv_tt_local_refresh_needed() - check if a local entry has to be modified
+ * @tt_local: the local TT entry to check
+ * @dynamic_flags: the dynamic flags the entry has to carry
+ *
+ * The bucket list_lock which is shared by many entries is only needed when
+ * the entry has to be modified or announced. For the common case of an
+ * already announced client with unchanged flags, it is enough to refresh the
+ * last_seen timestamp.
+ *
+ * Return: true if the slow path of batadv_tt_local_refresh() is required,
+ * false otherwise.
+ */
+static bool
+batadv_tt_local_refresh_needed(struct batadv_tt_local_entry *tt_local,
+ u16 dynamic_flags)
+{
+ struct batadv_tt_common_entry *common = &tt_local->common;
+ u16 flags;
+
+ flags = batadv_tt_flags_get(common);
+
+ if (flags & (BATADV_TT_CLIENT_PENDING | BATADV_TT_CLIENT_ROAM))
+ return true;
+
+ if ((flags & BATADV_TT_LOCAL_DYNAMIC_MASK) != dynamic_flags)
+ return true;
+
+ return hlist_unhashed_lockless(&common->hash_entry);
+}
+
/**
* batadv_tt_local_refresh_locked() - refresh a local TT entry
* @bat_priv: the bat priv with all the mesh interface information
* @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)
+ * @dynamic_flags: the dynamic flags the entry has to carry
* @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
@@ -1067,7 +1131,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
static bool
batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local,
- bool iif_is_wifi, u32 mark, bool announce,
+ u16 dynamic_flags, bool announce,
bool *roamed_back)
{
struct batadv_tt_common_entry *common = &tt_local->common;
@@ -1075,7 +1139,6 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
bool readded = false;
bool roamed = false;
u8 remote_flags;
- u32 match_mark;
u16 flags;
u32 i;
@@ -1111,21 +1174,8 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
*/
remote_flags = flags & BATADV_TT_REMOTE_MASK;
- if (iif_is_wifi)
- flags |= BATADV_TT_CLIENT_WIFI;
- else
- flags &= ~BATADV_TT_CLIENT_WIFI;
-
- /* check the mark in the skb: if it's equal to the configured
- * isolation_mark, it means the packet is coming from an
- * isolated non-mesh client
- */
- match_mark = (mark & bat_priv->isolation_mark_mask);
- if (bat_priv->isolation_mark_mask &&
- match_mark == bat_priv->isolation_mark)
- flags |= BATADV_TT_CLIENT_ISOLA;
- else
- flags &= ~BATADV_TT_CLIENT_ISOLA;
+ flags &= ~BATADV_TT_LOCAL_DYNAMIC_MASK;
+ flags |= dynamic_flags;
if (remote_flags ^ (flags & BATADV_TT_REMOTE_MASK))
announce = true;
@@ -1172,7 +1222,8 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
* any)
* @roamed_back: set to true when the client returned to its original location
*
- * See batadv_tt_local_refresh_locked() for the actual refresh.
+ * See batadv_tt_local_refresh_locked() for the actual refresh. The hash bucket
+ * list_lock is only taken when the entry has to be modified or announced.
*
* An entry whose modification could not be announced stays in its previous
* state. The refresh is then retried with the next packet of the client.
@@ -1188,14 +1239,22 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ u16 dynamic_flags;
int ret = 0;
u32 i;
- i = batadv_choose_tt(&common->key, hash->size);
- list_lock = &hash->list_locks[i];
+ dynamic_flags = batadv_tt_local_dynamic_flags(bat_priv, iif_is_wifi,
+ mark);
WRITE_ONCE(tt_local->last_seen, jiffies);
+ /* fast path: nothing to modify or to announce */
+ if (!batadv_tt_local_refresh_needed(tt_local, dynamic_flags))
+ return 0;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ list_lock = &hash->list_locks[i];
+
spin_lock_bh(list_lock);
/* the entry was removed from the local table after it was looked up */
@@ -1204,8 +1263,8 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
return -ENOENT;
}
- if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi,
- mark, false, roamed_back))
+ if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, dynamic_flags,
+ false, roamed_back))
ret = -ENOMEM;
spin_unlock_bh(list_lock);
@@ -1244,8 +1303,12 @@ static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
struct hlist_head *head;
struct hlist_node *node;
+ u16 dynamic_flags;
u32 i;
+ dynamic_flags = batadv_tt_local_dynamic_flags(bat_priv, iif_is_wifi,
+ mark);
+
i = batadv_choose_tt(&common->key, hash->size);
head = &hash->table[i];
list_lock = &hash->list_locks[i];
@@ -1261,8 +1324,8 @@ static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
}
/* announce the added client to the mesh */
- if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi,
- mark, true, roamed_back)) {
+ if (!batadv_tt_local_refresh_locked(bat_priv, tt_local, dynamic_flags,
+ true, roamed_back)) {
spin_unlock_bh(list_lock);
return false;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH batadv v5 11/11] batman-adv: tt: drop ADD+DEL events of never announced clients
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (9 preceding siblings ...)
2026-11-18 11:42 ` [PATCH batadv v5 10/11] batman-adv: tt: avoid list_lock for unchanged local clients Sven Eckelmann
@ 2026-11-18 11:42 ` Sven Eckelmann
2026-11-18 11:45 ` [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:42 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
If a detected client was not yet announced, a DEL event can directly drop
the ADD event. The other nodes never heard about the client and don't need
a DEL for it. The entry can then also be removed from the local table
immediately instead of waiting for the commit of its DEL.
Only the initial ADD queued by batadv_tt_local_insert() can be cancelled.
The BATADV_TT_CLIENT_NEW flag of the entry is not enough to identify such a
change: batadv_tt_local_commit_changes_nolock() takes the queued changes
before it clears this flag. An ADD queued by batadv_tt_local_refresh() in
this window (for example for a changed BATADV_TT_CLIENT_WIFI flag) must
still be announced together with a following DEL because the initial ADD is
already on its way to the other nodes. Each change entry therefore stores
whether it is the initial ADD of its client.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/translation-table.c | 119 +++++++++++++++++++++++++++++--------
net/batman-adv/types.h | 7 +++
2 files changed, 100 insertions(+), 26 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 6102bdf6..e08bf88b 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -704,13 +704,20 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
}
/**
- * __batadv_tt_local_event() - store a local TT event (ADD/DEL) with given flags
+ * batadv_tt_local_event() - store a local TT event (ADD/DEL) with given flags
* @bat_priv: the bat priv with all the mesh interface information
* @common: the TT entry involved in the event
* @flags: flags of the TT entry combined with the event flags
+ * @initial_add: whether the ADD is the first one of a client which was never
+ * announced to the other nodes
+ * @cancelled: set to true if a DEL cancelled the initial ADD of the client and
+ * to false otherwise (optional)
*
* Only a single change per client is queued. It describes the latest state of
- * the client and a new event therefore replaces an already queued one.
+ * the client and a new event therefore replaces an already queued one. The
+ * only exception is a DEL for a client whose initial ADD is still queued. The
+ * other nodes don't need to know anything about such a client and the ADD is
+ * cancelled instead.
*
* The other nodes only learn about the modification of a local entry through
* the queued change. The caller must therefore not modify the entry in a way
@@ -722,12 +729,12 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
* The caller must hold the flags_lock of @common. The events of an entry are
* then queued in the same order in which its flags were modified.
*
- * Return: true if the event was stored, false if the memory for it could not
- * be allocated.
+ * Return: true if the event was stored (or cancelled a queued ADD), false if
+ * the memory for it could not be allocated.
*/
-static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
- const struct batadv_tt_common_entry *common,
- u8 flags)
+static bool batadv_tt_local_event(struct batadv_priv *bat_priv,
+ const struct batadv_tt_common_entry *common,
+ u8 flags, bool initial_add, bool *cancelled)
__must_hold(&common->flags_lock)
{
struct batadv_tt_change_node *tt_change_node;
@@ -738,6 +745,9 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
lockdep_assert_held(&common->flags_lock);
+ if (cancelled)
+ *cancelled = false;
+
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
if (!tt_change_node)
return false;
@@ -757,6 +767,7 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
flags &= ~BATADV_TT_CLIENT_ROAM;
tt_change_node->change.flags = flags;
+ tt_change_node->initial_add = initial_add && !del_op_requested;
/* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */
spin_lock_bh(&bat_priv->tt.changes_list_lock);
@@ -769,12 +780,31 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
if (entry->change.vid != tt_change_node->change.vid)
continue;
- /* the other nodes may know the client with different
- * flags. A DEL+ADD must therefore still announce the
- * current flags and an ADD+DEL must still remove the
- * client. ADD+ADD and DEL+DEL only update the flags
- */
- entry->change.flags = flags;
+ if (del_op_requested && entry->initial_add) {
+ /* ADD+DEL of a client which was never announced (e.g.
+ * roaming of a client still in the NEW state) have no
+ * effect and can be removed.
+ */
+ list_del(&entry->list);
+ kmem_cache_free(batadv_tt_change_cache, entry);
+ changes--;
+ if (cancelled)
+ *cancelled = true;
+ } else {
+ /* the other nodes may know the client with different
+ * flags. A DEL+ADD must therefore still announce the
+ * current flags and an ADD+DEL must still remove the
+ * client. ADD+ADD and DEL+DEL only update the flags.
+ *
+ * The queued change keeps its initial_add state. An
+ * ADD which only updates the flags of a still queued
+ * initial ADD stays cancellable. But an ADD queued
+ * after the initial ADD was committed (and before the
+ * entry left the NEW state) must not become
+ * cancellable.
+ */
+ entry->change.flags = flags;
+ }
kmem_cache_free(batadv_tt_change_cache, tt_change_node);
goto update_changes;
@@ -1116,6 +1146,10 @@ batadv_tt_local_refresh_needed(struct batadv_tt_local_entry *tt_local,
* 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.
*
+ * @announce is only set for an entry which is just being inserted. Its ADD is
+ * therefore the initial ADD of a client which was never announced to the other
+ * nodes.
+ *
* The entry is left untouched when the ADD event could not be queued. The
* other nodes would otherwise never be informed about the new state. An already
* hashed entry is simply refreshed again when the next packet of the client is
@@ -1136,6 +1170,7 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool initial_add = announce;
bool readded = false;
bool roamed = false;
u8 remote_flags;
@@ -1184,7 +1219,8 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
* without a queued change which commits/announces it
*/
if (announce &&
- !__batadv_tt_local_event(bat_priv, common, flags))
+ !batadv_tt_local_event(bat_priv, common, flags,
+ initial_add, NULL))
return false;
common->flags = flags;
@@ -1936,6 +1972,11 @@ static void batadv_tt_local_unhash(struct batadv_priv *bat_priv,
* retry it. Such an entry is marked as del_unqueued instead. It stays in the
* local table until batadv_tt_local_purge_list() was able to queue its DEL.
*
+ * A client whose initial ADD is still queued was never announced to the other
+ * nodes. Its DEL cancels the ADD and the entry is removed from the local table
+ * right away. The caller has to drop the hash reference of the entry after it
+ * released the flags_lock.
+ *
* The caller must hold the flags_lock of @tt_local_entry and must not have
* released it since it checked that the entry has to be removed. Both the
* queue-then-mark order and this single flags_lock section are required.
@@ -1944,8 +1985,11 @@ static void batadv_tt_local_unhash(struct batadv_priv *bat_priv,
* must have ensured that the entry is still part of the local table. A DEL for
* an entry which was already purged could otherwise cancel the ADD of a new
* entry for the same client.
+ *
+ * Return: true if the entry was removed from the local table instead of being
+ * marked as pending, false otherwise.
*/
-static void
+static bool
batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
u16 flags, const char *message)
@@ -1953,6 +1997,7 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool cancelled;
bool queued;
u32 i;
@@ -1960,8 +2005,13 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
lockdep_assert_held(&hash->list_locks[i]);
lockdep_assert_held(&common->flags_lock);
- queued = __batadv_tt_local_event(bat_priv, common,
- common->flags | flags);
+ queued = batadv_tt_local_event(bat_priv, common, common->flags | flags,
+ false, &cancelled);
+ if (cancelled) {
+ /* the entry was never announced */
+ batadv_tt_local_unhash(bat_priv, tt_local_entry, message);
+ return true;
+ }
/* a failed attempt must not hide the still queued DEL of an already
* pending entry
@@ -1977,6 +2027,8 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
"Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
tt_local_entry->common.key.addr,
batadv_print_vid(tt_local_entry->common.key.vid), message);
+
+ return false;
}
/**
@@ -1993,6 +2045,9 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
* also applies to an entry which still carries BATADV_TT_CLIENT_NEW because its
* ADD might already have been taken for the next ttvn.
*
+ * Only an entry whose initial ADD is still queued is removed from the local
+ * table immediately. Nothing was announced about it to the other nodes.
+ *
* An entry which was already removed from the local table after it was looked
* up is ignored and BATADV_NO_FLAGS is stored in @curr_flags.
*
@@ -2009,6 +2064,7 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool unhashed = false;
u16 flags;
u32 i;
@@ -2037,11 +2093,15 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
if (roaming)
flags |= BATADV_TT_CLIENT_ROAM;
- batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
- message);
+ unhashed = batadv_tt_local_set_pending(bat_priv, tt_local_entry,
+ flags, message);
}
spin_unlock_bh(list_lock);
+
+ /* drop reference of removed hash entry */
+ if (unhashed)
+ batadv_tt_local_entry_put(tt_local_entry);
}
/**
@@ -2090,6 +2150,8 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
hash_entry) {
+ bool unhashed = false;
+
tt_local_entry = container_of(tt_common_entry,
struct batadv_tt_local_entry,
common);
@@ -2099,10 +2161,10 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) {
/* but its removal must still be announced */
if (tt_local_entry->del_unqueued)
- batadv_tt_local_set_pending(bat_priv,
- tt_local_entry,
- BATADV_TT_CLIENT_DEL,
- "requeued");
+ unhashed = batadv_tt_local_set_pending(bat_priv,
+ tt_local_entry,
+ BATADV_TT_CLIENT_DEL,
+ "requeued");
break;
}
@@ -2113,10 +2175,15 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
timeout))
break;
- batadv_tt_local_set_pending(bat_priv, tt_local_entry,
- BATADV_TT_CLIENT_DEL,
- "timed out");
+ unhashed = batadv_tt_local_set_pending(bat_priv,
+ tt_local_entry,
+ BATADV_TT_CLIENT_DEL,
+ "timed out");
}
+
+ /* drop reference of removed hash entry */
+ if (unhashed)
+ batadv_tt_local_entry_put(tt_local_entry);
}
}
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index d443143f..0a2db658 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -2005,6 +2005,13 @@ struct batadv_tt_change_node {
/** @change: holds the actual translation table diff data */
struct batadv_tvlv_tt_change change;
+
+ /**
+ * @initial_add: the change is the initial ADD of a client which was
+ * never announced to the other nodes. A DEL of this client cancels
+ * the change instead of being queued
+ */
+ bool initial_add:1;
};
/**
--
2.47.3
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups
2026-11-18 11:41 [PATCH batadv v5 00/11] batman-adv: tt: shashiko 20260930 follow ups Sven Eckelmann
` (10 preceding siblings ...)
2026-11-18 11:42 ` [PATCH batadv v5 11/11] batman-adv: tt: drop ADD+DEL events of never announced clients Sven Eckelmann
@ 2026-11-18 11:45 ` Sven Eckelmann
11 siblings, 0 replies; 13+ messages in thread
From: Sven Eckelmann @ 2026-11-18 11:45 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sashiko
[-- Attachment #1.1: Type: text/plain, Size: 357 bytes --]
On Wednesday, 18 November 2026 12:41:50 CET Sven Eckelmann wrote:
> This makes the transitions well defined but looking at the full graph for
> too long causes headaches. I will submit these graphs as reply and would
> recommend only to look at the "main" (normal cases) and specialized "rare"
> graph for the corner cases.
See attachments.
Regards,
Sven
[-- Attachment #1.2: tt-local-states-all.dot --]
[-- Type: application/msword-template, Size: 4610 bytes --]
[-- Attachment #1.3: tt-local-states-all.svg --]
[-- Type: image/svg+xml, Size: 24731 bytes --]
[-- Attachment #1.4: tt-local-states-main.dot --]
[-- Type: application/msword-template, Size: 2436 bytes --]
[-- Attachment #1.5: tt-local-states-main.svg --]
[-- Type: image/svg+xml, Size: 14179 bytes --]
[-- Attachment #1.6: tt-local-states-rare.dot --]
[-- Type: application/msword-template, Size: 2265 bytes --]
[-- Attachment #1.7: tt-local-states-rare.svg --]
[-- Type: image/svg+xml, Size: 14906 bytes --]
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread