mptcp: improve subflow creation on errors
Subsystems (3)
Paolo Abeni
maintainerv6 cover mptcp: improve subflow creation on errors
This iteration tries to add address the feedback on v5, namely test counter update and locking in write_options. The latter required quite significant changes in patch 5/7.
Additionally the series now includes the pending cleanup, as they depends on the previous patches. No changes there WRT the previous iteration.
Currently when a subflow connection fails - either the TCP connection is reset by the peer, or the MPJ handshake never completes - the in kernel PM don't perform any further action. Notably no additional subflow creation is attempted.
This series is aimed at improving the in-kernel path manager behavior in the above scenario:
- each endpoint is used only once per connection (patch 2/4)
- on failure we try to move to the next subflow, if any (patch 3/4)
The first patch is minor cleanup, and the last patch adds specific self-tests.
This should address/close:
https://github.com/multipath-tcp/mptcp_net-next/issues/235
https://github.com/multipath-tcp/mptcp_net-next/issues/242
Paolo Abeni (7):
mptcp: fix per socket endpoint accounting.
mptcp: clean-up MPJ option writing.
mptcp: keep track of local endpoint still available for each msk
mptcp: do not block subflows creation on errors
selftests: mptcp: add tests for subflow creation failure
mptcp: cleanup MPJ subflow list handling
mptcp: avoid atomic bit manipulation when possible
net/mptcp/options.c | 44 ++-- net/mptcp/pm.c | 24 ++- net/mptcp/pm_netlink.c | 188 +++++++++++------- net/mptcp/protocol.c | 158 +++++++-------- net/mptcp/protocol.h | 46 +++-- net/mptcp/sockopt.c | 24 +-- net/mptcp/subflow.c | 9 +- tools/testing/selftests/net/mptcp/config | 1 + .../testing/selftests/net/mptcp/mptcp_join.sh | 83 +++++++- 9 files changed, 350 insertions(+), 227 deletions(-)
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 1/7 mptcp: fix per socket endpoint accounting.
Since full-mesh endpoint support, the reception of a single ADD_ADDR option can cause multiple subflows creation. When such option is accepted we increment 'add_addr_accepted' by one. When we received a paired RM_ADDR option, we deleted all the relevant subflows, decrementing 'add_addr_accepted' by one for each of them.
We have a similar issue for 'local_addr_used'
Fix them moving the pm endpoint accounting outside the subflow traversal.
--- net/mptcp/pm_netlink.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/mptcp/pm_netlink.c +12 -6
@@ -710,6 +710,8 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,return ;for (i =0 ; i < rm_list->nr; i++) { +bool removed = false; +list_for_each_entry_safe (subflow, tmp, &msk->conn_list, node) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);int how =RCV_SHUTDOWN |SEND_SHUTDOWN ;
@@ -729,15 +731,19 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,mptcp_close_ssk (sk, ssk, subflow);spin_lock_bh (&msk->pm.lock); -if (rm_type ==MPTCP_MIB_RMADDR ) { - msk->pm.add_addr_accepted--; -WRITE_ONCE (msk->pm.accept_addr, true); - }else if (rm_type ==MPTCP_MIB_RMSUBFLOW ) { - msk->pm.local_addr_used--; - } + removed = true; msk->pm.subflows--;__MPTCP_INC_STATS (sock_net (sk), rm_type); } +if (!removed) +continue ; + +if (rm_type ==MPTCP_MIB_RMADDR ) { + msk->pm.add_addr_accepted--; +WRITE_ONCE (msk->pm.accept_addr, true); + }else if (rm_type ==MPTCP_MIB_RMSUBFLOW ) { + msk->pm.local_addr_used--; + } } }
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 2/7 mptcp: clean-up MPJ option writing.
In reply to Paolo AbeniCheck for all MPJ variant at once, this reduces the number of conditionals traversed on average and will simplify the next patch.
No functional change intended.
--- net/mptcp/options.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
net/mptcp/options.c +23 -21
@@ -1381,27 +1381,29 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,/* MPC is additionally mutually exclusive with MP_PRIO */ goto mp_capable_done; - }else if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) { - *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , -TCPOLEN_MPTCP_MPJ_SYN , - opts->backup, opts->join_id); -put_unaligned_be32 (opts->token, ptr); - ptr +=1 ; -put_unaligned_be32 (opts->nonce, ptr); - ptr +=1 ; - }else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) { - *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , -TCPOLEN_MPTCP_MPJ_SYNACK , - opts->backup, opts->join_id); -put_unaligned_be64 (opts->thmac, ptr); - ptr +=2 ; -put_unaligned_be32 (opts->nonce, ptr); - ptr +=1 ; - }else if (OPTION_MPTCP_MPJ_ACK & opts->suboptions) { - *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , -TCPOLEN_MPTCP_MPJ_ACK ,0 ,0 ); -memcpy (ptr, opts->hmac,MPTCPOPT_HMAC_LEN ); - ptr +=5 ; + }else if (OPTIONS_MPTCP_MPJ & opts->suboptions) { +if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) { + *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , +TCPOLEN_MPTCP_MPJ_SYN , + opts->backup, opts->join_id); +put_unaligned_be32 (opts->token, ptr); + ptr +=1 ; +put_unaligned_be32 (opts->nonce, ptr); + ptr +=1 ; + }else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) { + *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , +TCPOLEN_MPTCP_MPJ_SYNACK , + opts->backup, opts->join_id); +put_unaligned_be64 (opts->thmac, ptr); + ptr +=2 ; +put_unaligned_be32 (opts->nonce, ptr); + ptr +=1 ; + }else { + *ptr++ =mptcp_option (MPTCPOPT_MP_JOIN , +TCPOLEN_MPTCP_MPJ_ACK ,0 ,0 ); +memcpy (ptr, opts->hmac,MPTCPOPT_HMAC_LEN ); + ptr +=5 ; + } }else if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {u8 len =TCPOLEN_MPTCP_ADD_ADDR_BASE ;u8 echo =MPTCP_ADDR_ECHO ;
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 3/7 mptcp: keep track of local endpoint still available for each msk
In reply to Paolo AbeniInclude into the path manager status a bitmap tracking the list of local endpoints still available - not yet used - for the relavant mptcp socket.
Keep such map updated at endpoint creation/deleteion time, so that we can easily skip already used endpoint at local address selection time.
The endpoint used by the initial subflow is lazyly accounted at subflow creation time: the usage bitmap is be up2date before endpoint selection and we avoid such unneeded task in some relevant scenarions - e.g. busy servers accepting incoming subflows but not creating any additional ones nor annuncing additional addresses.
Overall this allows for fair local endpoints usage in case of subflow failure.
As a side effect, this patch also enforces that each endpoint is used at most once for each mptcp connection.
---
v4 -> v5:
- track MPC subflow, too
- update self-tests accordingly
v3 -> v4:
- track the available (not yet used) id instead of the used ones
- track both
- cleanup duplication with id_bitmap
--- net/mptcp/pm.c | 1 + net/mptcp/pm_netlink.c | 116 +++++++++++------- net/mptcp/protocol.c | 3 +- net/mptcp/protocol.h | 11 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 5 +- 5 files changed, 86 insertions(+), 50 deletions(-)
net/mptcp/pm.c +1 -0
@@ -376,6 +376,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)WRITE_ONCE (msk->pm.accept_subflow, false);WRITE_ONCE (msk->pm.remote_deny_join_id0, false); msk->pm.status =0 ; +bitmap_fill (msk->pm.id_avail_bitmap,MAX_ADDR_ID +1 );mptcp_pm_nl_data_init (msk); }
net/mptcp/pm_netlink.c +70 -46
225 lines not on this page · raw message
net/mptcp/protocol.c +1 -2
@@ -2508,8 +2508,7 @@ static void mptcp_worker(struct work_struct *work)mptcp_check_fastclose (msk); -if (msk->pm.status) -mptcp_pm_nl_work (msk); +mptcp_pm_nl_work (msk);if (test_and_clear_bit (MPTCP_WORK_EOF , &msk->flags))mptcp_check_for_eof (msk);
net/mptcp/protocol.h +10 -1
@@ -173,16 +173,24 @@ enum mptcp_pm_status {MPTCP_PM_ADD_ADDR_SEND_ACK ,MPTCP_PM_RM_ADDR_RECEIVED ,MPTCP_PM_ESTABLISHED , -MPTCP_PM_ALREADY_ESTABLISHED ,/* persistent status, set after ESTABLISHED event */ MPTCP_PM_SUBFLOW_ESTABLISHED , +MPTCP_PM_ALREADY_ESTABLISHED ,/* persistent status, set after ESTABLISHED event */ +MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is +* accounted int id_avail_bitmap +*/ }; +/* Status bits below MPTCP_PM_ALREADY_ESTABLISHED need pm worker actions */ +#define MPTCP_PM_WORK_MASK ((1 << MPTCP_PM_ALREADY_ESTABLISHED) - 1) +enum mptcp_addr_signal_status {MPTCP_ADD_ADDR_SIGNAL ,MPTCP_ADD_ADDR_ECHO ,MPTCP_RM_ADDR_SIGNAL , }; +#define MAX_ADDR_ID 255 +struct mptcp_pm_data {struct mptcp_addr_info local;struct mptcp_addr_info remote;
@@ -201,6 +209,7 @@ struct mptcp_pm_data {u8 local_addr_used;u8 subflows;u8 status; +DECLARE_BITMAP (id_avail_bitmap,MAX_ADDR_ID +1 );struct mptcp_rm_list rm_list_tx;struct mptcp_rm_list rm_list_rx; };
tools/testing/selftests/net/mptcp/mptcp_join.sh +4 -1
@@ -1109,7 +1109,10 @@ signal_address_tests() ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags signal ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags signal run_tests $ns1 $ns2 10.0.1.1 - chk_add_nr 4 4 + + # the server will not signal the address teminating + # the MPC subflow + chk_add_nr 3 3 } link_failure_tests()
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 4/7 mptcp: do not block subflows creation on errors
In reply to Paolo AbeniIf the MPTCP configuration allows for multiple subflows creation, and the first additional subflows never reach the fully established status - e.g. due to packets drop or reset - the in kernel path manager do not move to the next subflow.
This patch introduces a new PM helper to cope with MPJ subflow creation failure and delay and hook it where appropriate.
Such helper triggers additional subflow creation, as needed and updates the PM subflow counter, if the current one is closing.
Additionally start all the needed additional subflows as soon as the MPTCP socket is fully established, so we don't have to cope with slow MPJ handshake blocking the next subflow creation.
---
v5 -> v6:
- start all the subflows at once.
v3 -> v4:
- fix 'subflows' underflow
v2 -> v3:
- fix compile warning (CI)
v1 -> v2:
- explicitly hook on subflow close instead of error notification
- fix checkpatch issue (Mat)
- introduce and use a new pm helper to cope with subflow close
- update pm subflow counters on close
--- net/mptcp/pm.c | 23 ++++++++++++-- net/mptcp/pm_netlink.c | 69 +++++++++++++++++++++++++----------------- net/mptcp/protocol.c | 6 ++++ net/mptcp/protocol.h | 4 ++- 4 files changed, 71 insertions(+), 31 deletions(-)
net/mptcp/pm.c +21 -2
@@ -172,9 +172,28 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk)spin_unlock_bh (&pm->lock); } -void mptcp_pm_subflow_closed (struct mptcp_sock *msk,u8 id) +void mptcp_pm_subflow_check_next (struct mptcp_sock *msk,const struct sock *ssk, +const struct mptcp_subflow_context *subflow) { -pr_debug ("msk=%p" , msk); +struct mptcp_pm_data *pm = &msk->pm; +bool update_subflows; + + update_subflows = (ssk->sk_state ==TCP_CLOSE ) && + (subflow->request_join || subflow->mp_join); +if (!READ_ONCE (pm->work_pending) && !update_subflows) +return ; + +spin_lock_bh (&pm->lock); +if (update_subflows) + pm->subflows--; + +/* Even if this subflow is not really established, tell the PM to try +* to pick the next ones, if possible. +*/ +if (mptcp_pm_nl_check_work_pending (msk)) +mptcp_pm_schedule_work (msk,MPTCP_PM_SUBFLOW_ESTABLISHED ); + +spin_unlock_bh (&pm->lock); } void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
net/mptcp/pm_netlink.c +41 -28
132 lines not on this page · raw message
net/mptcp/protocol.c +6 -0
@@ -2351,6 +2351,12 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk, {if (sk->sk_state ==TCP_ESTABLISHED )mptcp_event (MPTCP_EVENT_SUB_CLOSED ,mptcp_sk (sk), ssk,GFP_KERNEL ); + +/* subflow aborted before reaching the fully_established status +* attempt the creation of the next subflow +*/ +mptcp_pm_subflow_check_next (mptcp_sk (sk), ssk, subflow); +__mptcp_close_ssk (sk, ssk, subflow,MPTCP_CF_PUSH ); }
net/mptcp/protocol.h +3 -1
@@ -744,7 +744,9 @@ void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk,bool mptcp_pm_allow_new_subflow (struct mptcp_sock *msk);void mptcp_pm_connection_closed (struct mptcp_sock *msk);void mptcp_pm_subflow_established (struct mptcp_sock *msk); -void mptcp_pm_subflow_closed (struct mptcp_sock *msk,u8 id); +bool mptcp_pm_nl_check_work_pending (struct mptcp_sock *msk); +void mptcp_pm_subflow_check_next (struct mptcp_sock *msk,const struct sock *ssk, +const struct mptcp_subflow_context *subflow);void mptcp_pm_add_addr_received (struct mptcp_sock *msk,const struct mptcp_addr_info *addr); void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 5/7 selftests: mptcp: add tests for subflow creation failure
In reply to Paolo AbeniVerify that, when multiple endpoints are available, subflows creation proceed even when the first additional subflow creation fails - due to packet drop on the relevant link
---
v5 -> v6:
- fix test cnt update
v4 -> v5:
- new test checking for wrong MPC reuse
v3 -> v4:
- use $() where applicable - Matt
- fix typo in help() - Matt
v1 -> v2:
- add missing NF kconfig
- add more test-cases (drop, later subflow creation)
--- tools/testing/selftests/net/mptcp/config | 1 + .../testing/selftests/net/mptcp/mptcp_join.sh | 78 ++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/config +1 -0
@@ -18,4 +18,5 @@ CONFIG_NFT_TPROXY=m CONFIG_NFT_SOCKET=m CONFIG_IP_ADVANCED_ROUTER=y CONFIG_IP_MULTIPLE_TABLES=y +CONFIG_IP_NF_TARGET_REJECT=m CONFIG_IPV6_MULTIPLE_TABLES=y
tools/testing/selftests/net/mptcp/mptcp_join.sh +77 -1
112 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [PATCH v6 mptcp-next 5/7] selftests: mptcp: add tests for subflow creation failure
Quoted 99 lines · Paolo Abeni
Verify that, when multiple endpoints are available, subflows creation proceed even when the first additional subflow creation fails - due to packet drop on the relevant link
Signed-off-by Paolo Abeni <[email protected]>---
v5 -> v6:
- fix test cnt updatev4 -> v5:
- new test checking for wrong MPC reusev3 -> v4:
- use $() where applicable - Matt
- fix typo inhelp()- Mattv1 -> v2:
- add missing NF kconfig
- add more test-cases (drop, later subflow creation)
---tools/testing/selftests/net/mptcp/config| 1 +.../testing/selftests/net/mptcp/mptcp_join.sh| 78 ++++++++++++++++++-2 files changed, 78 insertions(+), 1 deletion(-)tools/testing/selftests/net/mptcp/config +0
-0@@ -18,4 +18,5 @@ CONFIG_NFT_TPROXY=m
CONFIG_NFT_SOCKET=mCONFIG_IP_ADVANCED_ROUTER=yCONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_NF_TARGET_REJECT=mCONFIG_IPV6_MULTIPLE_TABLES=ytools/testing/selftests/net/mptcp/mptcp_join.sh +50
-0@@ -975,6 +975,22 @@ chk_link_usage() fi } +wait_for_tw() +{ + local timeout_ms=$((timeout_poll * 1000)) + local time=0 + local ns=$1 + + while [ $time -lt $timeout_ms ]; do + local cnt=$(ip netns exec $ns ss -t state time-wait |wc -l) + + [ "$cnt" = 1 ] && return 1 + time=$((time + 100)) + sleep 0.1 + done + return 1 +} + subflows_tests() { reset@@ -1032,6 +1048,61 @@ subflows_tests() chk_join_nr "single subflow, dev" 1 1 1 } +subflows_error_tests() +{ + # If a single subflow is configured, and matches the MPC src + # address, no additional subflow should be created + reset + ip netns exec $ns1 ./pm_nl_ctl limits 0 1 + ip netns exec $ns2 ./pm_nl_ctl limits 0 1 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.1.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow + chk_join_nr "no MPC address reuse with single endpoint" 0 0 0 + + # multiple subflows, with subflow creation error + reset + ip netns exec $ns1 ./pm_nl_ctl limits 0 2 + ip netns exec $ns2 ./pm_nl_ctl limits 0 2 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow + ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j REJECT + run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow + chk_join_nr "multiple subflows, with failing subflow" 1 1 1 + + # multiple subflows, with subflow timeout on MPJ + reset + ip netns exec $ns1 ./pm_nl_ctl limits 0 2 + ip netns exec $ns2 ./pm_nl_ctl limits 0 2 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow + ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j DROP + run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow + chk_join_nr "multiple subflows, with subflow timeout" 1 1 1 + + # multiple subflows, check that the endpoint corresponding to + # closed subflow (due to reset) is not reused if additional + # subflows are added later
tools/testing/selftests/net/mptcp/mptcp_join.sh subflows_tests() · line 1094
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +10
-0+ reset + ip netns exec $ns1 ./pm_nl_ctl limits 0 1 + ip netns exec $ns2 ./pm_nl_ctl limits 0 1 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j REJECT + run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow & + + # updates in the child shell do not have any effect here, we + # need to bump the test counter for the above case + TEST_COUNT=$((TEST_COUNT))
Missing the "+1"... maybe Matthieu can adjust when applying?
-Mat
Quoted 43 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +13
-0+ + # mpj subflow will be in TW after the reset + wait_for_tw $ns2 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow + wait + + # additional subflow could be created only if the PM select + # the later endpoint, skipping the already used one + chk_join_nr "multiple subflows, fair usage on close" 1 1 1 +} + signal_address_tests() { # add_address, unused@@ -1843,6 +1914,7 @@ fullmesh_tests() all_tests() { subflows_tests + subflows_error_tests signal_address_tests link_failure_tests add_addr_timeout_tests@@ -1862,6 +1934,7 @@ usage() { echo "mptcp_join usage:" echo " -f subflows_tests" + echo " -e subflows_error_tests" echo " -s signal_address_tests" echo " -l link_failure_tests" echo " -t add_addr_timeout_tests"@@ -1910,11 +1983,14 @@ if [ $do_all_tests -eq 1 ]; then exit $retfi
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-1-while getopts 'fsltra64bpkdmchCS' opt; do +while getopts 'fesltra64bpkdmchCS' opt; docase $opt in f) subflows_tests ;;tools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+ e) + subflows_error_tests + ;;
Quoted 8 lines
s) signal_address_tests ;;Signature · 1 line
2.33.1
--
Mat Martineau
Intel
Paolo Abeni
maintainerPATCH v6 6/7 mptcp: cleanup MPJ subflow list handling
In reply to Paolo AbeniWe can simplify the join list handling leveraging the mptcp_release_cb(): if we can acquire the msk socket lock ad mptcp_finish_join time, move the new subflow directly into the conn_list, othewise place it on join_list and let the release_cb process such list.
Since pending MPJ connection are now always processed in a timely way, we can avoid flushing the join list every time we have to process all the current subflows.
Additionally we can now use the mptcp data lock to protect the join_list, removing the additional spin lock.
Finally, the MPJ handshake is now always finalized under the msk socket lock, we can drop the additional synchronization between mptcp_finish_join() and mptcp_close().
---
rfc -> v1:
- fix list corruption in __mptcp_flush_join_list()
- fix label name typo (Mat)
--- net/mptcp/pm_netlink.c | 3 -- net/mptcp/protocol.c | 109 +++++++++++++++++------------------------ net/mptcp/protocol.h | 15 +----- net/mptcp/sockopt.c | 24 +++------ net/mptcp/subflow.c | 5 +- 5 files changed, 56 insertions(+), 100 deletions(-)
net/mptcp/pm_netlink.c +0 -3
@@ -165,7 +165,6 @@ select_local_address(const struct pm_nl_pernet *pernet,msk_owned_by_me (msk);rcu_read_lock (); -__mptcp_flush_join_list (msk);list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) {if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ))continue ;
@@ -595,7 +594,6 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, subflows_max =mptcp_pm_get_subflows_max (msk);rcu_read_lock (); -__mptcp_flush_join_list (msk);list_for_each_entry_rcu (entry, &pernet->local_addr_list, list) {if (!(entry->flags &MPTCP_PM_ADDR_FLAG_FULLMESH ))continue ;
@@ -684,7 +682,6 @@ void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk) !mptcp_pm_should_rm_signal(msk))return ; -__mptcp_flush_join_list (msk); subflow =list_first_entry_or_null (&msk->conn_list,typeof (*subflow), node);if (subflow) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);
net/mptcp/protocol.c +46 -63
207 lines not on this page · raw message
net/mptcp/protocol.h +2 -13
@@ -120,7 +120,7 @@#define MPTCP_CLEAN_UNA 7#define MPTCP_ERROR_REPORT 8#define MPTCP_RETRANSMIT 9 -#define MPTCP_WORK_SYNC_SETSOCKOPT 10 +#define MPTCP_FLUSH_JOIN_LIST 10#define MPTCP_CONNECTED 11static inline bool before64 (__u64 seq1,__u64 seq2)
@@ -261,7 +261,6 @@ struct mptcp_sock { u8 recvmsg_inq:1, cork:1, nodelay:1; -spinlock_t join_list_lock;struct work_struct work;struct sk_buff *ooo_last_skb;struct rb_root out_of_order_queue;
@@ -510,15 +509,6 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)return subflow->map_seq +mptcp_subflow_get_map_offset (subflow); } -static inline void mptcp_add_pending_subflow (struct mptcp_sock *msk, -struct mptcp_subflow_context *subflow) -{ -sock_hold (mptcp_subflow_tcp_sock (subflow)); -spin_lock_bh (&msk->join_list_lock); -list_add_tail (&subflow->node, &msk->join_list); -spin_unlock_bh (&msk->join_list_lock); -} -void mptcp_subflow_process_delegated (struct sock *ssk);static inline void mptcp_subflow_delegate (struct mptcp_subflow_context *subflow,int action)
@@ -683,7 +673,6 @@ void __mptcp_data_acked(struct sock *sk);void __mptcp_error_report (struct sock *sk);void mptcp_subflow_eof (struct sock *sk);bool mptcp_update_rcv_data_fin (struct mptcp_sock *msk,u64 data_fin_seq,bool use_64bit); -void __mptcp_flush_join_list (struct mptcp_sock *msk);static inline bool mptcp_data_fin_enabled (const struct mptcp_sock *msk) { return READ_ONCE(msk->snd_data_fin_enable) &&
@@ -843,7 +832,7 @@ unsigned int mptcp_pm_get_subflows_max(struct mptcp_sock *msk);unsigned int mptcp_pm_get_local_addr_max (struct mptcp_sock *msk);void mptcp_sockopt_sync (struct mptcp_sock *msk,struct sock *ssk); -void mptcp_sockopt_sync_all (struct mptcp_sock *msk); +void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk);static inline struct mptcp_ext *mptcp_get_ext (const struct sk_buff *skb) {
net/mptcp/sockopt.c +6 -18
@@ -1285,27 +1285,15 @@ void mptcp_sockopt_sync(struct mptcp_sock *msk, struct sock *ssk) } } -void mptcp_sockopt_sync_all (struct mptcp_sock *msk) +void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk) { -struct mptcp_subflow_context *subflow; -struct sock *sk = (struct sock *)msk; -u32 seq; - - seq =sockopt_seq_reset (sk); +struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk); -mptcp_for_each_subflow (msk, subflow) { -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); -u32 sseq =READ_ONCE (subflow->setsockopt_seq); +msk_owned_by_me (msk); -if (sseq != msk->setsockopt_seq) { -__mptcp_sockopt_sync (msk, ssk); -WRITE_ONCE (subflow->setsockopt_seq, seq); - }else if (sseq != seq) { -WRITE_ONCE (subflow->setsockopt_seq, seq); - } +if (READ_ONCE (subflow->setsockopt_seq) != msk->setsockopt_seq) { +sync_socket_options (msk, ssk); -cond_resched (); + subflow->setsockopt_seq = msk->setsockopt_seq; } - - msk->setsockopt_seq = seq; }
net/mptcp/subflow.c +2 -3
@@ -1446,7 +1446,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, subflow->request_bkup = !!(flags &MPTCP_PM_ADDR_FLAG_BACKUP );mptcp_info2sockaddr (remote, &addr, ssk->sk_family); -mptcp_add_pending_subflow (msk, subflow); +sock_hold (ssk); +list_add_tail (&subflow->node, &msk->conn_list); err =kernel_connect (sf, (struct sockaddr *)&addr, addrlen,O_NONBLOCK );if (err && err != -EINPROGRESS ) goto failed_unlink;
@@ -1458,9 +1459,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,return err; failed_unlink: -spin_lock_bh (&msk->join_list_lock);list_del (&subflow->node); -spin_unlock_bh (&msk->join_list_lock);sock_put (mptcp_subflow_tcp_sock (subflow)); failed:
Signature · 1 line
2.33.1
Paolo Abeni
maintainerPATCH v6 7/7 mptcp: avoid atomic bit manipulation when possible
In reply to Paolo AbeniCurrently the msk->flags bitmask carries both state for the mptcp_release_cb() - mostly touched under the mptcp data lock
- and others state info touched even outside such lock scope.
As a consequence, msk->flags is always manipulated with atomic operations.
This change splits such bitmask in two separate fields, so that we use plain bit oper operations when touching the cb-related info.
The MPTCP_PUSH_PENDING bit needs additional care, as it is the only CB related field currently accessed either under the mptcp data lock or the mptcp socket lock.
Let's add another mask just for such bit's sake.
--- net/mptcp/protocol.c | 46 +++++++++++++++++++++++--------------------- net/mptcp/protocol.h | 18 ++++++++++------- net/mptcp/subflow.c | 4 ++-- 3 files changed, 37 insertions(+), 31 deletions(-)
net/mptcp/protocol.c +24 -22
@@ -763,7 +763,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)if (!sock_owned_by_user (sk))__mptcp_error_report (sk);else -set_bit (MPTCP_ERROR_REPORT , &msk->flags); +__set_bit (MPTCP_ERROR_REPORT , &msk->cb_flags); }/* If the moves have caught up with the DATA_FIN sequence number
@@ -1529,9 +1529,8 @@ static void mptcp_update_post_push(struct mptcp_sock *msk,void mptcp_check_and_set_pending (struct sock *sk) { -if (mptcp_send_head (sk) && - !test_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags)) -set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags); +if (mptcp_send_head (sk)) +mptcp_sk (sk)->push_pending |=MPTCP_PUSH_PENDING ; }void __mptcp_push_pending (struct sock *sk,unsigned int flags)
@@ -2146,7 +2145,7 @@ static void mptcp_retransmit_timer(struct timer_list *t)mptcp_schedule_work (sk); }else {/* delegate our work to tcp_release_cb() */ -set_bit (MPTCP_RETRANSMIT , &msk->flags); +__set_bit (MPTCP_RETRANSMIT , &msk->cb_flags); }bh_unlock_sock (sk);sock_put (sk);
@@ -2858,7 +2857,9 @@ static int mptcp_disconnect(struct sock *sk, int flags)mptcp_destroy_common (msk); msk->last_snd =NULL ; - msk->flags =0 ; +WRITE_ONCE (msk->flags,0 ); + msk->cb_flags =0 ; + msk->push_pending =0 ; msk->recovery = false; msk->can_ack = false; msk->fully_established = false;
@@ -3041,7 +3042,7 @@ void __mptcp_data_acked(struct sock *sk)if (!sock_owned_by_user (sk))__mptcp_clean_una (sk);else -set_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->flags); +__set_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->cb_flags);if (mptcp_pending_data_fin_ack (sk))mptcp_schedule_work (sk);
@@ -3060,22 +3061,22 @@ void __mptcp_check_push(struct sock *sk, struct sock *ssk)else if (xmit_ssk)mptcp_subflow_delegate (mptcp_subflow_ctx (xmit_ssk),MPTCP_DELEGATE_SEND ); }else { -set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags); +__set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->cb_flags); } } +#define MPTCP_FLAGS_PROCESS_CTX_NEED (MPTCP_PUSH_PENDING | \ + MPTCP_RETRANSMIT | \ + MPTCP_FLUSH_JOIN_LIST) +/* processes deferred events and flush wmem */ static void mptcp_release_cb (struct sock *sk) { +struct mptcp_sock *msk =mptcp_sk (sk); +for (;;) { -unsigned long flags =0 ; - -if (test_and_clear_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags)) - flags |=BIT (MPTCP_PUSH_PENDING ); -if (test_and_clear_bit (MPTCP_RETRANSMIT , &mptcp_sk (sk)->flags)) - flags |=BIT (MPTCP_RETRANSMIT ); -if (test_and_clear_bit (MPTCP_FLUSH_JOIN_LIST , &mptcp_sk (sk)->flags)) - flags |=BIT (MPTCP_FLUSH_JOIN_LIST ); +unsigned long flags = (msk->cb_flags &MPTCP_FLAGS_PROCESS_CTX_NEED ) | + msk->push_pending;if (!flags)break ;
@@ -3086,7 +3087,8 @@ 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);if (flags &BIT (MPTCP_FLUSH_JOIN_LIST ))__mptcp_flush_join_list (sk);
@@ -3102,11 +3104,11 @@ static void mptcp_release_cb(struct sock *sk)/* be sure to set the current sk state before tacking actions * depending on sk_state */ -if (test_and_clear_bit (MPTCP_CONNECTED , &mptcp_sk (sk)->flags)) +if (__test_and_clear_bit (MPTCP_CONNECTED , &msk->cb_flags))__mptcp_set_connected (sk); -if (test_and_clear_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->flags)) +if (__test_and_clear_bit (MPTCP_CLEAN_UNA , &msk->cb_flags))__mptcp_clean_una_wakeup (sk); -if (test_and_clear_bit (MPTCP_ERROR_REPORT , &mptcp_sk (sk)->flags)) +if (__test_and_clear_bit (MPTCP_ERROR_REPORT , &msk->cb_flags))__mptcp_error_report (sk);__mptcp_update_rmem (sk);
@@ -3148,7 +3150,7 @@ void mptcp_subflow_process_delegated(struct sock *ssk)if (!sock_owned_by_user (sk))__mptcp_subflow_push_pending (sk, ssk);else -set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags); +__set_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->cb_flags);mptcp_data_unlock (sk);mptcp_subflow_delegated_done (subflow,MPTCP_DELEGATE_SEND ); }
@@ -3268,7 +3270,7 @@ bool mptcp_finish_join(struct sock *ssk) }else {sock_hold (ssk);list_add_tail (&subflow->node, &msk->join_list); -set_bit (MPTCP_FLUSH_JOIN_LIST , &msk->flags); +__set_bit (MPTCP_FLUSH_JOIN_LIST , &msk->cb_flags); }mptcp_data_unlock (parent);
net/mptcp/protocol.h +11 -7
@@ -110,18 +110,20 @@/* MPTCP TCPRST flags */ #define MPTCP_RST_TRANSIENT BIT(0) -/* MPTCP socket flags */ +/* MPTCP socket atomic flags */ #define MPTCP_NOSPACE 1#define MPTCP_WORK_RTX 2#define MPTCP_WORK_EOF 3#define MPTCP_FALLBACK_DONE 4#define MPTCP_WORK_CLOSE_SUBFLOW 5 -#define MPTCP_PUSH_PENDING 6 -#define MPTCP_CLEAN_UNA 7 -#define MPTCP_ERROR_REPORT 8 -#define MPTCP_RETRANSMIT 9 -#define MPTCP_FLUSH_JOIN_LIST 10 -#define MPTCP_CONNECTED 11 + +/* MPTCP socket release cb flags */ +#define MPTCP_PUSH_PENDING 1 +#define MPTCP_CLEAN_UNA 2 +#define MPTCP_ERROR_REPORT 3 +#define MPTCP_RETRANSMIT 4 +#define MPTCP_FLUSH_JOIN_LIST 5 +#define MPTCP_CONNECTED 6static inline bool before64 (__u64 seq1,__u64 seq2) {
@@ -249,6 +251,8 @@ struct mptcp_sock {u32 token;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;
net/mptcp/subflow.c +2 -2
@@ -388,7 +388,7 @@ static void mptcp_set_connected(struct sock *sk)if (!sock_owned_by_user (sk))__mptcp_set_connected (sk);else -set_bit (MPTCP_CONNECTED , &mptcp_sk (sk)->flags); +__set_bit (MPTCP_CONNECTED , &mptcp_sk (sk)->cb_flags);mptcp_data_unlock (sk); }
@@ -1279,7 +1279,7 @@ static void subflow_error_report(struct sock *ssk)if (!sock_owned_by_user (sk))__mptcp_error_report (sk);else -set_bit (MPTCP_ERROR_REPORT , &mptcp_sk (sk)->flags); +__set_bit (MPTCP_ERROR_REPORT , &mptcp_sk (sk)->cb_flags);mptcp_data_unlock (sk); }
Signature · 1 line
2.33.1
Paolo Abeni
maintainerRe: [PATCH v6 mptcp-next 7/7] mptcp: avoid atomic bit manipulation when possible
Quoted 11 lines · Paolo Abeni
Currently the
msk->flagsbitmask carries both state for themptcp_release_cb()- mostly touched under the mptcp data lock
- and others state info touched even outside such lock scope.As a consequence,
msk->flagsis always manipulated with atomic operations.This change splits such bitmask in two separate fields, so that we use plain bit oper operations when touching the cb-related info.
Quoted 6 lines
The
MPTCP_PUSH_PENDINGbit needs additional care, as it is the only CB related field currently accessed either under the mptcp data lock or the mptcp socket lock.
Let's add another mask just for such bit's sake.Signed-off-by Paolo Abeni <[email protected]>
This patch has still a few issues - basically it lacks a bunch of BIT(). @Matt: could you please apply patches 1-6 (with modification on patch 5) and leave this alone? I'll try to send a new version soon.
Otherwise I'll re-send the whole series.
Thanks!
Paolo
Re: [PATCH v6 mptcp-next 7/7] mptcp: avoid atomic bit manipulation when possible
Hi Paolo, Mat,
Quoted 17 lines · Paolo Abeni
Quoted 16 lines · Paolo Abeni
Currently the
msk->flagsbitmask carries both state for themptcp_release_cb()- mostly touched under the mptcp data lock
- and others state info touched even outside such lock scope.As a consequence,
msk->flagsis always manipulated with atomic operations.This change splits such bitmask in two separate fields, so that we use plain bit oper operations when touching the cb-related info.
The
MPTCP_PUSH_PENDINGbit needs additional care, as it is the only CB related field currently accessed either under the mptcp data lock or the mptcp socket lock.
Let's add another mask just for such bit's sake.
Quoted 5 lines
Quoted 1 line
Signed-off-by Paolo Abeni <[email protected]>This patch has still a few issues - basically it lacks a bunch of
BIT(). @Matt: could you please apply patches 1-6 (with modification on patch 5) and leave this alone? I'll try to send a new version soon.
Thank you for the patches, the reviews and the notes.
These patches except the last one 7/7/ have just been applied in our tree (features for net-next) with Mat's RvB tags, without a few spelling typo spot by "checkpatch --codespell" and a typo spot by Mat in patch 5/7
- 7dff646b6956: mptcp: fix per socket endpoint accounting
- b3b313667f76: mptcp: clean-up MPJ option writing
- 93ddc71f0055: mptcp: keep track of local endpoint still available for each msk
- I had a small conflict and while at it, I added MPTCP_PM_ prefix toMAX_ADDR_ID: https://paste.opendev.org/show/811700/
- b3adca806c71: mptcp: do not block subflows creation on errors
- 0f4945b51e44: selftests: mptcp: add tests for subflow creation failure
- 07368dde952a: selftests: mptcp: apply Mat's comment
- 1d0e64a63ddc: mptcp: cleanup MPJ subflow list handling
- Results: 8c25dcd7cdf7..c94ca039d4f9
Builds and tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20211215T155626
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Quoted 19 lines · Paolo Abeni
This iteration tries to add address the feedback on v5, namely test counter update and locking in
write_options. The latter required quite significant changes in patch 5/7.Additionally the series now includes the pending cleanup, as they depends on the previous patches. No changes there WRT the previous iteration.
Currently when a subflow connection fails - either the TCP connection is reset by the peer, or the MPJ handshake never completes - the in kernel PM don't perform any further action. Notably no additional subflow creation is attempted.
This series is aimed at improving the in-kernel path manager behavior in the above scenario:
- each endpoint is used only once per connection (patch 2/4)
- on failure we try to move to the next subflow, if any (patch 3/4)
Quoted 7 lines
The first patch is minor cleanup, and the last patch adds specific self-tests.
This should address/close:
https://github.com/multipath-tcp/mptcp_net-next/issues/235
https://github.com/multipath-tcp/mptcp_net-next/issues/242
Hi Paolo -
Thanks for the changes, I think the "start all the subflows in a loop" works out better.
Looks good for wider testing on the export branch, with the one selftest fix noted in patch 5 (Matthieu, let us know how you prefer to proceed on that).
Quoted 9 lines
Paolo Abeni (7):
mptcp: fix per socket endpoint accounting.
mptcp: clean-up MPJ option writing.
mptcp: keep track of local endpoint still available for each msk
mptcp: do not block subflows creation on errors
selftests: mptcp: add tests for subflow creation failure
mptcp: cleanup MPJ subflow list handling
mptcp: avoid atomic bit manipulation when possible
Quoted 16 lines
net/mptcp/options.c | 44 ++-- net/mptcp/pm.c | 24 ++- net/mptcp/pm_netlink.c | 188 +++++++++++------- net/mptcp/protocol.c | 158 +++++++-------- net/mptcp/protocol.h | 46 +++-- net/mptcp/sockopt.c | 24 +-- net/mptcp/subflow.c | 9 +- tools/testing/selftests/net/mptcp/config | 1 + .../testing/selftests/net/mptcp/mptcp_join.sh | 83 +++++++- 9 files changed, 350 insertions(+), 227 deletions(-)Signature · 1 line
2.33.1
--
Mat Martineau
Intel
Hi Paolo,
Quoted 19 lines · Paolo Abeni
This iteration tries to add address the feedback on v5, namely test counter update and locking in
write_options. The latter required quite significant changes in patch 5/7.Additionally the series now includes the pending cleanup, as they depends on the previous patches. No changes there WRT the previous iteration.
Currently when a subflow connection fails - either the TCP connection is reset by the peer, or the MPJ handshake never completes - the in kernel PM don't perform any further action. Notably no additional subflow creation is attempted.
This series is aimed at improving the in-kernel path manager behavior in the above scenario:
- each endpoint is used only once per connection (patch 2/4)
- on failure we try to move to the next subflow, if any (patch 3/4)
Quoted 6 lines
The first patch is minor cleanup, and the last patch adds specific self-tests.
This should address/close:
https://github.com/multipath-tcp/mptcp_net-next/issues/235
https://github.com/multipath-tcp/mptcp_net-next/issues/242
Is it OK to close these two issues now or do you prefer to do that when patch 7/7 will be applied?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net