From nobody Wed Dec 4 19:14:34 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 ED49819C573 for ; Thu, 5 Sep 2024 13:52:18 +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=1725544339; cv=none; b=mPuEq34C0W9uL8dtRj4IJMcz9Zv60yuGGA0yBKyUrs+7k6FSUvYGXPIxcCUnB4iltHlI2a8t06n2JiiooD3NqPBl6zAAKTvVP8OlB/alXIg/IWRo6WXnRny1rGxVkYb+hTPqgyIUnFtOtYJBK8cye4/uqCftZU+LMs9kg4vImxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725544339; c=relaxed/simple; bh=3Iiw/ev4v7xyR8PryT/7z/c5DPHsx1sWHSFO9gPA1p8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=chIrbPCnaCT1bTiQgUihDnnl78N4OMCvT6cdjFAcX3JPUSCVzn4XJQA/JBEgiVmqdAWQt6pBR0TnU46SBgkaLyPeSLZGlw2TmEqkN1tSaTMsZmKDzSuzsIugk79eqLtfgCMbI6IUWFruetQtEm+fp553CjFb59HfPcBVbTxBUPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qNYK29vu; 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="qNYK29vu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C774C4CEC5; Thu, 5 Sep 2024 13:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725544338; bh=3Iiw/ev4v7xyR8PryT/7z/c5DPHsx1sWHSFO9gPA1p8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNYK29vuwyjSd6Vtj6xCL+zeDJx9/T704AC9SETPGum+XZJLWm6WxYHt4R4Wfcjx+ moYJYJJUZNHKQiDRzGruqL7tt5QZ4ZiRCt4EX8ewFRXofysWvF1GeHnJUHP7PQQPcu t9Gsird8CCpKhVjZzZJU+MCTjR7wOnXpYQxcWz8DCyuXT+U0wENxRGAzRGzM74K3x2 8f0PIAQ335Cldcq/lbroanTgdWGoBrioQhFQ8ZXrbSvpZyoZoXvuUkyS3nhi4dI3vi WUE5jK4Zd4DsrsJwFsGNpUll8vxZKDS+JuG4GOO58Ab9DIfPa5t0NdXZ14byPcgOcV Ls+XtkRUeGYKA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Martin KaFai Lau Subject: [PATCH mptcp-next 1/4] bpf: Add mptcp_subflow bpf_iter Date: Thu, 5 Sep 2024 21:52:09 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 It's necessary to traverse all subflows on the conn_list of an MPTCP socket and then call kfunc to modify the fields of each subflow. In kernel space, mptcp_for_each_subflow() helper is used for this: mptcp_for_each_subflow(msk, subflow) kfunc(subflow); But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this conn_list walking + modify-by-kfunc usage fits the bpf_iter use case. This patch adds a new bpf_iter type named "mptcp_subflow" to do this. Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- kernel/bpf/helpers.c | 3 +++ net/mptcp/bpf.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index b5f0adae8293..2340ba967444 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW) BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy) BTF_KFUNCS_END(common_btf_ids) =20 static const struct btf_kfunc_id_set common_kfunc_set =3D { diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 9672a70c24b0..cda09bbfd617 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -204,6 +204,63 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret= _set =3D { .set =3D &bpf_mptcp_fmodret_ids, }; =20 +struct bpf_iter__mptcp_subflow { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct mptcp_sock *, msk); + __bpf_md_ptr(struct list_head *, pos); +}; + +DEFINE_BPF_ITER_FUNC(mptcp_subflow, struct bpf_iter_meta *meta, + struct mptcp_sock *msk, struct list_head *pos) + +struct bpf_iter_mptcp_subflow { + __u64 __opaque[3]; +} __attribute__((aligned(8))); + +struct bpf_iter_mptcp_subflow_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __attribute__((aligned(8))); + +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *= it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + + kit->msk =3D msk; + kit->pos =3D &msk->conn_list; + spin_lock_bh(&msk->pm.lock); + + return 0; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + struct mptcp_subflow_context *subflow; + struct mptcp_sock *msk =3D kit->msk; + + subflow =3D list_entry((kit->pos)->next, struct mptcp_subflow_context, no= de); + if (list_entry_is_head(subflow, &msk->conn_list, node)) + return NULL; + + kit->pos =3D &subflow->node; + return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subf= low *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + struct mptcp_sock *msk =3D kit->msk; + + spin_unlock_bh(&msk->pm.lock); +} + +__bpf_kfunc_end_defs(); + __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs"); --=20 2.43.0 From nobody Wed Dec 4 19:14:34 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 459E51EA85 for ; Thu, 5 Sep 2024 13:52:19 +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=1725544340; cv=none; b=o6Ee+2uiJmXEUMBcC2YqY8SpGN5efe25NAdYNkOEsAVzH5mXAl7/ZtW4aTW3lL11ULhOVdzB3MRFiGS33EX8GTqacDQ6Y+WMBY5sCnCzU8I/gjbQiw0Mq8oAfaDnSLvREvnmz8BoSUalDbAD2N2bwcge4vBbedzNX/RfsqSL8kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725544340; c=relaxed/simple; bh=/7dcNxe7NJjQWtVfZyZqdN9uo0e0jW6M0qXBu8fSDN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mD8AJoDcxQXyj/B/wDQPAMxxHZl7bk7vrsPrRwuAlZ8bfjRgj1iK4Wkx6K2Wmtaw8Qh5wUDTcL5qPB9KWSxK3GcfwosCulI3+xypEHglXWjIO9AcyWLbrzNmZTppm8ttnAcJVlHOnSGr1NxDsE7v0hVrJgRvpFdYPq++M5xEzDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o+ZuNabf; 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="o+ZuNabf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0455DC4CEC7; Thu, 5 Sep 2024 13:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725544339; bh=/7dcNxe7NJjQWtVfZyZqdN9uo0e0jW6M0qXBu8fSDN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o+ZuNabfl9JBDS6+aDwFpZRAWfBarmZ0ehsO6V7pZOYMacXowoAc1AvMNIS0U6u4m fIe332GPRbjum6rUr7aBYGTQuu82MHBoyzKOKDUlgp921LgnQAvI11hZRWBLa4/SS1 dxer+L11HyVXp/A/zCBlvT84PcknHMdg2L+Ilw0x+O6J3wtwOSn+T0CsUiCXP5y96Z q+reImIrRoPuFaILF5r+6ONz1liD+EzR2rgz3Dbc5od1MTcdor0mXorb9CzZK8tnAx DZ0IF5zDcrmkT4eTaTQpOEAl+IlahHn1Hi8py+z0slhLVInab1JQkAmZzbkWc0FIkx 9t2Ir08CfzADg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/4] bpf: Register mptcp tracing kfunc set Date: Thu, 5 Sep 2024 21:52:10 +0800 Message-ID: <10a0327a5c882326e5ace658bfd2a4d6e075d794.1725544210.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 Since the kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() are invoked in the mptcp_subflow bpf_iter test in a trace for mptcp_subflow_get_send(), it's necessary to register them into a BPF_PROG_TYPE_TRACING type kfunc set. Note: BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids) Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index cda09bbfd617..01aedaff66ed 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -301,6 +301,8 @@ static int __init bpf_mptcp_kfunc_init(void) int ret; =20 ret =3D register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); + ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &bpf_mptcp_sched_kfunc_set); ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_mptcp_sched_kfunc_set); #ifdef CONFIG_BPF_JIT --=20 2.43.0 From nobody Wed Dec 4 19:14:34 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 958391EA85 for ; Thu, 5 Sep 2024 13:52:21 +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=1725544341; cv=none; b=oANYh/x16CV8DDCx+E9VSuZ8PYXzol9FeLyu2CvqhVZYBwBh979C2s4hGE8TJKcOhETp9OpTtVSle/H7v9ETOc71Xaj/FFWzwoVIg9L9XVWGCRtOUbrTNzAge/iLKM++2Z+mvE3gmDL0g2PGptRb0l9zW3QXHc5F0iHct+I3xD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725544341; c=relaxed/simple; bh=bJr0UQrY9gjo9mLkj6nQItUIEAc6Iyb65LatvsgtBvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VmNF60o51Sri2SZ0RdkmzPo2OV+sWyMhIKNVMjBH8StptHvQnVrRATQL4kg1AMsWv1vOmMXTb66QRbOCGAwinx1/cEBZdERAWXf2S5YeulJCzq1QKofE48+eq9XSqdLTcc2275R+drANGGicnyemCj7qsJoJ07ZlFjgl7zOfN+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gaMSjAFn; 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="gaMSjAFn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 558F1C4CEC3; Thu, 5 Sep 2024 13:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725544341; bh=bJr0UQrY9gjo9mLkj6nQItUIEAc6Iyb65LatvsgtBvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gaMSjAFnzXXOLcarryxeQ1gcY67l/2eriIx8qdyCinDBN6DUKiHNVxLe1JBsVjraX e1uUtWk3rSZBNs8/IUZB3c0Q5svx/ZtMjokBElEFvsDGYNw5VTAD23rpuC3el/Ps2c ec/CVzEgbO/fWRq510YZUIHiZ8vxAY83GUnuQieiWSMeTTvDFkrKcxxky3vJG1qYAu HrpE8ZEy1wvWwltOL9lPTGFPfyxziqBQtQ6HchFcIygUAy/Yn1h28Q2qLkMS3FGj5b eUJJ1nEmzPDsw8TIKxuCe0CavAkgkUOrFfhf03gzBOAOclAv+ZattgvDIFE+UUUeKe SYrEI+VTyJUVg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/4] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Thu, 5 Sep 2024 21:52:11 +0800 Message-ID: <42d7177dbc273c36c1ef1d5d10d889f3cd0411e2.1725544210.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 new mptcp bpf selftest program for the newly added mptcp_subflow bpf_iter. Export bpf_iter_mptcp_subflow_new/_next/_destroy into bpf_experimental.h then use bpf_for_each(mptcp_subflow, subflow, msk) to walk the mptcp subflow list. Add a trace for mptcp_subflow_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loop. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 ++ .../selftests/bpf/progs/mptcp_bpf_iter.c | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 828556cdc2f0..97aad95c90c6 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -549,6 +549,13 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it, extern struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *= it) __weak __ksym; extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; =20 +struct bpf_iter_mptcp_subflow; +extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) __weak __ksym; +extern struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ks= ym; +extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *= 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/progs/mptcp_bpf.h b/tools/testing/= selftests/bpf/progs/mptcp_bpf.h index 928a1e5ad8db..9496dad5e9f0 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -46,6 +46,9 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context= *subflow) extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subf= low, bool scheduled) __ksym; =20 +extern void bpf_rcu_read_lock(void) __ksym; +extern void bpf_rcu_read_unlock(void) __ksym; + extern struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) __ksym; =20 diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c b/tools/tes= ting/selftests/bpf/progs/mptcp_bpf_iter.c new file mode 100644 index 000000000000..a3e27901d1a0 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024, Kylin Software */ + +/* vmlinux.h, bpf_helpers.h and other 'define' */ +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" + +char _license[] SEC("license") =3D "GPL"; +int pid; + +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __= ksym; + +SEC("fentry/mptcp_subflow_get_send") +struct sock *BPF_PROG(trace_mptcp_subflow_get_send, struct mptcp_sock *msk) +{ + struct mptcp_subflow_context *subflow; + int i =3D 0; + + if (bpf_get_current_pid_tgid() >> 32 !=3D pid) + return NULL; + + bpf_rcu_read_lock(); + bpf_for_each(mptcp_subflow, subflow, msk) { + if (i++ > MPTCP_SUBFLOWS_MAX) + break; + + if (subflow->token !=3D msk->token) + break; + + if (!mptcp_subflow_active(subflow)) + continue; + + mptcp_subflow_set_scheduled(subflow, false); + } + bpf_rcu_read_unlock(); + + return NULL; +} --=20 2.43.0 From nobody Wed Dec 4 19:14:34 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 92B5B1EA85 for ; Thu, 5 Sep 2024 13:52:22 +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=1725544342; cv=none; b=Z3dkVvfQKq37mHWY/3uly1afys8Bj2uxd4zaD8XLd0OoR4C/8u8JclEE1kgBHYW5cbfl+7dH2Jd5B6iEmAUZN4MEpLFJlBmnTKU7LIEsvAC+BozJOFZbI8ZKbvPSe4GJuCglHkdal2L/U3wnTH4nHmLpAIM09ypLyeLwltiFkdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725544342; c=relaxed/simple; bh=wxGbqQjO23smCYcbkjfD/xvqSzshUyphD5ZAZvzAy9A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N0HWAKW2NCWO0htza0KWgDEGlEpDfE9HLnKJrcAeigfuPAoC7zoetxZ3cgYpm9+eS4L14g1f6q3we1qa1QrZBQbaPMM5hpQREVYVcosXXs0V76A9AmVfOCSwtDKUNvBpWLpezckhZT8cfqY3vyBXW283Xt5oAwJeMJDHMTF/LPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uobdIixc; 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="uobdIixc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6165C4CEC5; Thu, 5 Sep 2024 13:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725544342; bh=wxGbqQjO23smCYcbkjfD/xvqSzshUyphD5ZAZvzAy9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uobdIixcGBuDvarmg28bMAsDdXll1nikhJMA+Pi556Tszk4muxQoe5I3wiHO7pKys tT5r8/apsorf50V025g/207decMDprHJ4GtpxIhj+XRzTZkTqyptgE5/COn8j3KRPV x4d+mu+/kMbWh1vsaBp3LppTx/8EH3LNtqKniLWpmRl52wCFXgQhpIJXf2soZTdP/c L/2GiM1dDYyU4c1oFwuZKzBmyewKBkFsR4EzjKT3nex2jDoZNFBB4xOvg1npqFdphc zqIuvD1V4XL61yLEE3PpUu2gUFYOQPbBIOXYq1wMbmpXeIiheOeUkigjC4GcqhzRiB 0l6Ms8MRN+ZqA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 4/4] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Thu, 5 Sep 2024 21:52:12 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 subtest named test_bpf_iter to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. Use endpoint_init() to add a new subflow endpoint. Use send_byte() to trigger the tracing program for mptcp_subflow_get_send. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 93869c873cad..2642d97af461 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -10,6 +10,7 @@ #include "mptcp_sock.skel.h" #include "mptcpify.skel.h" #include "mptcp_subflow.skel.h" +#include "mptcp_bpf_iter.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" @@ -470,6 +471,58 @@ static void test_subflow(void) close(cgroup_fd); } =20 +static void run_bpf_iter(void) +{ + int server_fd, client_fd; + + server_fd =3D start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); + if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) + return; + + client_fd =3D connect_to_fd(server_fd, 0); + if (!ASSERT_GE(client_fd, 0, "connect to fd")) + goto close_server; + + send_byte(client_fd); + wait_for_new_subflows(client_fd); + send_byte(client_fd); + + close(client_fd); +close_server: + close(server_fd); +} + +static void test_bpf_iter(void) +{ + struct mptcp_bpf_iter *skel; + struct nstoken *nstoken; + int err; + + skel =3D mptcp_bpf_iter__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: mptcp_iter")) + return; + + skel->bss->pid =3D getpid(); + + err =3D mptcp_bpf_iter__attach(skel); + if (!ASSERT_OK(err, "skel_attach: mptcp_iter")) + goto skel_destroy; + + nstoken =3D create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_iter")) + goto skel_destroy; + + if (endpoint_init("subflow") < 0) + goto close_netns; + + run_bpf_iter(); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iter__destroy(skel); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -651,6 +704,8 @@ void test_mptcp(void) test_mptcpify(); if (test__start_subtest("subflow")) test_subflow(); + if (test__start_subtest("bpf_iter")) + test_bpf_iter(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) --=20 2.43.0