BPF packet scheduler
Subsystems (5)
v6 cover BPF packet scheduler
v6:
- fix the warning reported by kernel test robot:
Quoted 1 line
Quoted 1 line
net/mptcp/bpf.c:165:6: warning: no previous prototype for 'bpf_mptcp_subflow_set_scheduled' [-Wmissing-prototypes]
165 | void bpf_mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- rename bpf_mptcp_subflow_set_scheduled to mptcp_subflow_set_scheduled
v5:
- add bpf_mptcp_subflow_set_scheduled helper.
- drop padding bits before backup, use BPF_CORE_READ_BITFIELD_PROBED() instead.
- The new patch "mptcp: add bpf set scheduled helper" should be inserted between the commits "mptcp: add bpf_mptcp_sched_ops" and "selftests/bpf: add bpf_first scheduler"
v4:
- merge "mptcp: move is_scheduled into mptcp_subflow_context"
- rename bpf_backup tp bpf_bkup
- full patches of this series: https://github.com/geliangtang/mptcp_net-next
v3:
- use new BPF scheduler API:
- add backup scheduler
- add round-robin scheduler
- check bytes_sent of 'ss' output.
v2:
- Use new BPF scheduler API:
unsigned long (*get_subflow)(const struct mptcp_sock *msk, bool reinject,
struct mptcp_sched_data *data);
Geliang Tang (11):
Squash to "mptcp: add struct mptcp_sched_ops" Squash to "mptcp: add sched in mptcp_sock" Squash to "mptcp: add get_subflow wrappers" Squash to "mptcp: add bpf_mptcp_sched_ops"
mptcp: add subflow_set_scheduled helper Squash to "selftests/bpf: add bpf_first scheduler" Squash to "selftests/bpf: add bpf_first test" selftests/bpf: add bpf_bkup scheduler selftests/bpf: add bpf_bkup test selftests/bpf: add bpf_rr scheduler selftests/bpf: add bpf_rr test
include/net/mptcp.h | 7 +- net/mptcp/bpf.c | 34 ++++--- net/mptcp/protocol.h | 3 + net/mptcp/sched.c | 60 ++++++++++--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 17 +++- .../testing/selftests/bpf/prog_tests/mptcp.c | 89 ++++++++++++++++++- .../selftests/bpf/progs/mptcp_bpf_bkup.c | 43 +++++++++ .../selftests/bpf/progs/mptcp_bpf_first.c | 5 +- .../selftests/bpf/progs/mptcp_bpf_rr.c | 46 ++++++++++ 9 files changed, 272 insertions(+), 32 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Signature · 1 line
2.34.1
PATCH v6 1/11 Squash to "mptcp: add struct mptcp_sched_ops"
Use new BPF API.
Please update the commit log:
'''
This patch defines struct mptcp_sched_ops, which has three struct members, name, owner and list, and three function pointers, init(), release() and get_subflow().
The scheduler function get_subflow() has a struct mptcp_sched_data parameter, which contains a reinject flag and a mptcp_subflow_context array.
Add the scheduler registering, unregistering and finding functions to add, delete and find a packet scheduler on the global list mptcp_sched_list.
Add a new member scheduled in struct mptcp_subflow_context, which will be set in the MPTCP scheduler context when the scheduler picks this subflow to send data.
'''
--- include/net/mptcp.h | 7 ++++--- net/mptcp/protocol.h | 1 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-)
include/net/mptcp.h +4 -3
@@ -97,14 +97,15 @@ struct mptcp_out_options { };#define MPTCP_SCHED_NAME_MAX 16 +#define MPTCP_SUBFLOWS_MAX 8struct mptcp_sched_data { -struct sock *sock; -bool call_again; +bool reinject; +struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX ]; };struct mptcp_sched_ops { -void (*get_subflow)(const struct mptcp_sock *msk,bool reinject, +void (*get_subflow)(const struct mptcp_sock *msk,struct mptcp_sched_data *data);char name[MPTCP_SCHED_NAME_MAX ];
net/mptcp/protocol.h +1 -0
@@ -469,6 +469,7 @@ struct mptcp_subflow_context { valid_csum_seen :1 ;/* at least one csum validated */ enum mptcp_data_avail data_avail;bool mp_fail_response_expect; +bool scheduled;u32 remote_nonce;u64 thmac;u32 local_nonce;
tools/testing/selftests/bpf/bpf_tcp_helpers.h +8 -3
@@ -231,10 +231,15 @@ extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;#define MPTCP_SCHED_NAME_MAX 16 +#define MPTCP_SUBFLOWS_MAX 8 + +struct mptcp_subflow_context { +struct sock *tcp_sock;/* tcp sk backpointer */ +} __attribute__((preserve_access_index));struct mptcp_sched_data { -struct sock *sock; -bool call_again; +bool reinject; +struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX ]; };struct mptcp_sched_ops {
@@ -243,7 +248,7 @@ struct mptcp_sched_ops {void (*init)(const struct mptcp_sock *msk);void (*release)(const struct mptcp_sock *msk); -void (*get_subflow)(const struct mptcp_sock *msk,bool reinject, +void (*get_subflow)(const struct mptcp_sock *msk,struct mptcp_sched_data *data);void *owner; };
Signature · 1 line
2.34.1
PATCH v6 2/11 Squash to "mptcp: add sched in mptcp_sock"
In reply to Geliang TangNo need to export sched in bpf_tcp_helpers.h, drop it.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +0 -1
@@ -258,7 +258,6 @@ struct mptcp_sock {__u32 token;struct sock *first; -struct mptcp_sched_ops *sched;char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));
Signature · 1 line
2.34.1
PATCH v6 3/11 Squash to "mptcp: add get_subflow wrappers"
In reply to Geliang TangPlease update the commit log:
'''
This patch defines two new wrappers mptcp_sched_get_send() and mptcp_sched_get_retrans(), invoke get_subflow() of msk->sched in them. Use them instead of using mptcp_subflow_get_send() or mptcp_subflow_get_retrans() directly.
Set the subflow pointers array in struct mptcp_sched_data before invoking get_subflow(), then it can be used in get_subflow() in the BPF contexts.
Check the subflow scheduled flags to test which subflow or subflows are picked by the scheduler.
'''
--- net/mptcp/sched.c | 53 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-)
net/mptcp/sched.c +42 -11
@@ -88,11 +88,24 @@ void mptcp_release_sched(struct mptcp_sock *msk)bpf_module_put (sched, sched->owner); } -static int mptcp_sched_data_init (struct mptcp_sock *msk, +static int mptcp_sched_data_init (struct mptcp_sock *msk,bool reinject,struct mptcp_sched_data *data) { - data->sock =NULL ; - data->call_again =0 ; +struct mptcp_subflow_context *subflow; +int i =0 ; + + data->reinject = reinject; + +mptcp_for_each_subflow (msk, subflow) { +if (i ==MPTCP_SUBFLOWS_MAX ) { +pr_warn_once ("too many subflows" ); +break ; + } + data->contexts[i++] = subflow; + } + +for (; i <MPTCP_SUBFLOWS_MAX ; i++) + data->contexts[i] =NULL ;return 0 ; }
@@ -100,6 +113,8 @@ static int mptcp_sched_data_init(struct mptcp_sock *msk,struct sock *mptcp_sched_get_send (struct mptcp_sock *msk) {struct mptcp_sched_data data; +struct sock *ssk =NULL ; +int i;sock_owned_by_me ((struct sock *)msk);
@@ -113,16 +128,25 @@ struct sock *mptcp_sched_get_send(struct mptcp_sock *msk)if (!msk->sched)return mptcp_subflow_get_send (msk); -mptcp_sched_data_init (msk, &data); - msk->sched->get_subflow (msk, false, &data); +mptcp_sched_data_init (msk, false, &data); + msk->sched->get_subflow (msk, &data); + +for (i =0 ; i <MPTCP_SUBFLOWS_MAX ; i++) { +if (data.contexts[i] &&READ_ONCE (data.contexts[i]->scheduled)) { + ssk = data.contexts[i]->tcp_sock; + msk->last_snd = ssk; +break ; + } + } - msk->last_snd = data.sock; -return data.sock; +return ssk; }struct sock *mptcp_sched_get_retrans (struct mptcp_sock *msk) {struct mptcp_sched_data data; +struct sock *ssk =NULL ; +int i;sock_owned_by_me ((const struct sock *)msk);
@@ -133,9 +157,16 @@ struct sock *mptcp_sched_get_retrans(struct mptcp_sock *msk)if (!msk->sched)return mptcp_subflow_get_retrans (msk); -mptcp_sched_data_init (msk, &data); - msk->sched->get_subflow (msk, true, &data); +mptcp_sched_data_init (msk, true, &data); + msk->sched->get_subflow (msk, &data); + +for (i =0 ; i <MPTCP_SUBFLOWS_MAX ; i++) { +if (data.contexts[i] &&READ_ONCE (data.contexts[i]->scheduled)) { + ssk = data.contexts[i]->tcp_sock; + msk->last_snd = ssk; +break ; + } + } - msk->last_snd = data.sock; -return data.sock; +return ssk; }
Signature · 1 line
2.34.1
PATCH v6 4/11 Squash to "mptcp: add bpf_mptcp_sched_ops"
In reply to Geliang TangChange the access code from mptcp_sched_data to mptcp_subflow_context.
--- net/mptcp/bpf.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
net/mptcp/bpf.c +8 -10
@@ -42,29 +42,27 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log, {size_t end; -if (atype ==BPF_READ ) +if (atype ==BPF_READ ) {return btf_struct_access (log, btf, t, off, size, atype, next_btf_id, flag); + }if (t != mptcp_sched_type) { -bpf_log (log,"only access to mptcp_sched_data is supported\n" ); +bpf_log (log,"only access to mptcp_subflow_context is supported\n" );return -EACCES ; }switch (off) { -case offsetof(struct mptcp_sched_data , sock): - end = offsetofend(struct mptcp_sched_data, sock); -break ; -case offsetof(struct mptcp_sched_data , call_again): - end = offsetofend(struct mptcp_sched_data, call_again); +case offsetof(struct mptcp_subflow_context , scheduled): + end = offsetofend(struct mptcp_subflow_context, scheduled);break ;default : -bpf_log (log,"no write support to mptcp_sched_data at off %d\n" , off); +bpf_log (log,"no write support to mptcp_subflow_context at off %d\n" , off);return -EACCES ; }if (off + size > end) { -bpf_log (log,"access beyond mptcp_sched_data at off %u size %u ended at %zu" , +bpf_log (log,"access beyond mptcp_subflow_context at off %u size %u ended at %zu" , off, size, end);return -EACCES ; }
@@ -144,7 +142,7 @@ static int bpf_mptcp_sched_init(struct btf *btf) {s32 type_id; - type_id =btf_find_by_name_kind (btf,"mptcp_sched_data" , + type_id =btf_find_by_name_kind (btf,"mptcp_subflow_context" ,BTF_KIND_STRUCT );if (type_id <0 )return -EINVAL ;
Signature · 1 line
2.34.1
PATCH v6 5/11 mptcp: add subflow_set_scheduled helper
In reply to Geliang TangThis patch adds a new helper mptcp_subflow_set_scheduled() to set the scheduled flag of struct mptcp_subflow_context using WRITE_ONCE(). Register this helper in bpf_mptcp_sched_kfunc_init() to make sure it can be accessed from the BPF context.
--- net/mptcp/bpf.c | 16 ++++++++++++++++ net/mptcp/protocol.h | 2 ++ net/mptcp/sched.c | 7 +++++++ tools/testing/selftests/bpf/bpf_tcp_helpers.h | 3 +++ 4 files changed, 28 insertions(+)
net/mptcp/bpf.c +16 -0
@@ -161,6 +161,22 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = { .init = bpf_mptcp_sched_init, .name = "mptcp_sched_ops", }; + +BTF_SET_START (bpf_mptcp_sched_kfunc_ids) +BTF_ID (func ,mptcp_subflow_set_scheduled ) +BTF_SET_END (bpf_mptcp_sched_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { + .owner =THIS_MODULE , + .check_set = &bpf_mptcp_sched_kfunc_ids, +}; + +static int __init bpf_mptcp_sched_kfunc_init (void ) +{ +return register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , + &bpf_mptcp_sched_kfunc_set); +} +late_initcall (bpf_mptcp_sched_kfunc_init);#endif /* CONFIG_BPF_JIT */ struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk)
net/mptcp/protocol.h +2 -0
@@ -629,6 +629,8 @@ void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);int mptcp_init_sched (struct mptcp_sock *msk,struct mptcp_sched_ops *sched);void mptcp_release_sched (struct mptcp_sock *msk); +void mptcp_subflow_set_scheduled (struct mptcp_subflow_context *subflow, +bool scheduled);struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk);struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk);struct sock *mptcp_sched_get_send (struct mptcp_sock *msk);
net/mptcp/sched.c +7 -0
@@ -88,6 +88,12 @@ void mptcp_release_sched(struct mptcp_sock *msk)bpf_module_put (sched, sched->owner); } +void mptcp_subflow_set_scheduled (struct mptcp_subflow_context *subflow, +bool scheduled) +{ +WRITE_ONCE (subflow->scheduled, scheduled); +} +static int mptcp_sched_data_init (struct mptcp_sock *msk,bool reinject,struct mptcp_sched_data *data) {
@@ -101,6 +107,7 @@ static int mptcp_sched_data_init(struct mptcp_sock *msk, bool reinject,pr_warn_once ("too many subflows" );break ; } +mptcp_subflow_set_scheduled (subflow, false); data->contexts[i++] = subflow; }
tools/testing/selftests/bpf/bpf_tcp_helpers.h +3 -0
@@ -261,4 +261,7 @@ struct mptcp_sock {char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index)); +extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, + bool scheduled) __ksym; +#endif
Signature · 1 line
2.34.1
PATCH v6 6/11 Squash to "selftests/bpf: add bpf_first scheduler"
In reply to Geliang TangUse new get_subflow API.
--- tools/testing/selftests/bpf/progs/mptcp_bpf_first.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_first.c +2 -3
@@ -17,10 +17,9 @@ void BPF_PROG(mptcp_sched_first_release, const struct mptcp_sock *msk) }void BPF_STRUCT_OPS (bpf_first_get_subflow ,const struct mptcp_sock *msk, -bool reinject,struct mptcp_sched_data *data) +struct mptcp_sched_data *data) { - data->sock = msk->first; - data->call_again =0 ; +mptcp_subflow_set_scheduled (data->contexts[0 ], true); }SEC (".struct_ops" )
Signature · 1 line
2.34.1
PATCH v6 7/11 Squash to "selftests/bpf: add bpf_first test"
In reply to Geliang TangAdd two helpers, add_veth() and cleanup().
Please update the commit log:
'''
This patch expends the MPTCP test base to support MPTCP packet scheduler tests. Add the bpf_first scheduler test in it.
Use sysctl to set net.mptcp.scheduler to use this sched. The new helper add_veth() adds a veth net device to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add this new endpoint to PM netlink.
Some code in send_data() is from prog_tests/bpf_tcp_ca.c.
Check bytes_sent of 'ss' output after send_data() to make sure no data has been sent on the new veth net device. All data has been sent on the first subflow.
Invoke the new helper cleanup() to set back net.mptcp.scheduler to default, flush all mptcp endpoints, and delete the veth net device.
'''
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +18 -1
@@ -250,6 +250,20 @@ static void send_data(int lfd, int fd) PTR_ERR(thread_ret)); } +static void add_veth (void ) +{ +system ("ip link add veth1 type veth" ); +system ("ip addr add 10.0.1.1/24 dev veth1" ); +system ("ip link set veth1 up" ); +} + +static void cleanup (void ) +{ +system ("sysctl -qw net.mptcp.scheduler=default" ); +system ("ip mptcp endpoint flush" ); +system ("ip link del veth1" ); +} +static void test_first (void ) {struct mptcp_bpf_first *first_skel;
@@ -266,15 +280,18 @@ static void test_first(void)return ; } +add_veth (); +system ("ip mptcp endpoint add 10.0.1.1 subflow" );system ("sysctl -qw net.mptcp.scheduler=bpf_first" ); server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); client_fd =connect_to_fd (server_fd,0 );send_data (server_fd, client_fd); +ASSERT_GT (system ("ss -MOenita | grep '10.0.1.1' | grep 'bytes_sent:'" ),0 ,"ss" );close (client_fd);close (server_fd); -system ("sysctl -qw net.mptcp.scheduler=default" ); +cleanup ();bpf_link__destroy (link);mptcp_bpf_first__destroy (first_skel); }
Signature · 1 line
2.34.1
PATCH v6 8/11 selftests/bpf: add bpf_bkup scheduler
In reply to Geliang TangThis patch implements the backup flag test scheduler, named bpf_bkup, which picks the first non-backup subflow to send data.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + .../selftests/bpf/progs/mptcp_bpf_bkup.c | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -234,6 +234,7 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;#define MPTCP_SUBFLOWS_MAX 8struct mptcp_subflow_context { +__u32 backup :1 ;struct sock *tcp_sock;/* tcp sk backpointer */ } __attribute__((preserve_access_index));
tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v6 9/11 selftests/bpf: add bpf_bkup test
In reply to Geliang TangThis patch adds the backup BPF MPTCP scheduler test. Use sysctl to set net.mptcp.scheduler to use this sched. Add a veth net device to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add this new endpoint to PM netlink with backup flag. Send data, check bytes_sent of 'ss' output, and do some cleanups.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +35 -0
@@ -7,6 +7,7 @@#include "network_helpers.h" #include "mptcp_sock.skel.h" #include "mptcp_bpf_first.skel.h" +#include "mptcp_bpf_bkup.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16
@@ -296,10 +297,44 @@ static void test_first(void)mptcp_bpf_first__destroy (first_skel); } +static void test_bkup (void ) +{ +struct mptcp_bpf_bkup *bkup_skel; +int server_fd, client_fd; +struct bpf_link *link; + + bkup_skel =mptcp_bpf_bkup__open_and_load (); +if (!ASSERT_OK_PTR (bkup_skel,"bpf_bkup__open_and_load" )) +return ; + + link =bpf_map__attach_struct_ops (bkup_skel->maps.bkup); +if (!ASSERT_OK_PTR (link,"bpf_map__attach_struct_ops" )) { +mptcp_bpf_bkup__destroy (bkup_skel); +return ; + } + +add_veth (); +system ("ip mptcp endpoint add 10.0.1.1 subflow backup" ); +system ("sysctl -qw net.mptcp.scheduler=bpf_bkup" ); + server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); + client_fd =connect_to_fd (server_fd,0 ); + +send_data (server_fd, client_fd); +ASSERT_GT (system ("ss -MOenita | grep '10.0.1.1' | grep 'bytes_sent:'" ),0 ,"ss" ); + +close (client_fd); +close (server_fd); +cleanup (); +bpf_link__destroy (link); +mptcp_bpf_bkup__destroy (bkup_skel); +} +void test_mptcp (void ) {if (test__start_subtest ("base" ))test_base ();if (test__start_subtest ("first" ))test_first (); +if (test__start_subtest ("bkup" )) +test_bkup (); }
Signature · 1 line
2.34.1
PATCH v6 10/11 selftests/bpf: add bpf_rr scheduler
In reply to Geliang TangThis patch implements the round-robin BPF MPTCP scheduler, named bpf_rr, which always picks the next available subflow to send data. If no such next subflow available, picks the first one.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + .../selftests/bpf/progs/mptcp_bpf_rr.c | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -257,6 +257,7 @@ struct mptcp_sched_ops {struct mptcp_sock {struct inet_connection_sock sk; +struct sock *last_snd;__u32 token;struct sock *first;char ca_name[TCP_CA_NAME_MAX ];
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v6 11/11 selftests/bpf: add bpf_rr test
In reply to Geliang TangThis patch adds the round-robin BPF MPTCP scheduler test. Use sysctl to set net.mptcp.scheduler to use this sched. Add a veth net device to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add this new endpoint to PM netlink. Send data and check bytes_sent of 'ss' output after it to make sure the data has been sent on the new veth net device.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +35 -0
@@ -8,6 +8,7 @@#include "mptcp_sock.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" +#include "mptcp_bpf_rr.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16
@@ -329,6 +330,38 @@ static void test_bkup(void)mptcp_bpf_bkup__destroy (bkup_skel); } +static void test_rr (void ) +{ +struct mptcp_bpf_rr *rr_skel; +int server_fd, client_fd; +struct bpf_link *link; + + rr_skel =mptcp_bpf_rr__open_and_load (); +if (!ASSERT_OK_PTR (rr_skel,"bpf_rr__open_and_load" )) +return ; + + link =bpf_map__attach_struct_ops (rr_skel->maps.rr); +if (!ASSERT_OK_PTR (link,"bpf_map__attach_struct_ops" )) { +mptcp_bpf_rr__destroy (rr_skel); +return ; + } + +add_veth (); +system ("ip mptcp endpoint add 10.0.1.1 subflow" ); +system ("sysctl -qw net.mptcp.scheduler=bpf_rr" ); + server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); + client_fd =connect_to_fd (server_fd,0 ); + +send_data (server_fd, client_fd); +ASSERT_OK (system ("ss -MOenita | grep '10.0.1.1' | grep -q 'bytes_sent:'" ),"ss" ); + +close (client_fd); +close (server_fd); +cleanup (); +bpf_link__destroy (link); +mptcp_bpf_rr__destroy (rr_skel); +} +void test_mptcp (void ) {if (test__start_subtest ("base" ))
@@ -337,4 +370,6 @@ void test_mptcp(void)test_first ();if (test__start_subtest ("bkup" ))test_bkup (); +if (test__start_subtest ("rr" )) +test_rr (); }
Signature · 1 line
2.34.1
Re: selftests/bpf: add bpf_rr test: Build Failure
Hi Geliang,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://patchwork.kernel.org/project/mptcp/patch/94de6d463bde36d3ad8e50324b9c40ce9ae36467.1654092153.git.geliang.tang@suse.com/
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/2422165357
Status: failure
Initiator: MPTCPimporter
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4d61a8b660c4
Feel free to reply to this email if you cannot access logs, if you need some support to fix the error, if this doesn't seem to be caused by your modifications or if the error is a false positive one.
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
Re: selftests/bpf: add bpf_rr test: Build Failure
Hi Geliang,
Thank you for the new version!
Quoted 10 lines · MPTCP CI
Hi Geliang,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://patchwork.kernel.org/project/mptcp/patch/94de6d463bde36d3ad8e50324b9c40ce9ae36467.1654092153.git.geliang.tang@suse.com/
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/2422165357
Regarding these errors, are they normal? I mean: will they be removed after having applied the different Squash-to patch?
I guess for these ones yes:
net/mptcp/sched.c: In function 'mptcp_sched_data_init':
net/mptcp/sched.c:94:6: error: 'struct mptcp_sched_data' has no member
named 'sock'
94 | data->sock = NULL;
| ^~(...)
But also for these ones?
In file included from ./include/uapi/linux/posix_types.h:5,
from ./include/uapi/linux/types.h:14,
from ./include/linux/types.h:6,
from ./include/uapi/linux/bpf.h:11,
from ./include/linux/bpf.h:7,
from net/mptcp/bpf.c:12: net/mptcp/bpf.c: In function 'bpf_mptcp_sched_btf_struct_access':
./include/linux/stddef.h:16:32: error: 'struct mptcp_sched_data' has
no member named 'sock'
16 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
| ^~~~~~~~~~~~~~~~~~
net/mptcp/bpf.c:55:7: note: in expansion of macro 'offsetof'
55 | case offsetof(struct mptcp_sched_data, sock):
| ^~~~~~~~
(...)
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Re: selftests/bpf: add bpf_rr test: Tests Results
In reply to Geliang TangHi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6191871876661248
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6191871876661248/summary/summary.txt
- KVM Validation: debug:
- Unstable: 1 failed test(s): selftest_diag 🔴:
- Task: https://cirrus-ci.com/task/4951362948562944
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4951362948562944/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4d61a8b660c4
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
Re: selftests/bpf: add bpf_rr test: Build Failure
In reply to Matthieu BaertsHi Matt,
Quoted 11 lines · Matthieu Baerts
Hi Geliang,
Thank you for the new version!
Quoted 6 lines · MPTCP CI
Hi Geliang,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
Quoted 7 lines
Quoted 4 lines
You can find more details there:
https://patchwork.kernel.org/project/mptcp/patch/94de6d463bde36d3ad8e50324b9c40ce9ae36467.1654092153.git.geliang.tang@suse.com/
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/2422165357Regarding these errors, are they normal? I mean: will they be removed after having applied the different Squash-to patch?
Yes, they will be removed after having applied all the squash-to patches.
Quoted 9 lines
I guess for these ones yes:
net/mptcp/sched.c: In function 'mptcp_sched_data_init':
net/mptcp/sched.c:94:6: error: 'structmptcp_sched_data' has no member
named 'sock'94 | data->sock = NULL; | ^~(...)
This will be removed by "Squash to "mptcp: add get_subflow wrappers"".
Quoted 10 lines
But also for these ones?
In file included from
./include/uapi/linux/posix_types.h:5,from ./include/uapi/linux/types.h:14, from ./include/linux/types.h:6, from ./include/uapi/linux/bpf.h:11, from ./include/linux/bpf.h:7, from net/mptcp/bpf.c:12:
Quoted 9 lines
net/mptcp/bpf.c: In function 'bpf_mptcp_sched_btf_struct_access':
./include/linux/stddef.h:16:32: error: 'structmptcp_sched_data' has
no member named 'sock'
16 | #defineoffsetof(TYPE, MEMBER)__builtin_offsetof(TYPE, MEMBER)
| ^~~~~~~~~~~~~~~~~~
net/mptcp/bpf.c:55:7: note: in expansion of macro 'offsetof'
55 | caseoffsetof(struct mptcp_sched_data, sock):
| ^~~~~~~~
(...)
And this will be removed by "Squash to "mptcp: add bpf_mptcp_sched_ops"".
Thanks,
-Geliang
Quoted 8 lines
Cheers,
MattSignature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Quoted 8 lines · Geliang Tang
v6:
- fix the warning reported by kernel test robot:Quoted 1 line
Quoted 1 line
net/mptcp/bpf.c:165:6: warning: no previous prototype for 'bpf_mptcp_subflow_set_scheduled' [-Wmissing-prototypes]165 | void
bpf_mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- renamebpf_mptcp_subflow_set_scheduledtomptcp_subflow_set_scheduled
I think these should be squashed/applied to the export branch. Any other fixes can be squashed later.
I have a minor change to suggest in patch 5, I'll reply to that separately.
- Mat
Quoted 47 lines
v5:
- addbpf_mptcp_subflow_set_scheduledhelper.
- drop padding bits before backup, useBPF_CORE_READ_BITFIELD_PROBED()instead.
- The new patch "mptcp: add bpf set scheduled helper" should be inserted between the commits "mptcp: addbpf_mptcp_sched_ops" and "selftests/bpf: addbpf_firstscheduler"v4:
- merge "mptcp: moveis_scheduledintomptcp_subflow_context"
- renamebpf_backuptpbpf_bkup
- full patches of this series: https://github.com/geliangtang/mptcp_net-nextv3:
- use new BPF scheduler API:
- add backup scheduler
- add round-robin scheduler
- checkbytes_sentof 'ss' output.v2:
- Use new BPF scheduler API:
unsigned long (*get_subflow)(const structmptcp_sock*msk, bool reinject,struct mptcp_sched_data *data);Geliang Tang (11):
Squash to "mptcp: add structmptcp_sched_ops" Squash to "mptcp: add sched inmptcp_sock" Squash to "mptcp: addget_subflowwrappers" Squash to "mptcp: addbpf_mptcp_sched_ops"
mptcp: addsubflow_set_scheduledhelper Squash to "selftests/bpf: addbpf_firstscheduler" Squash to "selftests/bpf: addbpf_firsttest" selftests/bpf: addbpf_bkupscheduler selftests/bpf: addbpf_bkuptest selftests/bpf: addbpf_rrscheduler selftests/bpf: addbpf_rrtestinclude/net/mptcp.h | 7 +- net/mptcp/bpf.c | 34 ++++--- net/mptcp/protocol.h | 3 + net/mptcp/sched.c | 60 ++++++++++--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 17 +++- .../testing/selftests/bpf/prog_tests/mptcp.c | 89 ++++++++++++++++++- .../selftests/bpf/progs/mptcp_bpf_bkup.c | 43 +++++++++ .../selftests/bpf/progs/mptcp_bpf_first.c | 5 +- .../selftests/bpf/progs/mptcp_bpf_rr.c | 46 ++++++++++ 9 files changed, 272 insertions(+), 32 deletions(-)
Quoted 8 lines
create mode 100644
tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.ccreate mode 100644tools/testing/selftests/bpf/progs/mptcp_bpf_rr.cSignature · 1 line
2.34.1
--
Mat Martineau
Intel
Re: [PATCH mptcp-next v6 05/11] mptcp: add subflow_set_scheduled helper
In reply to Geliang TangQuoted 11 lines · Geliang Tang
This patch adds a new helper
mptcp_subflow_set_scheduled()to set the scheduled flag of structmptcp_subflow_contextusingWRITE_ONCE(). Register this helper inbpf_mptcp_sched_kfunc_init()to make sure it can be accessed from the BPF context.Signed-off-by Geliang Tang <[email protected]>---
net/mptcp/bpf.c | 16 ++++++++++++++++ net/mptcp/protocol.h | 2 ++ net/mptcp/sched.c | 7 +++++++ tools/testing/selftests/bpf/bpf_tcp_helpers.h | 3 +++
Geliang -
This commit changes both bpf_tcp_helpers.h and MPTCP core code. There are different upstreaming requirements for bpf_tcp_helpers.h since the BPF maintainers own that file.
Could you split the changes to bpf_tcp_helpers.h in this commit, and in the others already in the export branch, in to a separate "MPTCP BPF helper" commit before "selftests/bpf: add bpf_first scheduler"? I think that will make it easier to upstream commits that don't need to go through the BPF maintainers.
Quoted 47 lines
4 files changed, 28 insertions(+)net/mptcp/bpf.c +16
-0@@ -161,6 +161,22 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = { .init = bpf_mptcp_sched_init, .name = "mptcp_sched_ops", }; + +BTF_SET_START (bpf_mptcp_sched_kfunc_ids) +BTF_ID (func ,mptcp_subflow_set_scheduled ) +BTF_SET_END (bpf_mptcp_sched_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { + .owner =THIS_MODULE , + .check_set = &bpf_mptcp_sched_kfunc_ids, +}; + +static int __init bpf_mptcp_sched_kfunc_init (void ) +{ +return register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , + &bpf_mptcp_sched_kfunc_set); +} +late_initcall (bpf_mptcp_sched_kfunc_init);#endif /* CONFIG_BPF_JIT */ struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk)net/mptcp/protocol.h +2
-0@@ -629,6 +629,8 @@ void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);int mptcp_init_sched (struct mptcp_sock *msk,struct mptcp_sched_ops *sched);void mptcp_release_sched (struct mptcp_sock *msk); +void mptcp_subflow_set_scheduled (struct mptcp_subflow_context *subflow, +bool scheduled);struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk);struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk);struct sock *mptcp_sched_get_send (struct mptcp_sock *msk);net/mptcp/sched.c +0
-0
net/mptcp/sched.c void mptcp_release_sched(struct mptcp_sock *msk) · line 95
Quoted 8 lines
net/mptcp/sched.c +5
-0@@ -88,6 +88,12 @@ void mptcp_release_sched(struct mptcp_sock *msk)bpf_module_put (sched, sched->owner); } +void mptcp_subflow_set_scheduled (struct mptcp_subflow_context *subflow, +bool scheduled) +{ +WRITE_ONCE (subflow->scheduled, scheduled); +}
As far as I can tell, it is safe to call a function like this from BPF code. I modified the bpf_first test to try to pass a bad subflow pointer in a few different ways, and the BPF verifier caught it.
I'm curious, have you found any documentation for how the verifier checks args for kfunc calls? I'd like to understand that better and will keep searching.
Thanks,
Mat
Quoted 29 lines
net/mptcp/sched.c +2
-0+static int mptcp_sched_data_init (struct mptcp_sock *msk,bool reinject,struct mptcp_sched_data *data) {@@ -101,6 +107,7 @@ static int mptcp_sched_data_init(struct mptcp_sock *msk, bool reinject,pr_warn_once ("too many subflows" );break ; } +mptcp_subflow_set_scheduled (subflow, false); data->contexts[i++] = subflow; }tools/testing/selftests/bpf/bpf_tcp_helpers.h +3
-0@@ -261,4 +261,7 @@ struct mptcp_sock {char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index)); +extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, + bool scheduled) __ksym; +#endif Signature · 1 line
2.34.1
--
Mat Martineau
Intel