From patchwork Mon Apr 14 12:59:30 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: 14050398 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2049.outbound.protection.outlook.com [40.107.104.49]) (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 201412E62AF; Mon, 14 Apr 2025 13:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636803; cv=fail; b=Ge182M3VNqxjDlMDMIFrqh5+qS63jjzl4lmBsh7OuNoLJYaFaWoQXx4U/lOBU0lcKXp6tslzvJZ6QHk1H5Advbeb3/isrXOeN+l2gy0QUn3+NGqJFSHeQzWSchQt/tLZRbo6fAxeKGwGM89sngClOF4b/atLnfkEuphnx5KigYw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636803; c=relaxed/simple; bh=PYyCXUuKVKRWlC5fYTcacULQXbuy70otEK62ZKgXQqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jbEdfXm/Arai6GydInZFiZlyvxswWtoGj/I9TYURnMT5HNB6Hee2MtOeIHEk5BlRn0uV4TkeQcegtbMPtvbtmW9/JReSSIMQkdkbybUR8ByLn8dkGv+PAkLm5IqAjXYpm8+FZzBoRBsvzowVVGnirSknfoe8Rp273QE0y7JTLow= 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=JrWKNQkd; arc=fail smtp.client-ip=40.107.104.49 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="JrWKNQkd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=saZT2daRW1V9u2CVwnxUCz1O9eWm/aJ09yFVFzzodjqgrdT1tPGcxst8q8jbOe6hNbUIHAYQrQWekafXouTxLi8akT4lCLdvQv7+hdZJzKB+Mp8X7+TDwiUhoGax5n+fnEVT6NhNK467MPAcvBrWqZlbmQE0Ra1yNwV/ktXKzuGddnofd9e4cBqu5Vv98YqW3hhfcHUk7UUCMdiiGq7Mo2RyqnsEFLmv7eQE1k0IPCPb6yhz+8FLSIRT2RUTrI/gSHjqTzLwwEinwHUgHR4gYLgKNRb9juwKNu58sak6nNbnFbMvJwMFYUE9AvOMmlj8li/76E/7J6/KxsHR96Virg== 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=yEFVFKN8ThLo5Ycg8ISHMYLynpxeQ5dnWTIGEd5UTr+3DI68ZGDOg/CdDGWpKv7GYI+hYTlCfS4DByo0NrQamietTDBnJ7fvVT+OrTeLehMiOKGRgX0HGwGyjBFxfsaRGkx8VaxLsVzlOJStA61ZiSythwTodI1mR8NrkfbELumwVFeCNIeABB9A2ojBGh0z1G0OKnpmGBkKIu/NgooMRrMJJbmNKWkXUp0rONDd5lc5suwfDCmyrcarCMk8RgqbxvVtJHCcAOjM80Lk7NBD1Bfe78CnA7N8tNzA1xk78jXLy5Z/at1YzhAoxQ+2fW2OiSUTwhyb84XGb7PKXfOkDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=JrWKNQkdnmjbPXndC8N1DHDCs9qtBRwxNJbenhbREANWbPcGoaPEekuRLHcSee9FCoqGxIXJIBNHRcw7+T+aU5tJmBTruBoh7yde182N/OZd+DOaVcjzZ27T/xJaTdxM4UAElwG7jJYrXcajuC5q46/tNskkiY9Om7zIXfEL9zRMkLqhvasI4SGmEJdENsu4Qs2e+YSgu1oiOy0BgNFBB3RMLbuIYjzFKkbD+gFgTnj6y522duwym9er9ljLgL4+n6JyjJVK/CHOiNgGjQY5/RjMbciaJz4nVjIV2IXo5GNMBGyqMfHmVPTYVI/RAcsBw792+noKfDntEHET8llY1g== Received: from DU2PR04CA0043.eurprd04.prod.outlook.com (2603:10a6:10:234::18) by PAXPR07MB8699.eurprd07.prod.outlook.com (2603:10a6:102:245::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.32; Mon, 14 Apr 2025 13:19:53 +0000 Received: from DU6PEPF0000A7E2.eurprd02.prod.outlook.com (2603:10a6:10:234:cafe::8) by DU2PR04CA0043.outlook.office365.com (2603:10a6:10:234::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Mon, 14 Apr 2025 13:19:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DU6PEPF0000A7E2.mail.protection.outlook.com (10.167.8.42) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 13:19:53 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 80A0C4EE4A; Mon, 14 Apr 2025 16:00:06 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 01/15] tcp: reorganize SYN ECN code Date: Mon, 14 Apr 2025 14:59:30 +0200 Message-Id: <20250414125944.97350-2-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DU6PEPF0000A7E2:EE_|PAXPR07MB8699:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fbbe64b-cb65-44cd-1f71-08dd7b570b19 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|7416014|376014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?mLDH7MetMaMzXCHb9CPLiw+JJWj4rMB?= =?utf-8?q?IzIHaX9umfoh5s+iw2RwR73l+rYqEL3mOzk9ru2G4f2nXlILScnz+mSRfpAuwSM9c?= =?utf-8?q?wfFUF49Z1g7zloO4XDLXpzc4wsqeYJ5ZcfB9zJLoD2NWp6NAgwlRPKx9scdaht0EB?= =?utf-8?q?soZjTPgKdEOdVeVJLCxymTXXZzfwOgfBN7tug3bxBSe1/gqIIUIwlbSFU0mgBx8Jn?= =?utf-8?q?EQ+VaN0h9ZAAPCp/DEIB5JtfykxaYNbQli4y2jC/QgALX2gIVJlrpQ6NO+zr+D0Yj?= =?utf-8?q?kHqm9plHHZlHKwvNymaOo1guTjEEU7KrxBjnPsNvOinIuYYIAmHwhFNYSd+NBbHEM?= =?utf-8?q?8s6NIrJuW7TarOGUrZmwUplDdprPbhutHAkCBZJQWBSuLPoFBl1sa3eZ9DE8FxC3t?= =?utf-8?q?pi0D7MkCog99GYMI18xfCSc9W2ImWLbA3EReODwgyJ7X3BjfPPp6IBxc9N52t9v6g?= =?utf-8?q?hQn8OnWg9IUgCrffB/s1ud2ob32aDvIY9g6V7eRt2ui8lpRGa4ZcEN/WPfNtSU3xc?= =?utf-8?q?3mgbb2+E0i9TlYgKVxLC44yzpUme0wN3CIYK98p4igcxb7z2BYkSYNkg1uMWZ2MwG?= =?utf-8?q?F69PxDoQ/cq++9ekEX5UPoNzi1AvpeprHU0cihWple6jiQVZWybltvb3C03t7UPCk?= =?utf-8?q?lh3ynLZvG5IaDs+Vx8Sv7gEYZ8lkHzz57pwC339Q0vZiOlFsMsSWpm7DtUo+5Q5NF?= =?utf-8?q?HS8EJyKUcg8jUWqWdl8IEiBSZIv3hedDY9cWCFfzA/iewDNQMxXvwQypy279PHpnf?= =?utf-8?q?xxw+laiCa7j9Yf3AtBC35xECVcuC9ImFQ3Jp3KENtyK/oEGPnCAv/0k2AuyqKLPzn?= =?utf-8?q?FI/4KDhNH0daLzmvfsh3YXgZ1jrAyX/OOnHfjVm3yDTj578ydVlunU/96SI/FzgQV?= =?utf-8?q?tTn/Clw9rAF7pSCB4/KWQK7aHe0YSseD+nd6cvEkMFV0ecukY+yFl5e+OXRjKP8Sq?= =?utf-8?q?bxJP1L/u4qIWARNXg03+GBlBbN1UyTnEGUYxk1D/DUEMojR7v1r5QObpt2IYotf1q?= =?utf-8?q?nokMrTYdXhjc29mmeM7vptC6sCPjEh6I5z/gPYWhghR/D4M91oZGXxw/YFb7pBqX4?= =?utf-8?q?xLXm0GY/endYQPQCU5HBVQm9Fb0KbkA60clHBSVjOhfiuOPZh9C2ojufMw0j33QIt?= =?utf-8?q?x09r7FVY6jlpBOMkP2WDIDZZLMpjcFmDmznN7j8kDVrieQ4LtJ/pOuAe4CzwbbqYW?= =?utf-8?q?uQ9LA5JX8g83sKN09yrCN+BauOoO926vgHWW46sfMzfgHyRjH2Zcgs0tVihluwUU1?= =?utf-8?q?AMsKg1giW0fwimdz/PSapOygOZoFMphDa6V6xNi3DN4tepsI5F8XAEtGOoT9j21EW?= =?utf-8?q?VI/0TjMbm0lCo+PHNTMUaWDdLEtrm1M/h/Jo9Y0HpgwPp9j0gsYwojXE4F0sPDrgH?= =?utf-8?q?0MfrTx465MXsachWaBb+pnTCKL5rCSB5mtGcERniIwbbGquGXZSnmQO5yGDVUkyLs?= =?utf-8?q?wtNo8BD9YisRASqhIFQK0xhJW3d06kLw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(7416014)(376014)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 13:19:53.3482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4fbbe64b-cb65-44cd-1f71-08dd7b570b19 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF0000A7E2.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB8699 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 Mon Apr 14 12:59:31 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: 14050397 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011008.outbound.protection.outlook.com [52.101.65.8]) (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 2222A2E62B9; Mon, 14 Apr 2025 13:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.8 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636803; cv=fail; b=H8XHv+QJLRwb0ZninndS3GdCaAzsYPUAlw8AsiRaN+cmgfJMTlniAtkuSNevvU9Fg9hVAf9vISi6Gn8xTxfekB3nZrtn4cbMWgQppmzSlyoT2InzOmy2HJoPNpeQY7DdPysfZqDZb3AV9V6JtqJeFwxBVrZye9Mgwtoc/w4U+o8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636803; c=relaxed/simple; bh=jzGjlVHTjyWEGx0OxJrvgDWNiNQ6gwMZm/yT5kX2loA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XJgFHNyAh2LJlI39xhbP1qp7ML/+A6v4PaFMLkiareFXTgFp/6qXhl+Fn2dI1xXnmdy2+NDLBk3F/636LUe+j8W3zILjbiiAH7+5AqwEiBHuqD6VHba6Uk0y2MJ7O/ZMVtBnfngBrHtdANpwTS6x3W562l0iAoZSG04lVGnV1B8= 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=R9Gbqz1p; arc=fail smtp.client-ip=52.101.65.8 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="R9Gbqz1p" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yUgg3D/myn+alDPUaFu0v6v9pd86yMzak+kx61bu1/5iK83Y7TNNwPqmdjQTIer4hDxthaFApjs9JvgGmWun+p0imkVAuYgaM+0iLzWzuv19Gd3TqxMrWBwEmTQTyN5x0uI7kJberAtcjXKV/Mle+460odKqMkuZUouGegBn9Fu25agXdC4KxgeYv3NHXnEIKuteKmp9ukKylwy+pc9jd2utWZRQ0YjMPyMQuWeLJ/f5i/HOcLBw9JdAaK2Uv5bK58LrTIDbU4bn8TRoQv6eQ6Ai6j3GGvzBmvkQ+LfWQvIwgkPA1Jy5hBrnuUHIPqn41QydgEViygk0zdRcj77yhg== 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=aP/7Psq07ihqriJaEJ63jaVwaWZLAB4da/DunpSK6As=; b=qWvoeFl3pOzDu77b2fyBbrSYMzrlPjal1YYxkrRyeD0Gd++LkUrVlSxAXsbk+uzZweo6uPJFWj4Pb3Bo4I7qqDWWvRm8DBnkf6VYJpFd6ZGOIcXaR2VoS//QUtHmH2yPpMCnfyi3PzsiuN+qkMoERTJbnhgX8b5pyhrGHmT8dp6pNAsrzpqcjhDv+51hjUsI9EtLXKB0cb8gK7QaDzRVEeQ6wA8XiwzoWFedgm5tQh9ahBjTNWcM87AEiZW19aQ1SOIj+TRuI1nWEUNpN5jYos1Z3+us9830CdG0saUm58aRXwXepwO1WWR6Wqw76umb9O/go6p6FZZjAO/TVJLIFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=aP/7Psq07ihqriJaEJ63jaVwaWZLAB4da/DunpSK6As=; b=R9Gbqz1ptEgNScOGaUtx5jJIdPfA23DcC+KzL8C9fJooVNkX0jc81FiBMl3DGB4nh6+v14vSxW4Pg1/d3l7OuDvjo0eIISKL9T7+iDo41icTGa8tnQuyjoba4l57jr/WsHs6Edu464xQnx6SA1iKeh7kw3BIYe9RdDpvHU7QE5xt5asDBM74Hm+NqO0AZdT8alY9u24w5QEvDkdst1wv0rn/oo1W/tjbmkxtAH99weEzB/a/V3YZKqZ+hcws9FIg4hAiUQiBg+SHG2w6qd65E7zNTed0hE7Cb2wYuTcC3FdRvV4rbOzjvTqL0Fcclqo3+kMqy18Tj2fBY5rW18Ndmg== Received: from AS4P191CA0034.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:657::27) by DB9PR07MB9835.eurprd07.prod.outlook.com (2603:10a6:10:4c1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.32; Mon, 14 Apr 2025 13:19:53 +0000 Received: from AMS1EPF0000004A.eurprd04.prod.outlook.com (2603:10a6:20b:657:cafe::e8) by AS4P191CA0034.outlook.office365.com (2603:10a6:20b:657::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Mon, 14 Apr 2025 13:19:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by AMS1EPF0000004A.mail.protection.outlook.com (10.167.16.134) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 13:19:53 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 8A1FF4EE61; Mon, 14 Apr 2025 16:00:07 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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: Chai-Yu Chang Subject: [PATCH v3 net-next 02/15] tcp: fast path functions later Date: Mon, 14 Apr 2025 14:59:31 +0200 Message-Id: <20250414125944.97350-3-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: AMS1EPF0000004A:EE_|DB9PR07MB9835:EE_ X-MS-Office365-Filtering-Correlation-Id: a2dbf8f6-69d0-447f-785f-08dd7b570b0c 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|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?YoRGhNVFKUQfkd0KetQoXr6Ed90ykqP?= =?utf-8?q?FEiHQGlySX9h9Z3JTh6ufPtGSjISL7D0Ny5SCp4KU1BcV6jMjtlArgn7E7jAWtiM5?= =?utf-8?q?uVozTGqjn9Qg4CSG5T+Os6qcvjE67eaO3OPHdyRKT665G36cQ8pnhaYxWZ6NHaOpu?= =?utf-8?q?4w4UCZINaq1GY8Of6qNwGRmIkAF0+SNGw/OBhh+kPMkGGA47QNeptuld0/ux60tIv?= =?utf-8?q?XXWiCng1elHgFLx+GrMyyE+ztic7q1qLceeUk4UcwOx5YCo9ambd7bmCCTaUqUPDp?= =?utf-8?q?9RPGMWmb9Q7E9gDum2Fcw92JsBGB+dkLamog9FFKKJI+olgAP9gQBSTW6sNuu25V8?= =?utf-8?q?orgjcK81AHm8zYx0jVOalk7QMolo7e5DKXtzDygbnohl+1Z937HeKcYPV25Af5dy0?= =?utf-8?q?qgTOoQKD1vXjsDKIlQCz5vdVTcrr+k6QFoB4l9qNFOqLkBDwl0tB6Ih6/+bow+M/K?= =?utf-8?q?p1TPjXbXBMAS3fKZcWhjjvKbL4IlrBfSbzVxtilKk3/IPwjfHvZ/M6mwdCMNwToED?= =?utf-8?q?6+FL2LJs0e1LRl7GuO/LHuthsh4xdB4+IzwP95o5M3kYd9rAC2OimYXDzb5NcV8C0?= =?utf-8?q?phbW956gUgS/6CsjuJEE+TdnXkG5Hj3zl9DixYlM6nDrejKz6xwpFy66DuYHxU4AA?= =?utf-8?q?2JPsEznXLk7ESsiozlheMoDXY9+a3aWAdxZ7tF2FtpNVsNaKwCaz/1qPFW1OwZR/d?= =?utf-8?q?TQAoYefwO7jd6YJfG6eyZjeE+PlpEsz9J20IGE/BC87Ir+qwfs1mUD5iRuvNcVqNO?= =?utf-8?q?ViGfVBvJ6MSgLzZ1Uk+XD7tAQLaTZVxpMZyjpy7z/mdTMR2mOR2lfqWWG27boidy/?= =?utf-8?q?S/xz4vDMI8SJYigrpfUjyINzOaCWSAutQH8bISkI5XgHDv+Nzzgz2cxeNLR4hon62?= =?utf-8?q?JPw+ul6KpeCZs/PsCQ46/hcomeS1ag5xkTy5W5wtVq+LblKP/TiOeQ7hbLq3IzaS0?= =?utf-8?q?YxAQFbtneQmI2wGfV7eaRM6zczZjC7bZ5cXwZIHtgF7bTOZDadTk0rNiCa9sU3PlK?= =?utf-8?q?/JOIpv0ZVUW27H8ke6nafxlpGKIuBxEWCp9LAwAwK+Hpl5AXdgUJM5glO14Cm/QnL?= =?utf-8?q?Lb4KT8xbeizDo30o65iXCCwA6KotGAuPT3qBFIejm1flpyW8gXStMcv7NTpjasPUO?= =?utf-8?q?+pHUeLcYxwcapRLgex+7UUY8kEU2lWETcDCRhUmoGL4CpYXP945hAws7YwQ16B1nL?= =?utf-8?q?WXmkD5Vf9+Ms4U7N/EPg7fTD3MLVXHXzC2v3xG52JhlyPvv6vrgnJIDZvfih65NPr?= =?utf-8?q?BBTc/3S7EVyCmnq1cLXz4dvblDgFFxaHKRk1nrnhtD2uHY6LmlAbzleKNV2HqBEky?= =?utf-8?q?DxMBldvdxo6k+BrHwl5q4jgNbl0g59Yq7sAlWCauMLDFtahGBPKPnA7Flluvjk5Bg?= =?utf-8?q?pEordGsZYyMx8uAAEdHmOtDFhIlwEOBmrgBqL/Qxh9nd6RNDbtCaZVUPVnExrdHV+?= =?utf-8?q?zBt+/JX4sCiyTtZjRHL3OyB3FI+JtLvw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 13:19:53.3278 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2dbf8f6-69d0-447f-785f-08dd7b570b0c 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AMS1EPF0000004A.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9835 From: Ilpo Järvinen The following patch will use tcp_ecn_mode_accecn(), TCP_ACCECN_CEP_INIT_OFFSET, TCP_ACCECN_CEP_ACE_MASK in __tcp_fast_path_on() to make new flag for AccECN. No functional changes. Signed-off-by: Ilpo Järvinen Signed-off-by: Chai-Yu Chang --- include/net/tcp.h | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 5078ad868fee..4dacd4a11669 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -812,33 +812,6 @@ static inline u32 __tcp_set_rto(const struct tcp_sock *tp) return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us); } -static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) -{ - /* mptcp hooks are only on the slow path */ - if (sk_is_mptcp((struct sock *)tp)) - return; - - tp->pred_flags = htonl((tp->tcp_header_len << 26) | - ntohl(TCP_FLAG_ACK) | - snd_wnd); -} - -static inline void tcp_fast_path_on(struct tcp_sock *tp) -{ - __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); -} - -static inline void tcp_fast_path_check(struct sock *sk) -{ - struct tcp_sock *tp = tcp_sk(sk); - - if (RB_EMPTY_ROOT(&tp->out_of_order_queue) && - tp->rcv_wnd && - atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && - !tp->urg_data) - tcp_fast_path_on(tp); -} - u32 tcp_delack_max(const struct sock *sk); /* Compute the actual rto_min value */ @@ -1798,6 +1771,33 @@ static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt, return true; } +static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) +{ + /* mptcp hooks are only on the slow path */ + if (sk_is_mptcp((struct sock *)tp)) + return; + + tp->pred_flags = htonl((tp->tcp_header_len << 26) | + ntohl(TCP_FLAG_ACK) | + snd_wnd); +} + +static inline void tcp_fast_path_on(struct tcp_sock *tp) +{ + __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); +} + +static inline void tcp_fast_path_check(struct sock *sk) +{ + struct tcp_sock *tp = tcp_sk(sk); + + if (RB_EMPTY_ROOT(&tp->out_of_order_queue) && + tp->rcv_wnd && + atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && + !tp->urg_data) + tcp_fast_path_on(tp); +} + bool tcp_oow_rate_limited(struct net *net, const struct sk_buff *skb, int mib_idx, u32 *last_oow_ack_time); From patchwork Mon Apr 14 12:59:32 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: 14050396 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) (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 5BD842D4B5C; Mon, 14 Apr 2025 13:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636801; cv=fail; b=pBXVvES2hypAtqdu/++8KM3LgNKGT8Hlp0NE1dvbElz2sn3P1YjXRGZK8hEf6b1aQA+c9sLszHnvxoYnPBt8vUm3NExtq4m1fv8MupQmdaWLjJrqJ3lpqHImqFVzBcQVcZ+5/C0Kaa95lUOE+FSOz3SNPYpy4QedHRI4wUtQXfM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744636801; c=relaxed/simple; bh=U6q/bXRBi17sP6YLpcdxzeTbpNHFCeio/M7MPrlQrZ4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=HOUvz8YPrO6xFyzEKBlZWCPuZEvOWkAUY3wcaug2Jxl4n6b3yZKRbT6pNlzuqrjgTC4zgT9UqDtS5C7eeqtZvdkPpYqZDa1G47zjPjae/gziF2TLcJi0GHVT7HHjVFGIidfXxSmkEmldc4okQ/n5RocACsnEhBAOhJiwdMnGseo= 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=rMOre+Wg; arc=fail smtp.client-ip=40.107.22.82 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="rMOre+Wg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WIqA5h+FJ/nMTG1Foh/3JpWhKPRfpq29zuhQ1d914EzGQK8gJHRpUTXhtxSx7ucwjVnRsyM7XWarF7sEelZsD64Dmt9iiFWSNwBSxf4lNEInc+HxK5qAxsNzthBAvISPQhhH15nBcKeP21OOMqvBl+8pWQbKKELDQe8O19WhZKvdEqzBiEVhPPmF+x02det7q6eMhPlFUJ7oWTJLDxOSB/9Q5/7wg8+364XR/Sn8jFVVnn9yNWJdQtDzOIy7slQHkwLfAybRPMvF9sAJDkZSAwlEhGab0AawN2Lufo8ZrZwDkMMbjW9gN78dDnV88vSWhj6juMMq43mputF4W0eMGg== 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=CKqUtkCZicIIqEaUVe0VUEnNx6SZovaIXtfpaq4KjlSjV91VCUrjHv6Wrz6UWP2JxePaCQKijVImSL8Y0D+evjPJ+aL9WKiv94wH2XvNuCahORs1G3Sk0esaGSfmQMcjUtWB4zkInqdqpIY79Gtm65QWr/dGr33XjljU/ZRldCjp03B9W+ghBfNHmf6sQyidVL20sbwMIfB25cMtVUYctRTaXLjOLGJwOA7lh+vxTCAfl2esc9Qrwb3AdbQU51zWHoEd16iMiEAslLR0uy2Emx6dDbN8p3QXrRGJkD5HqYVDq1uKC/A3HJrv6IqqIu0sCLcEyCzPnu8Xm/93rsXzlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=temperror (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.com smtp.mailfrom=nokia-bell-labs.com; dmarc=temperror 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=rMOre+WgZ9d1PGbzLdweFsLPoLVBQQQ7dwWUMKCp3+udo59ztrws6KdDkTRn72/6qSX4p2YW+upFwLa3EDb7/vV+BT3lw+iid1w6z/53nafVhVXJJ1qU/MpgPsylYkUGn7WvOe1qvr8DjpIRqdy2lFzcVTvue2lYnBXXqtRPf4pmUXJunPwpYkWjeyCHdSYnKxtmLE0OWiO81NFVYNQMaTOaF3NcMqzyS/tZHLbfJDw8GKU8dC6fNI6Y1iF8JpRsDotkD0/OWlcQCV+my37HV3EguAOGKeZQVQ4mgaLKLS80HJSoECvJan62wbq8qr9EH2D7fvHzWtCBjTyFAeUSPg== Received: from DU2PR04CA0168.eurprd04.prod.outlook.com (2603:10a6:10:2b0::23) by PR3PR07MB8098.eurprd07.prod.outlook.com (2603:10a6:102:171::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Mon, 14 Apr 2025 13:19:56 +0000 Received: from DU6PEPF00009525.eurprd02.prod.outlook.com (2603:10a6:10:2b0:cafe::a2) by DU2PR04CA0168.outlook.office365.com (2603:10a6:10:2b0::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.33 via Frontend Transport; Mon, 14 Apr 2025 13:19:55 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 131.228.2.20) smtp.mailfrom=nokia-bell-labs.com; dkim=none (message not signed) header.d=none;dmarc=temperror action=none header.from=nokia-bell-labs.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of nokia-bell-labs.com: DNS Timeout) Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DU6PEPF00009525.mail.protection.outlook.com (10.167.8.6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 13:19:53 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 8A6194EE78; Mon, 14 Apr 2025 16:00:08 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 03/15] tcp: AccECN core Date: Mon, 14 Apr 2025 14:59:32 +0200 Message-Id: <20250414125944.97350-4-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DU6PEPF00009525:EE_|PR3PR07MB8098:EE_ X-MS-Office365-Filtering-Correlation-Id: ea0f08ae-6328-4f2e-b858-08dd7b570b26 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|376014|1800799024|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?veygljnB0zxIdj5c7utTGkrQhvzdM1D?= =?utf-8?q?TP1QrvyZaN2bcubhuw+NtKzqy8Gay/PyiVyFhdkd7IeEIbUI+/FrTZ/SXOTK2M71F?= =?utf-8?q?DcY4nrs/1CXjWR6EXB5cQzV02rlNcav5LIvU+ZnD9vRIuXCcQYYZwi0NdZ4OI1FDD?= =?utf-8?q?WnMewxYhKje2eRszSPsjCw7v/+gQJEvCXL8L86AifMzP1J7pcvZHtm+Fyp+Cd+MbN?= =?utf-8?q?3jPgRAGGxOyYzB2l6fCb/1ZhAqKLLN3w89FC72h0zESbw00TseljFSKxYCIAqbfPy?= =?utf-8?q?yLrOENXdzj9D87sJpC3NVgCIwTN2R6GcVTKvk+092M/RDStXU4R/QpkZ79qY64o1X?= =?utf-8?q?zulyybMpPNlVXwqDvjUPEzuJh3+QffhDGvGfO5f6l4UFI9Zz0BsQY3XYhA+yxALbX?= =?utf-8?q?+bsIdiCIq2zihwkzo+tnjxmQrT/rlbiZFoKzWU42ZFzkRbcLXkdpcBLl9gksKek5H?= =?utf-8?q?8/58zETJYYS9DO7gB5UcNSanlbtFxIjByllH0JiJKvNLzR3TVWkiEQBFp75AW0X/o?= =?utf-8?q?c+WGHACiNVkvjkX0n/sewxuGDvjUdvYMKM7BXqSLzeG9n2C1djtrGvBCNSTQ+8Ij8?= =?utf-8?q?x8rqzs8rVOQQqmk9jbqA6HzMWeLNdkspmlQzt8v7Od5PlwoaR5PLlGLc9xTSVc33p?= =?utf-8?q?EfkIt25HyJtMGICNryHxTdQD5M1XHEFC+ymnH7E65SLzfan+dmqe3rZuH13Mhjhde?= =?utf-8?q?mIRqC69dxp5+pPGUQTXCap01FjF/AaASJFitUJ7s/coh1T78+F8iPrEU67Xgqf7Uk?= =?utf-8?q?/iQ8irsO665YHtM91hogMqmL1BaHGrXJazKnAxNbn/JQt4mEYoij/zyTpKq6gRXxt?= =?utf-8?q?Ijp1x2b+s5Wz628FR1sVlx8+mfJCqrTCTN52a+UxwYLDmPpgBRTtkimoBMwv834EA?= =?utf-8?q?LQ7SvkHRq5JinbThnWIfRww8eSU4kDWwMdzPUIkPIgRUwPDV2wIx4v2IglHUziyeM?= =?utf-8?q?3LKy/OfDLu3ZxO/TSa1P1DYDDHM0XrUEtYgtFQZbmRI++a6Xyma21mtpr/Y2Qxu1H?= =?utf-8?q?te7wqMLmHCa5WUTmdthqRGj1UjPuqpqmr/mOo2VJwqjDrwIPR80q04hzZAnswb1OR?= =?utf-8?q?J/f7Oy9mG11g83Ps0sbo6XiOQSJ/DcO4aOZva03MCwYCvDG3n4sJjq5bamwDoDKqG?= =?utf-8?q?/kCuFjkNJlFX44DMnv3VrtQgXFIeC29yA4TZ/RGhpsn6yLKhQjxtddERSNHiF3Ft+?= =?utf-8?q?CvxajAzSIU5mgQ64uj61isT/RYaaw2EkuZXCpnOP8tIWyGTElToVenS2XN8eyPGok?= =?utf-8?q?z+GyxdDombgEfNa/SpwCODle6vimfmF35FahLpSs8I9SrFWFG397uKgFzW5pqTLi+?= =?utf-8?q?nld3GFFLQYsLYHqIABrF4IFrkJqBdiQ/wn9DsRdNdp2W8nOOCpaCGkLFUxxLVhDqp?= =?utf-8?q?g+8otuODzXDKm8OFEGE66O7av177Ommf0YUes6fLcDlbc+AKos6N4Ey5wjLXOebQX?= =?utf-8?q?npeMtd1eBKubvBlnLaP5Kd/SkaTdwDXg=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 13:19:53.4686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea0f08ae-6328-4f2e-b858-08dd7b570b26 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF00009525.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB8098 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 Mon Apr 14 12:59:34 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: 14051399 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2079.outbound.protection.outlook.com [40.107.22.79]) (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 D564F2DFA32; Tue, 15 Apr 2025 03:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744686490; cv=fail; b=YBIjet2LDgPhzWCGYiTzAO5/2NhxVWgOt1WAA+zZDZY6j5v8DMUDtAgNpPq2rjApsxtuICkKvc9R7UXuHulelYpFGEhNN4zYmiC/Y/mT90RLF+xgHk7mOYNkvO343lVnEJy3d55I3gXkwdJNW2GMG61cZ0Erkdhx7Vxc3Sfm7vc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744686490; c=relaxed/simple; bh=e7UrFITwpmygTjGLAEnZ3V7gb1JncYGCuLIqU5AKJKg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YTL2rpfQZVYNO8KMzM4GfZra2m/7NW+Y9YxpA2qFrXCzv00MO7YujF6CVZZbOFp0GDNnzX6TdHxB0NL3yPbU99PONqQPagYrbeMisIXcVM6no2YUczIG59YVlxwKr9Ha9ne48Bz4YjGvFPUiBpSs9+ImgjgMLSJ8+QXvfdXlegk= 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=IuFtvAAT; arc=fail smtp.client-ip=40.107.22.79 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="IuFtvAAT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AbZLFDzyzKNAEZ1TJXrWcgg5ubpnlK+/rbemCCi1v81f5Z3BSz+eLRJTWlSGZ+FhABpmigSZIX70Oz/hhLLc6/by1XWDduUeD7d3g6XyyrDfQfXmLIiD67bScInTQitXRvijWYXs5LbOwn+2EpjC7spSC6AUjyUcCxTzEC1kqxTDnbvC9FzlAGegflK92qGN8GrviYLDFMqbrun/sKBEsaEK/d6LxG4VaL4yX+tgTiQIRVgOM6PUKkG8Xdqe2ppy1rQTIwFTXFktjJW1xOoHzI6Q5/vYSDnaoujw7P7mjHLaXGj5OozBgReW9UMwnVeVyZc7FUaBKVUjaWm6u1GT4Q== 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=K7r8uly+ZR1PUPikdYkXp376WrR5KVziPb7QO8/Apvo=; b=aZg0k0cxF7jVicQbU0P2l1QTQpHKWS01apc1luFhJpLWa5UpImEnwdyoHBdq0dBuXoKkiipISy+m91xzoDPUbMNj6Xu7HSbKde5ms7lGKV7cbVUkKNhKMsSiKTOiEcGVQeQt9FGbXT5BXZGlaJOS2QjF0a6cQXLrwI0lbqQy0kwS/LBImYhOtbAs8RauvVi0Q9BtM9Qhv2U1kzJt06F4QZsuOabIYDr7vW0Klo1LUv9qCixKV5SGtTN3ZQQDouHQscUWGM5Ls8KpPMkqphuHDH4InpLLLqNt/76NV/HhB+HV/RRBmH8a4kua5obAsFqFadsmX6EXYV/evnJGmpO++Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=K7r8uly+ZR1PUPikdYkXp376WrR5KVziPb7QO8/Apvo=; b=IuFtvAATrn1pVXrGmFggKJRdV4jtiBMbwyr+YgUbwbAeZJzYZRhBG9IuLE95ehTwin7OxAiDPtM/pLhQjEfRGCOsLIoUtKMXKe8ZEQy69jJyjHuDcp9vnVNGbS3C41ikuSmeSTgf0AS85OKOdPQ3mIt5Jy8CJUVhl3WUjsPf5ba3EpoVy7STrratvdoqZRSuIeX+7O/Wz10hLpgt709Tdo/F3wsY7KeEme2z6K7EsDazuE68O2UUPg9fVEEZhcKRkLd7B68nnpN/vp2N8BPYRvVQyijHtAJFwh//8WsdGAwdXIXjLEYTq/bvFFummyqSv/DjzY02wUoIO+Zypr3+Uw== Received: from DB9PR05CA0028.eurprd05.prod.outlook.com (2603:10a6:10:1da::33) by VI1PR07MB9732.eurprd07.prod.outlook.com (2603:10a6:800:1d9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.30; Tue, 15 Apr 2025 03:08:00 +0000 Received: from DU6PEPF0000B621.eurprd02.prod.outlook.com (2603:10a6:10:1da:cafe::6f) by DB9PR05CA0028.outlook.office365.com (2603:10a6:10:1da::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Tue, 15 Apr 2025 03:08:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DU6PEPF0000B621.mail.protection.outlook.com (10.167.8.138) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 03:07:59 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 990704EEA1; Mon, 14 Apr 2025 16:00:10 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 05/15] tcp: accecn: add AccECN rx byte counters Date: Mon, 14 Apr 2025 14:59:34 +0200 Message-Id: <20250414125944.97350-6-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DU6PEPF0000B621:EE_|VI1PR07MB9732:EE_ X-MS-Office365-Filtering-Correlation-Id: bd2f230b-4b46-475c-40ff-08dd7bcaba81 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|7416014|376014|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7qmYRVB3R6F3xNT8+qDZ7Zf+OnDbgFw?= =?utf-8?q?YkKSMSniBAaBoY0HiqduyG6X0sZ3kO4Y+gD/SjWRDGTy3qDeGbQgvLqam1dEhav1J?= =?utf-8?q?S65yDo6kl3bJFLI7/bxLWeX1CzSxo7DdT1LJsNjwaLExv2WUdZ6g9h6uOk2Fqb2lj?= =?utf-8?q?aRP3w/Xnk1GEpBbTltApUC9lIliAE45qyAXwg0eQzgSV1tg41MqB7ZJdJueVNPBlw?= =?utf-8?q?qZreIRz4xOUfOZIusxVgU3bLEv1HSupF/dNRJk8FpLbsGTb/0vAkuAkLFFsc7U5s6?= =?utf-8?q?yMLR7HcttODuhZk/NZgmpYZD+X8NNFoYN90cW5IBj5waOMZACqjnVXEbHFk//+qUB?= =?utf-8?q?vtUiIs1Kn1Q8X5k8kSPNbwSsSZ8tzWUgvsAWsqhFCQzDvWkXFkX02aKamKGhSm8FW?= =?utf-8?q?dD2okSQH142245IUfLBLeP7hNmnmGSOArQETQ/MDwuskv7t8y18Zqpb2uBqQW92Dp?= =?utf-8?q?WMLJ4Rt3XQxX0gDXojqh1cHuO7cOGKOVkSjmmG0OCVXseNleCM9cRS7WCPTIxJwQR?= =?utf-8?q?0f8q+XuPHbA5KqeQc2oEyHwvH7EGc85YJhcolvf7cpzSOV8pDJ6b6Wp0ke/e+MxBY?= =?utf-8?q?Jo+gTFD/q/8rS942J5nD0CLWBywnoyaFtyr6dJiaoGMJBKcWnScaV03OKjl4u4kVC?= =?utf-8?q?mCiN6WZQJS91Gt5r95T3uxdBu+Prr5vV2c+IAOMC5FKHVolmfqrCA1j2+/DGCYTrt?= =?utf-8?q?jmRCVBVJnOfAIUR5bsQ5TP3hWp/0WwbWYMZUOa006we5nH7jJYh+lH3wAnsSmHfsC?= =?utf-8?q?UBrOdVQ45BQ2ck0/SUE3VSk7kFMaKkbNVN3+4UAv/Krxidrwk55PeNOk6jwNknzwf?= =?utf-8?q?NhpnQLxfbH6zuLJXLYZFyU9PLM4c+UBN6LdkH/hsrLjTlkYvPyYXtGzxD2LqIzXSw?= =?utf-8?q?edP29ssXkxsuzSTDCX6Hd056W/25f2iBP2/WBdaZBOyhJA6TegWEePaXtA41druUJ?= =?utf-8?q?O1LpyKHEVQA5imjm8/Ljf3ytkmretvKLPSqQgiN470qJRTKfmu3gS8eeY5dXxtkn0?= =?utf-8?q?Axd7KfnRjf7jB4ENhc8TOsLkzNkoQuO3GCM4TW3ZIBOUNkNsURJcsfTXcQPtA0Tv8?= =?utf-8?q?VpECgJZ5kucJqGfIZ0UMIqlUJYiNsFmHqv+M04GT1GxlA7XgsHS64DjxB/M5DL51b?= =?utf-8?q?3vjOv9hFpQT42yqbca0kZPRvWexWYG7OTP8+lRLHmKNYUyC7r5E+li05Jnr3SaZF4?= =?utf-8?q?NqybQ3B9cYJr0WyAHUffmuGvEpA0qBlrDLJPFqi0/5GLH/4xSuNxVzOXeRGQ9RdQ1?= =?utf-8?q?5h3uGA75Wlnw7AD0zUV5z4RvpeR3dHYwPo/SQLGY9VZUPV1VU39/oVuLs4g7ypl4i?= =?utf-8?q?scdxI0Wq9ON280bzLuCbGpm9jK+lCklSgou5+6DrpWHo2CZMNMaAWX+Li9xeNrsCr?= =?utf-8?q?tuDNTKzoomhJW06HoXcN3UY3v35lLgYQ+pEuchfi8zwmb7G+iRxqHygzyaS8NMylD?= =?utf-8?q?Y7EYCbTbX97WIYE3ymfIuJfkp3C712vw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(7416014)(376014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 03:07:59.8184 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd2f230b-4b46-475c-40ff-08dd7bcaba81 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF0000B621.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB9732 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..278990dba721 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 + 3); /* 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 Mon Apr 14 12:59:35 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: 14051715 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2076.outbound.protection.outlook.com [40.107.21.76]) (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 99BCC27587B; Tue, 15 Apr 2025 08:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744707487; cv=fail; b=dpOKgoaYB+AAFte/qtJn0IuaJc3NjfLG7vK0Xjy68e+0ZwuOQg211ksAhPJ0sjgxuZJoqD5hYCFjn6afMPSD14joEpAZzofVSXK6Ip5MWoq0vZnv21SysbXsOsWSA7brskjUJuP2VEu1X3VxL9QBcX/HP5owW1wHOdT8ahNEbLw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744707487; c=relaxed/simple; bh=bz0uIeWpSGSuIQvh66yhCx2wBEBZLK1Uhj3GCh55+fI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=iyIXS/k9pXVX8/OkgGbgK2NKSXkqswvtZcpCuESyWoIGiJESaL7cYWAPA1zOWbOo//Q4bEadnReNK4dA9N6+eYyVOagrTykQ8PVswix1PuG01PAnHkuVzlCXI6MuPLlieR2CEUKXuhgt17rWsy/k5vH3gluufsaCgVpLubyB9Iw= 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=eDkOcew+; arc=fail smtp.client-ip=40.107.21.76 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="eDkOcew+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=snYQ7OhUk6CP8JtjDrgt0Q2iltJgMH1DOvixkNXOAC25G8CBecbD4GMWl+Y0gu+fW5yKEYqQ1IfeSqs0RxeXp6Tb789jWhiUze1ARhri3mq8KKf/o6t4oy6GsHr7AUUQ0UOVwaEBR0NQcj4yfua+RJhuLnqwi+Z39LFV8DQ4Bdnx/twvgy8wMPkOXYe/o4SGFzNymQtCMWoUDR9y8HiH8bhn1jm7G9n7JekfcynIgZkUmmK4NjP7tvvPdhw/wwjZqQdCwvCfYDqJ2doqUK16Fyr0QCQfGof3J8ZYu2b+XluQuwayWNR9Y62jyl4VKm7GjeDvxDqH1eYvBsaMRjeI/g== 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=xY4cSgz9DD+izQ5CHXWWIiWN/HVvG4kiITK+k1h7IUY=; b=xuMGm8ai44dROUnzrS8TB8lZTZXY/P8POgG07NDi8i/vx35gS3jQKAHol3AVDrhO/A8MSbpFzA29/kM9Guc9LUMWGsWlfcqFenZ7/TvJNozPikiL+kA8wLscpW77NeVLpRQepTsDVglWQ6TfnarUuVt6BAwfuqrEJq19N5N24NCWGFzzlBB7NH/ENmL1HIUx219LFZaKt7kVADJohqsP0PUq0tdvsvDPGXU7hcHnyIGRXUSsb18xpkJfHrThgZwvT5rbMQEAxch0zdifd/OaqMibHVJJF+xLsWrqOad3MgeiVmszFeCJjupFi5iDP+pVxD/Txurv+tDwWEiUCElTyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=xY4cSgz9DD+izQ5CHXWWIiWN/HVvG4kiITK+k1h7IUY=; b=eDkOcew+pYHn1BmRrRaklTFT8XIcB04HH1XbgYRjaT25fklfAdYGxfRyZqnxaTLF1TSSggT2+fA4eMZkzGpcj9+cYvnYvj9KhdAcE7azVqG1cgAwydoQDv4wDrJyiGNWf51cAPedFojjeDiLnZTy/3V+K3yxegim9SrgsMFs9rZertzNf2f68H9E3u6bms9oEJ6NeY++cYHYActJ4QWR4z6OMu+ivVWGwK5NNjI2vJkuRT5kVEfpIgsN7BbPCcKwOPbNX8gkk+ulfIqXYAph2970nY7NfFpdxeaMDQa6ISzIWeFal197OgpgO1adzepKW6TJodcQU/atSMPNpcTOwg== Received: from AS4P189CA0051.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:659::16) by DU0PR07MB8907.eurprd07.prod.outlook.com (2603:10a6:10:323::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.32; Tue, 15 Apr 2025 08:58:00 +0000 Received: from AM3PEPF0000A79C.eurprd04.prod.outlook.com (2603:10a6:20b:659:cafe::c5) by AS4P189CA0051.outlook.office365.com (2603:10a6:20b:659::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Tue, 15 Apr 2025 08:58:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by AM3PEPF0000A79C.mail.protection.outlook.com (10.167.16.107) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 08:58:00 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 9844B4EE7A; Mon, 14 Apr 2025 16:00:11 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 06/15] tcp: accecn: AccECN needs to know delivered bytes Date: Mon, 14 Apr 2025 14:59:35 +0200 Message-Id: <20250414125944.97350-7-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: AM3PEPF0000A79C:EE_|DU0PR07MB8907:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ab65cb8-1e7f-4cee-68f7-08dd7bfb9fe7 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|376014|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?FnWD5ZM9ZiJStkWspzIuVTE8qo0RBmr?= =?utf-8?q?3eTjf8qIlDM8Wfu/Yc6v9c/mxqF5JTSuwXFEaPdAlz105R40ARki0V2HE7vsRkKKW?= =?utf-8?q?Ykr+oChKd/xYgdh0Rt8yMdSdfJlsc1KhgxWLKNOH6VwZEpfPZTm18SqDNbPmBo42o?= =?utf-8?q?hIrt2squzI3r6ak8MwDp6LD4RwG9qxJzm+ISjnesirexg6gf/R5aX/qWDTd3X+lK9?= =?utf-8?q?tTql1+00zQvDh0u291t2NmtHZvej2bebjcLm9PMYsFhMW1YMTjCw6fL7/yiCFLiBz?= =?utf-8?q?BLXGKtTvgpb8DaSgMfwk1BhN13x1xb8qHxfqmDlGy5mXYGDbYKo+M0km61BOPGJbd?= =?utf-8?q?ignolqiTCPYM643oWXnrLUCXlYqenBN0KjuAydaT8CrtfIX35TK3Zrwh78giMDyzH?= =?utf-8?q?924RwMvcuJvWkCeKj/axMz4v/YE98rKpqik1WHviK/AfHnMY0Vl23JMQZQeaT1FyC?= =?utf-8?q?DrAYeriQrUI6pAAdWSoTGAE/FoHNlLSoSuEkXcM6du/thDtt+txgHCeZ4l1X8T7Tc?= =?utf-8?q?VjsjUeIgwt9dcI+WjFI/v6mL0AYhRo+be8IL8sOUlOKx+fdpmRgZB0mYKbeBpiFNj?= =?utf-8?q?eOY1OwqT7nQQ/yehD7DHLvXvOT0stMBUq1GyxtP/+jYu+6ICGVIO7tmLDgIOrfGoz?= =?utf-8?q?NxFky2hnd3bzBlj+J/1vcr85PHs99Gr81aOz4DCfi5RrSwza8goILq2Rd3VLmD7YI?= =?utf-8?q?xE4vZTnKZ9NPsLXavscSFEJM8QBHGCYI6gU+zOhnHjbg278f7d7k3UnUCOYKbeFAS?= =?utf-8?q?fHWxNuCjil8OeC761n4CEXWKKAJqs9r66PR19HQIKKcFf82sXtKTAJwuL6cdjXTpA?= =?utf-8?q?EG0L1tswCkpSS3FnaZ17bmMY5MDxHBjwv//CenDdDDnBFAO0dt6w+2pXURKWojOX9?= =?utf-8?q?eXXS7BsCMHCrP/U+9tGuTzWCJGHCADdapwMhHWsjbY1T1yMV3BLsaZfrliZARoEJ+?= =?utf-8?q?ZuMCblHdlVYmsbMKDbrx+FN/xzVzAApBVxPyEVyF1k2aRG1NAXP9zC41F2eYGecrr?= =?utf-8?q?LK/yfOtN+3hOMjUJBCKSuS3vfZq8xU9xNleROCOvYenJYxjEeynIu1qGcqQbU+vOZ?= =?utf-8?q?sVIzDjtHr5cXij3hLjXbsSFtPBnnQxIc9bZPYVHMF4YRdXb2CSfo6TrbpC5M0GIvi?= =?utf-8?q?Hu31CcgB4h7DJq8mwJ+cCtpUP3OQL2hny6CI51JyVLzrogyfsO+ZMXqItS/tcp+L+?= =?utf-8?q?eKy6hV5RwceAs40pSRZEXymKCl+bb/rS7psJOccBKyPl+Z6zFZXlajWXUG755mxCR?= =?utf-8?q?LCDKgH5lVS99DsblOp6JHn5OxKZsI3mk+cmNLdkVBqrqpmx69U1QECRYebd4WIztg?= =?utf-8?q?UbRpPYeQ9KgNv/PrwJly1qbrQIWG/5vDPwzMkpbHi9E0fDPninyYbxjJ/3GGmcszX?= =?utf-8?q?SZ+L2TvRuv0TvNiccKTt/se3nd2aoEDJrOFYmrXzX13KZWGEuzlI5Ys16fxKHINFp?= =?utf-8?q?1LntbEBizuQCn5GDpBx8xsCO63NYTiIA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 08:58:00.5291 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ab65cb8-1e7f-4cee-68f7-08dd7bfb9fe7 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A79C.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR07MB8907 From: Ilpo Järvinen AccECN byte counter estimation requires delivered bytes which can be calculated while processing SACK blocks and cumulative ACK. The delivered bytes will be used to estimate the byte counters between AccECN option (on ACKs w/o the option). Non-SACK calculation is quite annoying, inaccurate, and likely bogus. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_input.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index c017e342f092..5bd7fc9bcf66 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -1170,6 +1170,7 @@ struct tcp_sacktag_state { u64 last_sackt; u32 reord; u32 sack_delivered; + u32 delivered_bytes; int flag; unsigned int mss_now; struct rate_sample *rate; @@ -1531,7 +1532,7 @@ static int tcp_match_skb_to_sack(struct sock *sk, struct sk_buff *skb, static u8 tcp_sacktag_one(struct sock *sk, struct tcp_sacktag_state *state, u8 sacked, u32 start_seq, u32 end_seq, - int dup_sack, int pcount, + int dup_sack, int pcount, u32 plen, u64 xmit_time) { struct tcp_sock *tp = tcp_sk(sk); @@ -1591,6 +1592,7 @@ static u8 tcp_sacktag_one(struct sock *sk, tp->sacked_out += pcount; /* Out-of-order packets delivered */ state->sack_delivered += pcount; + state->delivered_bytes += plen; /* Lost marker hint past SACKed? Tweak RFC3517 cnt */ if (tp->lost_skb_hint && @@ -1632,7 +1634,7 @@ static bool tcp_shifted_skb(struct sock *sk, struct sk_buff *prev, * tcp_highest_sack_seq() when skb is highest_sack. */ tcp_sacktag_one(sk, state, TCP_SKB_CB(skb)->sacked, - start_seq, end_seq, dup_sack, pcount, + start_seq, end_seq, dup_sack, pcount, skb->len, tcp_skb_timestamp_us(skb)); tcp_rate_skb_delivered(sk, skb, state->rate); @@ -1924,6 +1926,7 @@ static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk, TCP_SKB_CB(skb)->end_seq, dup_sack, tcp_skb_pcount(skb), + skb->len, tcp_skb_timestamp_us(skb)); tcp_rate_skb_delivered(sk, skb, state->rate); if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) @@ -3540,6 +3543,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, const struct sk_buff *ack_skb, if (sacked & TCPCB_SACKED_ACKED) { tp->sacked_out -= acked_pcount; + /* snd_una delta covers these skbs */ + sack->delivered_bytes -= skb->len; } else if (tcp_is_sack(tp)) { tcp_count_delivered(tp, acked_pcount, ece_ack); if (!tcp_skb_spurious_retrans(tp, skb)) @@ -3643,6 +3648,10 @@ static int tcp_clean_rtx_queue(struct sock *sk, const struct sk_buff *ack_skb, delta = prior_sacked - tp->sacked_out; tp->lost_cnt_hint -= min(tp->lost_cnt_hint, delta); } + + sack->delivered_bytes = (skb ? + TCP_SKB_CB(skb)->seq : tp->snd_una) - + prior_snd_una; } else if (skb && rtt_update && sack_rtt_us >= 0 && sack_rtt_us > tcp_stamp_us_delta(tp->tcp_mstamp, tcp_skb_timestamp_us(skb))) { @@ -4097,6 +4106,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) sack_state.first_sackt = 0; sack_state.rate = &rs; sack_state.sack_delivered = 0; + sack_state.delivered_bytes = 0; /* We very likely will need to access rtx queue. */ prefetch(sk->tcp_rtx_queue.rb_node); From patchwork Mon Apr 14 12:59:37 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: 14051540 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013021.outbound.protection.outlook.com [40.107.159.21]) (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 838AC10F2; Tue, 15 Apr 2025 06:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.159.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744699086; cv=fail; b=tmc4BVlMSDLQIDZ/1b3kk4TFIl2ASp44dZhWdB9DbnFgEM1K4eE47tMscHHdRNj5K/f2oBKNO+b4UrFCxegc8T1zbRoAIuavX6F7ZbSAxn+B1g2vK63i6xHkEWYP1jPYEgdYcyQfn2JLK0dU5O1QuEX5buWsshmp6CfRgl+C3QQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744699086; c=relaxed/simple; bh=+ezEZy8hckPaea1lF4ilsBt0GsZjvoaMn1f9l0j0RCk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=QFmBygJmJZ3OTpEdZY/Wq4LOefcYTugXnynv2vfnqEZIFldbGMx/Ac4Pf9pY44CcNt3M6wa5ygr1iAg+mlJr5KMVHA6sr8bE/3DbxRl5uOv9Ux0tXl+b+mf9Y+JF38+w0JXoMwbBxb3mNPzfR3ULizkPvJNJcXBZhxYfx7RSN1w= 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=ceO860qC; arc=fail smtp.client-ip=40.107.159.21 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="ceO860qC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yv4NdOvTQrqjxQd9LzpzQ2hl4rpXfz51q5FuHF4v1ckBngRshOKS9FPLQomb2CFLUBfXTbem5VeildvX+wy3QE171hlMB2JqWztSKj/BLZOlWJ4smJRnw98zfde9sXRo/ZgMDndijTdhEYYNEe6HxHM6/p2XVbklmeyPo8zrCRtRvEKxrRM+FVBO4mzKj/eT33kYAs2MstfEvYoWBjMOGXq1WyOCB0QnzuseGbitoPfUu07ZRwiKV38sTVV93txAbJgrCTLFNsT0MFvuLvZxnW5kY661bcM8G6OzSBIRLTxiZEOLt4VCLKWsBlLIjcEtn+dSWbNKMndNJ81M6mWIXQ== 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=ix+QtM7JJKtuEJJnzOOAErViBOEsmOlScq7uOdppACk=; b=k7OMwKABCa5EgzJI2Z/QWiR+VBFW+sDyCanpUFQjE9pr21eHScUKyQVfayI7IiFdn/mOeozzXpl6wL7sRQ/ikOWtcmw+oeBctUSh6T4PwoWaNIEGMrpieWOmT5vWqDBn4FqRutinZJTVp9iYrL5hcdhlbMJNksUJk2jA5NssyPIMbJL5UMuBUq6v6Vcc9gtgT0cNSUO3RCMa3VQZ687ftJY5ZS4KVFFcbtvp+pMdOZJd4hLtyINHJjyKq6WWfrBs3mZhnFiAF5wMyZFrSqf7w5786b+9QqM9aAIPsStbY9i6grAKjglTGfr4UDUQvewOuOemC9Aqm4XRfRi5lfb5wQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=ix+QtM7JJKtuEJJnzOOAErViBOEsmOlScq7uOdppACk=; b=ceO860qCRW11XLxzio1udaWgiWGgr74D3jL8LxjoRrQ9dTBKXq15OdxS1ndkRcdmhNWANmr3RKbaOJTdelQX8mIhXvTTUYGuYpQ+FI6Lz2cNoTg7y52pmZP3HCb3jUEkHiTjXjVJNk3oaGJ6RP8e1gGeUPUH4LhmilWHXutYdStpI6zYTN9DTclH4yn4xY/ZMAEJ4EbaJSkm0/m3w0lFljkr8mFyeWaMmfo2OKATL6asXAb1mHS8h9FopFB8DpcKzvYg9VG7y/oV9SbEHS8LEtnG5Ms8jrYMr6W+Uba5LH8f2fEFx82jivAm/uiTPQGhc0XwynCgezHVcdXcRD38SA== Received: from AM8P251CA0028.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:21b::33) by DB9PR07MB8636.eurprd07.prod.outlook.com (2603:10a6:10:30b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.33; Tue, 15 Apr 2025 06:38:00 +0000 Received: from AM3PEPF0000A78E.eurprd04.prod.outlook.com (2603:10a6:20b:21b:cafe::49) by AM8P251CA0028.outlook.office365.com (2603:10a6:20b:21b::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Tue, 15 Apr 2025 06:38:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by AM3PEPF0000A78E.mail.protection.outlook.com (10.167.16.117) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 06:37:59 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 99D914EED9; Mon, 14 Apr 2025 16:00:13 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 08/15] tcp: sack option handling improvements Date: Mon, 14 Apr 2025 14:59:37 +0200 Message-Id: <20250414125944.97350-9-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: AM3PEPF0000A78E:EE_|DB9PR07MB8636:EE_ X-MS-Office365-Filtering-Correlation-Id: 87a5e83c-5d7b-4e18-d94e-08dd7be810a6 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|376014|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?X8Qw6w0K63ZsV9mvKRNT9YNQPdXcbyk?= =?utf-8?q?qlcrtloHAlZPrvwKex5hMcNxsmcC1sO77hZVLy9mkqo+JMsix8kcNe6AQfkSe5jr2?= =?utf-8?q?EyM0TrOKjn9OYMtipCy/Rg8Wbvf1V+8Sxr9uRF5JyY2Vrsq0tFAPAsN4eVlIya8qs?= =?utf-8?q?MGtrnS3ZCLZdV4iRUmbOUpDAP7yHCaQpo4TrHdtatthuk7e3UbdGYrESy/rEis3qZ?= =?utf-8?q?kPpOCgxAymI/W5PrpgxScKptm80DGStCo/6UFZaBrHG8AReo7MyRdo1FgnzoA1AFD?= =?utf-8?q?AR/AxosDexIIUhJzBlMDK0qkh3Y5fs9c3nxnBLjRc9iddB4p3zI4juZT2GxnwTZ6b?= =?utf-8?q?JZM92ge6JDDaNUkg/wJoWZwXnvz1SNJylGk+VB7Z2mNi8+Nbynv1zXxJj6lpuLNRy?= =?utf-8?q?531k8eLj2UnQ/HTWejMGyS4EgTCMdGa0Bi3YUiXGStbQE52vOeXDz1KcBuWcJfNPX?= =?utf-8?q?XkNo311s2ZgykApDyFo+Ad4oikkZv01jHR2HyqJkbVyomOyc2ANZ1N+U6hepKD3aU?= =?utf-8?q?LjRjUIELS4b4DYT5vIUNsP50ZLLWc3ztFbx5JjvyU8RhrjVxu7obBOU1/IMwMoAHn?= =?utf-8?q?p1Opo/YqA3qDEj/W8rotPDlcS134BCCIIFzp33oiYV93AeANXuM7eD2Lcn223m+e6?= =?utf-8?q?4MDQpb8mN+beA00wzhrKlXSMywmtRzj+WY0KkmnHdABv98GYvaCGpCOpUVHYZd46i?= =?utf-8?q?eG5LFq4WEXpU3eDtWX+tsuWP0bov2b3si63iqp76KGEsSZNKoZPG/dsCWoQweZdXX?= =?utf-8?q?p1w+/Tbjmq6MBP89Llxy/oKiFuibsXw+axfVH48QUNxmwxp5hgnkpLiTpvF38BQbA?= =?utf-8?q?sB2xw+3IBz+1UaOs27nUzqb5VtHC653lurqMGBk8WNOsFxQmBi9kitaUL21jSs8Ll?= =?utf-8?q?7t90iihwFpJz5qhjovCcyqjtDlEKkU4DzY29tvuFA90uELnbWFsqSwo0owtKh+OBI?= =?utf-8?q?cWyuFEBcAFd+7IfJ3ssaog/L2/Nwr6vCZOEqZ1FoIAI6ouoCLbFnAEQK6pIhmPhb9?= =?utf-8?q?o16QuyEESeFFmWT9jPv54QUyNrs5ButcHNQ8VRBN4THGCsJ4Gbx1FsbpMqiwewyIG?= =?utf-8?q?CPtMcIh95bIW9FhHBaLYlsSKJclUUKz7FO+l2Rc/OQ51eu6XWgXMi5/O4cI0wgX07?= =?utf-8?q?+jmS7kxCblAeDuLWjRY/66C0+ayPLleGvYWvrdz8hMSujCy53EF/1VNW4cfaHZIit?= =?utf-8?q?l7T9V/6/zVtbadM193F6X0irSTeVKZSYBvEzz3p2ltItpHsHvK9u/3QyK/oD5hRcY?= =?utf-8?q?tp/OqOo1bqQF/Atip/OuHCVf+thToOaFccSp/9q9sffNifvRPZJ8KtrZVdurqyGcT?= =?utf-8?q?i/VLIDeVrW+M+vYvz8KAdKQeu8Umifdbb3qHuz0KzWi/7wFoWuegtdIIXIUPmy5O8?= =?utf-8?q?JgqYvCTbiKTo4lN/opaB9/rIJLSWaxy7q8kvUqBPootpPN4koWs81ABfHRsU2kWx/?= =?utf-8?q?p9mRvTeF4qYpFdL+CpPz790DWhEA10jA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(7416014)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 06:37:59.7540 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87a5e83c-5d7b-4e18-d94e-08dd7be810a6 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A78E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB8636 From: Ilpo Järvinen 1) Don't early return when sack doesn't fit. AccECN code will be placed after this fragment so no early returns please. 2) Make sure opts->num_sack_blocks is not left undefined. E.g., tcp_current_mss() does not memset its opts struct to zero. AccECN code checks if SACK option is present and may even alter it to make room for AccECN option when many SACK blocks are present. Thus, num_sack_blocks needs to be always valid. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_output.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index d63f505a30e2..ad97bb9951fd 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1103,17 +1103,18 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack; if (unlikely(eff_sacks)) { const unsigned int remaining = MAX_TCP_OPTION_SPACE - size; - if (unlikely(remaining < TCPOLEN_SACK_BASE_ALIGNED + - TCPOLEN_SACK_PERBLOCK)) - return size; - - opts->num_sack_blocks = - min_t(unsigned int, eff_sacks, - (remaining - TCPOLEN_SACK_BASE_ALIGNED) / - TCPOLEN_SACK_PERBLOCK); - - size += TCPOLEN_SACK_BASE_ALIGNED + - opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK; + if (likely(remaining >= TCPOLEN_SACK_BASE_ALIGNED + + TCPOLEN_SACK_PERBLOCK)) { + opts->num_sack_blocks = + min_t(unsigned int, eff_sacks, + (remaining - TCPOLEN_SACK_BASE_ALIGNED) / + TCPOLEN_SACK_PERBLOCK); + + size += TCPOLEN_SACK_BASE_ALIGNED + + opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK; + } + } else { + opts->num_sack_blocks = 0; } if (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp, From patchwork Mon Apr 14 12:59:38 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: 14051716 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2083.outbound.protection.outlook.com [40.107.20.83]) (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 D845C27B514; Tue, 15 Apr 2025 08:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744707503; cv=fail; b=NbPmtVBRGtsIO1MnIHlzAXZaKLD9IgHUDPHa/eZ5W68CibNM+WaSk5teboTre9SyjOX9wn0YSirXo2/fqtrPnG2vt3PveyXuenLjjbyRVDckmAFnPubS1+q8e8HSokIvTfVojGPbnFzPyifSjG1xFfFzhEzWNEBuK/4ll/LiXu4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744707503; c=relaxed/simple; bh=pZScXlunx27E0K/2YSh3KV2+w18w+Ce7rC+CfGYk6zI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=S0sBa9+liGVHsBnJS8a74ebaLLMSr4A+QgjExff6xNSywSWM1gMKpT9GoBseF/bvS10iuUaEZsshdUoU+AqI8hU92sD/ANuQlmHHdGNDOYj723qQDNMTbbVe+tTlti1PT57HX7/13YuX3n5lwUxAh0xfN5BRVop8kTxmGpjBX5Y= 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=GoKq4LT1; arc=fail smtp.client-ip=40.107.20.83 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="GoKq4LT1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kjSTT7HcCUU1Cr3+WnjM696O9b9oMETje1mjytleD1ZqQ9U8V5lS0SLLWe9gAUc3PHRfWTcgKo77EFKS/OkMhYoTqpoUeAGB+JCHAG5p+WvpQNmpXoO8Mm/k8CJ4VD9MDqEOPqYScAsKoybw6HIFPkIKgTFuPbZTL+6NWicDOP/0HhVJDsC0DfwNXr3/uEQnSfW0Qy8cK0hPN/TDtmFyCfcM7KKMxkbINLFLbqI5/68lIwJhMUlOCrtELvIU+9cHqFVSys1enXHTD4ysj0ch+KkNSkduX9VIpeh5ITNI9XYyLEApoKuIYxVTB5UQXsjtnxsAc/IQd00u7n+enrEMfg== 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=WEc59bxJ15jUVesl8ZX2jvg4TjaF3mnTL3rSXFRuAq8=; b=LBeZ300ccCcgC9n8PZJt1mIjeq5ujZ8zxnZbvbtchwt2LmBT076MZ2X1I4a0HJyPKfbyhD1aJIKnPMci/IyzZ5lB7Z4hXGL+ctf7EI22dx7U/BMiP+RTG4h5/pjPJ2lO/iBWgvn3s0aoOq4bxB6nnK3ZxDqP5/BDs/1An2gDTluwCAU9MWlAmFOBWUM5ywUKXFpE+EzPeNjE0g91sVNsr0MbaILv17w+C5w/lg8i+iN3iXSfwDL4eTs3/3QW2NKi1lZKbA/AUJWIpZj19kmUUgu9ipHz87PNauQOV5Vy0JPjw99WVT7fL2hkoZqfpeLPzZYZLWsTBtlfXwZhcyUN+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=WEc59bxJ15jUVesl8ZX2jvg4TjaF3mnTL3rSXFRuAq8=; b=GoKq4LT1fAOBSDSLHbDoW80t3mJqJltbFclqvwNvvk5rWpQeNgCZAaZGlFEBsEB70zYbWUJnzpomQkQc37QnWxz7MBnzuO0qwMAC2syooUd7GKwl+ClL++5ZCtf2gxTIFg4Clls+kYTLH3q8F0EoIjpaTkQNIoh2/rh/fmiuzIG5eIYgnyb6L3RydjqCCvSVJ54363xU25l4CSejTrYsyh0/W7y8VKBBlNG1TIyz3cLOzoKWVSwwK97OpRLpsPgU5d0J2wSdn5wZeNuZWd1Gn21Zq/3DKIIvxzY34niIHn3UAy7Q5Ss1naHYs52Ip9ciu68315JJjDL77lALdQJ25g== Received: from DUZPR01CA0289.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b7::20) by AS1PR07MB8501.eurprd07.prod.outlook.com (2603:10a6:20b:4de::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.28; Tue, 15 Apr 2025 08:58:01 +0000 Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com (2603:10a6:10:4b7:cafe::22) by DUZPR01CA0289.outlook.office365.com (2603:10a6:10:4b7::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Tue, 15 Apr 2025 08:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 08:58:00 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id 9B7EB4EEE3; Mon, 14 Apr 2025 16:00:14 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 09/15] tcp: accecn: AccECN option Date: Mon, 14 Apr 2025 14:59:38 +0200 Message-Id: <20250414125944.97350-10-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DU2PEPF00028D06:EE_|AS1PR07MB8501:EE_ X-MS-Office365-Filtering-Correlation-Id: 16da84ad-e001-4c3d-7804-08dd7bfb9ff4 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|376014|36860700013|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?tgKJ1tItZ2Rk/aXOAxht1WpZDrGk8ht?= =?utf-8?q?HYEVlJBxTw4FV8Pa6LuaZOWWQivao4kHuJQVRUgZ6dLjA8qLbrENayE42OLDGwsCd?= =?utf-8?q?8fhEWOtKCm438I97h7rwxDScwbsOpdtJEmktAYWXFd0SldSeq2aaHawFrRLPogmW0?= =?utf-8?q?g0f2JWzm7pM6X8ONPn9m9hRPhe0SF0VGlfFHunHxapxVbrmX3Onxq6GF8oJD7CqiB?= =?utf-8?q?ukaZT3yI6XW9zDjW0Q1fWPzzAtxJCz7HgU0D8NSLK6+Bk6IpJIi56vvoWwcD9G0fU?= =?utf-8?q?7rEIxBf4B8KfcTJYDJKG/tAMIb2Ic8jFIanh64YRHKbrIRhSu41e/ebpd25m+L3rM?= =?utf-8?q?N89n1en4rbcOwnhaCTF7qpc2zeDHN8qIMSrJlKe1RWC+yFnqCdc0lRAUB5KUdhZvV?= =?utf-8?q?ykBez7CInPAPun1+419JmIteNCW/q4fATFTBDxParNgG0tmj49EbFIua3KZ6Ib2zI?= =?utf-8?q?NjF0ZjcQMyM7pIppt5AQI9DCCAhj97u7ltd7NGmWkqQmuhg733C5xBp5WioMUzl+y?= =?utf-8?q?1hh+5pOOZClPzHVKbBQee9X2892egE5WxF1wRR9MLZ993hCWgmUDZ9fxP+8DQiaHd?= =?utf-8?q?Xo5R/5spouUWBHp6fp39jH1lKbllr99P8RFAqkos0vU+VRHt+WyHFSEx+aZ8+C4wT?= =?utf-8?q?dj8Awn4dwZBzMBESCpk2ELaGpvYwPclpl7Dk8StOObXvoRsXkdFXmuIyMBrmXx1/l?= =?utf-8?q?zEcec6cMGeDttHOeh5CP+UOKTCenedT1Rhjqsqb1IHxJsTB5aDZKuoicPKtLRVNPu?= =?utf-8?q?Kcyjz2gUH+RbaX0mNHYBtkKV0yk26jruubo7GARRtSOc7l+nlyicByKrrPWv8w4U9?= =?utf-8?q?HXCgA8CD6YhqnIbo4etu6D+tBysiLV7bj1BYe+bOolLiC5CrMmXwHL3pi9Tu76P0y?= =?utf-8?q?6ai+jgQROuSup7TnKTe1soVZmiKTG0vWoKGD3dzMcBvpyt8EsWl1UdTJTsWPQmGD3?= =?utf-8?q?6FAjogSg765nz1vZ3Abtu0kQxETM7vrUS2yj8InFmzkWr6Sz7iPOqjvAz56xsY+Ai?= =?utf-8?q?Ts6+UrwFtaeaUCy8r50BKKRTvWBEqYtIP+uPoDOUfa56PT99YAG/0dzkzevTmNWjS?= =?utf-8?q?+g53T0jRkXT5ujyFshW7/KbfuUjR0cH6vaSOMRfTrtf6ZGFc6jPpjlvHcEeypFvAI?= =?utf-8?q?n0C1pno4Ixq8ERDfefheQWyF5uMBLG2hfxxBBAI99EYcR9gFe6xAt5cr9j/H+ChC8?= =?utf-8?q?8pKdnrZ9xkrm6MqNMV60LqbfWckMlg+LVq0/fXLfB7glwle+gePPNZXh7Ps3Sihsq?= =?utf-8?q?j9uCzqFsIG/1QG+fQGgr9tcuBiue6kH8wSd1ExZurbQS/G3qlPlZg3GRbqgOCYU6E?= =?utf-8?q?FqraxRL8ojK++1Ndm32C4rmfD/T4+zdtAm4n2pMKDMxF1taGETFzmNSa/Fqy8KRY/?= =?utf-8?q?GL1Y8gqLgzR0o4URcoaD2i4xkvlQ1WtAWqvoUknXK+ch2cyDwHIFbMr5+2vtodZNY?= =?utf-8?q?n5LlfGQLRH6KOM7217/FybRA6Cifhvow=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 08:58:00.5835 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16da84ad-e001-4c3d-7804-08dd7bfb9ff4 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D06.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8501 From: Ilpo Järvinen The Accurate ECN allows echoing back the sum of bytes for each IP ECN field value in the received packets using AccECN option. This change implements AccECN option tx & rx side processing without option send control related features that are added by a later change. Based on specification: https://tools.ietf.org/id/draft-ietf-tcpm-accurate-ecn-28.txt (Some features of the spec will be added in the later changes rather than in this one). A full-length AccECN option is always attempted but if it does not fit, the minimum length is selected based on the counters that have changed since the last update. The AccECN option (with 24-bit fields) often ends in odd sizes so the option write code tries to take advantage of some nop used to pad the other TCP options. The delivered_ecn_bytes pairs with received_ecn_bytes similar to how delivered_ce pairs with received_ce. In contrast to ACE field, however, the option is not always available to update delivered_ecn_bytes. For ACK w/o AccECN option, the delivered bytes calculated based on the cumulative ACK+SACK information are assigned to one of the counters using an estimation heuristic to select the most likely ECN byte counter. Any estimation error is corrected when the next AccECN option arrives. It may occur that the heuristic gets too confused when there are enough different byte counter deltas between ACKs with the AccECN option in which case the heuristic just gives up on updating the counters for a while. tcp_ecn_option sysctl can be used to select option sending mode for AccECN. Signed-off-by: Ilpo Järvinen Signed-off-by: Neal Cardwell Signed-off-by: Chia-Yu Chang --- include/linux/tcp.h | 8 +- include/net/netns/ipv4.h | 1 + include/net/tcp.h | 13 +++ include/uapi/linux/tcp.h | 7 ++ net/ipv4/sysctl_net_ipv4.c | 9 ++ net/ipv4/tcp.c | 15 +++- net/ipv4/tcp_input.c | 171 +++++++++++++++++++++++++++++++++++-- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_output.c | 129 ++++++++++++++++++++++++++++ 9 files changed, 346 insertions(+), 8 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 9cbfefd693e3..0e032d9631ac 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -122,8 +122,9 @@ struct tcp_options_received { smc_ok : 1, /* SMC seen on SYN packet */ snd_wscale : 4, /* Window scaling received from sender */ rcv_wscale : 4; /* Window scaling to send to receiver */ - u8 saw_unknown:1, /* Received unknown option */ - unused:7; + u8 accecn:6, /* AccECN index in header, 0=no options */ + saw_unknown:1, /* Received unknown option */ + unused:1; u8 num_sacks; /* Number of SACK blocks */ u16 user_mss; /* mss requested by user in ioctl */ u16 mss_clamp; /* Maximal mss, negotiated at connection setup */ @@ -302,10 +303,13 @@ 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 delivered_ecn_bytes[3]; 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; + u8 accecn_minlen:2,/* Minimum length of AccECN option sent */ + est_ecnfield:2;/* ECN field for AccECN delivered estimates */ 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 6373e3f17da8..4569a9ef4fb8 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -148,6 +148,7 @@ struct netns_ipv4 { struct local_ports ip_local_ports; u8 sysctl_tcp_ecn; + u8 sysctl_tcp_ecn_option; u8 sysctl_tcp_ecn_fallback; u8 sysctl_ip_default_ttl; diff --git a/include/net/tcp.h b/include/net/tcp.h index 6ffa4ae085db..bfff2a9f95bf 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -204,6 +204,8 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); #define TCPOPT_AO 29 /* Authentication Option (RFC5925) */ #define TCPOPT_MPTCP 30 /* Multipath TCP (RFC6824) */ #define TCPOPT_FASTOPEN 34 /* Fast open (RFC7413) */ +#define TCPOPT_ACCECN0 172 /* 0xAC: Accurate ECN Order 0 */ +#define TCPOPT_ACCECN1 174 /* 0xAE: Accurate ECN Order 1 */ #define TCPOPT_EXP 254 /* Experimental */ /* Magic number to be after the option value for sharing TCP * experimental options. See draft-ietf-tcpm-experimental-options-00.txt @@ -221,6 +223,7 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); #define TCPOLEN_TIMESTAMP 10 #define TCPOLEN_MD5SIG 18 #define TCPOLEN_FASTOPEN_BASE 2 +#define TCPOLEN_ACCECN_BASE 2 #define TCPOLEN_EXP_FASTOPEN_BASE 4 #define TCPOLEN_EXP_SMC_BASE 6 @@ -234,6 +237,13 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); #define TCPOLEN_MD5SIG_ALIGNED 20 #define TCPOLEN_MSS_ALIGNED 4 #define TCPOLEN_EXP_SMC_BASE_ALIGNED 8 +#define TCPOLEN_ACCECN_PERFIELD 3 + +/* Maximum number of byte counters in AccECN option + size */ +#define TCP_ACCECN_NUMFIELDS 3 +#define TCP_ACCECN_MAXSIZE (TCPOLEN_ACCECN_BASE + \ + TCPOLEN_ACCECN_PERFIELD * \ + TCP_ACCECN_NUMFIELDS) /* tp->accecn_fail_mode */ #define TCP_ACCECN_ACE_FAIL_SEND BIT(0) @@ -1056,6 +1066,9 @@ 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); + __tcp_accecn_init_bytes_counters(tp->delivered_ecn_bytes); + tp->accecn_minlen = 0; + tp->est_ecnfield = 0; } /* State flags for sacked in struct tcp_skb_cb */ diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index dc8fdc80e16b..74ac8a5d2e00 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -298,6 +298,13 @@ struct tcp_info { __u32 tcpi_snd_wnd; /* peer's advertised receive window after * scaling (bytes) */ + __u32 tcpi_received_ce; /* # of CE marks received */ + __u32 tcpi_delivered_e1_bytes; /* Accurate ECN byte counters */ + __u32 tcpi_delivered_e0_bytes; + __u32 tcpi_delivered_ce_bytes; + __u32 tcpi_received_e1_bytes; + __u32 tcpi_received_e0_bytes; + __u32 tcpi_received_ce_bytes; __u32 tcpi_rcv_wnd; /* local advertised receive window after * scaling (bytes) */ diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 75ec1a599b52..1d7fd86ca7b9 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -731,6 +731,15 @@ static struct ctl_table ipv4_net_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = &tcp_ecn_mode_max, }, + { + .procname = "tcp_ecn_option", + .data = &init_net.ipv4.sysctl_tcp_ecn_option, + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_TWO, + }, { .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 278990dba721..89799f73c451 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -270,6 +270,7 @@ #include #include +#include #include #include #include @@ -4109,6 +4110,9 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) { const struct tcp_sock *tp = tcp_sk(sk); /* iff sk_type == SOCK_STREAM */ const struct inet_connection_sock *icsk = inet_csk(sk); + const u8 ect1_idx = INET_ECN_ECT_1 - 1; + const u8 ect0_idx = INET_ECN_ECT_0 - 1; + const u8 ce_idx = INET_ECN_CE - 1; unsigned long rate; u32 now; u64 rate64; @@ -4227,6 +4231,14 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_rehash = tp->plb_rehash + tp->timeout_rehash; info->tcpi_fastopen_client_fail = tp->fastopen_client_fail; + info->tcpi_received_ce = tp->received_ce; + info->tcpi_delivered_e1_bytes = tp->delivered_ecn_bytes[ect1_idx]; + info->tcpi_delivered_e0_bytes = tp->delivered_ecn_bytes[ect0_idx]; + info->tcpi_delivered_ce_bytes = tp->delivered_ecn_bytes[ce_idx]; + info->tcpi_received_e1_bytes = tp->received_ecn_bytes[ect1_idx]; + info->tcpi_received_e0_bytes = tp->received_ecn_bytes[ect0_idx]; + info->tcpi_received_ce_bytes = tp->received_ecn_bytes[ce_idx]; + info->tcpi_total_rto = tp->total_rto; info->tcpi_total_rto_recoveries = tp->total_rto_recoveries; info->tcpi_total_rto_time = tp->total_rto_time; @@ -5091,6 +5103,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, 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, app_limited); @@ -5100,7 +5113,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, 109 + 3); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 122 + 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 5bd7fc9bcf66..41e45b9aff3f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -499,6 +500,144 @@ static bool tcp_ecn_rcv_ecn_echo(const struct tcp_sock *tp, const struct tcphdr return false; } +/* Maps IP ECN field ECT/CE code point to AccECN option field number, given + * we are sending fields with Accurate ECN Order 1: ECT(1), CE, ECT(0). + */ +static u8 tcp_ecnfield_to_accecn_optfield(u8 ecnfield) +{ + switch (ecnfield) { + case INET_ECN_NOT_ECT: + return 0; /* AccECN does not send counts of NOT_ECT */ + case INET_ECN_ECT_1: + return 1; + case INET_ECN_CE: + return 2; + case INET_ECN_ECT_0: + return 3; + default: + WARN_ONCE(1, "bad ECN code point: %d\n", ecnfield); + } + return 0; +} + +/* Maps IP ECN field ECT/CE code point to AccECN option field value offset. + * Some fields do not start from zero, to detect zeroing by middleboxes. + */ +static u32 tcp_accecn_field_init_offset(u8 ecnfield) +{ + switch (ecnfield) { + case INET_ECN_NOT_ECT: + return 0; /* AccECN does not send counts of NOT_ECT */ + case INET_ECN_ECT_1: + return TCP_ACCECN_E1B_INIT_OFFSET; + case INET_ECN_CE: + return TCP_ACCECN_CEB_INIT_OFFSET; + case INET_ECN_ECT_0: + return TCP_ACCECN_E0B_INIT_OFFSET; + default: + WARN_ONCE(1, "bad ECN code point: %d\n", ecnfield); + } + return 0; +} + +/* Maps AccECN option field #nr to IP ECN field ECT/CE bits */ +static unsigned int tcp_accecn_optfield_to_ecnfield(unsigned int optfield, + bool order) +{ + u8 tmp; + + optfield = order ? 2 - optfield : optfield; + tmp = optfield + 2; + + return (tmp + (tmp >> 2)) & INET_ECN_MASK; +} + +/* Handles AccECN option ECT and CE 24-bit byte counters update into + * the u32 value in tcp_sock. As we're processing TCP options, it is + * safe to access from - 1. + */ +static s32 tcp_update_ecn_bytes(u32 *cnt, const char *from, u32 init_offset) +{ + u32 truncated = (get_unaligned_be32(from - 1) - init_offset) & + 0xFFFFFFU; + u32 delta = (truncated - *cnt) & 0xFFFFFFU; + + /* If delta has the highest bit set (24th bit) indicating + * negative, sign extend to correct an estimation using + * sign_extend32(delta, 24 - 1) + */ + delta = sign_extend32(delta, 23); + *cnt += delta; + return (s32)delta; +} + +/* Returns true if the byte counters can be used */ +static bool tcp_accecn_process_option(struct tcp_sock *tp, + const struct sk_buff *skb, + u32 delivered_bytes, int flag) +{ + u8 estimate_ecnfield = tp->est_ecnfield; + bool ambiguous_ecn_bytes_incr = false; + bool first_changed = false; + unsigned int optlen; + unsigned char *ptr; + bool order1, res; + unsigned int i; + + if (!(flag & FLAG_SLOWPATH) || !tp->rx_opt.accecn) { + if (estimate_ecnfield) { + u8 ecnfield = estimate_ecnfield - 1; + + tp->delivered_ecn_bytes[ecnfield] += delivered_bytes; + return true; + } + return false; + } + + ptr = skb_transport_header(skb) + tp->rx_opt.accecn; + optlen = ptr[1] - 2; + WARN_ON_ONCE(ptr[0] != TCPOPT_ACCECN0 && ptr[0] != TCPOPT_ACCECN1); + order1 = (ptr[0] == TCPOPT_ACCECN1); + ptr += 2; + + res = !!estimate_ecnfield; + for (i = 0; i < 3; i++) { + if (optlen >= TCPOLEN_ACCECN_PERFIELD) { + u32 init_offset; + u8 ecnfield; + s32 delta; + u32 *cnt; + + ecnfield = tcp_accecn_optfield_to_ecnfield(i, order1); + init_offset = tcp_accecn_field_init_offset(ecnfield); + cnt = &tp->delivered_ecn_bytes[ecnfield - 1]; + delta = tcp_update_ecn_bytes(cnt, ptr, init_offset); + if (delta) { + if (delta < 0) { + res = false; + ambiguous_ecn_bytes_incr = true; + } + if (ecnfield != estimate_ecnfield) { + if (!first_changed) { + tp->est_ecnfield = ecnfield; + first_changed = true; + } else { + res = false; + ambiguous_ecn_bytes_incr = true; + } + } + } + + optlen -= TCPOLEN_ACCECN_PERFIELD; + ptr += TCPOLEN_ACCECN_PERFIELD; + } + } + if (ambiguous_ecn_bytes_incr) + tp->est_ecnfield = 0; + + return res; +} + static void tcp_count_delivered_ce(struct tcp_sock *tp, u32 ecn_count) { tp->delivered_ce += ecn_count; @@ -515,7 +654,8 @@ static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered, /* Returns the ECN CE delta */ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, - u32 delivered_pkts, int flag) + u32 delivered_pkts, u32 delivered_bytes, + int flag) { const struct tcphdr *th = tcp_hdr(skb); struct tcp_sock *tp = tcp_sk(sk); @@ -526,6 +666,8 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, if (!(flag & (FLAG_FORWARD_PROGRESS | FLAG_TS_PROGRESS))) return 0; + tcp_accecn_process_option(tp, skb, delivered_bytes, flag); + if (!(flag & FLAG_SLOWPATH)) { /* AccECN counter might overflow on large ACKs */ if (delivered_pkts <= TCP_ACCECN_CEP_ACE_MASK) @@ -551,12 +693,14 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, } static u32 tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, - u32 delivered_pkts, int *flag) + u32 delivered_pkts, u32 delivered_bytes, + int *flag) { struct tcp_sock *tp = tcp_sk(sk); u32 delta; - delta = __tcp_accecn_process(sk, skb, delivered_pkts, *flag); + delta = __tcp_accecn_process(sk, skb, delivered_pkts, + delivered_bytes, *flag); if (delta > 0) { tcp_count_delivered_ce(tp, delta); *flag |= FLAG_ECE; @@ -4212,6 +4356,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) if (tcp_ecn_mode_accecn(tp)) ecn_count = tcp_accecn_process(sk, skb, tp->delivered - delivered, + sack_state.delivered_bytes, &flag); tcp_in_ack_event(sk, flag); @@ -4251,6 +4396,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) if (tcp_ecn_mode_accecn(tp)) ecn_count = tcp_accecn_process(sk, skb, tp->delivered - delivered, + sack_state.delivered_bytes, &flag); tcp_in_ack_event(sk, flag); /* If data was DSACKed, see if we can undo a cwnd reduction. */ @@ -4378,6 +4524,7 @@ void tcp_parse_options(const struct net *net, ptr = (const unsigned char *)(th + 1); opt_rx->saw_tstamp = 0; + opt_rx->accecn = 0; opt_rx->saw_unknown = 0; while (length > 0) { @@ -4469,6 +4616,12 @@ void tcp_parse_options(const struct net *net, ptr, th->syn, foc, false); break; + case TCPOPT_ACCECN0: + case TCPOPT_ACCECN1: + /* Save offset of AccECN option in TCP header */ + opt_rx->accecn = (ptr - 2) - (__u8 *)th; + break; + case TCPOPT_EXP: /* Fast Open option shares code 254 using a * 16 bits magic number. @@ -4529,11 +4682,14 @@ static bool tcp_fast_parse_options(const struct net *net, */ if (th->doff == (sizeof(*th) / 4)) { tp->rx_opt.saw_tstamp = 0; + tp->rx_opt.accecn = 0; return false; } else if (tp->rx_opt.tstamp_ok && th->doff == ((sizeof(*th) + TCPOLEN_TSTAMP_ALIGNED) / 4)) { - if (tcp_parse_aligned_timestamp(tp, th)) + if (tcp_parse_aligned_timestamp(tp, th)) { + tp->rx_opt.accecn = 0; return true; + } } tcp_parse_options(net, skb, &tp->rx_opt, 1, NULL); @@ -6133,8 +6289,12 @@ void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, tp->received_ce_pending = min(tp->received_ce_pending + pcount, 0xfU); - if (payload_len > 0) + if (payload_len > 0) { + u8 minlen = tcp_ecnfield_to_accecn_optfield(ecnfield); tp->received_ecn_bytes[ecnfield - 1] += payload_len; + tp->accecn_minlen = max_t(u8, tp->accecn_minlen, + minlen); + } } } @@ -6358,6 +6518,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) */ tp->rx_opt.saw_tstamp = 0; + tp->rx_opt.accecn = 0; /* pred_flags is 0xS?10 << 16 + snd_wnd * if header_prediction is to be made diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 5c5d4b94b59c..3f3e285fc973 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3450,6 +3450,7 @@ static void __net_init tcp_set_hashinfo(struct net *net) 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_fallback = 1; net->ipv4.sysctl_tcp_base_mss = TCP_BASE_MSS; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index ad97bb9951fd..a36de6c539da 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -491,6 +491,7 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp) #define OPTION_SMC BIT(9) #define OPTION_MPTCP BIT(10) #define OPTION_AO BIT(11) +#define OPTION_ACCECN BIT(12) static void smc_options_write(__be32 *ptr, u16 *options) { @@ -512,12 +513,14 @@ struct tcp_out_options { u16 mss; /* 0 to disable */ u8 ws; /* window scale, 0 to disable */ u8 num_sack_blocks; /* number of SACK blocks to include */ + u8 num_accecn_fields; /* number of AccECN fields needed */ u8 hash_size; /* bytes in hash_location */ u8 bpf_opt_len; /* length of BPF hdr option */ __u8 *hash_location; /* temporary pointer, overloaded */ __u32 tsval, tsecr; /* need to include OPTION_TS */ struct tcp_fastopen_cookie *fastopen_cookie; /* Fast open cookie */ struct mptcp_out_options mptcp; + u32 *ecn_bytes; /* AccECN ECT/CE byte counters */ }; static void mptcp_options_write(struct tcphdr *th, __be32 *ptr, @@ -766,6 +769,47 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp, *ptr++ = htonl(opts->tsecr); } + if (OPTION_ACCECN & options) { + const u8 ect0_idx = INET_ECN_ECT_0 - 1; + const u8 ect1_idx = INET_ECN_ECT_1 - 1; + const u8 ce_idx = INET_ECN_CE - 1; + u32 e0b; + u32 e1b; + u32 ceb; + u8 len; + + e0b = opts->ecn_bytes[ect0_idx] + TCP_ACCECN_E0B_INIT_OFFSET; + e1b = opts->ecn_bytes[ect1_idx] + TCP_ACCECN_E1B_INIT_OFFSET; + ceb = opts->ecn_bytes[ce_idx] + TCP_ACCECN_CEB_INIT_OFFSET; + len = TCPOLEN_ACCECN_BASE + + opts->num_accecn_fields * TCPOLEN_ACCECN_PERFIELD; + + if (opts->num_accecn_fields == 2) { + *ptr++ = htonl((TCPOPT_ACCECN1 << 24) | (len << 16) | + ((e1b >> 8) & 0xffff)); + *ptr++ = htonl(((e1b & 0xff) << 24) | + (ceb & 0xffffff)); + } else if (opts->num_accecn_fields == 1) { + *ptr++ = htonl((TCPOPT_ACCECN1 << 24) | (len << 16) | + ((e1b >> 8) & 0xffff)); + leftover_bytes = ((e1b & 0xff) << 8) | + TCPOPT_NOP; + leftover_size = 1; + } else if (opts->num_accecn_fields == 0) { + leftover_bytes = (TCPOPT_ACCECN1 << 8) | len; + leftover_size = 2; + } else if (opts->num_accecn_fields == 3) { + *ptr++ = htonl((TCPOPT_ACCECN1 << 24) | (len << 16) | + ((e1b >> 8) & 0xffff)); + *ptr++ = htonl(((e1b & 0xff) << 24) | + (ceb & 0xffffff)); + *ptr++ = htonl(((e0b & 0xffffff) << 8) | + TCPOPT_NOP); + } + if (tp) + tp->accecn_minlen = 0; + } + if (unlikely(OPTION_SACK_ADVERTISE & options)) { *ptr++ = htonl((leftover_bytes << 16) | (TCPOPT_SACK_PERM << 8) | @@ -886,6 +930,60 @@ static void mptcp_set_option_cond(const struct request_sock *req, } } +/* Initial values for AccECN option, ordered is based on ECN field bits + * similar to received_ecn_bytes. Used for SYN/ACK AccECN option. + */ +static u32 synack_ecn_bytes[3] = { 0, 0, 0 }; + +static u32 tcp_synack_options_combine_saving(struct tcp_out_options *opts) +{ + /* How much there's room for combining with the alignment padding? */ + if ((opts->options & (OPTION_SACK_ADVERTISE | OPTION_TS)) == + OPTION_SACK_ADVERTISE) + return 2; + else if (opts->options & OPTION_WSCALE) + return 1; + return 0; +} + +/* Calculates how long AccECN option will fit to @remaining option space. + * + * AccECN option can sometimes replace NOPs used for alignment of other + * TCP options (up to @max_combine_saving available). + * + * Only solutions with at least @required AccECN fields are accepted. + * + * Returns: The size of the AccECN option excluding space repurposed from + * the alignment of the other options. + */ +static int tcp_options_fit_accecn(struct tcp_out_options *opts, int required, + int remaining, int max_combine_saving) +{ + int size = TCP_ACCECN_MAXSIZE; + + opts->num_accecn_fields = TCP_ACCECN_NUMFIELDS; + + while (opts->num_accecn_fields >= required) { + int leftover_size = size & 0x3; + /* Pad to dword if cannot combine */ + if (leftover_size > max_combine_saving) + leftover_size = -((4 - leftover_size) & 0x3); + + if (remaining >= size - leftover_size) { + size -= leftover_size; + break; + } + + opts->num_accecn_fields--; + size -= TCPOLEN_ACCECN_PERFIELD; + } + if (opts->num_accecn_fields < required) + return 0; + + opts->options |= OPTION_ACCECN; + return size; +} + /* Compute TCP options for SYN packets. This is not the final * network wire format yet. */ @@ -968,6 +1066,17 @@ 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) && + sock_net(sk)->ipv4.sysctl_tcp_ecn_option && + remaining >= TCPOLEN_ACCECN_BASE)) { + u32 saving = tcp_synack_options_combine_saving(opts); + + opts->ecn_bytes = synack_ecn_bytes; + remaining -= tcp_options_fit_accecn(opts, 0, remaining, saving); + } + bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining); return MAX_TCP_OPTION_SPACE - remaining; @@ -985,6 +1094,7 @@ static unsigned int tcp_synack_options(const struct sock *sk, { struct inet_request_sock *ireq = inet_rsk(req); unsigned int remaining = MAX_TCP_OPTION_SPACE; + struct tcp_request_sock *treq = tcp_rsk(req); if (tcp_key_is_md5(key)) { opts->options |= OPTION_MD5; @@ -1047,6 +1157,14 @@ 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) { + u32 saving = tcp_synack_options_combine_saving(opts); + + opts->ecn_bytes = synack_ecn_bytes; + remaining -= tcp_options_fit_accecn(opts, 0, remaining, saving); + } + bpf_skops_hdr_opt_len((struct sock *)sk, skb, req, syn_skb, synack_type, opts, &remaining); @@ -1117,6 +1235,17 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb opts->num_sack_blocks = 0; } + 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 (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) { unsigned int remaining = MAX_TCP_OPTION_SPACE - size; From patchwork Mon Apr 14 12:59:39 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: 14051167 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010062.outbound.protection.outlook.com [52.101.69.62]) (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 2AE0B1F3B8B; Mon, 14 Apr 2025 22:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744669691; cv=fail; b=QVsfbbJqpgiLRdn8Stn+dRJaVayy5Q8+BpLA1eeWXWpPpQC4caBZwlPvupi2rz+3Kt6Su0qaKa/QpJm9GGxZ0aLM8GTRBqnqJJVAZAgz1GFp4oZwXJ2JT7e+k+6A8ewPZ+3PvONFmGxTDxyoY+rRYooSI+CZ2ol7H1NkkNnlPVU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744669691; c=relaxed/simple; bh=G7AD1z9w1HgJyE5etSVk9tk++GMHosLLpz93FfPbtls=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=OhblhX1qAm8dq1TBSpTdmnKtcWV8Oh7ivhqkzamAO5oN/lTrhVfoOf8g3T90hGAuRY+1ShhN2ZQRXJeFwr1jeq0R1ePleUPA/9OLv24qTgLWWwLTCTjYIwzO3SGTUuc8bSdds/ipvxIdM9XIJzyF9Jo+0t+HdU+scttI2Lqxt74= 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=GcdSdzDX; arc=fail smtp.client-ip=52.101.69.62 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="GcdSdzDX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vO7JcUVYF4ggnmzVlaOvDfyPaMncu1tyYDGOvSiZNGR6sOpKQKrVB5SQ1IqgwEaY/6DKPXjF+lSW7aYiDjeTO17NRY+Gz4rRGW8uyoCN2jS7lPPA5IYINSMBKPERDPOmjRvjBBCzYO9hXlY5WzDVVXyp7SK00TEY3M3/djr0DRh9gW3cgvXH36WRubIH4OooFUBm8Br3mke2lxCklRrY4S5ZxfhQk8kxi5on4IZ0e9R/FEYveuc2epJ6XDFirudLjlay/VbS9Y76rqwHw1hTdomYhumMKJ2b6hszyOkbCbprvTuq3qLtps/uODxR0FXEKY1oBpG8nl66RRgSX+noIg== 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=Y1bJrMT4Yx8LlVau11V3O5J0lNJGAsjJmy+SxYpINkTXXnEoZaCqxvYooVME5oC1bkI6IyRRkGDq5d019RXHPCipK8ZOVXEHGIaVxxNF5hUEYOGJ476xt8rvdaRxErmMJx/Gdr13OVD2Wki3/z7hNkjwxoNlbRxm9U2zXq7pw8AKlqEKOwoMJtD5/IFKbS9TYZW4066r5QKhQY7E8G7fQYBbqdl74qhLySLGkujv5Gh3/iOs4LSkjTBvpfWRjHIafKiY1RRd8kyYRpsPW9Bnn8dmx0Kryy73dw9ceDu0zMkgDcIdmR+qATwZR18SRBuxgJogJiF3TrFOw8A7yCs0nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=GcdSdzDXgeIkW4gw7R/+lKt7k3cK5nzguw4kPkONYRGDmaGGsDkvqP2LjNmikQgteb8Nn1YnryM3mLRHjFGmrCb9uGtGOQ/iso4aY8W/3wXMId2EF9oeclYGaAXgHKVuYG4r/sDCEcNaCl3svecrUMjm6s8b4xAmhSyDhWxd8W1C1tzeErzplRLJ+2fCDSq5FhJ7aG80CLR4Sb/fHA5mdwNbyPDmSY24WX2yDfNmm6ORD8eASm/o2RbbuyjBfRkwo6JCLwOhbXPGu2mCSdol3NTgHNe6f2TwnzwgFYM56wDAPFcdGOnuqH6pvR9yOBwA/w6t1ktkHRa4zP/WiXzSrA== Received: from DU2P250CA0020.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:231::25) by VI1PR07MB6448.eurprd07.prod.outlook.com (2603:10a6:800:138::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Mon, 14 Apr 2025 22:28:02 +0000 Received: from DU2PEPF0001E9C0.eurprd03.prod.outlook.com (2603:10a6:10:231:cafe::2c) by DU2P250CA0020.outlook.office365.com (2603:10a6:10:231::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Mon, 14 Apr 2025 22:28:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DU2PEPF0001E9C0.mail.protection.outlook.com (10.167.8.69) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 22:28:01 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id A0E3A4EEF3; Mon, 14 Apr 2025 16:00:15 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 10/15] tcp: accecn: AccECN option send control Date: Mon, 14 Apr 2025 14:59:39 +0200 Message-Id: <20250414125944.97350-11-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DU2PEPF0001E9C0:EE_|VI1PR07MB6448:EE_ X-MS-Office365-Filtering-Correlation-Id: ef7c7879-8a81-4777-774b-08dd7ba39e20 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|376014|7416014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?M7v0KVCaq3ugKf6jWJob/AZcONi5gxu?= =?utf-8?q?//9LRy5sWnBs5sxozqeUdMxhSCVX7c+N1saXOnnzJ+FFdEmeFbiynFhyqnlZB8ETy?= =?utf-8?q?etwp7amDCllVxIHEB0WIJEIel18JhuJZJUCr5QZAkz+uNw/E834c6ZQIKI7ffkVOE?= =?utf-8?q?Y0eckB2Evchu1C7z8OJcm9Gjlwk9+O+sx9ppdIicPPJXAG+9/spcb+cAdufhGdNHn?= =?utf-8?q?6rlmNyGCIOdnK/q+hfk5B51TYD4MXlYEdQfv/ybtqS32Sq1fOLKjnYRVJ0MFPPszz?= =?utf-8?q?MZXTZoNyoOC0pqsdPo+kjNgQSYWA/dDVlrj1WN/EuxE97JoJz1JNhCEVoBPfw384B?= =?utf-8?q?LfzBPVXGtzqhN6KlVV3YscofSUsoBZWBLZp9VJgpodOkVEiSi3bH6CuKQODUoQL8h?= =?utf-8?q?1mdHgobFeRGweu57GAopTgvag78AIZtYH/+FtqRhesAfEuSYIxJCbTM2t+4l6IARJ?= =?utf-8?q?NhkzEHuR1gS1Jltoer9t77U7xpbs3VzQ35V490GY6bi66lizgj14N1GP3vxA1VvUe?= =?utf-8?q?hkDQRxgyMvQskhAdTLpj7VFreGPUm/b2OP0zdmxQKau9oXLEZuJiNRRZ+uiZIZfcE?= =?utf-8?q?jYcbIGPrRVyDEX8HKWIN2s6/5jvrkg86fgakjx5DCBP4QA9Q9/LpEQIrYx3+wYQXT?= =?utf-8?q?D62nLlN7mNUf6quOygNKXzOiRDjlpV9fsUDP38k7gneVrjKuvc3F/gB/cvWq7YI9C?= =?utf-8?q?BzzfYNQtfLhtHi/SMTG/hjec5BLRk6AVPYbL8unX3uzakgGY4ZQYI8HZhzPDWQNil?= =?utf-8?q?lZegardz8ZK7E90XQj0A6EJZN0EFVesfDdnyKRPpfZ4hZJzXI+J4M8Fg56cAGUpYk?= =?utf-8?q?9jHWE8g9nCMAF25Jt3h//KE13oNKh6qshvycOVYAWlDTbT8AuZG8gKGw8RBHrsiVO?= =?utf-8?q?kv7qs9iQ8okW8PXKvtJuBoXRHq3uW0kYm2/auDz+nC3DkU2Cs3JsL4fz7BvgPROmT?= =?utf-8?q?/uHbbA/2SaKloe/MuVy6w1QnOl0gVU0Fcd9h+ovSQrFZQBPcAbqxoXTlarbh7pUNO?= =?utf-8?q?ooTbKWcpCEfhK1x2hiFY3c3gvAgO2MnCue8DWZbQsqJ5Leme2xr8/Qd5HcFiJWgXO?= =?utf-8?q?y/qB00LKIFAWa6LUFGMSDuB4ZTBht8cB/j4Di900hSRQVPTyUIw+D0x8xn3H7u4n5?= =?utf-8?q?joLnf8Fc+5vV3vLQ7TDMHf4a4FxrUm/h4QofZQ+NSbf+/rcQf7Jy+Zh7W3nu2z1wt?= =?utf-8?q?IwyRypVpRm45hdAIVgy9/6pimpvqrSCdiLcJUvB9MTiUsxqGUMJma0ZHvGoyMd7HY?= =?utf-8?q?S2fGmWZTDvJla9bQZEqV8q4w4pzyxfeb3DHmb3sk4Lv0UPoYBZmplSHWC2DEUSmHI?= =?utf-8?q?WXEBEdZagPM9h8hGlpXgk5MM+R4ySd2rPiJswaG6kszO0H29Q5jUqCuO00MnG3Ska?= =?utf-8?q?45hqAvoKWBMc7dqd8ZA/XB+4CvChpiDbFxBC2rgfWK5Ae8dCBtYfBeLZfeTyheKIc?= =?utf-8?q?8FsuQ3Y1BYQ0Z0If9SZPd+oVyuevkviw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 22:28:01.8198 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef7c7879-8a81-4777-774b-08dd7ba39e20 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF0001E9C0.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6448 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 Mon Apr 14 12:59:40 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: 14051166 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2053.outbound.protection.outlook.com [40.107.21.53]) (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 D52621F12FF; Mon, 14 Apr 2025 22:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744669690; cv=fail; b=hNVlarotZVGfAguIf7Z47HNYPZdKBE8FWGYy9VLa0o3x5/jbryGh60kb+rJ8TtodtKEA8n9OLfrvT+u7ElCue6y61nzdpNIBqlKwtSpyAnvsxvKdZ0Oczxta9U9syXC6N2npk145KO8OZxj/0ytLnzCYHBW0VL+FbVYWXDfjl10= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744669690; c=relaxed/simple; bh=KD7/NR3z7EZK3pNxTn5FeoJCQ5ELLAzCb70Q6PtqoD0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nXxOZD9Trltz8LS491qfFvd/m9nZZodUJZKdlJuOXmlU2D4FR4iic5D8N71Aykvf7i9Qo7afry88a2NOnIw4WF6x9I7pnarKXSFWrQruGaczTPnSr2P2U2KMnCz8uRYLitxuZXsbgnTZiK7RDITaF5UZDB2w3lfDD40uNFkiK8o= 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=nga/bosR; arc=fail smtp.client-ip=40.107.21.53 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="nga/bosR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T4HJfVU8wkKGNpFhC8gk3+1R6BMRjrYZvFSryVbg3rNING2gEH88MS2XjAGz/4AGtHCB4ejWpMPvfpgRi+uKnKzom/SjR8RTtokIc4+m6zGmpfv/MsJTCCrrNcTOd/1eatUfzP1XAGtmJCzuIUAlf8cg19X+lBFCs07wliDm3bu01WGZavt0lkhHsx/moLROX1jcOQH7kUo/2jk65CZ76u3Z1gzCXJC355iiDNb52lJwEHYLIAq/gHufkAUsKa2++E1cIjsBoyp19M8wzwWxTydw2z2d8NfdAviYZMqNnYZeyvINB9H7GAv3gez/giFHmQaokeSuTvL+sEf4Q4P6zw== 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=K/gq8kMU/dg+Tpt0aUYLG0OB2j9IOdaakg5P/p2DoNCdI+MR4Wd6w4oLDEuWLnI6/U/XLBZZCibaw9P205O9qYMFAxFFB6a1kFB2kUB3bM9YxtcyiuLtBp9T85X2hbSyDNAJ9Celx1AfUeRraA7RXBLMhKInK/sxe5HAWbXNoonlLjDMZYnHhUxfrNXOKbD/ZYKgyy/JrEcLe0BDNW3B3pjbfIl76VzxFVBXRCaJCTY+dzDx78rVHuASq2cFbZ1PDxxcucWA8uqUVfzFD9t421D8UxEsFS3TPKVwmd6R4aOaFldJmrT/DCavs8qYvDH4fmWuAz4758jR+b53qRqIUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=nga/bosR9e+ARtqzMSQQwXpx2CNz7F69E/ayBvpF8IrH0wxLW4ZhGb7tzLjCxayTlFAMMgZPaQdWNZ1Tt9b3qBd9Un0l8RwpsRYvXrFe6MyXyHX0k/2PMYsVBQZj34fNH3Lte89+5bAvkxjqJ3CdUy7RZuVMJah5Ap7JC5TZBk7nZaBDay+g67gwr05KIrQmx4a5Y04nobEg4LR6nFOqStwzZ3BmMgG6ImeGbqhyq5bp65sL0SJrgkQMhgs+rJ2UbZrGpO9FsspkF1walM2f8fC1bqZP63/OQuSc6lDlRsX9O8mlmUzFabnKDVjdWbGQCyIG2+S29TsFXVP3WhsdjQ== Received: from PR0P264CA0152.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1b::20) by DU2PR07MB8347.eurprd07.prod.outlook.com (2603:10a6:10:2e6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.35; Mon, 14 Apr 2025 22:28:02 +0000 Received: from AM2PEPF0001C715.eurprd05.prod.outlook.com (2603:10a6:100:1b:cafe::cf) by PR0P264CA0152.outlook.office365.com (2603:10a6:100:1b::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Mon, 14 Apr 2025 22:28:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by AM2PEPF0001C715.mail.protection.outlook.com (10.167.16.185) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 22:28:01 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id A0C294EEFF; Mon, 14 Apr 2025 16:00:16 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 11/15] tcp: accecn: AccECN option failure handling Date: Mon, 14 Apr 2025 14:59:40 +0200 Message-Id: <20250414125944.97350-12-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: AM2PEPF0001C715:EE_|DU2PR07MB8347:EE_ X-MS-Office365-Filtering-Correlation-Id: 3dddf4b0-848f-493c-b16a-08dd7ba39e2d 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|376014|7416014|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?1jL/X/9BUdB3WG5NPl4nK05c05CmxUM?= =?utf-8?q?rP0GXP2RPH937MDtofbivoAZK57dwF9OWz11KOW+HqyJQmwcqbkDALWRQ8hC0Vn/A?= =?utf-8?q?vnlZ4KLsLubHLqxgFh1SqEw744TtfFFURM7+bM3+fDTz+Z4CprAlJvPUOMO0evof1?= =?utf-8?q?QXRzdh8sZGfvMUDK8H++Hu7t+driR0u6cY9JqAEEc+w2l1J7FgSAeYp9A4Ov3pxJ4?= =?utf-8?q?ddhfU6JklTmL3bHt/M1R3c2tJ+ijcQaOKkCvb1R4jmEeyiTy0CLLsDIxs/4Iu1RjM?= =?utf-8?q?Dni4zhVVZ+oKw1JPEOROzmMooz6U5zP3zEvmG0p0VH4Kh8hE2xFqVRZ2UYa1rwpQw?= =?utf-8?q?y7JhVbjhTSx0uzZulGuN/QAGPt704Dqh+Nz026NEBx70MywsLgNztKmkI/anRWyxR?= =?utf-8?q?Dfr5gRDKH5036khfOy2PS8i+bjGNjpYJP9yaPJYuWvDwuha25TWxBEvENDPKP0tLY?= =?utf-8?q?N7rwrpzD0MIicETjxFms9FjEH3hX+UyEjkm+3gn8VkOuG4y7mrWAB8huVe862aOnj?= =?utf-8?q?zZO/eW+wyBqGC/9lpP9aJJadjuoByCaDT1zD2cvDkV9BNEAsrJp0tA2wj7uAH3Pkx?= =?utf-8?q?F0+NpsqJ0KxLo7yMIr+3AN+TtII8ikR/oq0cGsCeTJvAZXAGFYW4/QgCPQbkOO35P?= =?utf-8?q?hK6zymLbzDdAGTt++KMjaDG2QTEL6mgv7ObVXWA2Wgqi4hplN6P9D6xdQKdZ+5Cha?= =?utf-8?q?b1umSTqF3/Noo9EQEf6VgZnXfSNSKqeFtntJuaLNAptGFSxKhjbkDGARthFAOdLvg?= =?utf-8?q?LAjaeyFqLj8zsRtIq1Jafg4DntUnewqVgGzTu6kBPmOSloCsdIeLnwisJyjhbqVur?= =?utf-8?q?tU/7Rne6nBA90kbz70weAZpM6HzJC4LVj4GT9u0KQ4j3uOtRelkaC2gF7MJ/R+QBb?= =?utf-8?q?HqvYHvmaDYqfA5pg3QDFmcidFu4x15EPrRieYV8Qwa7SGhfuvu7sqMQE/N/XIHQAD?= =?utf-8?q?b/dI9iBbr6MdjuLcrfxUahetXZVxBdUOAW7iPTQL1XTt3USBQz21gxK3P2Bd5K/cX?= =?utf-8?q?tPH+Jy/IDQJY9Y3ai7bUQz+lsnxdB3GuOrks6YuMLrI+Zd5wfGIpxlqqUnJVECcj5?= =?utf-8?q?9b/cj4vWdPura/7oHOWBc4oDMEXigBCC/fGUZPG51lgT/M32JHEKXcmBsjaxLlSVg?= =?utf-8?q?tub4jWh/hSg2vx8xm2APxFSUbtsrLZ3eVY0TjUDRpo26W9B2CddBgKCUGbA/MS468?= =?utf-8?q?txUmb3KDvCISEtUUscWus778S472V3RZLAtTMEyGAko1P8niwffKKmDxG3afVwiob?= =?utf-8?q?+EGAdE0Eg92cdDLdugVsKQQ7QpLRqgLco5Ossfn7v7AVxghShwe8Mf/9ixvOKaFmW?= =?utf-8?q?xcQO74ycuYthcnWuayJUB2H68/qPFsveoaUJtRvqtz15aYB6xtpuqXoTtdM3r4HLE?= =?utf-8?q?9XgeUp2yvngWZwT+hw2VwLyKtFA9jkPYTTPtZBffNcRs8IJ9dDQveVWvp7tKnuWTL?= =?utf-8?q?4fSdRrx9jS1l535M4P2PAwtChqMrcH2w=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 22:28:01.8127 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3dddf4b0-848f-493c-b16a-08dd7ba39e2d 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C715.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR07MB8347 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 Mon Apr 14 12:59:43 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: 14051329 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2078.outbound.protection.outlook.com [40.107.249.78]) (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 D225F3A1BA; Tue, 15 Apr 2025 01:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744682286; cv=fail; b=KgryT5ZVKE2nnqHYHaNzTP2JiC1Hha6G4agsoQ2o16DMDKksehv6OlX9k4wHDH5pNVFCJT+buzMcW3g07wTp/uPDdOaP+p7LpfzTS8khZ1P/MC7ZgJVg66i8+HNWRbLUS+qf4S8CAKYIiEErvblXjh+2buM4JBbr3lR27WmE/fU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744682286; c=relaxed/simple; bh=w4JD0NL/AHwo1JfoAZFre+bdqHcUx1W0DN0F2Zs4Y58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MWL+FrZqGdAV+k1PItd5g1oSg/qNZD7HblJEYZkdQ9s1G8WpFNzjwyOKOiGHRGwk12E1mE+VeZi75Oi+pTdbI9dGMhoesOFKT+apnqO8gzTWsf0ggGShvkIALsffuuiwPymopZ3xnOEZIpUOU8NVeWkuHTFgxwzk5oXMZI7tLr0= 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=JtEttDHF; arc=fail smtp.client-ip=40.107.249.78 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="JtEttDHF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HD/jyR7ccx63xusPi89XhYoYobSY84lZ9OdFr7IzHKyXurcYXMCfaUbmBKxpcjJM/oGMGBgQsK64pPxbtySqcn/HtV4pCT6CGSPRmdEvyFx4rDSYxQIZRZ/BEleJJYarM5Yb9QdSStWCEtWDXwrwG4PwRNPOHiQSsSniv+4RDhULaz4ZsAE6Mq+y6CFx7XCVxjBaY1okA7W8BVhXBfYacbxwmFWq6j0E4k3uJCPnXLVqZOGcvaP+4xuCENt7HYEMqJfY+BvMA/4KoiA8rSjZ5KYT0UOU2IBxOR+mAdT61uK7fGAaC9Nm1JoXeTs832H+eYB3Y4/MK6Psr3iXfA3AMw== 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=SMcrZYM463qpXcRhkrG0+mbXiFQzAPSySth9TyHjelo=; b=g5l/jHyL3V+CoSLwi6zdF67fCFvxr/+V25D5ZypAvSj/YfzVSBIG/mO368dBnkKN1YW5kBa+7C1nhFtzTxHqCQ33l7BVbfxzkg/UQxDQ0Ue85DJEf34GlrLU7of7RxHgX2NmLINLRU9u7sGqVOZEwuUWeL6j8mE2Dj7u6JNv5dcxXhy2oC9kr6/PBBVHIbXafpgZ/50kCBkloa5cyXzEU5+NrRH/VfYCLKZmxJyy+JTaMiJd9Mgg+W1kctKaqIMBW2fi+JPQjaX9PnQs8Hm38P4bpgl4DvaZBpOSfu9LWj+Jy92DpVkh3LnVCGOSalzyinQeRVh7GKfMvIFyFywrtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=SMcrZYM463qpXcRhkrG0+mbXiFQzAPSySth9TyHjelo=; b=JtEttDHF4cpCfAD8P6MAipTi8H6Hdv3Bhc8sUtoRsp/diS9W7deeosS9HD2aDc9BZIfTu/FzmIcAkMJIeVOlZclxO0rG1RKN08LEE3Hm53t3vzWwEpqBwOcpE1rxFHZ0pZJGfkMKzs//64HmGEu2gcoj3iRVTFLmfCGBe8iVKD/GdpOrjnyGfCPCW00g5OVYVaTAB8dFHldlsli3WHO8UA3WPglApzwNHoYXIWjkKIh43ZSIuvfnvD1/XZX8mnPKHXQKoBVuJGcwSNF7en2EbWCJe2Ox2q/WbBHSgv2v1FMJyAzyLzlx1dtYXUGw1tcS5prnY+Eq78ke9RbhnGjbfg== Received: from DU2P250CA0008.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:231::13) by AM0PR07MB6259.eurprd07.prod.outlook.com (2603:10a6:20b:145::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.33; Tue, 15 Apr 2025 01:58:00 +0000 Received: from DB1PEPF00039233.eurprd03.prod.outlook.com (2603:10a6:10:231:cafe::f1) by DU2P250CA0008.outlook.office365.com (2603:10a6:10:231::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Tue, 15 Apr 2025 01:58:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by DB1PEPF00039233.mail.protection.outlook.com (10.167.8.106) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 01:58:00 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id A26244EF75; Mon, 14 Apr 2025 16:00:19 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 14/15] tcp: accecn: try to fit AccECN option with SACK Date: Mon, 14 Apr 2025 14:59:43 +0200 Message-Id: <20250414125944.97350-15-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: DB1PEPF00039233:EE_|AM0PR07MB6259:EE_ X-MS-Office365-Filtering-Correlation-Id: 388b04c7-d3d6-4730-d418-08dd7bc0f373 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|376014|7416014|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?D57JjisHvIYbmHh1Cp+uVDQp+s/XTq5?= =?utf-8?q?aDpc3PYCNIgIWrmsEX7eYNOJ14L/i1OQ9ZWfN6v7peM60HRZhxfUfzPyKEVCNi0cT?= =?utf-8?q?iskyzEOvyGBTFs88nTR8t7o4LVhd5RB4KifdfLZDLnrHJISh0UEeLUIPmSChaUERu?= =?utf-8?q?saTtEOOg7ONulaCmaUuuWWL1fyL6uTDdKO5nBReIV6ZS1f6GFG3nmznwibq4DaDzK?= =?utf-8?q?aWQJO2sZ8zvJ7ASVmQ9Y+cMAYLeH9jALdFmUUTKglCuk/lr/ZECQ5Z7kyRlblkwHv?= =?utf-8?q?Z5GLkTbxHOVqcmiLIu+NGWJnsuvsy3p9mR9CQ25lyHRnYbUOrNSbtdnlDSZeB7/Bg?= =?utf-8?q?hD9jtsLU2reUOvqAxVl1VHSR1TC+yB4uprmnDZtryNBWIyLPk/2WDdSBbdGY2RE9F?= =?utf-8?q?rcIyyogDKAzRoNLYP8nliJJqw78gUrQ42tpwwDynDY9OqcXvldXK6MNHBvlEJ3KGG?= =?utf-8?q?qoF79CDsIElHsxfXLg6xPgSrJoZaiqw1/8NIN1IRDtzleL5P6nLkVioj41nznnz3/?= =?utf-8?q?NZ4dB61JSy8hMovcVJzPwzaCC5EKaUkHu5I3j1I+lr2aFiLt9Z14DJRz8ZiHATKyl?= =?utf-8?q?vbNUfb/A3W0DssKaWAVR4EZgA6ipS8V/t8qEojOyHqCg/kKRs6RP4ZZImG9eHqJ9+?= =?utf-8?q?Q/ZxhHYIA28mXmp0AOK9XP5gS4RGGqM6amgWONxCcjdbaWPhl+n+2vB8RxExx9rV4?= =?utf-8?q?4L8wHWoRhCZVOM9ytC4LlWUKGr9xW+PeBjzd4qxPp2HITR+74jjpejT5er1oELEKb?= =?utf-8?q?el51/vj4qQGi7e6buqkg0dvxJLSSS83M7e0/Hn6GrwJyaPkhZDsMb7Fe2BYXZ5+zg?= =?utf-8?q?qyP2wIHuGjtNMT0VX2D1YHUmxMUXmrUKKnGiMpKKjOQyZxj76ux7FtXPqGG0Sfbgc?= =?utf-8?q?sD/VwR8drT5SeF2PoG7RNVGjHN7+l95DFb5at0s44XyCmEyS8HpJr96jNslvHQP0t?= =?utf-8?q?iN4gr2zmOAzWpBxHF8tCv5qQ1tdKRJHnyCgQWWMYADS+JuXEe05KaML7U697E9lxp?= =?utf-8?q?5RQU/qEnuRxAX992o9RS4XInu71EWHyQBuC5KbHiIinW8AbmQ+vhgRDx3pPAL2m5j?= =?utf-8?q?sOtixyK55AYGJDpLgq250zWQcq7ThU3JCL3L8HOy5tMKdvrs+vszfjBEOg9wQdNP2?= =?utf-8?q?skApX9A0Ver+oW4ubqzweFOMASnnaIevetZKQ/U4KjKyb2a554FpuTisP7O0oRvEp?= =?utf-8?q?4O5G7xNEHR0m72li0Gp359RQo8GEd1ON47gDm1yJ62YTRnxbPlbtLwJZo4dB0W1g8?= =?utf-8?q?iy8PjNs9eus/yFokF5Aar2uC9/Bh3tffilG5cv4vYk2nTE6oq9bYL/rvkI6A2h1cD?= =?utf-8?q?bDqbEtuRKOcCdX78GbMRxRfghlqBH/OEbMFIlut3cviPnOH3vAxuUwU9D3FUA9VLY?= =?utf-8?q?cuCLBaO3xqSRgFW2ZDVOSqXsq3WLPq1RjL+hSWagumum9mhLy8IFAm8d+ccE4FmuL?= =?utf-8?q?ZdKqJnZqKqkhV9sgwCgpVyt92LEALMWQ=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 01:58:00.3776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 388b04c7-d3d6-4730-d418-08dd7bc0f373 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00039233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR07MB6259 From: Ilpo Järvinen As SACK blocks tend to eat all option space when there are many holes, it is useful to compromise on sending many SACK blocks in every ACK and try to fit AccECN option there by reduction the number of SACK blocks. But never go below two SACK blocks because of AccECN option. As AccECN option is often not put to every ACK, the space hijack is usually only temporary. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_output.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 8e1535635aab..936ec8788c8e 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -981,8 +981,21 @@ static int tcp_options_fit_accecn(struct tcp_out_options *opts, int required, opts->num_accecn_fields--; size -= TCPOLEN_ACCECN_PERFIELD; } - if (opts->num_accecn_fields < required) + if (opts->num_accecn_fields < required) { + if (opts->num_sack_blocks > 2) { + /* Try to fit the option by removing one SACK block */ + opts->num_sack_blocks--; + size = tcp_options_fit_accecn(opts, required, + remaining + + TCPOLEN_SACK_PERBLOCK, + max_combine_saving); + if (opts->options & OPTION_ACCECN) + return size - TCPOLEN_SACK_PERBLOCK; + + opts->num_sack_blocks++; + } return 0; + } opts->options |= OPTION_ACCECN; return size; From patchwork Mon Apr 14 12:59:44 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: 14051236 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2046.outbound.protection.outlook.com [40.107.20.46]) (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 E946A15B54C; Mon, 14 Apr 2025 23:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744673888; cv=fail; b=VBYYCmbBZZmHEt03fZzPlTVdLyFn8lVsK/XuF37msrgc06W1QlQhhw0xtUvWPcKvZpQji7J2peaCaKR9kaZWhGpFsn4L5rHQMYJciJZAf4hov1uurd6+xMpQyBPEdjKiti8h3YVHdjzThqISwCYjR02xOGllYSicVXuPdWejbxs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744673888; c=relaxed/simple; bh=WJHQxI6i/fEm60bcI2XfCDvqnlxwPFZf87Vi7aVBoy0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=fOmYqgc7vSYkPEFz2O4T9uvV3LQUHoDFpQySsOj0itZRVuA/qaefT+tHsE+X8/lb4TBKM39bJPc5TesBJcHy75iFKYAE4bXp6by3t/xj3Rkk8FRAogEt22AajWcKFVl3VcDCf4SfO1CJVn59IUTjg9RwkqaIwTjFPtg61F00+2U= 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=WboQoVXP; arc=fail smtp.client-ip=40.107.20.46 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="WboQoVXP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yT7GRNFllASwvZoIdGLAqT0J4cIZEwSgyZ3B4I0Nq9YKc9tv0JL4ivFCAg9OF3HUiweTyTLtZA9HDZXUCvGkTal57IQ7rM4DurWxKe+9vkLs/qwqGZKgThAHwrPIH9/scMasyyCw78BnPOvhrnBcXK4pPPjic17qwJddwnmvNtTzDx4eSGzyqL5VagtRRhljkGrWT923LJnFh1xhIb8a5+iV59CCrvHdvr/09dUdiPy+l9NM1QzBemeqX1ZhpQ2RTbFF6q0Qq0xmxlCWb15lco1MdHh3SOoNcFBA/UHmu8C4SwvTrFcpf6j4EBW/pq+AbmnqCtmH9DJWk1lrf7IHJg== 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=bJrGNiiOHulkzV3MesfEyK14yRPd86Kdu/49Wik9ee0=; b=HV+DUw0O9dBuVHYdZa9P7xDoKxhrh9xf2nJ2/w+0qQcv4eZa5ctlJgOojVfjaJmD9AE/6br5hhMPjvAyAjRWHzNpigZmPpWuHRh7NmLSehcWCPWlJ9MZimIBU0eOHWJO9gTauIWHoP6J8hGeuN6l9nLnumxOA6fNoc/hiwD6I7x/U9c42mspVbYLUmr/zE0WJssLmS1Nb5cgehMhxrWx9nx/GbyQIRp7sp1C0jiBTptLLokyBFAzeclF0zPMc/xpW0qYl5uHT2z0G7XUey2NFrgjyXqpFeGmvv29R7h8M50nO9mLviwIz3yBfLy5W4lLnpxdLc1XpubmnRQLIYWCrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.2.20) smtp.rcpttodomain=apple.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=bJrGNiiOHulkzV3MesfEyK14yRPd86Kdu/49Wik9ee0=; b=WboQoVXPna2mJ7IA53keFA2AzIA1K00vAq3358r2CJjaZh3xPKA9ltlB6Uuqe4fewxbB3YpsrDOtbNvIyRPfTdA5GZh2TnQc1OySA1iRmgM/BFJDSKkAGBx0vu+ZptyJyxSbh5P9vZ8KumqNt29wt0EG6GXwp6VpW4eVvTZxqg8zc6J34mgpvHnCE1FNNiVG3/mH8JWDV9NJprK+uZGaTNZ91BDHKMcZJ/PLTtw8J/ts7xVrXJRCLXhE4FmD7L4D2VwcsdcAai0LnSN9HZnZD8bUoLl6wrRubSYsVKfU28hPBMJm6M91JJakx1vcQuaQ0Hce2GejO5WivxDsw0JZ8Q== Received: from AS4PR09CA0018.eurprd09.prod.outlook.com (2603:10a6:20b:5d4::6) by PA4PR07MB7552.eurprd07.prod.outlook.com (2603:10a6:102:c6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.33; Mon, 14 Apr 2025 23:38:00 +0000 Received: from AM2PEPF0001C708.eurprd05.prod.outlook.com (2603:10a6:20b:5d4:cafe::8d) by AS4PR09CA0018.outlook.office365.com (2603:10a6:20b:5d4::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.35 via Frontend Transport; Mon, 14 Apr 2025 23:38:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.2.20) 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.20 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.20; helo=fihe3nok0734.emea.nsn-net.net; pr=C Received: from fihe3nok0734.emea.nsn-net.net (131.228.2.20) by AM2PEPF0001C708.mail.protection.outlook.com (10.167.16.196) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Mon, 14 Apr 2025 23:38:00 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fihe3nok0734.emea.nsn-net.net (Postfix) with ESMTP id A83C94EF87; Mon, 14 Apr 2025 16:00:20 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: 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 v3 net-next 15/15] tcp: try to avoid safer when ACKs are thinned Date: Mon, 14 Apr 2025 14:59:44 +0200 Message-Id: <20250414125944.97350-16-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250414125944.97350-1-chia-yu.chang@nokia-bell-labs.com> References: <20250414125944.97350-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: AM2PEPF0001C708:EE_|PA4PR07MB7552:EE_ X-MS-Office365-Filtering-Correlation-Id: 576218be-d72a-4b4e-d4b7-08dd7bad64a8 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|36860700013|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Leu4/dTo5cblCgmZydm1bV2Gzyxlhh6?= =?utf-8?q?nkOeuA3qEU3gu9uNu8SAHiKcdRyexsVXSiOjG0HG9gI6bzL1U/MN9GXGVfErN8sXw?= =?utf-8?q?M5n66RasY/wphk+1vc67mBLGvbFB6a3T8rissO+h4Ybbb124RcnQHrYqpd7etH0C6?= =?utf-8?q?Sb0yGWCFv8g7xdh5zA4xboIBSV1nPvmmmPxy9YFL19xbSmGR5Lj0YHbJG9p256xbu?= =?utf-8?q?3OVKeJZXacxXQHBbPlhiKMRF4yd6REzaDMbXleGyO9D5mSEqcMEu9D6GRXMFeS/Oq?= =?utf-8?q?lemF6oL0sxZx7wBZUsGJew8+s3mEUHOoVXkAJaH4OdkF12Sq9uTESiOyIg/rn4DsH?= =?utf-8?q?ZFVmU7xiM6C5BvtGe7V9az8ewRVVFmI2vz8/PY3EymRGwdFkDgIsDJr0Cdx2IIeDY?= =?utf-8?q?aIZjLJgno7YamULhKnx//NUoiYWyNjxrwEDRxOxu4u81HLoIPa4cEJ+vW6yeykWzj?= =?utf-8?q?YdgLqsiK4Um2tKBm3+lOWMYKjqKL91r+gNHkJCuWe9FLZI4UsGQ07oimZljgfzwWA?= =?utf-8?q?IaysLF3XK56SwxaEgmxh4qgRFcbMAuSN29TXHjXZunPoF1Yb/LSrErFH3SI78nn7Z?= =?utf-8?q?GooIBI0mbTRmkLST+izkt5ntalINL9DBJZrtzyc/0PxvOTufwWeIn8KBzT/fMKHxf?= =?utf-8?q?v6/FPbSY+H8fQcDbowBDN0LIzWGlcpCFnzx2A3tFkVBcvsfDj3UcC+1q2WutBjuWv?= =?utf-8?q?3mBICsLlugbA+irHjTTOtWRv2y56pIqbPCa7V4zCXZkttRnIgIlVlp+bcas6zSTaA?= =?utf-8?q?/990W2JKGbw8EIaUfweUoxL5bIXgUCZRjxNXWjISJ14pZGFHuKdLD1w/yRGBV/SLU?= =?utf-8?q?ewThV1LjXPYPDdQr/eaC/8nugwea8hgOF/Y5j8FP2Bs0r+mzTasrChaUY0+ju2Pt3?= =?utf-8?q?d1mooQboml7F9QSp2YGez8DnrAxMCTa5QQclod+1rCjKLeBLDndkJao55YzxWdCQw?= =?utf-8?q?2BfzmDdTY6Njw8x9t0ljoM2XL3gcoaPbv9BBn5FHhxz2RWbBk64w75hPfpof7TldM?= =?utf-8?q?4rmjdYkAi3+1w9IQJoK/65BCwbSVV1Y/nom7E19EqxlIrLBRPql4NkCmViMfelTsH?= =?utf-8?q?Q6L+7P0yGmGwOhAbtu85BvKE2C104Lq/M3L4BoVp1fQRyWKJDuU56noZ2N25k0rzo?= =?utf-8?q?WL5xlaFZm6V+RazMddyp8gqXfgr6Hz7OGXc6tTcE7TOvS+DAthE1P8W/FRV7btmRV?= =?utf-8?q?yMH5AQVhrdg//lThglmjfGPYvxu6Xede4iDV+qFHhw4+f+WgiqJHpqbAThB7Vh0P2?= =?utf-8?q?yse0tVHhnXt38ZTVFUXf7BGgtJYhbqMyTCiawjU5QrWLEddN0IiWr1oAbiD6ZSchZ?= =?utf-8?q?q2Qgji6nHljCxTgvX9CiyyygHZEs+duu8ePHlaufJ+ey5mDpcAk3rE+WJbqfZEynw?= =?utf-8?q?S+7g9gdNBGsZc89s3YT762SGoWQC3dFwRbyunV+DzjVou08wvwL5mt+b6MUjXrm4U?= =?utf-8?q?r3pJqMRQqX2uP1EYJ8i0OFx7guYr8nsw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.2.20;CTRY:FI;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:fihe3nok0734.emea.nsn-net.net;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2025 23:38:00.3885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 576218be-d72a-4b4e-d4b7-08dd7bad64a8 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.20];Helo=[fihe3nok0734.emea.nsn-net.net] X-MS-Exchange-CrossTenant-AuthSource: AM2PEPF0001C708.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB7552 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..673224273540 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 + 4); /* 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; }