From patchwork Fri Mar 8 11:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13586736 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15F2A5646D for ; Fri, 8 Mar 2024 11:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709897116; cv=none; b=gg0tAMty0GfaztCvKGocxlBWlLf7cgxYD+2jphxCGog9MwWjwXAe8ktuEm91zeaviMZBgzF59NcoNFP7gYrXceF86/MQBBnUVN9CdlfRtChdldNFYwM+2VI+D+fCw3B1IJvNZUOiVGTlMr+uif01AXan/tKwC6lHKkuRs2CiezY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709897116; c=relaxed/simple; bh=XZ60jz/4L+dtCcaLrNLOEHxEb91G13YdPFdP6fZhVDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kRyC6UjqdS+fQ5J088w5pd+mMGLw1Ft8Qd6s3uQ5s/MIOtuOY1l2f+B5Hv43O1ZfWOvXq7UHVzBQe0Vh3eju01of2MRvivgVC87I5RFhehBhnowEp1mm79xTpNKoTqZiVZAj7DV1mgkMxS2wh8ZMx3JKl9kDeNXak8KIUHakXIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LZIB/137; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LZIB/137" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dd611d5645so9436305ad.1 for ; Fri, 08 Mar 2024 03:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709897114; x=1710501914; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FOV6rkeK+dAF2umQi90xQLCfmYrig/9c5Ifw/L4zFXA=; b=LZIB/137cfGnfLO2X6iOCNEP8hJtPpQAxxgv+OE6k1j5ioeKRcMh+H09aZQgx6wwdl Aw8g5yk9Yrg/tHdEf5cR5d5qz2Yev4+Qho9QRSGvGkLdVXD0UdpO4jnIXQYpWVRLgvK5 NblYj1r0uLANassqNMqfbNfyyKUxI7ZAARPcWO0gRK9PmE61Ti9oGXKD98dg0HW7+PNF 9Ket7ndywA/vvPocf/j0IgvxVtN96ZGEYubQZO42fxeQRsiWba3lloa1LEEqwqiy5VoT RWeR6phHusLZUED9OokbFCE7AGtrJg/d+UeUOwT6GpU/9cE+GCrv5TE0upMtW+Ra1piK GCQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709897114; x=1710501914; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FOV6rkeK+dAF2umQi90xQLCfmYrig/9c5Ifw/L4zFXA=; b=dhK8PsS807sQnoQGdAt8z+nJX8Lr29etgqG5bgcczcEaBTqJ7398Neqsx9HBpzdFpj a2x1U0ssOnOr4y0OPogZ16CBtFnn2Q7OBtAlA/b1hQhZ0VliA+HSs665aJGZLN1k5aUf VSBWrvd6VHdR/qAse5QQ/72rZzLoC60KXanh0DBDjz9AoJqSbt3m65IHfVaSfwhIGoRC 3QedJkeX94R5gXA0LkgnlJOiz9DgheMIVO8wakvo/gTeoZ0tBzAoJMqF0r+C+4V3+mBZ ZKAPMvww6Edzf+mog1ejStsV4vE3KQnqB5p7oyVYv387a5vfabC+VRnW497cePDwILhn 5KUQ== X-Forwarded-Encrypted: i=1; AJvYcCWE+a9W8LP+v2R8isLimvUF+CHlDOebteLeD61qMr/0GPQctU4oP2iYo80qQjdvFp3/FWrCNaBeceDHi8HcVHVA92hlxcUL X-Gm-Message-State: AOJu0YxIL5YXuTBsppMyZcxqlOWbpQY36DOFFjUiEJkvV23zLVcf7ah8 qTjM7SjBndz40BPlvERyp1C3OR4uE+gmsZzaSRkp8JTexpjW58Oc X-Google-Smtp-Source: AGHT+IG7sno4VUVtN1IfNefGmWd6UIeSez2uZObIv68bmv/gFoj2UfKeoZdWMoXWurBSXW4afI7lvw== X-Received: by 2002:a17:902:fa90:b0:1dc:c161:bce6 with SMTP id lc16-20020a170902fa9000b001dcc161bce6mr4888621plb.15.1709897114213; Fri, 08 Mar 2024 03:25:14 -0800 (PST) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id q7-20020a17090311c700b001db608b54a9sm16049806plh.23.2024.03.08.03.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 03:25:13 -0800 (PST) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next 1/2] mptcp: annotate a data-race around sysctl_tcp_wmem[0] Date: Fri, 8 Mar 2024 19:25:03 +0800 Message-Id: <20240308112504.29099-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240308112504.29099-1-kerneljasonxing@gmail.com> References: <20240308112504.29099-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing It's possible that writer and the reader can manipulate the same sysctl knob concurrently. Using READ_ONCE() to prevent reading an old value. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet Reviewed-by: Mat Martineau --- net/mptcp/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f16edef6026a..a10ebf3ee10a 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -850,7 +850,7 @@ static inline void __mptcp_sync_sndbuf(struct sock *sk) if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) return; - new_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[0]; + new_sndbuf = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]); mptcp_for_each_subflow(mptcp_sk(sk), subflow) { ssk_sndbuf = READ_ONCE(mptcp_subflow_tcp_sock(subflow)->sk_sndbuf); From patchwork Fri Mar 8 11:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13586737 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3144156743 for ; Fri, 8 Mar 2024 11:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709897119; cv=none; b=h4uk+hUoCpfHgTWGz6PTbak6XVn6qyuJIqFA007pHPoD2gCkldj//H44mR+JjF9x4uPBL81sZv7DYMpxIhgWNs/r08r05wLyoSfP/Ny/5eD97IeVfXrwH7Ltf/QaV6vsLJEdXM5C0xt1/3psdywET02nwOT8T+FIfIJ7xL80wKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709897119; c=relaxed/simple; bh=Luvsy+WOnkG5qwVTfDfExXvIyB7rY3PNoN5HeFz1GrA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FCq+OpDJ1UM17rr7aItJtNeVCkOsENX8hM7JS480VE0zv3HFh4hhkl8G9J4Th+rGjH1/uLPxhGWrWxy4LaMVYt0Uu3BzNmHxbJfnqX0lpSY4yUQMGo1w279xIXMLkWHwh46POdaAkx9envVBGN76a6CwuFDtYuTt5SZ+rUEa7x8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HS/hzBYo; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HS/hzBYo" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1dcc7f4717fso5900435ad.0 for ; Fri, 08 Mar 2024 03:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709897117; x=1710501917; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cXvQs0Wk+UfdeZ/dr1xV6h7P5P/4xSbgdWXCtbE0DXA=; b=HS/hzBYohxRfL4pMdHmDEytz1kvnpeIY8a1b3ageZoSOhMxaRM9XhRtpdYoXyaUeh2 ueq6CDlEelm7ZBzMaiMEKjvHI7qOSDOnLe2F7o6c26E3NJlrqVqBKZfiBN0kk07AYxsL Pfw0cpzKTvzhiYlh6Szyv+wcAJkbQMfsW3/CIn8oXWlATBz10aPTTdw1zbWLNKskGbCS u7kLY+x6E5YpTpHA+w28+vLRjuu6zT4l17St/Myk6rzDbDJNtZ234+hSBzvQyRcIZmqF +Dr4WG5dHcwo3+/RUVOUUzRuIMd+73vRJTm2O4JF0d+XdkY9o8iTJTLt4rGkO96Z8vU4 tq/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709897117; x=1710501917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cXvQs0Wk+UfdeZ/dr1xV6h7P5P/4xSbgdWXCtbE0DXA=; b=qZLuiA6Z4CUQqgF4EfrTj8b3u9ORg1EJ2mSvsJIDQnYENfWSiR+Tnp+Sw6eSwt39M/ A4j9BgIgXXxVRUwfseY0bo0lFn0zJEio+FJaAH4J139jDaKaQ3AU3kn9gXJ+ouI8O5QK IsWayZdfAsqlTlBiUZ273+UTzmRUfBufhTV+/6kTOLa0h3q7e+Xy8sOyMoyygKyjezK4 gYebI5XM+Npn/eivmrlS3T4Ed2hpvw0La3WZ8MJrz0XQMADUrlbUmCMqnSVqO1QNP69D mN86fO9tekNHg7Fk4MTBIUU5fHyBL2CxKF24eLdfb960SofvfZVoo7GzQ6vn3+wnTUna 1sSQ== X-Forwarded-Encrypted: i=1; AJvYcCUuWbRYS/ItTR0DVXuAjWTWW6LeOvNs5Ed2A+9a3zd1DaPU3IFxmTvcnCr/SGJ0p9ld4NlNVlWcM6wNOizHb9NgWpDSS2aL X-Gm-Message-State: AOJu0YzsTAExhLQWsEGvZMsHaHHwNirAnUJqMYCFYBeiK7QohQo4Xofb lSBQT+cAvYwThGCORVEGSoPmAt/p5GvZCmU3Fm3aecvqLDyeKjOX X-Google-Smtp-Source: AGHT+IFFQ/0l4f/zaDEvYCTncyZ1WnhaATXM7WfOwj8dMyzIDUDLSi8bXOQb1X+6McLld5Oh6BOAEA== X-Received: by 2002:a17:902:ce09:b0:1dd:6e47:862e with SMTP id k9-20020a170902ce0900b001dd6e47862emr614753plg.63.1709897117518; Fri, 08 Mar 2024 03:25:17 -0800 (PST) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id q7-20020a17090311c700b001db608b54a9sm16049806plh.23.2024.03.08.03.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 03:25:17 -0800 (PST) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next 2/2] tcp: annotate a data-race around sysctl_tcp_wmem[0] Date: Fri, 8 Mar 2024 19:25:04 +0800 Message-Id: <20240308112504.29099-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240308112504.29099-1-kerneljasonxing@gmail.com> References: <20240308112504.29099-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing When reading wmem[0], it could be changed concurrently without READ_ONCE() protection. So add one annotation here. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index c5b83875411a..e3904c006e63 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -975,7 +975,7 @@ int tcp_wmem_schedule(struct sock *sk, int copy) * Use whatever is left in sk->sk_forward_alloc and tcp_wmem[0] * to guarantee some progress. */ - left = sock_net(sk)->ipv4.sysctl_tcp_wmem[0] - sk->sk_wmem_queued; + left = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]) - sk->sk_wmem_queued; if (left > 0) sk_forced_mem_schedule(sk, min(left, copy)); return min(copy, sk->sk_forward_alloc);