mptcp: sched: add subflow avoid flag
Subsystems (5)
v2 cover mptcp: sched: add subflow avoid flag
The core benches a subflow via the "stale" bit after net.mptcp.stale_loss_cnt retransmission intervals without progress. That bit is core-owned and RTO-coupled -- cleared as soon as a packet is acked on the subflow. A scheduler has no way to bench a subflow for its own reasons (high latency, instability) independently of ack traffic.
"scheduled" doesn't help either: the core clears it after every send/retrans pass, so it can't hold a standing "leave this alone" decision, and nothing outside the scheduler that set it can see it.
Changes since v1:
- avoid now lives in the existing __unused:8 bitfield padding instead of its own bool. No struct growth (Paolo).
- the selftest scheduler sets avoid once, on the first get_send() call, and only reads it back afterward -- proving persistence scheduled can't do, instead of just claiming it. A get_send_calls counter, asserted >1, makes sure multiple rounds actually ran (Paolo).
- mptcp_subflow_get_send() and mptcp_subflow_get_retrans() -- the default subflow picker, active with or without a custom scheduler -- now skip an avoided subflow next to the existing active-subflow check. avoid is also exposed via MPTCP diag (Paolo).
- set_avoid() marked __bpf_kfunc: it has no C callers, unlike set_scheduled(), and could be dropped under LTO before resolve_btfids finds it in BTF (review bot).
- added the missing extern __ksym for mptcp_subflow_active() in the selftest, matching mptcp_bpf_burst.c (review bot).
- moved the set_avoid extern out of mptcp_bpf.h into mptcp_bpf_avoid.c: checkpatch flags new externs in shared headers, and it has only the one caller.
Probing an avoided subflow to decide when to clear it (issue #348) is left out on purpose -- that's scheduler policy, not core mechanism.
Patch 1 adds the flag, the kfunc, default-scheduler enforcement, and diag support. Patch 2 reworks the selftest to prove persistence and picks up the missing extern.
Ran the full suite through mptcp-upstream-virtme-docker (auto-normal and auto-btf) -- selftests, packetdrill, and BPF tests pass, avoid subtest included.
Kalpan Jani (2):
mptcp: sched: add subflow avoid flag and enforce it in core
selftests: mptcp: bpf: exercise the subflow avoid flag across rounds
include/uapi/linux/mptcp.h | 1 + net/mptcp/bpf.c | 1 + net/mptcp/diag.c | 2 + net/mptcp/protocol.c | 4 +- net/mptcp/protocol.h | 5 +- net/mptcp/sched.c | 6 ++ .../testing/selftests/bpf/prog_tests/mptcp.c | 16 +++++ .../selftests/bpf/progs/mptcp_bpf_avoid.c | 70 +++++++++++++++++++ 8 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c
base-commit: 490b4823cb98b233af2b7562bddc90ecb5dfbf4e
Signature · 1 line
2.43.0
PATCH v2 1/2 mptcp: sched: add subflow avoid flag and enforce it in core
The core benches a subflow via the "stale" bit after net.mptcp.stale_loss_cnt retransmission intervals without progress. That bit belongs to the core and is tightly coupled to the RTO: it gets cleared as soon as a packet is acked on the subflow (mptcp_subflow_active() calls mptcp_subflow_set_active() once rcv_tstamp moves forward).
"scheduled" doesn't cover this either. The core clears it right after every send/retrans pass the scheduler set it in, so there's no way to express "leave this subflow alone across future rounds" with it, and nothing outside the scheduler that set it ever sees the value.
Add a scheduler-owned "avoid" bit to mptcp_subflow_context:
- only mptcp_subflow_set_avoid() touches it, never the core. It's exposed to BPF struct_ops schedulers as a kfunc with the same registration and filter as mptcp_subflow_set_scheduled(), so only a scheduler can call it;
- it sits in the existing __unused:8 padding of the flag bitfield rather than as its own bool, so the struct doesn't grow;
- it lives in the struct_group(reset) block, so it clears on subflow reset and a re-established path starts fresh;
- mptcp_subflow_get_send() and mptcp_subflow_get_retrans() -- the default in-kernel subflow picker -- now skip an avoided subflow next to the existing active-subflow check. This runs regardless of whether a custom scheduler is loaded, so the flag has real weight on core selection and isn't only meaningful to whatever BPF program happens to read it back. avoid defaults to false and only an explicit set_avoid() call flips it, so this is a no-op for anyone who doesn't use it;
- it's surfaced through MPTCP diag as MPTCP_SUBFLOW_FLAG_AVOID, alongside the existing BKUP/FULLY_ESTABLISHED flags.
set_avoid() has no C callers in-tree, unlike set_scheduled() which the core send/retrans/close paths call directly -- mark it __bpf_kfunc so it survives LTO/dead-code-elimination before resolve_btfids looks for it in BTF.
---
Changes since v1:
- moved avoid from a standalone bool into the existing __unused:8 bitfield padding: the extra bool pushed lent_mem_frag onto a 4-byte-aligned boundary, adding a 4-byte hole. The bitfield slot was already reserved and unused.
- marked mptcp_subflow_set_avoid() __bpf_kfunc: no C callers, unlike set_scheduled(), so it could be dropped under LTO before resolve_btfids finds it in BTF.
- switched subflow->avoid access from WRITE_ONCE()/READ_ONCE() to plain assignment/read: it's a bitfield member now, and {READ,WRITE}_ONCE() require taking its address, which bitfields don't allow.
- mptcp_subflow_get_send() and mptcp_subflow_get_retrans() now skip a subflow with avoid set, next to the existing active-subflow check:
previously nothing in the core consulted the flag.
- exposed avoid via MPTCP diag as MPTCP_SUBFLOW_FLAG_AVOID, next to the existing BKUP_LOC/FULLY_ESTABLISHED flags.
v1: https://lore.kernel.org/all/[email protected]/
--- include/uapi/linux/mptcp.h | 1 + net/mptcp/bpf.c | 1 + net/mptcp/diag.c | 2 ++ net/mptcp/protocol.c | 4 ++-- net/mptcp/protocol.h | 5 ++++- net/mptcp/sched.c | 6 ++++++ 6 files changed, 16 insertions(+), 3 deletions(-)
include/uapi/linux/mptcp.h +1 -0
@@ -22,6 +22,7 @@#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED _BITUL(6)#define MPTCP_SUBFLOW_FLAG_CONNECTED _BITUL(7)#define MPTCP_SUBFLOW_FLAG_MAPVALID _BITUL(8) +#define MPTCP_SUBFLOW_FLAG_AVOID _BITUL(9)#define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds"#define MPTCP_PM_EV_GRP_NAME "mptcp_pm_events"
net/mptcp/bpf.c +1 -0
@@ -318,6 +318,7 @@ BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) +BTF_ID_FLAGS(func, mptcp_subflow_set_avoid) BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_set_timeout)BTF_ID_FLAGS (func, mptcp_wnd_end)
net/mptcp/diag.c +2 -0
@@ -49,6 +49,8 @@ static int subflow_get_info(struct sock *sk, struct sk_buff *skb, bool net_admin flags |=MPTCP_SUBFLOW_FLAG_BKUP_LOC ;if (READ_ONCE (sf->fully_established)) flags |=MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED ; +if (sf->avoid) + flags |=MPTCP_SUBFLOW_FLAG_AVOID ;if (sf->conn_finished) flags |=MPTCP_SUBFLOW_FLAG_CONNECTED ;if (sf->map_valid)
net/mptcp/protocol.c +2 -2
@@ -1582,7 +1582,7 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)trace_mptcp_subflow_get_send (subflow); ssk =mptcp_subflow_tcp_sock (subflow); -if (!mptcp_subflow_active (subflow)) +if (!mptcp_subflow_active (subflow) || subflow->avoid)continue ; tout =max (tout,mptcp_timeout_from_subflow (subflow));
@@ -2501,7 +2501,7 @@ struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk)mptcp_for_each_subflow (msk, subflow) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow); -if (!__mptcp_subflow_active (subflow)) +if (!__mptcp_subflow_active (subflow) || subflow->avoid)continue ;/* still data outstanding at TCP level? skip this */
net/mptcp/protocol.h +4 -1
@@ -584,7 +584,8 @@ struct mptcp_subflow_context { is_mptfo : 1, /* subflow is doing TFO */ close_event_done : 1, /* has done the post-closed part */ mpc_drop : 1, /* the MPC option has been dropped in a rtx */ - __unused : 8; + avoid : 1, /* pkt scheduler: skip subflow if possible */ + __unused : 7;bool data_avail;bool scheduled;bool pm_listener;/* a listener managed by the kernel PM? */
@@ -897,6 +898,8 @@ static inline bool __mptcp_subflow_active(struct mptcp_subflow_context *subflow)void mptcp_subflow_set_active (struct mptcp_subflow_context *subflow); +void mptcp_subflow_set_avoid (struct mptcp_subflow_context *subflow,bool avoid); +bool mptcp_subflow_active (struct mptcp_subflow_context *subflow);void mptcp_subflow_drop_ctx (struct sock *ssk);
net/mptcp/sched.c +6 -0
@@ -165,6 +165,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,WRITE_ONCE (subflow->scheduled, scheduled); } +__bpf_kfunc void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow, +bool avoid) +{ + subflow->avoid = avoid; +} +int mptcp_sched_get_send (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow;
Signature · 1 line
2.43.0
PATCH v2 2/2 selftests: mptcp: bpf: exercise the subflow avoid flag across rounds
In reply to Kalpan JaniAdd a BPF struct_ops scheduler selftest for mptcp_subflow_set_avoid(), and add the required extern declarations for it and for mptcp_subflow_active(), both declared locally in this file rather than in the shared mptcp_bpf.h. mptcp_subflow_active()'s extern was missing here even though the other BPF scheduler progs already have it (see mptcp_bpf_burst.c).
"scheduled" gets cleared by the core after every single send/retrans pass, so a scheduler has to set it again every round. This test's scheduler does the opposite on purpose: it marks a subflow avoided exactly once, the first time get_send() runs, and never calls set_avoid() again after that. Every later round skips the marked subflow purely by reading back state set earlier. A counter of get_send() invocations, asserted greater than one once the transfer is done, makes sure the test actually ran more than one round instead of just assuming it from how much data got sent.
---
Changes since v1:
- reworked the scheduler to set avoid once, on the first get_send() call, and rely on reading it back on every later call rather than re-asserting it: the previous version set and read the flag within the same call, which doesn't exercise standing state across scheduling rounds. Added a get_send_calls counter, asserted >1, so the test enforces multiple rounds actually occurred.
- added the missing extern __ksym declaration for mptcp_subflow_active(), matching the existing pattern in mptcp_bpf_burst.c.
- declared the mptcp_subflow_set_avoid() extern in this file instead of mptcp_bpf.h: checkpatch flags new externs in shared headers, and this kfunc has only one caller.
v1: https://lore.kernel.org/all/[email protected]/
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 16 +++++ .../selftests/bpf/progs/mptcp_bpf_avoid.c | 70 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c
tools/testing/selftests/bpf/prog_tests/mptcp.c +16 -0
@@ -17,6 +17,7 @@#include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" #include "mptcp_bpf_red.skel.h" +#include "mptcp_bpf_avoid.skel.h" #include "mptcp_bpf_burst.skel.h" #define NS_TEST "mptcp_ns"
@@ -813,6 +814,19 @@ static void test_burst(void)mptcp_bpf_burst__destroy (skel); } +static void test_avoid (void ) +{ +struct mptcp_bpf_avoid *skel; + + skel =mptcp_bpf_avoid__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open_and_load: avoid" )) +return ; + +test_bpf_sched (skel->maps.avoid,"avoid" ,WITH_DATA ,WITHOUT_DATA ); +ASSERT_GT (skel->bss->get_send_calls,1 ,"get_send_calls" ); +mptcp_bpf_avoid__destroy (skel); +} +void test_mptcp (void ) {if (test__start_subtest ("base" ))
@@ -835,4 +849,6 @@ void test_mptcp(void)test_red ();if (test__start_subtest ("burst" ))test_burst (); +if (test__start_subtest ("avoid" )) +test_avoid (); }
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +68 -0
68 lines not on this page · raw message
+ .name = "bpf_avoid",
+};
Signature · 1 line
2.43.0