* [PATCH mptcp-net 0/4] mptcp: locking cleanup
@ 2024-01-15 15:16 Paolo Abeni
2024-01-15 15:16 ` [PATCH mptcp-net 1/4] mptcp: drop the push_pending field Paolo Abeni
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Paolo Abeni @ 2024-01-15 15:16 UTC (permalink / raw)
To: mptcp
This is a preparatory work for the TCP_NOTSENT_LOWAT support. The latter
will need tracking more state under the msk data lock.
Since the locking msk locking schema is already quite complex, do a long
awaited clean-up step, moving several confusing lockless initialization
under the relevant locks.
Note that patches 2-4 carry fixes tag, and could target the net tree,
but AFACIS no real race could really happen even prior to such patches
as the MPTCP-level state machine implicitly ensure proper serialization
of the write accesses, even lacking explicit lock.
Patch 1 has no fixes, but still is logically tied to the other patches.
Possibly we could target net-next for the whole series.
Paolo Abeni (4):
mptcp: drop the push_pending field
mptcp: fix rcv space initialization
mptcp: fix more tx path fields initialization
mptcp: corner case locking for rx path fields initialization
net/mptcp/fastopen.c | 6 ++--
net/mptcp/options.c | 9 +++---
net/mptcp/protocol.c | 31 ++++++++++---------
net/mptcp/protocol.h | 13 ++++----
net/mptcp/subflow.c | 71 +++++++++++++++++++++++++++-----------------
5 files changed, 75 insertions(+), 55 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH mptcp-net 1/4] mptcp: drop the push_pending field 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni @ 2024-01-15 15:16 ` Paolo Abeni 2024-02-08 11:36 ` Matthieu Baerts 2024-01-15 15:16 ` [PATCH mptcp-net 2/4] mptcp: fix rcv space initialization Paolo Abeni ` (4 subsequent siblings) 5 siblings, 1 reply; 17+ messages in thread From: Paolo Abeni @ 2024-01-15 15:16 UTC (permalink / raw) To: mptcp Such field is there to avoid acquiring the data lock in a few spots, but if adds complexity to the already non trivial locking schema. All the relevant call sites (mptcp-level reinjection, set socket optins), are slow-path, drop such field in favor of 'cb_flags', adding the relevant locking. Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/mptcp/protocol.c | 12 ++++++------ net/mptcp/protocol.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e570c7e2b18c..5129e1235cc5 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1505,8 +1505,11 @@ static void mptcp_update_post_push(struct mptcp_sock *msk, void mptcp_check_and_set_pending(struct sock *sk) { - if (mptcp_send_head(sk)) - mptcp_sk(sk)->push_pending |= BIT(MPTCP_PUSH_PENDING); + if (mptcp_send_head(sk)) { + mptcp_data_lock(sk); + mptcp_sk(sk)->cb_flags |= BIT(MPTCP_PUSH_PENDING); + mptcp_data_unlock(sk); + } } static int __subflow_push_pending(struct sock *sk, struct sock *ssk, @@ -3145,7 +3148,6 @@ static int mptcp_disconnect(struct sock *sk, int flags) mptcp_destroy_common(msk, MPTCP_CF_FASTCLOSE); WRITE_ONCE(msk->flags, 0); msk->cb_flags = 0; - msk->push_pending = 0; msk->recovery = false; msk->can_ack = false; msk->fully_established = false; @@ -3333,8 +3335,7 @@ static void mptcp_release_cb(struct sock *sk) struct mptcp_sock *msk = mptcp_sk(sk); for (;;) { - unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED) | - msk->push_pending; + unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED); struct list_head join_list; if (!flags) @@ -3350,7 +3351,6 @@ static void mptcp_release_cb(struct sock *sk) * datapath acquires the msk socket spinlock while helding * the subflow socket lock */ - msk->push_pending = 0; msk->cb_flags &= ~flags; spin_unlock_bh(&sk->sk_lock.slock); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f7b9c1b995df..ebb32b7563be 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -286,7 +286,6 @@ struct mptcp_sock { int rmem_released; unsigned long flags; unsigned long cb_flags; - unsigned long push_pending; bool recovery; /* closing subflow write queue reinjected */ bool can_ack; bool fully_established; -- 2.43.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 1/4] mptcp: drop the push_pending field 2024-01-15 15:16 ` [PATCH mptcp-net 1/4] mptcp: drop the push_pending field Paolo Abeni @ 2024-02-08 11:36 ` Matthieu Baerts 2024-02-08 15:12 ` Paolo Abeni 0 siblings, 1 reply; 17+ messages in thread From: Matthieu Baerts @ 2024-02-08 11:36 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, On 15/01/2024 16:16, Paolo Abeni wrote: > Such field is there to avoid acquiring the data lock in a few spots, > but if adds complexity to the already non trivial locking schema. > > All the relevant call sites (mptcp-level reinjection, set socket optins), > are slow-path, drop such field in favor of 'cb_flags', adding the relevant > locking. In your cover-letter, you mentioned: > Patch 1 has no fixes, but still is logically tied to the other patches. I think it makes sense to have this patch in -net, especially because it is logically tied to the others. Would it be OK for you if I add: Fixes: e9d09baca676 ("mptcp: avoid atomic bit manipulation when possible") Or do you prefer without? Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 1/4] mptcp: drop the push_pending field 2024-02-08 11:36 ` Matthieu Baerts @ 2024-02-08 15:12 ` Paolo Abeni 2024-02-08 18:05 ` Matthieu Baerts 0 siblings, 1 reply; 17+ messages in thread From: Paolo Abeni @ 2024-02-08 15:12 UTC (permalink / raw) To: Matthieu Baerts; +Cc: mptcp On Thu, 2024-02-08 at 12:36 +0100, Matthieu Baerts wrote: > Hi Paolo, > > On 15/01/2024 16:16, Paolo Abeni wrote: > > Such field is there to avoid acquiring the data lock in a few spots, > > but if adds complexity to the already non trivial locking schema. > > > > All the relevant call sites (mptcp-level reinjection, set socket optins), > > are slow-path, drop such field in favor of 'cb_flags', adding the relevant > > locking. > > In your cover-letter, you mentioned: > > > Patch 1 has no fixes, but still is logically tied to the other patches. > > I think it makes sense to have this patch in -net, especially because it > is logically tied to the others. Would it be OK for you if I add: > > Fixes: e9d09baca676 ("mptcp: avoid atomic bit manipulation when possible") The obove, or add a sentence to the commit message alike: """ This will also simplify the next patch """ > > Or do you prefer without? > > Cheers, > Matt ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 1/4] mptcp: drop the push_pending field 2024-02-08 15:12 ` Paolo Abeni @ 2024-02-08 18:05 ` Matthieu Baerts 2024-02-08 18:07 ` Paolo Abeni 0 siblings, 1 reply; 17+ messages in thread From: Matthieu Baerts @ 2024-02-08 18:05 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, On 08/02/2024 16:12, Paolo Abeni wrote: > On Thu, 2024-02-08 at 12:36 +0100, Matthieu Baerts wrote: >> Hi Paolo, >> >> On 15/01/2024 16:16, Paolo Abeni wrote: >>> Such field is there to avoid acquiring the data lock in a few spots, >>> but if adds complexity to the already non trivial locking schema. >>> >>> All the relevant call sites (mptcp-level reinjection, set socket optins), >>> are slow-path, drop such field in favor of 'cb_flags', adding the relevant >>> locking. >> >> In your cover-letter, you mentioned: >> >>> Patch 1 has no fixes, but still is logically tied to the other patches. >> >> I think it makes sense to have this patch in -net, especially because it >> is logically tied to the others. Would it be OK for you if I add: >> >> Fixes: e9d09baca676 ("mptcp: avoid atomic bit manipulation when possible") > > The obove, or add a sentence to the commit message alike: > > """ > This will also simplify the next patch > """ Good idea! I added both: > This patch could be seen as an improvement, instead of a fix. But it > simplifies the next patch. The 'Fixes' tag has been added to help having > this series backported to stable. I hope that's OK! :) Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 1/4] mptcp: drop the push_pending field 2024-02-08 18:05 ` Matthieu Baerts @ 2024-02-08 18:07 ` Paolo Abeni 0 siblings, 0 replies; 17+ messages in thread From: Paolo Abeni @ 2024-02-08 18:07 UTC (permalink / raw) To: Matthieu Baerts; +Cc: mptcp On Thu, 2024-02-08 at 19:05 +0100, Matthieu Baerts wrote: > On 08/02/2024 16:12, Paolo Abeni wrote: > > > This patch could be seen as an improvement, instead of a fix. But it > > simplifies the next patch. The 'Fixes' tag has been added to help having > > this series backported to stable. > > I hope that's OK! :) fine by me, thanks! /P ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH mptcp-net 2/4] mptcp: fix rcv space initialization 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 1/4] mptcp: drop the push_pending field Paolo Abeni @ 2024-01-15 15:16 ` Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 3/4] mptcp: fix more tx path fields initialization Paolo Abeni ` (3 subsequent siblings) 5 siblings, 0 replies; 17+ messages in thread From: Paolo Abeni @ 2024-01-15 15:16 UTC (permalink / raw) To: mptcp mptcp_rcv_space_init() is supposed to happen under the msk socket lock, but active msk socket does that without such protection. Leverage the existing mptcp_propagate_state() helper to that extent. We need to ensure mptcp_rcv_space_init will happen before mptcp_rcv_space_adjust(), and the release_cb does not assure that: explicitly check for such condition. While at it, move the wnd_end initialization out of mptcp_rcv_space_init(), it never belonged there. Note that the race does not produce ill effect in practice, but change allows cleaning-up and defying better the locking model. Fixes: a6b118febbab ("mptcp: add receive buffer auto-tuning") Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/mptcp/protocol.c | 10 ++++++---- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 5129e1235cc5..c41f49532a0a 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1963,6 +1963,9 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) if (copied <= 0) return; + if (!msk->rcvspace_init) + mptcp_rcv_space_init(msk, msk->first); + msk->rcvq_space.copied += copied; mstamp = div_u64(tcp_clock_ns(), NSEC_PER_USEC); @@ -3163,6 +3166,7 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->bytes_received = 0; msk->bytes_sent = 0; msk->bytes_retrans = 0; + msk->rcvspace_init = 0; WRITE_ONCE(sk->sk_shutdown, 0); sk_error_report(sk); @@ -3250,6 +3254,7 @@ void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk) { const struct tcp_sock *tp = tcp_sk(ssk); + msk->rcvspace_init = 1; msk->rcvq_space.copied = 0; msk->rcvq_space.rtt_us = 0; @@ -3260,8 +3265,6 @@ void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk) TCP_INIT_CWND * tp->advmss); if (msk->rcvq_space.space == 0) msk->rcvq_space.space = TCP_INIT_CWND * TCP_MSS_DEFAULT; - - WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); } void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags) @@ -3481,10 +3484,9 @@ void mptcp_finish_connect(struct sock *ssk) WRITE_ONCE(msk->write_seq, subflow->idsn + 1); WRITE_ONCE(msk->snd_nxt, msk->write_seq); WRITE_ONCE(msk->snd_una, msk->write_seq); + WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); mptcp_pm_new_connection(msk, ssk, 0); - - mptcp_rcv_space_init(msk, ssk); } void mptcp_sock_graft(struct sock *sk, struct socket *parent) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index ebb32b7563be..385aa92926d7 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -304,7 +304,8 @@ struct mptcp_sock { nodelay:1, fastopening:1, in_accept_queue:1, - free_first:1; + free_first:1, + rcvspace_init:1; struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 90984b053adc..23f639e0d8c3 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -424,6 +424,8 @@ void __mptcp_sync_state(struct sock *sk, int state) struct mptcp_sock *msk = mptcp_sk(sk); __mptcp_propagate_sndbuf(sk, msk->first); + if (!msk->rcvspace_init) + mptcp_rcv_space_init(msk, msk->first); if (sk->sk_state == TCP_SYN_SENT) { mptcp_set_state(sk, state); sk->sk_state_change(sk); @@ -545,7 +547,6 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) } } else if (mptcp_check_fallback(sk)) { fallback: - mptcp_rcv_space_init(msk, sk); mptcp_propagate_state(parent, sk); } return; @@ -1744,7 +1745,6 @@ static void subflow_state_change(struct sock *sk) msk = mptcp_sk(parent); if (subflow_simultaneous_connect(sk)) { mptcp_do_fallback(sk); - mptcp_rcv_space_init(msk, sk); pr_fallback(msk); subflow->conn_finished = 1; mptcp_propagate_state(parent, sk); -- 2.43.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH mptcp-net 3/4] mptcp: fix more tx path fields initialization 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 1/4] mptcp: drop the push_pending field Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 2/4] mptcp: fix rcv space initialization Paolo Abeni @ 2024-01-15 15:16 ` Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni ` (2 subsequent siblings) 5 siblings, 0 replies; 17+ messages in thread From: Paolo Abeni @ 2024-01-15 15:16 UTC (permalink / raw) To: mptcp The 'msk->write_seq' and 'msk->snd_nxt' are always updated under the msk socket lock, except at MPC handshake completiont time. Builds-up on the previous commit to move such init under the relevant lock. There are no known problems caused by the potential race, the primary goal is consistency. Fixes: 6d0060f600ad ("mptcp: Write MPTCP DSS headers to outgoing data packets") Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/mptcp/protocol.c | 6 ++---- net/mptcp/subflow.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index c41f49532a0a..b7d1da7bcb50 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3481,10 +3481,8 @@ void mptcp_finish_connect(struct sock *ssk) * accessing the field below */ WRITE_ONCE(msk->local_key, subflow->local_key); - WRITE_ONCE(msk->write_seq, subflow->idsn + 1); - WRITE_ONCE(msk->snd_nxt, msk->write_seq); - WRITE_ONCE(msk->snd_una, msk->write_seq); - WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); + WRITE_ONCE(msk->snd_una, subflow->idsn + 1); + WRITE_ONCE(msk->wnd_end, subflow->idsn + 1 + tcp_sk(ssk)->snd_wnd); mptcp_pm_new_connection(msk, ssk, 0); } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 23f639e0d8c3..fe5334cee477 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -421,12 +421,21 @@ static bool subflow_use_different_dport(struct mptcp_sock *msk, const struct soc void __mptcp_sync_state(struct sock *sk, int state) { + struct mptcp_subflow_context *subflow; struct mptcp_sock *msk = mptcp_sk(sk); + struct sock *ssk = msk->first; - __mptcp_propagate_sndbuf(sk, msk->first); + subflow = mptcp_subflow_ctx(ssk); + __mptcp_propagate_sndbuf(sk, ssk); if (!msk->rcvspace_init) - mptcp_rcv_space_init(msk, msk->first); + mptcp_rcv_space_init(msk, ssk); + if (sk->sk_state == TCP_SYN_SENT) { + /* subflow->idsn is always available is TCP_SYN_SENT state, + * even for the FASTOPEN scenarios + */ + WRITE_ONCE(msk->write_seq, subflow->idsn + 1); + WRITE_ONCE(msk->snd_nxt, msk->write_seq); mptcp_set_state(sk, state); sk->sk_state_change(sk); } -- 2.43.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH mptcp-net 4/4] mptcp: corner case locking for rx path fields initialization 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni ` (2 preceding siblings ...) 2024-01-15 15:16 ` [PATCH mptcp-net 3/4] mptcp: fix more tx path fields initialization Paolo Abeni @ 2024-01-15 15:16 ` Paolo Abeni 2024-01-15 16:13 ` mptcp: corner case locking for rx path fields initialization: Tests Results MPTCP CI ` (4 more replies) 2024-01-17 2:32 ` [PATCH mptcp-net 0/4] mptcp: locking cleanup Mat Martineau 2024-01-17 11:58 ` Matthieu Baerts 5 siblings, 5 replies; 17+ messages in thread From: Paolo Abeni @ 2024-01-15 15:16 UTC (permalink / raw) To: mptcp Most MPTCP-level related fields are under the mptcp data lock protection, but are written one-off without such lock at MPC complete time, both for the client and the server Leverage the mptcp_propagate_state() infrastructure to move such initialization under the proper lock client-wise. The server side critical init steps are done by mptcp_subflow_fully_established(): ensure the caller properly held the relevant lock, and avoid acquiring the same lock in the nested scopes. There are no real potential races, as write access to such fields is implicitly serialized by the MPTCP state machine; the primary goal is consistency. Fixes: d22f4988ffec ("mptcp: process MP_CAPABLE data option") Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/mptcp/fastopen.c | 6 ++--- net/mptcp/options.c | 9 +++---- net/mptcp/protocol.c | 9 ++++--- net/mptcp/protocol.h | 9 +++---- net/mptcp/subflow.c | 56 +++++++++++++++++++++++++------------------- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index 74698582a285..ad28da655f8b 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -59,13 +59,12 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf mptcp_data_unlock(sk); } -void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, - const struct mptcp_options_received *mp_opt) +void __mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt) { struct sock *sk = (struct sock *)msk; struct sk_buff *skb; - mptcp_data_lock(sk); skb = skb_peek_tail(&sk->sk_receive_queue); if (skb) { WARN_ON_ONCE(MPTCP_SKB_CB(skb)->end_seq); @@ -77,5 +76,4 @@ void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_ } pr_debug("msk=%p ack_seq=%llx", msk, msk->ack_seq); - mptcp_data_unlock(sk); } diff --git a/net/mptcp/options.c b/net/mptcp/options.c index d2527d189a79..e3e96a49f922 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -962,9 +962,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, /* subflows are fully established as soon as we get any * additional ack, including ADD_ADDR. */ - subflow->fully_established = 1; - WRITE_ONCE(msk->fully_established, true); - goto check_notify; + goto set_fully_established; } /* If the first established packet does not contain MP_CAPABLE + data @@ -986,7 +984,10 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, set_fully_established: if (unlikely(!READ_ONCE(msk->pm.server_side))) pr_warn_once("bogus mpc option on established client sk"); - mptcp_subflow_fully_established(subflow, mp_opt); + + mptcp_data_lock((struct sock *)msk); + __mptcp_subflow_fully_established(msk, subflow, mp_opt); + mptcp_data_unlock((struct sock *)msk); check_notify: /* if the subflow is not already linked into the conn_list, we can't diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b7d1da7bcb50..70108854ec9b 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3189,6 +3189,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, { struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); struct sock *nsk = sk_clone_lock(sk, GFP_ATOMIC); + struct mptcp_subflow_context *subflow; struct mptcp_sock *msk; if (!nsk) @@ -3229,7 +3230,8 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, /* The msk maintain a ref to each subflow in the connections list */ WRITE_ONCE(msk->first, ssk); - list_add(&mptcp_subflow_ctx(ssk)->node, &msk->conn_list); + subflow = mptcp_subflow_ctx(ssk); + list_add(&subflow->node, &msk->conn_list); sock_hold(ssk); /* new mpc subflow takes ownership of the newly @@ -3244,6 +3246,9 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, __mptcp_propagate_sndbuf(nsk, ssk); mptcp_rcv_space_init(msk, ssk); + + if (mp_opt->suboptions & OPTION_MPTCP_MPC_ACK) + __mptcp_subflow_fully_established(msk, subflow, mp_opt); bh_unlock_sock(nsk); /* note: the newly allocated socket refcount is 2 now */ @@ -3481,8 +3486,6 @@ void mptcp_finish_connect(struct sock *ssk) * accessing the field below */ WRITE_ONCE(msk->local_key, subflow->local_key); - WRITE_ONCE(msk->snd_una, subflow->idsn + 1); - WRITE_ONCE(msk->wnd_end, subflow->idsn + 1 + tcp_sk(ssk)->snd_wnd); mptcp_pm_new_connection(msk, ssk, 0); } diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 385aa92926d7..d442d876f465 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -622,8 +622,9 @@ unsigned int mptcp_stale_loss_cnt(const struct net *net); unsigned int mptcp_close_timeout(const struct sock *sk); int mptcp_get_pm_type(const struct net *net); const char *mptcp_get_scheduler(const struct net *net); -void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, - const struct mptcp_options_received *mp_opt); +void __mptcp_subflow_fully_established(struct mptcp_sock *msk, + struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt); bool __mptcp_retransmit_pending_data(struct sock *sk); void mptcp_check_and_set_pending(struct sock *sk); void __mptcp_push_pending(struct sock *sk, unsigned int flags); @@ -957,8 +958,8 @@ void mptcp_event_pm_listener(const struct sock *ssk, enum mptcp_event_type event); bool mptcp_userspace_pm_active(const struct mptcp_sock *msk); -void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, - const struct mptcp_options_received *mp_opt); +void __mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt); void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow, struct request_sock *req); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index fe5334cee477..52568227c229 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -441,20 +441,6 @@ void __mptcp_sync_state(struct sock *sk, int state) } } -static void mptcp_propagate_state(struct sock *sk, struct sock *ssk) -{ - struct mptcp_sock *msk = mptcp_sk(sk); - - mptcp_data_lock(sk); - if (!sock_owned_by_user(sk)) { - __mptcp_sync_state(sk, ssk->sk_state); - } else { - msk->pending_state = ssk->sk_state; - __set_bit(MPTCP_SYNC_STATE, &msk->cb_flags); - } - mptcp_data_unlock(sk); -} - static void subflow_set_remote_key(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, const struct mptcp_options_received *mp_opt) @@ -476,6 +462,31 @@ static void subflow_set_remote_key(struct mptcp_sock *msk, atomic64_set(&msk->rcv_wnd_sent, subflow->iasn); } +static void mptcp_propagate_state(struct sock *sk, struct sock *ssk, + struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt) +{ + struct mptcp_sock *msk = mptcp_sk(sk); + + mptcp_data_lock(sk); + if (mp_opt) { + /* Options are available only in the non fallback cases + * avoid updating rx path fields otherwise + */ + WRITE_ONCE(msk->snd_una, subflow->idsn + 1); + WRITE_ONCE(msk->wnd_end, subflow->idsn + 1 + tcp_sk(ssk)->snd_wnd); + subflow_set_remote_key(msk, subflow, mp_opt); + } + + if (!sock_owned_by_user(sk)) { + __mptcp_sync_state(sk, ssk->sk_state); + } else { + msk->pending_state = ssk->sk_state; + __set_bit(MPTCP_SYNC_STATE, &msk->cb_flags); + } + mptcp_data_unlock(sk); +} + static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); @@ -510,10 +521,9 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) if (mp_opt.deny_join_id0) WRITE_ONCE(msk->pm.remote_deny_join_id0, true); subflow->mp_capable = 1; - subflow_set_remote_key(msk, subflow, &mp_opt); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVEACK); mptcp_finish_connect(sk); - mptcp_propagate_state(parent, sk); + mptcp_propagate_state(parent, sk, subflow, &mp_opt); } else if (subflow->request_join) { u8 hmac[SHA256_DIGEST_SIZE]; @@ -556,7 +566,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) } } else if (mptcp_check_fallback(sk)) { fallback: - mptcp_propagate_state(parent, sk); + mptcp_propagate_state(parent, sk, subflow, NULL); } return; @@ -741,17 +751,16 @@ void mptcp_subflow_drop_ctx(struct sock *ssk) kfree_rcu(ctx, rcu); } -void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, - const struct mptcp_options_received *mp_opt) +void __mptcp_subflow_fully_established(struct mptcp_sock *msk, + struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt) { - struct mptcp_sock *msk = mptcp_sk(subflow->conn); - subflow_set_remote_key(msk, subflow, mp_opt); subflow->fully_established = 1; WRITE_ONCE(msk->fully_established, true); if (subflow->is_mptfo) - mptcp_fastopen_gen_msk_ackseq(msk, subflow, mp_opt); + __mptcp_fastopen_gen_msk_ackseq(msk, subflow, mp_opt); } static struct sock *subflow_syn_recv_sock(const struct sock *sk, @@ -844,7 +853,6 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, * mpc option */ if (mp_opt.suboptions & OPTION_MPTCP_MPC_ACK) { - mptcp_subflow_fully_established(ctx, &mp_opt); mptcp_pm_fully_established(owner, child); ctx->pm_notified = 1; } @@ -1756,7 +1764,7 @@ static void subflow_state_change(struct sock *sk) mptcp_do_fallback(sk); pr_fallback(msk); subflow->conn_finished = 1; - mptcp_propagate_state(parent, sk); + mptcp_propagate_state(parent, sk, subflow, NULL); } /* as recvmsg() does not acquire the subflow socket for ssk selection -- 2.43.0 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: mptcp: corner case locking for rx path fields initialization: Tests Results 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni @ 2024-01-15 16:13 ` MPTCP CI 2024-01-15 17:07 ` MPTCP CI ` (3 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: MPTCP CI @ 2024-01-15 16:13 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, Thank you for your modifications, that's great! Our CI (GitHub Action) did some validations and here is its report: - KVM Validation: normal: - Unstable: 2 failed test(s): packetdrill_fastopen selftest_mptcp_join 🔴: - Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/7530894597 Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/61ffb2fba924 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-normal For 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 (NGI0 Core) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: mptcp: corner case locking for rx path fields initialization: Tests Results 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni 2024-01-15 16:13 ` mptcp: corner case locking for rx path fields initialization: Tests Results MPTCP CI @ 2024-01-15 17:07 ` MPTCP CI 2024-01-17 2:57 ` MPTCP CI ` (2 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: MPTCP CI @ 2024-01-15 17:07 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, Thank you for your modifications, that's great! Our CI (Cirrus) did some validations with a debug kernel and here is its report: - KVM Validation: debug (except selftest_mptcp_join): - Unstable: 1 failed test(s): packetdrill_fastopen 🔴: - Task: https://cirrus-ci.com/task/5162165229846528 - Summary: https://api.cirrus-ci.com/v1/artifact/task/5162165229846528/summary/summary.txt - KVM Validation: debug (only selftest_mptcp_join): - Success! ✅: - Task: https://cirrus-ci.com/task/6288065136689152 - Summary: https://api.cirrus-ci.com/v1/artifact/task/6288065136689152/summary/summary.txt Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/61ffb2fba924 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-debug For 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 (NGI0 Core) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: mptcp: corner case locking for rx path fields initialization: Tests Results 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni 2024-01-15 16:13 ` mptcp: corner case locking for rx path fields initialization: Tests Results MPTCP CI 2024-01-15 17:07 ` MPTCP CI @ 2024-01-17 2:57 ` MPTCP CI 2024-01-17 3:54 ` MPTCP CI 2024-01-17 7:01 ` MPTCP CI 4 siblings, 0 replies; 17+ messages in thread From: MPTCP CI @ 2024-01-17 2:57 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, Thank you for your modifications, that's great! Our CI (GitHub Action) did some validations and here is its report: - KVM Validation: normal: - Critical: 1 Call Trace(s) - Critical: Unexpected stop of the VM ❌: - Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/7550415246 Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1fd81af266b7 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-normal For 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 (NGI0 Core) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: mptcp: corner case locking for rx path fields initialization: Tests Results 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni ` (2 preceding siblings ...) 2024-01-17 2:57 ` MPTCP CI @ 2024-01-17 3:54 ` MPTCP CI 2024-01-17 7:01 ` MPTCP CI 4 siblings, 0 replies; 17+ messages in thread From: MPTCP CI @ 2024-01-17 3:54 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, Thank you for your modifications, that's great! Our CI (Cirrus) did some validations with a debug kernel and here is its report: - KVM Validation: debug (except selftest_mptcp_join): - Unstable: 1 failed test(s): selftest_diag 🔴: - Task: https://cirrus-ci.com/task/4675429135548416 - Summary: https://api.cirrus-ci.com/v1/artifact/task/4675429135548416/summary/summary.txt - KVM Validation: debug (only selftest_mptcp_join): - Success! ✅: - Task: https://cirrus-ci.com/task/5801329042391040 - Summary: https://api.cirrus-ci.com/v1/artifact/task/5801329042391040/summary/summary.txt Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1fd81af266b7 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-debug For 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 (NGI0 Core) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: mptcp: corner case locking for rx path fields initialization: Tests Results 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni ` (3 preceding siblings ...) 2024-01-17 3:54 ` MPTCP CI @ 2024-01-17 7:01 ` MPTCP CI 4 siblings, 0 replies; 17+ messages in thread From: MPTCP CI @ 2024-01-17 7:01 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp Hi Paolo, Thank you for your modifications, that's great! Our CI (GitHub Action) did some validations and here is its report: - KVM Validation: normal: - Unstable: 2 failed test(s): packetdrill_regressions selftest_mptcp_join 🔴: - Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/7550415246 Initiator: Patchew Applier Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1fd81af266b7 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-normal For 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 (NGI0 Core) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 0/4] mptcp: locking cleanup 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni ` (3 preceding siblings ...) 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni @ 2024-01-17 2:32 ` Mat Martineau 2024-01-17 10:30 ` Paolo Abeni 2024-01-17 11:58 ` Matthieu Baerts 5 siblings, 1 reply; 17+ messages in thread From: Mat Martineau @ 2024-01-17 2:32 UTC (permalink / raw) To: Paolo Abeni; +Cc: mptcp On Mon, 15 Jan 2024, Paolo Abeni wrote: > This is a preparatory work for the TCP_NOTSENT_LOWAT support. The latter > will need tracking more state under the msk data lock. > > Since the locking msk locking schema is already quite complex, do a long > awaited clean-up step, moving several confusing lockless initialization > under the relevant locks. > > Note that patches 2-4 carry fixes tag, and could target the net tree, > but AFACIS no real race could really happen even prior to such patches > as the MPTCP-level state machine implicitly ensure proper serialization > of the write accesses, even lacking explicit lock. > > Patch 1 has no fixes, but still is logically tied to the other patches. > Possibly we could target net-next for the whole series. > > Paolo Abeni (4): > mptcp: drop the push_pending field > mptcp: fix rcv space initialization > mptcp: fix more tx path fields initialization > mptcp: corner case locking for rx path fields initialization > Hi Paolo - The series LGTM, assuming the CI failure is the issue fixed by "mptcp: relax check on MPC passive fallback": Reviewed-by: Mat Martineau <martineau@kernel.org> > net/mptcp/fastopen.c | 6 ++-- > net/mptcp/options.c | 9 +++--- > net/mptcp/protocol.c | 31 ++++++++++--------- > net/mptcp/protocol.h | 13 ++++---- > net/mptcp/subflow.c | 71 +++++++++++++++++++++++++++----------------- > 5 files changed, 75 insertions(+), 55 deletions(-) > > -- > 2.43.0 > > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 0/4] mptcp: locking cleanup 2024-01-17 2:32 ` [PATCH mptcp-net 0/4] mptcp: locking cleanup Mat Martineau @ 2024-01-17 10:30 ` Paolo Abeni 0 siblings, 0 replies; 17+ messages in thread From: Paolo Abeni @ 2024-01-17 10:30 UTC (permalink / raw) To: Mat Martineau; +Cc: mptcp On Tue, 2024-01-16 at 18:32 -0800, Mat Martineau wrote: > On Mon, 15 Jan 2024, Paolo Abeni wrote: > > > This is a preparatory work for the TCP_NOTSENT_LOWAT support. The latter > > will need tracking more state under the msk data lock. > > > > Since the locking msk locking schema is already quite complex, do a long > > awaited clean-up step, moving several confusing lockless initialization > > under the relevant locks. > > > > Note that patches 2-4 carry fixes tag, and could target the net tree, > > but AFACIS no real race could really happen even prior to such patches > > as the MPTCP-level state machine implicitly ensure proper serialization > > of the write accesses, even lacking explicit lock. > > > > Patch 1 has no fixes, but still is logically tied to the other patches. > > Possibly we could target net-next for the whole series. > > > > Paolo Abeni (4): > > mptcp: drop the push_pending field > > mptcp: fix rcv space initialization > > mptcp: fix more tx path fields initialization > > mptcp: corner case locking for rx path fields initialization > > > > Hi Paolo - > > The series LGTM, assuming the CI failure is the issue fixed by "mptcp: > relax check on MPC passive fallback": AFAIK, they are: I tested locally this series on top of the fixes, without any problem. > Reviewed-by: Mat Martineau <martineau@kernel.org> Thanks! Paolo ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH mptcp-net 0/4] mptcp: locking cleanup 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni ` (4 preceding siblings ...) 2024-01-17 2:32 ` [PATCH mptcp-net 0/4] mptcp: locking cleanup Mat Martineau @ 2024-01-17 11:58 ` Matthieu Baerts 5 siblings, 0 replies; 17+ messages in thread From: Matthieu Baerts @ 2024-01-17 11:58 UTC (permalink / raw) To: Paolo Abeni, mptcp Hi Paolo, Mat, On 15/01/2024 16:16, Paolo Abeni wrote: > This is a preparatory work for the TCP_NOTSENT_LOWAT support. The latter > will need tracking more state under the msk data lock. > > Since the locking msk locking schema is already quite complex, do a long > awaited clean-up step, moving several confusing lockless initialization > under the relevant locks. > > Note that patches 2-4 carry fixes tag, and could target the net tree, > but AFACIS no real race could really happen even prior to such patches > as the MPTCP-level state machine implicitly ensure proper serialization > of the write accesses, even lacking explicit lock. > > Patch 1 has no fixes, but still is logically tied to the other patches. > Possibly we could target net-next for the whole series. Thank you for the patches and the review! Now in our tree (fixes for -net), without a typo spotted by "checkpatch.pl --codespell" (and Vim's "set spell spelllang=en_gb") New patches for t/upstream-net and t/upstream: - c6d26639b0a9: mptcp: drop the push_pending field - 2541670ad929: mptcp: fix rcv space initialization - a6f5bfc5abf7: mptcp: fix more tx path fields initialization - 7e6e9b2c5e9d: mptcp: corner case locking for rx path fields initialization - Results: dd080a859960..50a3b99c60bd (export-net) - Results: 2d5218531f82..387cadd951df (export) Tests are now in progress: https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export-net/20240117T115551 https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20240117T115551 Cheers, Matt -- Sponsored by the NGI0 Core fund. ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2024-02-08 18:07 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-01-15 15:16 [PATCH mptcp-net 0/4] mptcp: locking cleanup Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 1/4] mptcp: drop the push_pending field Paolo Abeni 2024-02-08 11:36 ` Matthieu Baerts 2024-02-08 15:12 ` Paolo Abeni 2024-02-08 18:05 ` Matthieu Baerts 2024-02-08 18:07 ` Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 2/4] mptcp: fix rcv space initialization Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 3/4] mptcp: fix more tx path fields initialization Paolo Abeni 2024-01-15 15:16 ` [PATCH mptcp-net 4/4] mptcp: corner case locking for rx " Paolo Abeni 2024-01-15 16:13 ` mptcp: corner case locking for rx path fields initialization: Tests Results MPTCP CI 2024-01-15 17:07 ` MPTCP CI 2024-01-17 2:57 ` MPTCP CI 2024-01-17 3:54 ` MPTCP CI 2024-01-17 7:01 ` MPTCP CI 2024-01-17 2:32 ` [PATCH mptcp-net 0/4] mptcp: locking cleanup Mat Martineau 2024-01-17 10:30 ` Paolo Abeni 2024-01-17 11:58 ` Matthieu Baerts
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.