From nobody Mon Dec 2 15:11:02 2024 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 2FD2F36124 for ; Tue, 22 Oct 2024 07:48:07 +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=1729583288; cv=none; b=TmFvHQG17k1YqYw99QtvLuCveK5vqIRgNzR23jb/fmEMMWtk8mBzAejtQDFNyK4V4mUCaNNoK34BHgU2k/lB7zv4G9PFAbO5Eb3XCJQY14bhXx/a6uI5uCJVrquyxBRCGWhmY3PkNC1ZFn3ZgYL1OrQEGO95wPkpAir0ZcPl4tE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729583288; c=relaxed/simple; bh=XllIU5PP4KHCy/vHDfYzdS5QKTFdoSnoikvzIgm3/nE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LjDS0eENwPGgV4W+DzUPucyC25Lq7RDsUHCrJRBZgS3DSay66qPlCzm/EPh8mhkOVpUEzTOnrKxwhn9Mh65qly4XYBpmYDvQj7y6mD/oox6ivApFOJN7JPZGjAD60bi4tsmkPAOe4UoyuqC0MWv7LwzNoDDnYVhyVe3p2NJfTEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YLFRoETi; 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="YLFRoETi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B23C4CEC3; Tue, 22 Oct 2024 07:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729583287; bh=XllIU5PP4KHCy/vHDfYzdS5QKTFdoSnoikvzIgm3/nE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLFRoETihmUN1fNJTP11IhkGXo7PqNLR1b/Dv00esHv4VBkWeCYEcQNIsngELnRcg 8EOEXiiWr467J6Utu/3sVPsp7V02YtEnJphWMlZ6lJMe5LSw222M57aXqu3DBgYma5 txg4aSc8pExEAQ0yB4P2HjyZSdo0i32KrKJB+vJpTMFvkfI3B1hOu/kRaGqrD+vLIK vJ5ASkguWMlIBx+4sIU5pCQW6lu+dqQWVBHPl3hj2YftfQf4c2iIocgGHJrCOCiQ2M KpN/TbtmkW1rsxHxOq3jZ0fe+BqNfCeO+k3yL51EHB3gVlyZfae9X8rlb6LmCEIhTH hbCV3IhEJ3i3A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Matthieu Baerts Subject: [PATCH mptcp-next v2 1/5] selftests/bpf: Add mptcp pm_nl_ctl link Date: Tue, 22 Oct 2024 15:47:56 +0800 Message-ID: <7e8ad4d681305c2df66040addbf0b21d1ed44c67.1729582332.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a symlink to MPTCP's pm_nl_ctl tool into bpf selftests, and updates Makefile to compile it. This is useful to run MPTCP BPF selftests on systems with an old version of IPRoute2. This tool can be used as an alternative to 'ip mptcp'. In addition, this tool is used as userspace path manager. "csf" and "dsf" commands of pm_nl_ctl for creating and destroying subflows, and "ann" and "rem" commands for signaling ADD_ADDR and RM_ADDR. These commands are not currently supported in 'ip mptcp' yet. MAINTAINERS needs to be updated since a new file is added in a non covered place. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- MAINTAINERS | 1 + tools/testing/selftests/bpf/Makefile | 3 ++- tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 120000 tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c diff --git a/MAINTAINERS b/MAINTAINERS index b21dbd7a7a26..f53d8820e233 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16298,6 +16298,7 @@ F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp*.h F: net/mptcp/ F: tools/testing/selftests/bpf/*/*mptcp*.[ch] +F: tools/testing/selftests/bpf/*mptcp*.[ch] F: tools/testing/selftests/net/mptcp/ =20 NETWORKING [TCP] diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests= /bpf/Makefile index f04af11df8eb..662825f55f99 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -157,7 +157,7 @@ TEST_GEN_PROGS_EXTENDED =3D \ flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ - xdp_features bpf_test_no_cfi.ko + xdp_features bpf_test_no_cfi.ko mptcp_pm_nl_ctl =20 TEST_GEN_FILES +=3D liburandom_read.so urandom_read sign-file uprobe_multi =20 @@ -726,6 +726,7 @@ TRUNNER_EXTRA_FILES :=3D $(OUTPUT)/urandom_read $(OUTPU= T)/bpf_testmod.ko \ $(OUTPUT)/xdp_synproxy \ $(OUTPUT)/sign-file \ $(OUTPUT)/uprobe_multi \ + $(OUTPUT)/mptcp_pm_nl_ctl \ ima_setup.sh \ verify_sig_setup.sh \ $(wildcard progs/btf_dump_test_case_*.c) \ diff --git a/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c b/tools/testing/= selftests/bpf/mptcp_pm_nl_ctl.c new file mode 120000 index 000000000000..5a08c255b278 --- /dev/null +++ b/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c @@ -0,0 +1 @@ +../net/mptcp/pm_nl_ctl.c \ No newline at end of file --=20 2.45.2 From nobody Mon Dec 2 15:11:02 2024 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 F02F436124 for ; Tue, 22 Oct 2024 07:48:09 +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=1729583290; cv=none; b=XR+gtOcOtQWBoUS0XIVdJRdKFxgOjZCp1EUDx+sUbCFhv3sKp2+bW0jTE656RsXlyUt6uVBSGVq5Dmko8dg0k83hWOWLhhOL2YXHUn1BaCm2d55piHbo/zUwtmoa3leGrhnxvOuth4l8+GkHXY2nI3MagUgrPOHETUlgIzXqbgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729583290; c=relaxed/simple; bh=/z9OKymIbh9Q0RjtqpgMrnbDymcmPYZhI9q62HvCf0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S3gPartEoxlVjxAwUyUivVPzMdZU3TYWRinWqyD5vAS1J10n2C02bEBJDBIUPwR2SGnkRRofpuxNjrCice6aiM+aYP/FRDAqlzysJqt/XYFCRblWlpNRpYMq6raBYvu5F7ERUvAivR9qKFk1nMU6oG0JH8pDUKFU4BZmTmNpgYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jd4xC/sM; 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="Jd4xC/sM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 649E0C4CEC3; Tue, 22 Oct 2024 07:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729583289; bh=/z9OKymIbh9Q0RjtqpgMrnbDymcmPYZhI9q62HvCf0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jd4xC/sMRhyK7LGondB+9fnikcmoiNBVSIqHjkHCwNOgmA4r1X3O85kFP8qUUDANg SlrXQoC7UtUe2B+2blHkPQGinK0MOMCPYOq4H8KRkGxOx1aVd/DDccJCKfXISfcIyF JBjQX8WUnRnm97smEHPv8T0BYXScNrsJ3Np3JXOCj1tPKp9MCE5/iaK3NxM9V4yhGa hM1Bj2q+lk+AepjQUBjm9Opbdp8zTrgGfOdvjHE/+GqTYlNevUHs+87R8Tr9bfliiW v/TKKjv1EXR5PnEoFldDb/ZlrRjyN4lVnBsEhOnxx2uOcQped99lOgMCCSACm/vos6 SyB+wyQEnuVWA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/5] selftests/bpf: Use pm_nl_ctl if ip mptcp not supported Date: Tue, 22 Oct 2024 15:47:57 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang If running MPTCP BPF selftests on systems with an old version of IPRoute2, 'ip mptcp' command is not supported. In this case, instead of skipping the test, falling back to using 'pm_nl_ctl' tool is a better option. This patch adds an 'ip_mptcp' argument for endpoint_add() to control whether to use 'ip mptcp' or 'pm_nl_ctl' to add an endpoint. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index be746e0fc393..97652f7683e8 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -28,6 +28,7 @@ #define ADDR6_3 "dead:beef:3::1" #define ADDR6_4 "dead:beef:4::1" #define PORT_1 10001 +#define PM_CTL "./mptcp_pm_nl_ctl" #define WITH_DATA true #define WITHOUT_DATA false =20 @@ -384,13 +385,18 @@ static int address_init(void) return -1; } =20 -static int endpoint_add(char *addr, char *flags) +static int endpoint_add(char *addr, char *flags, bool ip_mptcp) { - return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, addr, f= lags); + if (ip_mptcp) + return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", + NS_TEST, addr, flags); + return SYS_NOFAIL("ip netns exec %s %s add %s flags %s", + NS_TEST, PM_CTL, addr, flags); } =20 static int endpoint_init(char *flags, u8 endpoints) { + bool ip_mptcp =3D true; int ret =3D -1; =20 if (!endpoints || endpoints > 4) @@ -401,17 +407,16 @@ static int endpoint_init(char *flags, u8 endpoints) =20 if (SYS_NOFAIL("ip -net %s mptcp limits set add_addr_accepted 4 subflows = 4", NS_TEST)) { - printf("'ip mptcp' not supported, skip this test.\n"); - test__skip(); - goto fail; + SYS(fail, "ip netns exec %s %s limits 4 4", NS_TEST, PM_CTL); + ip_mptcp =3D false; } =20 if (endpoints > 1) - ret =3D endpoint_add(ADDR_2, flags); + ret =3D endpoint_add(ADDR_2, flags, ip_mptcp); if (endpoints > 2) - ret =3D ret ?: endpoint_add(ADDR_3, flags); + ret =3D ret ?: endpoint_add(ADDR_3, flags, ip_mptcp); if (endpoints > 3) - ret =3D ret ?: endpoint_add(ADDR_4, flags); + ret =3D ret ?: endpoint_add(ADDR_4, flags, ip_mptcp); =20 fail: return ret; --=20 2.45.2 From nobody Mon Dec 2 15:11:02 2024 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 866DB36124 for ; Tue, 22 Oct 2024 07:48:11 +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=1729583291; cv=none; b=jGn4IYTBDRBaYO1mQncj7x4xWddcKrXYt6rp6AXWtPhSz4S7Gx8l8cRAGcKcoCIPwcYYjxzENQ1FZFTbcQz2J/Z/V3ZgcO0G2yTdyecLxtfpnKpyEAxOsVV30vrNcQ1udtrZRMtws5W6feyiuAr0zO49nmzUW4X3yP/PnuyIy9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729583291; c=relaxed/simple; bh=AgpknJVijjJyHhc4i7xj+d54hIAL5FcOm7XRITrl/MA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nt0X1+s00SpFHsVveMb1xN4a1ZoeuQaJKRg487/VsEc/VlnQ0taClqsjx3dcMBKel0fpvEGCdS1sgMOFfsBGnYwqPW6EnYI4CYcuPpKG1P+xg/BNKdQxidBAVAm+biQI0YsJUQsp5DR1CxIVUtJvWbvZl2dHROfiYkqJbASSkOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tXhDHhSh; 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="tXhDHhSh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FC37C4CEC3; Tue, 22 Oct 2024 07:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729583291; bh=AgpknJVijjJyHhc4i7xj+d54hIAL5FcOm7XRITrl/MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tXhDHhShHlhjipceQjdlyyRzSMVY2chHhqcS5njAaNs4sRKZgF5i1gQrJrIpUvHUS KcZjzJmnd6LejHdFf2E0wl05UlX7Sirg+vGplM+BtwvQ5c/2lxhPlEDUfcQET3pSzL XjsfUG99T5Ehtsliml9dpdPnXNoLgyP0aPmTjdIiIU78Y0HyMaxxchIPp/YutKCGGT D9fX6gFIStEmkQjrZgt4uzS4H0eMkpTLTGWcweV3KryraoHCEIKL8XsMcbXkOfR961 jmtXdVdF5wDFyGaHq04u/nduQh8d2R6KREerY8u9DUezFdLyLdDGtMepYs3or7w4Gj 3HIL1yHh65TQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/5] bpf: Add mptcp_address bpf_iter Date: Tue, 22 Oct 2024 15:47:58 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Just like the mptcp_subflow bpf_iter used to implement the MPTCP BPF packet scheduler, another bpf_iter is also needed, named mptcp_address, to traverse all address entries on userspace_pm_local_addr_list of an MPTCP socket for implementing the MPTCP BPF path manager. In kernel space, we walk this list like this: list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) kfunc(entry); With the mptcp_address bpf_iter, bpf_for_each() can be used to do the same thing in BPF program: bpf_for_each(mptcp_address, entry, msk) kfunc(entry); This bpf_iter should be invoked under holding the msk pm lock, so use lockdep_assert_held() to assert the lock is holding. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index e9db856972cb..8889e5351897 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -214,6 +214,15 @@ struct bpf_iter_mptcp_subflow_kern { struct list_head *pos; } __aligned(8); =20 +struct bpf_iter_mptcp_address { + __u64 __opaque[2]; +} __aligned(8); + +struct bpf_iter_mptcp_address_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __aligned(8); + __bpf_kfunc_start_defs(); =20 __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) @@ -266,6 +275,39 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_s= ubflow *it) { } =20 +__bpf_kfunc static int +bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_address_kern *kit =3D (void *)it; + + kit->msk =3D msk; + if (!msk) + return -EINVAL; + + lockdep_assert_held(&msk->pm.lock); + + kit->pos =3D &msk->pm.userspace_pm_local_addr_list; + return 0; +} + +__bpf_kfunc static struct mptcp_pm_addr_entry * +bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it) +{ + struct bpf_iter_mptcp_address_kern *kit =3D (void *)it; + + if (!kit->msk || list_is_last(kit->pos, &kit->msk->pm.userspace_pm_local_= addr_list)) + return NULL; + + kit->pos =3D kit->pos->next; + return list_entry(kit->pos, struct mptcp_pm_addr_entry, list); +} + +__bpf_kfunc static void +bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it) +{ +} + __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) { @@ -305,6 +347,9 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_AR= GS) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_new, KF_ITER_NEW | KF_TRUSTED_AR= GS) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_next, KF_ITER_NEXT | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE) BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) --=20 2.45.2 From nobody Mon Dec 2 15:11:02 2024 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 25B1136124 for ; Tue, 22 Oct 2024 07:48:12 +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=1729583293; cv=none; b=P4IBPl7K+eKgnB4WBM+4jyJSJxaQgkCgHbgBNFhnLjg1H1w10N7c/myPxtDYcFuiOxTKlS4kvsoGprgqesyzkzMG7iuA11iroIx8+8WS/9OTFAzpZcc7QbXZFHCmcF+VXLLXAQbdF356bxPR3Mynv3v0g2e8sklCi4ET7HHS5tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729583293; c=relaxed/simple; bh=/ZW0LmjaKhBp10DMOxqXaZ7TjypcW1MActVI30YmzNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ryc4BZOv0m2Z52P29y+pLkIpDYYRkYQaHjKNjACZmWCpeYD9h4HvATCVobhrFykq1GYhHs4nxfFm/T/ZrEoRJGaGb7UVHIt9geJUPQWnV8auOTqpRepJam+Nlk2Zfbve3VDzAjEErbJda3qGiMZdf5JKZcdtEfuh2x60AX06+ok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m992TW2O; 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="m992TW2O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2526C4CEC3; Tue, 22 Oct 2024 07:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729583292; bh=/ZW0LmjaKhBp10DMOxqXaZ7TjypcW1MActVI30YmzNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m992TW2OqkWUzC0H4eKCdkyfYYr058GRTntrzDDyezmH8Lt4jOamQQqoVj6WfZQGN CzxxPwFhZBYuDvEI0n463VM4hM107pNr4P9fK5Ii2yZ1gpWS8Q+vz9r5rw3YUWbYx4 3W4Dq4HJk9xjLp7r5utlmX1mobGdK4L88vuticzEN95ZhjtGafL2QgM3ARVDbLEusY guDKQWuHAER0cFWK8GgAQZzSTVbYUBUiPedipz+uV3D1bby3buPowyY90WplqDTmz2 LpBiIqi1PRzZHdeKDkc8PXYBW6RxAZOiNkphhrjnPXzvMepUTKGLlnyKqueCygYWMq 46lntZqaPtNlw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/5] bpf: Export more helpers used by mptcp_address test Date: Tue, 22 Oct 2024 15:47:59 +0800 Message-ID: <5063a458ea30f6393526ab034f4479e25b898231.1729582332.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The mptcp_address bpf_iter should be invoked under holding the msk pm lock, so spin_lock_bh() and spin_unlock_bh() are needed in BPF program to hold or release the msk pm lock. And bpf_ipv6_addr_v4mapped() helper is also needed by the mptcp_address bpf_iter selftest program. This patch adds the corresponding BPF wrappers for these helpers and adds them to the mptcp common kfunc_set. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 8889e5351897..057017d3f5c0 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -325,6 +325,24 @@ __bpf_kfunc static void bpf_mptcp_sock_release(struct = mptcp_sock *msk) WARN_ON_ONCE(!sk || !refcount_dec_not_one(&sk->sk_refcnt)); } =20 +__bpf_kfunc static void bpf_spin_lock_bh(spinlock_t *lock) +{ + spin_lock_bh(lock); +} + +__bpf_kfunc static void bpf_spin_unlock_bh(spinlock_t *lock) +{ + spin_unlock_bh(lock); +} + +__bpf_kfunc static bool bpf_ipv6_addr_v4mapped(const struct mptcp_addr_inf= o *a) +{ +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + return ipv6_addr_v4mapped(&a->addr6); +#endif + return false; +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) { @@ -352,6 +370,9 @@ BTF_ID_FLAGS(func, bpf_iter_mptcp_address_next, KF_ITER= _NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_address_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE) +BTF_ID_FLAGS(func, bpf_spin_lock_bh) +BTF_ID_FLAGS(func, bpf_spin_unlock_bh) +BTF_ID_FLAGS(func, bpf_ipv6_addr_v4mapped) BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) =20 static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set =3D { --=20 2.45.2 From nobody Mon Dec 2 15:11:02 2024 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 C9FF236124 for ; Tue, 22 Oct 2024 07:48:14 +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=1729583294; cv=none; b=G77VyzUlVlK5PogBrTfvudSpXSPqpBXJsWYgY4eyZzFaSeezxvxPewdnKWYV6pMaEEVficFuUim3j1Ogf2VBmM1lJC88hyyqAxr9o9zUbR8CYgth5o2hXquQOY0xohBnRR/IC0GFZ9Iq4kw94KnxnVLRvBi2NUs9K3RoqsvNfGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729583294; c=relaxed/simple; bh=V/QyjIF+7EJ2itx8z+XkfviYSKnXuHTyHmKnCTxT2kI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gppJwXbfYSxok6/hOCeAB8jNjuW4pgLKTx4j9qvmttmYuCSBCg5ypLehpqB7cAr5mcFxlRu6C4jkvI5piHwo2QwSuXIL+EnvpK3YoikvhVBfqz6fJhW1njq9vPMAZyMXBAlAtv6q2XT7LPJqd3cVURE+xiPzJWFCrvJAb8eoFxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LNQ2jWZi; 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="LNQ2jWZi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CDE9C4CEC3; Tue, 22 Oct 2024 07:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729583294; bh=V/QyjIF+7EJ2itx8z+XkfviYSKnXuHTyHmKnCTxT2kI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNQ2jWZi8YdWNjQnkA17wYywziO8saCtxEW+ugpE5Y0YZvA/6RLRMh/dS9sgppwS9 LSKNbvr9zkiuc1wI6/wRq79nvkokW/vh6RORv89d8ffTSc2fgnTxjXvxL/YFqosHM5 +kCJGcoRANimsM0XhnrKRZqsoVNxe1Q9zAcqIWBjOLJriRM0iVvaNpnJ04JITV6n5E UmuwwkjMIqyVRc2E0SkNxgdQnuEnAn7wJIkcLswSsX+BjqN48uS8DBGbu14j3owtIA Pu4RjZ0ffigcoX7pajD3fcDKw53h6WwHu1SuyMkq2gIE68YUsOZJHvzcC4NPUWbvN8 4YbO7ZiYF1qag== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 5/5] selftests/bpf: Add mptcp_address bpf_iter subtest Date: Tue, 22 Oct 2024 15:48:00 +0800 Message-ID: <7646544aba9fe416676a1ab913232d08ba26a585.1729582332.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a test program for the newly added mptcp_address bpf_iter in SEC "cgroup/getsockopt". This test iterates over all address entries on the local address list of userspace PM and check whether each one is an IPv4mapped address. Export mptcp_address helpers bpf_iter_mptcp_address_new/_next/_destroy into bpf_experimental.h. Use bpf_mptcp_sock_acquire() to acquire the msk, then lock the msk pm lock and use bpf_for_each(mptcp_address) to walk the local address list of this msk. Invoke bpf_ipv6_addr_v4mapped() in the loop to check whether the address is an IPv4mapped one. Then Add the address ID of each entry to local veriable local_ids. Out of the loop, unlock the msk pm lock and use bpf_mptcp_sock_release() to release the msk. Finally, assign local_ids to global variable ids so that the application can obtain this value. Add a subtest named test_iters_address to load and verify the newly added mptcp_address type bpf_iter example in test_mptcp. Since mptcp_address bpf_iter iterates over all address entries on the local address list of userspace PM. A set of userspace PM helpers are added. Set pm_type and start "pm_nl_ctl events" command to save pm events into the log file /tmp/bpf_userspace_pm_events in userspace_pm_init(). Kill "pm_nl_ctl" command and remove the log file in userspace_pm_cleanup(). Parse the log file in userspace_pm_add_subflow() to get the token, sport and dport values, then use "pm_nl_ctl csf" command to create a subflow. Use the helper userspace_pm_add_subflow() to add 3 new subflow endpoints. Send a byte of message to start the mptcp connection, and receive the message. getsockopt() is invoked to trigger the "cgroup/getsockopt" test program. Check if skel->bss->ids equals 60 to verify whether the program loops three times as expected. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 8 + .../testing/selftests/bpf/prog_tests/mptcp.c | 214 ++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 5 + .../selftests/bpf/progs/mptcp_bpf_iters.c | 39 ++++ 4 files changed, 266 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 08eaa431aafd..305c19fb377b 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -583,6 +583,14 @@ bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subf= low *it) __weak __ksym; extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak _= _ksym; =20 +struct bpf_iter_mptcp_address; +extern int bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it, + struct mptcp_sock *msk) __weak __ksym; +extern struct mptcp_pm_addr_entry * +bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it) __weak __ks= ym; +extern void +bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it) __weak _= _ksym; + extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags= ) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ks= ym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 97652f7683e8..73bfd177dc04 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -29,6 +29,7 @@ #define ADDR6_4 "dead:beef:4::1" #define PORT_1 10001 #define PM_CTL "./mptcp_pm_nl_ctl" +#define PM_EVENTS "/tmp/bpf_userspace_pm_events" #define WITH_DATA true #define WITHOUT_DATA false =20 @@ -57,6 +58,14 @@ #endif #define MPTCP_SCHED_NAME_MAX 16 =20 +enum mptcp_pm_type { + MPTCP_PM_TYPE_KERNEL =3D 0, + MPTCP_PM_TYPE_USERSPACE, + + __MPTCP_PM_TYPE_NR, + __MPTCP_PM_TYPE_MAX =3D __MPTCP_PM_TYPE_NR - 1, +}; + static const unsigned int total_bytes =3D 10 * 1024 * 1024; static int duration; =20 @@ -270,6 +279,19 @@ static void send_byte(int fd) ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); } =20 +static int recv_byte(int fd) +{ + char buf[1]; + ssize_t n; + + n =3D recv(fd, buf, sizeof(buf), 0); + if (CHECK(n <=3D 0, "recv_byte", "recv")) { + log_err("failed/partial recv"); + return -1; + } + return 0; +} + static int verify_mptcpify(int server_fd, int client_fd) { struct __mptcp_info info; @@ -585,6 +607,196 @@ static void test_iters_subflow(void) close(cgroup_fd); } =20 +static int userspace_pm_init(enum mptcp_pm_type pm_type) +{ + if (address_init()) + goto fail; + + SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.pm_type=3D%u", + NS_TEST, pm_type); + SYS(fail, "ip netns exec %s %s limits 4 4", + NS_TEST, PM_CTL); + SYS(fail, "ip netns exec %s %s events >> %s 2>&1 &", + NS_TEST, PM_CTL, PM_EVENTS); + + return 0; +fail: + return -1; +} + +static void userspace_pm_cleanup(void) +{ + SYS_NOFAIL("ip netns exec %s killall %s > /dev/null 2>&1", + NS_TEST, PM_CTL); + SYS_NOFAIL("ip netns exec %s rm -rf %s", NS_TEST, PM_EVENTS); +} + +static int userspace_pm_get_events_line(char *type, char *line) +{ + char buf[BUFSIZ], *str; + size_t len; + int fd; + + fd =3D open(PM_EVENTS, O_RDONLY); + if (fd < 0) { + log_err("failed to open pm events\n"); + return -1; + } + + len =3D read(fd, buf, sizeof(buf)); + close(fd); + if (len <=3D 0) { + log_err("failed to read pm events\n"); + return -1; + } + + str =3D strstr(buf, type); + if (!str) { + log_err("failed to get type %s pm event\n", type); + return -1; + } + + strcpy(line, str); + return 0; +} + +static int userspace_pm_get_token(int fd) +{ + char line[1024], *str; + __u32 token; + int i; + + /* Wait max 2 sec for the connection to be established */ + for (i =3D 0; i < 10; i++) { + usleep(200000); /* 0.2s */ + send_byte(fd); + + sync(); + if (userspace_pm_get_events_line("type:2", line)) + continue; + str =3D strstr(line, "token"); + if (!str) + continue; + if (sscanf(str, "token:%u,", &token) !=3D 1) + continue; + return token; + } + + return 0; +} + +static int userspace_pm_add_subflow(__u32 token, char *addr, __u8 id) +{ + bool ipv6 =3D strstr(addr, ":"); + char line[1024], *str; + __u32 sport, dport; + + if (userspace_pm_get_events_line("type:2", line)) + return -1; + + str =3D strstr(line, "sport"); + if (!str || sscanf(str, "sport:%u,dport:%u,", &sport, &dport) !=3D 2) { + log_err("add_subflow error, str=3D%s\n", str); + return -1; + } + + str =3D ipv6 ? (strstr(addr, ".") ? "::ffff:"ADDR_1 : ADDR6_1) : ADDR_1; + SYS_NOFAIL("ip netns exec %s %s csf lip %s lid %u rip %s rport %u token %= u", + NS_TEST, PM_CTL, addr, id, str, dport, token); + + return 0; +} + +static void run_iters_address(void) +{ + int server_fd, client_fd, accept_fd; + int is_mptcp, err; + socklen_t len; + __u32 token; + + server_fd =3D start_mptcp_server(AF_INET6, "::ffff:"ADDR_1, PORT_1, 0); + if (!ASSERT_OK_FD(server_fd, "start_mptcp_server")) + return; + + client_fd =3D connect_to_fd(server_fd, 0); + if (!ASSERT_OK_FD(client_fd, "connect_to_fd")) + goto close_server; + + accept_fd =3D accept(server_fd, NULL, NULL); + if (!ASSERT_OK_FD(accept_fd, "accept")) + goto close_client; + + token =3D userspace_pm_get_token(client_fd); + if (!token) + goto close_client; + recv_byte(accept_fd); + usleep(200000); /* 0.2s */ + + err =3D userspace_pm_add_subflow(token, "::ffff:"ADDR_2, 10); + err =3D err ?: userspace_pm_add_subflow(token, "::ffff:"ADDR_3, 20); + err =3D err ?: userspace_pm_add_subflow(token, "::ffff:"ADDR_4, 30); + if (!ASSERT_OK(err, "userspace_pm_add_subflow")) + goto close_accept; + + send_byte(accept_fd); + recv_byte(client_fd); + + len =3D sizeof(is_mptcp); + /* mainly to trigger the BPF program */ + err =3D getsockopt(client_fd, SOL_TCP, TCP_IS_MPTCP, &is_mptcp, &len); + if (ASSERT_OK(err, "getsockopt(client_fd, TCP_IS_MPTCP)")) + ASSERT_EQ(is_mptcp, 1, "is_mptcp"); + +close_accept: + close(accept_fd); +close_client: + close(client_fd); +close_server: + close(server_fd); +} + +static void test_iters_address(void) +{ + struct mptcp_bpf_iters *skel; + struct nstoken *nstoken; + int cgroup_fd; + int err; + + cgroup_fd =3D test__join_cgroup("/iters_address"); + if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: iters_address")) + return; + + skel =3D mptcp_bpf_iters__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_address")) + goto close_cgroup; + + skel->links.iters_address =3D bpf_program__attach_cgroup(skel->progs.iter= s_address, + cgroup_fd); + if (!ASSERT_OK_PTR(skel->links.iters_address, "attach getsockopt")) + goto skel_destroy; + + nstoken =3D create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto skel_destroy; + + err =3D userspace_pm_init(MPTCP_PM_TYPE_USERSPACE); + if (!ASSERT_OK(err, "userspace_pm_init: iters_address")) + goto close_netns; + + run_iters_address(); + + /* 10 + 20 + 30 =3D 60 */ + ASSERT_EQ(skel->bss->ids, 60, "address ids"); + + userspace_pm_cleanup(); +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iters__destroy(skel); +close_cgroup: + close(cgroup_fd); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -768,6 +980,8 @@ void test_mptcp(void) test_subflow(); if (test__start_subtest("iters_subflow")) test_iters_subflow(); + if (test__start_subtest("iters_address")) + test_iters_address(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/= selftests/bpf/progs/mptcp_bpf.h index 3b20cfd44505..376979a9c4f0 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -52,6 +52,11 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym; extern struct sock * bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) __= ksym; =20 +extern void bpf_spin_lock_bh(spinlock_t *lock) __ksym; +extern void bpf_spin_unlock_bh(spinlock_t *lock) __ksym; + +extern bool bpf_ipv6_addr_v4mapped(const struct mptcp_addr_info *a) __ksym; + extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subf= low, bool scheduled) __ksym; =20 diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/te= sting/selftests/bpf/progs/mptcp_bpf_iters.c index 1bede22a7e3d..513be1bbe749 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -62,3 +62,42 @@ int iters_subflow(struct bpf_sockopt *ctx) bpf_mptcp_sock_release(msk); return 1; } + +SEC("cgroup/getsockopt") +int iters_address(struct bpf_sockopt *ctx) +{ + struct mptcp_pm_addr_entry *entry; + struct bpf_sock *sk =3D ctx->sk; + struct mptcp_sock *msk; + int local_ids =3D 0; + + if (!sk || sk->protocol !=3D IPPROTO_MPTCP || + ctx->level !=3D SOL_TCP || ctx->optname !=3D TCP_IS_MPTCP) + return 1; + + msk =3D bpf_mptcp_sk((struct sock *)sk); + if (msk->pm.server_side) + return 1; + + msk =3D bpf_mptcp_sock_acquire(msk); + if (!msk) + return 1; + bpf_spin_lock_bh(&msk->pm.lock); + bpf_for_each(mptcp_address, entry, msk) { + /* Here MPTCP-specific path manager kfunc can be called: + * this test is not doing anything really useful, only to + * verify the iteration works. + */ + + if (!bpf_ipv6_addr_v4mapped(&entry->addr)) + break; + + local_ids +=3D entry->addr.id; + } + bpf_spin_unlock_bh(&msk->pm.lock); + bpf_mptcp_sock_release(msk); + + ids =3D local_ids; + + return 1; +} --=20 2.45.2