From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.88.38.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795454322; b=ltmO8PL+JgxiOlOw+iY9JSa/cNwX7tGrnz7zIWtgQ50CX14Y+F70ghWY76QLv8/OuBzl hHBbA8UzzxpUR/qpqc2IWpLgCxSRILGVel4dDkQ3PF7VgM4OxlpMu4fkn8bhwO3/d8Kov CQoLnPXz4X5ivZMOjKmlgJ9krJy8kKUv2B2Jw0xvagxQWX433QJDMk5l7HxSc7v9GUe93 EFbwpnrKw+vz7WZ0LKdtVFXImKJtEaYLCOYG5SeLyVA7+GU6OVZD+ZN3x46kMILhdg5ee kF6B9x+BY9FG1bvtfnqkE0QhWpzFGshBYxP6i2Mq4+U1JxqCnPv4WmC3h49zPTN0cYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795454322; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=9m8KFjyLBuEGWvkUX+zuLasC9JtQT3T+Xo3Iyb1Jbik=; b=Vp7KXOiWxqCKYbuMDGNNWTvW78MW2yjVo3PjnbV1LDVJSePfg7/6RgJMeFoSEdMLEKc2 IM6rvTZC3sQ1JJ+Kn9LiPJvU8fkhZKCL2v6ykB/8PeCumCKqQGYuP1cac9j7CRBqnL6ks I1y54o4Gf8ckHJOut0WHio9MQsg8xWJodRu+2mBl/wzpNhDLjHq61WgRTbyhE0Dl+A1tD htD8fgsyyZfB9+qa4nezUYBpXdhl9zaxzuUS5CxWzD8/gGSjylfS4OjXtO216VSumLXo4 OQSWl2gcoH3cHBOFjty/NHieJRxqP8W8jRfTaCDkcLmlKUDX2tgShVNHUwvayGSVQww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=simonwunderlich.de; spf=pass smtp.mailfrom=simonwunderlich.de; dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=h+CzS7Ze; arc=none smtp.remote-ip=23.88.38.48 Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id B090C606A33E for ; Mon, 23 Nov 2026 17:18:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B090C606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=h+CzS7Ze Received: from kero.packetmixer.de (p200300C59714C2E05A704819B6ba2dB4.dip0.t-ipconnect.de [IPv6:2003:c5:9714:c2e0:5a70:4819:b6ba:2db4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with UTF8SMTPSA id 3F4A4FA3DF; Mon, 23 Nov 2026 18:18:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de; s=09092022; t=1795454317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9m8KFjyLBuEGWvkUX+zuLasC9JtQT3T+Xo3Iyb1Jbik=; b=h+CzS7Zeg4SrAgyhXb5EYaIW3fxAdHGe4dgbyg1g/zRqMNVT4A7E6QBL7IQMlTVQZs0Ggj GhLLUWoxlCMcGdEBWV9ddQV9GSQaKQg+NIjkKJYZmX40f0eyr+I6bulKdlFPRW/A7pbHWj s6QpFJ4JpwaNhZPj52A+pVzwtEfm9YMloVWMRDpXaQChZpVs9D0XZkNi/M2GnJVMnsg3Kb GzHMMAzoYaXScVdkB4g0l4AqBItMxncT9iy4NXl2LmAQIpD5rO2wKZCSGuJKNdmfonXBzi zJsNj8A4sY1U9eyqI9oMuVcMY77fXlSN8GdHgEfQbW76dzqyPuOHkoUiLjBUkg== From: Simon Wunderlich To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann , Sashiko , Simon Wunderlich Subject: [PATCH net-next 06/15] batman-adv: tt: refresh local entry in single flags_lock section Date: Mon, 23 Nov 2026 18:18:18 +0100 Message-ID: <20261123171827.3294525-7-sw@simonwunderlich.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de> References: <20261123171827.3294525-1-sw@simonwunderlich.de> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: 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. Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-7602d89e-b2cd-43ca-8aca-c165e5d674b2 Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/translation-table.c | 129 ++++++++++++----------------- 1 file changed, 55 insertions(+), 74 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 1c784a0e8c9b..63eac1e1c65e 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -903,57 +903,6 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex) return batadv_is_wifi(wifi_flags); } -/** - * batadv_tt_local_add_existing() - refresh an already known local TT entry - * @bat_priv: the bat priv with all the mesh interface information - * @tt_local: the local TT entry which was found in the local table - * @roamed_back: set to true when the client returned to its original location - * - * Return: true when the client has to be announced to the mesh again, false - * otherwise. - */ -static bool batadv_tt_local_add_existing(struct batadv_priv *bat_priv, - struct batadv_tt_local_entry *tt_local, - bool *roamed_back) -{ - struct batadv_tt_common_entry *common = &tt_local->common; - bool readded = false; - - WRITE_ONCE(tt_local->last_seen, jiffies); - - scoped_guard(spinlock_bh, &common->flags_lock) { - if (common->flags & BATADV_TT_CLIENT_PENDING) { - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Re-adding pending client %pM (vid: %d)\n", - common->key.addr, - batadv_print_vid(common->key.vid)); - /* whatever the reason why the PENDING flag was set, - * this is a client which was enqueued to be removed in - * this orig_interval. Since it popped up again, the - * flag can be reset like it was never enqueued - */ - common->flags &= ~BATADV_TT_CLIENT_PENDING; - readded = true; - } - - if (common->flags & BATADV_TT_CLIENT_ROAM) { - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Roaming client %pM (vid: %d) came back to its original location\n", - common->key.addr, - batadv_print_vid(common->key.vid)); - /* the ROAM flag is set because this client roamed away - * and the node got a roaming_advertisement message. Now - * that the client popped up again at its original - * location such flag can be unset - */ - common->flags &= ~BATADV_TT_CLIENT_ROAM; - *roamed_back = true; - } - } - - return readded; -} - /** * batadv_tt_local_create() - allocate and initialize a local TT entry * @mesh_iface: netdev struct of the mesh interface @@ -1028,27 +977,63 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr, } /** - * batadv_tt_local_update_flags() - update the dynamic flags of a local entry + * batadv_tt_local_refresh() - refresh a local TT entry of an active client * @bat_priv: the bat priv with all the mesh interface information - * @tt_local: the local TT entry to update + * @tt_local: the local TT entry to refresh * @iif_is_wifi: whether the client is connected via a wifi interface * @mark: the value contained in the skb->mark field of the received packet (if * any) + * @announce: whether an ADD event has to be queued even when no announced + * flag was modified + * @roamed_back: set to true when the client returned to its original location * - * Return: true if a flag announced to the other nodes was modified, false - * otherwise. + * A pending removal of the entry is cancelled and its dynamic flags are + * updated. An ADD event is queued when @announce is set, the pending removal + * was cancelled or a flag announced to the other nodes was modified. + * + * All checks and modifications of the flags and the queueing of the ADD event + * happen in a single flags_lock section. The announced flags are therefore the + * ones which were just stored in the entry. */ -static bool -batadv_tt_local_update_flags(struct batadv_priv *bat_priv, - struct batadv_tt_local_entry *tt_local, - bool iif_is_wifi, u32 mark) +static void +batadv_tt_local_refresh(struct batadv_priv *bat_priv, + struct batadv_tt_local_entry *tt_local, + bool iif_is_wifi, u32 mark, bool announce, + bool *roamed_back) { struct batadv_tt_common_entry *common = &tt_local->common; u8 remote_flags; u32 match_mark; - bool modified; scoped_guard(spinlock_bh, &common->flags_lock) { + if (common->flags & BATADV_TT_CLIENT_PENDING) { + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Re-adding pending client %pM (vid: %d)\n", + common->key.addr, + batadv_print_vid(common->key.vid)); + /* whatever the reason why the PENDING flag was set, + * this is a client which was enqueued to be removed in + * this orig_interval. Since it popped up again, the + * flag can be reset like it was never enqueued + */ + common->flags &= ~BATADV_TT_CLIENT_PENDING; + announce = true; + } + + if (common->flags & BATADV_TT_CLIENT_ROAM) { + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Roaming client %pM (vid: %d) came back to its original location\n", + common->key.addr, + batadv_print_vid(common->key.vid)); + /* the ROAM flag is set because this client roamed away + * and the node got a roaming_advertisement message. Now + * that the client popped up again at its original + * location such flag can be unset + */ + common->flags &= ~BATADV_TT_CLIENT_ROAM; + *roamed_back = true; + } + /* store the current remote flags before altering them. This * helps understanding is flags are changing or not */ @@ -1070,10 +1055,13 @@ batadv_tt_local_update_flags(struct batadv_priv *bat_priv, else common->flags &= ~BATADV_TT_CLIENT_ISOLA; - modified = remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK); - } + if (remote_flags ^ (common->flags & BATADV_TT_REMOTE_MASK)) + announce = true; - return modified; + if (announce) + __batadv_tt_local_event(bat_priv, common, + common->flags); + } } /** @@ -1109,8 +1097,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid); if (tt_local) { - added = batadv_tt_local_add_existing(bat_priv, tt_local, - &roamed_back); + WRITE_ONCE(tt_local->last_seen, jiffies); } else { tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi); if (!tt_local) @@ -1130,18 +1117,12 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, added = true; } - /* announce the (re-)added client to the mesh */ - if (added) - batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); + /* announce the (re-)added client or its modified flags to the mesh */ + batadv_tt_local_refresh(bat_priv, tt_local, iif_is_wifi, mark, added, + &roamed_back); batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back); - /* if any "dynamic" flag has been modified, resend an ADD event for this - * entry so that all the nodes can get the new flags - */ - if (batadv_tt_local_update_flags(bat_priv, tt_local, iif_is_wifi, mark)) - batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); - ret = true; out: batadv_tt_local_entry_put(tt_local); -- 2.47.3