From nobody Sun Dec 22 06:28:43 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 13C041173F; Mon, 9 Sep 2024 01:36:57 +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=1725845818; cv=none; b=cpWfeVLGbprgnxH3pKTYLuy6QLrLx/r4cAFLO3+Legv30LSVavBEn1kABMMr/po2seIWQPPi540k9Zl0cPXFPR1AXKqoSxs6EaI0AX5vjf4AfhPvU++rnBxQBkPbBK8BtXUAb5MvMKiQKRYHPqdp9DPhybQcqvoC4CpIA1TNfx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845818; c=relaxed/simple; bh=YkJdh4kxKvOb4Mn7ACfv1Xo7kqGDDToIapY7046mY3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dQFQdth1MadanzcbSuKyo2NL6IFT7KmqSMps1WEeRu5mTOUT2t6m/7RcHpnNfuhsqqpbF/6hkn/g4E1mnG33R6IlwNCDAHgA6qaoCfpsdQ+tLoV++w3NsHtPiRgOjKb8D6L349lVmvm8mlIjQfLatE/3jW53rD9YAhOTfIOs8PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F6ZfF0K+; 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="F6ZfF0K+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFB71C4CEC3; Mon, 9 Sep 2024 01:36:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725845817; bh=YkJdh4kxKvOb4Mn7ACfv1Xo7kqGDDToIapY7046mY3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F6ZfF0K+dDblR59zUQmCZdureyxdCOjvvakwaohNI/4RsGv+57Qj2/nHisfWgKUPj VlFZjFBYrP+Z0I1lts7DBQIepOVet/tjOjQUlvsmsT7o6h1zh2sFkBdK8eYmwIJRei Qgd5uhFx0vhTBXdBF3JgR8f2PiQLV3rprCCnRTMzZS+rIXJzHkTk6MnU+FjMLJa+Dc xK2S13kYnCQwTRaIPN92olBS/gq1OElZdK2Rz0m5u3xoDN+N8UVVS+TANkg4V3DN9U fD/P0PbUnDmleuNC6OGPDasukb1DMCZP/CtUv7gTQvN3tKpPJ1f4VRdpRG9zkP61KL pxKdW+RY5pICg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , bpf , Martin KaFai Lau Subject: [PATCH mptcp-next v2 1/4] bpf: Add mptcp_subflow bpf_iter Date: Mon, 9 Sep 2024 09:36:44 +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. So this patch adds a new bpf_iter type named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). Then bpf_for_each() for mptcp_subflow can be used in BPF program like this: bpf_rcu_read_lock(); bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow); bpf_rcu_read_unlock(); Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 6 ++++++ 2 files changed, 57 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 9672a70c24b0..799264119891 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -204,10 +204,59 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodre= t_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); +}; + +struct bpf_iter_mptcp_subflow { + __u64 __opaque[2]; +} __attribute__((aligned(8))); + +struct bpf_iter_mptcp_subflow_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __attribute__((aligned(8))); + __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs"); =20 +__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; + + if (!msk) + return -EINVAL; + + kit->msk =3D msk; + kit->pos =3D &msk->conn_list; + 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 (!msk || 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) +{ +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) { @@ -221,6 +270,8 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct = sock *sk) return tcp_rtx_queue_empty(sk); } =20 +__bpf_kfunc_end_defs(); + __diag_pop(); =20 BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d25d2dac88a5..b3f5254e3c0d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -715,6 +715,12 @@ void mptcp_subflow_queue_clean(struct sock *sk, struct= sock *ssk); void mptcp_sock_graft(struct sock *sk, struct socket *parent); u64 mptcp_wnd_end(const struct mptcp_sock *msk); void mptcp_set_timeout(struct sock *sk); +struct bpf_iter_mptcp_subflow; +int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk); +struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it); +void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it); bool bpf_mptcp_subflow_queues_empty(struct sock *sk); struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos); --=20 2.43.0 From nobody Sun Dec 22 06:28:43 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 189A7125B9 for ; Mon, 9 Sep 2024 01:36:59 +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=1725845820; cv=none; b=LxBNQItGgcifT7sYFgKYZ/AQ7xaHunR4HdABLNMc+UW6In0SYYj4i3XPAb3H7rj56MFdKTjO9dGNVDZgkQh3ImYjFeInAjO7Z+VjxTYS/WUvzM9tv1fYU65HBWwklVEXOpzDS85e3kMoSWJpl0dLnlA3+meA7+lpNSRQoxv6ykY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845820; c=relaxed/simple; bh=JspjdKMBqx48yFGCjzfZH/jfXt7PLjQ88Jz68gDrMPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WpOCvsir4bH15FrsmV4JqI62/ndH3RM+L4bfzATD3vPF8FRD7niRlHlnrrKEdBUg6hxSsfdnLsYxQzOBeCj9YTcmUBb90a6MKTeXlQKQWTloA77pC/LHTVbV3K38CzVyGRiqjV3O5zsKbdIiDgp3y8K38vYgjf3HG9Gu2JOewfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cXvSh+Fn; 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="cXvSh+Fn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B0D8C4CEC3; Mon, 9 Sep 2024 01:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725845819; bh=JspjdKMBqx48yFGCjzfZH/jfXt7PLjQ88Jz68gDrMPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXvSh+Fnl/kKCgAGeaOTjE9i40EdZyh5gWSP2wrP/Y1dm/j3dXiarWc2ecvR343Kj KFu/qu12o+sHJIz36wHvodUEgqjwXo7okCqjGdMkHLKfS+RbL56dLFx2GU74KeUa0F 3zvvf/mx0upxkQyRNRKCiJnBZCHQ1vP3Y4ku3657qa0lF7t3IRW/osWq/pQNvJb1YP +BiJ1Tk+VDID96LGZmRFhZ5FlCwqSLlilkZ0mX7BIrXr11CmeqNOdN23h6XdgiLV0w pUjtmX/5C0ie30qoiriNXnL8NEzS1U2Wqc50d9eFmBb5SJyh889/fSfuQNO2FtpphC nLX0y6NlYuyIg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/4] bpf: Register mptcp tracing kfunc set Date: Mon, 9 Sep 2024 09:36:45 +0800 Message-ID: <54b9eaedf9d244fa30b6db570f9eab366d4ee75f.1725845619.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 ftrace hook for mptcp_sched_get_send(), it's necessary to register them into a BPF_PROG_TYPE_TRACING type kfunc set together with the bpf_iter mptcp_subflow helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 799264119891..f653142ada4f 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -275,9 +275,12 @@ __bpf_kfunc_end_defs(); __diag_pop(); =20 BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) +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_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx_by_pos) -BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_set_timeout) BTF_ID_FLAGS(func, mptcp_wnd_end) BTF_ID_FLAGS(func, tcp_stream_memory_free) @@ -295,6 +298,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 Sun Dec 22 06:28:43 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 AF46E1171D for ; Mon, 9 Sep 2024 01:37: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=1725845821; cv=none; b=NxKO4oGgPb5+GhnuHaC4mF0IOJpm4jqg7egvx0xyNI2YM9vFKD51bTwln/WPj6ZT3U1eD8rPJX/dlXQow28IQbFrlp9cyD1wtqH0hgfT71gnLmWpvxdEjvhW7UIbA/AEolBzNoP6stWnmQhaIusw/Lwt8tMqbKWyidxxl3JYrWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845821; c=relaxed/simple; bh=O7H5p81f3ccOd4bUeotTC/JgYHamD54yF+Aj4VgqtxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUH4aZv42/2D7jCCmftZwm9/aNL80KvViTFrpcMZhol+MUawKjQofIC0JN8Ioy+6vByfVUQ9DGwgTvH6aZaqoecNC0S1jwOiQaoeYP90w/AMyI4Fwudqmf7o1TpZi+99fc1i0BbnC8U4e6ObBkmdAPWijqhvYoPFBYPtnvvBVEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gYZg1a2J; 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="gYZg1a2J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DCB6C4CEC3; Mon, 9 Sep 2024 01:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725845821; bh=O7H5p81f3ccOd4bUeotTC/JgYHamD54yF+Aj4VgqtxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gYZg1a2JjcnYXOgJFFpEdcSdA1WLVb8U3U2FDtfVPTqeBDzoA/nqLuW7nwa3PsW+D EKj3rj4AAV1Pu16pKEqxSy65lJgHG4TSmYvpEsomKENNIG7C4PnVQwFio4Ke9IJfqF uMeSnIefc/FvRwxrD/G7CtIE22Woe1vf9zFMw7vS8/zMwq+pe9or8GwiwJtVzeQYsi o0akbuxP/Dcd2D33875q1diqcWFOCkEDnyXOkUsB8XT592eKqjGftjS4qEhLar5D10 LgSZLX14Q84+aDKDyq8sF6vAItmhUBIzqicGp70sBoLO3YhpAMrj+ej/g+GyoKXGB+ hFggYJ4orKIAw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/4] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Mon, 9 Sep 2024 09:36:46 +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 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 ftrace hook for mptcp_sched_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loops. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 4 ++ .../selftests/bpf/progs/mptcp_bpf_iter.c | 38 +++++++++++++++++++ 3 files changed, 49 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..3280d4183beb 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,9 +43,13 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_contex= t *subflow) } =20 /* ksym */ +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __= ksym; 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..03168be3980b --- /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 iter =3D 0; +int pid; + +SEC("fentry/mptcp_sched_get_send") +int BPF_PROG(trace_mptcp_sched_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 0; + + bpf_rcu_read_lock(); + bpf_for_each(mptcp_subflow, subflow, msk) { + if (i++ >=3D 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(); + + iter =3D i; + return 0; +} --=20 2.43.0 From nobody Sun Dec 22 06:28:43 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 3F8DA125B9 for ; Mon, 9 Sep 2024 01:37:02 +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=1725845823; cv=none; b=kHSzrgLS/3y0EWQxHPEciYCDkx1jJqPmGWMjaGeKYirXXisOsPGaE9gGy5jzLpeDRQW7rvHlmhH01xQqwUZ517/KKLiTCn62h2/PcVfu/zFvXLcrQCSYMKaLjSCOXQIaN7Z5IWwSQ771USKpqPioVoWT0mZtTjAICAdcJlUfN5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845823; c=relaxed/simple; bh=f3t6MWz0aO+H6ULFGwOIbEMQGgnzS1hHj5xLwgrgTew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5uet/dms0/gYCeBIKWLHyGAZI6PG9c/GuG4F4OFkUVRxyMjOpbBrqXmU17oiu+BcPjzudyt+nvzQi9K0kL+FYhsQaenLLXL+VjZ1dJQjnY+liWSudl2/+O7rsdYc3uLXqG8yVwBfK79JkyIuOmIUXtDvPJ1CmVue/P4vg5oFIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m+aoZxkG; 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="m+aoZxkG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB713C4CEC3; Mon, 9 Sep 2024 01:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725845822; bh=f3t6MWz0aO+H6ULFGwOIbEMQGgnzS1hHj5xLwgrgTew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+aoZxkGS0DT1HCMZ5KnjpS2KogJoCycd3/cm4y+f8jm3pxpM+O1U9NqBI0GJ2sO7 hMQWe26JUDe4m7jziNXdrXOryJENNQT/3qKBT8hbjONWKQnv6V6zjixRJDNSvoptE7 lZfYmKZJ0XloJYK43Bk4dGavH2WGwBcAXl+WyqqCj8H2xdRNQ6bL7cyq1OydbExVsS O/VoFRu9yeI6huRBu3OPTOkoh7C9MeoA1ZjWdQGQDnwrY1Gt8F7vlxuhuVyYe1MeDK kXwHG4StYbZtWXg3kscHy1N8olT/lfEo6PrHRm4YdYedL+maDUSLEm/9tXPR2K2F/I wF898yLIStRDQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/4] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Mon, 9 Sep 2024 09:36:47 +0800 Message-ID: <7a10b2fcb5910bfbd6884421e165b0fc36416b3f.1725845619.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 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. A new helper recv_send() is invoked to trigg= er the ftrace hook for mptcp_sched_get_send() after wait_for_new_subflows(). Check if skel->bss->iter equals 2 to verify whether the ftrace program loops twice as expected. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 93869c873cad..9217566446b1 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" @@ -258,6 +259,34 @@ static void send_byte(int fd) ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); } =20 +static int recv_send(int server_fd) +{ + char buf[1]; + int ret, fd; + ssize_t n; + + fd =3D accept(server_fd, NULL, NULL); + if (!ASSERT_OK_FD(fd, "accept")) + return -1; + + n =3D recv(fd, buf, sizeof(buf), 0); + if (!ASSERT_GT(n, 0, "recv")) { + ret =3D -1; + goto close; + } + + n =3D send(fd, buf, n, 0); + if (!ASSERT_GT(n, 0, "send")) { + ret =3D -1; + goto close; + } + + ret =3D 0; +close: + close(fd); + return ret; +} + static int verify_mptcpify(int server_fd, int client_fd) { struct __mptcp_info info; @@ -470,6 +499,60 @@ 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_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; + + send_byte(client_fd); + wait_for_new_subflows(client_fd); + recv_send(server_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(); + + ASSERT_EQ(skel->bss->iter, 2, "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 +734,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