Skip to contentSkip to conversation

batman-adv: stop tp_meter sessions during mesh teardown

PATCH Superseded Ren Wei 2 participants 2 messages Apr 25 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 batman-adv: stop tp_meter sessions during mesh teardown

In reply to a message not in the archive

From: Jiexun Wang <[email protected]>

TP meter sessions are started asynchronously and remain linked on bat_priv->tp_list after the netlink request has already finished. When the mesh interface is removed, batadv_mesh_free() currently tears down the mesh without first draining these sessions.

A running sender thread or a late incoming tp_meter packet can then keep processing against a mesh instance which is already shutting down. Synchronize tp_meter with the mesh lifetime by stopping all active sessions from batadv_mesh_free(), refusing new sender/receiver setup once the mesh is no longer active, and waiting for sender threads to exit before teardown continues.

Fixes 33a3bb4a3345 ("batman-adv: throughput meter implementation")
---
 net/batman-adv/main.c     |   1 +
 net/batman-adv/tp_meter.c | 112 +++++++++++++++++++++++++++++++-------
 net/batman-adv/tp_meter.h |   1 +
 net/batman-adv/types.h    |   4 ++
 4 files changed, 97 insertions(+), 21 deletions(-)
net/batman-adv/main.c +1 -0
index 3a35aadd8b41..a4d33ee0fda5 100644
@@ -249,6 +249,7 @@ void batadv_mesh_free(struct net_device *mesh_iface)
 	atomic_set(&bat_priv->mesh_state, BATADV_MESH_DEACTIVATING);
 
 	batadv_purge_outstanding_packets(bat_priv, NULL);
+	batadv_tp_stop_all(bat_priv);
 
 	batadv_gw_node_free(bat_priv);
 
net/batman-adv/tp_meter.c +91 -21

192 lines not on this page · raw message

net/batman-adv/tp_meter.h +1 -0
index f0046d366eac..4e97cd10cd02 100644
@@ -17,6 +17,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 		     u32 test_length, u32 *cookie);
 void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst,
 		    u8 return_value);
+void batadv_tp_stop_all(struct batadv_priv *bat_priv);
 void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb);
 
 #endif /* _NET_BATMAN_ADV_TP_METER_H_ */
net/batman-adv/types.h +4 -0
index 8fc5fe0e9b05..daa06f421154 100644
@@ -14,6 +14,7 @@
 #include <linux/average.h>
 #include <linux/bitops.h>
 #include <linux/compiler.h>
+#include <linux/completion.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
 #include <linux/kref.h>
@@ -1328,6 +1329,9 @@ struct batadv_tp_vars {
 	/** @finish_work: work item for the finishing procedure */
 	struct delayed_work finish_work;
 
+	/** @finished: completion signaled when a sender thread exits */
+	struct completion finished;
+
 	/** @test_length: test length in milliseconds */
 	u32 test_length;
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw
Quoted 7 lines · Ren Wei

Thanks. I have some minor notes about the patch:

Quoted 10 lines
net/batman-adv/tp_meter.c +0 -0
index 2e42f6b3..028cd4e0 100644
@@ -947,6 +964,13 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 
 	/* look for an already existing test towards this node */
 	spin_lock_bh(&bat_priv->tp_list_lock);

net/batman-adv/tp_meter.c void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, · line 976

Quoted 10 lines
net/batman-adv/tp_meter.c +7 -0
+	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) {
+		spin_unlock_bh(&bat_priv->tp_list_lock);
+		batadv_tp_batctl_error_notify(BATADV_TP_REASON_DST_UNREACHABLE,
+					      dst, bat_priv, session_cookie);
+		return;
+	}
+
 	tp_vars = batadv_tp_list_find(bat_priv, dst);
 	if (tp_vars) {
 		spin_unlock_bh(&bat_priv->tp_list_lock);

Hm, this looks a little bit out of place. Maybe split it in a patch for handling the starting part (this) and the rest (the shutdown handling).

net/batman-adv/tp_meter.c void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, · line 995

Quoted 8 lines
net/batman-adv/tp_meter.c +0 -1
@@ -966,7 +990,6 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 					      bat_priv, session_cookie);
 		return;
 	}
-
 	tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC);
 	if (!tp_vars) {
 		spin_unlock_bh(&bat_priv->tp_list_lock);

Why was this changed?

net/batman-adv/tp_meter.c batadv_tp_init_recv(struct batadv_priv *bat_priv, · line 1367

Quoted 8 lines
net/batman-adv/tp_meter.c +0 -1
@@ -1342,7 +1362,6 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv,
 			   "Meter: too many ongoing sessions, aborting (RECV)\n");
 		goto out_unlock;
 	}
-
 	tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC);
 	if (!tp_vars)
 		goto out_unlock;

Why was this changed?

net/batman-adv/tp_meter.c void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb) · line 1517

Quoted 8 lines
net/batman-adv/tp_meter.c +0 -0
@@ -1478,9 +1500,57 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)

[ ... skip 12 lines ... ]

net/batman-adv/tp_meter.c +6 -0
+void batadv_tp_stop_all(struct batadv_priv *bat_priv)
+{
+	struct batadv_tp_vars *tp_vars[BATADV_TP_MAX_NUM];
+	struct batadv_tp_vars *tp_var;
+	int count = 0;
+	int i;

size_t count = 0;
size_t i;

Signature · 1 line
Sven Eckelmann <[email protected]>