@@ -410,6 +410,7 @@ static void mptcp_close_wake_up(struct sock *sk)
410410 sk_wake_async (sk , SOCK_WAKE_WAITD , POLL_IN );
411411}
412412
413+ /* called under the msk socket lock */
413414static bool mptcp_pending_data_fin_ack (struct sock * sk )
414415{
415416 struct mptcp_sock * msk = mptcp_sk (sk );
@@ -441,16 +442,17 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
441442 }
442443}
443444
445+ /* can be called with no lock acquired */
444446static bool mptcp_pending_data_fin (struct sock * sk , u64 * seq )
445447{
446448 struct mptcp_sock * msk = mptcp_sk (sk );
447449
448450 if (READ_ONCE (msk -> rcv_data_fin ) &&
449- ((1 << sk -> sk_state ) &
451+ ((1 << inet_sk_state_load ( sk ) ) &
450452 (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 ))) {
451453 u64 rcv_data_fin_seq = READ_ONCE (msk -> rcv_data_fin_seq );
452454
453- if (msk -> ack_seq == rcv_data_fin_seq ) {
455+ if (READ_ONCE ( msk -> ack_seq ) == rcv_data_fin_seq ) {
454456 if (seq )
455457 * seq = rcv_data_fin_seq ;
456458
@@ -748,7 +750,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
748750 __skb_queue_tail (& sk -> sk_receive_queue , skb );
749751 }
750752 msk -> bytes_received += end_seq - msk -> ack_seq ;
751- msk -> ack_seq = end_seq ;
753+ WRITE_ONCE ( msk -> ack_seq , end_seq ) ;
752754 moved = true;
753755 }
754756 return moved ;
@@ -985,6 +987,7 @@ static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
985987 put_page (dfrag -> page );
986988}
987989
990+ /* called under both the msk socket lock and the data lock */
988991static void __mptcp_clean_una (struct sock * sk )
989992{
990993 struct mptcp_sock * msk = mptcp_sk (sk );
@@ -1033,13 +1036,15 @@ static void __mptcp_clean_una(struct sock *sk)
10331036 msk -> recovery = false;
10341037
10351038out :
1036- if (snd_una == READ_ONCE (msk -> snd_nxt ) &&
1037- snd_una == READ_ONCE (msk -> write_seq )) {
1039+ if (snd_una == msk -> snd_nxt && snd_una == msk -> write_seq ) {
10381040 if (mptcp_rtx_timer_pending (sk ) && !mptcp_data_fin_enabled (msk ))
10391041 mptcp_stop_rtx_timer (sk );
10401042 } else {
10411043 mptcp_reset_rtx_timer (sk );
10421044 }
1045+
1046+ if (mptcp_pending_data_fin_ack (sk ))
1047+ mptcp_schedule_work (sk );
10431048}
10441049
10451050static void __mptcp_clean_una_wakeup (struct sock * sk )
@@ -1499,7 +1504,7 @@ static void mptcp_update_post_push(struct mptcp_sock *msk,
14991504 */
15001505 if (likely (after64 (snd_nxt_new , msk -> snd_nxt ))) {
15011506 msk -> bytes_sent += snd_nxt_new - msk -> snd_nxt ;
1502- msk -> snd_nxt = snd_nxt_new ;
1507+ WRITE_ONCE ( msk -> snd_nxt , snd_nxt_new ) ;
15031508 }
15041509}
15051510
@@ -2108,7 +2113,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
21082113
21092114 skb = skb_peek (& msk -> receive_queue );
21102115 if (skb ) {
2111- u64 hint_val = msk -> ack_seq - MPTCP_SKB_CB (skb )-> map_seq ;
2116+ u64 hint_val = READ_ONCE ( msk -> ack_seq ) - MPTCP_SKB_CB (skb )-> map_seq ;
21122117
21132118 if (hint_val >= INT_MAX )
21142119 return INT_MAX ;
@@ -2752,7 +2757,7 @@ static void __mptcp_init_sock(struct sock *sk)
27522757 __skb_queue_head_init (& msk -> receive_queue );
27532758 msk -> out_of_order_queue = RB_ROOT ;
27542759 msk -> first_pending = NULL ;
2755- msk -> rmem_fwd_alloc = 0 ;
2760+ WRITE_ONCE ( msk -> rmem_fwd_alloc , 0 ) ;
27562761 WRITE_ONCE (msk -> rmem_released , 0 );
27572762 msk -> timer_ival = TCP_RTO_MIN ;
27582763 msk -> scaling_ratio = TCP_DEFAULT_SCALING_RATIO ;
@@ -2968,7 +2973,7 @@ static void __mptcp_destroy_sock(struct sock *sk)
29682973
29692974 sk -> sk_prot -> destroy (sk );
29702975
2971- WARN_ON_ONCE (msk -> rmem_fwd_alloc );
2976+ WARN_ON_ONCE (READ_ONCE ( msk -> rmem_fwd_alloc ) );
29722977 WARN_ON_ONCE (msk -> rmem_released );
29732978 sk_stream_kill_queues (sk );
29742979 xfrm_sk_free_policy (sk );
@@ -3144,16 +3149,16 @@ static int mptcp_disconnect(struct sock *sk, int flags)
31443149 msk -> cb_flags = 0 ;
31453150 msk -> push_pending = 0 ;
31463151 msk -> recovery = false;
3147- msk -> can_ack = false;
3148- msk -> fully_established = false;
3149- msk -> rcv_data_fin = false;
3150- msk -> snd_data_fin_enable = false;
3151- msk -> rcv_fastclose = false;
3152- msk -> use_64bit_ack = false;
3153- msk -> bytes_consumed = 0 ;
3152+ WRITE_ONCE (msk -> can_ack , false);
3153+ WRITE_ONCE (msk -> fully_established , false);
3154+ WRITE_ONCE (msk -> rcv_data_fin , false);
3155+ WRITE_ONCE (msk -> snd_data_fin_enable , false);
3156+ WRITE_ONCE (msk -> rcv_fastclose , false);
3157+ WRITE_ONCE (msk -> use_64bit_ack , false);
31543158 WRITE_ONCE (msk -> csum_enabled , mptcp_is_checksum_enabled (sock_net (sk )));
31553159 mptcp_pm_data_reset (msk );
31563160 mptcp_ca_reset (sk );
3161+ msk -> bytes_consumed = 0 ;
31573162 msk -> bytes_acked = 0 ;
31583163 msk -> bytes_received = 0 ;
31593164 msk -> bytes_sent = 0 ;
@@ -3193,17 +3198,17 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
31933198 __mptcp_init_sock (nsk );
31943199
31953200 msk = mptcp_sk (nsk );
3196- msk -> local_key = subflow_req -> local_key ;
3197- msk -> token = subflow_req -> token ;
3201+ WRITE_ONCE ( msk -> local_key , subflow_req -> local_key ) ;
3202+ WRITE_ONCE ( msk -> token , subflow_req -> token ) ;
31983203 msk -> in_accept_queue = 1 ;
31993204 WRITE_ONCE (msk -> fully_established , false);
32003205 if (mp_opt -> suboptions & OPTION_MPTCP_CSUMREQD )
32013206 WRITE_ONCE (msk -> csum_enabled , true);
32023207
3203- msk -> write_seq = subflow_req -> idsn + 1 ;
3204- msk -> snd_nxt = msk -> write_seq ;
3205- msk -> snd_una = msk -> write_seq ;
3206- msk -> wnd_end = msk -> snd_nxt + req -> rsk_rcv_wnd ;
3208+ WRITE_ONCE ( msk -> write_seq , subflow_req -> idsn + 1 ) ;
3209+ WRITE_ONCE ( msk -> snd_nxt , msk -> write_seq ) ;
3210+ WRITE_ONCE ( msk -> snd_una , msk -> write_seq ) ;
3211+ WRITE_ONCE ( msk -> wnd_end , msk -> snd_nxt + req -> rsk_rcv_wnd ) ;
32073212 msk -> setsockopt_seq = mptcp_sk (sk )-> setsockopt_seq ;
32083213 mptcp_init_sched (msk , mptcp_sk (sk )-> sched );
32093214
@@ -3303,9 +3308,6 @@ void __mptcp_data_acked(struct sock *sk)
33033308 __mptcp_clean_una (sk );
33043309 else
33053310 __set_bit (MPTCP_CLEAN_UNA , & mptcp_sk (sk )-> cb_flags );
3306-
3307- if (mptcp_pending_data_fin_ack (sk ))
3308- mptcp_schedule_work (sk );
33093311}
33103312
33113313void __mptcp_check_push (struct sock * sk , struct sock * ssk )
0 commit comments