From patchwork Thu Apr 17 23:00:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882068 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2047.outbound.protection.outlook.com [40.107.21.47]) (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 34FF91624DC; Thu, 17 Apr 2025 23:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930850; cv=fail; b=cfJH+mR9rfVwgKzAOk8hogTesVeJw9iwixXzjOFXnz0R0T/D1wyzV3GnvTi/eHBObIdZZ/w+QStKjbSDf4XvjvyTcTId2onVaU9r7ZKe7NnUAK3NFZwhbDrqOhRyNWXIJmyPnZcwtBZseS61/VCTbpo4cX07rO1HpLWkVItzjHE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930850; c=relaxed/simple; bh=PYyCXUuKVKRWlC5fYTcacULQXbuy70otEK62ZKgXQqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=W9gXl8IVzCgJ/TAKUY3QPYLNlygnl+GFJRG7NUD5tpsgusF+VNM/FUC6cB0e+XnAWqZ2rYfGgD/l31o02IR0/Zvz5Kh8lB0GvToxFUCCdHyT/gDwa4KIPiQrkYwCsCA9kPuduGgakXyddmhM3wDR1+wBdYZ6iqS+FRIv1tO91CA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=guIP0KQ4; arc=fail smtp.client-ip=40.107.21.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="guIP0KQ4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jmzr1JLlyp45qXfLTqhF4YaWBfsWeA5/6iDeccaOaFfAospt223Ajg4PstMN+QAr0XLom2C2V6CWJh3wf4fj1n3VUuswcaObdWJGDipFTl5obhNz4eUMctzyqXcZOneyzrRpvFwyMVzg9VG13AP1X2+1NdHfZuGEIWByDAyyyfLQgVFVgOVHUZueMwO8CgOHTggM1ixMr3Pa3GqU4JWN543dQbYGUIeCBR3ayRuo36hToQrrMd4rb7NXySzCpbloQtGDNu/djoxGHdhbkTkQGuEkPok2+VPs3rszS2UBQqwQgCBpFq0kmI4JQwW07u6O7QVvX1kdO0Bixzbm2laDew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jbp9mDaGjGTen8BidXf0OT4su1XnPFAKk8A8EBFXEZQ=; b=QhZiU9Omm/HPKshIDN1oEaCJOOncBlOFJ8RnBHjd9WOqBkZz5YzZU/q+Yz1q8DBuMWQgHW9E/cf/xEv292eJ8jWSc2wkBZblNpWEAN0SirdcPACuSLlXo6DjefGbCdjKUseKGMhKoaXVhDatL9gp20HLJlqCNgn0mPnBw8NtH37H1Vx7JQjMQMpGLfIDJei9re2Do+o24lf5BpHh+TO/15TOS3mowBYSd8fYENiw+zlGEyOv5bdYnBCcc6lN76TbxcdQh5bxNbgvpkrvrd8YkxGI5dCaLMND0fadEfD24cNc+JlrdGtCAqZPO0dl3qpA8Agg7Bt54iIBZ78pRa7aIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jbp9mDaGjGTen8BidXf0OT4su1XnPFAKk8A8EBFXEZQ=; b=guIP0KQ4TmzWf43rLjUJur35qyNKWU3WLwlB+eboed7M3u61nZqGX0RWxQquWfDCk84SrDAz9sONm3NdCgcxcquvlum5E3VY+4zD5ZP2LG0e9P3W4ztVQo5eLheT7vLLzXVGnFyPHJqrq09Hph6zpttCAYGo/uMYzalp80sgbh4Ed7PtJC7QUz7eIf1UGp8XTuYIrs/ah/Y9YNUTDSa2PhKMjk4LWZkPVK1uKWkvFE4ZqiWRq9kgqoMN/BhcLJN8W8to3fqG8ViVEXDvugu7rt3fMy2IZCqHqHCKy25m2QYTGhAm/hCf29G5f3ys5JmtMYWdguvTQiGzCIH4mt0wyg== Received: from AM6PR10CA0050.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::27) by DB9PR07MB8497.eurprd07.prod.outlook.com (2603:10a6:10:36e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.25; Thu, 17 Apr 2025 23:00:44 +0000 Received: from AMS0EPF0000019D.eurprd05.prod.outlook.com (2603:10a6:209:80:cafe::f9) by AM6PR10CA0050.outlook.office365.com (2603:10a6:209:80::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.18 via Frontend Transport; Thu, 17 Apr 2025 23:00:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by AMS0EPF0000019D.mail.protection.outlook.com (10.167.16.249) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:00:43 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id 0A58220827; Fri, 18 Apr 2025 02:00:42 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 01/15] tcp: reorganize SYN ECN code Date: Fri, 18 Apr 2025 01:00:15 +0200 Message-Id: <20250417230029.21905-2-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF0000019D:EE_|DB9PR07MB8497:EE_ X-MS-Office365-Filtering-Correlation-Id: acc7685d-b01b-41b2-e3d9-08dd7e03ae90 X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?1zUm6EtmLKyN3dInbQ4d3vmU3B65gKV?= =?utf-8?q?VIIOt3CkuFsXoEd7ranzqRlqd/EukkFfoc67q6MInZP2C+qYEOLO93qbRzIOtU9ZW?= =?utf-8?q?JSTRM1AoEhMaep9xB9U88dcOjR4d7vaW5izZGkuirXPwvdK6qOwJDFMO4zmlmMuja?= =?utf-8?q?5aTvaLOLNJSfqEKhHbqQg1/PCGOskfkTfxbbdj618W5HKj66JVPy1WO1bvCkrwS3m?= =?utf-8?q?kopAoOgiu+Wylwf4QDmm1Ao5D18N5d9lBrgH5h9+WT2Sx2vCtu8yKbz/iIpBSQSUK?= =?utf-8?q?Q5bmiZB7UQbpAtCz8snwkq37gZ7W2Hnzg9P8j/5DJI/XhaqNastnLAK2D2h5+CnGG?= =?utf-8?q?0h/+WbpOTnzU7ip9HkUfVysf3/sLYfdwMS5i/8OcE31QygRSr3m3OJgpPvAABSggg?= =?utf-8?q?XwrP4oLdbs0AssJ6Nv42bgEUcSk9e4UOMqRzxF4RzNALMqCOIQOVT07i5uluZ1e90?= =?utf-8?q?B4qS7nN+pFk2Q7T29e1pOvK9OTDBNx2PI5W3eaLlGCHG6cR2WDkoTmnwL6KNpSHiZ?= =?utf-8?q?R0T2OOOMlpEffNfTAHao0PnEzB/yIgy1ApQZT9R7ACSa1mWR8No15osHqgygTNixw?= =?utf-8?q?Gqfbl4mJqqY8av++y8IFkWQQXZb9iMDRaP6KsKvshTJtOkPuT6fVp96tMxf/5Ss9/?= =?utf-8?q?tGKYMPUXS0NUfjuUdGHyRg16Ef4jL29A4n/mOMoCkTUd5DojYmQmICkO9CwWQDuJw?= =?utf-8?q?vZ9obEmFbOD7UJkUfkqSOHlIYYktOuIRXAWIw5U+6JlNw5zRXJj8x69LuNxKABdMc?= =?utf-8?q?FmO7qBlOJGw/92Ms25kGCxYb5tN9F5pqW5kwK66iySET3VcWJjUR3rzMo41Y8hvKF?= =?utf-8?q?x8AAo7NmhHjhyXMaRKlGHJp4UmZxTp38WL4l4D7iSStT3GQAg/B4qYBOM6U72C27k?= =?utf-8?q?itEi6pcNQB4WJFhz6kK0RMy9KUgifLMvdVAXzGLC2VzV7DLegWN/4fzsfTRjP9Ljc?= =?utf-8?q?Zx6F+xhcNY/WaMRo0iKVyoqpSKRgO8tJD17lg3UwBO/dz98+HBrLaaMhTSLu7K07I?= =?utf-8?q?qiizun3SM0B+6yufB681/99gYsdfTjPJu5SwE/htTlTbEqwz2o24lmXXRN0xDifqP?= =?utf-8?q?P52bo454aRsMzLXLHjZtbpg4dmlLfm3XUzU3l1jhGWkA5xZAlCrt2MHuIrGdv3zzS?= =?utf-8?q?tS2z3C5IhRl9supl5bigY+KpC6M35zBuxKAI0VZpylwmOds7IWig7sMLAsEBKYpmt?= =?utf-8?q?nbYcmcVwbvZLkJ5rKkLG/4zwNu/JMrLZcvxMxHYBvrsaWMUmzaeYDPq8WKoc1mWMV?= =?utf-8?q?YZbeMX0dz4wCE3P42ZR3t93lyWgK5AlY5L9sjanJx4qCkZfTqal8jt5n3ZJFcm6tx?= =?utf-8?q?KWPmRSnHSzMJlcf+qmIA88Fp1K8P3Qeo1ig7g+Cr6y71DKIeV/PNmsTYq4H72f33P?= =?utf-8?q?edzHer92qhS0uarLpQfavTrbQos5erhxXRIeMk3CpbMpnRsKDLEWIh4SBX5ELnwzn?= =?utf-8?q?z7qvgCPuVQuVa3npA8cSGgsn11wWksiw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:00:43.4742 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: acc7685d-b01b-41b2-e3d9-08dd7e03ae90 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF0000019D.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB8497 From: Ilpo Järvinen Prepare for AccECN that needs to have access here on IP ECN field value which is only available after INET_ECN_xmit(). No functional changes. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang Reviewed-by: Eric Dumazet --- net/ipv4/tcp_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 13295a59d22e..9a1ab946ff62 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -350,10 +350,11 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) tp->ecn_flags = 0; if (use_ecn) { - TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR; - tcp_ecn_mode_set(tp, TCP_ECN_MODE_RFC3168); if (tcp_ca_needs_ecn(sk) || bpf_needs_ecn) INET_ECN_xmit(sk); + + TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR; + tcp_ecn_mode_set(tp, TCP_ECN_MODE_RFC3168); } } From patchwork Thu Apr 17 23:00:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882067 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2070.outbound.protection.outlook.com [40.107.103.70]) (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 644C221ABCC; Thu, 17 Apr 2025 23:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930859; cv=fail; b=GSNaf4LXnTncYX0CrO9edD4pgzVdpF4pm+tYU7BA+lGgjywuljb7VMJSBJrq21QuUb5+XYYrb/gOPTh8ixbWoCa/5NJJkp5StCdfau8dbqAp5F9pv3ZejOdfwLW0Uaavylvb/5bhgq1uiATHtRwvGHxzrrD6goFsMLSKKqRkTCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930859; c=relaxed/simple; bh=U6q/bXRBi17sP6YLpcdxzeTbpNHFCeio/M7MPrlQrZ4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TuWAuLBmvm4MjYBd2g6LZYQZrY79CBSNNNyCePcS0Gy+Uihg2C6dSJu0wsHu9br9Ns9O+2lAoUGNGAO51pFTYw8CdqOjHZ7odp/Z4Nd2nOr5CFrUXvaKer8UU4V5gYFFaPGJKeJDCtcLzh6FvQEk3gjpFfj+SVekyF/z4zugHEY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=YtSO4PaC; arc=fail smtp.client-ip=40.107.103.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="YtSO4PaC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RVvFcv+Wb4NoZIHFF6n682pLymrh+nuwX8JWoBrgp4v4PFo0AlBOB2YLuH/ezNldNAUpkA/tCTS0nB5RdKaD1qhs2Qo/eyDMKF6VIU1L0zAIVDONCrBHI/F3vgbYd9TFFGTvULOhXPnBa/eNGbDpu8xWra/65I9UM9+z5VWWKiSeUKLGvv2sf1tirnD7oWJIgafO6notvJ6WrLmEtTo8JB9dmZfhZC1layKqnqy8lQqMyVj8/nOtstJxiWmcks7bKtXQ0KSqCBGfdDLlBJxF1Ct1O/p4FvB2qIYTCSdej6E/KkWvdQl7EEhkt/IsvS1dS9AwB+18QGuZlmnYxM2InQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EO0JnilW42J6qJIyNXcH3joHs9jMP2hYH+EBwh+DOUk=; b=K3WJQPKDfi/dW4evJMq/GC4Nigvj7hkyLatQaorx8U2yxPJhsF+/uWyiAlHS1izQLJD7F+TefLciCASAg5NBe4u9lXjlvW/EECQUwtvSRriXXwsPbVScGWY95UvU6qOolP9t8fIQ7XqeFaU1w2YCKYyWMUQWbXkOFJH6XcCqmYgRn7k+AwkbB+rMppcKTAv5o3/d9L0RLu0yyLZIOmtNP8bHdwtFzhHCeaYHueEjGUc6FXtqJn+PEi+qGFCo7Drd1/fb7+cvZWBegT26IMhDSe330p3k76Lp93T09wNSnO/3gooySX6hRSFIm5aSkjDxYEAxahogZ1U0X0+pRXboKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EO0JnilW42J6qJIyNXcH3joHs9jMP2hYH+EBwh+DOUk=; b=YtSO4PaCUB70C7umjbtEc0cY0iyl7QDJYFPTpOJxArajyYeRUuxa9XRgVbBrFi0ZEXRDI1AHmOu9zqgXRrUbXAvHDW101IjVeZSdfFXdwl3HlEftEJ03eFAORGyJzcUVJqM0yMATrwvneAHYnoEDKPX6HRy0f+pRSpo91A/TPq+E4wBJSLEqHDrLyfZ+no/xX7v3543KVsf9/idJPuPimPSFWkqY55T3mArTNYICW3wKJ0sIsdhFcU3UAZWGmQ7EOsE2rBoCwu0xE94e4UVlVfZ9tCwssXmwWRvcOeabSSoTAMhcALBx/J9bdYANDCWWG2q61ZcB2CiXbvvKh7QWhw== Received: from PAZP264CA0017.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:21::22) by PAXPR07MB8495.eurprd07.prod.outlook.com (2603:10a6:102:2b6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.36; Thu, 17 Apr 2025 23:00:50 +0000 Received: from AMS0EPF000001A3.eurprd05.prod.outlook.com (2603:10a6:102:21:cafe::2d) by PAZP264CA0017.outlook.office365.com (2603:10a6:102:21::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.22 via Frontend Transport; Thu, 17 Apr 2025 23:00:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by AMS0EPF000001A3.mail.protection.outlook.com (10.167.16.228) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:00:50 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id A10FE20868; Fri, 18 Apr 2025 02:00:48 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Olivier Tilmans , Chia-Yu Chang Subject: [PATCH v4 net-next 03/15] tcp: AccECN core Date: Fri, 18 Apr 2025 01:00:17 +0200 Message-Id: <20250417230029.21905-4-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A3:EE_|PAXPR07MB8495:EE_ X-MS-Office365-Filtering-Correlation-Id: 75ed038a-b778-46d4-702c-08dd7e03b288 X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|7416014|30052699003|1800799024|82310400026|13003099007|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ndMHZ5LK8UNac0lEjI1e29x1+3QgU4e?= =?utf-8?q?3sSv5Ye2lwZlS6aLgZmbPWnTZFzXHGNbwwdUuTYBmMnd9sWqiw4y2HBlK6fmbZSdD?= =?utf-8?q?xGW+DZmZcBLHVtDV9+vJWOTytx+27mh3S6Slz19rsqXrNvHWvjSeJ37WnYtHoaFfb?= =?utf-8?q?6eZwNZC2dzPjWxps69dbdHS7xQzyiAFyBfJEwGdYF45NdCgBnz3tGoV8Ht/oYCZb6?= =?utf-8?q?VqQHO8tMaqtbJNiT7AuXikPVU1zrN0R1r5hazVOGSax0jw0zIWfELRgiI2M5MTCjs?= =?utf-8?q?WZJsp4bCF2rQYlcYOdRJ5SWzXtQPSTE92bTZ7Vk8TLgO8Jz0VcLz0Bz27/uYNDH8t?= =?utf-8?q?z/c3mS6zcefgQplUOnPYBf1AQ7Sy1dNCiMDyh2y2h0HaxjfxEiMBK279CHYAy6xzq?= =?utf-8?q?9EEHbH2prhR2wBRyENpQed8k2AHKvA4mMyAayGUcMN7mZcZ6/Mei4LcChgUIsYgif?= =?utf-8?q?wKkPJ2HZLjJqLH9mEAF346FHfcpj3DRfOljtGSNBjkr7UIyTjR7z36KOESDHwNnbu?= =?utf-8?q?oJQkm2lVh0bXMeLi2wTiwCDj3+w/0foFZelbMQ4Cl6OgRAv4WE3kcFuOkeycuCRQo?= =?utf-8?q?ca5yUl87DB6EbyQneyCfqFBrL4zHufjSjQFxGRF8mjgmGbIU7xTbV99rdxyG/2FwL?= =?utf-8?q?MnaM76uxN/gAS6+v8GIg2f50psK70A2FBVgScFNAW5ejwc08Bj55gMUtCBoZAVrB5?= =?utf-8?q?T2I2TM7dQloU7vsZNxvF4jtHL2t9s8tAgKVGxr4I9MhGzvEGLItpDIibZjXaJnBXJ?= =?utf-8?q?wzKdXY98u0SGncGMp/8thdeIBHPLe3MKAPHOCzqEBXxfcIDu9FOXlP4YcPIlt8aTn?= =?utf-8?q?MMjjZbaZMfVnZPsVwdHidg8xtDFJVM+MZRweyV+j+Bk4nrEBr0T0uCnwhXD7ff78g?= =?utf-8?q?Q4WquehiOfCYk5HztM0VNXgc6BafJ3GjnyOZTL2EWKidGTlvQzPeatLWnT/SNon9Z?= =?utf-8?q?WsbGijOo1zQHpjssyckPvy5ry++QbnyOYTbiATwu35ZZSTULucswbD3TafEW01ty1?= =?utf-8?q?7NGVtLxrqP+zLstTFVUyZwgDsX4n2ZP+0SsgX4iH2FW0GH3NdIBhsmtX1aL1jjuWK?= =?utf-8?q?1PzwQ4EuFh7MJsKSUp9pobeftCHuIf7lL+4zSqMpWhy26hg3pb43dkMd7xN4Noqsf?= =?utf-8?q?fsjwl0NQHxAcG9exFDlvaVH32NcrGnEOG+LEBdZ8PWRsdfgRU1ltwp3WsRL8zyrYw?= =?utf-8?q?3mjw9+poFbmNy/gkIm2PVZDjqI3VTLcmEB0By4l0eqUxLljuSOmalFgkNCkZjRqfH?= =?utf-8?q?a56IFsCjvp7yTEnH7a2CwudIsdLeRVk+XCoDvbZN/ZEJ5UKrpKTX0a6VaryHJ8RxZ?= =?utf-8?q?YIseQqm+Nw5viXTTUky6GNdHYgz03idbgSYGd3tKVPkCeeEV/aUqShEfNeMxAhIZd?= =?utf-8?q?jOFwWm1QupdklGwuy4qeRjvKtd7s4PNBsOvXfu0M7yhr5wGdNDatOGe+6JUQSplwV?= =?utf-8?q?Ej3svp6et83jcrHUO4XRrHTP4f9VenyQ=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(36860700013)(7416014)(30052699003)(1800799024)(82310400026)(13003099007)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:00:50.0984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75ed038a-b778-46d4-702c-08dd7e03b288 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001A3.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB8495 From: Ilpo Järvinen This change implements Accurate ECN without negotiation and AccECN Option (that will be added by later changes). Based on AccECN specifications: https://tools.ietf.org/id/draft-ietf-tcpm-accurate-ecn-28.txt Accurate ECN allows feeding back the number of CE (congestion experienced) marks accurately to the sender in contrast to RFC3168 ECN that can only signal one marks-seen-yes/no per RTT. Congestion control algorithms can take advantage of the accurate ECN information to fine-tune their congestion response to avoid drastic rate reduction when only mild congestion is encountered. With Accurate ECN, tp->received_ce (r.cep in AccECN spec) keeps track of how many segments have arrived with a CE mark. Accurate ECN uses ACE field (ECE, CWR, AE) to communicate the value back to the sender which updates tp->delivered_ce (s.cep) based on the feedback. This signalling channel is lossy when ACE field overflow occurs. Conservative strategy is selected here to deal with the ACE overflow, however, some strategies using the AccECN option later in the overall patchset mitigate against false overflows detected. The ACE field values on the wire are offset by TCP_ACCECN_CEP_INIT_OFFSET. Delivered_ce/received_ce count the real CE marks rather than forcing all downstream users to adapt to the wire offset. Co-developed-by: Olivier Tilmans Signed-off-by: Olivier Tilmans Signed-off-by: Ilpo Järvinen Co-developed-by: Chia-Yu Chang Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 3 ++ include/net/tcp.h | 26 +++++++++ net/ipv4/tcp.c | 4 +- net/ipv4/tcp_input.c | 121 +++++++++++++++++++++++++++++++++++++----- net/ipv4/tcp_output.c | 21 +++++++- 5 files changed, 160 insertions(+), 15 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 1669d95bb0f9..e36018203bd0 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -298,6 +298,9 @@ struct tcp_sock { u32 snd_up; /* Urgent pointer */ u32 delivered; /* Total data packets delivered incl. rexmits */ u32 delivered_ce; /* Like the above but only ECE marked packets */ + u32 received_ce; /* Like the above but for rcvd CE marked pkts */ + u8 received_ce_pending:4, /* Not yet transmit cnt of received_ce */ + unused2:4; u32 app_limited; /* limited until "delivered" reaches this val */ u32 rcv_wnd; /* Current receiver window */ /* diff --git a/include/net/tcp.h b/include/net/tcp.h index 4dacd4a11669..cc28255deef7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -415,6 +415,11 @@ static inline void tcp_ecn_mode_set(struct tcp_sock *tp, u8 mode) tp->ecn_flags |= mode; } +static inline u8 tcp_accecn_ace(const struct tcphdr *th) +{ + return (th->ae << 2) | (th->cwr << 1) | th->ece; +} + enum tcp_tw_status { TCP_TW_SUCCESS = 0, TCP_TW_RST = 1, @@ -964,6 +969,20 @@ static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq) #define TCPHDR_ACE (TCPHDR_ECE | TCPHDR_CWR | TCPHDR_AE) #define TCPHDR_SYN_ECN (TCPHDR_SYN | TCPHDR_ECE | TCPHDR_CWR) +#define TCP_ACCECN_CEP_ACE_MASK 0x7 +#define TCP_ACCECN_ACE_MAX_DELTA 6 + +/* To avoid/detect middlebox interference, not all counters start at 0. + * See draft-ietf-tcpm-accurate-ecn for the latest values. + */ +#define TCP_ACCECN_CEP_INIT_OFFSET 5 + +static inline void tcp_accecn_init_counters(struct tcp_sock *tp) +{ + tp->received_ce = 0; + tp->received_ce_pending = 0; +} + /* State flags for sacked in struct tcp_skb_cb */ enum tcp_skb_cb_sacked_flags { TCPCB_SACKED_ACKED = (1 << 0), /* SKB ACK'd by a SACK block */ @@ -1773,11 +1792,18 @@ static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt, static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) { + u32 ace; + /* mptcp hooks are only on the slow path */ if (sk_is_mptcp((struct sock *)tp)) return; + ace = tcp_ecn_mode_accecn(tp) ? + ((tp->delivered_ce + TCP_ACCECN_CEP_INIT_OFFSET) & + TCP_ACCECN_CEP_ACE_MASK) : 0; + tp->pred_flags = htonl((tp->tcp_header_len << 26) | + (ace << 22) | ntohl(TCP_FLAG_ACK) | snd_wnd); } diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e0e96f8fd47c..372c58170f4c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3364,6 +3364,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->window_clamp = 0; tp->delivered = 0; tp->delivered_ce = 0; + tcp_accecn_init_counters(tp); if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release(sk); memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); @@ -5088,6 +5089,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, snd_up); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered_ce); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rx_opt); @@ -5095,7 +5097,7 @@ static void __init tcp_struct_check(void) /* 32bit arches with 8byte alignment on u64 fields might need padding * before tcp_clock_cache. */ - CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 92 + 4); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 97 + 7); /* RX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_received); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index a35018e2d0ba..8dbb625f5e8a 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -341,14 +341,17 @@ static bool tcp_in_quickack_mode(struct sock *sk) static void tcp_ecn_queue_cwr(struct tcp_sock *tp) { + /* Do not set CWR if in AccECN mode! */ if (tcp_ecn_mode_rfc3168(tp)) tp->ecn_flags |= TCP_ECN_QUEUE_CWR; } static void tcp_ecn_accept_cwr(struct sock *sk, const struct sk_buff *skb) { - if (tcp_hdr(skb)->cwr) { - tcp_sk(sk)->ecn_flags &= ~TCP_ECN_DEMAND_CWR; + struct tcp_sock *tp = tcp_sk(sk); + + if (tcp_ecn_mode_rfc3168(tp) && tcp_hdr(skb)->cwr) { + tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR; /* If the sender is telling us it has entered CWR, then its * cwnd may be very low (even just 1 packet), so we should ACK @@ -384,17 +387,16 @@ static void tcp_data_ecn_check(struct sock *sk, const struct sk_buff *skb) if (tcp_ca_needs_ecn(sk)) tcp_ca_event(sk, CA_EVENT_ECN_IS_CE); - if (!(tp->ecn_flags & TCP_ECN_DEMAND_CWR)) { + if (!(tp->ecn_flags & TCP_ECN_DEMAND_CWR) && + tcp_ecn_mode_rfc3168(tp)) { /* Better not delay acks, sender can have a very low cwnd */ tcp_enter_quickack_mode(sk, 2); tp->ecn_flags |= TCP_ECN_DEMAND_CWR; } - tp->ecn_flags |= TCP_ECN_SEEN; break; default: if (tcp_ca_needs_ecn(sk)) tcp_ca_event(sk, CA_EVENT_ECN_NO_CE); - tp->ecn_flags |= TCP_ECN_SEEN; break; } } @@ -428,10 +430,64 @@ static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered, bool ece_ack) { tp->delivered += delivered; - if (ece_ack) + if (tcp_ecn_mode_rfc3168(tp) && ece_ack) tcp_count_delivered_ce(tp, delivered); } +/* Returns the ECN CE delta */ +static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, + u32 delivered_pkts, int flag) +{ + const struct tcphdr *th = tcp_hdr(skb); + struct tcp_sock *tp = tcp_sk(sk); + u32 delta, safe_delta; + u32 corrected_ace; + + /* Reordered ACK or uncertain due to lack of data to send and ts */ + if (!(flag & (FLAG_FORWARD_PROGRESS | FLAG_TS_PROGRESS))) + return 0; + + if (!(flag & FLAG_SLOWPATH)) { + /* AccECN counter might overflow on large ACKs */ + if (delivered_pkts <= TCP_ACCECN_CEP_ACE_MASK) + return 0; + } + + /* ACE field is not available during handshake */ + if (flag & FLAG_SYN_ACKED) + return 0; + + if (tp->received_ce_pending >= TCP_ACCECN_ACE_MAX_DELTA) + inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW; + + corrected_ace = tcp_accecn_ace(th) - TCP_ACCECN_CEP_INIT_OFFSET; + delta = (corrected_ace - tp->delivered_ce) & TCP_ACCECN_CEP_ACE_MASK; + if (delivered_pkts <= TCP_ACCECN_CEP_ACE_MASK) + return delta; + + safe_delta = delivered_pkts - + ((delivered_pkts - delta) & TCP_ACCECN_CEP_ACE_MASK); + + return safe_delta; +} + +static u32 tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, + u32 delivered_pkts, int *flag) +{ + struct tcp_sock *tp = tcp_sk(sk); + u32 delta; + + delta = __tcp_accecn_process(sk, skb, delivered_pkts, *flag); + if (delta > 0) { + tcp_count_delivered_ce(tp, delta); + *flag |= FLAG_ECE; + /* Recalculate header predictor */ + if (tp->pred_flags) + tcp_fast_path_on(tp); + } + return delta; +} + /* Buffer size and advertised window tuning. * * 1. Tuning sk->sk_sndbuf, when connection enters established state. @@ -3919,7 +3975,8 @@ static void tcp_xmit_recovery(struct sock *sk, int rexmit) } /* Returns the number of packets newly acked or sacked by the current ACK */ -static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered, int flag) +static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered, + u32 ecn_count, int flag) { const struct net *net = sock_net(sk); struct tcp_sock *tp = tcp_sk(sk); @@ -3927,8 +3984,12 @@ static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered, int flag) delivered = tp->delivered - prior_delivered; NET_ADD_STATS(net, LINUX_MIB_TCPDELIVERED, delivered); - if (flag & FLAG_ECE) - NET_ADD_STATS(net, LINUX_MIB_TCPDELIVEREDCE, delivered); + + if (flag & FLAG_ECE) { + if (tcp_ecn_mode_rfc3168(tp)) + ecn_count = delivered; + NET_ADD_STATS(net, LINUX_MIB_TCPDELIVEREDCE, ecn_count); + } return delivered; } @@ -3949,6 +4010,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) u32 delivered = tp->delivered; u32 lost = tp->lost; int rexmit = REXMIT_NONE; /* Flag to (re)transmit to recover losses */ + u32 ecn_count = 0; /* Did we receive ECE/an AccECN ACE update? */ u32 prior_fack; sack_state.first_sackt = 0; @@ -4056,6 +4118,11 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) tcp_rack_update_reo_wnd(sk, &rs); + if (tcp_ecn_mode_accecn(tp)) + ecn_count = tcp_accecn_process(sk, skb, + tp->delivered - delivered, + &flag); + tcp_in_ack_event(sk, flag); if (tp->tlp_high_seq) @@ -4080,7 +4147,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP)) sk_dst_confirm(sk); - delivered = tcp_newly_delivered(sk, delivered, flag); + delivered = tcp_newly_delivered(sk, delivered, ecn_count, flag); + lost = tp->lost - lost; /* freshly marked lost */ rs.is_ack_delayed = !!(flag & FLAG_ACK_MAYBE_DELAYED); tcp_rate_gen(sk, delivered, lost, is_sack_reneg, sack_state.rate); @@ -4089,12 +4157,16 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) return 1; no_queue: + if (tcp_ecn_mode_accecn(tp)) + ecn_count = tcp_accecn_process(sk, skb, + tp->delivered - delivered, + &flag); tcp_in_ack_event(sk, flag); /* If data was DSACKed, see if we can undo a cwnd reduction. */ if (flag & FLAG_DSACKING_ACK) { tcp_fastretrans_alert(sk, prior_snd_una, num_dupack, &flag, &rexmit); - tcp_newly_delivered(sk, delivered, flag); + tcp_newly_delivered(sk, delivered, ecn_count, flag); } /* If this ack opens up a zero window, clear backoff. It was * being used to time the probes, and is probably far higher than @@ -4115,7 +4187,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) &sack_state); tcp_fastretrans_alert(sk, prior_snd_una, num_dupack, &flag, &rexmit); - tcp_newly_delivered(sk, delivered, flag); + tcp_newly_delivered(sk, delivered, ecn_count, flag); tcp_xmit_recovery(sk, rexmit); } @@ -5952,6 +6024,26 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t } } +/* Updates Accurate ECN received counters from the received IP ECN field */ +static void tcp_ecn_received_counters(struct sock *sk, + const struct sk_buff *skb) +{ + u8 ecnfield = TCP_SKB_CB(skb)->ip_dsfield & INET_ECN_MASK; + u8 is_ce = INET_ECN_is_ce(ecnfield); + struct tcp_sock *tp = tcp_sk(sk); + + if (!INET_ECN_is_not_ect(ecnfield)) { + u32 pcount = is_ce * max_t(u16, 1, skb_shinfo(skb)->gso_segs); + + tp->ecn_flags |= TCP_ECN_SEEN; + + /* ACE counter tracks *all* segments including pure ACKs */ + tp->received_ce += pcount; + tp->received_ce_pending = min(tp->received_ce_pending + pcount, + 0xfU); + } +} + /* Accept RST for rcv_nxt - 1 after a FIN. * When tcp connections are abruptly terminated from Mac OSX (via ^C), a * FIN is sent followed by a RST packet. The RST is sent with the same @@ -6214,6 +6306,8 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) flag |= __tcp_replace_ts_recent(tp, delta); + tcp_ecn_received_counters(sk, skb); + /* We know that such packets are checksummed * on entry. */ @@ -6258,6 +6352,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) /* Bulk data transfer: receiver */ tcp_cleanup_skb(skb); __skb_pull(skb, tcp_header_len); + tcp_ecn_received_counters(sk, skb); eaten = tcp_queue_rcv(sk, skb, &fragstolen); tcp_event_data_recv(sk, skb); @@ -6298,6 +6393,8 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) return; step5: + tcp_ecn_received_counters(sk, skb); + reason = tcp_ack(sk, skb, FLAG_SLOWPATH | FLAG_UPDATE_TS_RECENT); if ((int)reason < 0) { reason = -reason; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 9a1ab946ff62..9c978d12c7cf 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -374,6 +374,17 @@ tcp_ecn_make_synack(const struct request_sock *req, struct tcphdr *th) th->ece = 1; } +static void tcp_accecn_set_ace(struct tcphdr *th, struct tcp_sock *tp) +{ + u32 wire_ace; + + wire_ace = tp->received_ce + TCP_ACCECN_CEP_INIT_OFFSET; + th->ece = !!(wire_ace & 0x1); + th->cwr = !!(wire_ace & 0x2); + th->ae = !!(wire_ace & 0x4); + tp->received_ce_pending = 0; +} + /* Set up ECN state for a packet on a ESTABLISHED socket that is about to * be sent. */ @@ -382,11 +393,17 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb, { struct tcp_sock *tp = tcp_sk(sk); - if (tcp_ecn_mode_rfc3168(tp)) { + if (!tcp_ecn_mode_any(tp)) + return; + + INET_ECN_xmit(sk); + if (tcp_ecn_mode_accecn(tp)) { + tcp_accecn_set_ace(th, tp); + skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ACCECN; + } else { /* Not-retransmitted data segment: set ECT and inject CWR. */ if (skb->len != tcp_header_len && !before(TCP_SKB_CB(skb)->seq, tp->snd_nxt)) { - INET_ECN_xmit(sk); if (tp->ecn_flags & TCP_ECN_QUEUE_CWR) { tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR; th->cwr = 1; From patchwork Thu Apr 17 23:00:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882066 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2071.outbound.protection.outlook.com [40.107.20.71]) (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 EE7F82206B2; Thu, 17 Apr 2025 23:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930864; cv=fail; b=i3yG//78ywE7iqS3m4vPTetR6jIAmkBnV4ahjF+WdQ6qkR5g5YvRSDQVrZktBYqjobQN+ri06Vjl05uQlnTTNSeGc0cUV2e1ppBdPjylzkul9MmvLKxhX0+Vi/NFFqBh2/0aS+57c9dAT5HzVJkRtxphRbzGxfOOa0Kv5Aay8Ww= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930864; c=relaxed/simple; bh=g1x1wSE8mDsEEGPuXD/eGJRl+sR0RK7CBjRuw48/ZGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=cRHcQH3yAToZJMQ6SI5VmiyAjjfT1IZjvvxu9eljodPjgzv5oEznpTVY0i3uqqgGwdjk++3v3SN2SbxBwiCurtclgSN1GIuz5vpbKWnUu+4yVQuZiN0X/b3BP9XWnhbPUwbGIwl+gSt9wO56+phwkw/gsKGBcni2GKvvxz+ZQ58= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=PaMEA6k/; arc=fail smtp.client-ip=40.107.20.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="PaMEA6k/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Xx4DV5D3RJHdIz1S4nPO4roeYPNH1JhYS+lPsbuAGfk7xCg2u3yi5/PBHptrZCoxRmnc1BxBjMHCKVAU7wb7RvlE7ey72oS3VxbmbfKqBriFgVoMYf3OU9GhHT4NTU9knJDJ6wmwo+ul7ajLQqxJvRGH7A96bIgpb43IQ+qLg8QYuq0saTg2kD0waO4vDO4hdILP+//ac3Ok6/abA1wblBLMJSh4bge+hI63Isp2bdivbO1Bm8EQA2imi3AuafoFOeHMXDBg0+cf9cq+U+Ws31AqUiUYvYvgK0faUtLm8+7fLox4IsXRD8t7iAdifMxtvp2fsnsVirQju+Wfru/kkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QhuGs1hGnXUmt37E9qd1tbYti4EboLpVQ2TRoAXN87U=; b=k5Ry6c/ZnebpLXXW2tN1SFkKYtwezpAwalxr2DN446pepHLOHkn+0PmxlThY6VNpafHev3b2HcsEPSBi26mqAa4/i6YT0yg+BzwMQoocFqMslHLukhOWLi2BXxD/17SLmOdYiIIZa/skB8SVy74b235Fgg0uNQ4+/p5T5vMVnQTVsobJZnCxtI/L3WsfqYxr9d0Lzd8Ptgrr2QeNG1anTN4WWZ5TGn5lYTj81CPhFPmOb6DweoFWRkcA6VBEVpkDYeHCspzMhQJf/Jaq/aLrooDvEicfzLFsl9gtXRodkZWxCKb4y+mvq9SzOqqPdcA8dSRCAdgFlaMKRkGdD4EMjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QhuGs1hGnXUmt37E9qd1tbYti4EboLpVQ2TRoAXN87U=; b=PaMEA6k/5FKuuckucqmtXWOGpfNKK2SOt2/M4KsLmqoK/Py8sID5KW1smBktoVVOk0/tlHaWa+FGQ+xXfpIippdsQHUHi2iS9sTKdcXcs7spwwtmv9gaUs3zHN5YTOt47z9115B2WPDYLkmRQXua1qv7AMdN+qgiN7hru8SDBbEcEKnaDdnIxg4MONdeidFG0WOMGSCgIDn/qdryaQHId5sezaQNMvxYiUjCyFisN6ADRqS+QAMdKjpL84cbb4lAA1DIqFAJLzfrZc708xl/+lGwQmrYknhd/JhUuuY/pmeY09jTdxdKYQR8E9W4ff6wYzxj1MjXghDdOPf0ll0mmQ== Received: from DUZPR01CA0108.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bb::23) by DB9PR07MB7771.eurprd07.prod.outlook.com (2603:10a6:10:2a6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.22; Thu, 17 Apr 2025 23:00:56 +0000 Received: from DU6PEPF0000A7DD.eurprd02.prod.outlook.com (2603:10a6:10:4bb:cafe::7) by DUZPR01CA0108.outlook.office365.com (2603:10a6:10:4bb::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.23 via Frontend Transport; Thu, 17 Apr 2025 23:01:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by DU6PEPF0000A7DD.mail.protection.outlook.com (10.167.8.37) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:00:56 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id 2C39C20864; Fri, 18 Apr 2025 02:00:55 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 05/15] tcp: accecn: add AccECN rx byte counters Date: Fri, 18 Apr 2025 01:00:19 +0200 Message-Id: <20250417230029.21905-6-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF0000A7DD:EE_|DB9PR07MB7771:EE_ X-MS-Office365-Filtering-Correlation-Id: e869a4f6-cbd0-497a-2d45-08dd7e03b65f X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?o3L3vnzdXQVFGzAOf+24xsmzqwdjhfC?= =?utf-8?q?sk4PRNXNK2ACPRHXssDGPcCHq8pFF+8gZcR2B4eTc0A/lpPGpueXkSph5pNZWWbno?= =?utf-8?q?7K2wkTCW8uyo8T+4T45K3k7zfC3kM8zbM1uPSUXcuyJhPmyFYp4c6RspmdHiImzh1?= =?utf-8?q?uqHldUYwx7y5gHcV+rUQ5d/on2CvMWkg4KOJSs622FFZc/mJEvnYi5HgkDiOWTXTa?= =?utf-8?q?cKTTr6mp+fiFJ90ogQLlbzoof3IKK67Wq+uuOaqh6zFRaH2cxSLiKDvpm/M0XHpet?= =?utf-8?q?6PatYIp5QF0rka9RAXm9D+h53ZvDbsfDletX+S/KQas93V41CJyJlJ/HvLa9htSas?= =?utf-8?q?4Nw9mzDNqkseGTaGBCyzWnu+mh3BDyQ3HuCxyx9SJhzKcnB//kS9GdREnfGt021cR?= =?utf-8?q?qgqtT9j4SmypSBGAFknA6tqfosXeSNCoulsA78X26OX3CeWhEXC+1RSnQtgOSTQ1h?= =?utf-8?q?a3xCGW8sTcrFvWffv3avgcR0R+xxvmZKKXI7XSaClhHny8yFpdQPAZvBNM5jqyDP5?= =?utf-8?q?zFZAQBY0Yyh1X1PWX0WiXUFOiyXMh54Vuagc95AedaapXgwHzkcm35QhqzRsv6PXL?= =?utf-8?q?HQErosLRZaa+nXAJDVRuKWFxxSODdVUj0hFBTdOaSYpfJBRmJzdpqriniZqsUr20u?= =?utf-8?q?w4NbtWKu7XHtDSqjGva0yURJQrUg7jEE/AITOL03DeKxPKSABm2GW+ezHMVrCqbrC?= =?utf-8?q?4skuJnmlxvQa4u/YRVHaAZ9zcKWr9ujdA8tBYixJ5XmBo0jN/MEDZb1rVx2xgD6Ym?= =?utf-8?q?dplBvYxHccOevbxTZyPA1lNE7XtHb5Euk5qhtiEIUBjnLU722B/avJnG3OgZvtZJr?= =?utf-8?q?uuo/5d2rqIgbKpFqVO9gPeLwexVTsFIdTAGGzmn55y9cT5mQ4HCnQn8FEC77fhtXO?= =?utf-8?q?u0YpMmhN2cvQzqBWXyShKZq6lUaqX9NFRUay01OyxTn6e+dDcEIRYwVyg5XYoi/mE?= =?utf-8?q?9a1CqETjzuWnVfgGCdFiUz/Ms8ZnV2IA8OAsyXnucWUeGqlmWwaa2I2t4T2fYOUHT?= =?utf-8?q?Nf4DHZ48ernqC6xINnVAt+yaPuokpwbk4k4SYCOBGvCh7R297q4I+9lUqaeZzBRsB?= =?utf-8?q?cgazq8FFyT/BKLeBYG3ntDwB94ZP8Cn3S9jE+mlZrHZ1uPie9ERNm6eFa1YNKP8TM?= =?utf-8?q?BWkciesrFQ4avMVW/CSoYolM4tJQ0LWsR72F16TzUYrGBZHg05Z61csXzR8PApotO?= =?utf-8?q?JUelXkBgyPAFSe37qmF59Lj6IiQhgNbQd20RxD9LltxwkZtUG6v6YUrhM4/BrvXaP?= =?utf-8?q?RGImxdaKf1TYAyMNRHEouqtU2c83rWpy4tX7EUZr6IbWnrcBIfCG3uZlPUnVlXdKQ?= =?utf-8?q?Hlpy7grF6EISPRgBX6ZC1pDfqm+QSOPXjT3RD0QXC6pn/izRqm5bQkJ/gbsPeTzWq?= =?utf-8?q?jJ6x6Wm1jDGh9HqxWPVZNSv7jvKAcTr2LBfR2qB5Vo/nC2ja83RYGfO3ZgidR0Yxl?= =?utf-8?q?U/E50ChhSQ6fw9KMK+px1nj2XVCF0Lsw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:00:56.5515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e869a4f6-cbd0-497a-2d45-08dd7e03b65f X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF0000A7DD.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB7771 From: Ilpo Järvinen These counters track IP ECN field payload byte sums for all arriving (acceptable) packets. The AccECN option (added by a later patch in the series) echoes these counters back to sender side. Signed-off-by: Ilpo Järvinen Signed-off-by: Neal Cardwell Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 1 + include/net/tcp.h | 18 +++++++++++++++++- net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_input.c | 13 +++++++++---- net/ipv4/tcp_minisocks.c | 3 ++- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index af38fff24aa4..9cbfefd693e3 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -303,6 +303,7 @@ struct tcp_sock { u32 delivered; /* Total data packets delivered incl. rexmits */ u32 delivered_ce; /* Like the above but only ECE marked packets */ u32 received_ce; /* Like the above but for rcvd CE marked pkts */ + u32 received_ecn_bytes[3]; u8 received_ce_pending:4, /* Not yet transmit cnt of received_ce */ unused2:4; u32 app_limited; /* limited until "delivered" reaches this val */ diff --git a/include/net/tcp.h b/include/net/tcp.h index f36a1a3d538f..6ffa4ae085db 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -467,7 +467,8 @@ static inline int tcp_accecn_extract_syn_ect(u8 ace) bool tcp_accecn_validate_syn_feedback(struct sock *sk, u8 ace, u8 sent_ect); void tcp_accecn_third_ack(struct sock *sk, const struct sk_buff *skb, u8 syn_ect_snt); -void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb); +void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, + u32 payload_len); enum tcp_tw_status { TCP_TW_SUCCESS = 0, @@ -1035,11 +1036,26 @@ static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq) * See draft-ietf-tcpm-accurate-ecn for the latest values. */ #define TCP_ACCECN_CEP_INIT_OFFSET 5 +#define TCP_ACCECN_E1B_INIT_OFFSET 1 +#define TCP_ACCECN_E0B_INIT_OFFSET 1 +#define TCP_ACCECN_CEB_INIT_OFFSET 0 + +static inline void __tcp_accecn_init_bytes_counters(int *counter_array) +{ + BUILD_BUG_ON(INET_ECN_ECT_1 != 0x1); + BUILD_BUG_ON(INET_ECN_ECT_0 != 0x2); + BUILD_BUG_ON(INET_ECN_CE != 0x3); + + counter_array[INET_ECN_ECT_1 - 1] = 0; + counter_array[INET_ECN_ECT_0 - 1] = 0; + counter_array[INET_ECN_CE - 1] = 0; +} static inline void tcp_accecn_init_counters(struct tcp_sock *tp) { tp->received_ce = 0; tp->received_ce_pending = 0; + __tcp_accecn_init_bytes_counters(tp->received_ecn_bytes); } /* State flags for sacked in struct tcp_skb_cb */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 73f8cc715bff..1e21bdf43f23 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -5092,6 +5092,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rx_opt); @@ -5099,7 +5100,7 @@ static void __init tcp_struct_check(void) /* 32bit arches with 8byte alignment on u64 fields might need padding * before tcp_clock_cache. */ - CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 97 + 7); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 109 + 7); /* RX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_received); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index cc34664805f8..c017e342f092 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6106,7 +6106,8 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t } /* Updates Accurate ECN received counters from the received IP ECN field */ -void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb) +void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, + u32 payload_len) { u8 ecnfield = TCP_SKB_CB(skb)->ip_dsfield & INET_ECN_MASK; u8 is_ce = INET_ECN_is_ce(ecnfield); @@ -6121,6 +6122,9 @@ void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb) tp->received_ce += pcount; tp->received_ce_pending = min(tp->received_ce_pending + pcount, 0xfU); + + if (payload_len > 0) + tp->received_ecn_bytes[ecnfield - 1] += payload_len; } } @@ -6398,7 +6402,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) flag |= __tcp_replace_ts_recent(tp, delta); - tcp_ecn_received_counters(sk, skb); + tcp_ecn_received_counters(sk, skb, 0); /* We know that such packets are checksummed * on entry. @@ -6444,7 +6448,8 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) /* Bulk data transfer: receiver */ tcp_cleanup_skb(skb); __skb_pull(skb, tcp_header_len); - tcp_ecn_received_counters(sk, skb); + tcp_ecn_received_counters(sk, skb, + len - tcp_header_len); eaten = tcp_queue_rcv(sk, skb, &fragstolen); tcp_event_data_recv(sk, skb); @@ -6491,7 +6496,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) tcp_accecn_third_ack(sk, skb, tp->syn_ect_snt); tcp_fast_path_on(tp); } - tcp_ecn_received_counters(sk, skb); + tcp_ecn_received_counters(sk, skb, len - th->doff * 4); reason = tcp_ack(sk, skb, FLAG_SLOWPATH | FLAG_UPDATE_TS_RECENT); if ((int)reason < 0) { diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 779a206a5ca6..3f8225bae49f 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -497,10 +497,11 @@ static void tcp_ecn_openreq_child(struct sock *sk, struct tcp_sock *tp = tcp_sk(sk); if (treq->accecn_ok) { + const struct tcphdr *th = (const struct tcphdr *)skb->data; tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); tp->syn_ect_snt = treq->syn_ect_snt; tcp_accecn_third_ack(sk, skb, treq->syn_ect_snt); - tcp_ecn_received_counters(sk, skb); + tcp_ecn_received_counters(sk, skb, skb->len - th->doff * 4); } else { tcp_ecn_mode_set(tp, inet_rsk(req)->ecn_ok ? TCP_ECN_MODE_RFC3168 : From patchwork Thu Apr 17 23:00:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882065 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013007.outbound.protection.outlook.com [52.101.72.7]) (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 C6FAF21CFEA; Thu, 17 Apr 2025 23:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.72.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930869; cv=fail; b=M8p/0jfNPYULkybMuLl2GnJCsI5ZjgU9QB3PY3e3orrtaJvWAeqkBG/3skyytzbZbTeh6j6VMdB4Yn6L1+6FP0hLfMlxc4o7EIuDkcdRLxx1rwd0LHTs1950uNTVKekUN8HJrQjyZCP8gX5wVht3V/ZlNsU84uyYiG4DkraDCyI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930869; c=relaxed/simple; bh=bnrDau03MTqEb+55uE4ECIXJc1PXmTb+6uznb2nRdxQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=iOi3dT/ANeR1qvEUK6Mm841qyEZs8/4FbgjuN1HhVk/1/6SxZ9lsa16ZzddrWVv3llWcnzjuH+fcxEcGP9n6AZRNwotLOh8XSmhKAQWPo97xSrUyOQh7KwsGqdeGPSOUOcwkRTh8dUYjhOoxfo7b4ME+B+22KHvqv8jOKxagT8A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=KrnC0JMA; arc=fail smtp.client-ip=52.101.72.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="KrnC0JMA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P23r9CRUSRILJK5MAlw9zGsXp7eOkX4iD5JYMmFjU14+TvR3xiszmFpB88bGDq7UASSVk1P34fymfUhx3psI7oowgFyWAf6+6REJkfGIRtI8slzHCbclRWrLXDU44+muVccM472Xm3OtWe/lGelk9WyUSTBha7pP6NIEcsSF6KbBqb07yw5bDVpF1my20VmWKhBr6DQE/pABvqp4VYo/T7ALiVUoVb5Vmknb2pPGuCO5G/uBYQkpGxM51/+FWhxtLDaaZJWkoAwzCReyjNGhfTWLfIbFx/ralTZGJvMeAxDFWJXqc+UrxCNm8knQG2vrwYhwMBqSe7h09gCvOoV61Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PF6XTXiEfjIReTh6hy2n4CrqURGfKz4X+CBDtXd3M1A=; b=rNza8mEv6RfZFCDB8m/79pzQ4Bs4FDfVNNQMr9aACoot7LlLr04hQm24c7aiCgkbyyXJD9KdPSpFDopR4YoOPF+sCnBIwyJ7XtT02Le8hoK2+wFZH9rP5uiIyZMlfxybA2KgjZidh6VMbAI63UF/divG2hasDrHBvgHTl6493ETvo0IMVgVAocu8XhkdQfiY051sLRrP6tlS77BsJjkO45AvrTgGP0E8i++A392ifVsQ8IMJZMBA39zB79SnQd8WBdQo3sXenO8dSYocacXvsTfZyROYUpG4Q2cPEjUwXYfvDgmCzUs+3G2ngV7vIuBCQAGDOyDtJ8uLYTQY6kAhBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PF6XTXiEfjIReTh6hy2n4CrqURGfKz4X+CBDtXd3M1A=; b=KrnC0JMANlV8x3DA1amv3sKJlRxSDqNdFy9sNtRkT3izqiyUn5UaLe4qU2JbypWIOzqDTZ84xE61YS/HcS6tK8AKY+ychymIF945YQ8r27GZxrEdmn+pm+xQaXrAyQ9EyRXtao1M9He75EeZ5OWIYbc/hcDjsqajwhRBjOmHCdwFYBGojKtMZJj0dony0yXCfwTxe7BEeV+Y6+YpRPBnGrwo6Qa0unW+iDN2QaLD4y+iR9Jl6DwZ762SRm3Mj//lkB94Ekm3/Gxv5mOLWWOIMVi3hSMabQCyiO9Ck5jqRSswrksSRK8IcjB0xE/pjilwluO0KqsVVPOVBbX5vL75VA== Received: from DB6PR0301CA0075.eurprd03.prod.outlook.com (2603:10a6:6:30::22) by VI1PR07MB6607.eurprd07.prod.outlook.com (2603:10a6:800:181::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.25; Thu, 17 Apr 2025 23:01:04 +0000 Received: from DU2PEPF00028D09.eurprd03.prod.outlook.com (2603:10a6:6:30:cafe::c6) by DB6PR0301CA0075.outlook.office365.com (2603:10a6:6:30::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.23 via Frontend Transport; Thu, 17 Apr 2025 23:01:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by DU2PEPF00028D09.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:01:04 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id B65FA20864; Fri, 18 Apr 2025 02:01:02 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 07/15] tcp: allow embedding leftover into option padding Date: Fri, 18 Apr 2025 01:00:21 +0200 Message-Id: <20250417230029.21905-8-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D09:EE_|VI1PR07MB6607:EE_ X-MS-Office365-Filtering-Correlation-Id: d4e07edf-be26-4ea3-f6a0-08dd7e03baee X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?r/TBxDv4CZQlJCUv96K+qfpMkTctSZ/?= =?utf-8?q?zL+5AJnBNln3/qSjtmWYtFcSC0XE7qsseNi5l0hjoz9TDZ6M5U+a8tf19psXVs4O4?= =?utf-8?q?Bxkb6uHPhSQauLlKkREoMRtmrP8g8w+a5jaz2roySyE8ULXr7YmlGTnX52bKBHzUw?= =?utf-8?q?fpQCcdERx7dJCDWFdt+XCJmsHjk2iKP8+aEwJ3Qb2n4ulR5txRAhgyEyVOYRyWDti?= =?utf-8?q?6snvV2e2ClygOk08b6ByCKBLhrgGBmmyWMJXXc9dHrKGghkQwvgwWHx1unHDsWtNf?= =?utf-8?q?cQz9BTRUbBfH9Uaakrw+RalVBeAZAUmsUul0ZqwY00B1AV1hiqcy4tO1zHY6THQrH?= =?utf-8?q?FQgZHszOIFuM5hK9V4ihT7GmjbGrKbPr1TVBqrxmdHN1KMVEZATdHy+U/P7KEgR6N?= =?utf-8?q?3wkWm1A1I+em0vw7TdiSucVnY6ehE7DoQ0nUH4k6125dcZ8x29KyY2io4jDCcGhhQ?= =?utf-8?q?rCJM2z6RuEW7kdyr/fldeQc+OX3TNpIagSAg30LPbWu42IsUFbBZRpRyXFXTC9FvE?= =?utf-8?q?7RPFY+fXXfdsiEjfGaej+tPbliPsDjZKXHXwvL95XmXtTUH0I/M8Wfq1BlNxwFeqa?= =?utf-8?q?zqqkbEB+N4kky97k5e/Q0BTNR+DUxFEZNEfHG3boUWPw5q78IYiQZky76QjWgHtch?= =?utf-8?q?qlSqCC6wtRtN3Xu5Jr0zue3l3lGBbsHRoRPuQAWdQ1CZJCumwTLMMZHdtb8Srm8Zu?= =?utf-8?q?R5NpVFREO5Wwsl6LnOgy10/WyJphvpPu4Fb25W9HIHO8yxezz/jNX6UcFUviRPyZ0?= =?utf-8?q?0/T6wG6KUdpfbnS9KfbFTGPnxuhVsFUcxt4x+YdhTQmTPfr32UOcmv73ho2aCjmNs?= =?utf-8?q?a1Yxw+wPmofXszqwXMb3Ls7+gVs2oJsJ7kCRQtGNxX0zDuOEFnbDpeJIXMkb67kc8?= =?utf-8?q?gmMuja5GnSgNIACqmOqXMir623j/eusozjj06epskypEYbvHKY3eb7TOj4gxgrWBo?= =?utf-8?q?4Vjdz5+ZrgRGW4A/MhFF4u/uWr5utzl8hRvl0B8bid+RQYmeYZocdStG8azu0i3l6?= =?utf-8?q?IF3ZURAwhQrkJMGoFlguJLpvuEZzUP4cOpMicd5UEP7av/PNwgVWB8r07hqBvtABD?= =?utf-8?q?XCXl6W7xqE7YG3ASCuGGIcZUjABjHjJ3e2UuPzwK+s8zHVqnh8SDBzDVKDHzdTes4?= =?utf-8?q?wJILEDFvq4cMxAgvO+YEkTOw+VoX9tA2Yq6BRTM1e0a/vV9jMfN/xt5WMzbZGH09k?= =?utf-8?q?PtLgvcj1/IbR+OluIpEyHkJ24wwC/iGS9GNWUpbjyKy8yLWFsmJ4gpbpQ0ttVU8hB?= =?utf-8?q?y7U3WVMzJnEM5G18y+UUycJiLjqUg97AaRyjZFv1LQqYW0PORlaAiXY5Fnp/zWOdZ?= =?utf-8?q?Ux8AuTGoGRRdinE/ZndkUdkNjzwd8ALkpSKyFAee/e/QhT/Q2/DU+4UYY5of0c3La?= =?utf-8?q?vxC38ge2e7uLBZHEXz1TSp4RChL3DQ7AqywytX+kjULaUBeEAwZH7vsE931+8EqSx?= =?utf-8?q?CYHE5nYzWwRqiStR3vY40uK0Dg/XxS+A=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:01:04.2234 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4e07edf-be26-4ea3-f6a0-08dd7e03baee X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D09.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6607 From: Ilpo Järvinen There is some waste space in the option usage due to padding of 32-bit fields. AccECN option can take advantage of those few bytes as its tail is often consuming just a few odd bytes. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_output.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index b4eac0725682..d63f505a30e2 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -709,6 +709,8 @@ static __be32 *process_tcp_ao_options(struct tcp_sock *tp, return ptr; } +#define NOP_LEFTOVER ((TCPOPT_NOP << 8) | TCPOPT_NOP) + /* Write previously computed TCP options to the packet. * * Beware: Something in the Internet is very sensitive to the ordering of @@ -727,8 +729,10 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, struct tcp_out_options *opts, struct tcp_key *key) { + u16 leftover_bytes = NOP_LEFTOVER; /* replace next NOPs if avail */ __be32 *ptr = (__be32 *)(th + 1); u16 options = opts->options; /* mungable copy */ + int leftover_size = 2; if (tcp_key_is_md5(key)) { *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) | @@ -763,17 +767,22 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, } if (unlikely(OPTION_SACK_ADVERTISE & options)) { - *ptr++ = htonl((TCPOPT_NOP << 24) | - (TCPOPT_NOP << 16) | + *ptr++ = htonl((leftover_bytes << 16) | (TCPOPT_SACK_PERM << 8) | TCPOLEN_SACK_PERM); + leftover_bytes = NOP_LEFTOVER; } if (unlikely(OPTION_WSCALE & options)) { - *ptr++ = htonl((TCPOPT_NOP << 24) | + u8 highbyte = TCPOPT_NOP; + + if (unlikely(leftover_size == 1)) + highbyte = leftover_bytes >> 8; + *ptr++ = htonl((highbyte << 24) | (TCPOPT_WINDOW << 16) | (TCPOLEN_WINDOW << 8) | opts->ws); + leftover_bytes = NOP_LEFTOVER; } if (unlikely(opts->num_sack_blocks)) { @@ -781,8 +790,7 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, tp->duplicate_sack : tp->selective_acks; int this_sack; - *ptr++ = htonl((TCPOPT_NOP << 24) | - (TCPOPT_NOP << 16) | + *ptr++ = htonl((leftover_bytes << 16) | (TCPOPT_SACK << 8) | (TCPOLEN_SACK_BASE + (opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK))); @@ -794,6 +802,10 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, } tp->rx_opt.dsack = 0; + } else if (unlikely(leftover_bytes != NOP_LEFTOVER)) { + *ptr++ = htonl((leftover_bytes << 16) | + (TCPOPT_NOP << 8) | + TCPOPT_NOP); } if (unlikely(OPTION_FAST_OPEN_COOKIE & options)) { From patchwork Thu Apr 17 23:00:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882063 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2054.outbound.protection.outlook.com [40.107.20.54]) (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 7F46F2222D2; Thu, 17 Apr 2025 23:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930884; cv=fail; b=uRYO1CmDNa5APqzpnb8z18ppC3KBYA2pmOhZ8BB+/ZJGJmenL9LgjRvG0ZkiLqpIZdwb2RBtG9IeIFsY3Tr7QiFMuqlnKx+04+hgmO0ur1w6Ddk9OBeUIVz8gSgEzXEjlBG65VKz+ripVHVKCljMH/2T7A2T1ydou/Pofl+crIg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930884; c=relaxed/simple; bh=G7AD1z9w1HgJyE5etSVk9tk++GMHosLLpz93FfPbtls=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Uc6i2piEGwh9QMilJj6A+j7E1ETFNwcdhyU1jzhCxhg+flA8kcbjYAtfyoMTEj+XKKCKujfoOZT4svuCpyarU0AZ/RYZV760MacgUP1KXLPc6zWyan/SP77FDygq150VkMKUmyhzEgyikYMHuppXTXEc+5AC9j33JGRXNIO0EYI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=R9rYpiWO; arc=fail smtp.client-ip=40.107.20.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="R9rYpiWO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aPdCTIc0U7yrzM8fWC20LDVbEZkOrwqeKlwC7XejtfjixfO29s7moOQoR0Xaz6omDfRSToImlyq/Km6wkamRamvALLQtYBE/wQOU/K0fcV/lbIr2CEOcL/mbFC5iW4gn80k3ePr+hCmCB1jovz48XIIsB0l420Dlp5kR5gpOOXAu9cv12GJHkDqgPcQu2rzTHnNopJNu15KW7aoBy6a9V5MkXdU8AcxrA6qrJaD+o7otFIY5nDbPNaKQAaj5Qkpy4bnu0lTjBabou2KErGGHRnEVZYKD43ou9wIaUfV+4YkA532v8p0WVXWDAwrJDiU31r/dmTjKzJfeJWtRL4Mqsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=99oKgOcN6Ay0P/Xag6QzCJxFE5Sfm9d6UD3XFt66CiM=; b=tl27FhvU7egonlNm4x3YjLCZVlT8ct1gbl70Y9eaY05XaWTsUYA9TuPzAJO0kdole+snJXxOg8q1F6E1AJXUV41R0g4iIRF4gBNYC3ZvolzlpXgvnkeTMr6h6xiUkBVJjxfajrUWEUzJatOHER8whAYGdu1WIVUsM/HlJyWCW4dCoQUjX2EPq7+zYj5OnlVeLg9gNIOt9bVfr2F2MDat6JnxU47Kb3EISlCfkyoXQJ2JM5oq1qdGjt4QasE/ygHdXCsSijXHiW6OQTWS78klZgon4Myhv89AMyP2rjR7kgwkoMhd++fRc5hI7zse0eXUmZ1mAN7sIrREYWJhFR+g9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=99oKgOcN6Ay0P/Xag6QzCJxFE5Sfm9d6UD3XFt66CiM=; b=R9rYpiWOP1zMTNdAaVAvNAJWX5P1/b01sHmo83xp/bj3nnwUlWIj8P4HUyu2slJpLQC8Sbuyhe2viSj5CdKp8SElxHQ0Ju9nH+oVa5RJSDARB47WdUav0OtA+h7x+xjaWz3HkK6Myb1jh5yb9R7QQSj/iaWv6ntRMKMgP0asIjcRO23YNlBqJPRRhUK6mDWiqG3F8+e+//YMl9Dsn+5+4cjStjG8EhRx2ZIqiEGt0V/A/P8xQtM1dhVy9zUUQVQdO+iNWtaATJKHgmrY8lFXy4hfQlp3e5VbZr+VqwrjstWW+tnM8isXgnYnFruMU3BYVn2z7yD/OAeUvkth5hDeRA== Received: from DU7P250CA0012.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:54f::25) by PR3PR07MB6684.eurprd07.prod.outlook.com (2603:10a6:102:2f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.26; Thu, 17 Apr 2025 23:01:14 +0000 Received: from DB1PEPF000509E8.eurprd03.prod.outlook.com (2603:10a6:10:54f:cafe::38) by DU7P250CA0012.outlook.office365.com (2603:10a6:10:54f::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.22 via Frontend Transport; Thu, 17 Apr 2025 23:01:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by DB1PEPF000509E8.mail.protection.outlook.com (10.167.242.58) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:01:14 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id EBF662084F; Fri, 18 Apr 2025 02:01:12 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 10/15] tcp: accecn: AccECN option send control Date: Fri, 18 Apr 2025 01:00:24 +0200 Message-Id: <20250417230029.21905-11-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509E8:EE_|PR3PR07MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: 6bb4769d-e2fa-4875-ea6a-08dd7e03c0ff X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?qDfFiBqm7eloQs4bSKTcNnfzFVlthbA?= =?utf-8?q?GZ9KdzreTGilwpaaWyuz9ajYh6pSv8Fs4BsklPjBUMMPV68nxWpM3/iAzNdpSpCXd?= =?utf-8?q?ElHBgPPCUoFwV1GmhmnSc6KkamUqdk2xGd+v5Af7aHfKeE9sDu92NFebHIPw6xTjn?= =?utf-8?q?m+bGUwf6W9hS9nI2qXXZfc9p0WlVl1K+hdRMxCdHv098h2fPrG/FSLiyiqafJwYPi?= =?utf-8?q?KWdMDuL5JhMQ+2I3q/HehmSI00Cn3Z4LcgBKeG9iA/5T36zc6QMpQOAR6Z2ol13Fs?= =?utf-8?q?ecRgvT5vWrzE7fuh7WoFKwVCKTU0WW61l+TbzG2nuGTaEoJjN9suTC59Wu5xo36ZZ?= =?utf-8?q?6DCOl7AmPfx/7KyLmOqSayo6WblVvH3P0uEU7m7epB2ghC4f3Mqa50wNFnAm1te1y?= =?utf-8?q?0cYG18Z+cdreDX8+rlLK2TDiYmAFWnbujZkjZIvNcLQeqYvo+iYbpp3Au9hQM6nCs?= =?utf-8?q?/GjAhlNM6F6Y8wYyILl6UGTG4AFBa69xsL3+E4lNPnPBfmqnMy3Jdd0ADQDxXuuzn?= =?utf-8?q?WQKql7maLvLPkW5tznTL23BtmAilD38/Y7sRvWVspf2AIl4Fodx9TfbVppHEDhPvf?= =?utf-8?q?bFmPZyHDoZWKVWiWYZMrDplUcPKZppIQkyndzGZpTU70FFxFgVAbA4afrCh/dveH2?= =?utf-8?q?gj0yhlWiTi5mmmV9B5dYbPBZUCWCzvtql/vTeEG3DBpT9BHKJxmAHQ5upTfjted1v?= =?utf-8?q?1uyXpRH3ms8DcIgmXWvOS0xlh93n0DTv1DWksdYB3vvjDdIu2H6nS2fperhN/Tjfs?= =?utf-8?q?bSvMHGivgVIYGBMi1xQSxEsya3vuMj48BRiYiQCV4w0fpVhQwW37l+BkqLj91U+l0?= =?utf-8?q?duc3JLGKtbKlwlQOUqWMHDe3C6cAGECGnXxFc4LuRl+DL99bR2gD2PYZGclK3kSI2?= =?utf-8?q?Kzy0Cb58E7yEQ2ykUEizmeba70kHGqdXPIXW3pEwoIjEezU1ZpW1feC6PM1307q+v?= =?utf-8?q?LpsNw3XPmPLKsMU3RyIG32qTt3XcQMnXmKYsZg3+9PXfNqEFggf/bVJ2Bku930i3f?= =?utf-8?q?51GiVB+HUTzkNcjun47gi99uLoEXREaLNlCmjdiMyzkEn4+h03YXQ5h6yKbHdKOdq?= =?utf-8?q?AU3dLr6zoqUCV7Lm3c5pTIxyxpBgZNnZzcRVa++UXkWtG2Tn9Tp5i9OJ963g/OI/P?= =?utf-8?q?FOsNb0RyHPg2jz5ODMbHvp6Ei/XguYCF8NGGSJ3j87nz/v+t9jT88xHKDOOhQo4db?= =?utf-8?q?I8QHVI8t5vXTWB8d5NLZtS6+Lj5E5TxsuIJXTLk9f66fTeNI8fXiTpv3ivTr3Mirx?= =?utf-8?q?ycjeJ9cXwbdyXTOuOi6mz6U9/s4yfal2TlQKoCEEVYmpvFhL7xmZlU1m668bmlSJs?= =?utf-8?q?wfNL4LJ8OmOpHfRuBbBLphbI48Pw5cy0cxHVUrHWtfcTNaTLQpWWph9MWl8spg05s?= =?utf-8?q?wrL4C7F5C29fIdRgt+lTm6tk0D5s2iRcWd5pRg4iu9nHlHykleb0CTnSbmbs5BAjX?= =?utf-8?q?1K/wfrqk/SMuNqxtedX4cNxdGNtUInOA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:01:14.3852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6bb4769d-e2fa-4875-ea6a-08dd7e03c0ff X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509E8.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB6684 From: Ilpo Järvinen Instead of sending the option in every ACK, limit sending to those ACKs where the option is necessary: - Handshake - "Change-triggered ACK" + the ACK following it. The 2nd ACK is necessary to unambiguously indicate which of the ECN byte counters in increasing. The first ACK has two counters increasing due to the ecnfield edge. - ACKs with CE to allow CEP delta validations to take advantage of the option. - Force option to be sent every at least once per 2^22 bytes. The check is done using the bit edges of the byte counters (avoids need for extra variables). - AccECN option beacon to send a few times per RTT even if nothing in the ECN state requires that. The default is 3 times per RTT, and its period can be set via sysctl_tcp_ecn_option_beacon. Signed-off-by: Ilpo Järvinen Co-developed-by: Chia-Yu Chang Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 3 +++ include/net/netns/ipv4.h | 1 + include/net/tcp.h | 1 + net/ipv4/sysctl_net_ipv4.c | 9 ++++++++ net/ipv4/tcp.c | 5 ++++- net/ipv4/tcp_input.c | 36 +++++++++++++++++++++++++++++++- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_minisocks.c | 2 ++ net/ipv4/tcp_output.c | 42 ++++++++++++++++++++++++++++++-------- 9 files changed, 90 insertions(+), 10 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 0e032d9631ac..9619524d8901 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -309,7 +309,10 @@ struct tcp_sock { u8 received_ce_pending:4, /* Not yet transmit cnt of received_ce */ unused2:4; u8 accecn_minlen:2,/* Minimum length of AccECN option sent */ + prev_ecnfield:2,/* ECN bits from the previous segment */ + accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */ est_ecnfield:2;/* ECN field for AccECN delivered estimates */ + u64 accecn_opt_tstamp; /* Last AccECN option sent timestamp */ u32 app_limited; /* limited until "delivered" reaches this val */ u32 rcv_wnd; /* Current receiver window */ /* diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 4569a9ef4fb8..ff8b5b56ad00 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -149,6 +149,7 @@ struct netns_ipv4 { u8 sysctl_tcp_ecn; u8 sysctl_tcp_ecn_option; + u8 sysctl_tcp_ecn_option_beacon; u8 sysctl_tcp_ecn_fallback; u8 sysctl_ip_default_ttl; diff --git a/include/net/tcp.h b/include/net/tcp.h index bfff2a9f95bf..3ee5b52441e3 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1068,6 +1068,7 @@ static inline void tcp_accecn_init_counters(struct tcp_sock *tp) __tcp_accecn_init_bytes_counters(tp->received_ecn_bytes); __tcp_accecn_init_bytes_counters(tp->delivered_ecn_bytes); tp->accecn_minlen = 0; + tp->accecn_opt_demand = 0; tp->est_ecnfield = 0; } diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 1d7fd86ca7b9..3ceefd2a77d7 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -740,6 +740,15 @@ static struct ctl_table ipv4_net_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_TWO, }, + { + .procname = "tcp_ecn_option_beacon", + .data = &init_net.ipv4.sysctl_tcp_ecn_option_beacon, + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_FOUR, + }, { .procname = "tcp_ecn_fallback", .data = &init_net.ipv4.sysctl_tcp_ecn_fallback, diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 89799f73c451..25a986ad1c2f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3368,6 +3368,8 @@ int tcp_disconnect(struct sock *sk, int flags) tp->wait_third_ack = 0; tp->accecn_fail_mode = 0; tcp_accecn_init_counters(tp); + tp->prev_ecnfield = 0; + tp->accecn_opt_tstamp = 0; if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release(sk); memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); @@ -5106,6 +5108,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, accecn_opt_tstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rx_opt); @@ -5113,7 +5116,7 @@ static void __init tcp_struct_check(void) /* 32bit arches with 8byte alignment on u64 fields might need padding * before tcp_clock_cache. */ - CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 122 + 6); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 130 + 6); /* RX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_received); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 41e45b9aff3f..1e8e49881ca4 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -466,6 +466,7 @@ static void tcp_ecn_rcv_synack(struct sock *sk, const struct tcphdr *th, default: tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); tp->syn_ect_rcv = ip_dsfield & INET_ECN_MASK; + tp->accecn_opt_demand = 2; if (INET_ECN_is_ce(ip_dsfield) && tcp_accecn_validate_syn_feedback(sk, ace, tp->syn_ect_snt)) { @@ -486,6 +487,7 @@ static void tcp_ecn_rcv_syn(struct tcp_sock *tp, const struct tcphdr *th, } else { tp->syn_ect_rcv = TCP_SKB_CB(skb)->ip_dsfield & INET_ECN_MASK; + tp->prev_ecnfield = tp->syn_ect_rcv; tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); } } @@ -6278,6 +6280,7 @@ void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, u8 ecnfield = TCP_SKB_CB(skb)->ip_dsfield & INET_ECN_MASK; u8 is_ce = INET_ECN_is_ce(ecnfield); struct tcp_sock *tp = tcp_sk(sk); + bool ecn_edge; if (!INET_ECN_is_not_ect(ecnfield)) { u32 pcount = is_ce * max_t(u16, 1, skb_shinfo(skb)->gso_segs); @@ -6291,9 +6294,36 @@ void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, if (payload_len > 0) { u8 minlen = tcp_ecnfield_to_accecn_optfield(ecnfield); + u32 oldbytes = tp->received_ecn_bytes[ecnfield - 1]; + tp->received_ecn_bytes[ecnfield - 1] += payload_len; tp->accecn_minlen = max_t(u8, tp->accecn_minlen, minlen); + + /* Demand AccECN option at least every 2^22 bytes to + * avoid overflowing the ECN byte counters. + */ + if ((tp->received_ecn_bytes[ecnfield - 1] ^ oldbytes) & + ~((1 << 22) - 1)) { + u8 opt_demand = max_t(u8, 1, + tp->accecn_opt_demand); + + tp->accecn_opt_demand = opt_demand; + } + } + } + + ecn_edge = tp->prev_ecnfield != ecnfield; + if (ecn_edge || is_ce) { + tp->prev_ecnfield = ecnfield; + /* Demand Accurate ECN change-triggered ACKs. Two ACK are + * demanded to indicate unambiguously the ecnfield value + * in the latter ACK. + */ + if (tcp_ecn_mode_accecn(tp)) { + if (ecn_edge) + inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW; + tp->accecn_opt_demand = 2; } } } @@ -6426,8 +6456,12 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, * RFC 5961 4.2 : Send a challenge ack */ if (th->syn) { - if (tcp_ecn_mode_accecn(tp)) + if (tcp_ecn_mode_accecn(tp)) { + u8 opt_demand = max_t(u8, 1, tp->accecn_opt_demand); + send_accecn_reflector = true; + tp->accecn_opt_demand = opt_demand; + } if (sk->sk_state == TCP_SYN_RECV && sk->sk_socket && th->ack && TCP_SKB_CB(skb)->seq + 1 == TCP_SKB_CB(skb)->end_seq && TCP_SKB_CB(skb)->seq + 1 == tp->rcv_nxt && diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 3f3e285fc973..2e95dad66fe3 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3451,6 +3451,7 @@ static int __net_init tcp_sk_init(struct net *net) { net->ipv4.sysctl_tcp_ecn = 2; net->ipv4.sysctl_tcp_ecn_option = 2; + net->ipv4.sysctl_tcp_ecn_option_beacon = 3; net->ipv4.sysctl_tcp_ecn_fallback = 1; net->ipv4.sysctl_tcp_base_mss = TCP_BASE_MSS; diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 3f8225bae49f..e0f2bd2cee9e 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -501,6 +501,8 @@ static void tcp_ecn_openreq_child(struct sock *sk, tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); tp->syn_ect_snt = treq->syn_ect_snt; tcp_accecn_third_ack(sk, skb, treq->syn_ect_snt); + tp->prev_ecnfield = treq->syn_ect_rcv; + tp->accecn_opt_demand = 1; tcp_ecn_received_counters(sk, skb, skb->len - th->doff * 4); } else { tcp_ecn_mode_set(tp, inet_rsk(req)->ecn_ok ? diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index a36de6c539da..a76061dc4e5f 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -806,8 +806,12 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, *ptr++ = htonl(((e0b & 0xffffff) << 8) | TCPOPT_NOP); } - if (tp) + if (tp) { tp->accecn_minlen = 0; + tp->accecn_opt_tstamp = tp->tcp_mstamp; + if (tp->accecn_opt_demand) + tp->accecn_opt_demand--; + } } if (unlikely(OPTION_SACK_ADVERTISE & options)) { @@ -984,6 +988,18 @@ static int tcp_options_fit_accecn(struct tcp_out_options *opts, int required, return size; } +static bool tcp_accecn_option_beacon_check(const struct sock *sk) +{ + const struct tcp_sock *tp = tcp_sk(sk); + + if (!sock_net(sk)->ipv4.sysctl_tcp_ecn_option_beacon) + return false; + + return tcp_stamp_us_delta(tp->tcp_mstamp, tp->accecn_opt_tstamp) * + sock_net(sk)->ipv4.sysctl_tcp_ecn_option_beacon >= + (tp->srtt_us >> 3); +} + /* Compute TCP options for SYN packets. This is not the final * network wire format yet. */ @@ -1237,13 +1253,18 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb if (tcp_ecn_mode_accecn(tp) && sock_net(sk)->ipv4.sysctl_tcp_ecn_option) { - int saving = opts->num_sack_blocks > 0 ? 2 : 0; - int remaining = MAX_TCP_OPTION_SPACE - size; - - opts->ecn_bytes = tp->received_ecn_bytes; - size += tcp_options_fit_accecn(opts, tp->accecn_minlen, - remaining, - saving); + if (sock_net(sk)->ipv4.sysctl_tcp_ecn_option >= 2 || + tp->accecn_opt_demand || + tcp_accecn_option_beacon_check(sk)) { + int saving = opts->num_sack_blocks > 0 ? 2 : 0; + int remaining = MAX_TCP_OPTION_SPACE - size; + + opts->ecn_bytes = tp->received_ecn_bytes; + size += tcp_options_fit_accecn(opts, + tp->accecn_minlen, + remaining, + saving); + } } if (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp, @@ -2959,6 +2980,11 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, sent_pkts = 0; tcp_mstamp_refresh(tp); + + /* AccECN option beacon depends on mstamp, it may change mss */ + if (tcp_ecn_mode_accecn(tp) && tcp_accecn_option_beacon_check(sk)) + mss_now = tcp_current_mss(sk); + if (!push_one) { /* Do MTU probing. */ result = tcp_mtu_probe(sk); From patchwork Thu Apr 17 23:00:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882064 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2081.outbound.protection.outlook.com [40.107.20.81]) (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 686A420896E; Thu, 17 Apr 2025 23:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930881; cv=fail; b=WbDcVS+vkszlWGG1sDPdEtqFmUSb9TP8vJi2/Xf0ZTvMSV2uXFFqK6FUpZUDvdEdjuHHBgqHpExzb2Oz/wsEOlzmTabbhIyrucvxpdfF48vcFJk2s1xLuDc4nJStuDDMHJYsHuvZAsrpdyu8raOK6HfkxH7wVAch1EemBGRcLxU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930881; c=relaxed/simple; bh=KD7/NR3z7EZK3pNxTn5FeoJCQ5ELLAzCb70Q6PtqoD0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=p016UKnapHRROIv+jVlzAj/vZ0w/UEcVYKtBK3PK5VANKunCV8QsOPrQD2eNNb6WBMnw+j8FEjwxHHFplj2EZ9ew7r1CeDTKT4nDJGXzIDj/M+5Vv9HMe63hiz/hGw7UgwJJ9Ee0lzNdUrstVpu3/qj5ownAYZ9xa3IUJIW1G2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=qgpAxqTc; arc=fail smtp.client-ip=40.107.20.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="qgpAxqTc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vgG1EuFZpBR66/6c81YYJ7GLFmxb0AmUfyEHfCfdvq2nw/hSGtC1LPTDJ65ny41HaiGiIaU0hT3lyZVN8zvNwSOspDmtPbJyoLcEjU2oZjLJWXz07uYeZnEQ6gQ206BD3A4y4iGmG6HGq/XlePd18oy63BjvpNW9w5V4h0QeJ3t4gdfhhgXneuKRiaX6Buk2IDJnofw3aDGp+kD3dgGobnLWjXv0vmX4ZMwT3ENj/p1AOZNRiUe8ZK3Uk3SCELWUsf67ukZbbltnroSkop4mfzA+Z1mcLZ1ud1BG4RYneSmXhHPh7pGT+N3eQPLpM12Nh0ZnTd5pF1DHJA7BuMQrzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fgX0CwSPtzsPeTZbfIpkANOIMszxeyMZ4gue9xFsyEQ=; b=kddzynak04KSOmah97SI4JnalWCP/rKRXQSFUD8MLHNxsM2Mr7qG53sxqICNG9isacRFR7K0/s9x+qUbzDaARTJw1IODwB/QP/ndwN3meglkRLOiWyEL7dZLacbGtrXA5p+XXOc2KOf44W+6M2ssCXjo4xDagHyl0BjMDuNuAj+g4XxUVFebp+j5512b4gtHUE3tVMNl7HblHwbbq9t82v78Cn9SLsWlluFe6+H895Lnh/lrEalui5B8954Jtj5sU+cTxWRlTgToWg1/X2yzIPfnAmHNxJ11NmTuer9fI700+EIcdcZtZPLETeeTbKMtL0J5LCicFx9OHroH+6dPig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fgX0CwSPtzsPeTZbfIpkANOIMszxeyMZ4gue9xFsyEQ=; b=qgpAxqTclUxn+GK+jvFlAe2lZ7XqBy8hkonh1A41KowEHPZXgHMW/8mw2NCqJhWGu04SreRzdIHuw3K/W6oZteTw4RhI6jUZm57wJmYhCPBWgBHBrTFQF2cZk3W1QsS9QgNF12Ej+8yURdJ2x+vIaUgXf0cCg1IX9tfud9sRJg5wcFYJnCYFUjer5ZnBD1wgPRMT//JH2x+jr3XuHru0xKXh22mTVmQAXpmCg3JrG+v6PoCEsvDjSD8e1XmFdo664utf3sJxX98BDFtbRpwt5/30gOz/PrQ8zbCKnXOKuSqBrzWH3/l07kkCKFqOm0Hi2v/2gH+W9CapAEL4QuO2+g== Received: from DU2PR04CA0331.eurprd04.prod.outlook.com (2603:10a6:10:2b4::19) by AM9PR07MB7844.eurprd07.prod.outlook.com (2603:10a6:20b:304::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.22; Thu, 17 Apr 2025 23:01:16 +0000 Received: from DB1PEPF000509F4.eurprd02.prod.outlook.com (2603:10a6:10:2b4:cafe::4d) by DU2PR04CA0331.outlook.office365.com (2603:10a6:10:2b4::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.22 via Frontend Transport; Thu, 17 Apr 2025 23:01:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by DB1PEPF000509F4.mail.protection.outlook.com (10.167.242.150) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:01:16 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id 3E7D120827; Fri, 18 Apr 2025 02:01:15 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 11/15] tcp: accecn: AccECN option failure handling Date: Fri, 18 Apr 2025 01:00:25 +0200 Message-Id: <20250417230029.21905-12-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F4:EE_|AM9PR07MB7844:EE_ X-MS-Office365-Filtering-Correlation-Id: 358a1f2c-2cbd-45bf-d8a9-08dd7e03c25f X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|1800799024|376014|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?1ElZn/NrgXzhRLAOPeFkUaOrKcFEIHM?= =?utf-8?q?3XKrh/bIJwr+9XweOi+FEOaJTYdUR23hqBcbfCW8pa3Ygau8TnKqcKP06JQsyUHZz?= =?utf-8?q?NgPKOkqk8r/TMMl5FHuKEGuQls5FMEaNCfDAjbyXXxadjEzH0/SxuF8XZFNHbrPGN?= =?utf-8?q?hrBmIAJIaaKXahxRSl2wTVvLNfbIG9HxQ8f4OVHnM85LC43+Kjo10iyyNgcB0xbTg?= =?utf-8?q?GjaBr1IrnFGc1LvceamptI96TCOZWcFYKyy080seBKFg+gSMJ99E+bMYRGVKEUUyO?= =?utf-8?q?rnDkngdRqOcDfBLEfpZ0hOw5OVGNoheLPWL9fDlE4nnUWkGDsmfh1829fLx5LNcx5?= =?utf-8?q?1wiRvQR6c1aYFVfGHV4dULJnJcl8kXn2FgE4l9FcYKfpFewIcIZt0vYmSDzW45SHS?= =?utf-8?q?kfzj9HsPxpFpJy9vjsgXdilHE9NDxWBLR/UMypNVhfX10KVpkWOfhopc6ZYfxBB+V?= =?utf-8?q?6N8BnKQS1fd5uhLOACxeJLH3OBqDnBiiZluOqlhNIiIlXa1agJypemvHYpWPY2hiu?= =?utf-8?q?o/udzD0vkSrNCy0roersxx4AYAbpuqQpHuV3ho/Znnp7ucc1Tjp2H1v8rJIAGv63O?= =?utf-8?q?BMLFm4Ef5Wz1DOTXaP0CgbFafZuC/SdfKlRMOJHrKZ5vxR72hhE6dyN8vaZnewYB9?= =?utf-8?q?fdc0rML3jancXcqBc+XO4HaCqB+RAe7x6fZB6WhX4aL9eh8YIa6uFxb01Ej5+gtI6?= =?utf-8?q?Zn8Vwts9VwUlaCgmCjF0NCKLw0OzQwr0j3TgM0fuk6SLTroQBxuhcq9r6BwpkgVQc?= =?utf-8?q?KvdxEty1Ib5LwGwkM/POeDB3WqlKjNR+E2xQvnYGZaxt1lwgBzSJFw1IgyIbnzJfo?= =?utf-8?q?NtPzxzqrMg0rhxKGP6d7pApfd10+ByUSxdoKOyylLBMkDhGqiaSudVXROJISYvLwl?= =?utf-8?q?crCU49gsM4oS4zTVcwAB2BBzbqEMavyrFR0N5nDSn7N7dbl0Zc0fo7gBOM0BuGwud?= =?utf-8?q?xCNw16ANUgNx+Yre6VqK0AGvL32BqK9AANchdA8sqVRBFD0l0AEg5TX565tDiKW/G?= =?utf-8?q?WU7DotbLQVqnStFZHJ0iU0DvkWdIgD7at/6HRaKTs0l3lKPyLWLhVFAJW0NQ4RadG?= =?utf-8?q?6KIwU8MK1A71pZb1jt0mTlWwsXLwzMnx6j38rWj+1sQqMe7Yfduf5EnrgSF3+1m9Q?= =?utf-8?q?+s8585LTnmLyD2j9NXhOrrttnK8d4NgguIEf/XWtAAng9Q53JZAyg8lygyR3X9lry?= =?utf-8?q?9/qqlqFq64zHz6qoqZsfoy6v8Xz6JpUzCyYoZHDOI0rwLZ+cmYBVUTxx6vwyZJ3Js?= =?utf-8?q?YIsc3HGogtxQx7wlDK/BPdffYSnLELw4M0Bhm37IoTfo7knV/yOPi/PXoE/BewfTG?= =?utf-8?q?PMC+Zo7KiGKTvL5yTv22rt8KYz9iMEj+W05I0ycwZwR6rAQ8EIukVvbbrYNmXE3GL?= =?utf-8?q?auNjY+H/jtCdkOMhgYiM5Vsk+bTbSVBfPNbn66EpZcMKnxTqAmU2GB3fvDcVjuAZL?= =?utf-8?q?AWIcVVMuDD8vFLMVKOr+WfwMU+YO7unw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(7416014)(1800799024)(376014)(82310400026)(36860700013)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:01:16.7082 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 358a1f2c-2cbd-45bf-d8a9-08dd7e03c25f X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509F4.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7844 From: Chia-Yu Chang AccECN option may fail in various way, handle these: - Remove option from SYN/ACK rexmits to handle blackholes - If no option arrives in SYN/ACK, assume Option is not usable - If an option arrives later, re-enabled - If option is zeroed, disable AccECN option processing Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 6 ++-- include/net/tcp.h | 7 +++++ net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 67 +++++++++++++++++++++++++++++++++++----- net/ipv4/tcp_minisocks.c | 38 +++++++++++++++++++++++ net/ipv4/tcp_output.c | 7 +++-- 6 files changed, 115 insertions(+), 11 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 9619524d8901..782e4dd58bf7 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -160,7 +160,8 @@ struct tcp_request_sock { u8 accecn_ok : 1, syn_ect_snt: 2, syn_ect_rcv: 2; - u8 accecn_fail_mode:4; + u8 accecn_fail_mode:4, + saw_accecn_opt :2; u32 txhash; u32 rcv_isn; u32 snt_isn; @@ -391,7 +392,8 @@ struct tcp_sock { syn_ect_snt:2, /* AccECN ECT memory, only */ syn_ect_rcv:2, /* ... needed durign 3WHS + first seqno */ wait_third_ack:1; /* Wait 3rd ACK in simultaneous open */ - u8 accecn_fail_mode:4; /* AccECN failure handling */ + u8 accecn_fail_mode:4, /* AccECN failure handling */ + saw_accecn_opt:2; /* An AccECN option was seen */ u8 thin_lto : 1,/* Use linear timeouts for thin streams */ fastopen_connect:1, /* FASTOPEN_CONNECT sockopt */ fastopen_no_cookie:1, /* Allow send/recv SYN+data without a cookie */ diff --git a/include/net/tcp.h b/include/net/tcp.h index 3ee5b52441e3..0ade2873b84e 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -276,6 +276,12 @@ static inline void tcp_accecn_fail_mode_set(struct tcp_sock *tp, u8 mode) tp->accecn_fail_mode |= mode; } +/* tp->saw_accecn_opt states */ +#define TCP_ACCECN_OPT_NOT_SEEN 0x0 +#define TCP_ACCECN_OPT_EMPTY_SEEN 0x1 +#define TCP_ACCECN_OPT_COUNTER_SEEN 0x2 +#define TCP_ACCECN_OPT_FAIL_SEEN 0x3 + /* Flags in tp->nonagle */ #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ #define TCP_NAGLE_CORK 2 /* Socket is corked */ @@ -477,6 +483,7 @@ static inline int tcp_accecn_extract_syn_ect(u8 ace) bool tcp_accecn_validate_syn_feedback(struct sock *sk, u8 ace, u8 sent_ect); void tcp_accecn_third_ack(struct sock *sk, const struct sk_buff *skb, u8 syn_ect_snt); +u8 tcp_accecn_option_init(const struct sk_buff *skb, u8 opt_offset); void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, u32 payload_len); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 25a986ad1c2f..8e3582c1b5bb 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3367,6 +3367,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->delivered_ce = 0; tp->wait_third_ack = 0; tp->accecn_fail_mode = 0; + tp->saw_accecn_opt = TCP_ACCECN_OPT_NOT_SEEN; tcp_accecn_init_counters(tp); tp->prev_ecnfield = 0; tp->accecn_opt_tstamp = 0; diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 1e8e49881ca4..8f1e10530880 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -446,8 +446,8 @@ bool tcp_accecn_validate_syn_feedback(struct sock *sk, u8 ace, u8 sent_ect) } /* See Table 2 of the AccECN draft */ -static void tcp_ecn_rcv_synack(struct sock *sk, const struct tcphdr *th, - u8 ip_dsfield) +static void tcp_ecn_rcv_synack(struct sock *sk, const struct sk_buff *skb, + const struct tcphdr *th, u8 ip_dsfield) { struct tcp_sock *tp = tcp_sk(sk); u8 ace = tcp_accecn_ace(th); @@ -466,7 +466,19 @@ static void tcp_ecn_rcv_synack(struct sock *sk, const struct tcphdr *th, default: tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); tp->syn_ect_rcv = ip_dsfield & INET_ECN_MASK; - tp->accecn_opt_demand = 2; + if (tp->rx_opt.accecn && + tp->saw_accecn_opt < TCP_ACCECN_OPT_COUNTER_SEEN) { + u8 saw_opt = tcp_accecn_option_init(skb, + tp->rx_opt.accecn); + + tp->saw_accecn_opt = saw_opt; + if (tp->saw_accecn_opt == TCP_ACCECN_OPT_FAIL_SEEN) { + u8 fail_mode = TCP_ACCECN_OPT_FAIL_RECV; + + tcp_accecn_fail_mode_set(tp, fail_mode); + } + tp->accecn_opt_demand = 2; + } if (INET_ECN_is_ce(ip_dsfield) && tcp_accecn_validate_syn_feedback(sk, ace, tp->syn_ect_snt)) { @@ -586,7 +598,23 @@ static bool tcp_accecn_process_option(struct tcp_sock *tp, bool order1, res; unsigned int i; + if (tcp_accecn_opt_fail_recv(tp)) + return false; + if (!(flag & FLAG_SLOWPATH) || !tp->rx_opt.accecn) { + if (!tp->saw_accecn_opt) { + /* Too late to enable after this point due to + * potential counter wraps + */ + if (tp->bytes_sent >= (1 << 23) - 1) { + u8 fail_mode = TCP_ACCECN_OPT_FAIL_RECV; + + tp->saw_accecn_opt = TCP_ACCECN_OPT_FAIL_SEEN; + tcp_accecn_fail_mode_set(tp, fail_mode); + } + return false; + } + if (estimate_ecnfield) { u8 ecnfield = estimate_ecnfield - 1; @@ -602,6 +630,13 @@ static bool tcp_accecn_process_option(struct tcp_sock *tp, order1 = (ptr[0] == TCPOPT_ACCECN1); ptr += 2; + if (tp->saw_accecn_opt < TCP_ACCECN_OPT_COUNTER_SEEN) { + tp->saw_accecn_opt = tcp_accecn_option_init(skb, + tp->rx_opt.accecn); + if (tp->saw_accecn_opt == TCP_ACCECN_OPT_FAIL_SEEN) + tcp_accecn_fail_mode_set(tp, TCP_ACCECN_OPT_FAIL_RECV); + } + res = !!estimate_ecnfield; for (i = 0; i < 3; i++) { if (optlen >= TCPOLEN_ACCECN_PERFIELD) { @@ -6457,10 +6492,25 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, */ if (th->syn) { if (tcp_ecn_mode_accecn(tp)) { - u8 opt_demand = max_t(u8, 1, tp->accecn_opt_demand); - send_accecn_reflector = true; - tp->accecn_opt_demand = opt_demand; + if (tp->rx_opt.accecn && + tp->saw_accecn_opt < TCP_ACCECN_OPT_COUNTER_SEEN) { + u8 offset = tp->rx_opt.accecn; + u8 opt_demand; + u8 saw_opt; + + saw_opt = tcp_accecn_option_init(skb, offset); + tp->saw_accecn_opt = saw_opt; + if (tp->saw_accecn_opt == + TCP_ACCECN_OPT_FAIL_SEEN) { + u8 fail_mode = TCP_ACCECN_OPT_FAIL_RECV; + + tcp_accecn_fail_mode_set(tp, fail_mode); + } + opt_demand = max_t(u8, 1, + tp->accecn_opt_demand); + tp->accecn_opt_demand = opt_demand; + } } if (sk->sk_state == TCP_SYN_RECV && sk->sk_socket && th->ack && TCP_SKB_CB(skb)->seq + 1 == TCP_SKB_CB(skb)->end_seq && @@ -6954,7 +7004,8 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, */ if (tcp_ecn_mode_any(tp)) - tcp_ecn_rcv_synack(sk, th, TCP_SKB_CB(skb)->ip_dsfield); + tcp_ecn_rcv_synack(sk, skb, th, + TCP_SKB_CB(skb)->ip_dsfield); tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); tcp_try_undo_spurious_syn(sk); @@ -7531,6 +7582,8 @@ static void tcp_openreq_init(struct request_sock *req, tcp_rsk(req)->snt_tsval_first = 0; tcp_rsk(req)->last_oow_ack_time = 0; tcp_rsk(req)->accecn_ok = 0; + tcp_rsk(req)->saw_accecn_opt = TCP_ACCECN_OPT_NOT_SEEN; + tcp_rsk(req)->accecn_fail_mode = 0; tcp_rsk(req)->syn_ect_rcv = 0; tcp_rsk(req)->syn_ect_snt = 0; req->mss = rx_opt->mss_clamp; diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index e0f2bd2cee9e..8bb4953fc8bd 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -501,6 +501,7 @@ static void tcp_ecn_openreq_child(struct sock *sk, tcp_ecn_mode_set(tp, TCP_ECN_MODE_ACCECN); tp->syn_ect_snt = treq->syn_ect_snt; tcp_accecn_third_ack(sk, skb, treq->syn_ect_snt); + tp->saw_accecn_opt = treq->saw_accecn_opt; tp->prev_ecnfield = treq->syn_ect_rcv; tp->accecn_opt_demand = 1; tcp_ecn_received_counters(sk, skb, skb->len - th->doff * 4); @@ -555,6 +556,30 @@ static void smc_check_reset_syn_req(const struct tcp_sock *oldtp, #endif } +u8 tcp_accecn_option_init(const struct sk_buff *skb, u8 opt_offset) +{ + unsigned char *ptr = skb_transport_header(skb) + opt_offset; + unsigned int optlen = ptr[1] - 2; + + WARN_ON_ONCE(ptr[0] != TCPOPT_ACCECN0 && ptr[0] != TCPOPT_ACCECN1); + ptr += 2; + + /* Detect option zeroing: an AccECN connection "MAY check that the + * initial value of the EE0B field or the EE1B field is non-zero" + */ + if (optlen < TCPOLEN_ACCECN_PERFIELD) + return TCP_ACCECN_OPT_EMPTY_SEEN; + if (get_unaligned_be24(ptr) == 0) + return TCP_ACCECN_OPT_FAIL_SEEN; + if (optlen < TCPOLEN_ACCECN_PERFIELD * 3) + return TCP_ACCECN_OPT_COUNTER_SEEN; + ptr += TCPOLEN_ACCECN_PERFIELD * 2; + if (get_unaligned_be24(ptr) == 0) + return TCP_ACCECN_OPT_FAIL_SEEN; + + return TCP_ACCECN_OPT_COUNTER_SEEN; +} + /* This is not only more efficient than what we used to do, it eliminates * a lot of code duplication between IPv4/IPv6 SYN recv processing. -DaveM * @@ -716,6 +741,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, bool own_req; tmp_opt.saw_tstamp = 0; + tmp_opt.accecn = 0; if (th->doff > (sizeof(struct tcphdr)>>2)) { tcp_parse_options(sock_net(sk), skb, &tmp_opt, 0, NULL); @@ -893,6 +919,18 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, if (!(flg & TCP_FLAG_ACK)) return NULL; + if (tcp_rsk(req)->accecn_ok && tmp_opt.accecn && + tcp_rsk(req)->saw_accecn_opt < TCP_ACCECN_OPT_COUNTER_SEEN) { + u8 saw_opt = tcp_accecn_option_init(skb, tmp_opt.accecn); + + tcp_rsk(req)->saw_accecn_opt = saw_opt; + if (tcp_rsk(req)->saw_accecn_opt == TCP_ACCECN_OPT_FAIL_SEEN) { + u8 fail_mode = TCP_ACCECN_OPT_FAIL_RECV; + + tcp_rsk(req)->accecn_fail_mode |= fail_mode; + } + } + /* For Fast Open no more processing is needed (sk is the * child socket). */ diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index a76061dc4e5f..8e1535635aab 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1085,6 +1085,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb, /* Simultaneous open SYN/ACK needs AccECN option but not SYN */ if (unlikely((TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK) && tcp_ecn_mode_accecn(tp) && + inet_csk(sk)->icsk_retransmits < 2 && sock_net(sk)->ipv4.sysctl_tcp_ecn_option && remaining >= TCPOLEN_ACCECN_BASE)) { u32 saving = tcp_synack_options_combine_saving(opts); @@ -1174,7 +1175,7 @@ static unsigned int tcp_synack_options(const struct sock *sk, smc_set_option_cond(tcp_sk(sk), ireq, opts, &remaining); if (treq->accecn_ok && sock_net(sk)->ipv4.sysctl_tcp_ecn_option && - remaining >= TCPOLEN_ACCECN_BASE) { + req->num_timeout < 1 && remaining >= TCPOLEN_ACCECN_BASE) { u32 saving = tcp_synack_options_combine_saving(opts); opts->ecn_bytes = synack_ecn_bytes; @@ -1252,7 +1253,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb } if (tcp_ecn_mode_accecn(tp) && - sock_net(sk)->ipv4.sysctl_tcp_ecn_option) { + sock_net(sk)->ipv4.sysctl_tcp_ecn_option && + tp->saw_accecn_opt && + !tcp_accecn_opt_fail_send(tp)) { if (sock_net(sk)->ipv4.sysctl_tcp_ecn_option >= 2 || tp->accecn_opt_demand || tcp_accecn_option_beacon_check(sk)) { From patchwork Thu Apr 17 23:00:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882062 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012007.outbound.protection.outlook.com [52.101.66.7]) (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 EBE282222DF; Thu, 17 Apr 2025 23:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930887; cv=fail; b=Ba/bop6mrmCeMBeyuiUT6N3MxUpD32IM7PLgXGXNRW8VUYDdgP7vrLPS5KkPmwnUAf6LOKu+4BG0efHB305tDGUwOJjIXevDtOb+KPjcyaiZHmg8TNj8oeAIDfzCO/y99/s3xreAFeLI2Mr3AlA5peSIKXmXLS2CWJZi9bAkaZ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930887; c=relaxed/simple; bh=I4ubTWT3RFl5BeQzn9ugdonkuIPtlIVxMelUvF756Yk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=gnFiznZjjXAaFUwhpJPdfbCbIob+Xa9knxV31D+rB/9iVq2BZfCQFRV0WL9U/+ADlGnjnFeoN4Bffsmk3fyUPuP24bvQc5V0f1j88wonNQo3Pf02U83PFXc5ykhLOrFBzzbNOSEzNUhwAtSxrz2XwjObnDN1CVV21PnWHxAq2v0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=pu5YF+dT; arc=fail smtp.client-ip=52.101.66.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="pu5YF+dT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=au3t5CM/lGK5mi5p0eKGTEm8wSlTISLujLr9btjZHfRQaM1WMFue2VOiK1Wqfu7T3uqyfA0C42shVxQvLANlhj4w5wbDYd6HnNQ2cfLAgfFDDm9Td8ginGnW1jEpk7L8YGaFSF7FiDH0ZONd/nOWMJ7S7TB1Vht5pVHUd5wLYMjCv2ZEbc3q1KQuQY8Jl01HATKTyMJqhU/RiXbeTL2ImTW3c5fnGdlMqXJTH/tLsRWyFkolfrWyNE5WkWWNfi9PdOvl73ePNKb+d07h5CJQQS3O3tLU0y33TuhDjOrUqFRhmc6y/wy/H7ZaouTORVIhk3jCR+yjF9cv5ZeJAV+lCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wjzGCXWtVKbrVv/LQ94yH6VK8X9J1eeWY+M2JK853FY=; b=mbljlDRBc9d9t7rPJMnKkHfWbAUUebSmInK5IiWuXEYGl6Fu7i0Dk1Q7OfzxLaXFgu+MjaYkTbYRB6yyUAHJstm7EZL7NJovnwiXEUhVzeOuxmgKW1BFPoi/7z7smP0kYbu1y3PoWw7eau0drLrIzICRPuBTHV6OHqfwbRtjBQPKREN/ssqwTwYdXiOLM5XMZku1pw3P3gjYAoNw2UYsPpWZyt45M+fYcSWj0ZCW16EL+7O98IsqXyVpp4Z+aN0LvkaB5rCgDBgYOID6/x4rA4fEckxn8MEJvQSAUS592iXztNaPdraMkChPCwLQi0g4boSGJtIwMLmCzEHwwnYY2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wjzGCXWtVKbrVv/LQ94yH6VK8X9J1eeWY+M2JK853FY=; b=pu5YF+dTy4fh3jBWb1R56pKpPfyRcKcTfWKPy8hXYIWAkCumrP6yBElaxCUuFp6mq33L3EeYMtZM7wZ3Vt9TO10OZu1Urdvjn6OdBX21XzZkMhEOu+FFt0Df1fLQUthDavsmVrS9TIzcuR89gw0J5PbGpKy4hYKjMlfHBCgXkgb1xIybnfvqTw0C/4UVuob2RAewKkKNCRga3MSOCwqxPklwJfwv8TOtLoNSX3JFzIEDIe7abdI3t/0tId1AfgOi6hxUrZr+rFHIlUUYdV3ka7M/pT7RO0z2kCWLBW8gy52u8P0QJxDH8qlONuuybA/5Z7eQJ0dhMPccFfQv/MI1cw== Received: from AM9P193CA0027.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:21e::32) by PA4PR07MB8648.eurprd07.prod.outlook.com (2603:10a6:102:261::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.29; Thu, 17 Apr 2025 23:01:22 +0000 Received: from AM2PEPF0001C70D.eurprd05.prod.outlook.com (2603:10a6:20b:21e:cafe::6) by AM9P193CA0027.outlook.office365.com (2603:10a6:20b:21e::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.18 via Frontend Transport; Thu, 17 Apr 2025 23:01:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by AM2PEPF0001C70D.mail.protection.outlook.com (10.167.16.201) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:01:22 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id B2FCE2084C; Fri, 18 Apr 2025 02:01:20 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 13/15] tcp: accecn: AccECN ACE field multi-wrap heuristic Date: Fri, 18 Apr 2025 01:00:27 +0200 Message-Id: <20250417230029.21905-14-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM2PEPF0001C70D:EE_|PA4PR07MB8648:EE_ X-MS-Office365-Filtering-Correlation-Id: dfac9e3c-748d-4f05-0865-08dd7e03c598 X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?HIe/qAbOV0pu6HvmTuiWGMjrCYvCJnS?= =?utf-8?q?D9QF2VFYuJlZeq0FILFdVSECM9oChIoqlr7cQkNsnZDW1KYaTzbqtjS28SVzhVcHv?= =?utf-8?q?f+F7vcB1BFILFV65BtIFI1i4Gb96uzUuJD0INKmMRaaBiNsBUOfwrCKJLMJKfMouH?= =?utf-8?q?uUC7Fq1C/Z2DWBAI93dUsQ8B9EJNCkQ6l/h4CYN/owzDwCy7bsZfK5ygGW/IEbJe4?= =?utf-8?q?rWsWAjzkq7wymVJQHoAJOxj3NaCWrN/tiC0ypOd4nEqArBii8SOVXgn7Gw6PUaOtu?= =?utf-8?q?zp9JAoac9CnwPlcCvXcBLgW8L8xFuvpNpZaFCXGYygwM0OGoVyoPXFn66cgIDJzOw?= =?utf-8?q?bF8FkhSv6hKjtERdDg0wfOvDv9fdaiFrSxZbeNpVfPoct5phaJAwGK2BkR+3ggylu?= =?utf-8?q?mYNn8wqT24XtcVZ0XH6ofpK/U83ZCMK7pdmw4W0jbNrLnIqpi+edbO6m5IEZkWnqM?= =?utf-8?q?RGPER2kpdjeVIzmWAOncjbAK6UEiAWm9p3sNdomlIvCRgj2RgSg22vS0NfrhgUi/E?= =?utf-8?q?34RY5RcbaKwKqtGpa+7C2F3ZM64pM5A3cWBQFQiH5xjGb/hdEHQBQrdfRU6lJUjrt?= =?utf-8?q?LAmKRNO88vi55TwnnJ2adlzQXNYeMNrhQ1SB1zqr0x2BfOWg/CrrWm18z9XxTZIhT?= =?utf-8?q?MEvMU77FDVxNWmRL6WYilP5y0ZaRcbQlwH+MZk8qx/6axFF6/pCyE/aUKOQPJgK2j?= =?utf-8?q?EK+RA//FU/WlDDs9wRxNRAU3PSYn8hL7RtxxT0Eupk+4mJv9jBmNN9W190V/vG9Ep?= =?utf-8?q?pbYtrJb6D+z1xZoy0q6pZ/XDKZB3NOm9u4dtqfAcL7Rwc6Rxhmm85TuJIN6CAJMXv?= =?utf-8?q?oygpkxB8CbnTsFoTFbgM7w0HF7+TISMiH/ZGtXWefmGXfA/CBX4LN3Vi8IwJy7ec2?= =?utf-8?q?pyYbcDsOOweFG9BH4oDfiRS0iFxah/PXPnGDm8T/C3bFpgKIveMZlyeuzN4g4riZX?= =?utf-8?q?rRnmBaCmEKKNd0LwIgYwiFRp9L24MjDBYrxpAvB5HtOOggQSoLvP20YqM97MykNm6?= =?utf-8?q?fLCi+ik3/U8KfCWDNv2RpqnVK/5GAjYw0ohw8Z5vdq1Vl1DWeKAVeN1Ne4qbWDzg1?= =?utf-8?q?BU70oM/e8cx1VE3PPTJLAL8OxB8WG6lTDkxUs0HRSQ22NGJTbSS9qwxmJGXuYBj5a?= =?utf-8?q?cAg1ZNd9y+xX1AR20MoxGVfT+zbLTy4/Kd3nStyr94lkU5m5bWje3KVWejAO0SddA?= =?utf-8?q?l401knlxZxMlD0Gq4E8GmJAyR7W1UrzyHpsPz0pO7YWjdAGBsOtaqkzh8rxybHTs5?= =?utf-8?q?SJfzoTr4wYjEzCAsnCGryK67JOWkq6suYLa6bebZNkIDkrIqQZDIBiBylbqf6Px8v?= =?utf-8?q?aBpglo7nmxpTgtKjKIIUmw8QlrOX1YWeW81N3z5nS6bGUkbUUmPzktIFxN5oqL0/W?= =?utf-8?q?EnJU+ofsqBU6xVJ+tx5YNsH0ziG5iJj0KUnMv1CXywCJ3yYsBi3erKp0lHn8M0P1/?= =?utf-8?q?UhbMgc4nkrsD24p2P5kr05QklO/ZJaGA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:01:22.1086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dfac9e3c-748d-4f05-0865-08dd7e03c598 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C70D.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB8648 From: Ilpo Järvinen Armed with ceb delta from option, delivered bytes, and delivered packets it is possible to estimate how many times ACE field wrapped. This calculation is necessary only if more than one wrap is possible. Without SACK, delivered bytes and packets are not always trustworthy in which case TCP falls back to the simpler no-or-all wraps ceb algorithm. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_input.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 54f798161d14..c6dac3c2d47a 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -733,6 +733,24 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, d_ceb = tp->delivered_ecn_bytes[INET_ECN_CE - 1] - old_ceb; if (!d_ceb) return delta; + + if ((delivered_pkts >= (TCP_ACCECN_CEP_ACE_MASK + 1) * 2) && + (tcp_is_sack(tp) || + ((1 << inet_csk(sk)->icsk_ca_state) & + (TCPF_CA_Open | TCPF_CA_CWR)))) { + u32 est_d_cep; + + if (delivered_bytes <= d_ceb) + return safe_delta; + + est_d_cep = DIV_ROUND_UP_ULL((u64)d_ceb * + delivered_pkts, + delivered_bytes); + return min(safe_delta, + delta + + (est_d_cep & ~TCP_ACCECN_CEP_ACE_MASK)); + } + if (d_ceb > delta * tp->mss_cache) return safe_delta; if (d_ceb < From patchwork Thu Apr 17 23:00:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 882061 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2047.outbound.protection.outlook.com [40.107.21.47]) (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 67DE21A5BBB; Thu, 17 Apr 2025 23:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930893; cv=fail; b=mZZ2B2oKtuGd8PXDIezncNwQMH3FE3cnBu0WOdejT/pGxt6HzpivlO4yboSfc9YTSJaQxiwk7zVyKIsz8EuA/oRy/bXuFx5qdSlN1j2i/0lajOTtij85Z3b/h0qqLDMf2q8CGoY+Tgkbdc7SS9BwrUBEDc8sOg5uC6X6aoJG7YM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744930893; c=relaxed/simple; bh=BO2C7Yxj1XlxijxJtesTYtQsvKTzVV3DCZRpIE1vjs0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YOgzHLqIn9iT2EUXrjZikNSFeJGw1X0qLNyPzdmXQlFuej0dK2U5tzaecGvkYBcN6wJ0loYSU9YBP114i6ziHZszYYKkYluPoP512KcDKs+3vsSpchZh+KoWRRnZ1nFXZW4bkktgmHgLKGmRC9AtjBaH/C02nlz8X2+bHufC/ws= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com; spf=fail smtp.mailfrom=nokia-bell-labs.com; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b=dgRDhjn8; arc=fail smtp.client-ip=40.107.21.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia-bell-labs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia-bell-labs.com header.i=@nokia-bell-labs.com header.b="dgRDhjn8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kOCIfmJwz9qAPfsfl/GvUFcr7z5lS97O2HfpwJAd59RA4pjviqtqnWOAhVGg3rnaytd6W5YYziWh/fACa4G8PfdJSD5b9aei/H4HLO4gO7uVnXHeLOcA6G1H4YVCIsPMFvnLIOGlra4TDmpJTNJMQMcgkEgslsrpg1g2/r2yUzwN8HYUiZDNLQKLi7lv27ge8slxFwkemhKfHxvcwJ+0fj4tWJx/zlFRHmny3Z+b3eA3Z8t9q9Ia/y/QNG4RC5O23/ZuDka8Evft5nhZY/JC97petV1mXTOxnwqSOfzJpSm3m4JllUhvphBIdS4pcc5cx5iMnNWfLglAkTTvrAFXhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UcWHWlz+pn6+3DSlonX0uLWbfhn5DkxcFeo+8Nqq6jU=; b=K2uoQZ0aFQooV7K2zzz2DWcn40KQJfOYkS47trlNrdViOkl0PTezvbesSaAwk/xyq2Ih6AKMkAfgrOnOu8/bu67gy0SF1lWKllg4VvRrf/RlKHkH818bSgC5KSYzHq4PYvZnnfyVljNY1a6FHs0Ng9PfcHMFtCKmEgcXWqVAuhFrFEs3BhIP+xweeW2s+MPKBOVF+I7jCZkwvBV3832a6cFvesdUMpgyLqb0vEc2UBjHampn9ovd/o8xb1l8X7WD9j+io+XfMo/6kJoBT/HI5pX36oVbpyGPwlfzrNBCs3TlHTkznPdhaHpDqZAr9OWV3HPshiaQIXqThbRxAtFJQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.29) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UcWHWlz+pn6+3DSlonX0uLWbfhn5DkxcFeo+8Nqq6jU=; b=dgRDhjn8ybC6IdBIx+ch7yduejZR2tWyMVR8cVL7L7KazDzB5bUEeAIC7HpXgrYsBT76eKdxU5esBbnBgUn+6+/sGyjy3jQAXmnGnYm7ksv6WiQ8CJjJPij+ATW+rUStAP5z+OlPaHDAjazc6ztB70mZ10Hs84Xxi7Rk6awnsE94ue+oOcj+iknWNU1BCHSTzdPla2VgF3YtiR/feaAg3hiOTK5ab7xzYCx8O0xy4wXip4afDQ1kjWm1NXzFLVj5nyluTd5kyDbvFiI9ddY6jU3ElRryPsFsMVTEviC+kuY6Glyt/DijjANR1zWoI9llQPoSvS7J4D2BiFkjyacQlQ== Received: from DB9PR02CA0005.eurprd02.prod.outlook.com (2603:10a6:10:1d9::10) by AS4PR07MB8899.eurprd07.prod.outlook.com (2603:10a6:20b:4f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Thu, 17 Apr 2025 23:01:26 +0000 Received: from DB1PEPF000509F8.eurprd02.prod.outlook.com (2603:10a6:10:1d9:cafe::ef) by DB9PR02CA0005.outlook.office365.com (2603:10a6:10:1d9::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.23 via Frontend Transport; Thu, 17 Apr 2025 23:01:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.29) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nokia-bell-labs.com; Received-SPF: Pass (protection.outlook.com: domain of nokia-bell-labs.com designates 131.228.2.29 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.29; helo=fihe3nok0735.emea.nsn-net.net; pr=C Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.29) by DB1PEPF000509F8.mail.protection.outlook.com (10.167.242.154) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Thu, 17 Apr 2025 23:01:26 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0735.emea.nsn-net.net (Postfix) with ESMTP id 4D84D2081B; Fri, 18 Apr 2025 02:01:25 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, pabeni@redhat.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, horms@kernel.org, andrew+netdev@lunn.ch, donald.hunter@gmail.com, ast@fiberby.net, liuhangbin@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, ij@kernel.org, ncardwell@google.com, koen.de_schepper@nokia-bell-labs.com, g.white@cablelabs.com, ingemar.s.johansson@ericsson.com, mirja.kuehlewind@ericsson.com, cheshire@apple.com, rs.ietf@gmx.at, Jason_Livingood@comcast.com, vidhi_goel@apple.com Cc: Chia-Yu Chang Subject: [PATCH v4 net-next 15/15] tcp: try to avoid safer when ACKs are thinned Date: Fri, 18 Apr 2025 01:00:29 +0200 Message-Id: <20250417230029.21905-16-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> References: <20250417230029.21905-1-chia-yu.chang@nokia-bell-labs.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F8:EE_|AS4PR07MB8899:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a19c3f4-66f5-4799-286a-08dd7e03c867 X-LD-Processed: 5d471751-9675-428d-917b-70f44f9630b0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?FGugsfy7EGCq1snWYFjW97D+shk5nsZ?= =?utf-8?q?8VR2vrtKSbsHYX/075zMSx2IQN+Kq+4kAh03NGqrxLj78XAzqwdvBPaddexpTPt5U?= =?utf-8?q?KOIKGCZp3M9tHwuiV5gGGh7z3lEfRF345IMEI8JtTK/B+AJdeSGIyM8RjoLP9S9w1?= =?utf-8?q?zbe3gH2LWGX3L/87opukj+QKL6PXm8P4qy2gM7pynxsLnTarNV1QOn8BwpR22Sj9j?= =?utf-8?q?94Bu+P7mnbqGQA5ygdbVNRMmP/RJf9o2/9BhES6uUNYrVwaXu5wS/QDtoLxJ9llQT?= =?utf-8?q?YeMcqoXY4XRFAWjtIdjhLI4VYCu7hiwMIDyJmwQwRXufJxRVjtWOs8nAoYw6NIYaL?= =?utf-8?q?sO9eZL6jl6pnAfTu5CFuwc+DJEWuCk3fC38crHZjV9cOVaCoQC48OzQv1Qg8nVcOX?= =?utf-8?q?aAu+ejGsBRj8FuXCVoCQ05wV0ocwRdZdb8fH9vfKpyB2osYX6jYt2QP0YhMLUo/FV?= =?utf-8?q?CYN/on3aFUab63AIhQUwPL3xjSttaQISgn9Uagt/ohsCdh2KrqaEVy9Fz/CJN8J4b?= =?utf-8?q?+ZaMYl4olbcebcOfKMzzawi9bMOt0z43gJ0VSDPi4D+E405x9llsLZ+N+AmXtZulv?= =?utf-8?q?GpSzs0rn/krPMwoG3IU8VaRoot2s2TnUMWeKHehl+fPHoSfsUqc0Tr500iLnpsovL?= =?utf-8?q?55+pUi7/wXjR9jZT4UcYstr17fwHHpZU7fkf+FG/5Dz6WQl0I7MQB0l7ceqSkn4TL?= =?utf-8?q?qUKihvgMQ5XNs74/tOKlD0FJBchp7nup/nYwEH7dG9t0ILRlkoeB2fFYk6u3ECczK?= =?utf-8?q?Zg+2DXlzx+TmYi4UfjGtmE4uLcuTd+QazW4PzmmR0uL9lD7cE9bNMcomq9Oey78Jc?= =?utf-8?q?xMAtsfLKJ8p42/pE1fcHrfDsAH+aN273AcP2GSfRHXENLUMpIA7TMu1b544Tb8THT?= =?utf-8?q?Rys64ZzZ/SmP8QMlJzx5L7mNeEJRU+EIwhZ51TPOIlRLKA8rGYchZWwbPR2oqlujR?= =?utf-8?q?rt53P2kixWi3f1mOCZhP8TjUkHu06mo9Ooj0Kboz+cSBcFA1UmCR1YZ1gY64+6whl?= =?utf-8?q?CHD1Fa7OhEUnA0TPZO5ZkAcWU9Ssk3xBq/rJ/fYNdE8QeQa+77ru1HblFFeab9MYm?= =?utf-8?q?0W+p5B058dSXIM4sJWp4p20fFaP/LP1urCD3jX/MsFWuken16Eu6fVQGAW4orFqxd?= =?utf-8?q?Qcm81cmn6idxqx2BSQpPsxpDL+o7MKAWUF2McSkE6SUzm/riDmrhlQ4kqUD1xsjPp?= =?utf-8?q?O2xfax+2l8At1zlUrbvSHCLLw77X8yDI228ooH0QYiNUX14RXHcRfGOInAvEl9GZK?= =?utf-8?q?BOKM4tTmBbIM+AbzyS2Qg0e0+mH3ZwyD0EbdPSmhe25grHuhfosl+Egf18F/bdNGf?= =?utf-8?q?3cWhurIaco0Ml65BjgSWwrBZ9ZfM4nTUJRj8m3+SB2G+BC486/v9qhSlXyradK2BT?= =?utf-8?q?AzR0okVokL4/S7dlQ0jBXFXU896v8YB4jJBQJjbAtutNpyO630k63R5VqtZMLW1BF?= =?utf-8?q?zWA+ltmezAMRvVTSoHSP0hU0Fv2bupug=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.29; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fihe3nok0735.emea.nsn-net.net; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(1800799024)(7416014)(376014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2025 23:01:26.8227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a19c3f4-66f5-4799-286a-08dd7e03c867 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.29]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509F8.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR07MB8899 From: Ilpo Järvinen Add newly acked pkts EWMA. When ACK thinning occurs, select between safer and unsafe cep delta in AccECN processing based on it. If the packets ACKed per ACK tends to be large, don't conservatively assume ACE field overflow. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 1 + net/ipv4/tcp.c | 4 +++- net/ipv4/tcp_input.c | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 782e4dd58bf7..230f55b22a51 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -313,6 +313,7 @@ struct tcp_sock { prev_ecnfield:2,/* ECN bits from the previous segment */ accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */ est_ecnfield:2;/* ECN field for AccECN delivered estimates */ + u16 pkts_acked_ewma;/* Pkts acked EWMA for AccECN cep heuristic */ u64 accecn_opt_tstamp; /* Last AccECN option sent timestamp */ u32 app_limited; /* limited until "delivered" reaches this val */ u32 rcv_wnd; /* Current receiver window */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 8e3582c1b5bb..56b6467df18b 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3371,6 +3371,7 @@ int tcp_disconnect(struct sock *sk, int flags) tcp_accecn_init_counters(tp); tp->prev_ecnfield = 0; tp->accecn_opt_tstamp = 0; + tp->pkts_acked_ewma = 0; if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release(sk); memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); @@ -5109,6 +5110,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, delivered_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, pkts_acked_ewma); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, accecn_opt_tstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); @@ -5117,7 +5119,7 @@ static void __init tcp_struct_check(void) /* 32bit arches with 8byte alignment on u64 fields might need padding * before tcp_clock_cache. */ - CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 130 + 6); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 132 + 8); /* RX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, bytes_received); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index c6dac3c2d47a..5bdd82d3c201 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -689,6 +689,10 @@ static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered, tcp_count_delivered_ce(tp, delivered); } +#define PKTS_ACKED_WEIGHT 6 +#define PKTS_ACKED_PREC 6 +#define ACK_COMP_THRESH 4 + /* Returns the ECN CE delta */ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, u32 delivered_pkts, u32 delivered_bytes, @@ -708,6 +712,19 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, opt_deltas_valid = tcp_accecn_process_option(tp, skb, delivered_bytes, flag); + if (delivered_pkts) { + if (!tp->pkts_acked_ewma) { + tp->pkts_acked_ewma = delivered_pkts << PKTS_ACKED_PREC; + } else { + u32 ewma = tp->pkts_acked_ewma; + + ewma = (((ewma << PKTS_ACKED_WEIGHT) - ewma) + + (delivered_pkts << PKTS_ACKED_PREC)) >> + PKTS_ACKED_WEIGHT; + tp->pkts_acked_ewma = min_t(u32, ewma, 0xFFFFU); + } + } + if (!(flag & FLAG_SLOWPATH)) { /* AccECN counter might overflow on large ACKs */ if (delivered_pkts <= TCP_ACCECN_CEP_ACE_MASK) @@ -756,7 +773,8 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, if (d_ceb < safe_delta * tp->mss_cache >> TCP_ACCECN_SAFETY_SHIFT) return delta; - } + } else if (tp->pkts_acked_ewma > (ACK_COMP_THRESH << PKTS_ACKED_PREC)) + return delta; return safe_delta; }