Skip to contentSkip to conversation

tcp: mptcp: use mptcp receive buffer space to select rcv window

RFC In review Florian Westphal 2 participants 5 messages Mar 18, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 tcp: mptcp: use mptcp receive buffer space to select rcv window

In MPTCP, the receive windo is shared across all subflows, because it refers to the mptcp-level sequence space.

This commit doesn't change choice of initial window for passive or active connections.
While it would be possible to change those as well, this adds complexity (especially when handling MP_JOIN requests).

However, the MPTCP RFC specifically says that a MPTCP sender 'MUST NOT use the RCV.WND field of a TCP segment at the connection level if it does not also carry a DSS option with a Data ACK field.'

SYN/SYNACK packets do not carry a DSS option with a Data ACK field.

CC Eric Dumazet <edumazet(a)google.com>
Signed-off-by Florian Westphal <fw(a)strlen.de>

---
This patch would add additional direct call in __tcp_select_window().

I looked at mptcp option writing to check if it could be done there but that seemed worse.

 include/net/mptcp.h   |  3 +++
 net/ipv4/tcp_output.c |  5 +++++
 net/mptcp/subflow.c   | 17 +++++++++++++++++
 3 files changed, 25 insertions(+)
include/net/mptcp.h +3 -0
index 7489f9267640..1ef4520f45c3 100644
@@ -66,6 +66,8 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
+void mptcp_space(const struct sock *ssk, int *space, int *full_space);
+
 void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 			int opsize, struct tcp_options_received *opt_rx);
 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
@@ -195,6 +197,7 @@ static inline bool mptcp_sk_is_subflow(const struct sock *sk)
 	return false;
 }
 
+static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
 static inline void mptcp_seq_show(struct seq_file *seq) { }
 #endif /* CONFIG_MPTCP */
 
net/ipv4/tcp_output.c +5 -0
index 306e25d743e8..1a829536a115 100644
@@ -2771,6 +2771,11 @@ u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
+	if (sk_is_mptcp(sk)) {
+		mptcp_space(sk, &free_space, &allowed_space);
+		full_space = min_t(int, tp->window_clamp, allowed_space);
+	}
+
 	if (unlikely(mss > full_space)) {
 		mss = full_space;
 		if (mss <= 0)
net/mptcp/subflow.c +17 -0
index 40ad7995b13b..aefcbb8bb737 100644
@@ -745,6 +745,23 @@ bool mptcp_subflow_data_available(struct sock *sk)
 	return subflow->data_avail;
 }
 
+/* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
+ * not the ssk one.
+ *
+ * In mptcp, rwin is about the mptcp-level connection data.
+ *
+ * Data that is still on the ssk rx queue can thus be ignored,
+ * as far as mptcp peer is concerened that data is still inflight.
+ */
+void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+{
+	const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	const struct sock *sk = READ_ONCE(subflow->conn);
+
+	*space = tcp_space(sk);
+	*full_space = tcp_full_space(sk);
+}
+
 static void subflow_data_ready(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
Signature · 1 line
2.24.1
#1 lore raw
Quoted 53 lines · Florian Westphal

In MPTCP, the receive windo is shared across all subflows, because it refers to the mptcp-level sequence space.

This commit doesn't change choice of initial window for passive or active connections.
While it would be possible to change those as well, this adds complexity (especially when handling MP_JOIN requests).

However, the MPTCP RFC specifically says that a MPTCP sender 'MUST NOT use the RCV.WND field of a TCP segment at the connection level if it does not also carry a DSS option with a Data ACK field.'

SYN/SYNACK packets do not carry a DSS option with a Data ACK field.

CC Eric Dumazet <edumazet(a)google.com>
Signed-off-by Florian Westphal <fw(a)strlen.de>

---
This patch would add additional direct call in __tcp_select_window().

I looked at mptcp option writing to check if it could be done there but that seemed worse.

 include/net/mptcp.h   |  3 +++
 net/ipv4/tcp_output.c |  5 +++++
 net/mptcp/subflow.c   | 17 +++++++++++++++++
 3 files changed, 25 insertions(+)
include/net/mptcp.h +3 -0
index 7489f9267640..1ef4520f45c3 100644
@@ -66,6 +66,8 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
+void mptcp_space(const struct sock *ssk, int *space, int *full_space);
+
 void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 			int opsize, struct tcp_options_received *opt_rx);
 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
@@ -195,6 +197,7 @@ static inline bool mptcp_sk_is_subflow(const struct sock *sk)
 	return false;
 }
 
+static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
 static inline void mptcp_seq_show(struct seq_file *seq) { }
 #endif /* CONFIG_MPTCP */
 
net/ipv4/tcp_output.c +0 -0
index 306e25d743e8..1a829536a115 100644

net/ipv4/tcp_output.c u32 __tcp_select_window(struct sock *sk) · line 2777

Quoted 7 lines
net/ipv4/tcp_output.c +4 -0
@@ -2771,6 +2771,11 @@ u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
+	if (sk_is_mptcp(sk)) {
+		mptcp_space(sk, &free_space, &allowed_space);
+		full_space = min_t(int, tp->window_clamp, allowed_space);
+	}

You could move the full_space = min_t(int, tp->window_clamp, allowed_space); after this block factorize it.

Quoted 14 lines
net/ipv4/tcp_output.c +1 -0
+
 	if (unlikely(mss > full_space)) {
 		mss = full_space;
 		if (mss <= 0)
net/mptcp/subflow.c +2 -0
index 40ad7995b13b..aefcbb8bb737 100644
@@ -745,6 +745,23 @@ bool mptcp_subflow_data_available(struct sock *sk)
 	return subflow->data_avail;
 }
 
+/* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
+ * not the ssk one.

net/mptcp/subflow.c bool mptcp_subflow_data_available(struct sock *sk) · line 759

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+ *
+ * In mptcp, rwin is about the mptcp-level connection data.
+ *
+ * Data that is still on the ssk rx queue can thus be ignored,
+ * as far as mptcp peer is concerened that data is still inflight.
+ */
+void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+{
+	const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	const struct sock *sk = READ_ONCE(subflow->conn);

What are the rules protecting subflow->conn lifetime ?

Why dereferencing sk after this line is safe ?

Quoted 9 lines
net/mptcp/subflow.c +5 -0
+
+	*space = tcp_space(sk);
+	*full_space = tcp_full_space(sk);
+}
+
 static void subflow_data_ready(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
#2 lore raw
Quoted 11 lines · Eric Dumazet

net/ipv4/tcp_output.c u32 __tcp_select_window(struct sock *sk) · line 2777

Quoted 8 lines
net/ipv4/tcp_output.c +4 -0
@@ -2771,6 +2771,11 @@ u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
+	if (sk_is_mptcp(sk)) {
+		mptcp_space(sk, &free_space, &allowed_space);
+		full_space = min_t(int, tp->window_clamp, allowed_space);
+	}

You could move the full_space = min_t(int, tp->window_clamp, allowed_space); after this block factorize it.

Indeed, will do.

Quoted 23 lines
Quoted 10 lines
net/mptcp/subflow.c +2 -0
index 40ad7995b13b..aefcbb8bb737 100644
@@ -745,6 +745,23 @@ bool mptcp_subflow_data_available(struct sock *sk)
 	return subflow->data_avail;
 }
 
+/* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
+ * not the ssk one.

net/mptcp/subflow.c bool mptcp_subflow_data_available(struct sock *sk) · line 759

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+ *
+ * In mptcp, rwin is about the mptcp-level connection data.
+ *
+ * Data that is still on the ssk rx queue can thus be ignored,
+ * as far as mptcp peer is concerened that data is still inflight.
+ */
+void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+{
+	const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	const struct sock *sk = READ_ONCE(subflow->conn);

What are the rules protecting subflow->conn lifetime ?

Quoted 1 line

Why dereferencing sk after this line is safe ?

Subflow sockets hold a reference on the master/parent mptcp-socket.

#3 lore raw
Quoted 38 lines · Florian Westphal
Quoted 11 lines · Eric Dumazet

net/ipv4/tcp_output.c u32 __tcp_select_window(struct sock *sk) · line 2777

Quoted 8 lines
net/ipv4/tcp_output.c +4 -0
@@ -2771,6 +2771,11 @@ u32 __tcp_select_window(struct sock *sk)
 	int full_space = min_t(int, tp->window_clamp, allowed_space);
 	int window;
 
+	if (sk_is_mptcp(sk)) {
+		mptcp_space(sk, &free_space, &allowed_space);
+		full_space = min_t(int, tp->window_clamp, allowed_space);
+	}

You could move the full_space = min_t(int, tp->window_clamp, allowed_space); after this block factorize it.

Indeed, will do.

Quoted 23 lines
Quoted 10 lines
net/mptcp/subflow.c +2 -0
index 40ad7995b13b..aefcbb8bb737 100644
@@ -745,6 +745,23 @@ bool mptcp_subflow_data_available(struct sock *sk)
 	return subflow->data_avail;
 }
 
+/* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
+ * not the ssk one.

net/mptcp/subflow.c bool mptcp_subflow_data_available(struct sock *sk) · line 759

Quoted 10 lines
net/mptcp/subflow.c +10 -0
+ *
+ * In mptcp, rwin is about the mptcp-level connection data.
+ *
+ * Data that is still on the ssk rx queue can thus be ignored,
+ * as far as mptcp peer is concerened that data is still inflight.
+ */
+void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+{
+	const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	const struct sock *sk = READ_ONCE(subflow->conn);

What are the rules protecting subflow->conn lifetime ?

Quoted 4 lines
Quoted 1 line

Why dereferencing sk after this line is safe ?

Subflow sockets hold a reference on the master/parent mptcp-socket.

Presence of READ_ONCE() tells something might happen on this pointer after you read it.

Can this pointer be set while this thread is owning the socket lock ?

If not, then you do not need READ_ONCE(), this is confusing.

If yes, then it means that whatever changes the pointer might also release the reference on the old object.

Thanks.

#4 lore raw
Quoted 15 lines · Eric Dumazet
Quoted 15 lines
Quoted 15 lines

net/mptcp/subflow.c bool mptcp_subflow_data_available(struct sock *sk) · line 759

Quoted 12 lines
net/mptcp/subflow.c +12 -0
+/* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
+ * not the ssk one.
+ *
+ * In mptcp, rwin is about the mptcp-level connection data.
+ *
+ * Data that is still on the ssk rx queue can thus be ignored,
+ * as far as mptcp peer is concerened that data is still inflight.
+ */
+void mptcp_space(const struct sock *ssk, int *space, int *full_space)
+{
+	const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
+	const struct sock *sk = READ_ONCE(subflow->conn);

What are the rules protecting subflow->conn lifetime ?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Why dereferencing sk after this line is safe ?

Subflow sockets hold a reference on the master/parent mptcp-socket.

Presence of READ_ONCE() tells something might happen on this pointer after you read it.

Right, sorry about this. The READ_ONCE() isn't needed anymore after recent improvement from Paolo.

Quoted 1 line

Can this pointer be set while this thread is owning the socket lock ?

Only by the one holding the sk lock, so no race.

Quoted 1 line

If not, then you do not need READ_ONCE(), this is confusing.

Yes.

Quoted 2 lines

If yes, then it means that whatever changes the pointer might also release the reference on the old object.

The reference is released only after aquiring the socket lock.