From nobody Sun Dec 22 01:41:07 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 98777CA62 for ; Tue, 1 Oct 2024 06:47:23 +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=1727765243; cv=none; b=riwBL7eySyCEFp/J/TvAA3zjVFySJI9fk6PkVuNmmBCO1k6CgAJ7T49qTmCNg+jn6RkOmlTxlPC8AoOqcr6IBOw0H6G5fNg0I3uKFmQK52mBZr5Xjy6kArbcKUkWDKaCheHR45zyIdCRRNPbkVUMMN3Wn3h/icXsAEQZMIo7d/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765243; c=relaxed/simple; bh=kQqAiddCeIlBAqXA4dHyUYa56F4hufNbrB/31+DwG+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YMjjndaZwrbWOrDU164nci7fvh4dRnWIwkJCR1oIcOPbsH9Eum/yVT64nbkGJf4vvOav7gJVmTohF8hzgHwnlBA25nrkD2VOIJJtN3lGSVI6rpZ+3Lz5sbv8dV++LQZ75Bi/06UhLC6rPXv+YMoSclc9ey5wGKtay7rg1w5Juqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n7Wh6u61; 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="n7Wh6u61" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C737C4CEC7; Tue, 1 Oct 2024 06:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765243; bh=kQqAiddCeIlBAqXA4dHyUYa56F4hufNbrB/31+DwG+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n7Wh6u61HCNABuldudGPCcA4MxbEEjulvXCH/r0bfKSz7wl+fS7XIVuB9jQGDkaUp lr+vINnQeIerNmJl3DdDaOjmGuxwXfSlihsNj6kzMZpLex9gMk3IRbacsKayopnPtP 72WGyBwd7n+jxaumORyXwc7VkcNrv8YvPvGCu7Tk7ru3ITTTpfLq5G28RmHy9kux1Q pX7dteoLkS6EzrjD1eIGQYBFF8v5nJ2q26kWSkP+BlvTSI7pjVCo7yALgncPpDA31w xYeueHTKUydL2xFhnuwkxzguEsqwPOIniH/C5pkScIGa5gi+DUvyEt/dQWwdjKSn6o L+DYVbfSayLSg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 1/7] bpf: Register mptcp common kfunc set Date: Tue, 1 Oct 2024 14:47:08 +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 The mptcp kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() are going to be used in BPF selftests, so put them into mptcp common kfunc set and register it with BPF_PROG_TYPE_UNSPEC. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 6414824402e6..41937fde0bb6 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -220,10 +220,18 @@ __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, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) +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_subflow_active) BTF_ID_FLAGS(func, mptcp_set_timeout) BTF_ID_FLAGS(func, mptcp_wnd_end) BTF_ID_FLAGS(func, tcp_stream_memory_free) @@ -241,6 +249,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 Sun Dec 22 01:41:07 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 CAB7F63D for ; Tue, 1 Oct 2024 06:47:24 +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=1727765244; cv=none; b=lRyRySakapoJhetXzYRwr0gIMDnM0V5TJhRkoA/cymM7fuNvuhcHNXLS67+qpcmP6zj2hlJp34hL51oHJE06mtlmZDsv4hUw21NNDg09Jbptt+SbypBW5eBVi+jcdplKF28XNXJ1kbUR+blC97Z84asBl8LtrbdLGwr9rrMZ2Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765244; c=relaxed/simple; bh=SqdeLx/SVaZrkXGfF35ZGQGwZuMB9O93z5c1QWXFlJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fF+lSeto2HkD7bKwzEKusc3nKmUjl0b80Pc++R6XpdvdYjEMvbYsNIx4fmJpb58HSAoeuehuUAXwRUXwuqH12QKKzNzLDgoCxAhG+JJzgfzeiJxq+QFknufNJEL3GxkNu0DIZ3+i8x+j92yppbPOvchm8SzmicqTYDc31Mlplvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xr08iR42; 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="Xr08iR42" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 844A0C4CEC6; Tue, 1 Oct 2024 06:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765244; bh=SqdeLx/SVaZrkXGfF35ZGQGwZuMB9O93z5c1QWXFlJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xr08iR42Pf/TLx21uTt/W6+fbs5Yk4Q0GSSc7K1H2u2k/+EINGF3E3dbFRD9pacGY YWyL8Uw7g+4VtvPDu4mKOhTLsuKIVlqRfNNV1t+ytiBstBSiugsQEkO8ugM0znsFUw lgFKMvOzzfn6oemwz1UZhurFZz79Lb6YRdy1vHetI1kEjKjtwiw57Gr31v6xO+Un57 ujIJeuuv/E8+0mdHB2Ps5WclHZL4SbGTBBQm0tJ5P6e/SnzuAXqYtJuEABmJ49OZ2/ gDWOuFm3N3c3i8h4Tp83fuDIBmSsRXRWQVISo+1JRWRgQgZBWxP+4JJIPOrjRhlNgb LA3yahnywT5NQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 2/7] bpf: Add mptcp_subflow bpf_iter Date: Tue, 1 Oct 2024 14:47: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. 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 --- 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 41937fde0bb6..31bb2a869d34 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -201,9 +201,47 @@ 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(); + +__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) +{ +} =20 __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) @@ -218,11 +256,14 @@ __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, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) +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 Sun Dec 22 01:41:07 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 B1F5363D for ; Tue, 1 Oct 2024 06:47:25 +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=1727765245; cv=none; b=pGsF3uyRp1XWVqAKhOKninksyhvDxOBKb+nnA/l6ZKMVwIbUdoPn6HMja4/jzvAAsP4UNeXrpoM1JiZjqcr9mEXY/w6TFv8hpa6/4ijN2reSJjm8mjYCAI7QBtSc2B1m9Dbz4jMBl/2x1ZqWSpWoHgwz0YE41HTlh3CpSeJcdg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765245; c=relaxed/simple; bh=LtVt7ehTTBhyv9n7P3sh6p5RBizQeQ+VwmhO2uH/qRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LCuckpbz8lJZV0alJVhhXOy+QQbgJ7IEdMaBGCJU/fxqZfiAG+zGH7V2XWbHehOHJBnJw1N/32K6vwW9g0SASYaRoR9GwDg8VGjJ47dY6JBVYi309BC9a+lH5xSMEi29YMz5TcqQZqEdCDTZapdsQu1N+uXi/qDATkZfrqDjFSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V7fccBbB; 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="V7fccBbB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD4C2C4CEC7; Tue, 1 Oct 2024 06:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765245; bh=LtVt7ehTTBhyv9n7P3sh6p5RBizQeQ+VwmhO2uH/qRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V7fccBbBLUmpQ9XVEd6e4zRM7YzgWfS5cM/9XZVYIJEsmpjybRk99vdkEiISqVIG1 CHO/bGscdH+5K78w6iJgxzDrabliGuUKmo36NMD+kf9NLBoXoa+59Hj54NVdSySxiN ngCDzadbIEzn8jN7dfPECQjSiCPi+hOYXQpnPG53eeLylyjdPuG/TCTBMiXoLRni+Y HYAO4Cka4YyVtTNIk8UZ+F3nTwhv/01brIyRHR7N/ELf2CvIezzrqjieox9Nq7UPHw zVNBazc+eDZ1PyfG8dx7eBpijWXmvxLu8IZJmK8K1vN2pMF0XI8e8MZo76mo9ATWKc bX96VcKAxMaww== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 3/7] bpf: Add mptcp_sock acquire and release helpers Date: Tue, 1 Oct 2024 14:47:10 +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 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 --- net/mptcp/bpf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 31bb2a869d34..f5700dbe2024 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -243,6 +243,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) { @@ -264,6 +280,8 @@ BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) 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 Sun Dec 22 01:41:07 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 E0F5B63D for ; Tue, 1 Oct 2024 06:47:26 +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=1727765247; cv=none; b=VKFdh7We2yxapZd063ZLQzWJMD4vHv7EPNO6dS2WSHWNo64J0IzhNQaWrxe3DVGgD+06ALNeiKj2nSKlpnemLH3rYYx7opOCQh4PSDyvBrpAeE40PffXQqTJqNh6H3TR+FhivBbAlEkIaPFwl0IsXlIvdo/z6SEL34c92O1FlkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765247; c=relaxed/simple; bh=Q1Wx5JxP3AzULZ9dHq2Uun+kE+KkuUSuOgO/0ToF2w0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i5+rSfUB/ekz8oazMhSFoJZehmZdRdihtenL08QlyxoWsfEcb/8/UD/KfS8uqlf4fQgb9dUHJDuR9SfmbH6Sc9HgyIfC7vAZ7WbNeXTSN9ilk3kUG9+15dr/RzH3JS21llCHFr3SCNmr5oqVMLgMs0woW8mrkHKURRreYmDfSeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ShdVo5Wy; 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="ShdVo5Wy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3EC8C4AF0B; Tue, 1 Oct 2024 06:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765246; bh=Q1Wx5JxP3AzULZ9dHq2Uun+kE+KkuUSuOgO/0ToF2w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ShdVo5WyirgN3Y3P0aO56g8dhWMwoyLJNwUiw0JnFIm40+ezMVIJ6RgsTqNrcrJZ0 jgOZU9EDgn0HeZ5KdXMGIY1jp93Trrn5a8m/qlW+W3MowvSfhyiqbcKkLW/L+d9s3Q 2YIwixCEgTGAL9EI8YpTUjpkkj2G2l8Tu+tl7an5m0lcmJHORhCfhtC6nRtbi+yJ9R WHVKNaOdbpE3sZsanFJtT/tDSdfdDW1d+s7tGc0CtnouqLtbL0JlBLiseeNSQ386ab EaQlmqfXqj29iEMMrVJkHDrqv8i7+SOSBDhQIdyKrXEFdCtn//P2wDpJKhwwgtFDtv 1vt/poAC1BwZA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 4/7] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Tue, 1 Oct 2024 14:47:11 +0800 Message-ID: <507c23f6f7fb09363d9665d2241430150b78fa05.1727764822.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 ftrace hook for mptcp_sched_get_send() to test the newly added mptcp_subflow bpf_iter. Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy and bpf_mptcp_sock_acquire/_release into bpf_experimental.h, then use bpf_for_each(mptcp_subflow, subflow, msk) to walk the mptcp subflow list. 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 | 4 ++ .../selftests/bpf/progs/mptcp_bpf_iter.c | 39 +++++++++++++++++++ 3 files changed, 50 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 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..0d84b206764b 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 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_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..57ee738d27c1 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c @@ -0,0 +1,39 @@ +// 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; + + if (bpf_get_current_pid_tgid() >> 32 !=3D pid) + return 0; + + msk =3D bpf_mptcp_sock_acquire(msk); + if (!msk) + return 0; + + subflows =3D 0; + + bpf_for_each(mptcp_subflow, subflow, msk) { + if (subflow->token !=3D msk->token) + break; + + if (!mptcp_subflow_active(subflow)) + continue; + + mptcp_subflow_set_scheduled(subflow, false); + subflows++; + } + bpf_mptcp_sock_release(msk); + + return 0; +} --=20 2.43.0 From nobody Sun Dec 22 01:41:07 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 2BEE529CFE for ; Tue, 1 Oct 2024 06:47:28 +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=1727765248; cv=none; b=DIXkzI+IePn+kd1DWulydTzkwlsdJB35YOxWzkbFsK7uoHFl5dS3Ne4x8BCdgJMa5iMvpZKo4oOyajGmW5NoJINH2BZKxV7L7FBtaEHYhnMS9ZbL1e/4DVwENZMlhQu2UYIBZs/NN+vN76ZGbnAklppI49pDbCGRHvyDGGOK6+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765248; c=relaxed/simple; bh=PqhL1+HJ5QSdK+L/sMvyJR56R2rzBeswxSui00kjs7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eu4Zvfs4YbkUEz9xaCLFksD4wFRwExdWbDqrFijZvGSStP3GPsJetyLwUDqo5MQsT/MntcdQnYWggIhs1JY4D5xJzPDE5q7xA8F1Ms5mPBB6AyKI1VW3wuZTUsxkOojppyjdjACsqTLCwb0RxxqHANU2n+h3XzHpzAhA/rkDz5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XYXuoCrG; 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="XYXuoCrG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37B46C4CEC6; Tue, 1 Oct 2024 06:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765248; bh=PqhL1+HJ5QSdK+L/sMvyJR56R2rzBeswxSui00kjs7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYXuoCrG1+4j+OCTcFU49nnLav+WO9Ag0kncR8/NIqy6Pk9DtYC85Ur9Si46aMgQM x1FdIRHgZlkQvJzW+GumCYDySHtChd67f9Dcnkj3Smh8RKSCEmHEG/ggRunre9MNve Ezy012xsupYD+sO2mgrrLVLzxRaDQjhhrLE4SsaGwUHO7XiAspTdQcGOqgUDwS4Dm7 yZuvPS6qWXH0bmnimwzcxSEBPx/9wQya4graxzncfVO6U2umaEOrzXukbC+QO/gYPi C6ftERi3jkkcesFomWTgjTBb/ZYdvgnCbiBQPgZoWliJiwzpqv35ketfFMyDiGPJBw lZnt8sR2EQkfA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 5/7] selftests/bpf: More endpoints for endpoint_init Date: Tue, 1 Oct 2024 14:47:12 +0800 Message-ID: <5b84c40407eded05011495d2a61e6373f15b2ed3.1727764822.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 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 --- .../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 Sun Dec 22 01:41:07 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 BF09A29CFE for ; Tue, 1 Oct 2024 06:47:29 +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=1727765249; cv=none; b=BOytjGY22H+uYHK+OqPcZmXia2kPLiyP6RcFKH6QfMOErARgSY9146QqpGdhTNrZZyd/JcCDmR4omePO36vO/yLUjbvRoD47IzDeTIfT5Ft7MIYkvTS9QJb0EKOO3V/adU9+pncS62AjPTamADy0oHKJLln9E55DyRD2IYS628o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765249; c=relaxed/simple; bh=gOqNsUvZEZDjK8CsDu5DMyfFN8Ko6EcnpPEPr+AKob8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rwvat9SVtaXn/MfatuzEXitszWzjabNJOuGtB+B0V7g2lP0NQ7UfCSyEuqIXqrKAZS5IyFJJ+1fNoztEXyL/gcWPzKSSUrVRkxKzYpUSYmdT5v/OqmBcqx1ZLVeNwixVEANcBNj41nPr9EioS7vC1vAxlRmRWqU61LGwED+Uqc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bxaATj8m; 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="bxaATj8m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 889ECC4CEC6; Tue, 1 Oct 2024 06:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765249; bh=gOqNsUvZEZDjK8CsDu5DMyfFN8Ko6EcnpPEPr+AKob8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bxaATj8mi4tY2d+y2cH6olUDasEs2rwwca9XJvc4iQA5qTS5lOK5lw8Pj7kdRBzfE WJNjWUd29M3YsKsh/BVRhrsz/+VCWCOPM++mMBVzeDNnXmIdNaYaq0AZlWIziq/JiQ sygdMp3g/hYwEH8mK0rh3kcFOStqjWsIdD6/74x8hG4T7GWy/Q0Ffb6PJieCguQuLj l4kZ6Kllgm3ye+r9hS0tZu/tbhO2QXqH+iVEBu3a/RWrx1QcC7kpebu0SevVBCGpuz U+SWllXT2c2zhUq42VmoDe4gw6ZVN/31qGOSpYM36Hb/kVyduPW98pHFR2ljTGIBtS I0aKjzJyMVaNg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 6/7] Squash to "selftests/bpf: Add bpf scheduler test" Date: Tue, 1 Oct 2024 14:47:13 +0800 Message-ID: <9798b96d3e8c003e655bc1ce353ed80adf731a2d.1727764822.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 --- 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 Sun Dec 22 01:41:07 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 1DF7D1BC9F4 for ; Tue, 1 Oct 2024 06:47:30 +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=1727765251; cv=none; b=NBt5W//DyuZYzWdgjGL/jbT7gof/t5wRT9/wikolZVlgpjA5j1sriFyLzx/+CpK9Qcx3rMoyHNCsXEgT8/ZxhykjEezXk9EEPGj5zkRB+Wqftgnv4n5RdiDj/cFTb4oqQj3HiqM3USCqcienhUasnFdD93v02hS0f+fZzkFTBzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727765251; c=relaxed/simple; bh=AFbkfTXQEhD8dHj3RRFAxacukbj8ZyyDHGS+UDqVU3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bGshYfD1gWiSDzkMYmflamFDA8ZVsxndY0UDv9OibSHLKxTAziupv92y6SKfUrQWM5QoRGTEgb7IGCW0UEHgNlfa6NTgHoPi8Kt74ubBonaRhXY229yQlXF+vJcO4VtSlaU+TkayO+BOfo77AyGQafXhiyurm/LmNh6r6UzBHzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eQjCWi2b; 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="eQjCWi2b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAC4DC4CEC7; Tue, 1 Oct 2024 06:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727765250; bh=AFbkfTXQEhD8dHj3RRFAxacukbj8ZyyDHGS+UDqVU3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQjCWi2bt/1Cl+F+IDBnSYA21sG87zyFOc0Mb6wc2SZ10rbwFD0oEzuBEpFDBQ3yt Fm26JIvd2TDgzy6Ezpel1Dff+WrNelRu614Zqe5UE6IfuOVHzH0tG0RNJ1JThA8AgS 435y1S+iIq8GHSMw/fwh55T/q7lRCp1R5Zq+sHjlrF1idhH4zFJEtGlyg3ARKQqVj+ wA3kSLXca8wYTl59vItSRdRwPIu9nSQk+UTF83hKQ2b1dCtGoEHstYQVm799cPkI5D l9islkBB8ZIziddLommKfSZ6k0boqB4Rzjrdig39bFZoZeAkx5C4I3Oc7qNlmB6nFw OyvzRPgbvQGaA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 7/7] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Tue, 1 Oct 2024 14:47:14 +0800 Message-ID: <62b3642ebeafcc4736af1034fe2fa4d28606307a.1727764822.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 the helper endpoint_init() to add 3 new subflow endpoints. A new helper recv_byte() is invoked 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 --- .../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..233da5317e47 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_iter.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_bpf_iter(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_bpf_iter(void) +{ + struct mptcp_bpf_iter *skel; + struct nstoken *nstoken; + int subflows =3D 4; + 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", subflows) < 0) + goto close_netns; + + run_bpf_iter(); + + ASSERT_EQ(skel->bss->subflows, subflows, "subflows"); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iter__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("bpf_iter")) + test_bpf_iter(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) --=20 2.43.0