All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [PATCH mptcp-net-next 06/14] mptcp: Make mptcp_set_new_pathindex lockless
@ 2018-05-03 21:04 Christoph Paasch
  0 siblings, 0 replies; only message in thread
From: Christoph Paasch @ 2018-05-03 21:04 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 2890 bytes --]

There is quite a complex logic just for setting the next path-index. It
also prevents us from making the operation lockless.

Let's simplify this and make it lockless through a simple
test_and_set_bit.

Signed-off-by: Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts(a)tessares.net>
(cherry picked from commit e426daa6e7bf3797aee5993258cecc5bc8a89c31)
Signed-off-by: Christoph Paasch <cpaasch(a)apple.com>
---
 include/net/mptcp.h    | 34 +---------------------------------
 net/mptcp/mptcp_ctrl.c | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index f6ca550d9e6c..43f7f2ae1bad 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -326,9 +326,7 @@ struct mptcp_cb {
 	u8 mptcp_pm[MPTCP_PM_SIZE] __aligned(8);
 	struct mptcp_pm_ops *pm_ops;
 
-	u32 path_index_bits;
-	/* Next pi to pick up in case a new path becomes available */
-	u8 next_path_index;
+	unsigned long path_index_bits;
 
 	__u8	mptcp_ver;
 
@@ -1247,36 +1245,6 @@ static inline bool mptcp_fallback_infinite(struct sock *sk, int flag)
 	return false;
 }
 
-/* Find the first index whose bit in the bit-field == 0 */
-static inline u8 mptcp_set_new_pathindex(struct mptcp_cb *mpcb)
-{
-	u8 base = mpcb->next_path_index;
-	int i;
-
-	/* Start at 1, because 0 is reserved for the meta-sk */
-	mptcp_for_each_bit_unset(mpcb->path_index_bits >> base, i) {
-		if (i + base < 1)
-			continue;
-		if (i + base >= sizeof(mpcb->path_index_bits) * 8)
-			break;
-		i += base;
-		mpcb->path_index_bits |= (1 << i);
-		mpcb->next_path_index = i + 1;
-		return i;
-	}
-	mptcp_for_each_bit_unset(mpcb->path_index_bits, i) {
-		if (i >= sizeof(mpcb->path_index_bits) * 8)
-			break;
-		if (i < 1)
-			continue;
-		mpcb->path_index_bits |= (1 << i);
-		mpcb->next_path_index = i + 1;
-		return i;
-	}
-
-	return 0;
-}
-
 static inline bool mptcp_v6_is_v4_mapped(const struct sock *sk)
 {
 	return sk->sk_family == AF_INET6 &&
diff --git a/net/mptcp/mptcp_ctrl.c b/net/mptcp/mptcp_ctrl.c
index 1e67d5d6c87d..c2aae9020d91 100644
--- a/net/mptcp/mptcp_ctrl.c
+++ b/net/mptcp/mptcp_ctrl.c
@@ -1316,6 +1316,22 @@ void mptcp_fallback_meta_sk(struct sock *meta_sk)
 	kmem_cache_free(mptcp_cb_cache, tcp_sk(meta_sk)->mpcb);
 }
 
+/*  Called without holding lock on mpcb */
+static u8 mptcp_set_new_pathindex(struct mptcp_cb *mpcb)
+{
+	int i;
+
+	/* Start at 1, because 0 is reserved for the meta-sk */
+	for (i = 1; i < sizeof(mpcb->path_index_bits) * 8; i++) {
+		if (!test_and_set_bit(i, &mpcb->path_index_bits))
+			break;
+	}
+
+	if (i == sizeof(mpcb->path_index_bits) * 8)
+		return 0;
+	return i;
+}
+
 int mptcp_add_sock(struct sock *meta_sk, struct sock *sk, u8 loc_id, u8 rem_id,
 		   gfp_t flags)
 {
-- 
2.16.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-05-03 21:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 21:04 [MPTCP] [PATCH mptcp-net-next 06/14] mptcp: Make mptcp_set_new_pathindex lockless Christoph Paasch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.