From patchwork Fri Feb 2 11:40:07 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: 195859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp419955dyc; Fri, 2 Feb 2024 05:18:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IE56UkLZx3g09I1ny8oRv4Gs8l5OhfaNdmNvPp5eNK5warmT2J8cd4UVKKrnrTfTicMT2cr X-Received: by 2002:a17:90b:911:b0:296:286c:4dd6 with SMTP id bo17-20020a17090b091100b00296286c4dd6mr2111801pjb.46.1706879914588; Fri, 02 Feb 2024 05:18:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706879914; cv=pass; d=google.com; s=arc-20160816; b=Dp6mK4GPKicHBMAYa8n7oJWXkbbghTpOZzHN2Vki5xxZFRWiBksfX8b2XE1EfzbQY3 WXlws80kBmXsw7gJxZB6rNajwkvSmE7Fk5QT85D5O+Zy3OGaOpmCvrsmDVzm4KhGHN0s M+p6BZZjSNKIcH+q8iuo51Mc5RflV4kjhpWoWhP7BaE510YE0iHp03ZVQNcXGzia6i1N 4wzlUJQgHu6kga0xyxngixez2zerHfpO18GFUNA2hlEIWFXD8whFc/uTNr+brhDp6wg0 4+T1peXu+yzG9QjI0s07xs9hs/BmU1iCXwHKF3ZoRFfgQycOh5wJMh7i5bSL3Si8ADpg LJwg== 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=LAHWCQVHRQExv/UTIJjORWtcb/iJwJVBcjhPnVXaq54=; fh=z6meEuziVMLmAUkw/cG0GO/JnBDoNY2fAZfe58qQlQs=; b=fxJN9++eofIbplsV/R/w4nZsW0HmeUEBB2a3rLG2uIS9gl6ZR45alJ+YjQZDn+DSlO /s7/csGY9JK/XmEf5BXS2mO5BlfJdosxRY3VgPvU356cIVNTSh4x6EkB1erK90ldBjzG o6/vJISVV6Bh2pffa44ammk6565JACBncYJUc1SLeE1t9/AYBH3APqOq8kJ4KPYcmh6D mfSQaa9uM8kJDYru+UPYWIbi1QLGNcfMlfHbUrBERPdUgp7Lx+pCwtMkr8hMtMH4K/7y GTW6vCYIQP6upMldDSeX6gMq1uVtDCN0SBpTyzOGztvdoYBRoQ+w6fezKKp43/+dJB9+ 9/yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oKBHgSzg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49774-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49774-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWiHIOE07FxGowqMMVU1jWZXHln3juPjgUMq2NltyfpuDjDArWzG8V4E0zQ6ix7Z1tZWFAVVYX+ulEfYGNwhJ4jXHSeew== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b5-20020a170903228500b001d75d88f9a0si1762306plh.466.2024.02.02.05.18.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 05:18:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49774-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oKBHgSzg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49774-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49774-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4413A292CB9 for ; Fri, 2 Feb 2024 11:43:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF970144632; Fri, 2 Feb 2024 11:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oKBHgSzg" 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 7FECD13EFF7; Fri, 2 Feb 2024 11:40:20 +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=1706874020; cv=none; b=ubjq9rNsoybodQq/IXmzCtZrLFJcQbN5tOE8T+TSaDOctK98L3ujBy2ZVtwSPhLG+k6vE0p389FFmi797P/myQFZJYEID7vsQu8LJ1APQSRTDW0QRQL9xq7k/nc62DkEje6R1SNrlJxttBpjL3ATlVElHIMWXAIdSsGcZXSib5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874020; c=relaxed/simple; bh=5yc+86w3yyKe04H5iWLy/uFSmTiMA2lqTHZoCkfPUCU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N994CICy0d3e3TbHE438XoUTwV0KkCohpGSeG4ivX5ueyi+W+sozp7yN4H9674OCK+g3mttShyD/sEkLmCxLK/nBKfCekh7KXcBbw/S1GJU+l3sMtit8NFJcYpg6pGwSLHboaGKJJd2HgcJaO+L0y8Wz6+lJ/KAMtBeHBxJIXfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oKBHgSzg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5922C43390; Fri, 2 Feb 2024 11:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706874020; bh=5yc+86w3yyKe04H5iWLy/uFSmTiMA2lqTHZoCkfPUCU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oKBHgSzgToOEaPb7eGUdUc89q9lOc3ljyY4AmNcHzLGpkghl/p3DZyThZ0VBdclyg y6Towp76lYE7rY6yb8JmF0n9cwYQlIAlDRHT6lUAtQ8sbZSzJlNENqy2SP/eGvI1gH UDq87w1cCevNlVI4ibvzQUT7rgW+2nJamNlvBJwGnFg6olaKRf7TIRkq5s/5NBVRVC dFhD65oy6cZVusDR+NKPj39+y2gYBRtRcFB4zp67+vEbPIhk9cDQS/z+4GKxE9C6fP 6sUeDVjMig67fVvbhlmRtK+6cwoNPm9V7mVpFCoeIFzNX9WR+ShS7b9WgcrgdJMZhr ql6/2lVJ1h+AA== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 Feb 2024 12:40:07 +0100 Subject: [PATCH net-next 1/5] mptcp: annotate access for msk keys 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-1-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=4822; i=matttbe@kernel.org; h=from:subject:message-id; bh=96HWwfDzSrjT/wYUKZiVvF6RaRUdJdTbmitFuA8YVr4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlvNSeT6koPoNWOPabIN9mKiAw/EcaIERSBZoZ/ /nhmOYhhz2JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZbzUngAKCRD2t4JPQmmg czaKEADS+YXwH4jzDmGv2L3+5H/uS0oZWbZ8jjEHdWwXxUenyXHbDGBJ550y/EgvdfNIjSt82Eg /NinqEmTQNm32OMumcQ2ZnzUnr7o3n6sZd3iHsc+YUp5dYNskjVOLeo7xdIr6juDed4gTowIacC NaJjZRSeU1bByIm7gar9Gded4/m567WLtHsnq7S7RaDFy3gYVOWpcVstq7aOQtdKB3TibnjHhoQ EFWKbxsztiuQeLPOsKtH7o0U8OcFcpQvwbpDOXgdYRdDQBIudaHAawmFpuMiE9IO5H2GU1x4YPE J7AuPDcQUBdHLOtG7czM3gykGLhaFkb89MaU4+9UzDp3z1Y+UCnhbvMAxk1JB08+SURWnhrhYt7 qjFVkIHZvi4rhFPZQblkS9bBs/E6Pa8gW6Yu2RFYCE13G6rz4+RK4zgTtfkjtysA6nKOqJ9b488 ECTZi7YyManvuzRzSNfVqh6iXAIHMEt6YrsnLv8ncH3VJIFLidlaXKzKnAkJOW9WA3/a1VNjxaS zhPRztHSPDf+hdz/Wtl18NGCXot4Fps5NG50s6v5uLimfWKFFZ4gD8DF1AG+nlqIjTywsucXyim uxGaesC5g+n+9Dx5kmw8/ix9FhBaOz8G4wLwsCJxOSn9Kdfb1uIBcIAzu3RVhNbYBF/1VcE74/o ylz59Htow+Ix3eA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789793313682328547 X-GMAIL-MSGID: 1789793313682328547 From: Paolo Abeni Both the local and the remote key follow the same locking schema, put in place the proper ONCE accessors. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 12 ++++++------ net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 6 ++++-- net/mptcp/subflow.c | 10 ++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index d2527d189a79..5e2b130d8680 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -689,8 +689,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * opts->suboptions |= OPTION_MPTCP_ADD_ADDR; if (!echo) { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX); - opts->ahmac = add_addr_generate_hmac(msk->local_key, - msk->remote_key, + opts->ahmac = add_addr_generate_hmac(READ_ONCE(msk->local_key), + READ_ONCE(msk->remote_key), &opts->addr); } else { MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADDTX); @@ -792,7 +792,7 @@ static bool mptcp_established_options_fastclose(struct sock *sk, *size = TCPOLEN_MPTCP_FASTCLOSE; opts->suboptions |= OPTION_MPTCP_FASTCLOSE; - opts->rcvr_key = msk->remote_key; + opts->rcvr_key = READ_ONCE(msk->remote_key); pr_debug("FASTCLOSE key=%llu", opts->rcvr_key); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX); @@ -1099,8 +1099,8 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk, if (mp_opt->echo) return true; - hmac = add_addr_generate_hmac(msk->remote_key, - msk->local_key, + hmac = add_addr_generate_hmac(READ_ONCE(msk->remote_key), + READ_ONCE(msk->local_key), &mp_opt->addr); pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", @@ -1147,7 +1147,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) { if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) && - msk->local_key == mp_opt.rcvr_key) { + READ_ONCE(msk->local_key) == mp_opt.rcvr_key) { WRITE_ONCE(msk->rcv_fastclose, true); mptcp_schedule_work((struct sock *)msk); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX); diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 028e8b473626..874f019c5093 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3193,7 +3193,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, __mptcp_init_sock(nsk); msk = mptcp_sk(nsk); - msk->local_key = subflow_req->local_key; + WRITE_ONCE(msk->local_key, subflow_req->local_key); msk->token = subflow_req->token; msk->in_accept_queue = 1; WRITE_ONCE(msk->fully_established, false); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3517f2d24a22..13b8cf8ec704 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -260,8 +260,10 @@ struct mptcp_data_frag { struct mptcp_sock { /* inet_connection_sock must be the first member */ struct inet_connection_sock sk; - u64 local_key; - u64 remote_key; + u64 local_key; /* protected by the first subflow socket lock + * lockless access read + */ + u64 remote_key; /* same as above */ u64 write_seq; u64 bytes_sent; u64 snd_nxt; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 0dcb721c89d1..d60b83511302 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -75,7 +75,8 @@ static void subflow_req_create_thmac(struct mptcp_subflow_request_sock *subflow_ get_random_bytes(&subflow_req->local_nonce, sizeof(u32)); - subflow_generate_hmac(msk->local_key, msk->remote_key, + subflow_generate_hmac(READ_ONCE(msk->local_key), + READ_ONCE(msk->remote_key), subflow_req->local_nonce, subflow_req->remote_nonce, hmac); @@ -694,7 +695,8 @@ static bool subflow_hmac_valid(const struct request_sock *req, if (!msk) return false; - subflow_generate_hmac(msk->remote_key, msk->local_key, + subflow_generate_hmac(READ_ONCE(msk->remote_key), + READ_ONCE(msk->local_key), subflow_req->remote_nonce, subflow_req->local_nonce, hmac); @@ -1530,8 +1532,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, mptcp_pm_get_flags_and_ifindex_by_id(msk, local_id, &flags, &ifindex); subflow->remote_key_valid = 1; - subflow->remote_key = msk->remote_key; - subflow->local_key = msk->local_key; + subflow->remote_key = READ_ONCE(msk->remote_key); + subflow->local_key = READ_ONCE(msk->local_key); subflow->token = msk->token; mptcp_info2sockaddr(loc, &addr, ssk->sk_family); From patchwork Fri Feb 2 11:40:08 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: 195824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp366773dyc; Fri, 2 Feb 2024 03:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxDgR7g0xHHZuW2X2aTKFqlUsNBqhfAia4ZjOlfDAgoSdfMZatwqAu03mp2brcSg/9M5YQ X-Received: by 2002:a05:620a:225:b0:785:54d4:5568 with SMTP id u5-20020a05620a022500b0078554d45568mr1282343qkm.47.1706874199671; Fri, 02 Feb 2024 03:43:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706874199; cv=pass; d=google.com; s=arc-20160816; b=kTPM/4441FU6RhT3WjGidjEWLRN+LjyYPqhoC2DrgTrjPG/h4E0wylSKJFzygdzSn0 lxFB0vmHkR0dRrnFmZkfXygvUL+TR1MW5G7trXEfkt8Jl8jRXDGmSPx4bkDCD1jR7ks5 G3zjknMzkY18yYRJgNSvMjb0W12PrTIuht64Ealfob9SfcL+7CnA5Rb6JLITgvPGVA4H glMWiE0JS0u1UsedRaTXIn5D17pVwPyQPCbXTXxpvLcc0MRLtLAE4kptrKh76Hs+iqDN oCGwYyWcu+6k4hxzZZsB02OmzMj4fOkpo7yZlDIo58OfqExYFTaamJ0WoLutFCntYBkR OFww== 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=omQ3bMHPnKBXwstv4lM6rsw0hyQKdv5dUPi6Q7HZYAk=; fh=zN0pGz7lLA6/47yoTChr06c0t2zSdVhXQgqcq4zEYws=; b=ZROqvXuv3gIAgiSaER8iulH2p/FdiWXGvH7OrxsV4rIf2lJ0YyWWS3gw47IgYeOnn0 yMqbXgpljbR6E3DC5uggOJ8VQ1RRZMmFYS7eIkSvADAiRbqojyePmkluiKH5taYI1ndV 40Qe357VBsx/1488VE3QDySMaOkmMkehAqmi9ctrhqh/uIuUdNYdCr+KjINt8iWBJkz5 Grrf0ZOJZdmoTCjTH+Fav4H0e7FClVJlb85iKXDvmzxM0EAiV22DPIR8ubOmPX2BdE6r FGz0KlRW0R5r5+hqdzwGjrmck0N06Y6ELvA8I+HqDHDZ44hn+6FtNZZpQbva/5e1RAGm U8HA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NHx07HdA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49775-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49775-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX7XyxCQOBBbADMz8DZHCic3QtofsXtuhBsPSm8I9HTMSwgc/ASHJo3/4TjbYt1gZiljrr7/5qq4sB9VqHmXRo1rN4EYQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u25-20020ae9c019000000b00783f4d2dd34si1807779qkk.99.2024.02.02.03.43.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 03:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49775-ouuuleilei=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=NHx07HdA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49775-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49775-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5556B1C2406E for ; Fri, 2 Feb 2024 11:43:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6DF914532A; Fri, 2 Feb 2024 11:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NHx07HdA" 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 B7E1B144618; Fri, 2 Feb 2024 11:40:22 +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=1706874022; cv=none; b=HwB9GWf+HAfFiXQ3DcSre06Ob/gHE9TjWx5MEVHPYQvCk+wbPpQcQIsf+jVHEeMy/+1og24TKyK8XhOlzzvsVqmPVbeCWXwQ7vOO/ZvE+11ucAKkkm5sVrx8q5764zrsn84c6EoUNz5cO/9VQM4i2LeciCU829cjvJMJ/TRumy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874022; c=relaxed/simple; bh=jbBx8q1vG4VmSQFPNppoUAvomZ9X9DzfrEVGbLhs1RE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IxxKGwH8e8utSoVcNl7dwEyZw22OiOyrVJWvt2zwhja7UGBSvDfhd9C35/Ev/Ytn6GuB0AwEzeeu73SVt6LzbHvnWDVS0LwPLP01A+5cXsdTeaL4sf2lJCMOH2FwAIs+3O+7M+qTwB+x07JicIoosT/j7las/DvEqRsnyC+1GKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NHx07HdA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B01DC433C7; Fri, 2 Feb 2024 11:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706874022; bh=jbBx8q1vG4VmSQFPNppoUAvomZ9X9DzfrEVGbLhs1RE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NHx07HdA0txkz6Kg4jcglbOKmsnMJQ58xdfY9vQ097HoD2lqfWhNU++A6LQ9hvPDr PmgKyEkHh1COawu82I/+1FfMoQcLTXslltY6yU9BEiuFjq9iSw8pCgPEeBXj9/y2g9 aAybpsJy3SlwTCCTEkH8sJwhSDIu9RVgdQ20H/YCddHdiz6zFgqU/sMGFKcXuQhaic 9TkHtwER4oQf5GoGDRPaRVP9B03kpfgMhwT56jyYZ282TJQzU9YVNfzUbtwzZwJ4/b p56c3GeDu0lydQH6LdOIt7tL5Kr+GkYscYbEenA/P7OX22/biLGCqvOEW772fha6wA 2HzjsbtrPD0yA== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 Feb 2024 12:40:08 +0100 Subject: [PATCH net-next 2/5] mptcp: annotate lockless access for the tx path 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-2-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=3573; i=matttbe@kernel.org; h=from:subject:message-id; bh=7J0ps97A16g4/waL3hRAHqtfG/mCa7C1N2tO1Q3wljs=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlvNSeEHAGjdHYf9+bhXUw0e25/bnvtwTgQPzCO hD8NwuWSW+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZbzUngAKCRD2t4JPQmmg c2nrD/4rw4BSU4iHidYCavNrIGDXx87gVG23+vvfoUKu8HzUhssJai6lFM7HKzLL6nBbp0P/AYf Kk9XjZ/I9jq+gq3SmH3Unbdbb2a4CcQC1UmWy6Zm0tmmsj9tx/wWSSxCLAMxYYqJC1ay8rnb53N a2x/7hr6aoND1O/tqqskqXA50X/flbmCSUAneFYNAN4X1YENXB3pkIB/guybBgS2uE4fN9kdXON lP2zfKajD75+Oy2PXA2YM4Icswx7skiaaTPlv02ipfRoX7Uu3wRqDxuCm0DKsU+sIXHBOfDr2wc gRZcxRo7jE46xw3152JW6kjwVPf+D+pxjOas4PThmZoXwzo7QCmDCdVsk/1KC0u0AdCDJEMb/9A QvrkvvlCtek1dw2G/ywdxq2ZhoYf9YUO7IYyLZnFl/OzlBdwNLq3jPlZQ5Ew4AR/xJLXVNmNj6A ainP8gh97rpFenzS7OFAbkb1TyTne5KI9GhuO8YAbQ1TQgfDTXrTBsbx589TPeI03imb0Ycsh6f TtoYh6cjsdEK1vhkeL5bSrebmIv/J9joQ2xT0aharoSYV8wbIsfJ//TCbokpZh7t+aph70LuSqU OOOwywjBp3QGFl73cCGinUkAzWJ5qf1udzZW/XZseXb2D9JVRWqsLkjrrDH4LzF0aGeHdd3zIOk IG/KyuQMKV9qCjQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789787321179693625 X-GMAIL-MSGID: 1789787321179693625 From: Paolo Abeni The mptcp-level TX path info (write_seq, bytes_sent, snd_nxt) are under the msk socket lock protection, and are accessed lockless in a few spots. Always mark the write operations with WRITE_ONCE, read operations outside the lock with READ_ONCE and drop the annotation for read under such lock. To simplify the annotations move mptcp_pending_data_fin_ack() from __mptcp_data_acked() to __mptcp_clean_una(), under the msk socket lock, where such call would belong. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/options.c | 2 +- net/mptcp/protocol.c | 15 +++++++-------- net/mptcp/protocol.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 5e2b130d8680..9b31a0a06265 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1060,7 +1060,7 @@ static void ack_update_msk(struct mptcp_sock *msk, msk->wnd_end = new_wnd_end; /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */ - if (after64(msk->wnd_end, READ_ONCE(msk->snd_nxt))) + if (after64(msk->wnd_end, snd_nxt)) __mptcp_check_push(sk, ssk); if (after64(new_snd_una, old_snd_una)) { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 874f019c5093..b1c24ac3630f 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1033,13 +1033,15 @@ static void __mptcp_clean_una(struct sock *sk) msk->recovery = false; out: - if (snd_una == READ_ONCE(msk->snd_nxt) && - snd_una == READ_ONCE(msk->write_seq)) { + if (snd_una == msk->snd_nxt && snd_una == msk->write_seq) { if (mptcp_rtx_timer_pending(sk) && !mptcp_data_fin_enabled(msk)) mptcp_stop_rtx_timer(sk); } else { mptcp_reset_rtx_timer(sk); } + + if (mptcp_pending_data_fin_ack(sk)) + mptcp_schedule_work(sk); } static void __mptcp_clean_una_wakeup(struct sock *sk) @@ -1499,7 +1501,7 @@ static void mptcp_update_post_push(struct mptcp_sock *msk, */ if (likely(after64(snd_nxt_new, msk->snd_nxt))) { msk->bytes_sent += snd_nxt_new - msk->snd_nxt; - msk->snd_nxt = snd_nxt_new; + WRITE_ONCE(msk->snd_nxt, snd_nxt_new); } } @@ -3200,8 +3202,8 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) WRITE_ONCE(msk->csum_enabled, true); - msk->write_seq = subflow_req->idsn + 1; - msk->snd_nxt = msk->write_seq; + 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; msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq; @@ -3303,9 +3305,6 @@ void __mptcp_data_acked(struct sock *sk) __mptcp_clean_una(sk); else __set_bit(MPTCP_CLEAN_UNA, &mptcp_sk(sk)->cb_flags); - - if (mptcp_pending_data_fin_ack(sk)) - mptcp_schedule_work(sk); } void __mptcp_check_push(struct sock *sk, struct sock *ssk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 13b8cf8ec704..421dede93e2b 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -402,7 +402,7 @@ static inline struct mptcp_data_frag *mptcp_rtx_head(struct sock *sk) { struct mptcp_sock *msk = mptcp_sk(sk); - if (msk->snd_una == READ_ONCE(msk->snd_nxt)) + if (msk->snd_una == msk->snd_nxt) return NULL; return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list); 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); From patchwork Fri Feb 2 11:40:10 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: 195826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp367219dyc; Fri, 2 Feb 2024 03:44:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoXAhOtUnd1Z0usYDQL2P6saCJaIWAQpgfxvqIKytprEkWVqhEzWmRkNOchQ1yP98b9ZFA X-Received: by 2002:a05:6214:268f:b0:68c:3d2a:42a5 with SMTP id gm15-20020a056214268f00b0068c3d2a42a5mr5402231qvb.30.1706874260198; Fri, 02 Feb 2024 03:44:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706874260; cv=pass; d=google.com; s=arc-20160816; b=mUvl2aEwF4Hk/x6Fd0h7DDkjMn07uvlow8/SqZeDAYRGq9sXrqGVBn22mEp/AKaI9Z LJCKRwvaJPLhjaEZ/CoVQSRrihmqZ+HzP8UrxlMy5BHAp/rbNpBHQ/d5+1m8WpTFdSQ4 GpYIRwEezc8S6i7WCajrwnQrUFw2n3ZJYhmk7GPZ4LhxRjlYHmXgUcKc2kGaZ4fZsJCC ajWO6pjJneKODOk8dv/MbvoFwVnf8T16eqigrI/Xa/tVN38UtdC9nM2QXWuowBaSSMuF cI4GvHUdA54plMapRPhdbNq/obXV6bpe+mksLQLT0tlqD3KApIB+IHvbLguUxXwuC/fm JbIA== 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=hxxvBoLN/tQ+Qc76DViwqjIgYETydA7XIkPcgz8LrNo=; fh=aJ8So81dEPo6BQtZi5wXdn1K29jgHRQK7nKcW31KLQM=; b=m36I20WbK+KJ/wCW+MJuYnYinA127Q2afDMJQsYqGu7XW+JFl/h88T2zNX2/nvnpuG UGk6yZaWTdvppIElghzbAIuGZV5sZwNN6X1FpOzKKt93E3Qdyh0niF0WJ2NvoGWLfMw2 3paVDfqm5tZDbRcu5x2fj+H8JHnT/ikNFTPGU1SkonyE+gUJFenHcp8I8AweObF9PyM5 AweHRWZ3oli9to0YteAm/ryqLCMrBxuGqL3Hvu0mvKaDTC8Tg6gYQh0lnp6l5GEsdg74 0Hp0ejR4C4OoMPxatnvBHmbxYapdjaZzPfo7QoGdPdJUmEAzQznezvGTJ6BCXMNwNIRT mFtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vR66BzAo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49778-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49778-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWpxgYAlRR5dCp8PUapRyqn+ZGO7qGz/OGavUUVx5M0PlpDZifbPx+msgha+qppHqJAn/2mEDvqoCFcSkTDWIHI/TVe/w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r18-20020ad44052000000b00685c947ea1dsi1753947qvp.535.2024.02.02.03.44.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 03:44:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49778-ouuuleilei=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=vR66BzAo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49778-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49778-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 03D341C245E1 for ; Fri, 2 Feb 2024 11:44:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5579B1468E2; Fri, 2 Feb 2024 11:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vR66BzAo" 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 49F41145B03; Fri, 2 Feb 2024 11:40:27 +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=1706874028; cv=none; b=XIxOOOjUOT5HmG7qBsXbKAxfrq13gc0x8QyJUh43F+JOkM0yNmFsxdsmasfA7zLd+mWIP6glg0x1/1Xid5C6zvTZavs8/BPKyVEi8wX7IFUSrGQaWGVTyukpTWRjfccIc/LCzrvXY+w8Lmeyc3npOUscOY5pPxD5acvYNus9ZhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874028; c=relaxed/simple; bh=GP9eXw8XviQI7I0KXeWcmDow825AoLoWnedltmWdRbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8vzfys1KNqUPnO7xlzUVTNy5hegBvBoVrisAECSccRzFzGeHFdCnuS4OlkuYRSq/BTcgQc0Tb/dAkNVOA1CmzFTmfN5y7XngUfuCpd6WrpPcNHYlAIugPvR3s2mjdfYqRm7oDzlnSOTw5N1MaKcpZdbr2vdIHJWHEZEshznI0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vR66BzAo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B3E3C433B1; Fri, 2 Feb 2024 11:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706874027; bh=GP9eXw8XviQI7I0KXeWcmDow825AoLoWnedltmWdRbg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vR66BzAoA4FosnObRO94TlFpWdDcv7xzJZr4vhg0mO9RM8UjS1AbjbHXSbz8a8QtZ BhEWtso9AeuvvSGBNJ+/+PexFh62MFCm1nUc+RlFpZBvIvOl2JGcsjZt3nrRyqMVgZ D6j91IZL7SDAbmqCSDG26skA4nL29/eE8XkPMAMQDuuSOuIR9aisQfOPgljpEoHn0I uNW2i2NVSw4bxs8p9HkxdQkmZOZr9nht2Mk5oytVq89qBJ66Q6X7KEVXIJ+18ylAp0 A7pTCthFh7NngkE4+kRfc0k4TEJ+QUnZlIhaC/qupPI0cK3h7wY9Br2ocWV4Gn4PIE 1wW8Z9biWhiVg== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 Feb 2024 12:40:10 +0100 Subject: [PATCH net-next 4/5] mptcp: annotate lockless access for token 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-4-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=3367; i=matttbe@kernel.org; h=from:subject:message-id; bh=jKtAxP0DW7aZKLSgEet2dMJtl4rlzc/BQZ56tk1mhM4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlvNSe/zN+qxEADlW9fazl/W/zNsj2KuYaPoDWZ uvr5FB9OPWJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZbzUngAKCRD2t4JPQmmg c/x/D/9UTks+dD6xEfEuQzCbr0tb6px9mkKufMkQzQlIuX/Xyq8I3HUjWpycoqf/rJ2L05udR0r Jf8StKWhEAiX0KgZ5Ge7QPreVq9i6EtuXz9LgP2VAPu9ppvTwOo9X5zwu/3jQIPX/8QwbI6U+8C 4hwoGdT8XL8q7BS1tEErVMCxpWOOHTize/JWqk2a6Gxwxk6P17Mgkk08cTP0UKeqpuUiKVrXBm6 dzTz/VH/hB1frnYiUXaF/Evj8Mo3yDz/2Q7MsPdHAThbD5ajhyDCgvcY0qEW4VhxGLILikPXaSh PtJx+W/9gxITlok1GLfwZm7NaB3OjtvGRtoc+/bO8RmVCp4Ufu/EBLbHXRvOCqMngbNfX2uJIsS cAz0YhozWo6t4An7XN56N2UhyFlgMy6mmvyfFZkp7h/bIQY10JmrOSzy8GGJlqLqqTByiucU/IY r5c6uzVL3sJWUCXWtu36+m2HfWYKhT2K0R9Qsu5cxU9Fwpw8sOOzxbWnFKWiCSczCg+FiD4lLG3 wutdHdGKZmVwnyctzyKAKavUWBYWtDZQSVz5bGS52OtX/mttO2951WequvGPl08LhS9B3eoasXl 2bwf4UW8ubsaN7ncqHXWYZY1sh79HTCz1esoujsSAN+DFA4NzB0NZ47h3yj7OvjYgzJWucShXof ZWAZ8xnO0YbKLpA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789787384238486845 X-GMAIL-MSGID: 1789787384238486845 From: Paolo Abeni The token field is manipulated under the msk socket lock and accessed lockless in a few spots, add proper ONCE annotation Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 10 +++++----- net/mptcp/protocol.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 4ae19113b8eb..53e0b08b1123 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -77,7 +77,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int { struct mptcp_pm_data *pm = &msk->pm; - pr_debug("msk=%p, token=%u side=%d", msk, msk->token, server_side); + pr_debug("msk=%p, token=%u side=%d", msk, READ_ONCE(msk->token), server_side); WRITE_ONCE(pm->server_side, server_side); mptcp_event(MPTCP_EVENT_CREATED, msk, ssk, GFP_ATOMIC); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 287a60381eae..d9ad45959219 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1997,7 +1997,7 @@ static int mptcp_event_put_token_and_ssk(struct sk_buff *skb, const struct mptcp_subflow_context *sf; u8 sk_err; - if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token)) + if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token))) return -EMSGSIZE; if (mptcp_event_add_subflow(skb, ssk)) @@ -2055,7 +2055,7 @@ static int mptcp_event_created(struct sk_buff *skb, const struct mptcp_sock *msk, const struct sock *ssk) { - int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token); + int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)); if (err) return err; @@ -2083,7 +2083,7 @@ void mptcp_event_addr_removed(const struct mptcp_sock *msk, uint8_t id) if (!nlh) goto nla_put_failure; - if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token)) + if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token))) goto nla_put_failure; if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, id)) @@ -2118,7 +2118,7 @@ void mptcp_event_addr_announced(const struct sock *ssk, if (!nlh) goto nla_put_failure; - if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token)) + if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token))) goto nla_put_failure; if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, info->id)) @@ -2234,7 +2234,7 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, goto nla_put_failure; break; case MPTCP_EVENT_CLOSED: - if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token) < 0) + if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)) < 0) goto nla_put_failure; break; case MPTCP_EVENT_ANNOUNCED: diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 90804e7fb7f6..4478ddd3b5fa 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3199,7 +3199,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, msk = mptcp_sk(nsk); WRITE_ONCE(msk->local_key, subflow_req->local_key); - msk->token = subflow_req->token; + WRITE_ONCE(msk->token, subflow_req->token); msk->in_accept_queue = 1; WRITE_ONCE(msk->fully_established, false); if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) From patchwork Fri Feb 2 11:40:11 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: 195835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp375470dyc; Fri, 2 Feb 2024 04:02:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8LLRXY6xDmuyO8wB21KzGtMikGDWiEFoD2fu7wBtudHLhuwD0dQKw8tYgy+C9N1kGPwcK X-Received: by 2002:a17:902:e541:b0:1d8:f977:4159 with SMTP id n1-20020a170902e54100b001d8f9774159mr3273651plf.4.1706875341228; Fri, 02 Feb 2024 04:02:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706875341; cv=pass; d=google.com; s=arc-20160816; b=w6JDQtDdW9UAEsbx1syBDKczr+JwABYgGAmaIQBiy1V29eYWJsAFqSzc0ms6LI5Z7X fUx2s3PFcdgFVWMGfaSvv0osxjxfy8+tL0Oyn0kVqE0JJbsGnpxJK2wp3Zmv5dgi+tBx RddOuoEGaSJ8+ezvGVSZsOuOn1gBNMMmZ1wxOMDu9zCge8iWwbHquylKMS1NQvSWroVI rZc7m7gxbHHtZyg3hwgulvx1/9zxgIUfqniLCfzBdhnvpEEEPlXvzKX7sFBPctpuc0bz QPHq1YubLA4F064DVXF6/KZ2Fb3Yx+k/VEaGW8RaTlzQ+5iD8N4ksN6VQ8JWbjZqPW4Q jDYA== 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=hmABi22q85Co2MEcMOXWeo2FUPNIq8TRNz7fj/UcLdw=; fh=Y4P+OZWkgF9lbfChzaJ97Vq23HiI4LLUSKodlubHYAo=; b=dXcA4edSoAMoOP1uZsViNk9Bqx5PJhL5z0EDC8sd7RsDTWLxMKc+TRPNgj9EmTmDXE V7Hof9Dkps7HhMwtE4NnyhPuM5RC0KUcn+hsWnjEkKGhPKZ5+QQNpwwBbfp+dm4XJ7gW ecc2U54WNcUu8bEfckhShjW6a4xgbjOzVYG/uv744uVKUDfIE6jbUI252S69Ev9/RDw5 8LBn493wpvGb0lzX7GjaudmiYGuF5xCfdRDyMxPa/dYDz/Cs+bxJYgf0cfHJdCkH/ptf 789QNpQtTBSwYy3eEywTN26wZ7hFkVhHFUxXdwkZBGOM3QN1X1uKvxeyw6xcTQrfGt6r /HJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eZC0VIPY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49779-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49779-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX3mO4pvPMJf51QVHudo3hLe7KgevqW5FXX9XBQO7Dm1kaDYYwuIAskOU2wEa7F9LGm65R28Ux4wtZMcDaLp3u400MI3A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ix3-20020a170902f80300b001d9586d5d78si1570708plb.233.2024.02.02.04.02.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 04:02:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49779-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eZC0VIPY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49779-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49779-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 71E06295EE4 for ; Fri, 2 Feb 2024 11:44:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A84C145B39; Fri, 2 Feb 2024 11:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eZC0VIPY" 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 A6461145B31; Fri, 2 Feb 2024 11:40:30 +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=1706874030; cv=none; b=uBezmYQnZO77RR3lCMa//KeJ4BsAaNEP1h47s+BUTwI3siTAsYjcWnBuxYq9CmMkNdmqYofkQiJe67mYFX9XyWUI8O/h/t771KSE9Fy/3ZXF+CjqVM1JGXo3uzHGoTgDatFGoJjXWarDnQgAYD7f+jJ9RGCDBUuE6S9aYSsLFd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706874030; c=relaxed/simple; bh=Jxc4BXAT6dxBPjnLFX0FeEQI0zrczQYYN04opb4NwR8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=brHJ6fykaoHM2pcv3j9NSRBxRtv2kknwlQ2cdGFLC0jjc0N2x3qr1qMjd7rYkFveXB92kFgqBhPA3c3WB6VBKI1jfb80VhQvyE6+In7XaF4Ad3TX+NvqctsN8YSaBTI2MdjXx19iyRC0kHrQqdiH8x1lJkBPVEagdWnylw6Gj00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eZC0VIPY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EDDEC43390; Fri, 2 Feb 2024 11:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706874030; bh=Jxc4BXAT6dxBPjnLFX0FeEQI0zrczQYYN04opb4NwR8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eZC0VIPYmTttoPG1KCdP4MgZADpjHYBHdO1WmQLiDiUKpA0zC4WHTtfgjebCDwvKQ xikGyFVOqC7uU5JhR1Y49wTfWSlfOcIgAUJtycROLcm16vcxj1+lpzxegRkmmiK3DX PiKclq9lcZSox/ugQAVpb8AOkcmEIGAqfYofh2TCCJ2KAXvCePgHunx4SvK3VhH6xH wawNV0gILpWY+UqGlBvdstd+2csVmiyNCM0YIzp43v47Jq8M/zGb74ei/EYu2LZNUS sBP8G9oN82AkS4nwrvb/zGVrmWcpRL3I7ZUXfuIOv4jI5/ta2Na0CfUsXjejyLYTKi /qO6ZlZu2VBdQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 Feb 2024 12:40:11 +0100 Subject: [PATCH net-next 5/5] mptcp: annotate lockless accesses around read-mostly 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-5-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=2205; i=matttbe@kernel.org; h=from:subject:message-id; bh=mcjDNT7BXUOg/gwV+eNe8UHcg0uqImaUFo1VPMNJ1B8=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlvNSff8n+XmNCRtXgslij21RTQ7ZYYjUF0CJma R3m/ECc3fmJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZbzUnwAKCRD2t4JPQmmg c1LmEADl/BohaAL8uYm11SJ5Smbiq5+ZyWk01aKz/XPWg7ewbVlsU/R/RBjdM/O+rR1SbjbH6rG BrMYDgz4uiVDoh3h5B1ZEBm8g/EEkNzMc39hlXM4foIrHMyzi/0cPK5rElMzEV21Quq5r75c1RF nKLWmxprNunbJpLP0B30NwHEqXbYkatUJlHXRhpOEt4NZtcdvo60lMr1sMvrV7V+J4UsK61rMEH +TprDzAk+dcVmQUFUWQDpvsiX6Skm9LsDlsb2rXgFaAkB+gzlygsJdJnVydi70VMQ6SkSq56bgj m5R+sTKA22TuUvkDD+ycEscoPCUU0+qtwfdheP1ckZuD+6GZsHo3P2LbUbN+HSN50w13Va9D9QJ mb2SFl9x45Ep0FMmhohUaO49TQH4fnkdyVWTr5noJnMSKXqve1tWxT59lezdeir583uDhQFmBjL PW/z1wVxk0TbpGEDTRMoSOn6AkFPZ1a6ib6lRiisQl/MgeK4mVA04OUuH47RK2+Kf9DJkApPvCF gf5BCWV4npKtKkiM2hSv2eT/xCcAK7iaW5uEx9gL4daulhummlWTUqKnvTXP2PJPHgkK9UwIzLm zTa2yjXfu+JicdMuy9fLpTxzIhS0VFItjUmwwev6s3cD9a/3M+rfr5WvigXCVC4/4yCy7E8xDBx qYDLFPju75tNCUA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789788517653705545 X-GMAIL-MSGID: 1789788517653705545 From: Paolo Abeni The following MPTCP socket fields: - can_ack - fully_established - rcv_data_fin - snd_data_fin_enable - rcv_fastclose - use_64bit_ack are accessed without any lock, add the appropriate annotation. The schema is safe as each field can change its value at most once in the whole mptcp socket life cycle. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 14 +++++++------- net/mptcp/sockopt.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 4478ddd3b5fa..ad39f54b3a81 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3149,16 +3149,16 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->cb_flags = 0; msk->push_pending = 0; msk->recovery = false; - msk->can_ack = false; - msk->fully_established = false; - msk->rcv_data_fin = false; - msk->snd_data_fin_enable = false; - msk->rcv_fastclose = false; - msk->use_64bit_ack = false; - msk->bytes_consumed = 0; + WRITE_ONCE(msk->can_ack, false); + WRITE_ONCE(msk->fully_established, false); + WRITE_ONCE(msk->rcv_data_fin, false); + WRITE_ONCE(msk->snd_data_fin_enable, false); + WRITE_ONCE(msk->rcv_fastclose, false); + WRITE_ONCE(msk->use_64bit_ack, false); WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk))); mptcp_pm_data_reset(msk); mptcp_ca_reset(sk); + msk->bytes_consumed = 0; msk->bytes_acked = 0; msk->bytes_received = 0; msk->bytes_sent = 0; diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index c40f1428e602..da37e4541a5d 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -942,7 +942,7 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info) mptcp_data_unlock(sk); slow = lock_sock_fast(sk); - info->mptcpi_csum_enabled = msk->csum_enabled; + info->mptcpi_csum_enabled = READ_ONCE(msk->csum_enabled); info->mptcpi_token = msk->token; info->mptcpi_write_seq = msk->write_seq; info->mptcpi_retransmits = inet_csk(sk)->icsk_retransmits;