From eb22eb8646eaea977d7de5987fb74cdf21e64d9a Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 14 May 2024 22:41:57 +0200 Subject: [PATCH] WIP To be squashed in BPF topics. Link: https://lore.kernel.org/all/20240509175026.3423614-1-martin.lau@linux.dev/T/ Signed-off-by: Matthieu Baerts (NGI0) --- MAINTAINERS | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 28 +++++++++++++++++++ .../selftests/bpf/progs/mptcp_bpf_bkup.c | 14 ++++++---- .../selftests/bpf/progs/mptcp_bpf_burst.c | 20 +++++++------ .../selftests/bpf/progs/mptcp_bpf_first.c | 14 ++++++---- .../selftests/bpf/progs/mptcp_bpf_red.c | 14 ++++++---- .../selftests/bpf/progs/mptcp_bpf_rr.c | 14 ++++++---- .../selftests/bpf/progs/mptcp_subflow.c | 5 +--- 8 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf.h diff --git a/MAINTAINERS b/MAINTAINERS index b4ed6480e919b..504def176aab8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15513,7 +15513,7 @@ F: include/net/mptcp.h F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp*.h F: net/mptcp/ -F: tools/testing/selftests/bpf/*/*mptcp*.c +F: tools/testing/selftests/bpf/*/*mptcp*.[ch] F: tools/testing/selftests/net/mptcp/ NETWORKING [TCP] diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h new file mode 100644 index 0000000000000..2c58bf4aa359c --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __MPTCP_BPF_H__ +#define __MPTCP_BPF_H__ + +#define MPTCP_SUBFLOWS_MAX 8 + +extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, + bool scheduled) __ksym; + +extern struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym; + +static __always_inline struct sock * +mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) +{ + return subflow->tcp_sock; +} + +static __always_inline struct mptcp_subflow_context * +mptcp_subflow_ctx(const struct sock *sk) +{ + const struct inet_connection_sock *icsk = inet_csk(sk); + + /* Use RCU on icsk_ulp_data only for sock diag code */ + return (struct mptcp_subflow_context *)icsk->icsk_ulp_data; +} + +#endif diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c index bfd4644dd5928..746f83e68ba9d 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c @@ -1,23 +1,25 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022, SUSE. */ -#include -#include "bpf_tcp_helpers.h" +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" +#include char _license[] SEC("license") = "GPL"; -SEC("struct_ops/mptcp_sched_bkup_init") +SEC("struct_ops") void BPF_PROG(mptcp_sched_bkup_init, struct mptcp_sock *msk) { } -SEC("struct_ops/mptcp_sched_bkup_release") +SEC("struct_ops") void BPF_PROG(mptcp_sched_bkup_release, struct mptcp_sock *msk) { } -int BPF_STRUCT_OPS(bpf_bkup_get_subflow, struct mptcp_sock *msk, - struct mptcp_sched_data *data) +SEC("struct_ops") +int BPF_PROG(bpf_bkup_get_subflow, struct mptcp_sock *msk, + struct mptcp_sched_data *data) { int nr = -1; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c index b3c8115648667..dffb628296f76 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c @@ -1,15 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2023, SUSE. */ -#include +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" +#include #include -#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; #define MPTCP_SEND_BURST_SIZE 65428 -struct subflow_send_info { +#define min(a, b) ((a) < (b) ? (a) : (b)) + +struct bpf_subflow_send_info { __u8 subflow_id; __u64 linger_time; }; @@ -55,12 +58,12 @@ static __always_inline bool sk_stream_memory_free(const struct sock *sk) return __sk_stream_memory_free(sk, 0); } -SEC("struct_ops/mptcp_sched_burst_init") +SEC("struct_ops") void BPF_PROG(mptcp_sched_burst_init, struct mptcp_sock *msk) { } -SEC("struct_ops/mptcp_sched_burst_release") +SEC("struct_ops") void BPF_PROG(mptcp_sched_burst_release, struct mptcp_sock *msk) { } @@ -68,7 +71,7 @@ void BPF_PROG(mptcp_sched_burst_release, struct mptcp_sock *msk) static int bpf_burst_get_send(struct mptcp_sock *msk, struct mptcp_sched_data *data) { - struct subflow_send_info send_info[SSK_MODE_MAX]; + struct bpf_subflow_send_info send_info[SSK_MODE_MAX]; struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; __u32 pace, burst, wmem; @@ -182,8 +185,9 @@ static int bpf_burst_get_retrans(struct mptcp_sock *msk, return 0; } -int BPF_STRUCT_OPS(bpf_burst_get_subflow, struct mptcp_sock *msk, - struct mptcp_sched_data *data) +SEC("struct_ops") +int BPF_PROG(bpf_burst_get_subflow, struct mptcp_sock *msk, + struct mptcp_sched_data *data) { if (data->reinject) return bpf_burst_get_retrans(msk, data); diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c index 23a3e8e69e8fe..029ff06ee2d1d 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c @@ -1,23 +1,25 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022, SUSE. */ -#include -#include "bpf_tcp_helpers.h" +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" +#include char _license[] SEC("license") = "GPL"; -SEC("struct_ops/mptcp_sched_first_init") +SEC("struct_ops") void BPF_PROG(mptcp_sched_first_init, struct mptcp_sock *msk) { } -SEC("struct_ops/mptcp_sched_first_release") +SEC("struct_ops") void BPF_PROG(mptcp_sched_first_release, struct mptcp_sock *msk) { } -int BPF_STRUCT_OPS(bpf_first_get_subflow, struct mptcp_sock *msk, - struct mptcp_sched_data *data) +SEC("struct_ops") +int BPF_PROG(bpf_first_get_subflow, struct mptcp_sock *msk, + struct mptcp_sched_data *data) { mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, 0), true); return 0; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c index a3f3e5ca5278f..80023038ffbf8 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c @@ -1,23 +1,25 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022, SUSE. */ -#include -#include "bpf_tcp_helpers.h" +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" +#include char _license[] SEC("license") = "GPL"; -SEC("struct_ops/mptcp_sched_red_init") +SEC("struct_ops") void BPF_PROG(mptcp_sched_red_init, struct mptcp_sock *msk) { } -SEC("struct_ops/mptcp_sched_red_release") +SEC("struct_ops") void BPF_PROG(mptcp_sched_red_release, struct mptcp_sock *msk) { } -int BPF_STRUCT_OPS(bpf_red_get_subflow, struct mptcp_sock *msk, - struct mptcp_sched_data *data) +SEC("struct_ops") +int BPF_PROG(bpf_red_get_subflow, struct mptcp_sock *msk, + struct mptcp_sched_data *data) { for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { if (!bpf_mptcp_subflow_ctx_by_pos(data, i)) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c index 39b7e1cfbbd55..24586ee0645d4 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022, SUSE. */ -#include -#include "bpf_tcp_helpers.h" +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" +#include char _license[] SEC("license") = "GPL"; @@ -17,21 +18,22 @@ struct { __type(value, struct mptcp_rr_storage); } mptcp_rr_map SEC(".maps"); -SEC("struct_ops/mptcp_sched_rr_init") +SEC("struct_ops") void BPF_PROG(mptcp_sched_rr_init, struct mptcp_sock *msk) { bpf_sk_storage_get(&mptcp_rr_map, msk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); } -SEC("struct_ops/mptcp_sched_rr_release") +SEC("struct_ops") void BPF_PROG(mptcp_sched_rr_release, struct mptcp_sock *msk) { bpf_sk_storage_delete(&mptcp_rr_map, msk); } -int BPF_STRUCT_OPS(bpf_rr_get_subflow, struct mptcp_sock *msk, - struct mptcp_sched_data *data) +SEC("struct_ops") +int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk, + struct mptcp_sched_data *data) { struct mptcp_subflow_context *subflow; struct mptcp_rr_storage *ptr; diff --git a/tools/testing/selftests/bpf/progs/mptcp_subflow.c b/tools/testing/selftests/bpf/progs/mptcp_subflow.c index de9dbba37133e..32e86d6c7483d 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_subflow.c +++ b/tools/testing/selftests/bpf/progs/mptcp_subflow.c @@ -2,11 +2,8 @@ /* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2024, Kylin Software */ -#include // SOL_SOCKET, SO_MARK, ... -#include // TCP_CONGESTION -#include +#include "bpf_tracing_net.h" #include -#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL";