From nobody Wed Sep 17 16:19:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6C182E7652; Tue, 2 Sep 2025 21:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847515; cv=none; b=HPn1jFvvdDfkSB/p6m6XbZ9hosl/k4ma1hGAijT3nv6ejJCU1kwUc8eX51ToGS2CLDFWpoQpz68iL+J9dgBMzcI0aS9URXIi1xEstw5+OhL26QmfKDC6pU5XJT/ihoi8aXBPP8KFcxQI7GikK5igG+gkeVObz0UcDaosHXs9nVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847515; c=relaxed/simple; bh=RMPz+kei/l12vMhnBcZU59rKFNLt7AmYvJ+NTIta3uE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rXQDBgEX6v6uG8sB1NSQyUOM3MqQRc5CMbGLxMxlSkd6yG6yv2zEXtU6S8MVlXAUoj3A1W7mUWMnQlVwamANLP/KDBquHfBcaejsou399kDpBdUai0JP1WxqzmOgvxWxnDvzchEda1yCVk6Am1tgw4/9gBRJDoep51WyTyh71XU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TwGa4oPI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TwGa4oPI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D16CFC4CEED; Tue, 2 Sep 2025 21:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756847515; bh=RMPz+kei/l12vMhnBcZU59rKFNLt7AmYvJ+NTIta3uE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TwGa4oPIkHPlzOD1D8xF7kS5N215+V5mQX0aSPnhXN41/SWZoe2JsiTqoT9WK0ttf jHtuRFa2fiLO6XxaU167JDDwgwUz15JJ0FW2HGbHewA4sR8EE69pkEpQWJJrioG/xB s3sC8vlwrvqnxRSCJWWA/+N4o+93b/Px45pT+KGtIkZFp/ZztsOgrolQVElnv2pJiW 7lxSzWqzVJHFiIE2J1lgYwdijeO/A61newp2LY9lNJxJolizgNTD+Y1BExXLCMxjdT ghuUL/vSLTn4ffOhmPAPo4tTNOdj7aKvqDWiQKURt8e5C56q1oGd2TVj/ub9uWxk/Q n7SVGfLLherzQ== From: "Matthieu Baerts (NGI0)" Date: Tue, 02 Sep 2025 23:11:33 +0200 Subject: [PATCH net-next v2 1/4] mptcp: use HMAC-SHA256 library instead of open-coded HMAC Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-net-next-mptcp-misc-feat-6-18-v2-1-fa02bb3188b1@kernel.org> References: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> In-Reply-To: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , Eric Biggers X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2283; i=matttbe@kernel.org; h=from:subject:message-id; bh=6oQ+I5kcPXTiXDL88deD5lugpAEBwivyOnumWZNKRys=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDK2x058VK58Ov/ym5i5HfdmePzj5XjWETXn7uS6uamu1 f8sVDf+7yhlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZjI4sOMDHMOMt57ePLzn/mO S0Mu6Ll+tEx1MWTiW2LNwGZVybLySTAjQ3eWD9uh1gcdD/b9ZbaUsc/9eeJpu8ay/abrHt86bRa cwQkA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Eric Biggers Now that there are easy-to-use HMAC-SHA256 library functions, use these in net/mptcp/crypto.c instead of open-coding the HMAC algorithm. Remove the WARN_ON_ONCE() for messages longer than SHA256_DIGEST_SIZE. The new implementation handles all message lengths correctly. The mptcp-crypto KUnit test still passes after this change. Signed-off-by: Eric Biggers Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/crypto.c | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/net/mptcp/crypto.c b/net/mptcp/crypto.c index b08ba959ac4fd485bb833043ff58d4c8bac8a37a..31948e18d97da7ee0ee2ae9e4f7= c9ca0e3b330a7 100644 --- a/net/mptcp/crypto.c +++ b/net/mptcp/crypto.c @@ -22,7 +22,6 @@ =20 #include #include -#include =20 #include "protocol.h" =20 @@ -43,39 +42,9 @@ void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn) =20 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hma= c) { - u8 input[SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE]; - u8 key1be[8]; - u8 key2be[8]; - int i; + __be64 key[2] =3D { cpu_to_be64(key1), cpu_to_be64(key2) }; =20 - if (WARN_ON_ONCE(len > SHA256_DIGEST_SIZE)) - len =3D SHA256_DIGEST_SIZE; - - put_unaligned_be64(key1, key1be); - put_unaligned_be64(key2, key2be); - - /* Generate key xored with ipad */ - memset(input, 0x36, SHA256_BLOCK_SIZE); - for (i =3D 0; i < 8; i++) - input[i] ^=3D key1be[i]; - for (i =3D 0; i < 8; i++) - input[i + 8] ^=3D key2be[i]; - - memcpy(&input[SHA256_BLOCK_SIZE], msg, len); - - /* emit sha256(K1 || msg) on the second input block, so we can - * reuse 'input' for the last hashing - */ - sha256(input, SHA256_BLOCK_SIZE + len, &input[SHA256_BLOCK_SIZE]); - - /* Prepare second part of hmac */ - memset(input, 0x5C, SHA256_BLOCK_SIZE); - for (i =3D 0; i < 8; i++) - input[i] ^=3D key1be[i]; - for (i =3D 0; i < 8; i++) - input[i + 8] ^=3D key2be[i]; - - sha256(input, SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE, hmac); + hmac_sha256_usingrawkey((const u8 *)key, sizeof(key), msg, len, hmac); } =20 #if IS_MODULE(CONFIG_MPTCP_KUNIT_TEST) --=20 2.51.0 From nobody Wed Sep 17 16:19:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89D3635A2B3; Tue, 2 Sep 2025 21:11:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847518; cv=none; b=U8nfsl+els7GXuhyGm4ZhY+7rj+hGxk/xhiMpdEgE3+/PC4HNTIX7grg1ctvI9awWxU2tswF8/KN7UswoserC/7vMqu3PKWeM8lbRFa1R6BcLC+iAtS1LysuD5fCvbUZQhpT+uvfhlfJky8Df58Z+0a7pAziVeW38jsYNj2XKbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847518; c=relaxed/simple; bh=3It9f7wBm5Rp8zLOuMv7YF9Z060LmIqxgasdXFylhyY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EqjMw1VwC6eerOnPNXh7hND/Rimh39OJ+lqzWOPztIyYjdNrITF3iO6R5bEqShxL9rxuBX0iERabrN1amdHQnVCI0CEA/C2Y/3wprSiVFTp9gYI2zi35HiuvXxq4lGHgYuwYwDkKyD0es0WrotaTHs8AAUkaIS7UpchHnn01kkY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=udtvWgUA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="udtvWgUA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC246C4CEF4; Tue, 2 Sep 2025 21:11:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756847518; bh=3It9f7wBm5Rp8zLOuMv7YF9Z060LmIqxgasdXFylhyY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=udtvWgUAemhzNhfskbkM1GE2OSlz16m88Xh59eXvZGkiUgPTK9IP2IizoVIyjZnE2 azYEpIhxMr6ibbdfypw9Bmh8tO1lsZyfVaihAn02IJ1M5pmqUpKCZ5B6xD1eo5/Xnd YxLD0wAx6yPY/msRTUrD5A6+YokrGN59xwsfEXeqGQqLwpPOc2yuCIjSBhkSR6intM WEizjZKSxE4vdCVDnpCEOfp+lQGzNckL96MZs5MRl72CSP4yP8WL+i3nzDa4oYiSUn +UqZaPhmNNwoU258IHKvvboO2Z97dredBsTNFxx+vQK1EaZmAt9CEupopktVlPPCev Pxz/4sn3HuWag== From: "Matthieu Baerts (NGI0)" Date: Tue, 02 Sep 2025 23:11:34 +0200 Subject: [PATCH net-next v2 2/4] selftests: mptcp: add checks for fallback counters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-net-next-mptcp-misc-feat-6-18-v2-2-fa02bb3188b1@kernel.org> References: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> In-Reply-To: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5270; i=matttbe@kernel.org; h=from:subject:message-id; bh=hQWxxJjJp2AIjFFadn0D/zvpyvXXNy4+PSfJqVaO19w=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDK2x076a+v/q1/2koK0671pGy5vU0rVNJ925cqBmCnLO q8t/vj2XUcpC4MYF4OsmCKLdFtk/sznVbwlXn4WMHNYmUCGMHBxCsBEit4wMnw2lmrVcVnuYfmG ZeesDx8U85jqT/6+8uf9vhLbrPqID8oM/yN415UG3v/L8tW64desKSlKUmn9ynp3J8xXeHnI+7P QKm4A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan Recently, some mib counters about fallback has been added, this patch provides a method to check the expected behavior of these mib counters during the test execution. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/571 Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 123 ++++++++++++++++++++= ++++ 1 file changed, 123 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 82cae37d9c2026cc55466636d53a76f929a03452..2f046167a0b6cc6fb5531a033d8= d95c9ea399cf9 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -74,6 +74,17 @@ unset join_create_err unset join_bind_err unset join_connect_err =20 +unset fb_ns1 +unset fb_ns2 +unset fb_infinite_map_tx +unset fb_dss_corruption +unset fb_simult_conn +unset fb_mpc_passive +unset fb_mpc_active +unset fb_mpc_data +unset fb_md5_sig +unset fb_dss + # generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) =3D=3D 0x30) || # (ip6 && (ip6[74] & 0xf0) =3D=3D 0x30)'" CBPF_MPTCP_SUBOPTION_ADD_ADDR=3D"14, @@ -1399,6 +1410,115 @@ chk_join_tx_nr() print_results "join Tx" ${rc} } =20 +chk_fallback_nr() +{ + local infinite_map_tx=3D${fb_infinite_map_tx:-0} + local dss_corruption=3D${fb_dss_corruption:-0} + local simult_conn=3D${fb_simult_conn:-0} + local mpc_passive=3D${fb_mpc_passive:-0} + local mpc_active=3D${fb_mpc_active:-0} + local mpc_data=3D${fb_mpc_data:-0} + local md5_sig=3D${fb_md5_sig:-0} + local dss=3D${fb_dss:-0} + local rc=3D${KSFT_PASS} + local ns=3D$1 + local count + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtInfiniteMapTx") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$infinite_map_tx" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns infinite map tx fallback" + fail_test "got $count infinite map tx fallback[s] in $ns expected $infin= ite_map_tx" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtDSSCorruptionFallback") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$dss_corruption" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns dss corruption fallback" + fail_test "got $count dss corruption fallback[s] in $ns expected $dss_co= rruption" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtSimultConnectFallback") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$simult_conn" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns simult conn fallback" + fail_test "got $count simult conn fallback[s] in $ns expected $simult_co= nn" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtMPCapableFallbackACK") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$mpc_passive" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns mpc passive fallback" + fail_test "got $count mpc passive fallback[s] in $ns expected $mpc_passi= ve" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtMPCapableFallbackSYNACK") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$mpc_active" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns mpc active fallback" + fail_test "got $count mpc active fallback[s] in $ns expected $mpc_active" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtMPCapableDataFallback") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$mpc_data" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns mpc data fallback" + fail_test "got $count mpc data fallback[s] in $ns expected $mpc_data" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtMD5SigFallback") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$md5_sig" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns MD5 Sig fallback" + fail_test "got $count MD5 Sig fallback[s] in $ns expected $md5_sig" + fi + + count=3D$(mptcp_lib_get_counter ${!ns} "MPTcpExtDssFallback") + if [ -z "$count" ]; then + rc=3D${KSFT_SKIP} + elif [ "$count" !=3D "$dss" ]; then + rc=3D${KSFT_FAIL} + print_check "$ns dss fallback" + fail_test "got $count dss fallback[s] in $ns expected $dss" + fi + + return $rc +} + +chk_fallback_nr_all() +{ + local netns=3D("ns1" "ns2") + local fb_ns=3D("fb_ns1" "fb_ns2") + local rc=3D${KSFT_PASS} + + for i in 0 1; do + if [ -n "${!fb_ns[i]}" ]; then + eval "${!fb_ns[i]}" \ + chk_fallback_nr ${netns[i]} || rc=3D${?} + else + chk_fallback_nr ${netns[i]} || rc=3D${?} + fi + done + + if [ "${rc}" !=3D "${KSFT_PASS}" ]; then + print_results "fallback" ${rc} + fi +} + chk_join_nr() { local syn_nr=3D$1 @@ -1484,6 +1604,8 @@ chk_join_nr() join_syn_tx=3D"${join_syn_tx:-${syn_nr}}" \ chk_join_tx_nr =20 + chk_fallback_nr_all + if $validate_checksum; then chk_csum_nr $csum_ns1 $csum_ns2 chk_fail_nr $fail_nr $fail_nr @@ -3337,6 +3459,7 @@ fail_tests() join_csum_ns1=3D+1 join_csum_ns2=3D+0 \ join_fail_nr=3D1 join_rst_nr=3D0 join_infi_nr=3D1 \ join_corrupted_pkts=3D"$(pedit_action_pkts)" \ + fb_ns1=3D"fb_dss=3D1" fb_ns2=3D"fb_infinite_map_tx=3D1" \ chk_join_nr 0 0 0 chk_fail_nr 1 -1 invert fi --=20 2.51.0 From nobody Wed Sep 17 16:19:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 603F535AACC; Tue, 2 Sep 2025 21:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847521; cv=none; b=EV5AxcmcqO5spo9vS9GQr9HjpzztgEGXcOFxWK4N4j08sYUM8WWbe0D82A5nsk8fDDo7mr2Zah2n69YJgOJzmoiulMu9Md0ZUfuAToa3gxsKPLZoyWt00eSGKku24aFz8NDIHWMl0SnX5fcyNTnjdKPTwkRPs/1HHL/kaOJ1Vfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847521; c=relaxed/simple; bh=QWEeyydJNsvze58/VXuVLfkDwLyhW9ikxYVMzbLVxSQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tOJ+5ZPP7cTlHTZzFIOI9L0w6ARQ6M/xbH6Xegcwp/+aRJVF50Il5eKzzbbnskBqv5vogpdQHA9c5u3v72pORedazv6lwf8xjYGE3LLtMES9pSq8Y801NC6fleRPlcNnl+9ZqPR7rK/9BN5N8Mvmie7UzgOcsrhHrIRBk5qIwbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HjLDBHmN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HjLDBHmN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 853AAC4AF09; Tue, 2 Sep 2025 21:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756847521; bh=QWEeyydJNsvze58/VXuVLfkDwLyhW9ikxYVMzbLVxSQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HjLDBHmNklBUpTPiHsz5Lly6McFYph1lu9FotzR+otYiD/1BRwBXfZu28UGVDJ8VV fbVG+DuyZ4GKTVbL3QjiGIf2JY+O0CeL1086LOuWti7kwYwHnqn4nMh4N7XYKcrbA1 v+s1FH02o/hXm6K9i81DQUQ07gpLTlrfJQGPfA5lwxhchtqBklq0US2yqCCMzOMnsj nZ7+uqo+S3wA8ogmnZwrlIw0YpOboh2iXC30UK0bbhXcb7YiPe+cbFkjcyJKue3Wh7 N0Kluro53owZEflyQXLIyJpJ/qdtey8lHG8rKjbM5WlyOnjdmhIpRy8o2hjJFhnMQ7 bprXwwcdlYXnQ== From: "Matthieu Baerts (NGI0)" Date: Tue, 02 Sep 2025 23:11:35 +0200 Subject: [PATCH net-next v2 3/4] net: Add rfs_needed() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-net-next-mptcp-misc-feat-6-18-v2-3-fa02bb3188b1@kernel.org> References: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> In-Reply-To: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , Christoph Paasch X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4310; i=matttbe@kernel.org; h=from:subject:message-id; bh=/xEF+Yn6Gngp+jxk4ymxVk3ZRYSpju3Y/fcC7uXVS2Y=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDK2x05+3WB66YiP6L7G2YvfrtLli3kis/Hewu9JbC+Wn Vkyp4TVoKOUhUGMi0FWTJFFui0yf+bzKt4SLz8LmDmsTCBDGLg4BWAiZyIYGb6FfPdU6rk8Qdtr ZVp0FEP9K+16k9fnjjbZntzubR9UvZqR4adLgv3KVGW2j1F8ll9X6ES0LblzLrjonEzb7k4m0ec 7mAE= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Christoph Paasch Add a helper to check if RFS is needed or not. Allows to make the code a bit cleaner and the next patch to have MPTCP use this helper to decide whether or not to iterate over the subflows. tun_flow_update() was calling sock_rps_record_flow_hash() regardless of the state of rfs_needed. This was not really a bug as sock_flow_table simply ends up being NULL and thus everything will be fine. This commit here thus also implicitly makes tun_flow_update() respect the state of rfs_needed. Suggested-by: Matthieu Baerts Signed-off-by: Christoph Paasch Acked-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- include/net/rps.h | 85 ++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/include/net/rps.h b/include/net/rps.h index 9917dce42ca457e9c25d9e84ee450235f771d09b..f1794cd2e7fb32a36bde9959fab= 651663ab190fd 100644 --- a/include/net/rps.h +++ b/include/net/rps.h @@ -85,11 +85,8 @@ static inline void rps_record_sock_flow(struct rps_sock_= flow_table *table, WRITE_ONCE(table->ents[index], val); } =20 -#endif /* CONFIG_RPS */ - -static inline void sock_rps_record_flow_hash(__u32 hash) +static inline void _sock_rps_record_flow_hash(__u32 hash) { -#ifdef CONFIG_RPS struct rps_sock_flow_table *sock_flow_table; =20 if (!hash) @@ -99,42 +96,33 @@ static inline void sock_rps_record_flow_hash(__u32 hash) if (sock_flow_table) rps_record_sock_flow(sock_flow_table, hash); rcu_read_unlock(); -#endif } =20 -static inline void sock_rps_record_flow(const struct sock *sk) +static inline void _sock_rps_record_flow(const struct sock *sk) { -#ifdef CONFIG_RPS - if (static_branch_unlikely(&rfs_needed)) { - /* Reading sk->sk_rxhash might incur an expensive cache line - * miss. - * - * TCP_ESTABLISHED does cover almost all states where RFS - * might be useful, and is cheaper [1] than testing : - * IPv4: inet_sk(sk)->inet_daddr - * IPv6: ipv6_addr_any(&sk->sk_v6_daddr) - * OR an additional socket flag - * [1] : sk_state and sk_prot are in the same cache line. + /* Reading sk->sk_rxhash might incur an expensive cache line + * miss. + * + * TCP_ESTABLISHED does cover almost all states where RFS + * might be useful, and is cheaper [1] than testing : + * IPv4: inet_sk(sk)->inet_daddr + * IPv6: ipv6_addr_any(&sk->sk_v6_daddr) + * OR an additional socket flag + * [1] : sk_state and sk_prot are in the same cache line. + */ + if (sk->sk_state =3D=3D TCP_ESTABLISHED) { + /* This READ_ONCE() is paired with the WRITE_ONCE() + * from sock_rps_save_rxhash() and sock_rps_reset_rxhash(). */ - if (sk->sk_state =3D=3D TCP_ESTABLISHED) { - /* This READ_ONCE() is paired with the WRITE_ONCE() - * from sock_rps_save_rxhash() and sock_rps_reset_rxhash(). - */ - sock_rps_record_flow_hash(READ_ONCE(sk->sk_rxhash)); - } + _sock_rps_record_flow_hash(READ_ONCE(sk->sk_rxhash)); } -#endif } =20 -static inline void sock_rps_delete_flow(const struct sock *sk) +static inline void _sock_rps_delete_flow(const struct sock *sk) { -#ifdef CONFIG_RPS struct rps_sock_flow_table *table; u32 hash, index; =20 - if (!static_branch_unlikely(&rfs_needed)) - return; - hash =3D READ_ONCE(sk->sk_rxhash); if (!hash) return; @@ -147,6 +135,45 @@ static inline void sock_rps_delete_flow(const struct s= ock *sk) WRITE_ONCE(table->ents[index], RPS_NO_CPU); } rcu_read_unlock(); +} +#endif /* CONFIG_RPS */ + +static inline bool rfs_is_needed(void) +{ +#ifdef CONFIG_RPS + return static_branch_unlikely(&rfs_needed); +#else + return false; +#endif +} + +static inline void sock_rps_record_flow_hash(__u32 hash) +{ +#ifdef CONFIG_RPS + if (!rfs_is_needed()) + return; + + _sock_rps_record_flow_hash(hash); +#endif +} + +static inline void sock_rps_record_flow(const struct sock *sk) +{ +#ifdef CONFIG_RPS + if (!rfs_is_needed()) + return; + + _sock_rps_record_flow(sk); +#endif +} + +static inline void sock_rps_delete_flow(const struct sock *sk) +{ +#ifdef CONFIG_RPS + if (!rfs_is_needed()) + return; + + _sock_rps_delete_flow(sk); #endif } =20 --=20 2.51.0 From nobody Wed Sep 17 16:19:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E545E35CEC1; Tue, 2 Sep 2025 21:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847524; cv=none; b=WLW6GTycKZESZlrW5NjilsS7kzsyTZBlawRiM9HysrR9LdjyJlDo37SziuwZOkL/Q2+vEoYfl2x6brLSClHtDhoosIChS0geOliTnGDJHxny1xnKAtFoInVAZFgly60R2OMPB9h91R2y450QyW/g99ky7mgjJYacjAwIrnZ+kK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756847524; c=relaxed/simple; bh=aKV7V4/h1VElLNwk04j6OR0rXx+jT4YWtNS//uiCe6w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Icro4JGcjXu7O8s21eRr9PheKP4yuiL8YRO30RB2A+NuS7Q8PVv8Mv4ZNLL3AUhPx+sMEB0t7XMxxns5A9d9CDOzo5sSeNbzg18T1dwjjKMaz7wGX/fT3MBEt/CVY2AgOgk36F8zebl21w1xWMBLM99v0tKSSJNrlfDaYLp4Thg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H7lAnzYE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H7lAnzYE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E333C4CEED; Tue, 2 Sep 2025 21:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756847523; bh=aKV7V4/h1VElLNwk04j6OR0rXx+jT4YWtNS//uiCe6w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=H7lAnzYEmW/NPPw04oAjm59dxUN1wcKksLZFgwM+oRkRk/bHbURBIRcrlyw0ue3OI LunqnZD0RqxuVhjxVczkR2QqIAbADeNoQBwA2CGu1xGudxw4xNFBIF1KNzkJU+/D6u l9mwSnaCunyobBqY/Jc7nSVJmg7N0CdPoM77nfll+FseezBmBx2jNfhRrYUUycnYAX SPW+MI0qKsWJ7SAbdcN5L3HBGIuBqunG2ZAxH/KDUTq5lpqAnBKQgDxA3EIHzzpx2Q Fnh4JUhKbaz8fQuk4j9WiJ93WxVvkJeF44QFFfWubCvFQEWEoWmCV/Nr7mVkXLGKP+ rb+ts+pOpVQ3g== From: "Matthieu Baerts (NGI0)" Date: Tue, 02 Sep 2025 23:11:36 +0200 Subject: [PATCH net-next v2 4/4] mptcp: record subflows in RPS table Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-net-next-mptcp-misc-feat-6-18-v2-4-fa02bb3188b1@kernel.org> References: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> In-Reply-To: <20250902-net-next-mptcp-misc-feat-6-18-v2-0-fa02bb3188b1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , Christoph Paasch X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2920; i=matttbe@kernel.org; h=from:subject:message-id; bh=JcdYSSMrpRvS9n1aF7EX7vQ1sd6hTMXnoLQdj6fho/M=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDK2x04JFZuneOLANe7ZrVYfNRSkZze/6tF9MmdR4rVoU cfDgu8edZSyMIhxMciKKbJIt0Xmz3xexVvi5WcBM4eVCWjIVAYuTgGYSPVRhv/xPrOOv9Q3eWG4 4OQv9fZvu/fl8TMeODG3tG/L7N49cy2KGf6XH/5Yuu2CpP1VmelVOW4PEi4VnKk5Lf7zZvp1Ucu M0CxuAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Christoph Paasch Accelerated Receive Flow Steering (aRFS) relies on sockets recording their RX flow hash into the rps_sock_flow_table so that incoming packets are steered to the CPU where the application runs. With MPTCP, the application interacts with the parent MPTCP socket while data is carried over per-subflow TCP sockets. Without recording these subflows, aRFS cannot steer interrupts and RX processing for the flows to the desired CPU. Record all subflows in the RPS table by calling sock_rps_record_flow() for each subflow at the start of mptcp_sendmsg(), mptcp_recvmsg() and mptcp_stream_accept(), by using the new helper mptcp_rps_record_subflows(). It does not by itself improve throughput, but ensures that IRQ and RX processing are directed to the right CPU, which is a prerequisite for effective aRFS. Signed-off-by: Christoph Paasch Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index ad41c48126e44fda646f1ec1c81957db1407a6cc..a8d57b88578dfea807d3d55e430= 849aa8005c637 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -1740,6 +1741,20 @@ static u32 mptcp_send_limit(const struct sock *sk) return limit - not_sent; } =20 +static void mptcp_rps_record_subflows(const struct mptcp_sock *msk) +{ + struct mptcp_subflow_context *subflow; + + if (!rfs_is_needed()) + return; + + mptcp_for_each_subflow(msk, subflow) { + struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); + + sock_rps_record_flow(ssk); + } +} + static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) { struct mptcp_sock *msk =3D mptcp_sk(sk); @@ -1753,6 +1768,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) =20 lock_sock(sk); =20 + mptcp_rps_record_subflows(msk); + if (unlikely(inet_test_bit(DEFER_CONNECT, sk) || msg->msg_flags & MSG_FASTOPEN)) { int copied_syn =3D 0; @@ -2131,6 +2148,8 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, goto out_err; } =20 + mptcp_rps_record_subflows(msk); + timeo =3D sock_rcvtimeo(sk, flags & MSG_DONTWAIT); =20 len =3D min_t(size_t, len, INT_MAX); @@ -3922,6 +3941,8 @@ static int mptcp_stream_accept(struct socket *sock, s= truct socket *newsock, mptcp_sock_graft(ssk, newsock); } =20 + mptcp_rps_record_subflows(msk); + /* Do late cleanup for the first subflow as necessary. Also * deal with bad peers not doing a complete shutdown. */ --=20 2.51.0