From patchwork Fri Oct 18 09:18:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841452 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 2158B1EE030 for ; Fri, 18 Oct 2024 09:19:07 +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=1729243148; cv=none; b=Qa4300oMSLrJUckIpv7bDbfQGnQus+Hnm7HBkIDorXHvP9xqcDQeMEihwnkm9xt98OgY0R8hyxRiDv9X0auGrBmZCTGDybv8ulPWzbkEdCgM667CWTNqRIPGkX8Q9StDNeTox9BduRXYpzHDlaJ6ILTIfcMdXR1Di4M0wZ5LgrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243148; c=relaxed/simple; bh=O/aDW83wsVpbVBtm3apBXP+i5+MgUJPEBFLiPHCpwps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bB71m4TQQEUNT2xl7M9tOZ9fmLt3Zx1086DVyC4pu+JHLPrGxRy8I/oIIN/imXuzxtD6jBDxBv5Qa53reqHFsT8CeKXmjwW3E6Nz4QhnVSk04hE8YP1GaaFE6J+PQBgBsBn7cCtWid3Ig2qANVCizI6A0DgdX9knBnTdpEzYTF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ia1HBelY; 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="Ia1HBelY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DB10C4CEC3; Fri, 18 Oct 2024 09:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243147; bh=O/aDW83wsVpbVBtm3apBXP+i5+MgUJPEBFLiPHCpwps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ia1HBelY8//abj6OLcAmf02jjOKx8bs6h+KeStxYaxpQ3l76hrIVeaclsjZF6UlRh 6thM+6v/QzPtrFcrjDzWpsER2NqKYG6VrLilK8d4RLBN0Urf/Q5YmIvDxLiqNnXhOW 4OFTd0PQbaph2EUlfYFKSJwcL2kYl59Zr2llZBaiN2GzF/sXIdSw4uvmr5RH41j812 VqTpIkFoZlsfo+tblczQ2nyfjavS9SW+3ntFp7dcWJCpZX3ar53kKFXtCS/D97kANw OQ+F0fK+mh494Zv2bIocjzJjTZGlvH0ZrQj1Ud7f+LzSNy4qv+7X4iLP9CU0QC89Q6 Jnt1d6NB3CFGA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 1/9] bpf: Register mptcp common kfunc set Date: Fri, 18 Oct 2024 17:18:03 +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 MPTCP helper mptcp_sk() is used to convert struct sock to mptcp_sock. Helpers mptcp_subflow_ctx() and mptcp_subflow_tcp_sock() are used to convert between struct mptcp_subflow_context and sock. They all will be used in MPTCP BPF programs too. 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index a9d6b5b939a2..efab2e6e28ef 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -209,6 +209,23 @@ __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs"); +__bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) +{ + return mptcp_sk(sk); +} + +__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) { @@ -224,6 +241,17 @@ __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_sk) +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) @@ -245,6 +273,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 Fri Oct 18 09:18:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841453 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 5A76D192B7C for ; Fri, 18 Oct 2024 09:19: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=1729243150; cv=none; b=VUeIc6P8tBBXoEiyUMSzyS25rHw0EKHkuwa0wGEq2ZbVAXkY79CEGlvsyc2Vq6RB8UFE98yUgRLJRNbwhhLbN+sk5yFghM8shj1QBn3Bup3kpEyuVtAv1hrC07Ype69F3YD0FDfFmqFAUZhnbuL3yYCs6M/5DByaVxPgHeY17uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243150; c=relaxed/simple; bh=/UWS8+VBjYFrqdOw4KZJINWR8TNN98J/VAUIMhPLzWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N5HTWYDSzcN9jXM02NcxF1oVd4bc7So0f05y8yOJrCzqhho4KHj9c+b59Vh08WRuF+BWoK43Wt1Ox1TlzY37PFh48vR17YvTgwBwynU8P4EldL/Z1YpFbuj5eiif5RXRh3+X2dyB8dEYmiLy1Jz72/wyFuEWnYx22dt7boZl3nE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UZQWB02L; 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="UZQWB02L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4A18C4CEC3; Fri, 18 Oct 2024 09:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243149; bh=/UWS8+VBjYFrqdOw4KZJINWR8TNN98J/VAUIMhPLzWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZQWB02Lh0lCOChvAzOvN93NtmuAVagyJfR+7bGL7KLJL9AoivBejqgVnmDuEtA+M wxMKRigNPecQN7l1ElycYWKF27KbmQG/sTpooXoHwgIAuIAFj81zTzGCyfo9ygbI7x slYx+ReOpeKGLkSKlUcwL8lOtbrVCLbxcurAyyW/5dWNNyVTEdPNPjPKihOZBajv87 BQK/pxDQJS4aSREYUa8bAbnV63G+7SeCsmhBbz2svB0zW4Skz4hb5AQYbJ6nE3ZUzc Kw1KgF7k8df6y4N+cNgYbA5bCLEfEAitf3MzV4Z6nyudD9B6oOT3KhrP+oBILnia1v E3FcGOscyNOxw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 2/9] bpf: Add mptcp_subflow bpf_iter Date: Fri, 18 Oct 2024 17:18:04 +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 efab2e6e28ef..65fa84d1e745 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -205,9 +205,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_sock *bpf_mptcp_sk(struct sock *sk) { @@ -226,6 +233,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) { @@ -239,12 +277,15 @@ __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_sk) 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 Fri Oct 18 09:18:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841454 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 C9FE518FC75 for ; Fri, 18 Oct 2024 09:19:11 +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=1729243151; cv=none; b=II5PZAI/bRA0+UoeRz9utbrpk0hlZmHSMvXka/jNgdX9JLtAnOeya7uaLBlkTGQSTnkyNF2a8JTgZuORtz9mRzlY5Bm1xtfQbn+YtiCtg1RwjDDwMg2WbfWQUMKRqE8cRsUeCoLro95B5Ln2uSQa7Ml5Z4RgTrn7JufIzdHO9tM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243151; c=relaxed/simple; bh=gfI7ffM4BR6nmpfVDJI4OeNg/i5LZsn1ZqXbETAKL/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IO69B85HNbIYtpJrMFgBmkU6k37CT0EtJhC+Ib83gekytkYFpNW5Q3yZc7onm687RH7lN2aUmTddSUKH1AdFs1Bc+ow56fwFEM9U5mwxiagt8h+zNF9VJ+TzHzhwksW7QN8+GcItBQsq369Qw3CAPSI2xizcWSugPg2CygKfVdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LtzkAYFs; 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="LtzkAYFs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87637C4CECF; Fri, 18 Oct 2024 09:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243151; bh=gfI7ffM4BR6nmpfVDJI4OeNg/i5LZsn1ZqXbETAKL/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtzkAYFssFzl6k0Rytr5WmChufW5ACZYKFK1PuroR7o3yO4hdxUTE4ppShHcN2LXS DW+vDhyMVdJcAWCNpk1JSeomQKZDPdt9X6zRcnxvYCEuDwupg+JSTRmxi3wgPRFV0/ 6EZ6U8/nnCKsAG4uUwgDeryJl/0B91lY/adXj5FkvX+BOwGSAGrMywM/xHcQ3hmz3i qsVNxd6cj0wB/QF8uyqc+5ROcxGtV2vlHehpLeDaCwbJYDm+oJyHJ1z3fBh4dsqvd4 tAvd8i514S/osK1+wSxvwW0MCLfUH0RzaAgTrGr82JLZiBDlbs3PExTy0c4Amx3CAM lz/URX3RqNPVw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 3/9] bpf: Acquire and release mptcp socket Date: Fri, 18 Oct 2024 17:18:05 +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 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 65fa84d1e745..cf660e561d7b 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -264,6 +264,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) { @@ -286,6 +302,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 Fri Oct 18 09:18:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841455 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 47D231EE02F for ; Fri, 18 Oct 2024 09:19: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=1729243153; cv=none; b=RZj5nvJk6XZqUBg62tjroXs2GAfSqY4WDNPjKICdbefnbtCZRaui8TYjh4u3SPW9T00h45wPrE3q7SCvy6ti08sjWVtwIC8uknNY2uun7me04HN/Ris/MASC2a64yK37foYVNc8+KxytoZyx+TzdIgkHbNHMThBPBnrrC6dAD4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243153; c=relaxed/simple; bh=0p2qBSCoSRlEEfD5UsSG+bDLhKKYofE7THwZNo8yY7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MCFQYbg6vF3Vx14mwEXMqhHhVma51pn5zl/J7KaWyZCeCaCwR3S6hKqiu7CrfQXTphBoeoxKc6C2avAzcqR7x6z8JmMJKsFtUH5uV2IXV5mDKNwuP3a6tWfs0LzPp6oXQFKy4iZzsj2PHRsQFNvqji1urms6pSwc3UPYT30G3+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=In3ORkDJ; 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="In3ORkDJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9B0BC4CEC3; Fri, 18 Oct 2024 09:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243152; bh=0p2qBSCoSRlEEfD5UsSG+bDLhKKYofE7THwZNo8yY7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=In3ORkDJbdVpSLDFj39dOgOc5UGo65CYO1/QNc5cU+CIZlxJZ2pWVlye/01N+/aYx QarLhW+5GDHGmcqw/Y+s46fGj/Dy6apKbOcLcHPoig0ufRYcfU9y93jrf9Mb4D9JGM qBOwxMxnHXqv/rFj7oTdyLI8R4hnCq3P4VaRMpil4NYwWGMwfQmefqgZVxgDYgOO7P T0dZ/wkTpbee5V4EDBxn8AFuwS6jLQ9bwR+bY2QLnllvZPtXoYnZ73WRgAOWhZbXW6 yoMr0K4czZo9f4X+bL8T5S2ddfet7PLZtjmu/mfVS1/a5yE2cHYOd0g6SP5lnpYxwu m3BBrIz1UHyIQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 4/9] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Fri, 18 Oct 2024 17:18:06 +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 | 9 +++ .../selftests/bpf/progs/mptcp_bpf_iters.c | 60 +++++++++++++++++++ 3 files changed, 76 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..3b20cfd44505 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,6 +43,15 @@ 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_sock *bpf_mptcp_sk(struct sock *sk) __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 Fri Oct 18 09:18:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841456 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 B3F001EF925 for ; Fri, 18 Oct 2024 09:19:14 +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=1729243154; cv=none; b=CIIFjJ/+n45G8mnWKxQPJFNW4kajXL8K/JhnTNmjjhuLz6NScUW7lIarqcMHqKOaGLsP2R2dQW0o5sIMnEHR1LsWTAfDdDGJIFT3uFuzpc25Q7R3HOiYYkCsqSRYeR0fkuqke44mNr1HiT1OO/l0g9y5mqFLWDdLVG1IzSubYjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243154; c=relaxed/simple; bh=Igt3me+CnEmDDCvFx8jssf6o0vBlnpw5qHsXTC9jK2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gMeNcjF83ZQcnoVaSvwFRVjt57+sLRIBQhEFHvA+NH+l1aAVm6dXMRer0WgQGY0itN8AThmnnCQxYDJ5uEHaApULRpiUXILBEUeX1l8o1gPEI1WtkfxT6fBffU3irfsZEOQ6H7eE10JpU9m5vZIUStjhvT7fVIQH/nG7WJ1/BLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=untXldta; 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="untXldta" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E1D6C4CECF; Fri, 18 Oct 2024 09:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243154; bh=Igt3me+CnEmDDCvFx8jssf6o0vBlnpw5qHsXTC9jK2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=untXldtaPjXQRPlEvvT3F/go1zPY+hmmwcma7hdIe/ZOUOPaTC0ixlebUpXo8GzHY DqKNeNErjBczCYrY6Y3h+baeV0xwsURrqXG0sjanCy67neY4Jslr2fjymDNYJzKTwV jeWcLq0/8jAvrKdDbT3BKnV3I3pTqxGK7PeDE7XAB6bZNRzhSCgdsw9otzk7t1zdB7 voAVCe/ZgE3cT6ythLP1HMETeYWc7mLK9dpIcyJ12YsasNwGjORMyuwD4gBL7DSN6D r3/3AGIDsQ/LHbmudyx615UaPSpyQyayPVOA30rz1ateGee44OiHj7iXRtQeLdsJUD NuuRpowUHrXtQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 5/9] selftests/bpf: More endpoints for endpoint_init Date: Fri, 18 Oct 2024 17:18:07 +0800 Message-ID: <7a6d58423af3592ca45ae04b5cd563ea0c0444f5.1729242644.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 changes ADDR_2 from "10.0.1.2" to "10.0.2.1", and adds two more IPv4 test addresses ADDR_3 - ADDR_4, 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 | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index d0dc2e4fbe46..02fdff87df2d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -19,7 +19,13 @@ #define NS_TEST "mptcp_ns" #define ADDR_1 "10.0.1.1" -#define ADDR_2 "10.0.1.2" +#define ADDR_2 "10.0.2.1" +#define ADDR_3 "10.0.3.1" +#define ADDR_4 "10.0.4.1" +#define ADDR6_1 "dead:beef:1::1" +#define ADDR6_2 "dead:beef:2::1" +#define ADDR6_3 "dead:beef:3::1" +#define ADDR6_4 "dead:beef:4::1" #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 Fri Oct 18 09:18: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: 13841457 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 62863192B8F for ; Fri, 18 Oct 2024 09:19:16 +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=1729243156; cv=none; b=F/faJ1opBccy9vZbVGOvwAMjX9iwZjReWY6BJmVzg7pdWGBOdo1YZUTw2Iod9lotdfHTseST5jlh4CauGZYEOpSUx5kpyqt7bfX54yU82YH5qusvHMaj+FkXvC4VJHYbcN0j9Tmn9J/LyfrwCz0OJoFW7EloaEmWWX9CftRbqlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243156; c=relaxed/simple; bh=qfonZmUyNt66WPclW0OyhIm/yyZMahz/mU5dvT5O6TU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FdJoSoU06YxsdDk3ARcOPOsTOxzdOeAQRQzPYIuMpSlLbFmMGkLodOBG7CGIKX0UCZB13hNPIiztedR6B5fp6G1fDhbOQ3l+s2lhGPjm1vlOCjv/OnwFwM0PyAhvbJbGVp1kzW6xPXnDPXU2CA2oM2bKYltAsnZfchE046PLBb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HOf80DJB; 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="HOf80DJB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E85ABC4CEC3; Fri, 18 Oct 2024 09:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243156; bh=qfonZmUyNt66WPclW0OyhIm/yyZMahz/mU5dvT5O6TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HOf80DJB30kQSlLrQKDi43o5Rnur2tS5T6BkAfj5w8FUhMUtR4MD7m/He2gHtpyj+ digI1bW+nNOjDJ3XZx/tHlCrdYfIlKmNjKrlMEPPKEZRwfod6Gg/qH+u8AHs8SvcBf /1J80pbZjiQlTQZewTCTKldY4dffXzLcAvwFkJXjf4sj2DnIn/rxO+WwIvMzI9zV2k 2KuEKKExF12rFw7lup/34vHDfVFMff21ntPYFLLfErelE8fGjTccFr99Yh+4C5YbxA PLU4T3jZtsCuOQn2fi97aPuBYws4cG/ixBM5sLuybkXBk9Gg2nJFB+OCq/fY+RLbKN XBl2OTV3VHXeA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 6/9] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Fri, 18 Oct 2024 17:18:08 +0800 Message-ID: <67cbbd7ff515dcc421605b24c14c734fd3263e42.1729242644.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 | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 02fdff87df2d..0f00eef7aef5 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,72 @@ 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; + + 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 +757,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 Fri Oct 18 09:18: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: 13841458 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 016FD18FC75 for ; Fri, 18 Oct 2024 09:19: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=1729243158; cv=none; b=YuWZVs5p1m4gHtIUCI1l1IIximt69ZFS4UEXJxaP4ZnLxfSN3e0pxFXsDZy/46pYUuUXjqgas4ilJ/L7JXcWjXipzPCjsBCFxmtR7RfUSIhZjHQDCKMI0/NGAXjvLFK5FX+XMHKW7TOiKfvwdDlXZ969QZCVxvjOy1dFmnnPhew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243158; c=relaxed/simple; bh=vtmI0n8XBT7iRa2qrLQje0sDS2tJxnSofErAGDdm9BY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hOlYG1J6mnjG5TPOnT94K2yFP6oFxWUPhbOL8qk3p6wxfq1ENBS7tXLzm4cF+zResqoDuUpQHoPNNsxMS+mkCu8m8tdjh7Cd2SE87tLKlHsjY3TzN3ZsqEng9JrGLohlbplxxBy0FfzF3NNbJuQCy1jN5/M4ckmyXpT+FhhhVsI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KLUqKPJ6; 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="KLUqKPJ6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB6CAC4CECF; Fri, 18 Oct 2024 09:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243157; bh=vtmI0n8XBT7iRa2qrLQje0sDS2tJxnSofErAGDdm9BY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLUqKPJ662dL2QyAXjWr0H9o+IAqvHWpSWeaYyKuJK1oeVka6SD5QYhWYhDd3kqz5 ESh5RkQPJ8wMWbuvwFcJpVqwGfPnbEweEvFwmzGG6OGo+DIJpxC7ysnHJwiG3xq+AL zZ0Oh7YlFnr44sk8AK0TEjDvj8bTrBM6h/B1VI57RLuqSk1icpGmgQWBiw4bJv4Spw Cr3eZ0C/T85uO7KIykiYVX9QUjlNK+EpJkDR9jV4lx40EY2cRKTffQgnSty+z5xIm2 tbbLZBqVpCUP/KtkMeOJTx42p6vxNzKacoOqmeHctZ6ce0XE8Q3HyfECDOgDEGZrZR rOD3ckDLXBwgA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 7/9] Squash to "selftests/bpf: Add bpf scheduler test" Date: Fri, 18 Oct 2024 17:18:09 +0800 Message-ID: <02aa117215d70934d4965dfb19e7a03fc1608f14.1729242644.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 0f00eef7aef5..5b9f29a569a6 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -584,7 +584,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 Fri Oct 18 09:18: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: 13841459 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 275591EE030 for ; Fri, 18 Oct 2024 09:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243160; cv=none; b=tHjyN75Uzyy+6FgEO8zXvwItQToM2CrcnqgIcNfJ5aav8SExfnMyndlMREEdRrMDqYlpLGzNOClR/vJFBTlvhwDm3tnRAI4gzpeKjRNx9caN5Obf9uW5PIHULc+e2+W0Uunw8915doFVTofRpTcDvxq2DFY/YGlNzbHNtYJvRQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243160; c=relaxed/simple; bh=Kbg/woWQyt8SzsP3SFPPdsPppNrlRZawsUM/d+hlE0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kRj/GnABVmOotG192X8dZo5lbkxfNawlXvRB7yHKtWCTYdFFSDBZVp2X7s+y8HTeWnbl9OqvQMGmLSWlrqfravAZl8GYUh++/Jc9gWjb06/8Sj+0tjmBPR8EIW1o4npj07gtmPkloVHkuOJqd+u2mUZ4R1WpU9JcSkBF6zeZjyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rL3Mvolx; 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="rL3Mvolx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8398EC4CECF; Fri, 18 Oct 2024 09:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243159; bh=Kbg/woWQyt8SzsP3SFPPdsPppNrlRZawsUM/d+hlE0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rL3MvolxVbC9JWS3FaS8R1n+O21fIMyYTn2chaJYQQoxfg1AJ7FpaUbQ5YWahf0TX Qw7DUbwretnaVUssNYh2BCgF9yrL+ZjX6JhCZohvLE4P0+qErwKbmME5gzF6CwOuyh 3uBXRcCWi/uD2Mj9QpaHvX8GHNKgDC+hsCpZeLmyX+tRxEfUjFGl1G5x/6XBJff0V5 LYsmA7Prs7b8cfzOmg25Fh+Oy3UyAssOWYSyxAuEtMTavs8MHMvSXEIVnGkY9VUZb8 S/2PPOmV4E9CiQrg4sk5FAnoEp1JuB1n9tlebPyz1NX22TyQy4ahfm2x0jPTFVVDm/ vtbkg0Yv/xPvg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 8/9] Revert "bpf: Export more bpf_burst related functions" Date: Fri, 18 Oct 2024 17:18:10 +0800 Message-ID: <02084f6354f9dae436d493618a7360af0b65e23b.1729242644.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. Signed-off-by: Geliang Tang --- 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 cf660e561d7b..476620526c79 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -288,11 +288,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) @@ -314,12 +309,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 21bc3586c33e..b0e9a745ea62 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 Fri Oct 18 09:18: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: 13841460 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 C8E2D1E883A for ; Fri, 18 Oct 2024 09:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243161; cv=none; b=Vgri44Cw531sd+5+FleX46k7t14rqt+bojyAudnaALUgDWVe5g+MVKlMxU3ysfu359byTAcIgLcpzcj3xqtnaPgxPCVUOTkZ7P1xKqR+XxgiaxeBSesk1KPUpNislkqlD+6bHO3tBGY/xlnmWGnRUt6xSbG884QSkJnaVAqD7HI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729243161; c=relaxed/simple; bh=oLzEaoF7HhnJ/lJr3NNq07/yId5b/25FLKZSkKUO4MM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bp9YLb0rFL2ecmeS4aT2N41NWeJ6/fJ+TdNR7b87uZmtfQPDj2tlEGQwGGSgUgKnnlJij6UqIwxBWrY/6mYggRrrZ6EAkL6aBTf5qfTheiAUDGsDLiF4eyLZKhTbHNvt3w2V8+9I66c5wzHwooMWmy2uGvT8KPeyRId2H1YqhJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K6JcGgql; 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="K6JcGgql" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B4B9C4CEC3; Fri, 18 Oct 2024 09:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729243161; bh=oLzEaoF7HhnJ/lJr3NNq07/yId5b/25FLKZSkKUO4MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6JcGgqlnqZfUnk53cUCQCWEVH74BoJWS0B7maU0NrVoS3a4IS9b3JeC+GDmpzfWT pWddlpgped8jlBY6GsfUCf+hTTgzkiETu1S1DZ1eJE26lvHueCP/S92QyRxQ8KJJjG 290Xgp4HUQsMAEBsvW95sI6Zq4OZN+kPUP5BP5cs84kp2C22UQxvou8NA0P1BUnayS xYjjh93cmVtmXZl4GmnqKjkyKliwxIDD5zF+Fxm82UayDSJss1QOu2R3Tts3N9v6G7 FsWNwPRuxsgkqQoI/ONwKNVihSF6NGLDhhRsojiXQuwnhYWQdFSNNUnIjiN+McDM1Z yNhEnVcDiq1uQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v11 9/9] Squash to "bpf: Add bpf_mptcp_sched_kfunc_set" Date: Fri, 18 Oct 2024 17:18: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 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 476620526c79..1ad7f703abb2 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -288,6 +288,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) @@ -309,6 +314,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 b0e9a745ea62..21bc3586c33e 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);