mptcp: never shrink offered window
Subsystems (4)
Paolo Abeni
maintainerRFC PATCH 2/2 mptcp: never shrink offered window
In reply to Paolo AbeniAs per RFC, the offered MPTCP-level window should never shrink. While we currently track the right edge, we don't enforce the above constraint on the wire.
Additionally, concurrent xmit on different subflows can end-up in erroneous right edge update.
Address the above explicitly updating the announced window and protecting the update with an additional atomic operation (sic)
--- net/mptcp/options.c | 52 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 7 deletions(-)
net/mptcp/options.c +45 -7
@@ -1224,20 +1224,58 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)return true; } -static void mptcp_set_rwin (const struct tcp_sock *tp) +static void mptcp_set_rwin (struct tcp_sock *tp,struct tcphdr *th) {const struct sock *ssk = (const struct sock *)tp; -const struct mptcp_subflow_context *subflow; +struct mptcp_subflow_context *subflow; +u64 ack_seq, rcv_wnd_old, rcv_wnd_new;struct mptcp_sock *msk; -u64 ack_seq; +u32 new_win; +u64 win; subflow =mptcp_subflow_ctx (ssk); msk =mptcp_sk (subflow->conn); - ack_seq =READ_ONCE (msk->ack_seq) + tp->rcv_wnd; + ack_seq =READ_ONCE (msk->ack_seq); + rcv_wnd_new = ack_seq + tp->rcv_wnd; + + rcv_wnd_old =READ_ONCE (msk->rcv_wnd_sent); +if (after64 (rcv_wnd_new, rcv_wnd_old)) { +u64 rcv_wnd; + +for (;;) { + rcv_wnd =cmpxchg64 (&msk->rcv_wnd_sent, rcv_wnd_old, rcv_wnd_new); + +if (rcv_wnd == rcv_wnd_old) +break ; +if (before64 (rcv_wnd_new, rcv_wnd)) + goto raise_win; + rcv_wnd_old = rcv_wnd; + }; +return ; + } + +if (rcv_wnd_new != rcv_wnd_old) { +raise_win: + win = rcv_wnd_old - ack_seq; + tp->rcv_wnd =min_t (u64, win,U32_MAX ); + new_win = tp->rcv_wnd; -if (after64 (ack_seq,READ_ONCE (msk->rcv_wnd_sent))) -WRITE_ONCE (msk->rcv_wnd_sent, ack_seq); +/* Make sure we do not exceed the maximum possible +* scaled window. +*/ +if (unlikely (th->syn)) + new_win =min (new_win,65535U ) << tp->rx_opt.rcv_wscale; +if (!tp->rx_opt.rcv_wscale && +sock_net (ssk)->ipv4.sysctl_tcp_workaround_signed_windows) + new_win =min (new_win,MAX_TCP_WINDOW ); +else + new_win =min (new_win, (65535U << tp->rx_opt.rcv_wscale)); + +/* RFC1323 scaling applied */ + new_win >>= tp->rx_opt.rcv_wscale; + th->window =htons (new_win); + } }u16 __mptcp_make_csum (u64 data_seq,u32 subflow_seq,u16 data_len,__wsum sum)
@@ -1550,7 +1588,7 @@ void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp, }if (tp) -mptcp_set_rwin (tp); +mptcp_set_rwin (tp, th); }__be32 mptcp_get_reset_option (const struct sk_buff *skb)
Signature · 1 line
2.35.1
Paolo Abeni
maintainercover mptcp: never shrink offered window
There patches are part of a somewhat largish series to implement more strict RFC compliance for the MPTCP-level congestion window handling, solving some tput instability issues.
The obtain the above we need to modify an existing MPTCP hook, touching the TCP code (in patch 1/2), ence the RFC.
The later patch demonstrates the actual usage of such hook.
Paolo Abeni (2):
tcp: allow MPTCP to update the announced window.
mptcp: never shrink offered window
include/net/mptcp.h | 2 +- net/ipv4/tcp_output.c | 14 ++++++----- net/mptcp/options.c | 54 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 55 insertions(+), 15 deletions(-)
Signature · 1 line
2.35.1
Paolo Abeni
maintainerRFC PATCH 1/2 tcp: allow MPTCP to update the announced window.
The MPTCP RFC requires that the MPTCP-level receive window's right edge never moves backward. Currently the MPTCP code enforces such constraint while tracking the right edge, but it does not reflects the constraint back on the wire, as lacks a suitable hook to update accordingly the TCP header.
This change modifies the existing mptcp_write_options() hook, providing the current packet's TCP header up to the MPTCP protocol level, so that the next patch could implement the above mentioned constraint.
No functional changes intended.
--- include/net/mptcp.h | 2 +- net/ipv4/tcp_output.c | 14 ++++++++------ net/mptcp/options.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-)
include/net/mptcp.h +1 -1
@@ -124,7 +124,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb, struct mptcp_out_options *opts);bool mptcp_incoming_options (struct sock *sk,struct sk_buff *skb); -void mptcp_write_options (__be32 *ptr,const struct tcp_sock *tp, +void mptcp_write_options (struct tcphdr *th,__be32 *ptr,struct tcp_sock *tp,struct mptcp_out_options *opts);void mptcp_diag_fill_info (struct mptcp_sock *msk,struct mptcp_info *info);
net/ipv4/tcp_output.c +8 -6
@@ -444,12 +444,13 @@ struct tcp_out_options {struct mptcp_out_options mptcp; }; -static void mptcp_options_write (__be32 *ptr,const struct tcp_sock *tp, +static void mptcp_options_write (struct tcphdr *th,__be32 *ptr, +struct tcp_sock *tp,struct tcp_out_options *opts) {#if IS_ENABLED (CONFIG_MPTCP )if (unlikely (OPTION_MPTCP & opts->options)) -mptcp_write_options (ptr, tp, &opts->mptcp); +mptcp_write_options (th, ptr, tp, &opts->mptcp);#endif }
@@ -605,9 +606,10 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,* At least SACK_PERM as the first option is known to lead to a disaster * (but it may well be that other scenarios fail similarly). */ -static void tcp_options_write (__be32 *ptr,struct tcp_sock *tp, +static void tcp_options_write (struct tcphdr *th,struct tcp_sock *tp,struct tcp_out_options *opts) { +__be32 *ptr = (__be32 *)(th +1 );u16 options = opts->options;/* mungable copy */ if (unlikely (OPTION_MD5 & options)) {
@@ -701,7 +703,7 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,smc_options_write (ptr, &options); -mptcp_options_write (ptr, tp, opts); +mptcp_options_write (th, ptr, tp, opts); } static void smc_set_option(const struct tcp_sock *tp,
@@ -1354,7 +1356,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, th->window =htons (min (tp->rcv_wnd,65535U )); } -tcp_options_write ((__be32 *)(th +1 ), tp, &opts); +tcp_options_write (th, tp, &opts);#ifdef CONFIG_TCP_MD5SIG /* Calculate the MD5 hash, as we have all we need now */
@@ -3590,7 +3592,7 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,/* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */ th->window =htons (min (req->rsk_rcv_wnd,65535U )); -tcp_options_write ((__be32 *)(th +1 ),NULL , &opts); +tcp_options_write (th,NULL , &opts); th->doff = (tcp_header_size >>2 );__TCP_INC_STATS (sock_net (sk),TCP_MIB_OUTSEGS );
net/mptcp/options.c +1 -1
@@ -1265,7 +1265,7 @@ static u16 mptcp_make_csum(const struct mptcp_ext *mpext) ~csum_unfold(mpext->csum)); } -void mptcp_write_options (__be32 *ptr,const struct tcp_sock *tp, +void mptcp_write_options (struct tcphdr *th,__be32 *ptr,struct tcp_sock *tp,struct mptcp_out_options *opts) {const struct sock *ssk = (const struct sock *)tp;
Signature · 1 line
2.35.1
Re: mptcp: never shrink offered window: Tests Results
In reply to Paolo AbeniHi Paolo,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Success! ✅:
- Task: https://cirrus-ci.com/task/5584135128350720
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5584135128350720/summary/summary.txt
- KVM Validation: debug:
- Unstable: 3 failed test(s): selftest_diag selftest_mptcp_join selftest_simult_flows - Critical: KMemLeak ❌:
- Task: https://cirrus-ci.com/task/5822711300620288
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5822711300620288/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/fecffc194d28
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)