mptcp: Check for orphaned subflow before handling MP_FAIL timer
Subsystems (2)
PATCH 1/2 mptcp: Check for orphaned subflow before handling MP_FAIL timer
MP_FAIL timeout (waiting for a peer to respond to an MP_FAIL with another MP_FAIL) is implemented using the MPTCP socket's sk_timer. That timer is also used at MPTCP socket close, so it's important to not have the two timer users interfere with each other.
At MPTCP socket close, all subflows are orphaned before sk_timer is manipulated. By checking the SOCK_DEAD flag on the subflows, each subflow can determine if the timer is safe to alter without acquiring any MPTCP-level lock. This replaces code that was using the mptcp_data_lock and MPTCP-level socket state checks that did not correctly protect the timer.
--- net/mptcp/pm.c | 7 ++----- net/mptcp/subflow.c | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-)
net/mptcp/pm.c +2 -5
@@ -312,13 +312,10 @@ void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq) subflow->send_mp_fail =1 ;MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_MPFAILTX ); subflow->send_infinite_map =1 ; - }else if (s &&inet_sk_state_load (s) !=TCP_CLOSE ) { + }else if (!sock_flag (sk,SOCK_DEAD )) {pr_debug ("MP_FAIL response received" ); -mptcp_data_lock (s); -if (inet_sk_state_load (s) !=TCP_CLOSE ) -sk_stop_timer (s, &s->sk_timer); -mptcp_data_unlock (s); +sk_stop_timer (s, &s->sk_timer); } }
net/mptcp/subflow.c +4 -8
@@ -1013,12 +1013,9 @@ static enum mapping_status get_mapping_status(struct sock *ssk,pr_debug ("infinite mapping received" );MPTCP_INC_STATS (sock_net (ssk),MPTCP_MIB_INFINITEMAPRX ); subflow->map_data_len =0 ; -if (sk &&inet_sk_state_load (sk) !=TCP_CLOSE ) { -mptcp_data_lock (sk); -if (inet_sk_state_load (sk) !=TCP_CLOSE ) -sk_stop_timer (sk, &sk->sk_timer); -mptcp_data_unlock (sk); - } +if (!sock_flag (ssk,SOCK_DEAD )) +sk_stop_timer (sk, &sk->sk_timer); +return MAPPING_INVALID ; }
@@ -1226,9 +1223,8 @@ static bool subflow_check_data_avail(struct sock *ssk)tcp_send_active_reset (ssk,GFP_ATOMIC );while ((skb =skb_peek (&ssk->sk_receive_queue)))sk_eat_skb (ssk, skb); - }else { + }else if (!sock_flag (ssk,SOCK_DEAD )) {WRITE_ONCE (subflow->mp_fail_response_expect, true); -/* The data lock is acquired in __mptcp_move_skbs() */ sk_reset_timer ((struct sock *)msk, &((struct sock *)msk)->sk_timer, jiffies +TCP_RTO_MAX );
Signature · 1 line
2.36.1
PATCH 2/2 mptcp: Do not traverse the subflow connection list without lock
The MPTCP socket's conn_list (list of subflows) requires the socket lock to access. The MP_FAIL timeout code added such an access, where it would check the list of subflows both in timer context and (later) in workqueue context where the socket lock is held.
Rather than check the list twice, remove the check in the timeout handler and only depend on the check in the workqueue.
--- net/mptcp/protocol.c | 16 ++-------------- net/mptcp/protocol.h | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-)
net/mptcp/protocol.c +2 -14
@@ -2182,23 +2182,11 @@ mp_fail_response_expect_subflow(struct mptcp_sock *msk)return ret; } -static void mptcp_check_mp_fail_response (struct mptcp_sock *msk) -{ -struct mptcp_subflow_context *subflow; -struct sock *sk = (struct sock *)msk; - -bh_lock_sock (sk); - subflow =mp_fail_response_expect_subflow (msk); -if (subflow) -__set_bit (MPTCP_FAIL_NO_RESPONSE , &msk->flags); -bh_unlock_sock (sk); -} -static void mptcp_timeout_timer (struct timer_list *t) {struct sock *sk =from_timer (sk, t, sk_timer); -mptcp_check_mp_fail_response (mptcp_sk (sk)); +set_bit (MPTCP_WORK_TIMEOUT , &mptcp_sk (sk)->flags);mptcp_schedule_work (sk);sock_put (sk); }
@@ -2575,7 +2563,7 @@ static void mptcp_worker(struct work_struct *work)if (test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags))__mptcp_retrans (sk); -if (test_and_clear_bit (MPTCP_FAIL_NO_RESPONSE , &msk->flags)) +if (test_and_clear_bit (MPTCP_WORK_TIMEOUT , &msk->flags))mptcp_mp_fail_no_response (msk); unlock:
net/mptcp/protocol.h +1 -1
@@ -117,7 +117,7 @@#define MPTCP_WORK_EOF 3#define MPTCP_FALLBACK_DONE 4#define MPTCP_WORK_CLOSE_SUBFLOW 5 -#define MPTCP_FAIL_NO_RESPONSE 6 +#define MPTCP_WORK_TIMEOUT 6/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1
Signature · 1 line
2.36.1
Paolo Abeni
maintainerRe: [PATCH mptcp-next 2/2] mptcp: Do not traverse the subflow connection list without lock
Quoted 35 lines · Mat Martineau
The MPTCP socket's
conn_list(list of subflows) requires the socket lock to access. TheMP_FAILtimeout code added such an access, where it would check the list of subflows both in timer context and (later) in workqueue context where the socket lock is held.Rather than check the list twice, remove the check in the timeout handler and only depend on the check in the workqueue.
Reported-by Paolo Abeni <[email protected]>Fixes 49fa1919d6bc ("mptcp: reset subflow when MP_FAIL doesn't respond")Signed-off-by Mat Martineau <[email protected]>--- net/mptcp/protocol.c | 16 ++-------------- net/mptcp/protocol.h | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-)net/mptcp/protocol.c +0
-11@@ -2182,23 +2182,11 @@ mp_fail_response_expect_subflow(struct mptcp_sock *msk)return ret; } -static void mptcp_check_mp_fail_response (struct mptcp_sock *msk) -{ -struct mptcp_subflow_context *subflow; -struct sock *sk = (struct sock *)msk; - -bh_lock_sock (sk); - subflow =mp_fail_response_expect_subflow (msk); -if (subflow) -__set_bit (MPTCP_FAIL_NO_RESPONSE , &msk->flags); -bh_unlock_sock (sk); -}
net/mptcp/protocol.c mp_fail_response_expect_subflow(struct mptcp_sock *msk) · line 2192
Quoted 10 lines
net/mptcp/protocol.c +1
-2-static void mptcp_timeout_timer (struct timer_list *t) {struct sock *sk =from_timer (sk, t, sk_timer); -mptcp_check_mp_fail_response (mptcp_sk (sk)); +set_bit (MPTCP_WORK_TIMEOUT , &mptcp_sk (sk)->flags);mptcp_schedule_work (sk);sock_put (sk); }
I'm wondering if at this point we could get rid also of the MPTCP_WORK_TIMEOUT flags. In case of mptcp-level timeout we just schedule the worker and let it do it's check.
Other than that the series LGTM, thanks!
Paolo
Re: [PATCH mptcp-next 2/2] mptcp: Do not traverse the subflow connection list without lock
Quoted 41 lines · Paolo Abeni
Quoted 40 lines · Mat Martineau
The MPTCP socket's
conn_list(list of subflows) requires the socket lock to access. TheMP_FAILtimeout code added such an access, where it would check the list of subflows both in timer context and (later) in workqueue context where the socket lock is held.Rather than check the list twice, remove the check in the timeout handler and only depend on the check in the workqueue.
Reported-by Paolo Abeni <[email protected]>Fixes 49fa1919d6bc ("mptcp: reset subflow when MP_FAIL doesn't respond")Signed-off-by Mat Martineau <[email protected]>--- net/mptcp/protocol.c | 16 ++-------------- net/mptcp/protocol.h | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-)net/mptcp/protocol.c +0
-12@@ -2182,23 +2182,11 @@ mp_fail_response_expect_subflow(struct mptcp_sock *msk)return ret; } -static void mptcp_check_mp_fail_response (struct mptcp_sock *msk) -{ -struct mptcp_subflow_context *subflow; -struct sock *sk = (struct sock *)msk; - -bh_lock_sock (sk); - subflow =mp_fail_response_expect_subflow (msk); -if (subflow) -__set_bit (MPTCP_FAIL_NO_RESPONSE , &msk->flags); -bh_unlock_sock (sk); -} -static void mptcp_timeout_timer (struct timer_list *t) {struct sock *sk =from_timer (sk, t, sk_timer);
Quoted 9 lines
net/mptcp/protocol.c mp_fail_response_expect_subflow(struct mptcp_sock *msk) · line 2192
Quoted 5 lines
net/mptcp/protocol.c +1
-1-mptcp_check_mp_fail_response (mptcp_sk (sk)); +set_bit (MPTCP_WORK_TIMEOUT , &mptcp_sk (sk)->flags);mptcp_schedule_work (sk);sock_put (sk); }I'm wondering if at this point we could get rid also of the
MPTCP_WORK_TIMEOUTflags. In case of mptcp-level timeout we just schedule the worker and let it do it's check.
Yeah, the iteration and READ_ONCE() calls over the subflows are not that expensive. I'll send a v2 for this patch...
Quoted 2 lines
Other than that the series LGTM, thanks!
...and mark the first patch as "queued".
--
Mat Martineau
Intel