From nobody Wed Dec 4 08:41: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 25DCA28EF for ; Wed, 9 Oct 2024 09:46:10 +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=1728467170; cv=none; b=iFdzLt43cgyaNBbfmkiA5w+LoeKllwRNITpBQvdAOcdmPrBKn6m2c7/PEfB7ael2yCatRvoipBkNTbgrB30rEOofDYXA/dLcllhGMW9rnxZNKl9ZHZwqJglDa4pT/CsbcD8E6fi7fLjTi3N8QTSzAlIAgJLBAHDgBu0skrxdp+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467170; c=relaxed/simple; bh=74jBSBcHvOpkLfR6IEqnDXq65A8v4eN1I0BZfS1W0/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UhGQ7nV+f2CnuqVm3z0jcZkl+ij/z88/xt6CxTqnCjCjp9+Erlnk9J8XSY+JkRefen8m+x4IUyZUxiPNMMa8sERk5QULh/fvaD7N8pVdJRuLDXDlqcdm0fL4bkBrKMi+cIi96IoZ1O2YFRIngMdYsLqZWeUldJVy8ZAFdKRdgy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m3Nj61Ac; 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="m3Nj61Ac" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C56B3C4CEC5; Wed, 9 Oct 2024 09:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467170; bh=74jBSBcHvOpkLfR6IEqnDXq65A8v4eN1I0BZfS1W0/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3Nj61AceFI2yzBT9VyNgZHLgiYzFbjf2WJC0dFAIuB4wEk/hCzNYNTwIDBVkzBGz 7QEmy592LmWYumldv4HBnjlYpf8igq+sOC8XPFVO6MGnlPEY8/vd+0sf6AavIQWNzu nCXRnZ9X9y620I4S7vmexcijisZudFpE2CbwwipkMk01aWvT7tKR00S39mTJt+AGpT eW4ZkODS/H9NWe4PvmnmiQGwRa4YCnQyRMoQgipBInt1t6nuF/cz1/r0HCh/V2ZapJ nRPsg5Bq3atyelQSNPXxko4V0gVJJjcy0nVlmynp/rvlO4KArE5VGTwX9j6VhTgWLY XSz9ndYBb7cAA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 1/7] bpf: Register mptcp common kfunc set Date: Wed, 9 Oct 2024 17:45:43 +0800 Message-ID: <0eb5e6ed76fd06c2b7638f9c1adf0d72454b770e.1728466623.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 Helpers mptcp_subflow_ctx() and mptcp_subflow_tcp_sock() are useful in MPTCP BPF programs. This patch defines corresponding wrappers of them, and put the wrappers into mptcp common kfunc set and register the set with BPF_PROG_TYPE_UNSPEC. Two other kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() are going to be used in mptcp_subflow bpf_iter selftest, put them into mptcp common kfunc set too. Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- net/mptcp/bpf.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 6414824402e6..71ab1efeed40 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -205,6 +205,18 @@ __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs"); =20 +__bpf_kfunc struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx(const struct sock *sk) +{ + return mptcp_subflow_ctx(sk); +} + +__bpf_kfunc struct sock * +bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) +{ + return mptcp_subflow_tcp_sock(subflow); +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) { @@ -220,10 +232,20 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struc= t sock *sk) =20 __diag_pop(); =20 -BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) +BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) 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_KFUNCS_END(bpf_mptcp_common_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set =3D { + .owner =3D THIS_MODULE, + .set =3D &bpf_mptcp_common_kfunc_ids, +}; + +BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx_by_pos) BTF_ID_FLAGS(func, mptcp_set_timeout) BTF_ID_FLAGS(func, mptcp_wnd_end) BTF_ID_FLAGS(func, tcp_stream_memory_free) @@ -241,6 +263,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_UNSPEC, + &bpf_mptcp_common_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 08:41: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 7347928EF for ; Wed, 9 Oct 2024 09:46: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=1728467172; cv=none; b=cw7ztoyeh6QoQ+useibEn9gGx8gFztUza7Ep2zXU2OGi+0NAdb7duo9eCxuziujARpkrVgG2VLUwXSCnh6bC2FPg+5n9BIPtNfbiaf4Q0Yc71KPyfSLswZ1ElVPy6CJ33AU8VNqydOR+Lp8ORyNNJoBc7K3o7hrX/73IY99Fbfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467172; c=relaxed/simple; bh=im72GA1G2aINreZonOksExvqd1DIV9NNKzp1J7r61yg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LErz8Q+eBL5a6S5wyQGpnwkoI3BjCQCmmMVpM7wbMyyG5WWza/qPOX98uVAtjlgIp5/pfM4H794XKXzdX4MJRXz0kqF6RvcQs4VaTbbT4KHjceE2Rl+9qNMfrb54tPqA4k7y0WiGobDee0T6yyTeil3djPP0cpone0cp/JkPznw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I5lKizju; 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="I5lKizju" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0D25C4CEC5; Wed, 9 Oct 2024 09:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467171; bh=im72GA1G2aINreZonOksExvqd1DIV9NNKzp1J7r61yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5lKizjuJFkcHFO8rzkALlz4HK5dVblyOJs6ZdsB4cs+1OpfeYel+MkqWC+F2BO6J 2Gfq0xjJYlpF20dtqVgchV0jLkAGskldhkDSEap+hp8iBZ0EFr9/nhRIyw5JLCByLF QZ0OLWgHn0f2vKJlpry8BZLpRvwEXiIilavVQ6K5jBAua6DrKHOEauc2v1GblU3qd1 ERQZ+ndzKDtnCa9WbTjCmx2jNBegq1AYyywE8MArH2gJv/FsgEaW8+Owgv/hkB1xVC Ns6naVxCBk/FbOlhvAdhVxVjhPnAFGteUr6Q1cu8xcxV/0EoH9S5tTtp++0uezp71K FrbJFrxiJ2AQQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 2/7] bpf: Add mptcp_subflow bpf_iter Date: Wed, 9 Oct 2024 17:45:44 +0800 Message-ID: <523733b831449ba096084d3d5224d05b4fd5c8bf.1728466623.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 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(). And register these bpf_iter mptcp_subflow into mptcp common kfunc set. Then bpf_for_each() for mptcp_subflow can be used in BPF program like this: bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow); v2: remove msk->pm.lock in _new() and _destroy() (Martin) drop DEFINE_BPF_ITER_FUNC, change opaque[3] to opaque[2] (Andrii) v3: drop bpf_iter__mptcp_subflow v4: if msk is NULL, initialize kit->msk to NULL in _new() and check it in _next() (Andrii) v5: use list_is_last() instead of list_entry_is_head() add KF_ITER_NEW/NEXT/DESTROY flags add msk_owned_by_me in _new() v6: add KF_TRUSTED_ARGS flag (Andrii, Martin) "Suggested-by: Martin KaFai Lau " Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- net/mptcp/bpf.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 71ab1efeed40..fe2ee03ff1ee 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -201,9 +201,16 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret= _set =3D { .set =3D &bpf_mptcp_fmodret_ids, }; =20 -__diag_push(); -__diag_ignore_all("-Wmissing-prototypes", - "kfuncs which will be used in BPF programs"); +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))); + +__bpf_kfunc_start_defs(); =20 __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx(const struct sock *sk) @@ -217,6 +224,37 @@ bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_= context *subflow) return mptcp_subflow_tcp_sock(subflow); } =20 +__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; + if (!msk) + return -EINVAL; + + msk_owned_by_me(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; + + if (!kit->msk || list_is_last(kit->pos, &kit->msk->conn_list)) + return NULL; + + kit->pos =3D kit->pos->next; + return list_entry(kit->pos, struct mptcp_subflow_context, node); +} + +__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) { @@ -230,13 +268,16 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struc= t sock *sk) return tcp_rtx_queue_empty(sk); } =20 -__diag_pop(); +__bpf_kfunc_end_defs(); =20 BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx) BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, mptcp_subflow_active) +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_KFUNCS_END(bpf_mptcp_common_kfunc_ids) =20 static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set =3D { --=20 2.43.0 From nobody Wed Dec 4 08:41: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 D945A28EF for ; Wed, 9 Oct 2024 09:46:13 +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=1728467173; cv=none; b=i0R3Nv4hqo9bIOZ59QGROpdO7As+V7uP8qH0AHBpavs8sjwMdQG8qY/xcogjDQrd1R6kMJGPYIlFUjqaoq0TjaaT+DydRb9LqvKhPKhznhKXJTJiwPboaT4Aih5pj3RIQRgfQQh1tOpOtP6WSavFHs/OEDHVZc+xfY/+rttOa18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467173; c=relaxed/simple; bh=ds9vcLnZuG6PXMN18GiFP755NxYGaiSlT21Y7zWUWSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rZauHBR06KYN6FDp85wemKxNFXo62WbcgpFir+1HlvOje7/WFBkxZdEhPOcEuDJoWd+0mRyM3k1KUfvy4eUh3/7Vtp3TZQdMnKLa7jkTP0mbQMIsk9sJRL7EyzQ64tjvWDw8Z2jgPvAd1YR10igMwJZycJ8rWQmlKYhkJLnBgSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p6Pd8Xwq; 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="p6Pd8Xwq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 798BAC4CECE; Wed, 9 Oct 2024 09:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467173; bh=ds9vcLnZuG6PXMN18GiFP755NxYGaiSlT21Y7zWUWSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p6Pd8XwqApZr3GYBvx121fRJg0XbHl687rdSTMwiRNcoesSoAwzndcKNfRx/tKARQ 5FodB8gmkBVXobc9vEo7J6JxlOeRU2ykwrJfmywDZJrkke/4b7SBb1+3ULJSC4NHOW 6n7iBsbwPwt26mTJnrEozeS0yZvEN14RZyMuJ5G4HYkOssuo+5+XtNrqwnD34DxHv3 rJGrNVffNEKvv5pOVNc0xxaksFzJbO15gt0pZR+okf8jevwRRu54Okm1EVobe1BG09 VRDTMSq762Ay4YHiCewBrqt9H3rT2n/5Y+mt5MAbtQNsW4M7UriB+Zxklq2KSO3+eX jOCU+oJIljvzg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 3/7] bpf: Add mptcp_sock acquire and release helpers Date: Wed, 9 Oct 2024 17:45:45 +0800 Message-ID: <193b59575ea5f422ab83cdd64adc40b3b2963230.1728466623.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 KF_TRUSTED_ARGS flag is used for bpf_iter_mptcp_subflow_new, it indicates that the all pointer arguments are valid. It's necessary to add a KF_ACQUIRE helper to get valid "msk". This patch adds bpf_mptcp_sock_acquire() and bpf_mptcp_sock_release() helpers for this. Increase sk->sk_refcnt in _acquire() and decrease it in _release(). Register them with KF_ACQUIRE flag and KF_RELEASE flag. Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- net/mptcp/bpf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index fe2ee03ff1ee..9b87eee13955 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -255,6 +255,22 @@ __bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct= bpf_iter_mptcp_subflow *i { } =20 +__bpf_kfunc struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *m= sk) +{ + struct sock *sk =3D (struct sock *)msk; + + if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) + return msk; + return NULL; +} + +__bpf_kfunc void bpf_mptcp_sock_release(struct mptcp_sock *msk) +{ + struct sock *sk =3D (struct sock *)msk; + + WARN_ON_ONCE(!sk || !refcount_dec_not_one(&sk->sk_refcnt)); +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) { @@ -278,6 +294,8 @@ BTF_ID_FLAGS(func, mptcp_subflow_active) 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_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 static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set =3D { --=20 2.43.0 From nobody Wed Dec 4 08:41: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 B74FC28EF for ; Wed, 9 Oct 2024 09:46:15 +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=1728467175; cv=none; b=HFGeUybiFhd0/T+gFNMPne671KUGqhCw4Nhh23zfYLAL6aKWyPaQaGzuSFQ827tuMPvFns2w2e6hqUfWybhzoJ2nzJiLIo7Farf7iFLK6S1fUVAFNRudmaVMI/dayyEqrUjK0prHiVskIhCG8/Q9My0A/I7nwzbKJTaNh2PN798= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467175; c=relaxed/simple; bh=55BhygoHSnTYYfomdFgaqo3ZmgCtTbwjGCXei+paJwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ENpWVKUG4pChF9XCbshjglRbkdq/n6zTZWJUU8Opd9vMMXyE7TBjHWh12KvCr+XDkYATTk36H7tl0ilkFgDEXSpmasRXHNAXxCkVOqW0Mfed7Tw5xE5laXxymjzed/weO4pWyp7vr+8N36tWt/lMOrl0v32iS3tNI+qAA02X4PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QVWGObKc; 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="QVWGObKc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20ACCC4CEC5; Wed, 9 Oct 2024 09:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467175; bh=55BhygoHSnTYYfomdFgaqo3ZmgCtTbwjGCXei+paJwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QVWGObKc+ee0QJ1lDcFHHtunMG3W3g10c1SuKdVymJpWX9AF4dmLafLTZGjiOcLNO yIFYlEutxmB2QGc26nj5I/DHpcq9GHYbL/WcTWdcU3ZzdKrYDKkgYLsspFyHr9UUEt LV3qTDa46MH585vC3TFnJ6/jA5g8QhI/TIV4WsUUk1VixGIIRGPaSsW8Nn9Kt17oX6 9EcBtoG1UQSpKxrQ7bRLcCHVfJJ9LM986lg5s4QptxIvlwdQagSQ673pO6y1yy/uQ5 ZcuLGJxKLiLFEWbEmNWro4S4lR156401SxCb369qi12POnFxzYzfJuWuzPasrqRnuM KVueivwnKTEQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 4/7] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Wed, 9 Oct 2024 17:45: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 ftrace hook for mptcp_sched_get_send() to test the newly added mptcp_subflow bpf_iter. This test simulates a typical mptcp packet scheduler, which selects a subflow from multiple subflows of an mptcp socket to send data. Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy, bpf_mptcp_sock_acquire/_release and other helpers into bpf_experimental.h. Use _acquire() to acquire the msk, then use bpf_for_each(mptcp_subflow) to walk the subflow list of this msk. Invoke kfuncs mptcp_subflow_active() and bpf_mptcp_subflow_tcp_sock() in the loop to pick a subsocket. Finally use bpf_mptcp_subflow_ctx() to get the subflow context of this subsocket and use mptcp_subflow_set_scheduled() to set it as being scheduled. Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 9 ++++ .../bpf/progs/mptcp_bpf_iters_subflow.c | 42 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iters_subfl= ow.c diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index b0668f29f7b3..d43690b17468 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -575,6 +575,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 c3800f986ae1..e18796361394 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,9 +43,18 @@ 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 struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) _= _ksym; +extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym; + +extern struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym; +extern struct sock * +bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) __= 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_iters_subflow.c b/= tools/testing/selftests/bpf/progs/mptcp_bpf_iters_subflow.c new file mode 100644 index 000000000000..4268e4604c5a --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters_subflow.c @@ -0,0 +1,42 @@ +// 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 subflows; +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; + struct sock *ssk =3D NULL; + + if (bpf_get_current_pid_tgid() >> 32 !=3D pid) + return 0; + + msk =3D bpf_mptcp_sock_acquire(msk); + if (!msk) + return 0; + bpf_for_each(mptcp_subflow, subflow, msk) { + if (subflow->token !=3D msk->token) + break; + + if (!mptcp_subflow_active(subflow)) + continue; + + ssk =3D bpf_mptcp_subflow_tcp_sock(subflow); + } + bpf_mptcp_sock_release(msk); + + if (!ssk) + return 0; + subflow =3D bpf_mptcp_subflow_ctx(ssk); + mptcp_subflow_set_scheduled(subflow, true); + subflows =3D subflow->subflow_id; + + return 0; +} --=20 2.43.0 From nobody Wed Dec 4 08:41: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 1A97428EF for ; Wed, 9 Oct 2024 09:46:17 +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=1728467177; cv=none; b=J1+3zBKs+B+ezg10CVVQoxnvXcyBdklK0AAaZJF9zAp6Z6EsuOztv9KGYZ3n6c7XN78fJIs83xcXvrAc4XerNGPP2L20CQxC5Rj2PYw1mGV6/hQjYO62SHUED711EDnIKkAgdaHdmARzW9ViIgoBfYyug6HBiVXkTJwF5N/r7cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467177; c=relaxed/simple; bh=Rrwmr/UzblTRnxYyE1VfmSxemd4f/+6ILdhvnsszKtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Phv/uPqDlHwKvLus4dlcSPj//uj4Ug2D7uF1FCDJGgKW6Y0rL7pEEXX6jic/JE1keKX7JTB2iwTTIFC/Vcma4WO9b92JBBoYWhG+f5Tlc0o8947NP+Fzez/uov5Ggyr+zIqfH3Gzv7YIk7c966Ac7vckGlcf6pXchPbkXvrl7+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s+8bV8GN; 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="s+8bV8GN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0C83C4CECE; Wed, 9 Oct 2024 09:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467177; bh=Rrwmr/UzblTRnxYyE1VfmSxemd4f/+6ILdhvnsszKtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+8bV8GNDURzAUI4XVM6enu/1CYEEYykKFna0IrCsFKnuAS8O6pVswRyiFLt6MX+0 zdP2yGSGV6u8bM9Azdhw64SY+Bq5bdTQpX5q08sil8q0c+h4yIh7wYysafitLu79F0 TC6CMeyAQ7gwbnaSkCm/T2xPDSFTaMYkgBXnjH9w3WhT2bu9nRrq/q63osF+oSjHlR SUeJREy0NlghLx85Z2BSQ/FxqQ2XZlWmif1AW5cQEG3c02UTyOrOn01DBXBsZ9FgJ6 1reOuHIDZ03xkcSWh1iyjwER3ga7y/xLGVQaYE8QS9JWyGwgF7JyHAg6u8Wn34wILT MGYmOUpRfA4iw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 5/7] selftests/bpf: More endpoints for endpoint_init Date: Wed, 9 Oct 2024 17:45:47 +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 two more test addresses ADDR_3 and ADDR_4, and adds a new helper address_init() to initialize all these addresses. Add a new parameter "endpoints" for endpoint_init() to control how many endpoints are used for the tests. This makes it more flexible. Update the parameters of endpoint_init() in test_subflow(). Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- .../testing/selftests/bpf/prog_tests/mptcp.c | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index acd79be134cd..076903680e75 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -20,6 +20,8 @@ #define NS_TEST "mptcp_ns" #define ADDR_1 "10.0.1.1" #define ADDR_2 "10.0.1.2" +#define ADDR_3 "10.0.1.3" +#define ADDR_4 "10.0.1.4" #define PORT_1 10001 #define WITH_DATA true #define WITHOUT_DATA false @@ -351,22 +353,56 @@ static void test_mptcpify(void) close(cgroup_fd); } =20 -static int endpoint_init(char *flags) +static int address_init(void) { SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST); SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1); SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST); SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2); SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST); - if (SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, fl= ags)) { + + SYS(fail, "ip -net %s link add veth3 type veth peer name veth4", NS_TEST); + SYS(fail, "ip -net %s addr add %s/24 dev veth3", NS_TEST, ADDR_3); + SYS(fail, "ip -net %s link set dev veth3 up", NS_TEST); + SYS(fail, "ip -net %s addr add %s/24 dev veth4", NS_TEST, ADDR_4); + SYS(fail, "ip -net %s link set dev veth4 up", NS_TEST); + + return 0; +fail: + return -1; +} + +static int endpoint_add(char *addr, char *flags) +{ + return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, addr, f= lags); +} + +static int endpoint_init(char *flags, u8 endpoints) +{ + int ret =3D -1; + + if (!endpoints || endpoints > 4) + goto fail; + + if (address_init()) + goto fail; + + 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; } =20 - return 0; + if (endpoints > 1) + ret =3D endpoint_add(ADDR_2, flags); + if (endpoints > 2) + ret =3D ret ?: endpoint_add(ADDR_3, flags); + if (endpoints > 3) + ret =3D ret ?: endpoint_add(ADDR_4, flags); + fail: - return -1; + return ret; } =20 static void wait_for_new_subflows(int fd) @@ -452,7 +488,7 @@ static void test_subflow(void) if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow")) goto skel_destroy; =20 - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto close_netns; =20 run_subflow(); --=20 2.43.0 From nobody Wed Dec 4 08:41: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 AD53728EF for ; Wed, 9 Oct 2024 09:46: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=1728467178; cv=none; b=u0sjKCPXOz910cSoVzu/zzQXkkf/TWfOiToZXzVzDJSgDt78dtJgM2zx/fm7OLPZ+qsDQ1J3pWGKsQEzUxK1Uydz7HmuVOHTFWMkjh8vMgL/TU8v5ryjwZUOC421KFI4EomVmuxPhZxuBaKNQR3332dlou3+coGxjYJg0QOl/Ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467178; c=relaxed/simple; bh=gOqNsUvZEZDjK8CsDu5DMyfFN8Ko6EcnpPEPr+AKob8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pihWgqynJjezibzLKalfIXpsn6sVKyXbbzn0wUatC23EawAtk7Ncr5MM69EzqQgbXgOBiks4OrB2zmO45zLYfpLYW207uG+ofv+Ujz/UrI2KdwK8T1abGb1lwsA9RVpjaz/uhmbNkodNGFRuQYNiwQPt5qLvp3X5KWcCaUgvESM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NX4OPfYA; 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="NX4OPfYA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 967FFC4CECE; Wed, 9 Oct 2024 09:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467178; bh=gOqNsUvZEZDjK8CsDu5DMyfFN8Ko6EcnpPEPr+AKob8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NX4OPfYARJX8TaDCXPb+ltDXDW6dcBMjd3p5af/qjYE5EBnNMrZkYi3YqnzDDTTVa j1RB+IZofY7rGi8MEcDJ/o1HHSxLdc1IqJWITgPq3hngJ8O/vWw5oPerCsOkc7mP0C RqySY9VH71FOBvhHLTx/GOa3CsR9fnhKjjnta/byuVNpjaoopRSdt0n35khBSWaV1O EIF+Rfrb80uhlU96X5LKU4xiaf7cc6inBR86xjJXIycwj9JggkJA6HeQntkVvFc5XL pqu7xgReVi66z08ycsmvDSjWa1X22dzS1F/0KKputXnAiXiumPSp7V7IGiq2jOlf6g ezFaTWgcx3zIg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 6/7] Squash to "selftests/bpf: Add bpf scheduler test" Date: Wed, 9 Oct 2024 17:45:48 +0800 Message-ID: <2d6c372fb199a5ae585c16d9fffae6be7c6ade61.1728466623.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 Update endpoint_init() in sched_init(). Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 076903680e75..64b5ce25e1a1 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -509,7 +509,7 @@ static struct nstoken *sched_init(char *flags, char *sc= hed) if (!ASSERT_OK_PTR(nstoken, "create_netns")) return NULL; =20 - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto fail; =20 SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=3D%s", NS_TEST= , sched); --=20 2.43.0 From nobody Wed Dec 4 08:41: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 4F19928EF for ; Wed, 9 Oct 2024 09:46:20 +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=1728467180; cv=none; b=Sej1PtaZ/sWj3Aj1zeG+YwfhF3YW5n+9xHzU+EbHRqAwqzD874PbzgTbPR5JVhQ5vKPuJW3CCRClrAGQnZ6Vs7g3xixoQT00Ng2eYAmF6kgXvcUSaI1g4Di4NkOClw87wAEIMAvpuJvj4HxrFkfaNCl/DxRAbuU8k6fBNrd+P2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728467180; c=relaxed/simple; bh=oumnZN7lfeBZipt/q7v7JY9vEXkhK5S+dRHfm39SAWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RJ2bUp8LCfy5U39Xs/iJiS+xToM9Fqc/QWuFTBWQVg8mQWP4xW88cRr7GmQMTpQen6qXm1HE2Z08YfyHb5or/MUU8XSp3O7+DmCckSNv3xks87sxyeEBYYfI8cZXk8Y0j5aXR2Z11VgE9OKm0t3SFzCOAx0QhfxjugmiwBgTPUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PzuKt8d6; 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="PzuKt8d6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2564DC4CECF; Wed, 9 Oct 2024 09:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728467180; bh=oumnZN7lfeBZipt/q7v7JY9vEXkhK5S+dRHfm39SAWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzuKt8d6P+GzuDXkrZiA0jEI6QjY1UzAn42P5ZD08aMJZi4Qconwh2T5KzZujrwQy yZd3FfjrTyvjH/NvPuPfW5eCpiA+RIU+D2JeR331/EUYJGeFtYN1H13yyKrsHSWmsY Ti683E5J+s5dPwdU6IiK9GraaxS8ZIBuIcWde0m/25j/kGpetxEVibxJCJLhuWshHX iJSZmoPrQ9UkVZz6ELfQ/PGuDOa4iNM6cJBDTluqlDGRCTVP19mV5cwk9La2BTvKex 5xLbu9VzclVZbqjZ2HnqzpLmUqfxMkOD22ciyb/EUF4JH9lrmpq2z6YxWC4kpN9SaO bf5u1IFOah3qA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 7/7] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Wed, 9 Oct 2024 17:45:49 +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_iters_subflow to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. Use the helper endpoint_init() to add 3 new subflow endpoints. Send a byte of message to start the mptcp connection, a new helper recv_byte() is added to receive this message. send_byte() is invoked again to trigger the ftrace hook for mptcp_sched_get_send() after wait_for_new_subflows(). Check if skel->bss->subflows equals 4 to verify whether the "fentry" program loops fourth as expected. Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau --- .../testing/selftests/bpf/prog_tests/mptcp.c | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 64b5ce25e1a1..589420f42845 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -11,6 +11,7 @@ #include "mptcp_sock.skel.h" #include "mptcpify.skel.h" #include "mptcp_subflow.skel.h" +#include "mptcp_bpf_iters_subflow.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" @@ -261,6 +262,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; @@ -501,6 +515,68 @@ static void test_subflow(void) close(cgroup_fd); } =20 +static void run_iters_subflow(void) +{ + int server_fd, client_fd, accept_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; + + accept_fd =3D accept(server_fd, NULL, NULL); + if (!ASSERT_OK_FD(accept_fd, "accept")) + goto close_client; + + send_byte(client_fd); + wait_for_new_subflows(client_fd); + recv_byte(accept_fd); + send_byte(client_fd); + + close(accept_fd); +close_client: + close(client_fd); +close_server: + close(server_fd); +} + +static void test_iters_subflow(void) +{ + struct mptcp_bpf_iters_subflow *skel; + struct nstoken *nstoken; + int subflows =3D 4; + int err; + + skel =3D mptcp_bpf_iters_subflow__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_subflow")) + return; + + skel->bss->pid =3D getpid(); + + err =3D mptcp_bpf_iters_subflow__attach(skel); + if (!ASSERT_OK(err, "skel_attach: iters_subflow")) + goto skel_destroy; + + nstoken =3D create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns: iters_subflow")) + goto skel_destroy; + + if (endpoint_init("subflow", subflows) < 0) + goto close_netns; + + run_iters_subflow(); + + ASSERT_EQ(skel->bss->subflows, subflows, "subflows"); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iters_subflow__destroy(skel); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -682,6 +758,8 @@ void test_mptcp(void) test_mptcpify(); if (test__start_subtest("subflow")) test_subflow(); + if (test__start_subtest("iters_subflow")) + test_iters_subflow(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) --=20 2.43.0