Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp771273rdb; Fri, 2 Feb 2024 03:43:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG0mNAqW8J5vrN5znE1tgcEt0Cp0nEMYgJr5IwudooyVAU1WnyF+NCZK/7dZZWC7/9WUOv X-Received: by 2002:a0c:dc0d:0:b0:68c:830d:3885 with SMTP id s13-20020a0cdc0d000000b0068c830d3885mr2530969qvk.20.1706874212651; Fri, 02 Feb 2024 03:43:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706874212; cv=pass; d=google.com; s=arc-20160816; b=tHojd5W9bbpqpEdaCyUA4eIR5kKRiNQbBw8jnZdmbqXoNsBkB3WFl7yXeKqVPJNQrf agE/c79VhUiSCGHfkQxmFrOFWi8pkcYVcKghR5k3ZieWGng2N04ShBz6z69/xqecNLw6 8DbtJiZpOnYmT0wEPChBufFV7qzNO5LbPTQR16sQzaHh7zn6CP/5MRpIfVMwzjMvB0pG XUKUG2VmxA+xq0XJ+XqAgAi0pANGQi2+aGFszQil3NyCxRgPMO0cFBk9QzDj7Et7nxiH qwa8YldQSEZbSo3gfl4tSwKf9ol1/vNa0dQEdez2ZJ8ZReUPQa9LQW3bViCioXiERCTL lvhg== 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=yREpLxQ6hGlRha973evyl0evVJkLnafO9rlyPDtzCVQ=; b=Nl8pCDIaBw03BhF6PxS4KgH0nxa7kfLSR5ggc+Gy4g5jotrtTzVHlWiOyu83AGf0SL yjt0GKM1/EIxPi5b6GY+SWV4mIagZWu+/Jm7KsWzStmsQJubxz7fszH+L5IpT9HoNJ2I F5QpDJcxL1acmcQRqOFwQ3gpUSexVwSfiaB/SlLNirDY72R9MU38lZTKKuYauc5wqlqA yj4XMg85pqNy4Ht+EBvw3NHq0RYgSGKTMh5BCvlp2hz/OnmatJSaqtXov6Bs7R1ImEBx iF2N8A0rJqVYuzGdO5wTEyNuuZph3biB3Z2xYJbYNc+Yg8aO9WXrBT40R/hy+5A+B5lA DXyw==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49776-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCW5QY1CeDx7DjqGrB5HFkMrfYTNMlRX1V1cJYMsr8tCYB61FODZ9PJxi+kuEWxx9g6s+EtdiS6uQpJLyesPEf86hTAO+aWMNjzSXM1H3Q== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c8-20020a0ce7c8000000b0068c6ea9786bsi1776358qvo.261.2024.02.02.03.43.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 03:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49776-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49776-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 596681C2450A for ; Fri, 2 Feb 2024 11:43:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91EFF144618; Fri, 2 Feb 2024 11:40:26 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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); -- 2.43.0