From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
b.a.t.m.a.n@lists.open-mesh.org,
Sven Eckelmann <sven@narfation.org>,
Sashiko <sashiko-bot@kernel.org>,
Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH net-next 13/15] batman-adv: tt: commit only the announced local changes
Date: Mon, 23 Nov 2026 18:18:25 +0100 [thread overview]
Message-ID: <20261123171827.3294525-14-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de>
From: Sven Eckelmann <sven@narfation.org>
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>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
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 2a7f50de70fc..b03d6c74732f 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -539,6 +539,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)
@@ -1876,9 +1882,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,
@@ -4545,49 +4550,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
@@ -4625,6 +4587,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
@@ -4633,8 +4701,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;
@@ -4644,6 +4718,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;
@@ -4683,6 +4759,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;
@@ -4705,9 +4782,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
next prev parent reply other threads:[~2026-11-23 17:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:18 [PATCH net-next 00/15] pull request for net-next: batman-adv 2026-11-23 Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 01/15] batman-adv: document refcount of returned objects Simon Wunderlich
2026-11-23 17:23 ` netdev-bot+sinfo
2026-11-23 17:18 ` [PATCH net-next 02/15] batman-adv: mcast: use mla_lock also during mcast_free Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 03/15] batman-adv: mark functions inheriting critical sections Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 04/15] batman-adv: bla: register own backbone gw when claiming for local node Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 05/15] batman-adv: tt: unhash local entries with hlist_del_init_rcu() Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 06/15] batman-adv: tt: refresh local entry in single flags_lock section Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 07/15] batman-adv: tt: don't remove unhashed local entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 08/15] batman-adv: tt: don't queue local events for unhashed entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 09/15] batman-adv: tt: remove unannounced local entries via pending state Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 10/15] batman-adv: tt: keep local entry unchanged when ADD can't be queued Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 11/15] batman-adv: tt: requeue DEL of pending local entry after failed allocation Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 12/15] batman-adv: tt: extract removal of pending local entry Simon Wunderlich
2026-11-23 17:18 ` Simon Wunderlich [this message]
2026-11-23 17:18 ` [PATCH net-next 14/15] batman-adv: tt: avoid list_lock for unchanged local clients Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 15/15] batman-adv: tt: drop ADD+DEL events of never announced clients Simon Wunderlich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123171827.3294525-14-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=sven@narfation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox