From patchwork Sat Jun 21 19:37:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Chia-Yu Chang \(Nokia\)" X-Patchwork-Id: 898920 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011019.outbound.protection.outlook.com [40.107.130.19]) (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 3AB4C27054B; Sat, 21 Jun 2025 19:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.130.19 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534671; cv=fail; b=f0/6ToFDB9FRHUg91V9fKbAdAPKfUHaDZL7Ohh/+9+/nnqLBGk98s5o2XZVnu7vuiA1B9mwfhdIlCg79EXTnywSLUrW2aN4nJ4nofDOjdwMLnEruHEb0RV98APKwLUf1b6Vvlmfzb2f/1rDDuyvgH/ZPoZu0B4mu3tpXrgwtUF4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534671; c=relaxed/simple; bh=HrthedlZLSF5PvL+mGmj96I5YV+Xk4AUUKoKHivcNic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=b1VlsvA5nN5/vrGt5ketNpv/ZsF5euDCpDhA00+jxfsf4yOfa/2NGxAbTRjSCRLfrbLCuy79vdvAUTyRmE1DCBjYX7lu7qvIxN4RwYFtosTLWCgHlMqJb7mJd+Wyck2SVeU7D0eZohLSpZ6/U4d7lvPTlNTg0zLVwd0cHmBnqYQ= 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=Spc3uUx+; arc=fail smtp.client-ip=40.107.130.19 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="Spc3uUx+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kRz8eQA5jgBYZAAr/3fKITok8//mI6BhoABVrLYPSiIdFycqILCQ7QhO395Ri3WF5494wrmiYP0hCtHKdrsSN/88V39Z4Baet8IMfTjPGSNKcmfcBZV9TPxoPp65rySwMIjPRYzO6hFGPzf9ZocE6KiXGbjEgHy4zHzsu7U47rSRJEwK6aVr+OwKFdMl7C2mRVz3qfEckRm7n7MnRmo79g4+0gSKcjQlrbdLXhfmvBpZzdY2PvUCV3fyPsDeTP/2qYTLIbZ9RdRomrIzPraVLlh+p6UAtNpYB23NeOpTpW0giKh5B9YGHWnnm0dMXMVxfiA2EfwuiO+p/XIDMfFOuw== 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=GxhDhWo+zuu9Jb2jKlYN8O7BEJ1zmYitwA27xZNz6d4=; b=KBDkKMPW7JGPLF+fYR+dMrLIOKgEMgXc7TVA8rD3P3wz2XherQF6GDlR1RGwj2j0nGuf3MUR6KXeYYu0Q3CkR49cer/y4cKnKm5l3rkc+h7Zb+nQt1vA0DzjA1rzuoDV7U1PRhy8r7iXK5Go4GmfPKW1EAFNSDkwDUd7KT2OG+LZwSK47nnKw1UjCRn36jC06JTsoEdoVBdPYY7EMmiHXDvKPTM+IAIUmXMnmBEBxmBUuctkTyhAYSEgfZLPWtih+NvHZRoU0dY2ijYnakqcYmr4edrI5yDvqyQCqMkKIup1DZCGmCGB3cZWXfM8g0rFDDMCcebH68wIGTU3YtmL9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GxhDhWo+zuu9Jb2jKlYN8O7BEJ1zmYitwA27xZNz6d4=; b=Spc3uUx+6fbqqFhDwYB32clSzAbVPeOxnwmTQh/vysXG1MX8A8ysSM2wxVGb7q4hqmgoeQ0CmF+Jk7dJjS6q2mPIE4PxPnB+lvmJE21wz9ZkmlicOnp0jfCSfAivk6VegqkUEG/rgNGbJFE3HJr43+4+DTIietlg8DYpx/gj3z5um59FArfFQTvLJR20YlOq4X3ZaVRbR5/l7U8KM2m1eD8Gub1H8W/SYgoCWbSRCMHbUzF6bsaPcXbLBJulkTH+QL4Armav2CsHqZCBqJP7UVsXpZfGBwzQN/E4lJxAMsgcWGkvLndRFNwxOL57bJoxw06Si+dUlDMqpVitpm4wOQ== Received: from DU2PR04CA0226.eurprd04.prod.outlook.com (2603:10a6:10:2b1::21) by AM9PR07MB7299.eurprd07.prod.outlook.com (2603:10a6:20b:2c6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.27; Sat, 21 Jun 2025 19:37:46 +0000 Received: from DU2PEPF00028CFF.eurprd03.prod.outlook.com (2603:10a6:10:2b1:cafe::73) by DU2PR04CA0226.outlook.office365.com (2603:10a6:10:2b1::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:37:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by DU2PEPF00028CFF.mail.protection.outlook.com (10.167.242.183) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:37:46 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id 054C21C0010; Sat, 21 Jun 2025 22:37:44 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 02/15] tcp: fast path functions later Date: Sat, 21 Jun 2025 21:37:24 +0200 Message-Id: <20250621193737.16593-3-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: DU2PEPF00028CFF:EE_|AM9PR07MB7299:EE_ X-MS-Office365-Filtering-Correlation-Id: 24dd53a0-bdea-46dc-5ac0-08ddb0fb1977 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?tzWqBb7n+wTQEGvhH1TEp0nbx2QFzVs?= =?utf-8?q?DD5U/tyRSnbWjXbCaasX5emUKdj/qUccJUct/WLmC8NwaJe1ucNrxs7lMPGh/UNuD?= =?utf-8?q?ZE9MGraJliFU7JVAIpIqJBUrwZ6oeBiLU3ytvBpEq1UhySB55gJ5bjoJXIvOVjCsC?= =?utf-8?q?wqUipACPidbyyN89g7p1WQXStQatYHqRvrdNPaAemWhvjziG08dcs4WuEBrPu0M0Q?= =?utf-8?q?fRzplJstiHOMRV6dK+SUedN0LrB+EVXLLDTPHmP5kJFSyr9NDHMk6smA8cIOHDVYE?= =?utf-8?q?uQNKjQGNiyBAyH/csTgp5IQN/CuXDXMcYfKjqu8hOLb3IbKuRH6wRpEXsbt8Yv7va?= =?utf-8?q?L7uUATrb9rl0NY4VKeaK0SgXFvX3z9Dhljn+1DIXAIkBBfvoN93V6nh+Xb7Grqb/2?= =?utf-8?q?bGlWJX1+zWKt22ntTC4SXqfa9Y4cNjxUHbxl6YTYKHgO19AVkZwsOrOK1M4kgVqda?= =?utf-8?q?C34s/rsTMnQ3iiAI4RGsV8H29yZ/cG8cnOoVbojj3v5N7EOP3sPO+s29yY+5kn2rE?= =?utf-8?q?R1w9mMobqXCYHoH1u+uOUYV7lZj6+t4iMEg7MWelCzmF3zw4pTW1AEx+2pjNnpNuf?= =?utf-8?q?G+nPBDGUziNRiAw6xWIlOT+73pWmbOB1hb2SKyBsrvLDLBoZPF3wzPwsAGLffQUVn?= =?utf-8?q?Ulgz5lS0Xqj3LFtEDh/1M0AtbMk/ofCnZf37HiJS7RG01gx5Xmw5sYc+DgFTh08OW?= =?utf-8?q?1XjGfpo1EHlZMiFVJIPxqntKD0jF/8KEWK8Iua/4pkQ+yaJWXqmAo3Sw33oRNkVs/?= =?utf-8?q?TVOBw/4yE9PhXsbv9lV2Odc9dnwzC2B6FfjUdH5OlxXY27Kd4ysBdOjycj4CjJrZR?= =?utf-8?q?bbkwmSfSJzIg5CjA3e9/n1j8Xf5XNFCQN2/TXOZ9pi0Bev0xkvQ8PxVP8T2gVhrH1?= =?utf-8?q?goDNkrAAraUxj9wvjVcFN5EyRaClYuwBm1MoLjsZhcnfqqkrG5LbvBqajX/zBMV87?= =?utf-8?q?rok+vxLbH8hNdJm+tKZTBdoPZHYiOjsoyHVsE13zLZTVsrEY+5yGzzfqK0uGNiO80?= =?utf-8?q?lIsZ/Yn/DHpsFrFrzRJbkubW/oUj6rY8yK+o8ZKae6vv1vexfKK9n7tamuXi8VSAm?= =?utf-8?q?CQD2iMFPIMwCwEQ53/OxDCdJGgFM2B9GjU/wPjJ98XQHCe9SXN6R4GhJ6XL3I23Q4?= =?utf-8?q?gIVlxxDmar7kyDhCMRP1MR9OMc+H7rWu+QQshJ9uKAjA+5ac7btsZhmiFdSe7h5si?= =?utf-8?q?nzxVYLVZb8X0htoYmgF1A7oOAqpwDSuFv4oL6eqR/Kylwid8ONobMAxmr88TuccM8?= =?utf-8?q?n+m/w2Z3ohRMxF20w1fxH6f+W6ewxSVa3QubeFsdnrN+66B3EN5XFqtti+aAsPR5O?= =?utf-8?q?byfkLt9QSpoW8CBo0ukJ5rYhA1PmLE2xgy57Ba7NW2FfmEdalA8YwnPHdFLeGwUSn?= =?utf-8?q?niQRcqQ3DeNkbsKdB89we2gWNeItwS+n6RBpXyS+3tToIuTf2Y2OqaQ5ksQ+bjrAq?= =?utf-8?q?1L7qncCtbhh5wSRnKeDhclxbRRwbXyCA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; 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: 21 Jun 2025 19:37:46.6221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24dd53a0-bdea-46dc-5ac0-08ddb0fb1977 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028CFF.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7299 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: Chia-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 761c4a0ad386..ed01ae4be7a9 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 Sat Jun 21 19:37:26 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: 898919 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012057.outbound.protection.outlook.com [52.101.66.57]) (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 4C9E726F463; Sat, 21 Jun 2025 19:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534679; cv=fail; b=MruGH4XQr4jn5Ae4Lh1U8qQJdyWgmAga96MUcY+rd7B9cAHFBpUr6j/q+FwCkcwHj+uQVtMt14k09BcMvFYl4Ho015c2K/XHKLXgN8ZpqftpIbGufm7ik08rqstsWJZ6rHtwrTrCbQvX9qgYVWUlSV4YHPTXo/rhf/M0g6lmr/s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534679; c=relaxed/simple; bh=BsDwe9MN9EhKNmauP0xy5BZhVt8S6cdTXLndNNId6sg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=iply4OhTs6l15mlQZjbtL+TgZfhj0dQ9OBgjXiaHH31OgXNYBxV7eO5+DjmvmLojqwepEG+f01RwoT+zvUh9ORbRbbrSk2I9henkbuxAy7gFo8sYPF+Vs7pnBxPIQs7ft/7plC3SOmhhMPWpS9Wom7PySYzeHyAJdcrcUIcgyI8= 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=iJBhkXnn; arc=fail smtp.client-ip=52.101.66.57 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="iJBhkXnn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vcqQBdnILuEr/ZseF64ky4bZ2oSsE9HpChWVmAd+rNuHdVBMj+xm37GtCLprZELjjyUFokDFoJAmphLYXO7MkY8sjrEDMQTou8LWJgxfDOVrfNPjEdAsLqTKJAfyT7CLIyhDC8rwrJFCOLFRdZc5KgguX4YI9B/Ocrf1dgC/hQIUkf+HFRH+Ljwbo1fMOjaVssu/fYSFv7bPqS+HjVjMeSbRqTTBheQ2EawpuoPmvWSYRo8ZG5ARecs35b2fgEGxHxBDwTt3/cBnUnkJbRZnFBIBOxJOgsUGn4ATt+pYzS/CcBn6qEgT4fkKKXn0Slb+PVQGRWKlMXwe4WKV8QEHlw== 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=QP/+0hgbTOeuimz95knht2mhD+W1Ii3B7b9fato1e/U=; b=kbtemn+UAIdo1HNplKtBHK+Av/dcHek3YwoJ7clhJymHB4gqU+xOWiCiwY8Nh7trVduLo1voIR6pzIu7SMcA9BEn1nSN7kCWAO1s7XX0EM68sqDm7l3S5nZToVu6vPHKuIAAVJev3zIYZMz6rG9+bemKLzQdhqGnQF7XeU1kccFeQ9aMWkGwv1Yu32UoXuFmgY1T5ybWZBKY5N0L9/MxJdy9vumuIjFIedWIrdmEpOh/8wIPLIJ3saQXjNfDHHPYUhqGSdXz0Td2hF1hiooz6ysJXIdS/M+SI2t/ECIZAvkf9Ig7G+xbAiTT4WP0tBAsRCCaDZmsOUkvxKjBsKwAtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QP/+0hgbTOeuimz95knht2mhD+W1Ii3B7b9fato1e/U=; b=iJBhkXnnN7Ne4N6kWySlCyGuBt6k6pgDmQHskt/ofn9WgSbirw4WaN9LdXDmDW6PWrq5p+eaqoSYBJppCwHWXVRl4uH0bqSp21SesSADb3sMRrkFuQM6o7TxCmTu0XE06bVPnU6aPeiMNQKrb5KhS4v51wvIjez71hXqt+F7PDv2FTs6APFUm7UOrRau8ZmaY5bgC5fwLJh4edsuG/SFKKGURe7qMbyMoZ2m/q4STDqNqxjricFkMaZcY+DST9U5E+ldRgAB9mO4Sn9iJrVQ0Jvi0eMLpOnIfRPkaW6Wr1f0j30l73e00pxffSqjou02Nygf4T0tKA5fykAyQ16pmQ== Received: from DU6P191CA0056.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53e::17) by AM9PR07MB7106.eurprd07.prod.outlook.com (2603:10a6:20b:2cd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.25; Sat, 21 Jun 2025 19:37:51 +0000 Received: from DU2PEPF00028D0B.eurprd03.prod.outlook.com (2603:10a6:10:53e:cafe::a4) by DU6P191CA0056.outlook.office365.com (2603:10a6:10:53e::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:37:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by DU2PEPF00028D0B.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:37:50 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id 332EA1C0031; Sat, 21 Jun 2025 22:37:49 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 04/15] tcp: AccECN core Date: Sat, 21 Jun 2025 21:37:26 +0200 Message-Id: <20250621193737.16593-5-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: DU2PEPF00028D0B:EE_|AM9PR07MB7106:EE_ X-MS-Office365-Filtering-Correlation-Id: ab2fc577-4afc-448e-b700-08ddb0fb1c0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|7416014|376014|30052699003|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ahBORSK7NdAnfOiBcedWwi7WNw8CGHb?= =?utf-8?q?4i9wrV0RGQk45kuqRrgbmDVUAZezKyi4CJYT2VGhEtbvn72EMzoDNXvYrnqqnhxF5?= =?utf-8?q?6Y7H6rbNXB17GAXa7AkJnCTc4w0yIveIsKilVgdOBWWVoKWROd3QW69zzV20ZRibL?= =?utf-8?q?7rIGsdOPgZj5AYLTJTz/mfQJk7KmSmjbMbI7v373u/pW5nV+3fvXkAWwR/5MehVzV?= =?utf-8?q?h5/uqJVvGyRJ18s+YKOWpunjm9UkszLB3Xs5oukg27cWGGk1rFjLeKQXIqQfWyM7I?= =?utf-8?q?qY/yyrFVgRSXpqJTQ5f8dfmcHdJn0OJptbEFHlsbhF+Pc5yOvWsPcoQAJs1gZsq3P?= =?utf-8?q?98GpvALfpekfNS88m9TM7LvscSyTsp8We91G340Exwn3cVj8Vs/46Xk0ppycZcBvU?= =?utf-8?q?AyP8ocuwdPoVLtBAOGemaO7wVy8fKHxLV6VLEkWApd4m4+W6FAQra1D3AV1djwHvS?= =?utf-8?q?EiPjh1KhEI50LDDLnXQL5bJxETJ08ndae/4/WunKzAJycstIMHJNVVDZONnvWfZeZ?= =?utf-8?q?NB7BLacJxzFr+bsfjS9hsfKCrXkhQsHE5i+/iRCUO/JTXbT6BFt6N/nrmKji1ObIj?= =?utf-8?q?4+UVAcwysbeEqfBdAAtP1ii6zd9zYGpuuPF0iQ05CRbaCdSvc7/VxL1gBnYDh3m1B?= =?utf-8?q?wNmNRiNfiLImidVLp1bs26Pf9fC1TJaZIuflDqt0eL+1+ykzAklovjuESADQcKwgq?= =?utf-8?q?2EIlmkz84buxmyzy9DVScPD7OfhvWNXYnw3qzrRbPLpXZ0fbMWXgT8oZ6Pff2FM/w?= =?utf-8?q?Z9KnLc512uLjskpa85oLZSkTLewkGtfFt5seADwQH3+0ni+29JIjOO0uwONqsbSMG?= =?utf-8?q?XpyOz56shOjNcLE5vPj8OAgRae6WVLoPtQjHxiLcmJK9qR7Me/UoPUPMJlexFVWrX?= =?utf-8?q?cfvYFDrj82I2VgY6IscYAZPyGpGk5qoxf1HHMzUiG8qBaxgnAsfUAiW/qABDP8xU5?= =?utf-8?q?hDnXOHCDXx+Zbx4uDP6Pdb3tRzOnFTYrkEFN0Aj2ypg6F+fhik7zbdfTJdjlimF8w?= =?utf-8?q?9t6CN7eRKaB4z0oKEOw94pSSOtP1/pF9/Kh+oE+9R7Eh/gQ7ALHAiEadGBnMddvmM?= =?utf-8?q?bNDEx+8ItchBuw6ZjbGq44xLk4h5W+YeLObfDNBtiQAaYniiLkovFYbIrR0OyrV7G?= =?utf-8?q?nlBSdKXG/eZsbJEo+50CF6Q+WeFrS+SDGIgs34S54KZEGwUU1pVYOXaWzp/69OUYI?= =?utf-8?q?Fd9U/OUkJkX9j13tIfduucC4WIIV/4XZc2akMCpFQ2xvaan+segKcXFaOuPUIZvbb?= =?utf-8?q?WS0CB9UCHaUySFyiHMBhU+im+UAyIk7+XWruqupd9MZHGDw0B1/brH+8Mks8ZUln1?= =?utf-8?q?MGgZlqDulQldwuqxV7RYfnsv6AhlzylTIsXuriVSslhzuhwgY3KMvBrTN0cg33LF+?= =?utf-8?q?TrqDNgznC5GDq/TVEvLhWjMtA+2s5t1WHIYTnucmLxu5f6F3iPtR1mQ3Moi2LqqEM?= =?utf-8?q?NNuailthtEcN5y2S5iGtqSkUP42B1usQ=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014)(30052699003)(921020)(13003099007); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:37:50.7903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab2fc577-4afc-448e-b700-08ddb0fb1c0d X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D0B.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7106 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. This patch uses the first 1-byte hole and the last 4-byte hole of the tcp_sock_write_txrx for 'received_ce_pending' and 'received_ce'. Also, the group size of tcp_sock_write_txrx is increased from 91 + 4 to 95 + 4 due to the new u32 received_ce member. Below are the trimmed pahole outcomes before and after this patch. [BEFORE THIS PATCH] struct tcp_sock { [...] __cacheline_group_begin__tcp_sock_write_txrx[0]; /* 2585 0 */ u8 nonagle:4; /* 2585: 0 1 */ u8 rate_app_limited:1; /* 2585: 4 1 */ /* XXX 3 bits hole, try to pack */ /* XXX 2 bytes hole, try to pack */ [...] u32 delivered_ce; /* 2640 4 */ u32 app_limited; /* 2644 4 */ u32 rcv_wnd; /* 2648 4 */ struct tcp_options_received rx_opt; /* 2652 24 */ __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2676 0 */ /* XXX 4 bytes hole, try to pack */ [...] /* size: 3264, cachelines: 51, members: 163 */ } [AFTER THIS PATCH] struct tcp_sock { [...] __cacheline_group_begin__tcp_sock_write_txrx[0]; /* 2585 0 */ u8 nonagle:4; /* 2585: 0 1 */ u8 rate_app_limited:1; /* 2585: 4 1 */ /* XXX 3 bits hole, try to pack */ /* Force alignment to the next boundary: */ u8 :0; u8 received_ce_pending:4;/* 2586: 0 1 */ u8 unused2:4; /* 2586: 4 1 */ /* XXX 1 byte hole, try to pack */ [...] u32 delivered_ce; /* 2640 4 */ u32 received_ce; /* 2644 4 */ u32 app_limited; /* 2648 4 */ u32 rcv_wnd; /* 2652 4 */ struct tcp_options_received rx_opt; /* 2656 24 */ __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2680 0 */ [...] /* size: 3264, cachelines: 51, members: 166 */ } Signed-off-by: Ilpo Järvinen Co-developed-by: Olivier Tilmans Signed-off-by: Olivier Tilmans Co-developed-by: Chia-Yu Chang Signed-off-by: Chia-Yu Chang --- v9: - Use tcp_data_ecn_check() to set TCP_ECN_SEE flag only for RFC3168 ECN - Add comments about setting TCP_ECN_SEEN flag for RFC3168 and Accruate ECN --- .../networking/net_cachelines/tcp_sock.rst | 2 + include/linux/tcp.h | 3 + include/net/tcp.h | 26 ++++ net/ipv4/tcp.c | 4 +- net/ipv4/tcp_input.c | 132 ++++++++++++++++-- net/ipv4/tcp_output.c | 20 ++- 6 files changed, 175 insertions(+), 12 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index 7bbda5944ee2..31313a9adccc 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -101,6 +101,8 @@ u32 prr_delivered u32 prr_out read_mostly read_mostly tcp_rate_skb_sent,tcp_newly_delivered(tx);tcp_ack,tcp_rate_gen,tcp_clean_rtx_queue(rx) u32 delivered read_mostly read_write tcp_rate_skb_sent, tcp_newly_delivered(tx);tcp_ack, tcp_rate_gen, tcp_clean_rtx_queue (rx) u32 delivered_ce read_mostly read_write tcp_rate_skb_sent(tx);tcp_rate_gen(rx) +u32 received_ce read_mostly read_write +u8:4 received_ce_pending read_mostly read_write u32 lost read_mostly tcp_ack u32 app_limited read_write read_mostly tcp_rate_check_app_limited,tcp_rate_skb_sent(tx);tcp_rate_gen(rx) u64 first_tx_mstamp read_write tcp_rate_skb_sent diff --git a/include/linux/tcp.h b/include/linux/tcp.h index bd692764d039..874e0e45dfad 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -287,6 +287,8 @@ struct tcp_sock { */ u8 nonagle : 4,/* Disable Nagle algorithm? */ rate_app_limited:1; /* rate_{delivered,interval_us} limited? */ + u8 received_ce_pending:4, /* Not yet transmit cnt of received_ce */ + unused2:4; __be32 pred_flags; u64 tcp_clock_cache; /* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */ u64 tcp_mstamp; /* most recent packet received/sent */ @@ -299,6 +301,7 @@ 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 */ 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 ed01ae4be7a9..6cf5cea992e3 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 18b6cb7dc02e..8e0e8d784b1c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3392,6 +3392,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)); @@ -5118,6 +5119,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); @@ -5125,7 +5127,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, 91 + 4); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 95 + 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 19a1542883df..0fa3803b353d 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,16 +387,25 @@ 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; } + /* As for RFC3168 ECN, the TCP_ECN_SEEN flag is set by + * tcp_data_ecn_check() when the ECN codepoint of + * received TCP data contains ECT(0), ECT(1), or CE. + */ + if (!tcp_ecn_mode_rfc3168(tp)) + break; tp->ecn_flags |= TCP_ECN_SEEN; break; default: if (tcp_ca_needs_ecn(sk)) tcp_ca_event(sk, CA_EVENT_ECN_NO_CE); + if (!tcp_ecn_mode_rfc3168(tp)) + break; tp->ecn_flags |= TCP_ECN_SEEN; break; } @@ -428,10 +440,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. @@ -3787,7 +3853,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); @@ -3795,8 +3862,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; } @@ -3817,6 +3888,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; @@ -3924,6 +3996,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) @@ -3948,7 +4025,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); @@ -3957,12 +4035,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 @@ -3983,7 +4065,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); } @@ -5821,6 +5903,31 @@ 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); + + /* As for accurate ECN, the TCP_ECN_SEEN flag is set by + * tcp_ecn_received_counters() when the ECN codepoint of + * received TCP data or ACK contains ECT(0), ECT(1), or CE. + */ + if (!tcp_ecn_mode_rfc3168(tp)) + 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 @@ -6083,6 +6190,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. */ @@ -6127,6 +6236,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); @@ -6167,6 +6277,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 974e4062be88..4b32aa619594 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,7 +393,14 @@ 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; + + if (tcp_ecn_mode_accecn(tp)) { + INET_ECN_xmit(sk); + 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)) { From patchwork Sat Jun 21 19:37:28 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: 898918 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011057.outbound.protection.outlook.com [40.107.130.57]) (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 AB1C0271441; Sat, 21 Jun 2025 19:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.130.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534682; cv=fail; b=QflEk5Ajw48fWfYXM2KkXwtaHzEUW57IOJNIcJHSNnKjcbm7LIlrDrl0zyf1cfzpmDP9gs9YzICPtyR1ZIUNhKQCPGk8lmgDAka+Gj2kS0xkoCTgbYholS/XPl2PNsLPHUQr4LbhQYEo6UqyWllboExgxD0dqqYfF1l9QPdK32Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534682; c=relaxed/simple; bh=cXDxxqZjYwuUFhfArfwmR8C1PMi46PlQdyemKT2pXiM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nS+RFJLnScyXuOr4CarQFRgGUFQXR8G8eBBbUZXnAEr0UzEA8mmbBNsWB/pwMFXWeC5OrFwRtYgP/Nvs9BNKuC3Betuh6eRz6VUiw+wL6y6lz9pzcpp4pvwGZ8gYzSGM5vT5/cWiryPx4pt1TmTE4HWhDNoH8WJgbuYuDO2gnbg= 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=tJgLccT6; arc=fail smtp.client-ip=40.107.130.57 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="tJgLccT6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T25/8qBwk28oLALhKPhzPDSNURvu1jkGCRjWM4FNI5C92LQidyEXSjjpZPXtQXRhDXylT2BQxuRaV65rUxGJm+fjQVw/iTROjMTSGbEmu7i9L+BfBg7uoDFPO8FqTcYho78XlnUd4vjRZqfr0jE4yj5G7Dtm4jpVM5BXoZHgxQ6HFd0qJR50uzSO6rjPVIlJFbjCfSJeiAW/wgbmN+ajr7QrMojx352/Y6rfXp1MWyAgbVVzYP7Xk5bFYPSOWEgXy6JTvvWJCINAYOxWx/aaMpVzkbEuqhuH9BvV6IMdmd561HCga8QKKsmx+E3/9LlE9wzadFO5T03CXdPSzBPUXw== 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=MPOAQU/te96NrkWhNBihknml/Sn+kaOMwRsDqN9Ipb8=; b=wjc3DVVqBv0atXSBMXGmBbx/+dlBRGghGOr5GqmgNFtX2ZhNB5BZnY6Qmo6GSFoXqe7Zi6DMeQ5yzkc9Px0u7OPMNhqlbkmH0tZt58luWP61I5lzkxl3d72ePAuQ8rdugKWnFT2CtSq2qr7f63BU0YVMoGK0DqfKF6IWHP2S6t3nqLIzRAsVY9owU7dZvyLiFRNXjUbs4eCaIH8qDObqqt5IH5ZEjshDZQqdCJUf0UQ2EWUxw0KcP+HnoTZy+Adl1Vt6kOuvdduA7wyAis+8tsZt+e59eJdWlhkIcKtW2PyVXqBAktslmkPZv6ahTN0ObYy61gcLGfk1+7qOmqmuyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MPOAQU/te96NrkWhNBihknml/Sn+kaOMwRsDqN9Ipb8=; b=tJgLccT65A8EBO9lzVgBQ5KZRy4cEXtKWOFaSStemrkp7Onl0d9y6Pk4tt3JOXuQb+Mi8hgrP07gAQuKXQtMO5u0J6rpenMwfGxye8gw3Dj6BU+99oIjwB2Z9v2AyuzXUwe81xvkbcWg+4O+el+Xw4ixqdHlF7rNTzEKJmif/ClxOShgogLK1ZWdf9Wq2o1vsQnhQVmYM40hsmZrV3ftgobeCig8dj/BsljgaNzV7145LTo8D+Y81r7yR02YQWmWXUao0J018fb5QR9SjPIdHUiCfZbduViy4Hg+KYHfVChTea0ZT7MJ41xQW8e6HhmmSoqMg60CwFSgWx8ZGJDkXg== Received: from DUZPR01CA0004.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::20) by PR3PR07MB6939.eurprd07.prod.outlook.com (2603:10a6:102:76::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.26; Sat, 21 Jun 2025 19:37:55 +0000 Received: from DB1PEPF00050A00.eurprd03.prod.outlook.com (2603:10a6:10:3c3:cafe::62) by DUZPR01CA0004.outlook.office365.com (2603:10a6:10:3c3::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:37:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by DB1PEPF00050A00.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:37:55 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id ED3741C002B; Sat, 21 Jun 2025 22:37:53 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 06/15] tcp: accecn: add AccECN rx byte counters Date: Sat, 21 Jun 2025 21:37:28 +0200 Message-Id: <20250621193737.16593-7-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: DB1PEPF00050A00:EE_|PR3PR07MB6939:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f913919-d964-460a-fe5f-08ddb0fb1ec6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|7416014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?G3nNwoJSxlpSUia4TFQaFtJhz5gxIzr?= =?utf-8?q?xfFwJKYjwlx6tre6ZvEoyClciLQajIN9uuZVCB6ETuSsVOzAGXQ3ZpOGm6ofoVOs4?= =?utf-8?q?PAPUfe9FVqzi48nJeP/z86RGGuD02IalhDpLprmmpVzzZMEJOh0Xl7VeMcKNaCdP7?= =?utf-8?q?2gUJJq87p4e9pSyLv2e/gi4OxtYo0A2gaLIH/klEauw89gJ2oJSpQyUyuwQtR57qt?= =?utf-8?q?6IIWB5+USpbFaqfym+qKTVFWSBkSnOMhZS1W23QRJJv6v7sagEn1g1Y5p2Lr879Dh?= =?utf-8?q?AYfICVMroUC+fJYSVns9rD9FXcupEitcrptNIdA/ly44FVe9rha48q0FA7jUlSi4T?= =?utf-8?q?glBOeClwWFHF+JlL0Yp8SHPwANxp4zXc9Nz60vUEgMQJEowXB4hXER7qnoDXOSt1A?= =?utf-8?q?6OhUBU8WUoottr9oxKvGmms9bV5W2PupITa5A9htHqKPYIQ6NWYFhUgbtnu52x/w+?= =?utf-8?q?IHkEDOsE1ZQPxJx0zaHfyY92n10Rpt/goOpqyB4oa2SAw0qxonANVOPtVIBgQxkTO?= =?utf-8?q?ymxeFQD+7EqOK/43UICdjhrIt5KrDRcCpjVSFDoiJ68vb1OSB9nh7gw6/PZqKd4rH?= =?utf-8?q?PNtTbJ8Gc/iG+x+15ItNEpSpyiAJIw7yUJEayKQ8uaRLxQGQdYef3PJhpAS+SVnIb?= =?utf-8?q?tDBZol7Udqdd8+KSsRjfAFKdJmhu5YXx/ZCoDSIzy4fm2oVuhrDaAAIroOCiczrna?= =?utf-8?q?RYSai6XfZYcxVI/Pp63BMY3+qlvIZkRvMIQ1ZulPRzJrfrZRB2+wO9Y/fS6lHsKmX?= =?utf-8?q?kWFFE2CKyzYvUgGpgw37jv7aYYwiAxUUh7LPxiSrayPQVk6ws1sAWi4IV0+Ua7ry3?= =?utf-8?q?zFdQNu5mQqUgpL38suNoYViDff9BqzQGbuIPP/lbLVA3fgehnPAxHF7W4ORL2y6SI?= =?utf-8?q?75pDV5iYjOg3jd3MSX+ifBR/b+8BQHcmlQfK176zBZbJwz4U+z1AXrHA4P8Wks3pc?= =?utf-8?q?qq2eawgkUfl5tJC6J+5A4hggNM6I5BIGTWeCAB5RuFPyEAgYeaBlWrznp5YZxgw0C?= =?utf-8?q?vUaHWyfLiUfby3aLDTZGEoRkSyy9zuq9rUO9o4D4frTdgDqSYkFPTksd0Zzh5vDFY?= =?utf-8?q?yfPEH2GFgENmYn6PW+mskAnrdWTZ+atqOQ8bcY4dzLRxECOZihJDN6JU183fFTZKC?= =?utf-8?q?7nVhID7kKnGyjVTt9I+MRUlles+ecbo6R6qCRLaInLNta6oeSGt2YvcLEkzUOCvDn?= =?utf-8?q?VWvs2QnRhbX0VSE4MaVmRvNfLERJt3eIZ/MajHialSIM0mi6+keS4XMAeOvtcK2ow?= =?utf-8?q?tYg/5M3F8sFq6pH1UHwjN4Vi5LH1gaOIFzMt4nc+k4dTZGCQzUaVNQ1knUCLMdZzq?= =?utf-8?q?BPXYpP1QBYQowqJaZj436nb8mDiHAyV0LiM+vzgcr3fTSeR5FVGgtMnXnEd2Bcm1E?= =?utf-8?q?dDtN3yGTXQ7rvdld2s/cctD4pn2Ty/OEMfJfrO82ybIshWGH35FxTw8+0fAdR/xlF?= =?utf-8?q?wV1CrmNKr3LTDkgfKC3wuAEaZ8NJz1dg=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:37:55.5305 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f913919-d964-460a-fe5f-08ddb0fb1ec6 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00050A00.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB6939 From: Ilpo Järvinen These three byte counters track IP ECN field payload byte sums for all arriving (acceptable) packets for ECT0, ECT1, and CE. The AccECN option (added by a later patch in the series) echoes these counters back to sender side; therefore, it is placed within the group of tcp_sock_write_txrx. Below are the pahole outcomes before and after this patch, in which the group size of tcp_sock_write_txrx is increased from 95 + 4 to 107 + 4 and an extra 4-byte hole is created but will be exploited in later patches: [BEFORE THIS PATCH] struct tcp_sock { [...] u32 delivered_ce; /* 2640 4 */ u32 received_ce; /* 2644 4 */ u32 app_limited; /* 2648 4 */ u32 rcv_wnd; /* 2652 4 */ struct tcp_options_received rx_opt; /* 2656 24 */ __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2680 0 */ [...] /* size: 3264, cachelines: 51, members: 169 */ } [AFTER THIS PATCH] struct tcp_sock { [...] u32 delivered_ce; /* 2640 4 */ u32 received_ce; /* 2644 4 */ u32 received_ecn_bytes[3];/* 2648 12 */ u32 app_limited; /* 2660 4 */ u32 rcv_wnd; /* 2664 4 */ struct tcp_options_received rx_opt; /* 2668 24 */ __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2692 0 */ /* XXX 4 bytes hole, try to pack */ [...] /* size: 3264, cachelines: 51, members: 170 */ } Signed-off-by: Ilpo Järvinen Signed-off-by: Neal Cardwell Co-developed-by: Chia-Yu Chang Signed-off-by: Chia-Yu Chang --- v8: - Add new helper function tcp_ecn_received_counters_payload() --- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 4 ++++ include/net/tcp.h | 20 +++++++++++++++++- net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_input.c | 21 +++++++++++++++---- net/ipv4/tcp_minisocks.c | 2 +- 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index 22ac668fe6c7..804480d39132 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -102,6 +102,7 @@ u32 prr_out read_mostly read_m u32 delivered read_mostly read_write tcp_rate_skb_sent, tcp_newly_delivered(tx);tcp_ack, tcp_rate_gen, tcp_clean_rtx_queue (rx) u32 delivered_ce read_mostly read_write tcp_rate_skb_sent(tx);tcp_rate_gen(rx) u32 received_ce read_mostly read_write +u32[3] received_ecn_bytes read_mostly read_write u8:4 received_ce_pending read_mostly read_write u8:2 syn_ect_snt write_mostly read_write u8:2 syn_ect_rcv read_mostly read_write diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 1d8301f2883c..0c2331e186e8 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -306,6 +306,10 @@ 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]; /* received byte counters for three ECN + * types: INET_ECN_ECT_1, INET_ECN_ECT_0, + * and INET_ECN_CE + */ 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 4d6325fa3f67..b861941a2213 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -467,7 +467,10 @@ 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_payload(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,6 +1038,20 @@ 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; +} /* The highest ECN variant (Accurate ECN, ECN, or no ECN) that is * attemped to be negotiated and requested for incoming connection @@ -1053,6 +1070,7 @@ 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 e6d7b5420c88..0e779de3ce01 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -5122,6 +5122,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); @@ -5129,7 +5130,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, 95 + 4); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_txrx, 107 + 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 c986452302cb..5c0159cc0083 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6013,8 +6013,17 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t } } +void tcp_ecn_received_counters_payload(struct sock *sk, + const struct sk_buff *skb) +{ + const struct tcphdr *th = (const struct tcphdr *)skb->data; + + tcp_ecn_received_counters(sk, skb, skb->len - th->doff * 4); +} + /* 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); @@ -6034,6 +6043,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; } } @@ -6307,7 +6319,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. @@ -6353,7 +6365,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); @@ -6400,7 +6413,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_payload(sk, skb); 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..f1e698c323f3 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -500,7 +500,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); - tcp_ecn_received_counters(sk, skb); + tcp_ecn_received_counters_payload(sk, skb); } else { tcp_ecn_mode_set(tp, inet_rsk(req)->ecn_ok ? TCP_ECN_MODE_RFC3168 : From patchwork Sat Jun 21 19:37: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: 898917 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012067.outbound.protection.outlook.com [52.101.66.67]) (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 8E2AC26A1AA; Sat, 21 Jun 2025 19:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534684; cv=fail; b=fOBV7rdgBzVBNRGKto8tFfqOUSQT/ARO8gpx6OI0xWfGQbXiKFgjUBmlTSe4LvvII0ipuhm4K8imxXKPgQgdBUsDETP8nlWV+/MC5er868X8o0qrNOQ1KWUdpj9SWQ79WBH/1IhECVQ7YLSy0SPrq2fwwJ6JnfAcP8QqiDIqL0s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534684; c=relaxed/simple; bh=iFcTZmQz+KoxMbWnmT2MTrBRX096Ooi/MssASdIt668=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=e1cVdmGiG+ukvneD9mcRRmSkG9qlJ2uJDBz87ei2ei4mpmqAWvArqZDRmv8QQ3oGmvWYw4dOpm+tjT0I4OIQyfT2s9bZ0MGb47OVAs0fuQFfU92z5IlwN7pg9ql1M34FW74FhQlNZLpLzkT26SjQ+9WoD4Ngz8LS2hKloYjQZIM= 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=rVDu5ZI+; arc=fail smtp.client-ip=52.101.66.67 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="rVDu5ZI+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QMquD+z+sf9uP2RWYr/L4kZxnGG2IUTtrnim3cTLCuCV5IdGxwdjWvt1MYJ1Gn6RvAcsQjISFkVZwGGUhd6/gNh00WKL98mS/HgJh8JMDeNpYdtAB6eNGX9KOZe43Zt9LVeZ/8AFeqW/C35HxyYWIRFFfIEeWZlnnBw4WQ7RKeVAUHR24l9XOgNTSiQO1e1eBWZ5BjoG9zrdEuhOxNtmbnGjf/yKIkh27+5X+2ZI9IO3kDk4Wp0T31PP84R3XdhBeUBUkp3zsLi2fWaq5cNO650iIlvmp4Haru0M24cbax2iG6cmW8L7Z7g2GHQ9cdXPoK4+S3eFcrNEb4Caf3FMxQ== 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=ohyzgWWmf7ArvRe6GftbHhI6Bzqti+BWAQUIhv2YGRs=; b=Xk7Xow7MGCWEMdLXHZ9Q5Ncwayt1QBvtjeZDFxQO+peIpCPqLBWBF8WUZoIRDfvE+YjHOOc7yFtzZrfdbr777qixDLTa7ngCWdrjrNVx3LK0gshLHKm1VcH+5/7IHqPMzOPNb9PsE5mB0OxydTLZJ/CNDcKbdYHVqi0s9Ge+0CkXZ0YlI83oX/HFjy/a5R7Cq/KHVLyLqJhiQf2WeKprS/zgx+ydt6eeKRYQpqUypBw5YJ2K4ctwTIG9fom6ptQY/AlMvXq7MIxwzX9NLPQ5KhVv4EAN0UCu5C4BJOmRY95HTJqY+82mb5m2CuF9yVhpYaEb0t/5j0Y/r44Dr+4kzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ohyzgWWmf7ArvRe6GftbHhI6Bzqti+BWAQUIhv2YGRs=; b=rVDu5ZI+ftT4i0x7T1ma88IAYzP5qppceRhiNkWuuwiMdIiQ/5xxqRBu+TQ2KLXvM6iPkimQA3Wv9MULqM2tyXtviEfLmcerONocGoHfvc3JE3vtVplmsBcdhMEkJywQMDLphPrhWnPxxkJyLLdTGC+TfI2D3faEBNq/Cm3BcnOPJdGDlenF3A/78jbakG+35eUZT6peWY7NOiJjPQlVRpYoFQ3/yloFp3pE2zDVKoP1ZqKicQrfCRXpPCJY9moGu6rDyAzS4SV5wVybSsAvIgBXdSlSyo0mVKRfdSbVljweCS73Q7o52twChB7m7KwbehJW2suegeNQclDQ6bnGWQ== Received: from DU2PR04CA0259.eurprd04.prod.outlook.com (2603:10a6:10:28e::24) by AS8PR07MB7432.eurprd07.prod.outlook.com (2603:10a6:20b:289::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.27; Sat, 21 Jun 2025 19:37:59 +0000 Received: from DB3PEPF0000885D.eurprd02.prod.outlook.com (2603:10a6:10:28e:cafe::c8) by DU2PR04CA0259.outlook.office365.com (2603:10a6:10:28e::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:37:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by DB3PEPF0000885D.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:37:59 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id A3AC91C002B; Sat, 21 Jun 2025 22:37:57 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 08/15] tcp: sack option handling improvements Date: Sat, 21 Jun 2025 21:37:30 +0200 Message-Id: <20250621193737.16593-9-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: DB3PEPF0000885D:EE_|AS8PR07MB7432:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d9601e9-0cd8-4904-96f5-08ddb0fb2101 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?FhsEuHKNg4BoHMNHdzw45s1Bn6JDtG2?= =?utf-8?q?aFGc0cN3E74w/gOMDKVovRYpqck5UJ7pJhEvSiHdFziVqC5Lz2BzdOHP/sfvTmoN0?= =?utf-8?q?UUVU/j5wJ9JJwSuhTr7+PYnbdNJFpeVaiudmZMzRh1puAPWsz6WWdrmmXW8L4oaN0?= =?utf-8?q?H2Q3nkCFHZcfhNfSLLCq6gCajLUrMLj42HQ1pIhqaySJxp6ySPMqBpDrg2UDZdMzx?= =?utf-8?q?6IqNa/xSV8v1FP6bmPRh64k3UX5v4CMWCnyRmVFogQTkdLt81eZ4IrG2IjO5v5wcH?= =?utf-8?q?bhmZsI8V+Buup5xUrA5KkjOau4XqEkoGLEHsbGM8tQGR/6/3iKCYT6t9fvhYjdxgq?= =?utf-8?q?52HDD99oiPsNPhkc9wvqC0sJUDq2PqkHzaXOZcLCUYbvJ5LUohbvrE83JURKiQ0LY?= =?utf-8?q?LoT5ht2tOJnaFpwPYhbOGTbyxCMGixCnOy2V+znaE9ZzmlddL+xAeH4vFnxCFhb9t?= =?utf-8?q?slxgzYL5MckBnXa8A2iBKWZnQ3gxgrBxB8wM1JY9BSmPhU5ihCqUABM6uRwcKP8ry?= =?utf-8?q?zDKqqEYDmjSPgv7JBmmr4vq4dHSeaprTJU095Yny6luKDzKSc/7s8bdLw2l6oK2zN?= =?utf-8?q?J2719/NmcWOUkuqAwD73B/2mdywcxmZz3gGrz//7ylR230aLZvQwvFzze6U84Pcuh?= =?utf-8?q?29zy8XdWpEod+GYyYKa0RUZLN5/+XtSKKIbwB9XtWpm+NPpylscKxagCsZp6frsFF?= =?utf-8?q?i+w7kcEUcPE5iHC448/6rDTx3RpM7Res5Znj9LnHlsUG+a1T+x8UiOtmGEx0tL9JQ?= =?utf-8?q?hZ9rgFSHTEZr9xkC754twY/CNYfA0vxYH3nwNNbzP+lMxbMkXF8abofz4NaWTExqs?= =?utf-8?q?FtWeZ/+OrVEuEkxZ5K+cUYqZ8vKPPsttAkNc4Nx4q8/thxtAttILqsq7DhTxX6mFa?= =?utf-8?q?2GjVyNwLEXSe3vrQgm7iY1GofAurq2Qh0JgzX4HkFdS+N46/s7xOuFF7FkcdcEBWV?= =?utf-8?q?3fjJkOb/xWpHS+6N3EYEtKZ0gk0UxfbbEl4noSpJdc4ZAoSKfecrs3ernKxejQcH9?= =?utf-8?q?dnkLC0GHQw7Zoq9ji5PChEmT0R40nKfUhYNA9pZvyZvWCiarkgzkaidypz9nQ1xOr?= =?utf-8?q?3/RE19F0k/ame8lpo8H2xRnudNG/wbm69d/uh4rxBaGbEAEGf3V9StcwJGQ37uRSO?= =?utf-8?q?GZBFQl3btD/MHhc0ReMkwSF2ObYjJgJ4/FgEJ8PpgO1H6SLbAx9T6gI0KiyX8HAd4?= =?utf-8?q?GjzHc28tvkoM7/Wtu3/OQuoR9KrxIYUe+OP6et9xtcV1jyXNbJ6KjObSezXlQLJGf?= =?utf-8?q?qUEi9+/lxSpll7a7HpnsgK3LtOH6HdhDXe0AW3HEQH7GW3Mps9j6LwM++TeDmxlXu?= =?utf-8?q?qhQOhrnJg7rANDKycINm1AQczT5OWFEQHC6twQGa5Qx0k5gkf0UDDN9Pk9behhgmV?= =?utf-8?q?GWSfzVPM4fE6KONP5euhMp+X5qj927zENxLfrc034cIqDtVmuQkATAvF6L33qDQm+?= =?utf-8?q?0W/2SW3sgvph9luDfc9vPKd/h3focB7Q=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(376014)(82310400026)(7416014)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:37:59.2723 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d9601e9-0cd8-4904-96f5-08ddb0fb2101 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: DB3PEPF0000885D.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB7432 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 --- v8: - Set opts->num_sack_blocks=0 to avoid potential undefined value --- net/ipv4/tcp_output.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 79ad69dfd9d6..37c981aa9bc6 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1092,17 +1092,20 @@ 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; + } + } else { + opts->num_sack_blocks = 0; } if (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp, From patchwork Sat Jun 21 19:37: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: 898915 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011032.outbound.protection.outlook.com [40.107.130.32]) (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 10E5026FDBB; Sat, 21 Jun 2025 19:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.130.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534691; cv=fail; b=nBjl2338IKF+zyPK84Cg5n9969WF9y1YtsnzxqPO10em/9Ur9HiPPvCawrm0pIvvFH6xw6O+BXdIwyRY2Ihg2tjwmUWOmW2YoD4s8Lc+IC7Ox3+B88O3hob22VDrZ70XslbJWGqJepvHJzggIssrA/VNVwrgoCB1yD1GpZRPY0M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534691; c=relaxed/simple; bh=T69UkHj78BeYpDGldWXpxgO6i/D/6KFdYFyYfu6bipw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=HvrQ6edOdnShTbbW/vio7yDfcgOPYxy62FQNHC358kdJ/zTSibercepKynaOfOzC4+mfqELEWIUpKysKbK+er7lfSAchO+Xl7Zt7r9Spu4DQbQMotaIbTgQNa5EuO1MeDW7yzKKzSyaKOFhGEoZjSWkfVdMwrHZOMiGR59eeJkg= 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=OefF2Hb0; arc=fail smtp.client-ip=40.107.130.32 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="OefF2Hb0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dgmWwVHhO3PGhFbimpYWqLKHo28lckDAOdErTXyEeZaAZt9oYQ888RTtQIkh7oQVjXSpVf3JY40ZtzK82aqG1/Wt94lfjz81oFIJuyt202bCnBDB9u2hq2+R9nptN3OxKKu65YhwG+o7m0f5lmSd0xa62g4y7KGem2bnuht+iTHV6drVIu8FPkzZMoMuNuiFU3RA5FLw2ZSBHDpnzhf1G64tBc64OegA2KNxF9FXRyfu85S1gTMWCQ3fN4Y+BGxl0TQ+bHlydZwmzilBre4zc1U+YIwZzgPOuAt4vZfgoDJ50892kp9wqb1nmTyMZyZnDwlTfTnQUNSZ9I1exmDHGQ== 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=k0dROp/XxbJ6j1+6IqD/iOCwy90b/14d0XTNnNgrFt8=; b=a8q7l4QqQfGKIgMUhhkktAh7QhbfRVRNR/YrJ1XS9cf8hTldCGOLIdhFhrkYHOdRJmGF1c1Surxsz6XYK4GT59bXn+oufaHvE9MAMuvVsVBnwSPE6m83oMlPJbgnoGpb4GShE1IU8svcbsuElua74uJWnhKRkMIQOlOwXg8NXDc3d3h8PmnUHuVcjvpXcesSvg5dx2i832AcN6Ibl5+OAdwIdkLIUfisUTuyny2x1W87UuIIl6ayqdY2Iz48euYiwqnOnYE04iZfhnUBfguSpWKHr5uriZRlmUgyKjBxU/X/dvqx+8dE/SAR105MLKIXCAOQ/cYxSTmAf0AXfHLqiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k0dROp/XxbJ6j1+6IqD/iOCwy90b/14d0XTNnNgrFt8=; b=OefF2Hb0tACBzzkGZZaVoCnwuuMPNwVG8yDau68IFu5DEY+Ug/h8yBI8iTmTcTX4vY5DbP5zK+A7wkWptSug2wH/101JtmHV4p5hQiQzunDbQvZbv7NwyR0od7/VW5h7DzvoVtwhSONQS1eSKf6RRxpt0p9TA1EEMD3Id2mGVVkWOfesIkO7WTnYeDVFOmaKiwiuLGMqs65mWPArx3usHwjkAcyZqmnb2l+1WY3JcU1MdLH1lVpiXwUaTTNG5afewrf6Oa47Z404ER25p5qae0nA20CZDP0MIWQOlroNHz/HwSLT/VAGq84oajKuV4npgGcVWHN4mv2ufAkfbONjiw== Received: from CWLP265CA0425.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1d7::17) by DB9PR07MB9125.eurprd07.prod.outlook.com (2603:10a6:10:3d7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.23; Sat, 21 Jun 2025 19:38:02 +0000 Received: from AM4PEPF00027A66.eurprd04.prod.outlook.com (2603:10a6:400:1d7:cafe::f7) by CWLP265CA0425.outlook.office365.com (2603:10a6:400:1d7::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:38:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by AM4PEPF00027A66.mail.protection.outlook.com (10.167.16.91) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:38:02 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id 0B01B1C0010; Sat, 21 Jun 2025 22:38:01 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 10/15] tcp: accecn: AccECN option send control Date: Sat, 21 Jun 2025 21:37:32 +0200 Message-Id: <20250621193737.16593-11-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: AM4PEPF00027A66:EE_|DB9PR07MB9125:EE_ X-MS-Office365-Filtering-Correlation-Id: aeab3ea9-05cf-4465-0dac-08ddb0fb2303 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|36860700013|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IV5FiOautLt2Bdy7nCsD/joQSYWTnyO?= =?utf-8?q?4xxQGdOADRvxmdLD4ipBcBsfqSk/T+kt5UyTl/txLaJjq2de1V46dEWDa2r/AzgZG?= =?utf-8?q?YC8BrkimaKu8AT0LvgcSN1/M3yPDWSuuvtPhPkMGFEWsalAhtYqbM/eopZl/8oDOK?= =?utf-8?q?Nq5XW44WXTSgTHHY7MvWSJ46PawCkUAqjgt29WuauGsS42DQd1HowyM8DQLp8QFmM?= =?utf-8?q?CMDb/hHNTuPyFIaHJsjMxoG06yFC5+ELUm2qqaLxyMTOUeaAGC4va2AJKGNUwKmI+?= =?utf-8?q?JeJ1yVMKZ3ZsRK2J03n8oLwgBnC6y6JgvSndCzy7Z0mV7TFvLhnOaPRURm4dsEOnL?= =?utf-8?q?ukSpM54c4llW6p1lWctbhHNDanWnYfdajyzs5LcJVf87lNmFo1GszJlmPlEUcNQ9v?= =?utf-8?q?atUWW56qEB2kbq2atdxqEPs5zP/HxFy/6VUk/taR6hjI8x82O2ebxoqIlmn1rfzIg?= =?utf-8?q?agK+7RWX9NE/tQXBTq5z6CSSGZRYPJUHDIktwcRycpa5zzflW2zDlrdV8AJIRYC63?= =?utf-8?q?oLCDW/K6f3xGo6Sh5GNpXdjaNgEpOlRxKedf81rQ3u9x2/LFFVPJeKmwqvlIYKmGU?= =?utf-8?q?3DtnFgUi8vbIuiEyBU3Oght3Wtwg6roMXNK7qQH1KvCOEQxpXyHYseSSI2l+DdiLk?= =?utf-8?q?kyai68UM1T3niznlymENQnjO8CiMui/1k3Rd0XNdNwX5/PaZJBfyQ67AA9XqxZttR?= =?utf-8?q?q4UZaMx1HIXL38m4o3s2jAd01wiRXCXafbwSAlwIH0uFLt3Hx0csz7tdm2Uc7zG56?= =?utf-8?q?A1WPRAN+OVPNkVLiHtFTGzycWLknaxEbagJa6Wa4urlC+nFVdRRfSJ64J/eKzzx36?= =?utf-8?q?3LKOnU9g7rP7MqpqBZQyZYNkcZYu83k598v80Q/gz+iOKru6QXu/dcq73nLu+lZ3x?= =?utf-8?q?B0nPuFAAXB9mOvL6tuHQeDhdIwv7FMrpja/xY+1GlByxtKDm9oiF8P/EVgmqj4kKt?= =?utf-8?q?4gLuxHzLBLqvVYJ2iznfYVK9VuDHPEHX5/QBSWQ7iGhIrzTJTcMF1MutJi97/WH33?= =?utf-8?q?4/BqV3x2LtEmtFD6qiHq7P0aNtMH/hzGrVm+nApaNDCMI2Xxbr2d0zUZadM7ZQKLU?= =?utf-8?q?JG08zjtMDg3PKyUe0wXWSulwKJ1Yc9XICuIL7CnYL5ZnqaBLax4Y1+nf2SRYUeJpD?= =?utf-8?q?ojNsGGJoI2mq3kv3EXfAQgUsP/jv4suDyD72ubChxvbn+5CY+XtRxNycfnGkyUY9y?= =?utf-8?q?XvXfDaWq1/Imr24jufLkIAuKZYHmo2qHRg9bkj2UUwgotr1AULBlMrrV9VKty9uUp?= =?utf-8?q?cIo9sVi5KoJwzf+93Rpr400KVyji/4lKGWy72yUJfaudEIz26gllv3gszYlbx4aK4?= =?utf-8?q?Omk/TfX480HiKI5k/fDidYqZLprqqbUYKtSLzPUd14b/I9uOZ0vHorU9bFmOhyk65?= =?utf-8?q?Wb2B3Bdvog+k+WIQLnkLYw7S+8sXTla6Y2ynnpecDd7AniKkMurkcaCkxcwmq+2Sw?= =?utf-8?q?Y+5xvvUeCQki1KwP1/6+FUhYvnqr77BQ=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:38:02.6212 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aeab3ea9-05cf-4465-0dac-08ddb0fb2303 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: AM4PEPF00027A66.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9125 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. Below are the pahole outcomes before and after this patch, in which the group size of tcp_sock_write_tx is increased from 89 to 97 due to the new u64 accecn_opt_tstamp member: [BEFORE THIS PATCH] struct tcp_sock { [...] u64 tcp_wstamp_ns; /* 2552 8 */ struct list_head tsorted_sent_queue; /* 2560 16 */ [...] __cacheline_group_end__tcp_sock_write_tx[0]; /* 2585 0 */ __cacheline_group_begin__tcp_sock_write_txrx[0]; /* 2585 0 */ u8 nonagle:4; /* 2585: 0 1 */ u8 rate_app_limited:1; /* 2585: 4 1 */ /* XXX 3 bits hole, try to pack */ /* Force alignment to the next boundary: */ u8 :0; u8 received_ce_pending:4;/* 2586: 0 1 */ u8 unused2:4; /* 2586: 4 1 */ u8 accecn_minlen:2; /* 2587: 0 1 */ u8 est_ecnfield:2; /* 2587: 2 1 */ u8 unused3:4; /* 2587: 4 1 */ [...] __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2692 0 */ [...] /* size: 3264, cachelines: 51, members: 174 */ } [AFTER THIS PATCH] struct tcp_sock { [...] u64 tcp_wstamp_ns; /* 2552 8 */ u64 accecn_opt_tstamp; /* 2560 8 */ struct list_head tsorted_sent_queue; /* 2568 16 */ [...] __cacheline_group_end__tcp_sock_write_tx[0]; /* 2593 0 */ __cacheline_group_begin__tcp_sock_write_txrx[0]; /* 2593 0 */ u8 nonagle:4; /* 2593: 0 1 */ u8 rate_app_limited:1; /* 2593: 4 1 */ /* XXX 3 bits hole, try to pack */ /* Force alignment to the next boundary: */ u8 :0; u8 received_ce_pending:4;/* 2594: 0 1 */ u8 unused2:4; /* 2594: 4 1 */ u8 accecn_minlen:2; /* 2595: 0 1 */ u8 est_ecnfield:2; /* 2595: 2 1 */ u8 accecn_opt_demand:2; /* 2595: 4 1 */ u8 prev_ecnfield:2; /* 2595: 6 1 */ [...] __cacheline_group_end__tcp_sock_write_txrx[0]; /* 2700 0 */ [...] /* size: 3264, cachelines: 51, members: 176 */ } Signed-off-by: Ilpo Järvinen Co-developed-by: Chia-Yu Chang Signed-off-by: Chia-Yu Chang --- v8: - Add new helper function tcp_accecn_opt_demand_min() - Remove white space only change --- .../networking/net_cachelines/tcp_sock.rst | 3 ++ include/linux/tcp.h | 4 +- include/net/netns/ipv4.h | 1 + include/net/tcp.h | 5 +++ net/ipv4/sysctl_net_ipv4.c | 9 +++++ net/ipv4/tcp.c | 5 ++- net/ipv4/tcp_input.c | 40 ++++++++++++++++++- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_minisocks.c | 2 + net/ipv4/tcp_output.c | 28 ++++++++++++- 10 files changed, 93 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index ed6af7d0110c..88c668f9c68b 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -110,6 +110,9 @@ u8:2 syn_ect_rcv read_mostly read_w u8:1 wait_third_ack read_write u8:2 accecn_minlen write_mostly read_write u8:2 est_ecnfield read_write +u8:2 accecn_opt_demand read_mostly read_write +u8:2 prev_ecnfield read_write +u64 accecn_opt_tstamp read_write u8:4 accecn_fail_mode u32 lost read_mostly tcp_ack u32 app_limited read_write read_mostly tcp_rate_check_app_limited,tcp_rate_skb_sent(tx);tcp_rate_gen(rx) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 0008b8190ea0..2c0a2db6e6dd 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -275,6 +275,7 @@ struct tcp_sock { u32 mdev_us; /* medium deviation */ u32 rtt_seq; /* sequence number to update rttvar */ u64 tcp_wstamp_ns; /* departure time for next sent data packet */ + u64 accecn_opt_tstamp; /* Last AccECN option sent timestamp */ struct list_head tsorted_sent_queue; /* time-sorted sent but un-SACKed skbs */ struct sk_buff *highest_sack; /* skb just after the highest * skb with SACKed bit set @@ -296,7 +297,8 @@ struct tcp_sock { unused2:4; u8 accecn_minlen:2,/* Minimum length of AccECN option sent */ est_ecnfield:2,/* ECN field for AccECN delivered estimates */ - unused3:4; + accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */ + prev_ecnfield:2; /* ECN bits from the previous segment */ __be32 pred_flags; u64 tcp_clock_cache; /* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */ u64 tcp_mstamp; /* most recent packet received/sent */ 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 f7ba314eb7f9..fb0d69ee3ce1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -91,6 +91,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo); /* Maximal number of window scale according to RFC1323 */ #define TCP_MAX_WSCALE 14U +/* Default sending frequency of accurate ECN option per RTT */ +#define TCP_ECN_OPTION_BEACON 3 + /* urg_data states */ #define TCP_URG_VALID 0x0100 #define TCP_URG_NOTYET 0x0200 @@ -477,6 +480,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); +void tcp_accecn_opt_demand_min(struct sock *sk, u8 opt_demand_min); void tcp_ecn_received_counters_payload(struct sock *sk, const struct sk_buff *skb); void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, @@ -1090,6 +1094,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..169a393374b3 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_THREE, + }, { .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 1c1d4cbdda1c..f7a85192c86f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3396,6 +3396,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)); @@ -5114,11 +5116,12 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, lsndtime); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, mdev_us); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, tcp_wstamp_ns); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, accecn_opt_tstamp); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, rtt_seq); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, tsorted_sent_queue); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, highest_sack); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_tx, ecn_flags); - CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_tx, 89); + CACHELINE_ASSERT_GROUP_SIZE(struct tcp_sock, tcp_sock_write_tx, 97); /* TXRX read-write hotpath cache lines */ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, pred_flags); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 66390966cc41..3cc9c57d9983 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -497,6 +497,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)) { @@ -517,6 +518,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); } } @@ -6182,6 +6184,15 @@ void tcp_ecn_received_counters_payload(struct sock *sk, tcp_ecn_received_counters(sk, skb, skb->len - th->doff * 4); } +void tcp_accecn_opt_demand_min(struct sock *sk, u8 opt_demand_min) +{ + struct tcp_sock *tp = tcp_sk(sk); + u8 opt_demand; + + opt_demand = max_t(u8, opt_demand_min, tp->accecn_opt_demand); + tp->accecn_opt_demand = opt_demand; +} + /* Updates Accurate ECN received counters from the received IP ECN field */ void tcp_ecn_received_counters(struct sock *sk, const struct sk_buff *skb, u32 payload_len) @@ -6189,6 +6200,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); @@ -6207,9 +6219,33 @@ 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)) { + tcp_accecn_opt_demand_min(sk, 1); + } + } + } + + 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; } } } @@ -6342,8 +6378,10 @@ 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)) { accecn_reflector = true; + tcp_accecn_opt_demand_min(sk, 1); + } 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 387cf8994202..7d4660378378 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 = TCP_ECN_IN_ECN_OUT_NOECN; net->ipv4.sysctl_tcp_ecn_option = TCP_ECN_OPTION_FULL; + net->ipv4.sysctl_tcp_ecn_option_beacon = TCP_ECN_OPTION_BEACON; 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 f1e698c323f3..5b0f703f23a5 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -500,6 +500,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_payload(sk, skb); } 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 ca36f5d775f7..a4c80be115e5 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -816,8 +816,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)) { @@ -1004,6 +1008,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. */ @@ -1258,7 +1274,10 @@ 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 && + (sock_net(sk)->ipv4.sysctl_tcp_ecn_option >= TCP_ECN_OPTION_FULL || + 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; @@ -2975,6 +2994,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 Sat Jun 21 19:37: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: 898914 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012036.outbound.protection.outlook.com [52.101.66.36]) (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 0F1A626FDAC; Sat, 21 Jun 2025 19:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534692; cv=fail; b=KQmHkXc4xd9ahdJumi+woYmC4xyrIvVIW/rzbrAyO/tSpVDat5/Bj3L5BQI2jNIwgIXyxr+x2qqyZLZrTjlyMGiiLlQlCAkA3X7IfFH0r5m09u6ALhiUIJ6Qu4eCu7ie9f8HsgetxKIlY2z/gFKyUbT5qcMzMh8waBpj51QhYWw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534692; c=relaxed/simple; bh=tAoIQmS+jzId2GDiEkPWpoWH4tUBog3+H+DlpW6QKLY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=JO28vW/H63nOyb7V2EgRUzbpicCDwOgCj91FTm5+qoJHxeCyCKgKQ4XCSob/+weeg26z4d9Ti7TagQqd4oeM8CuLme8pmvVVzZuuCZ/9s+NYOptFS/H0ahaN5AQZ/YfjWYomA7NICd1R2nSWwzIhF+C1HsIhLUfPscgTMRh1d0I= 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=sGIRZEvo; arc=fail smtp.client-ip=52.101.66.36 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="sGIRZEvo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CzyAes8GSKaNX9TPS4q/MGJ1VyV8WKNQmoINft8UKKCkdsmGjYLVOxwxDydesAoXafL8zwZ0I8ZVMU9pIWLS14YfYSEQywGpyygx+DRMp7MLMOUsVsyqTPeP63297kPgySjB8iXP4lQunDwhVs0THgopS+kpohIBduRN+q1jPNiRreFOEZLngRHb+Xau47H4CR9lk0PF4DVsC+x7pj87Sud9EVqenB+BhEmFoKArU0bJ6W42f2CmcR9SQM8mKSf5xRMkBibdCMly3z976/0Cics82F/QbxYRFc1Tk048FatFJk3xZEwaRfjLnnzgz0zzbwPDloaacMQLAWDd8qMo3A== 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=sJB27rbc11VycrzEBQ9Uk33DwopAtQ88geMSqc5nTC8=; b=dVqW1ldGUt7GpJCwSpywvJzhZ/CB1N8dI6xWDWSrR+CwU+gTm6HZXQz2MQetd34RqVf+q5772GSPBTYmJyFYR+DNWVxXG/ARVmpZdprsDPhmWJvO6nXjetlwI96eXgbPgUBk3IduukuO2PA/HgGb9E6mmLwBmZREaU0ucnAjjoq1xS3fyHjVWmqcIQNxO8o1oBESda1c+dIFuaeq9OGEslLqcPRdGN5Tczhporz1AEzmosjU7QYAcNqKAeZBrVUtftDRmq2wP5nmZG5Ljv9N1K2cw+5N8kYnIRZ8VNBZ4WyPiRcviZnEbP3AqEv5sqSgK3VPA5AdR0xYXz8YP1WNSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.com smtp.mailfrom=nokia-bell-labs.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nokia-bell-labs.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia-bell-labs.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sJB27rbc11VycrzEBQ9Uk33DwopAtQ88geMSqc5nTC8=; b=sGIRZEvoF6pPaVe7xiph3Xnnt6KsiGs0nGUxzLNtkd+UXsf+zJjXg/YTm1Nz6GwOdqGRdcEfVaaRRRWowqgSiRQRGifQ2Dhf2WFzr5k9evUHE/d9WXJRCRxJ4cFquvenOO3pmTVwuVyxtvUQYnjpeeErUDM14lmMQenK3WRBleQvniRRagHgWs8Txux2KFHlns3vr+I75vz8Ca7sJ5V6fW7Xu6aIY7TRTpDBUSCtfghgisl7TC+aV6GtG4O1Lbew2Q8Z8BPFfq2pyxsg0UkKDS6u8GtOMSmFdQKSMooEzJRaZZHVb8KpexWqa8/rjbJGGvItkFD4P/qvCXjcBcKwGw== Received: from DB8P191CA0016.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::26) by DBAPR07MB6520.eurprd07.prod.outlook.com (2603:10a6:10:178::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.26; Sat, 21 Jun 2025 19:38:08 +0000 Received: from DB5PEPF00014B98.eurprd02.prod.outlook.com (2603:10a6:10:130:cafe::a5) by DB8P191CA0016.outlook.office365.com (2603:10a6:10:130::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.27 via Frontend Transport; Sat, 21 Jun 2025 19:38:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 131.228.6.101) 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.6.101 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.6.101; helo=fr712usmtp1.zeu.alcatel-lucent.com; pr=C Received: from fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by DB5PEPF00014B98.mail.protection.outlook.com (10.167.8.165) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8880.14 via Frontend Transport; Sat, 21 Jun 2025 19:38:07 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id 5857B1C0031; Sat, 21 Jun 2025 22:38:06 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 13/15] tcp: accecn: AccECN ACE field multi-wrap heuristic Date: Sat, 21 Jun 2025 21:37:35 +0200 Message-Id: <20250621193737.16593-14-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: DB5PEPF00014B98:EE_|DBAPR07MB6520:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c86b271-251d-4404-f161-08ddb0fb2629 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|36860700013|1800799024|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?BRhAb9O41UZSjqFdzj6iCJKswzNEAYq?= =?utf-8?q?J+VLQSNLBKmtxoT9/+XkCLFHmZmkqK1+TQQ9X1Vg+3d8Q+Cwl/g3lSl9o6ddzD+zW?= =?utf-8?q?ND+3SWWsFwl7NUfsuussXU5fWqD5PKbYkJXU5Yy3JDXG0V7RH30fTB8NyX3Vr91Jj?= =?utf-8?q?LdI3XNwJcj/e7eMMHS+p4uLQnZpSaYSyv1Vhnul1hQua28KnGZby6m350ykvHczgL?= =?utf-8?q?pm1TtBkGkS7NN0hwq6lPAbFaUgwRwwpI3s45VPt3U85DNDdT71sBfF7F+sUYJgZgQ?= =?utf-8?q?CqzkojXkRIObzH6Cx7RRzdwUzQdkleWdMTPph519kVqb4N14PHorh1SLEsQeVcxVJ?= =?utf-8?q?dxwMsXj7fL5+nNNCNuSuVlbkRHkjbn2H1jFYz8Hf+tSlPy1a00U/xAhpXyuQnMmJ1?= =?utf-8?q?BLJO7mTNYOb8LeaXwWkal7IL41ML+/v4XQIPqP57Kni+F7BDPIAgNf8NvJy0ByKwf?= =?utf-8?q?k4O/LtpIajIPay4uXMdGQ2e9j1fJRn+6UZuj92CH11fp73RVIc/rnGN/cn5VxDQ2u?= =?utf-8?q?j6S1VhDBEADXPzm3T71iLU781ysY17vKEoEh3EUApxn4aLLfvQCqAkJ8diqTOUE4B?= =?utf-8?q?BxKWJHW/arKqZ+kF4ZwYhkcbdblRqPaOZ3c8+DJZHYvN5yD0UWFPPTIYTUICAPrW3?= =?utf-8?q?5AXHXKwGwRm1ac/z29NasgBbywWPWeGKMaC9F2lzP0uxNWl9FgwvV75kgDzNLu3xV?= =?utf-8?q?Tp0K8F338W0ReEk8vWKTobJHwaux7bhHhPAfojxongz5/2kjPGFwhJg9tsjQzgwkX?= =?utf-8?q?WyvPFehDkxpryzpYW7VoMNR9jLZH3KiEbXUrhxCUEghmuWOUW4Vg8yQiWi+PRJB69?= =?utf-8?q?jmF/3YXi1ZzC2Flsr6Su4Q0Xd5NaMGkfR1+qVQmx3A1PJXjtYMeYfVw66PqJW3AG4?= =?utf-8?q?CjuB8oX44Mv2ORFFiYzNbSCC9TicYjSzhZ+fJ/6xJfxq8ChobbJGG3JKger9WRR6H?= =?utf-8?q?MNTs6EG+8gW6Uqt9tRiEKC5cKeqqLHwLVLlQUV05i3OCxcoy7ICcGNJ2+rwWcdsB9?= =?utf-8?q?d450LmJ4cK4k8cndeV8JMxHv6OBXQzsxf56/GAmkf25j4IYtH3gXj/oMTTngk/z+5?= =?utf-8?q?WcSIVWRTdIcaLzm9fta/VW5TzANJxgkFLNJlxunK21rlCV3+SJQRlj/2fpomIWa8w?= =?utf-8?q?xz9H2RWmCdao3CxBHO9zSh7ga5GZpB5zjC6vW3a6Gyjeijirk3o3DR0FuFc0W0jU2?= =?utf-8?q?tHd32vMsc3IqkKFeCJqsXh7TwU0O5UDFZbBtCEzgjWpdRDqsy9FOX/Ci9lkUMht3S?= =?utf-8?q?xYJyc+BFmBXjglB/CeOwhoowUOa3sTnNXQ0/59EYu+ftgwvTWaCUccXnXchHzhLjY?= =?utf-8?q?BxHmH+H9BMv/O1KJTuJYOj8CYVvUcYWjvskhqjWZhBzM3S547FGG09xgd86fdlVY5?= =?utf-8?q?ZvA3Z/FwlYn36YFxailV9++GkEywYviTYIsYm6n/kVBMUh7g1aIN7VN97rLcm91Lp?= =?utf-8?q?FQBQfx0EynsKunKRXT6wIh/JeyFECaUA=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(7416014)(36860700013)(1800799024)(376014)(82310400026)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:38:07.9244 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c86b271-251d-4404-f161-08ddb0fb2629 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B98.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR07MB6520 From: Ilpo Järvinen Armed with ceb delta from option, delivered bytes, and delivered packets it is possible to estimate how many times ACE field wrapped. This calculation is necessary only if more than one wrap is possible. Without SACK, delivered bytes and packets are not always trustworthy in which case TCP falls back to the simpler no-or-all wraps ceb algorithm. Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- net/ipv4/tcp_input.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 3f8cac22efda..97b5fe52d8fd 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -758,6 +758,24 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb, d_ceb = tp->delivered_ecn_bytes[INET_ECN_CE - 1] - old_ceb; if (!d_ceb) return delta; + + if ((delivered_pkts >= (TCP_ACCECN_CEP_ACE_MASK + 1) * 2) && + (tcp_is_sack(tp) || + ((1 << inet_csk(sk)->icsk_ca_state) & + (TCPF_CA_Open | TCPF_CA_CWR)))) { + u32 est_d_cep; + + if (delivered_bytes <= d_ceb) + return safe_delta; + + est_d_cep = DIV_ROUND_UP_ULL((u64)d_ceb * + delivered_pkts, + delivered_bytes); + return min(safe_delta, + delta + + (est_d_cep & ~TCP_ACCECN_CEP_ACE_MASK)); + } + if (d_ceb > delta * tp->mss_cache) return safe_delta; if (d_ceb < From patchwork Sat Jun 21 19:37:36 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: 898913 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013051.outbound.protection.outlook.com [40.107.159.51]) (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 95E321F8753; Sat, 21 Jun 2025 19:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.159.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534698; cv=fail; b=QpQV6zdHVkutRbaah966A1wdojlAkVLDCjRx07nhQ9q/sDTcl8ny9RYDsfKYE3neGAdyVdx7BqAfnbqpXQ2CzwtCq2r7mCVmjWcXAWoMNCWZcVzb5qqeeq3wR6roVVkOV3d9WIllW/0/cl8lECVy9P+5niVsH34Cxg2HUhWo4GM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750534698; c=relaxed/simple; bh=V8jj6wEXdCVIFSasiziwiE/h7QW+uCjw67cDVA/Ah78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=in0x6xy/YbR+r9iViFvgNhS5XAP40e4OOONJ2FBg4dywn4OjC5HQ2qpD4mTfyyRjEx4V5+XHGFoCIZuLUanOdA5LjiU/NBXNwxmdU1ch/0P/T6k50pTzJvH5TUNeeJcr4IlbQkP04zv4D/UmQLvlMJTd391GReUIm/6ZtxuiRG0= 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=R3aJA9jm; arc=fail smtp.client-ip=40.107.159.51 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="R3aJA9jm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vPl4Z6Y7zCfAcpj1+yPVZQM18MznMr1fPYF7NLPGp0Lkal8XUGWbt3We6d1BKee++Qi/iUKpNaNQ8xkUGXvcF3g1eK7WG8vBHo/kgcLb2g4ACpMVHtXMBwvFoiQD21vwFHXVNPLicSOO5jEYxX+7d6JoP71o3CMedE5ACYh5FIYFVWUwW/OY6WpD4eV8BhR8P6a/9OXoaiBhLe8QPzu7x+8Ny0i/i46Sjij06UmbX9SETrP2lNnkaeHNleIIRlFcQGZeCq+mtx3fKc/ciRpyUVZKKc8tG/c6eCyNZMHYLDh2obreQXCvm2S0f5+paqjRkBgagahiGemZ2DrlpJQ5wQ== 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=lp7Yj183TjyJfN88VdSEfBdlvIKA6DyK+node/MPShY=; b=jml0xqcopPLjaaXjMltmKk/odeliA4eYu9YqDmQoahCDKDzkqq0d8xYImLBYzSAfIg/Nu3pwNqwS1WWIBPwE1x0e9tOrnBV28oYZZcKK3K/Djn87CH5GvnPx4+eBD5TC+YOmRTxbWGloVaD1Xf4RoopbXm7PDhkSZbwAIVoQBuQBDeiakG7JSimOgru7WPYyCF4FbiTm3LPeXOgSaWIuW09rXkDYgHSb8/ZL8ffvpP8JwGdG3sS1xMu+7bf6mnaBS8G5bB97+fEnlCFlDRrpASfzVutY23ximIWusHaLf7uOn0udXu/H7bqlRBFEfJvWy2Z1DIzsVTSVQsYqaKBRFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=temperror (sender ip is 131.228.6.101) smtp.rcpttodomain=amazon.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=lp7Yj183TjyJfN88VdSEfBdlvIKA6DyK+node/MPShY=; b=R3aJA9jmKCpbBRYEYp2sMU0sXvy5ppDnudmnRF7xOesprtcWaLhcPh/uaNtgF/g2TqDkRbXd/A/ZTtUv0KJU3++b8rNEt5XaUaRnZ6g3HyIa28B1ZhyTpE1xJ5wClkfL9ynJw9gbCL7dQYmPC8rCGlHBlJlKg3QIg8LYFggB0xlYO8DuUAnm9ab4VKiLwF9jSi9VSfggwGZSEbZGEWwawBd6NN66Y/PwriWrlRIlciQ4qfv/m2B7aJtEqu7cjUBsGT1lOlmGCgn3T/EMNADEVPTg+VB3Zy68EIH+Fww4z5exCIPMuRemXRw9X7V3sDMZGlocIeqmH4z6vpybAFNuKg== Received: from BE1P281CA0384.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:80::11) by VI1PR07MB6239.eurprd07.prod.outlook.com (2603:10a6:800:13e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.26; Sat, 21 Jun 2025 19:38:12 +0000 Received: from AMS0EPF000001A8.eurprd05.prod.outlook.com (2603:10a6:b10:80:cafe::14) by BE1P281CA0384.outlook.office365.com (2603:10a6:b10:80::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8880.14 via Frontend Transport; Sat, 21 Jun 2025 19:38:11 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 131.228.6.101) 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 fr712usmtp1.zeu.alcatel-lucent.com (131.228.6.101) by AMS0EPF000001A8.mail.protection.outlook.com (10.167.16.148) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.21 via Frontend Transport; Sat, 21 Jun 2025 19:38:09 +0000 Received: from sarah.nbl.nsn-rdnet.net (sarah.nbl.nsn-rdnet.net [10.0.73.150]) by fr712usmtp1.zeu.alcatel-lucent.com (Postfix) with ESMTP id 10B961C002B; Sat, 21 Jun 2025 22:38:08 +0300 (EEST) From: chia-yu.chang@nokia-bell-labs.com To: pabeni@redhat.com, edumazet@google.com, linux-doc@vger.kernel.org, corbet@lwn.net, horms@kernel.org, dsahern@kernel.org, kuniyu@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, dave.taht@gmail.com, jhs@mojatatu.com, kuba@kernel.org, stephen@networkplumber.org, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, 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 v9 net-next 14/15] tcp: accecn: try to fit AccECN option with SACK Date: Sat, 21 Jun 2025 21:37:36 +0200 Message-Id: <20250621193737.16593-15-chia-yu.chang@nokia-bell-labs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250621193737.16593-1-chia-yu.chang@nokia-bell-labs.com> References: <20250621193737.16593-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: AMS0EPF000001A8:EE_|VI1PR07MB6239:EE_ X-MS-Office365-Filtering-Correlation-Id: 459c7ae2-0231-4afe-3ab3-08ddb0fb2741 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|7416014|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?pGfrYOZdkuLApz8Mr4uLzMYZV9PKHOp?= =?utf-8?q?nw6aW1l3LYHelBB3RK6tyOqh+DefbYJ7HUVOURTOodp4+ssyjXaBlZE/j/ml9+ths?= =?utf-8?q?qlUkDg0vhQDJH5iixzaHJpr6xWzV/JBOPX6qhYJP1Ww7ukXDs1JCWN4R7PW7Z2QId?= =?utf-8?q?yH7R8cEHWgIW1dDV7xzxn7v1rVabkfYhqtmPJ8uH2wZUUeEatySVMYEgzlZ/hOPhv?= =?utf-8?q?IGUHTv2JvRxPHHg/v4AaNAfzGbxc7KESia7nqoRiIS9Hvc20GTyYa1/yRBoeWXLT9?= =?utf-8?q?iW136enTJNZn2dysegfDztoedi2tiorqD1PZTsUyn+hpf3HCaU5pT4LJBziCQhY0I?= =?utf-8?q?zdLKI271OCsH44rlrNOdWWPj3Un1MJz93UYqPbP9PhjHXkZT3Nio3EGdU8Qkjfv/z?= =?utf-8?q?31qQ6YMc8k23x4qlQTyXBajbRY4uGnv0DApRN4fpkGYRllUe4LDmFmaNyHbkPwstr?= =?utf-8?q?sMsb7P/xpQhTNDJhPc31sJ6Aua/5e9y11c+keXQgOhMblm4ReOE+u/o6hlpfqXqMM?= =?utf-8?q?0GjaOkrPXK2h2pWZCUQIA90v7X8xAIiZ76kwnudCNfpsi8T1bl4caEvNOzxpaE1hV?= =?utf-8?q?IggNpHTaP2xgWVTO2n5uarPzlrE9WvwpQJm/Cc4UMoJuBXoHf04SwkG9zHFOhQ4fi?= =?utf-8?q?3nqHi+4eQq33FpCz8r9i7AKKiGBeyvZguNRnR/wlApvM8kjTe5Xh+lm7SCXMTedcP?= =?utf-8?q?aEgfmWNSqjk49mINm1nAiZVwmpvXg0vOMIYxNPbuMZe+EiebheM55RAyPlCkJDvnA?= =?utf-8?q?QcXNCHTiw1FMFKiSVwkSFlMM/ClhLeQJX8JUyKYs7bXUkimhp7o0+K31iK/fV5wek?= =?utf-8?q?IwUxsU59awrrvt5DeZBY5wNUyfrL/U35rU+S0IxV32ecK5BVlIEyFWEBcC+246WbN?= =?utf-8?q?+72XpSfesAQjIpKXj+s/YE04X5PEPdDumprGqwJP4YdK6kwi/hPG+/6TsWr84k35Y?= =?utf-8?q?JFqvuCm9oSaoS2W148fjse9Z2pIwLADIJJnl66d7vBjFIirwvohCSEiCHn5JHTsFN?= =?utf-8?q?Xy/L3A9Dv0kHBlgt2CAVNr/Jv5iCCzWmXuytuebPp2Qra0QGtHTVQ3Zj5BR5++oep?= =?utf-8?q?0ZxpPmAPR4oVlQsRrFBZVSRZNj4jlZO0n2DrEMsx+WYa5tMynUqBwAYU/LB5yUoFu?= =?utf-8?q?mcbOq3o/Pct3s/HlbxAUXGeBKf6BB27s9Cv3bhpMRyM/Vj3fvLubj4IVGm5PlMtkH?= =?utf-8?q?CjlgRDOhQVbc4NJgZFOWpoYCSW8l03xLQ2001pesUvNiRcmwmUREFKvvhJE5EppRq?= =?utf-8?q?JzIBo5Gywcz+81XQ4+6Z+khCWIKIJ+2COUDbtQAXcg62Fo1a3ZsutcdjfAbom3F0d?= =?utf-8?q?sItN7Ho4qmwSbEOf/hHLKbyo675UdUkPbq2daV4C765K9f3nQycIbzwH6mwDgDaeR?= =?utf-8?q?h2srIA55Bm//n/Y6uupt8sGoI3bApeQE3uYFri+3xIE7EWoQusgk3K9aFqFptcjCo?= =?utf-8?q?4ZnhxaL/kMYtvGGOhXHDXe2WLwPCoAgw=3D=3D?= X-Forefront-Antispam-Report: CIP:131.228.6.101; CTRY:FI; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:fr712usmtp1.zeu.alcatel-lucent.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(376014)(82310400026)(7416014)(1800799024)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: nokia-bell-labs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2025 19:38:09.6313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 459c7ae2-0231-4afe-3ab3-08ddb0fb2741 X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.6.101]; Helo=[fr712usmtp1.zeu.alcatel-lucent.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6239 From: Chia-Yu Chang 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 attempt to fit the AccECN option there by reducing the number of SACK blocks. However, it will never go below two SACK blocks because of the AccECN option. As the AccECN option is often not put to every ACK, the space hijack is usually only temporary. Depending on the length of AccECN option (can be either 11, 8, 5, or 2 bytes, cf. Table 5 in AccECN spec) and the NOPs used for alignment of other TCP options, up to two SACK blocks will be reduced. Co-developed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen Signed-off-by: Chia-Yu Chang --- v8: - Update tcp_options_fit_accecn() to avoid using recursion --- net/ipv4/tcp_output.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 4a87380037cb..001c883c2940 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -984,23 +984,41 @@ static int tcp_options_fit_accecn(struct tcp_out_options *opts, int required, int remaining, int max_combine_saving) { int size = TCP_ACCECN_MAXSIZE; + int sack_blocks_reduce = 0; + int rem = remaining; 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) { + if (rem >= size - leftover_size) { size -= leftover_size; break; + } else if (opts->num_accecn_fields == required && + opts->num_sack_blocks > 2 && + required > 0) { + /* Try to fit the option by removing one SACK block */ + opts->num_sack_blocks--; + sack_blocks_reduce++; + rem = rem + TCPOLEN_SACK_PERBLOCK; + + opts->num_accecn_fields = TCP_ACCECN_NUMFIELDS; + size = TCP_ACCECN_MAXSIZE; + continue; } opts->num_accecn_fields--; size -= TCPOLEN_ACCECN_PERFIELD; } + if (sack_blocks_reduce > 0) { + if (opts->num_accecn_fields >= required) + size -= sack_blocks_reduce * TCPOLEN_SACK_PERBLOCK; + else + opts->num_sack_blocks += sack_blocks_reduce; + } if (opts->num_accecn_fields < required) return 0;