From patchwork Wed Oct 16 07:33:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837825 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 C81F91B3F3D for ; Wed, 16 Oct 2024 07:33: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=1729064005; cv=none; b=nkK1YpXEhXXbXaWM32NO4sl9rYjXKfLjqT2u28V83j1sL3XZrbn2IpXIKSh3EhvGrz/3Oaw65khxaLOj701rXJ/fEI0bZ2hEj/QTDsifg4n0AHmIUtyk8AXB30j4JSyspnc6bX9Q4dl8Jp2MjWyTrsVwZWo7C4uyVW1wq/+sLJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064005; c=relaxed/simple; bh=BNcn869J6bhMq7f3DYJakpmobr9NwRGJK/HBSEdJhXM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJEWEExcoAVIhoe7uo15zR7OwD2mL9eq0bt+Bu0t8CdKiBrfX1KLYbCttFfd1ty9qkDeHKE2rgT0FkosDN6r420sEf6I528c8fGotYt1pHbSpWYLdy3G5MG2n1TamAe8oeHqzOYxDuD9pCPAaeAkCrEBtfo9/d8yRCsLGoxlAno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=blkdkdtV; 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="blkdkdtV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41716C4CEC5; Wed, 16 Oct 2024 07:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064005; bh=BNcn869J6bhMq7f3DYJakpmobr9NwRGJK/HBSEdJhXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=blkdkdtVd3+0cU9b+8mdXllKToXofxOPq2IkgwG2J/t/kBWRjaJ5hloeDDrAdAlSQ 7xd6uBcOvN72K9SJeP+U9acBnXZCYz/pW0D+Fwun0zDJu55855k/xvDSdemtcL/xxo DYD/wTNuK1TCHD/mRrLSITCi2it8CAqaYc7p69Bpi++1FwM75vWeFBWLnFln9DERne Xy+W8XByHDvSsdtCmnpchIDvZuFlOUSkV0tzl36Ff7gOY0K94RM81qsdmk5WmBkrOG Jzq+RGpWtBeUSqYEgfGeoVJyUD50r1Gk3o1s/JJo+utTjImJkV9YdsYGQ29Yje4JB8 7wvaoSaArtY1A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 1/9] bpf: Register mptcp common kfunc set Date: Wed, 16 Oct 2024 15:33:08 +0800 Message-ID: <654efc001ecb62731ce2f14103d4a7791098bdc5.1729063444.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 From: Geliang Tang Helpers mptcp_subflow_ctx() and mptcp_subflow_tcp_sock(), for converting between struct mptcp_subflow_context and struct 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 the flag BPF_PROG_TYPE_UNSPEC to let them accessible to all types of BPF programs. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 6414824402e6..22d2d4d09be7 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"); +__bpf_kfunc static struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx(const struct sock *sk) +{ + return mptcp_subflow_ctx(sk); +} + +__bpf_kfunc static 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,6 +232,16 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) __diag_pop(); +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_KFUNCS_END(bpf_mptcp_common_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { + .owner = THIS_MODULE, + .set = &bpf_mptcp_common_kfunc_ids, +}; + BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx_by_pos) @@ -241,6 +263,8 @@ static int __init bpf_mptcp_kfunc_init(void) int ret; ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, + &bpf_mptcp_common_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_mptcp_sched_kfunc_set); #ifdef CONFIG_BPF_JIT From patchwork Wed Oct 16 07:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837826 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 A2AA4BA45 for ; Wed, 16 Oct 2024 07:33:27 +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=1729064007; cv=none; b=i6mReFrSD5pzxaQr5fJlht8NrKAkxhEPqgXYzgUH+/RciO966dxtDPEE3COU4KiTISjRs7yxsdPKSWcWYfmwb1QqogIk209EeoNefQdzJmLkX3Ewn52d6EZ9PXBAEntgTEO0ii+3o7NM2myEfeQGe0UkD0uDXbvIRpVq8XgbpsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064007; c=relaxed/simple; bh=RRSb1zeoSM+dyicu1bBIlFG1bgoV3aLuhu2RfPPacEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u/M1ddpaLf2qui+MOOU5KEfr6VUKM+v61O8y3VdECbL+pr9DnHUlOHRuXa68CCw1tIMCzbYOLzNNdy1FcZDO3z+fectjNOTObOTN5TAUTMWyy2hZn0pini35aCleOv9qi/7Lh94bisUXbiXTDABxv2/1RC6Wp+MMJ4bJ8okcRm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NY7G1nw8; 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="NY7G1nw8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AC97C4CECF; Wed, 16 Oct 2024 07:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064007; bh=RRSb1zeoSM+dyicu1bBIlFG1bgoV3aLuhu2RfPPacEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NY7G1nw8eMnzSevMdzyY2KxcvLeBfg2SB8DbvHKjR6jckdKpFnZXja4qmDuP7gXCz pNKVdQuAaF4Xi2P4Sr4dOWAmkG1r/nJyvFhFl/MZCECy3++5qj+a38zekwc4GJN87G wjgww0cbPX2W1heatMk3Ra11L7cCnR7yduXOA2vHpjv6TcnFUBySkUaWoWFASlJ0ej NqLALkI6DUwR5/sAAJwnZ3BHLXJKfZpTvInLFgDM1T18HCoIjr6bHuRFb/45bzBkw6 TLZbXotSW6765Sk1blx3pqjCcgbAfu8PAoOsvfn6PzkuA6E3mmETrkay5oo7Fck2Rv Rqx5SvRvddwtg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 2/9] bpf: Add mptcp_subflow bpf_iter Date: Wed, 16 Oct 2024 15:33: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 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 22d2d4d09be7..405907b79d4d 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 = { .set = &bpf_mptcp_fmodret_ids, }; -__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 static 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); } +__bpf_kfunc static int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + if (!msk) + return -EINVAL; + + msk_owned_by_me(msk); + + kit->pos = &msk->conn_list; + return 0; +} + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + if (!kit->msk || list_is_last(kit->pos, &kit->msk->conn_list)) + return NULL; + + kit->pos = kit->pos->next; + return list_entry(kit->pos, struct mptcp_subflow_context, node); +} + +__bpf_kfunc static void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) +{ +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) { @@ -230,11 +268,14 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) return tcp_rtx_queue_empty(sk); } -__diag_pop(); +__bpf_kfunc_end_defs(); 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, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS) +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) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { From patchwork Wed Oct 16 07:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837827 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 87EB1192D9D for ; Wed, 16 Oct 2024 07:33: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=1729064009; cv=none; b=q8329QtnrrZo+Q2hwWq0DJCM79zYxNly/OA9sFjKAIPd12ADiuDRSeRfPN0bIDTFRdbFU625ZGeypZTSjFp31RswkAGRNSasu5mN2b0kPGBZE8KrdlegU865LSRMU7XyU00kDHmmVXIpSCfvBk10jbPGy3VDz7+iTA665vve4t8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064009; c=relaxed/simple; bh=G3Mj/1LV2XacqFHXlZNcFs7RZYqQ88fkQCHIFhe3LKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLLrZydT8IkLcnwVFYhcrgFV5H+48fo1pynggIWzYfe3kQs9Ol9vPRBm1x5YMmkoWKBbqhNcYj8X+dHIBpiobwHUbKWcOUiZaePYsZ0iI73ES/UZrxLhr72SCYhujbx15NqO3+PB9mP4W3wAhVZpqX04V3yskVu8rz3Yy2ZWxZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nqNGBRRZ; 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="nqNGBRRZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8DC0C4CEC5; Wed, 16 Oct 2024 07:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064009; bh=G3Mj/1LV2XacqFHXlZNcFs7RZYqQ88fkQCHIFhe3LKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqNGBRRZs8efx0Q+lM+fqeDUDjF0BycpxaDhNYNgVUAWLw+Vzbg9IalI7CWbFFyUp lm6exJgQHJAztkVDYvVk1egV5Mc73WyzDJzVk1nf7bM+HdU9SsBr7BLo1yri9Egtpj 2lQKM0Q8PAihCdrF/oWqs0nNmUkOuiB2gdLPQEsqbZaqMVGCCVAT5NFYO6B0s3n5Kh 9e1rDzqC7Oxn0fsonN2Na0RtVQN1yKqEQxt9+X+QiMw0tfTkztUNuQsDg0/bM3lEeC j5jgYFIxGybuV4kqBA0EYO+5dS8eYwYAdIrAwLAWkEkYZDtDgLZA3Gv0MSyze6IFJB 8ylvWzwHGpEaQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 3/9] bpf: Acquire and release mptcp socket Date: Wed, 16 Oct 2024 15:33:10 +0800 Message-ID: <7442bbc9df71fb9b333e674b0421f2a7b8f6b74f.1729063444.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 From: Geliang Tang The 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 405907b79d4d..19dbf28018f5 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -255,6 +255,22 @@ __bpf_kfunc static void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_sub { } +__bpf_kfunc static struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) +{ + struct sock *sk = (struct sock *)msk; + + if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) + return msk; + return NULL; +} + +__bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_sock *msk) +{ + struct sock *sk = (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) { @@ -276,6 +292,8 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS) 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) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { From patchwork Wed Oct 16 07:33:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837828 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 263B618FC61 for ; Wed, 16 Oct 2024 07:33:31 +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=1729064011; cv=none; b=DVOxty9oPO9wJEIuNDkNkWmDl2JDMwzki7lZK1Ymn6As94pn78mYmwz7IQ8U3XII2QJpvsihVWh+xcrerD0evM/NQJP2Aou1VuLbwaakcUgJkflaJcKBqeptw54Yi+ry0j/RQJT5/2ozjtQduCH5+LSqgcgWuASyZTvjB2pBSjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064011; c=relaxed/simple; bh=oaMGBd1pK55bdmLctreYWKC0GMO08L9WxrADmppgE/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GG3aRFrOUdHILIxuy+Ze1R2deCEcLxdgagdTIFDz9igCM4eRyKOfLTCONugvvg0bB6RbmbbfO7T8zmV94fRmdbmTKbxmoZV9xDHsnaFGWo1jNF2ldGjQmB8Brk0r//0w7c71/6Lgs1DKpKO18+zrcS2ybXNjAQAKnXHp1vXq+bg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MgOkQgnx; 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="MgOkQgnx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2B02C4CEC5; Wed, 16 Oct 2024 07:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064011; bh=oaMGBd1pK55bdmLctreYWKC0GMO08L9WxrADmppgE/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgOkQgnxgI2hU/2UtACDUYhOLRPDOT9JvW34CK4uQYAcCxdHuKonZIqYvptJL96FY cPiRmpTQuKSs6MR9HaBXPArbiUZnHrYl8D6vaCPuTz39HUbZaLSFBRL9DMoPjwrz1X afV6uzuTiVV/W0M3q0eeeK/w04uqN1yyqwqlpmomAV5ZltO1FAI6kP/8yz1EMFVJQc uNoJNAIcQLeg6PR4D2skMME9Itd6sVazZCvshJS55pmXywisna6c4HG7pRY4yXZrde dcC8JsO5PYZtJM1IE+fzZuBM8qmgVS0vyM3USubjjQVHW5nRF6iivWnVtOKGOcuiRw ETR+1lt05qbJg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 4/9] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Wed, 16 Oct 2024 15:33:11 +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 From: Geliang Tang This patch adds a "cgroup/getsockopt" program "iters_subflow" to test the newly added mptcp_subflow bpf_iter. Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy, bpf_mptcp_sock_acquire/_release and other helpers into bpf_experimental.h. Use bpf_mptcp_sock_acquire() to acquire the msk, then use bpf_for_each() to walk the subflow list of this msk. MPTCP-specific packet scheduler kfunc can be called in the loop. In this test, just add all subflow ids to local veriable local_ids, then invoke the kfunc bpf_mptcp_subflow_tcp_sock() in the loop to pick a subsocket. Out of the loop, use bpf_mptcp_subflow_ctx() to get the subflow context of the picked subsocket and do some verification. Finally, assign local_ids to global variable ids so that the application can obtain this value, and release the msk. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 7 +++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 8 +++ .../selftests/bpf/progs/mptcp_bpf_iters.c | 60 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iters.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; +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 __ksym; +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 __ksym; 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..b1f6e1fb467e 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,6 +43,14 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) } /* ksym */ +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 void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file mode 100644 index 000000000000..263221ea6feb --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -0,0 +1,60 @@ +// 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") = "GPL"; +int ids; + +SEC("cgroup/getsockopt") +int iters_subflow(struct bpf_sockopt *ctx) +{ + struct mptcp_subflow_context *subflow; + struct bpf_sock *sk = ctx->sk; + struct sock *ssk = NULL; + struct mptcp_sock *msk; + int local_ids = 0; + + if (!sk || sk->protocol != IPPROTO_MPTCP || + ctx->level != SOL_TCP || ctx->optname != TCP_CONGESTION) + return 1; + + msk = bpf_mptcp_sk((struct sock *)sk); + if (msk->pm.server_side || !msk->pm.subflows) + return 1; + + msk = bpf_mptcp_sock_acquire(msk); + if (!msk) + return 1; + bpf_for_each(mptcp_subflow, subflow, msk) { + /* Here MPTCP-specific packet scheduler kfunc can be called: + * this test is not doing anything really useful, only to + * verify the iteration works. + */ + + local_ids += subflow->subflow_id; + + /* only to check the following kfunc works */ + ssk = bpf_mptcp_subflow_tcp_sock(subflow); + } + + if (!ssk) + goto out; + + /* assert: if not OK, something wrong on the kernel side */ + if (ssk->sk_dport != ((struct sock *)msk)->sk_dport) + goto out; + + /* only to check the following kfunc works */ + subflow = bpf_mptcp_subflow_ctx(ssk); + if (subflow->token != msk->token) + goto out; + + ids = local_ids; + +out: + bpf_mptcp_sock_release(msk); + return 1; +} From patchwork Wed Oct 16 07:33:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837829 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 360AE18FC61 for ; Wed, 16 Oct 2024 07:33:32 +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=1729064013; cv=none; b=X7HEdxBEOYr8o539HyEPH5pudgQTNHL1wadvn8Xf93eqrpXiSH7wKUhwULppBQTTWwTyYjozWNmwFB9NCMMXwsaaFVLklWnnUN4IkE261CqnkLHvjf3Fdnvty5lUmbX/JO5brSYz1YTcmgvx4nIyjktXpei0cmCQvpX+UoZ/RJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064013; c=relaxed/simple; bh=KofcqcZZRqSZH7wuEv74FVbm+1Zpvv2GTr5Ggt1/Ilg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PHZeKrOxfrKApY7hxBTBUQ+InSY9I0xy1i859moIkxaGJjRkEarajQToKNltgsQbXMpMDEwAq8ENDZk7Gn51cxBBvOoCmWCSP1rAyxQ4IoEQP9es1JZ7E2888Jkzx6BK61E2iHDuekuJZgSu4GCQdNGDeYMkTE0irzs8iJ3XDUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=elhWuSie; 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="elhWuSie" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C3D5C4CEC5; Wed, 16 Oct 2024 07:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064012; bh=KofcqcZZRqSZH7wuEv74FVbm+1Zpvv2GTr5Ggt1/Ilg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=elhWuSiec7QXJ9lpVrMF6bkZGtO5NDo4zfhJzEPg/HJxVTPIZl11Lsge9EjnEP9dL 9MzxSpNSvsrj4tc1tCdw9KLMFxBZzybRId4EoKO5UMgb9y5ze9JOE0zJiQwLNiywDK qLnBGgMdautaRHUu4KlZOu35XUP16x+eVEfMDx1CVPyR+b5J6OwG6eWbiOqBzxebaU lLg7yWLtRMc9QmBMpGpcvjeW/0OCimLx/5/MMFwPmKk9bilDptKUfWOcpy7sSsF6ED OykgMZ9wl/uJho2Al6l2oGfnV1skRlZD2MyX1rsslJulRdNPP0xx51DOcpUsfvXm4U eGiT5jkwdWSjg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 5/9] selftests/bpf: More endpoints for endpoint_init Date: Wed, 16 Oct 2024 15:33:12 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds two more IPv4 test addresses ADDR_3 - ADDR_4, and four IPv6 addresses ADDR6_1 - ADDR6_4. Add 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 | 54 +++++++++++++++++-- 1 file changed, 49 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..9a903f2fd52e 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -20,6 +20,12 @@ #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 ADDR6_1 "dead:beef:1::1" +#define ADDR6_2 "dead:beef:1::2" +#define ADDR6_3 "dead:beef:1::3" +#define ADDR6_4 "dead:beef:1::4" #define PORT_1 10001 #define WITH_DATA true #define WITHOUT_DATA false @@ -351,22 +357,60 @@ static void test_mptcpify(void) close(cgroup_fd); } -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 addr add %s/64 dev veth1 nodad", NS_TEST, ADDR6_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 addr add %s/64 dev veth2 nodad", NS_TEST, ADDR6_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, flags)) { + + 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 addr add %s/64 dev veth3 nodad", NS_TEST, ADDR6_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 addr add %s/64 dev veth4 nodad", NS_TEST, ADDR6_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, flags); +} + +static int endpoint_init(char *flags, u8 endpoints) +{ + int ret = -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; } - return 0; + if (endpoints > 1) + ret = endpoint_add(ADDR_2, flags); + if (endpoints > 2) + ret = ret ?: endpoint_add(ADDR_3, flags); + if (endpoints > 3) + ret = ret ?: endpoint_add(ADDR_4, flags); + fail: - return -1; + return ret; } static void wait_for_new_subflows(int fd) @@ -452,7 +496,7 @@ static void test_subflow(void) if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow")) goto skel_destroy; - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto close_netns; run_subflow(); From patchwork Wed Oct 16 07:33:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837830 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 D199C433CE for ; Wed, 16 Oct 2024 07:33:34 +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=1729064014; cv=none; b=X99HPSOKBCkiwiOQi9ZdvHW54doegyvqcWvE1eCTfd6cMFV7c/+tXy9xeJOdt7/zbjtOwmI/bFUhPoGNPmethGj+Qcb5QITTYB47Yp7EnmhSUwmhgwHBsKfO5fArqIIfOX2MLQ/pEbzWfHF1K0EeojxwlFHod86q+e+LjXJDEDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064014; c=relaxed/simple; bh=hRHA5enc7gK7LON2CvND444dftAJXg42kRE1AVGnjZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WTqfavsK94JpQdn7btPFSX4PDBVDZVJVk9bwEKZyhkI6G38x5iTcmsgDHebOEqL84hToArub51BmGYrnscNw2U0SIms6yfROdwitJ/+LxWuVbQeklDnB9h6vy1pb3ur+svR0cSETFbbOb6GabT39tBtDxvaHqE8m/yiHuzZLaHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ibOqcL19; 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="ibOqcL19" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77C83C4CED0; Wed, 16 Oct 2024 07:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064014; bh=hRHA5enc7gK7LON2CvND444dftAJXg42kRE1AVGnjZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibOqcL19Wc3l5Wsjp2Lv2KzLSqaJGmPT3bKT3O6g+fbSIQqLlVxvTuJ74/79+z1up MDPtA3/ZSdaNI4ruYvqjsZhw4dnL6AcCkHnEDX80tQw36AoVTo1ZGgdeUCQ/cNSmlZ bste8IibTzN0c6iNKWhwO6cpa6sNa/yJuwGQgyUcHYET+vNYAA3OaiQhRwIcFXGyd/ mKSaIdtd9kz7MEQw2scCzkGVAj+a4yAVhFhQDxuD/jsfI4rddMdYd2LBjAwsuyDW9p 4AucqWRg2OjOsIafhG51MJgMxg2+W1E/fKH9owOLD8qc+nk2jR8Jmla0akma+mWV78 EtUAxulaQIWXw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 6/9] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Wed, 16 Oct 2024 15:33:13 +0800 Message-ID: <4527c30ba381a5dcb84bcb33b3a05c7d8d19ab87.1729063444.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 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, and wait for new subflows to be added. getsockopt() is invoked to trigger the "cgroup/getsockopt" test program "iters_subflow". Check if skel->bss->ids equals 10 to verify whether this mptcp_subflow bpf_iter loops correctly as expected. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 9a903f2fd52e..0f92dfa95869 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.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" @@ -509,6 +510,73 @@ static void test_subflow(void) close(cgroup_fd); } +static void run_iters_subflow(void) +{ + int server_fd, client_fd; + char cc[TCP_CA_NAME_MAX]; + socklen_t len; + int err; + + server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); + if (!ASSERT_OK_FD(server_fd, "start_mptcp_server")) + return; + + client_fd = 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); + + len = sizeof(cc); + err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len); + if (ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)")) + ASSERT_STREQ(cc, "cubic", "cc"); + + close(client_fd); +close_server: + close(server_fd); +} + +static void test_iters_subflow(void) +{ + struct mptcp_bpf_iters *skel; + struct nstoken *nstoken; + int cgroup_fd; + int err; + + cgroup_fd = test__join_cgroup("/iters_subflow"); + if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: iters_subflow")) + return; + + skel = mptcp_bpf_iters__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_subflow")) + goto close_cgroup; + + skel->links.iters_subflow = bpf_program__attach_cgroup(skel->progs.iters_subflow, + cgroup_fd); + if (!ASSERT_OK_PTR(skel->links.iters_subflow, "attach getsockopt")) + goto skel_destroy; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns: iters_subflow")) + goto skel_destroy; + + if (endpoint_init("subflow", 4) < 0) + goto close_netns; + + run_iters_subflow(); + + ASSERT_EQ(skel->bss->ids, 10, "subflow ids"); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iters__destroy(skel); +close_cgroup: + close(cgroup_fd); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -690,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")) From patchwork Wed Oct 16 07:33:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837831 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 DC69218FC61 for ; Wed, 16 Oct 2024 07:33:36 +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=1729064016; cv=none; b=gkG3iXUg8p5zdOTvV2p0gL2krWyZCaO3m8Kz/49AfEUsPcEkL+Poe78oRuwULwibmjxDsk58Le4Ym7/puM4XtnyRYJ1PGTzBMbI6MJXTaeesJ8O75+79upQJG2fYFlhwXk6dgdjNeY3naj5IUoM5gTPa8rqvLEtM9LteGWQOo0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064016; c=relaxed/simple; bh=wIhmKLx50uCzoCDPi/07gUtp3YgKrJHJXGI5pw0ZgRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HsEV1AfZUonvvsywwy3YvEgJ6J+tZDYZOYSDvk4lL0GKVhpxOfCJbdPh93Bx8F+mHsoWUzYtieLmsVutEEYqkIkhYwndmPwZEumc0/qDDqPQc0I0388yzttaiIdwLR3etPNo6Ro83fpbq+X+4fUcjNbogVeA0aMWbY677CIxba4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EwS+Qbju; 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="EwS+Qbju" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50443C4CECE; Wed, 16 Oct 2024 07:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064016; bh=wIhmKLx50uCzoCDPi/07gUtp3YgKrJHJXGI5pw0ZgRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EwS+QbjuNFiLAGqufs2YvzhYn8S1dEh1za4eIfLLLhqNrdXx+d+jtU+NXOCbCRnTF N9hpeR1ltvIFOPu5e+e/OjIpv+7Dj/c3K3Ld0QUZHIeec6lebdoGbEO33kLZ1CDQ9L Lu0z22YGSW1bd5dK13RmiGVVc00w+YO7SqDhz7UK4xJfYr8rByK8Ao6NBEIznNzpYf FXRA8MHQ/5wWFLuN6u7c1yLWntROj7vwcKLusuzHhqFQcNU5RD5luB11BC/CaHe3V6 CF98UsswHlcyR22ZjIqi+wWhiWNR2+72SNiu6ElNt4Dw59169P6xGdFlwOKGiZLsli curt1sPwg6EcA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 7/9] Squash to "selftests/bpf: Add bpf scheduler test" Date: Wed, 16 Oct 2024 15:33:14 +0800 Message-ID: <66bc528ea6e3a0857ed7cd764fb36ed2622641d3.1729063444.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 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 0f92dfa95869..6c76f7aac035 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -585,7 +585,7 @@ static struct nstoken *sched_init(char *flags, char *sched) if (!ASSERT_OK_PTR(nstoken, "create_netns")) return NULL; - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto fail; SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched); From patchwork Wed Oct 16 07:33:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837832 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 5B13C433CE for ; Wed, 16 Oct 2024 07:33:38 +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=1729064018; cv=none; b=dHA25r8yRZqueoxWrwgJkc8ibJvBtn4R2HzD11QTWIu1psX/fA/u4J+bhZHhonIXGROlhz9loMjgDQWmCVeAKUZn0BJH955hkbre1NdaDh3Fh+Ujx85GHcrsIanWC4P58FuYY3rA9FMKKGgIE7cOp/SZoBPOSdCgHQ/vvRGlXKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064018; c=relaxed/simple; bh=MjN0T44+dZJ53UIGm4AzzT/hLa5oX37WYHBmpMD8qEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OokA0uIHOF01HjMAwaJgAV4WfyyO+tBFlLgGybvAXCeW+bgeMKGVgEt2r/np+HBeJFwNyp9E1Jp8wzrzqY8CBYQ4qlqxHTZGKV8yhS0Y1OEMARnwELlGSZ+c0miTprC5ax7HAkHPpZjxQTZbaqO8MToOeoXfECMMxJnD0dzL5mQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k7OVmpEu; 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="k7OVmpEu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1802BC4CECF; Wed, 16 Oct 2024 07:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064018; bh=MjN0T44+dZJ53UIGm4AzzT/hLa5oX37WYHBmpMD8qEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k7OVmpEujrnUDXuKt36s0g1HXxfA7p0gvDmxwxvqsRGQ43HF0QKF4tEY/DjgSRzp/ aJO+cGWYnRWEjevvh8Zu7U4vKnUkIkQ9Yt3YUpVAuGoN6WdA6LsruQ2Bo8i51trEMs FUCjnr+kNNE/M7xFZLZw35c470cZWufxzbgKzU3ooGMjLxSmOpNtx6temkvAqJfVhl OQLtuJz4TNdTAc0uKtNzM+X5muwTJwnHdoH8dV2tUgSzvI6P7aASnmAIPJK1SfFfTH wD0RewNl9YrfGhu33oBrzQkcJtaP2H0BEV6VByzTAh9B91HQ0BqSZoWDjuYLi4TGOA cVPjLNDXSYT7Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 8/9] Revert "bpf: Export more bpf_burst related functions" Date: Wed, 16 Oct 2024 15:33:15 +0800 Message-ID: <4da1aa50077637236c6528bb90d8ff2ef1d563e1.1729063444.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 From: Geliang Tang This reverts commit 371136b55b559e2ef4d117a901b9f96ee036a175. --- net/mptcp/bpf.c | 11 ----------- net/mptcp/protocol.c | 4 ++-- net/mptcp/protocol.h | 3 --- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 19dbf28018f5..1ff26069b9fd 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -279,11 +279,6 @@ bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int p return data->contexts[pos]; } -__bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) -{ - return tcp_rtx_queue_empty(sk); -} - __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) @@ -304,12 +299,6 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) 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) -BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty) -BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale) BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e420ce9bbfb6..e978e05ec8d1 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); static struct net_device mptcp_napi_dev; /* Returns end sequence number of the receiver's advertised window */ -u64 mptcp_wnd_end(const struct mptcp_sock *msk) +static u64 mptcp_wnd_end(const struct mptcp_sock *msk) { return READ_ONCE(msk->wnd_end); } @@ -489,7 +489,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl inet_csk(ssk)->icsk_timeout - jiffies : 0; } -void mptcp_set_timeout(struct sock *sk) +static void mptcp_set_timeout(struct sock *sk) { struct mptcp_subflow_context *subflow; long tout = 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b963e68451b1..0624de84e339 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -720,9 +720,6 @@ void __mptcp_subflow_send_ack(struct sock *ssk); void mptcp_subflow_reset(struct sock *ssk); 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); -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); struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk); From patchwork Wed Oct 16 07:33:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837833 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 D4CFDBA45 for ; Wed, 16 Oct 2024 07:33:40 +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=1729064020; cv=none; b=M1ch0ts9Bp5GqCsxRxUvJD4Q5kwZ5z2ZwriYrfKMdIFFLHeDBhITL/moXYx4UpBm0jgmJnFjAO5I6JPMytFp72X5a4LSMWCAVqdqtuWwMKHadP59IKvQ/mGzUkCIOVgGHYjcrA8XWc558y3za2gDo8nUjxn0wHST1B3Ulqkj1mU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729064020; c=relaxed/simple; bh=uP2+vEIHhzORm4aKIH4TIot3P+Ep8rXugxt0n7xXjkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XVOGOjkVo+HNwJH+ZCMzJVLPC3a+0u4tzLmDd1mX8jE4rmbdH4N40sbJPAD3G1FpTUgVPBUkPzhCxQ1rOBzAmsFCZUirMNSE7rczzF7mOC29HAArOsf1fyIYKbbdfBQMgltsNgKDP/DIekeZbeCLm0rLxlg2Px2PXY618ew5lQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oTp0jQQu; 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="oTp0jQQu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02E75C4CECE; Wed, 16 Oct 2024 07:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729064020; bh=uP2+vEIHhzORm4aKIH4TIot3P+Ep8rXugxt0n7xXjkY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oTp0jQQuX7D6thQAxQGNNscyFy5TY7Pfad/ctbFTuFCa+J3lGjWji1UKxyIujg17S dBdlo6C83FUgLx65E8EzZ0MkSlfIk+bSpdpEiOBtOssXGj7OwTrnTXusZYhxGC+Wzd 6vFPpTMIq63Q/xhAR7qPZVhJNdz4AN+TyG2iLFa+D6C4f4WFKHGwjn2xjY+mJFvsCr +rTEhKCvZBTpUlkpxWI/BjysCYnZCiicdTinC4Lctq5Iq2HYuwxMpI5q37W9CutZWi nyIyD2m31+rnCC0C02A6AKcHEGChM/FxX+TiwWuev4Pqg7dz1XmlCSJtGJguKXVWv3 usHmjSsxX6PoQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v10 9/9] Squash to "bpf: Add bpf_mptcp_sched_kfunc_set" Date: Wed, 16 Oct 2024 15:33:16 +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 From: Geliang Tang Please update the subject to "bpf: Export mptcp packet scheduler helpers" Make bpf_mptcp_subflow_queues_empty static. Merge "bpf: Export more bpf_burst related functions" into this patch. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 11 +++++++++++ net/mptcp/protocol.c | 4 ++-- net/mptcp/protocol.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 1ff26069b9fd..0a14cc45d240 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -279,6 +279,11 @@ bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int p return data->contexts[pos]; } +__bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk) +{ + return tcp_rtx_queue_empty(sk); +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) @@ -299,6 +304,12 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) 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) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty) +BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale) BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e978e05ec8d1..e420ce9bbfb6 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); static struct net_device mptcp_napi_dev; /* Returns end sequence number of the receiver's advertised window */ -static u64 mptcp_wnd_end(const struct mptcp_sock *msk) +u64 mptcp_wnd_end(const struct mptcp_sock *msk) { return READ_ONCE(msk->wnd_end); } @@ -489,7 +489,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl inet_csk(ssk)->icsk_timeout - jiffies : 0; } -static void mptcp_set_timeout(struct sock *sk) +void mptcp_set_timeout(struct sock *sk) { struct mptcp_subflow_context *subflow; long tout = 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0624de84e339..b4c72a73594f 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -720,6 +720,8 @@ void __mptcp_subflow_send_ack(struct sock *ssk); void mptcp_subflow_reset(struct sock *ssk); 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 mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos); struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);