Skip to contentSkip to conversation

dd locking to PM APis, implement PM netlink

RFC PATCH In review Paolo Abeni 3 participants 16 messages Feb 11, 2020 – Feb 15, 2020

Subsystems (2)
lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

cover dd locking to PM APis, implement PM netlink

Sending as an early RFC to gather feedback, as this is proving to be more intrusive that what I initially hoped for.

This implement the locking required by the PM to allow concurent subflow accessing the msk PM data in a safe way. Such data is protected via a msk-level spinlock. It relies on the Double checked locking to avoid contention in the most common scenarion (no or very little PM "actions").

Overall the above adds quite a bit of code churn, is that a too premature optimization? On the flip side, the whole PM processing should be quite light on the CPU in most cases.

Additionally changes more than a bit the PM hooks/APIs, to be hopefully simpler and avoiding duplicate code (no v4/v6 variant, work queue management done by the core PM infra).

It also introduce the PM netlink - should replace the current basic ones. Completely untested but please have a look at the specified netlink uAPI.

TODO:
- implement U/S helper
- self-tests
- do we need NL dump operation to inspect the PM netlink status?

 include/uapi/linux/mptcp.h |   42 +++
 net/mptcp/Makefile         |    3 
 net/mptcp/options.c        |   59 ++---
 net/mptcp/pm.c             |  340 +++++++++++++----------------
 net/mptcp/pm_netlink.c     |  524 +++++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.c       |    2 
 net/mptcp/protocol.h       |  110 +++++----
 net/mptcp/subflow.c        |   63 +++--
 8 files changed, 872 insertions(+), 271 deletions(-)
author
#1 lore raw

RFC PATCH 1/6 Squash-to: "mptcp: Add ADD_ADDR handling"

Drop addr_signal flag: it belong to the PM and
needs additional locking

Signed-off-by Paolo Abeni<pabeni(a)redhat.com>
---
 net/mptcp/options.c  | 5 -----
 net/mptcp/protocol.h | 1 -
 2 files changed, 6 deletions(-)
net/mptcp/options.c +0 -5
index 439bb14e29dc..331b020d64ae 100644
@@ -438,9 +438,6 @@ static bool mptcp_established_options_addr(struct sock *sk,
 	if (!msk)
 		return false;
 
-	if (!msk->addr_signal)
-		return false;
-
 	id = 0;
 	memset(&saddr, 0, sizeof(saddr));
 
@@ -463,8 +460,6 @@ static bool mptcp_established_options_addr(struct sock *sk,
 	}
 #endif
 
-	msk->addr_signal = 0;
-
 	return true;
 }
 
net/mptcp/protocol.h +0 -1
index fa707a57f000..65ba8ddb62e6 100644
@@ -91,7 +91,6 @@ struct mptcp_sock {
 	struct skb_ext	*cached_ext;	/* for the next sendmsg */
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct sock	*first;
-	u8		addr_signal;
 };
 
 #define mptcp_for_each_subflow(__msk, __subflow)			\
Signature · 1 line
2.21.1
author
#2 lore raw

RFC PATCH 2/6 Squash-to: "mptcp: Add path manager interface"

In reply to Paolo Abeni

Factor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.

The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.

Account the number of created subflow and received addresses, to enforce limits.

Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.

Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  |  45 +++++++++---------
 net/mptcp/pm.c       | 109 +++++++++++++------------------------------
 net/mptcp/protocol.c |   2 +
 net/mptcp/protocol.h |  96 ++++++++++++++++++++++---------------
 4 files changed, 117 insertions(+), 135 deletions(-)
net/mptcp/options.c +24 -21
index 6a2d6cea7d54..13fe6245cfcf 100644
@@ -432,34 +432,30 @@ static bool mptcp_established_options_addr(struct sock *sk,
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-	struct sockaddr_storage saddr;
-	u8 id;
+	struct mptcp_addr_info saddr;
+	int len;
 
 	if (!msk)
 		return false;
 
-	if (!msk->pm.fully_established)
+	if (!mptcp_pm_should_signal(msk) ||
+	    !(mptcp_pm_addr_signal(msk, remaining, &saddr)))
 		return false;
 
-	if (mptcp_pm_addr_signal(msk, &id, &saddr))
+	len = mptcp_add_addr_len(saddr.family);
+	if (remaining < len)
 		return false;
 
-	if (saddr.ss_family == AF_INET) {
-		if (remaining < TCPOLEN_MPTCP_ADD_ADDR)
-			return false;
+	*size = len;
+	opts->addr_id = saddr.id;
+	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
-		opts->addr_id = id;
-		opts->addr = ((struct sockaddr_in *)&saddr)->sin_addr;
-		*size = TCPOLEN_MPTCP_ADD_ADDR;
+		opts->addr = saddr.addr;
 	}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	else if (saddr.ss_family == AF_INET6) {
-		if (remaining < TCPOLEN_MPTCP_ADD_ADDR6)
-			return false;
+	else if (saddr.family == AF_INET6) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
-		opts->addr_id = id;
-		opts->addr6 = ((struct sockaddr_in6 *)&saddr)->sin6_addr;
-		*size = TCPOLEN_MPTCP_ADD_ADDR6;
+		opts->addr6 = saddr.addr6;
 	}
 #endif
 
@@ -557,13 +553,20 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 		return;
 
 	if (msk && mp_opt->add_addr) {
-		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4)
-			mptcp_pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+		struct mptcp_addr_info addr;
+
+		addr.id = mp_opt->addr_id;
+		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+			addr.family = AF_INET;
+			addr.addr = mp_opt->addr;
+		}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-		else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6)
-			mptcp_pm_add_addr6(msk, &mp_opt->addr6,
-					   mp_opt->addr_id);
+		else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6) {
+			addr.family = AF_INET6;
+			addr.addr6 = mp_opt->addr6;
+		}
 #endif
+		mptcp_pm_add_addr(msk, &addr);
 		mp_opt->add_addr = 0;
 	}
 
net/mptcp/pm.c +33 -76

167 lines not on this page · raw message

net/mptcp/protocol.c +2 -0
index 620af9d1c6bc..a30d26661b61 100644
@@ -605,6 +605,8 @@ static int __mptcp_init_sock(struct sock *sk)
 
 	msk->first = NULL;
 
+	mptcp_pm_data_init(msk);
+
 	return 0;
 }
 
net/mptcp/protocol.h +58 -38

119 lines not on this page · raw message

Signature · 1 line
2.21.1
#3 lore raw

[MPTCP] Re: [RFC PATCH 2/6] Squash-to: "mptcp: Add path manager interface"

net/mptcp/protocol.h static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) · line 111

Quoted 12 lines · Paolo Abeni
net/mptcp/protocol.h +12 -0
+struct mptcp_pm_data {
+	struct mptcp_addr_info local;
+	struct mptcp_addr_info remote;
+
+	spinlock_t	lock;
+
+	bool		addr_signal;
+	bool		server_side;
+	bool		fully_established;
+	enum mptcp_pm_status status;
+	u8		add_addr_signaled;
+	u8		add_addr_accepted;

Why are the first three bool and the rest u8?

We should probably avoid "bool" in structs.
Perhaps use foo:1 as most of net stack?

author
#4 lore raw

[MPTCP] Re: [RFC PATCH 2/6] Squash-to: "mptcp: Add path manager interface"

Quoted 15 lines · Florian Westphal

net/mptcp/protocol.h static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) · line 111

Quoted 12 lines · Paolo Abeni
net/mptcp/protocol.h +12 -0
+struct mptcp_pm_data {
+	struct mptcp_addr_info local;
+	struct mptcp_addr_info remote;
+
+	spinlock_t	lock;
+
+	bool		addr_signal;
+	bool		server_side;
+	bool		fully_established;
+	enum mptcp_pm_status status;
+	u8		add_addr_signaled;
+	u8		add_addr_accepted;

Why are the first three bool and the rest u8?

'addr_signal', 'server_side' and 'fully_established' have bool semantics, while the others are counter, maxing at 255.

Quoted 1 line

We should probably avoid "bool" in structs.

IIRC the bitfield usage force the compiler to emit worse code, as such I thought it was suggested only for size-critical structs?!? (mptcp pernet does not have stict memory constraint).

Quoted 1 line

Perhaps use foo:1 as most of net stack?

uhm?!? quick && dirty grep count shows more bool field than ':1;' under include/net/ !?!

Thanks,

Paolo

author
#5 lore raw

RFC PATCH 3/6 Squash-to: "mptcp: Add handling of incoming MP_JOIN requests"

In reply to Paolo Abeni

Update mptcp_pm_get_local_id() callers to new API.

Hook mptcp_pm_subflow_established() when MP_JOIN completes successfully

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c | 7 +++++--
 net/mptcp/subflow.c | 5 ++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
net/mptcp/options.c +5 -2
index 43bfeb3fa753..c2e0576065b6 100644
@@ -128,7 +128,6 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 		}
 		break;
 
-
 	case MPTCPOPT_DSS:
 		pr_debug("DSS");
 		ptr++;
@@ -565,8 +564,12 @@ static bool check_fourth_ack(struct mptcp_subflow_context *subflow,
 		   TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1))
 		return true;
 
-	if (mp_opt->use_ack)
+	if (mp_opt->use_ack) {
 		subflow->fourth_ack = 1;
+		if (subflow->mp_join)
+			mptcp_pm_subflow_established(mptcp_sk(subflow->conn),
+						     subflow);
+	}
 
 	if (subflow->can_ack)
 		return true;
net/mptcp/subflow.c +4 -1
index a8dedbd8d458..5710b439e418 100644
@@ -55,6 +55,7 @@ static bool subflow_token_join_request(struct request_sock *req,
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
 	u8 hmac[MPTCPOPT_HMAC_LEN];
 	struct mptcp_sock *msk;
+	int local_id;
 
 	msk = mptcp_token_get_sock(subflow_req->token);
 	if (!msk) {
@@ -63,10 +64,12 @@ static bool subflow_token_join_request(struct request_sock *req,
 		return false;
 	}
 
-	if (mptcp_pm_get_local_id(req, (struct sock *)msk, skb)) {
+	local_id = mptcp_pm_get_local_id(msk, (struct sock_common *)req);
+	if (local_id < 0) {
 		sock_put((struct sock *)msk);
 		return false;
 	}
+	subflow_req->local_id = local_id;
 
 	get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
 
Signature · 1 line
2.21.1
author
#6 lore raw

RFC PATCH 4/6 Squash-to: "mptcp: Add handling of outgoing MP_JOIN requests"

In reply to Paolo Abeni

record local id for outgoing MP_JOIN connection.

join_id is the local address id, set as such in mptcp_syn_options()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  |  2 +-
 net/mptcp/protocol.h |  6 +++--
 net/mptcp/subflow.c  | 58 ++++++++++++++++++++++++++++++++------------
 3 files changed, 47 insertions(+), 19 deletions(-)
net/mptcp/options.c +1 -1
index 29ccff13412e..2716cbc0953f 100644
@@ -309,7 +309,7 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 		pr_debug("remote_token=%u, nonce=%u", subflow->remote_token,
 			 subflow->local_nonce);
 		opts->suboptions = OPTION_MPTCP_MPJ_SYN;
-		opts->join_id = subflow->remote_id;
+		opts->join_id = subflow->local_id;
 		opts->token = subflow->remote_token;
 		opts->nonce = subflow->local_nonce;
 		opts->backup = subflow->request_bkup;
net/mptcp/protocol.h +4 -2
index f35f34eeda82..9b6d7f7ee244 100644
@@ -254,8 +254,10 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
 int mptcp_is_enabled(struct net *net);
 bool mptcp_subflow_data_available(struct sock *sk);
 void mptcp_subflow_init(void);
-int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,
-			  struct sockaddr *remote, u8 remote_id);
+
+/* called with sk socket lock held */
+int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
+			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
net/mptcp/subflow.c +42 -16

120 lines not on this page · raw message

Signature · 1 line
2.21.1
author
#7 lore raw

RFC PATCH 5/6 Squash-to: "mptcp: Implement path manager interface commands"

In reply to Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/pm.c | 213 +++++++++++++++++++++++++------------------------
 1 file changed, 107 insertions(+), 106 deletions(-)
net/mptcp/pm.c +107 -106
index 52c89e5a7d4f..5323945216f2 100644
@@ -15,117 +15,17 @@ static struct workqueue_struct *pm_wq;
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	int err = 0;
+	pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
-	if (!msk)
-		return -EINVAL;
-
-	if (msk->pm.local_valid) {
-		err = -EBADR;
-		goto announce_put;
-	}
-
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
-	msk->pm.local_valid = 1;
-	msk->pm.local_id = local_id;
-	msk->pm.local_family = AF_INET;
-	msk->pm.local_addr = *addr;
-	msk->addr_signal = 1;
-
-announce_put:
-	sock_put((struct sock *)msk);
-	return err;
-}
-
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	msk->pm.local_valid = 0;
-
-	sock_put((struct sock *)msk);
+	msk->pm.local = *addr;
+	WRITE_ONCE(msk->pm.addr_signal, true);
 	return 0;
 }
 
-int mptcp_pm_create_subflow(u32 token, u8 remote_id, struct in6_addr *addr)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in6 remote;
-	struct sockaddr_in6 local;
-	struct sock *sk;
-	int err;
-
-	pr_debug("msk=%p", msk);
-
-	sk = (struct sock *)msk;
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin_family = AF_INET;
-	local.sin_port = 0;
-	if (addr)
-		local.sin_addr = *addr;
-	else
-		local.sin_addr.s_addr = htonl(INADDR_ANY);
-
-	remote.sin_family = msk->pm.remote_family;
-	remote.sin_port = inet_sk(sk)->inet_dport;
-	remote.sin_addr = msk->pm.remote_addr;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
-}
-
-#if IS_ENABLED(CONFIG_MPTCP_IPV6)
-int mptcp_pm_create_subflow6(u32 token, u8 remote_id, struct in6_addr *addr)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in6 remote;
-	struct sockaddr_in6 local;
-	struct sock *sk;
-	int err;
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	sk = (struct sock *)msk;
-
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin6_family = AF_INET6;
-	local.sin6_port = 0;
-	if (addr)
-		local.sin6_addr = *addr;
-	else
-		local.sin6_addr = in6addr_any;
-
-	remote.sin6_family = msk->pm.remote_family;
-	remote.sin6_port = inet_sk(sk)->inet_dport;
-	remote.sin6_addr = msk->pm.remote_addr6;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
+	return -ENOTSUPP;
 }
-#endif
 
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id)
 {
@@ -143,11 +43,47 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)
 	WRITE_ONCE(pm->server_side, server_side);
 }
 
+static bool mptcp_pm_work_pending(const struct mptcp_pm_data *pm)
+{
+	return (READ_ONCE(pm->local_addr_used) <
+		READ_ONCE(pm->local_addr_max)) ||
+	       (READ_ONCE(pm->add_addr_signaled) <
+		READ_ONCE(pm->add_addr_signal_max));
+}
+
+static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
+				   enum mptcp_pm_status new_status)
+{
+	if (msk->pm.status != MPTCP_PM_IDLE)
+		return false;
+
+	if (queue_work(pm_wq, &msk->pm.work)) {
+		msk->pm.status = new_status;
+		sock_hold((struct sock *)msk);
+		return true;
+	}
+	return false;
+}
+
 void mptcp_pm_fully_established(struct mptcp_sock *msk)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
 	pr_debug("msk=%p", msk);
+
+	/* try to avoid acquiring the lock below */
+	if (READ_ONCE(pm->fully_established) || !mptcp_pm_work_pending(pm))
+		return;
+
+	spin_lock_bh(&pm->lock);
+	if (READ_ONCE(pm->fully_established))
+		goto out_unlock;
+
+	if (mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED))
+		WRITE_ONCE(pm->fully_established, true);
+
+out_unlock:
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_connection_closed(struct mptcp_sock *msk)
@@ -158,7 +94,19 @@ void mptcp_pm_connection_closed(struct mptcp_sock *msk)
 void mptcp_pm_subflow_established(struct mptcp_sock *msk,
 				  struct mptcp_subflow_context *subflow)
 {
+	struct mptcp_pm_data *pm = &msk->pm;
+
 	pr_debug("msk=%p", msk);
+
+	if (!mptcp_pm_work_pending(pm))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	if (mptcp_pm_work_pending(pm))
+		mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
+
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)
@@ -170,8 +118,30 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 		       const struct mptcp_addr_info *addr)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
+	unsigned max, cur;
 
 	pr_debug("msk=%p, remote_id=%d", msk, addr->id);
+
+	/* avoid acquiring the lock if there is no room for fouther addresses */
+	if (READ_ONCE(pm->add_addr_accepted) >=
+	    READ_ONCE(pm->add_addr_accept_max))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	/* be sure there is something to signal re-checking under PM lock */
+	max = READ_ONCE(pm->add_addr_accept_max);
+	cur = READ_ONCE(pm->add_addr_accepted);
+	if (cur >= max)
+		goto unlock;
+
+	if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR)) {
+		WRITE_ONCE(pm->add_addr_accepted, cur + 1);
+		pm->remote = *addr;
+	}
+
+unlock:
+	spin_unlock_bh(&pm->lock);
 }
 
 /* path manager helpers */
@@ -179,7 +149,27 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 int mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			 struct mptcp_addr_info *saddr)
 {
-	return 0;
+	struct mptcp_addr_info addr;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	/* load real data */
+	memset(&addr, 0, sizeof(addr));
+
+	if (remaining < mptcp_add_addr_len(saddr->family))
+		goto out_unlock;
+
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = 0;
+
+out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
 }
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
@@ -189,6 +179,17 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 
 static void pm_worker(struct work_struct *work)
 {
+	struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data,
+						work);
+	struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm);
+	struct sock *sk = (struct sock *)msk;
+
+	switch (pm->status) {
+	default:
+		break;
+	}
+
+	sock_put(sk);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
Signature · 1 line
2.21.1
#8 lore raw

[MPTCP] Re: [RFC PATCH 5/6] Squash-to: "mptcp: Implement path manager interface commands"

Quoted 141 lines · Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
net/mptcp/pm.c | 213 +++++++++++++++++++++++++------------------------

1 file changed, 107 insertions(+), 106 deletions(-)
net/mptcp/pm.c +5 -105
index 52c89e5a7d4f..5323945216f2 100644
@@ -15,117 +15,17 @@ static struct workqueue_struct *pm_wq;
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	int err = 0;
+	pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
-	if (!msk)
-		return -EINVAL;
-
-	if (msk->pm.local_valid) {
-		err = -EBADR;
-		goto announce_put;
-	}
-
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
-	msk->pm.local_valid = 1;
-	msk->pm.local_id = local_id;
-	msk->pm.local_family = AF_INET;
-	msk->pm.local_addr = *addr;
-	msk->addr_signal = 1;
-
-announce_put:
-	sock_put((struct sock *)msk);
-	return err;
-}
-
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	msk->pm.local_valid = 0;
-
-	sock_put((struct sock *)msk);
+	msk->pm.local = *addr;
+	WRITE_ONCE(msk->pm.addr_signal, true);
 	return 0;
 }
 
-int mptcp_pm_create_subflow(u32 token, u8 remote_id, struct in6_addr *addr)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in6 remote;
-	struct sockaddr_in6 local;
-	struct sock *sk;
-	int err;
-
-	pr_debug("msk=%p", msk);
-
-	sk = (struct sock *)msk;
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin_family = AF_INET;
-	local.sin_port = 0;
-	if (addr)
-		local.sin_addr = *addr;
-	else
-		local.sin_addr.s_addr = htonl(INADDR_ANY);
-
-	remote.sin_family = msk->pm.remote_family;
-	remote.sin_port = inet_sk(sk)->inet_dport;
-	remote.sin_addr = msk->pm.remote_addr;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
-}
-
-#if IS_ENABLED(CONFIG_MPTCP_IPV6)
-int mptcp_pm_create_subflow6(u32 token, u8 remote_id, struct in6_addr *addr)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in6 remote;
-	struct sockaddr_in6 local;
-	struct sock *sk;
-	int err;
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	sk = (struct sock *)msk;
-
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin6_family = AF_INET6;
-	local.sin6_port = 0;
-	if (addr)
-		local.sin6_addr = *addr;
-	else
-		local.sin6_addr = in6addr_any;
-
-	remote.sin6_family = msk->pm.remote_family;
-	remote.sin6_port = inet_sk(sk)->inet_dport;
-	remote.sin6_addr = msk->pm.remote_addr6;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
+	return -ENOTSUPP;
 }
-#endif
 
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id)
 {

net/mptcp/pm.c void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side) · line 52

Quoted 10 lines
net/mptcp/pm.c +7 -0
@@ -143,11 +43,47 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)
 	WRITE_ONCE(pm->server_side, server_side);
 }
 
+static bool mptcp_pm_work_pending(const struct mptcp_pm_data *pm)
+{
+	return (READ_ONCE(pm->local_addr_used) <
+		READ_ONCE(pm->local_addr_max)) ||
+	       (READ_ONCE(pm->add_addr_signaled) <
+		READ_ONCE(pm->add_addr_signal_max));
+}

It looks like these values are only modified under a lock, but are read some of the time without a lock. If the values are concurrently modified is it harmless? It would be helpful to have at least a comment explaining the expected locking semantics.

Would it be overkill to pack the values that are compared (like local_addr_used and local_addr_max) so they can be read & written together?

Mat

Quoted 137 lines
net/mptcp/pm.c +95 -1
+
+static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
+				   enum mptcp_pm_status new_status)
+{
+	if (msk->pm.status != MPTCP_PM_IDLE)
+		return false;
+
+	if (queue_work(pm_wq, &msk->pm.work)) {
+		msk->pm.status = new_status;
+		sock_hold((struct sock *)msk);
+		return true;
+	}
+	return false;
+}
+
 void mptcp_pm_fully_established(struct mptcp_sock *msk)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
 	pr_debug("msk=%p", msk);
+
+	/* try to avoid acquiring the lock below */
+	if (READ_ONCE(pm->fully_established) || !mptcp_pm_work_pending(pm))
+		return;
+
+	spin_lock_bh(&pm->lock);
+	if (READ_ONCE(pm->fully_established))
+		goto out_unlock;
+
+	if (mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED))
+		WRITE_ONCE(pm->fully_established, true);
+
+out_unlock:
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_connection_closed(struct mptcp_sock *msk)
@@ -158,7 +94,19 @@ void mptcp_pm_connection_closed(struct mptcp_sock *msk)
 void mptcp_pm_subflow_established(struct mptcp_sock *msk,
 				  struct mptcp_subflow_context *subflow)
 {
+	struct mptcp_pm_data *pm = &msk->pm;
+
 	pr_debug("msk=%p", msk);
+
+	if (!mptcp_pm_work_pending(pm))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	if (mptcp_pm_work_pending(pm))
+		mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
+
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)
@@ -170,8 +118,30 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 		       const struct mptcp_addr_info *addr)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
+	unsigned max, cur;
 
 	pr_debug("msk=%p, remote_id=%d", msk, addr->id);
+
+	/* avoid acquiring the lock if there is no room for fouther addresses */
+	if (READ_ONCE(pm->add_addr_accepted) >=
+	    READ_ONCE(pm->add_addr_accept_max))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	/* be sure there is something to signal re-checking under PM lock */
+	max = READ_ONCE(pm->add_addr_accept_max);
+	cur = READ_ONCE(pm->add_addr_accepted);
+	if (cur >= max)
+		goto unlock;
+
+	if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR)) {
+		WRITE_ONCE(pm->add_addr_accepted, cur + 1);
+		pm->remote = *addr;
+	}
+
+unlock:
+	spin_unlock_bh(&pm->lock);
 }
 
 /* path manager helpers */
@@ -179,7 +149,27 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 int mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			 struct mptcp_addr_info *saddr)
 {
-	return 0;
+	struct mptcp_addr_info addr;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	/* load real data */
+	memset(&addr, 0, sizeof(addr));
+
+	if (remaining < mptcp_add_addr_len(saddr->family))
+		goto out_unlock;
+
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = 0;
+
+out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
 }
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
@@ -189,6 +179,17 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 
 static void pm_worker(struct work_struct *work)
 {
+	struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data,
+						work);
+	struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm);
+	struct sock *sk = (struct sock *)msk;
+
+	switch (pm->status) {
+	default:
+		break;
+	}
+
+	sock_put(sk);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
Signature · 1 line
2.21.1

--
Mat Martineau
Intel

author
#9 lore raw

[MPTCP] Re: [RFC PATCH 5/6] Squash-to: "mptcp: Implement path manager interface commands"

Quoted 13 lines · Mat Martineau

+static bool mptcp_pm_work_pending(const struct mptcp_pm_data *pm)

net/mptcp/pm.c void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side) · line 52

Quoted 6 lines
net/mptcp/pm.c +6 -0
+{
+	return (READ_ONCE(pm->local_addr_used) <
+		READ_ONCE(pm->local_addr_max)) ||
+	       (READ_ONCE(pm->add_addr_signaled) <
+		READ_ONCE(pm->add_addr_signal_max));
+}

It looks like these values are only modified under a lock, but are read some of the time without a lock. If the values are concurrently modified is it harmless? It would be helpful to have at least a comment explaining the expected locking semantics.

Quoted 3 lines

Would it be overkill to pack the values that are compared (like local_addr_used and local_addr_max) so they can be read & written together?

Thank you for the feedback! I'm double minded about this READ_ONCE stuff. I'd like to avoid lock osperation when possible but I agree the current impl is ugly.

What if I a single 'work_pending' bool in 'struct mptcp_pm_data', let pm_netlink WRITE_ONCE it as needed, and use it to replace the above code?

Thanks,

Paolo

@Florian: addendum WRT bool vs u8:1 usage: I need 'bool' type to {WRITE,READ}_ONCE. Are you ok if I keep using bool?

#10 lore raw

[MPTCP] Re: [RFC PATCH 5/6] Squash-to: "mptcp: Implement path manager interface commands"

Quoted 18 lines · Paolo Abeni
Quoted 13 lines · Mat Martineau

+static bool mptcp_pm_work_pending(const struct mptcp_pm_data *pm)

net/mptcp/pm.c void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side) · line 52

Quoted 6 lines
net/mptcp/pm.c +6 -0
+{
+	return (READ_ONCE(pm->local_addr_used) <
+		READ_ONCE(pm->local_addr_max)) ||
+	       (READ_ONCE(pm->add_addr_signaled) <
+		READ_ONCE(pm->add_addr_signal_max));
+}

It looks like these values are only modified under a lock, but are read some of the time without a lock. If the values are concurrently modified is it harmless? It would be helpful to have at least a comment explaining the expected locking semantics.

Quoted 3 lines

Would it be overkill to pack the values that are compared (like local_addr_used and local_addr_max) so they can be read & written together?

Quoted 8 lines

Thank you for the feedback! I'm double minded about this READ_ONCE stuff. I'd like to avoid lock osperation when possible but I agree the current impl is ugly.

What if I a single 'work_pending' bool in 'struct mptcp_pm_data', let pm_netlink WRITE_ONCE it as needed, and use it to replace the above code?

Sure, that looks like a safe approach.

--
Mat Martineau
Intel

author
#11 lore raw

RFC PATCH 6/6 mptcp: add netlink based PM

In reply to Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack the ADD_ADDR echo (and related event) only the first addr is sent.

Idea is to add an additional PM hook for ADD_ADDR echo, to allow the PM netlink announcing multiple addresses, in sequence.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h |  42 +++
 net/mptcp/Makefile         |   3 +-
 net/mptcp/pm.c             |  18 +-
 net/mptcp/pm_netlink.c     | 524 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h       |   7 +
 5 files changed, 592 insertions(+), 2 deletions(-)
 create mode 100644 net/mptcp/pm_netlink.c
include/uapi/linux/mptcp.h +42 -0
index 3912a9808fa2..ec176be789fa 100644
@@ -31,4 +31,46 @@ enum {
 };
 
 #define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1)
+
+/* netlink interface */
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,
+
+	MPTCP_PM_ATTR_ADDR_LIST,			/* nested list */
+	MPTCP_PM_ATTR_ADD_ADDR_MAX,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_NS_SIGNAL,
+	MPTCP_CMD_NS_LOCAL,
+	MPTCP_CMD_NS_ADD_ADDR_MAX,
+
+	__MPTCP_CMD_AFTER_LAST
+};
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +2 -1
index faebe8ec9f73..baa0640527c7 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o mib.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
+	   mib.o pm_netlink.o
net/mptcp/pm.c +17 -1
index 5323945216f2..a813c090d0c2 100644
@@ -174,7 +174,7 @@ int mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 {
-	return 0;
+	return mptcp_pm_nl_get_local_id(msk, skc);
 }
 
 static void pm_worker(struct work_struct *work)
@@ -185,6 +185,18 @@ static void pm_worker(struct work_struct *work)
 	struct sock *sk = (struct sock *)msk;
 
 	switch (pm->status) {
+	case MPTCP_PM_ADD_ADDR:
+		mptcp_pm_nl_add_addr(msk);
+		break;
+
+	case MPTCP_PM_ESTABLISHED:
+		mptcp_pm_nl_fully_established(msk);
+		break;
+
+	case MPTCP_PM_SUBFLOW_ESTABLISHED:
+		mptcp_pm_nl_subflow_established(msk);
+		break;
+
 	default:
 		break;
 	}
@@ -202,6 +214,8 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 
 	spin_lock_init(&msk->pm.lock);
 	INIT_WORK(&msk->pm.work, pm_worker);
+
+	mptcp_pm_nl_data_init(msk);
 }
 
 void mptcp_pm_init(void)
@@ -209,4 +223,6 @@ void mptcp_pm_init(void)
 	pm_wq = alloc_workqueue("pm_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, 8);
 	if (!pm_wq)
 		panic("Failed to allocate workqueue");
+
+	mptcp_pm_nl_init();
 }
net/mptcp/pm_netlink.c new file +524 -0

524 lines not on this page · raw message

net/mptcp/protocol.h +7 -0
index 2060832123c2..d918e5aeefc1 100644
@@ -384,6 +384,13 @@ int mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			 struct mptcp_addr_info *saddr);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
+void mptcp_pm_nl_init(void);
+void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
+void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk);
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
+
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
 	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
Signature · 1 line
2.21.1
author
#12 lore raw

[MPTCP] Re: [RFC PATCH 6/6] mptcp: add netlink based PM

Quoted 22 lines · Paolo Abeni
include/uapi/linux/mptcp.h +22 -0
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,
+
+	MPTCP_PM_ATTR_ADDR_LIST,			/* nested list */
+	MPTCP_PM_ATTR_ADD_ADDR_MAX,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+
+	__MPTCP_PM_ADDR_ATTR_MAX

include/uapi/linux/mptcp.h enum { · line 71

Quoted 10 lines
include/uapi/linux/mptcp.h +10 -0
+};
+
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_NS_SIGNAL,
+	MPTCP_CMD_NS_LOCAL,
+	MPTCP_CMD_NS_ADD_ADDR_MAX,

Starting the self-test implementation, I noticed changing the above ABI a bit would make things simpler:

instead of MPTCP_CMD_NS_SIGNAL,

MPTCP_CMD_SIGNAL_ADD // adds a single addr to the 'signal' list

MPTCP_CMD_SIGNAL_DEL // remote an address from 'signal' list
by id
MPTCP_CMD_SIGNAL_GET // 'doit' get a single address from
// list, by id
// 'dumpit' dump the whole list.
MPTCP_CMD_SIGNAL_FLUSH // remove all addresses from 'signal'

				// list

And similar changes for 'MPTCP_CMD_NS_LOCAL' Also, I'dd an additional addr MPTCP_PM_ADDR_ATTR_ID

Any feedback welcome!

Thanks,

Paolo

#13 lore raw

[MPTCP] Re: [RFC PATCH 6/6] mptcp: add netlink based PM

In reply to Paolo Abeni
Quoted 10 lines · Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

Quoted 6 lines

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack the ADD_ADDR echo (and related event) only the first addr is sent.

Idea is to add an additional PM hook for ADD_ADDR echo, to allow the PM netlink announcing multiple addresses, in sequence.

Makes sense, thanks!

net/mptcp/pm_netlink.c line 263

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+static const struct nla_policy mptcp_pm_addr_policy[MPTCP_PM_ADDR_ATTR_MAX + 1] = {
+	[MPTCP_PM_ADDR_ATTR_FAMILY]	= { .type	= NLA_U16,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR4]	= { .type	= NLA_U32,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR6]	= { .type	= NLA_BINARY,

NLA_EXACT_LEN?

NLA_BINARY is weird (it allows shorter sizes...).

author
#14 lore raw

[MPTCP] Re: [RFC PATCH 6/6] mptcp: add netlink based PM

Quoted 8 lines · Florian Westphal

net/mptcp/pm_netlink.c line 263

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+static const struct nla_policy mptcp_pm_addr_policy[MPTCP_PM_ADDR_ATTR_MAX + 1] = {
+	[MPTCP_PM_ADDR_ATTR_FAMILY]	= { .type	= NLA_U16,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR4]	= { .type	= NLA_U32,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR6]	= { .type	= NLA_BINARY,

NLA_EXACT_LEN?

NLA_BINARY is weird (it allows shorter sizes...).

yup, thanks! I'm diving into the netlink APIs for the first time ;)

Will fix in the next iteration.

Thanks,

Paolo

author
#15 lore raw

[MPTCP] Re: [RFC PATCH 0/6] add locking to PM APis, implement PM netlink

In reply to Paolo Abeni
Quoted 16 lines · Paolo Abeni

Sending as an early RFC to gather feedback, as this is proving to be more intrusive that what I initially hoped for.

This implement the locking required by the PM to allow concurent subflow accessing the msk PM data in a safe way. Such data is protected via a msk-level spinlock. It relies on the Double checked locking to avoid contention in the most common scenarion (no or very little PM "actions").

Overall the above adds quite a bit of code churn, is that a too premature optimization? On the flip side, the whole PM processing should be quite light on the CPU in most cases.

Additionally changes more than a bit the PM hooks/APIs, to be hopefully simpler and avoiding duplicate code (no v4/v6 variant, work queue management done by the core PM infra).

Quoted 7 lines

It also introduce the PM netlink - should replace the current basic ones. Completely untested but please have a look at the specified netlink uAPI.

TODO:
- implement U/S helper
- self-tests
- do we need NL dump operation to inspect the PM netlink status?

The current snapshot of this work is available here:

https://github.com/pabeni/mptcp/tree/mptcp_net-next_part3_4

It includes some APIs schanges, basic self-tests for the NL APIs, a bunch of bugfixes, but I still have to include Mat's feedback and full MP_JOIN self-tests.

Cheers,

Paolo