From patchwork Fri Feb 2 11:40:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 195825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp367047dyc; Fri, 2 Feb 2024 03:43:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAXysimWwDARF++H15raSfyGzEBjIhJ2yGqpiHO/VpGI9gbl7QQoK0sVHLxp39Iiv1P6fS X-Received: by 2002:a17:906:304e:b0:a35:4d7d:77af with SMTP id d14-20020a170906304e00b00a354d7d77afmr1318473ejd.8.1706874237861; Fri, 02 Feb 2024 03:43:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706874237; cv=pass; d=google.com; s=arc-20160816; b=HH29L2lHSu1FGR2EXoBPhWd6C2UvweGBmCZvzZSdyErHQ7XRhASJzuDjdO7k8s8xor EGaSu/8sp6N982/Y5bR0yr189U7PDKk58GXZjY9owIOmOwP1NIGZq0dkMi/6rnJ8sBNv pt2JPCXUq9Z7uF6re5KC+kYNST6r+avTfwmRMElu4XBcuui9TyCOJKgEHoj8B9lp4wv8 IIjzLYJN5r5IZf5ymx4p5GZn193cUzH1esgoM7uLiF6GvXg7L3NHhJXleHZ3+pKORmpg 1mO4O61RVSckS4ksz2uiXvFxIQWNwINfYLa2O/K7N22nJAKSEM0bmQ7CAx2Wk4GrztgW kRZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=h35wUP20lAwVP3LkLomBCmRFjlil5+U5l/RMHDghu+s=; fh=ZoPXhzlIsPJemaTtoFb9Tq9gzFFRFrT08UoCZSulbGc=; b=Z+ySInFTrrWWyspAcpgJYfySSOYRr2vB6XImepvxrb7+CZ7P83cKxWGxJxgdCDebXb 5ZW6rBLKqfWmTHDZ5C9LJYjeqzPYT96O6GEb4IxaTIIiJTftKU1ZPV7JIYjYSY67x5Ss /MjBtwSU38g2CA/kg5Hgb0OLL8Wl9z9DUQ+zlNtLw9iV+nbcfymbPxdut3Il9JSjRrS2 UfE6qWSk4wk8baPdlEk4qQNkoyHO9UbKvxtE4YPzT9ZqO/AURKcy6zjMifd8qpRk3bOQ QIApHs2NDWTh9UCbKDQ95eaM7r8ydMrtCiVvSABpHYBJ5+i8QdAXdtFIbEEodzUxXDI2 nidg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sS35dn3G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCV3D0DRA56YDd++MCtygoe2OCJ5b/FHJB5S7is978XYlced5CTD71HD/vxOC2t9btD200OfzMFncsw9UNq//F3w0Wra0w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o15-20020a170906288f00b00a316d302fcesi710630ejd.10.2024.02.02.03.43.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 03:43:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sS35dn3G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49776-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4CA721F2285F for ; Fri, 2 Feb 2024 11:43:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C24BA145B12; Fri, 2 Feb 2024 11:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sS35dn3G" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F395145326; Fri, 2 Feb 2024 11:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874025; cv=none; b=gvynJGbHpe+mP34EsSYdF87fpIJoNhK5+a2qq31ROq2hfRaR8507sT91IB9hnWcCBpLEu+18prPOTy8cxi6zhvcPLDr9uYl/A2/wnwhNO2y1G61F1SjFmtvLsLjrS8PSQaGOvNfk7JvuTTyC2b346brE2eDTjVmrjaRyMMbtsvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874025; c=relaxed/simple; bh=NizLa/rzuw+1XgtkX7T+tjMOuMLxy4qTjak2ZKxBBB4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vg8rjFcehtRo5Q0zP3bPBIQPLl/R/gJM1FpNwlip1XsQSSCFzbAYMIweXzOHpeGO54HzsNTpHIowu/OCgbRaRLR/haVp0nl6gGtfL3GZRstQxRmmBcPB3Zb1Qm3vUz2/GxHhKeNfuFxlty9iscNGQf7f98acObBKQPjdMK76ddk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sS35dn3G; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FA57C43394; Fri, 2 Feb 2024 11:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706874025; bh=NizLa/rzuw+1XgtkX7T+tjMOuMLxy4qTjak2ZKxBBB4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sS35dn3GfZ3NAUVFNO1sYHY3vdND4ZhzohGSUBkVpIr+EiyEoQlr83u0vRcEE9nuL b4H3eHuzP5nGE6KfL7fIwMZwB9CZzECFQCuUqjTFbu7i8iZkWFzYg8wfgvmAabhmOJ 15Nt6mnazaYbLqImE0zBlXgPt7+Z9ZN24ruEOMRop5zuIWRhFe/G4FwSDal4t/Wk/b qUIxtsKvkdEyeRkjtKyaCSrFDil2FH6BVx3liO94jXBVXMUdb4+WYmp2sbnIUM1bAG W1b9qLeHcDoioyDUAgoo4gcm241xouE8rS2KylQLXFdBr5qG1KmVH2Fttzf9R7/+H+ QxRCbSJOEg+3g== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 Feb 2024 12:40:09 +0100 Subject: [PATCH net-next 3/5] mptcp: annotate lockless access for RX path fields Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240202-upstream-net-next-20240202-mptcp-annotate-lockless-access-v1-3-031d6680afdc@kernel.org> References: <20240202-upstream-net-next-20240202-mptcp-annotate-lockless-access-v1-0-031d6680afdc@kernel.org> In-Reply-To: <20240202-upstream-net-next-20240202-mptcp-annotate-lockless-access-v1-0-031d6680afdc@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4841; i=matttbe@kernel.org; h=from:subject:message-id; bh=ZorjGDFuRUMjEvA3t02IR2AVaAgagTO7avy9WKwC/u0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlvNSeOR5zPgpyWCXq5b7TWqTECM1pKsPLCrGxZ MOwzP6M1SaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZbzUngAKCRD2t4JPQmmg cyY8EACZIVq7G5mYaqJgirKzI5pndhJk3btBITCu5Q9/hfZ2QYOWFL1Qm9ibWXjS5ivb4Hs/sGr SjmkkXQnnfRRAbwmZp/yttf2NRWsFVsXgHPU+TDAnSOo2tWFEBAxyKUI35DQR1MmaOo1vDM6J7P qo3bl+qFs1siiyNxxR5MdDq5MKx8ylieb86yl1+PH4r6x/cTXFIE6+Ag2/7lhmYT+jIrgd4ULxa +jfPL6LFjKXhEDM9tImO2D4FopoAt298tdPVGEXoIyXlRrWbNubWllT8l0+hP68tG0zCjU0Apu8 5VC82anLrY5jS6/UzIbHK746r43bd5RssjV0Fh9olK4xaItQqbxcdxg3cNevN7dfdOCMvkaHoa4 iFA7fntpctqVeXbRl8kVki9uSHndG/KDg3tI2Z/JeI5lQpCxfANHlXbEkjuiXjEKB4AG31pWw+0 IfJNSsX+2reyL52Y5x/q4oguzTuedSBd1a9Bbe/J3cBB9E8ySU4xvP4t/x/yg9Y0fLbqtBNlbvE uzpcLiV55azcHwVv/KNRKVdWgACPjCEmJbvnVIOcCZ8GHeoqhdYQB6JObYp4EfhWlGJlJ6MVZ5f QYJjxw/x0gQQIgFRSPd+iQPPq2AchmOzSWhD8q3vX4x2kmc9jTYMme7H5s02BAdl2wu7mZZsswW 53f7o9sny7P84Ow== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789787360434811624 X-GMAIL-MSGID: 1789787360434811624 From: Paolo Abeni The following fields: - ack_seq - snd_una - wnd_end - rmem_fwd_alloc are protected by the data lock end accessed lockless in a few spots. Ensure ONCE annotation for write (under such lock) and for lockless read. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 6 +++--- net/mptcp/protocol.c | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 9b31a0a06265..801a3525230d 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1030,7 +1030,7 @@ u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq) static void __mptcp_snd_una_update(struct mptcp_sock *msk, u64 new_snd_una) { msk->bytes_acked += new_snd_una - msk->snd_una; - msk->snd_una = new_snd_una; + WRITE_ONCE(msk->snd_una, new_snd_una); } static void ack_update_msk(struct mptcp_sock *msk, @@ -1057,7 +1057,7 @@ static void ack_update_msk(struct mptcp_sock *msk, new_wnd_end = new_snd_una + tcp_sk(ssk)->snd_wnd; if (after64(new_wnd_end, msk->wnd_end)) - msk->wnd_end = new_wnd_end; + WRITE_ONCE(msk->wnd_end, new_wnd_end); /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */ if (after64(msk->wnd_end, snd_nxt)) @@ -1071,7 +1071,7 @@ static void ack_update_msk(struct mptcp_sock *msk, trace_ack_update_msk(mp_opt->data_ack, old_snd_una, new_snd_una, - new_wnd_end, msk->wnd_end); + new_wnd_end, READ_ONCE(msk->wnd_end)); } bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b1c24ac3630f..90804e7fb7f6 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -410,6 +410,7 @@ static void mptcp_close_wake_up(struct sock *sk) sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN); } +/* called under the msk socket lock */ static bool mptcp_pending_data_fin_ack(struct sock *sk) { struct mptcp_sock *msk = mptcp_sk(sk); @@ -441,16 +442,17 @@ static void mptcp_check_data_fin_ack(struct sock *sk) } } +/* can be called with no lock acquired */ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq) { struct mptcp_sock *msk = mptcp_sk(sk); if (READ_ONCE(msk->rcv_data_fin) && - ((1 << sk->sk_state) & + ((1 << inet_sk_state_load(sk)) & (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) { u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq); - if (msk->ack_seq == rcv_data_fin_seq) { + if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) { if (seq) *seq = rcv_data_fin_seq; @@ -748,7 +750,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) __skb_queue_tail(&sk->sk_receive_queue, skb); } msk->bytes_received += end_seq - msk->ack_seq; - msk->ack_seq = end_seq; + WRITE_ONCE(msk->ack_seq, end_seq); moved = true; } return moved; @@ -985,6 +987,7 @@ static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag) put_page(dfrag->page); } +/* called under both the msk socket lock and the data lock */ static void __mptcp_clean_una(struct sock *sk) { struct mptcp_sock *msk = mptcp_sk(sk); @@ -2110,7 +2113,7 @@ static unsigned int mptcp_inq_hint(const struct sock *sk) skb = skb_peek(&msk->receive_queue); if (skb) { - u64 hint_val = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq; + u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq; if (hint_val >= INT_MAX) return INT_MAX; @@ -2754,7 +2757,7 @@ static void __mptcp_init_sock(struct sock *sk) __skb_queue_head_init(&msk->receive_queue); msk->out_of_order_queue = RB_ROOT; msk->first_pending = NULL; - msk->rmem_fwd_alloc = 0; + WRITE_ONCE(msk->rmem_fwd_alloc, 0); WRITE_ONCE(msk->rmem_released, 0); msk->timer_ival = TCP_RTO_MIN; msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO; @@ -2970,7 +2973,7 @@ static void __mptcp_destroy_sock(struct sock *sk) sk->sk_prot->destroy(sk); - WARN_ON_ONCE(msk->rmem_fwd_alloc); + WARN_ON_ONCE(READ_ONCE(msk->rmem_fwd_alloc)); WARN_ON_ONCE(msk->rmem_released); sk_stream_kill_queues(sk); xfrm_sk_free_policy(sk); @@ -3204,8 +3207,8 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, WRITE_ONCE(msk->write_seq, subflow_req->idsn + 1); WRITE_ONCE(msk->snd_nxt, msk->write_seq); - msk->snd_una = msk->write_seq; - msk->wnd_end = msk->snd_nxt + req->rsk_rcv_wnd; + WRITE_ONCE(msk->snd_una, msk->write_seq); + WRITE_ONCE(msk->wnd_end, msk->snd_nxt + req->rsk_rcv_wnd); msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq; mptcp_init_sched(msk, mptcp_sk(sk)->sched);