Skip to contentSkip to conversation

mptcp: add scheduler-owned subflow avoid flag

PATCH Superseded Kalpan Jani 3 participants 7 messages Nov 23 – Nov 25

Subsystems (5)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover mptcp: add scheduler-owned subflow avoid flag

The MPTCP scheduler needs a persistent way for BPF schedulers to mark a subflow as one that should be avoided across scheduling rounds.

The existing stale and scheduled states do not provide this scheduler-owned behaviour.

This series introduces an avoid flag in mptcp_subflow_context, exposes it to BPF struct_ops schedulers through a kfunc, and exports its state through MPTCP diagnostics.

BPF schedulers can set the flag and must explicitly check it when selecting subflows. The flag does not change the behaviour of the default in-kernel scheduler.

The second patch adds a BPF struct_ops selftest that marks a subflow as avoided once and verifies that it remains skipped across subsequent scheduling rounds.

Changes since v6:
- Removed unreachable avoid checks from the default send and retransmission subflow pickers.
- Clarified that BPF schedulers must explicitly honour the avoid flag.
- Updated the first patch description to reflect BPF scheduler ownership.

Kalpan Jani (2):
mptcp: sched: add subflow avoid flag for BPF schedulers
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.h                          |  3 +
 net/mptcp/sched.c                             |  6 ++
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++
 .../selftests/bpf/progs/mptcp_bpf_avoid.c     | 87 +++++++++++++++++++
 7 files changed, 115 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v7 1/2 mptcp: sched: add subflow avoid flag for BPF schedulers

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" bool to mptcp_subflow_context:

- only mptcp_subflow_set_avoid() writes it. It is exposed to BPF struct_ops schedulers as a kfunc with the same registration and filter as mptcp_subflow_set_scheduled(), so only a BPF scheduler can change its value;

- it is a standalone bool, alongside "scheduled" and "data_avail", rather than a bit in the adjacent flag bitfield. mptcp_subflow_data_available()
clears map_valid, a bit in that bitfield, from the subflow's own receive path without holding the msk lock, while set_avoid() runs under the msk lock from BPF scheduler context. Bitfield writes are a non-atomic read-modify-write on the whole containing word, so placing avoid there would race with that update and risk silently corrupting map_valid or other neighbouring bits. The standalone bool is accessed with READ_ONCE()/WRITE_ONCE() for the same reason;

- the flag is exported through MPTCP diagnostics, allowing userspace to observe whether a subflow has been marked as avoided.

BPF schedulers must explicitly check subflow->avoid when selecting subflows. The flag is scheduler-owned and does not change the behavior of the default in-kernel scheduler.

---
Changes since v6:
- Removed the unreachable avoid checks from the default send and retransmission subflow pickers.
- Clarified that the avoid flag is owned and enforced by BPF schedulers.

v6: 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.h       | 3 +++
 net/mptcp/sched.c          | 6 ++++++
 5 files changed, 13 insertions(+)
include/uapi/linux/mptcp.h +1 -0
index 72a5d030154e1..b4ca97e074453 100644
@@ -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
index 74648ca1e99b5..6fcd2bb5e6bdd 100644
@@ -312,6 +312,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
index 70cf9ebce8338..7a2c40a63dfa4 100644
@@ -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 (READ_ONCE(sf->avoid))
+		flags |= MPTCP_SUBFLOW_FLAG_AVOID;
 	if (sf->conn_finished)
 		flags |= MPTCP_SUBFLOW_FLAG_CONNECTED;
 	if (sf->map_valid)
net/mptcp/protocol.h +3 -0
index 9febcaf84762d..24e2540c05caa 100644
@@ -607,6 +607,7 @@ struct mptcp_subflow_context {
 		__unused : 9;
 	bool	data_avail;
 	bool	scheduled;
+	bool	avoid;		    /* pkt scheduler: skip subflow if possible */
 	bool	pm_listener;	    /* a listener managed by the kernel PM? */
 	bool	fully_established;  /* path validated */
 	bool	close_event_done;   /* has done the post-closed part,
@@ -935,6 +936,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
index 1e59072d478c9..0ce59eb093df6 100644
@@ -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)
+{
+	WRITE_ONCE(subflow->avoid, avoid);
+}
+
 int mptcp_sched_get_send(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH mptcp-next v7 1/2] mptcp: sched: add subflow avoid flag for BPF schedulers

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mptcp: sched: subflow avoid flag is unused by MPTCP core --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mptcp: sched: subflow avoid flag is unused by MPTCP core --

commit 0e785089a6ea448f3459342cf4c1519134065b30
Author: Kalpan Jani <[email protected]>

mptcp: sched: add subflow avoid flag for BPF schedulers

This commit adds an avoid boolean to struct mptcp_subflow_context, a mptcp_subflow_set_avoid() BPF kfunc for struct_ops packet schedulers, and the MPTCP_SUBFLOW_FLAG_AVOID diagnostic flag.

Quoted 7 lines
net/mptcp/sched.c +0 -0
index 1e59072d478c9..0ce59eb093df6 100644
@@ -165,6 +165,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 	WRITE_ONCE(subflow->scheduled, scheduled);
 }

net/mptcp/sched.c void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, · line 176

Quoted 10 lines
net/mptcp/sched.c +6 -0
 
+__bpf_kfunc void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow,
+					 bool avoid)
+{
+	WRITE_ONCE(subflow->avoid, avoid);
+}
+
 int mptcp_sched_get_send(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;

[Severity: Medium]
As reported by Paolo Abeni on v1 [1], what does subflow->avoid provide when the MPTCP core never reads or acts on it?

Outside of subflow_get_info() exporting MPTCP_SUBFLOW_FLAG_AVOID for diagnostics, nothing in the MPTCP core checks subflow->avoid during scheduling, transmission, retransmission, or activity evaluation. A BPF scheduler calling mptcp_subflow_set_avoid() only stores a boolean for that same BPF scheduler to read back before calling mptcp_subflow_set_scheduled(), without changing any core subflow handling.

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH mptcp-next v7 1/2] mptcp: sched: add subflow avoid flag for BPF schedulers

In reply to Kalpan Jani
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] mptcp: sched: subflow avoid flag is unused by MPTCP core
- [Low] The commit message says "only mptcp_subflow_set_avoid() writes it ... so only a BPF scheduler can change its value".
- [Low] The new kfunc mptcp_subflow_set_avoid() (net/mptcp/sched.c) stores a BPF-supplied bool avoid with `WRITE_ONCE(subflow->avoid,…

--

mptcp: sched: add subflow avoid flag for BPF schedulers

This patch adds an "avoid" bool to struct mptcp_subflow_context. BPF struct_ops schedulers set it through a new mptcp_subflow_set_avoid() kfunc. The flag is also exported to userspace through MPTCP diag as MPTCP_SUBFLOW_FLAG_AVOID.

Quoted 6 lines

Add a scheduler-owned "avoid" bool to mptcp_subflow_context:

- only mptcp_subflow_set_avoid() writes it. It is exposed to BPF struct_ops schedulers as a kfunc with the same registration and filter as mptcp_subflow_set_scheduled(), so only a BPF scheduler can change its value;

[Severity: Low]
Is this description accurate? The new field is declared inside struct_group(reset, ...) in struct mptcp_subflow_context. That means mptcp_subflow_ctx_reset() also clears it:

net/mptcp/protocol.h:mptcp_subflow_ctx_reset() {
	memset(&subflow->reset, 0, sizeof(subflow->reset));
	...
}

The core reaches this from two places. One is __mptcp_close_ssk()->__mptcp_subflow_disconnect(), which includes msk->first being reset for reuse. The other is the error path of mptcp_connect().

Resetting the flag together with the rest of the subflow context is probably the intended behaviour. Could the commit message, or the field comment, say that avoid is cleared on subflow context reset, so BPF scheduler authors know the core can clear it?

[ ... ]

net/mptcp/sched.c void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, · line 171

Quoted 12 lines
net/mptcp/sched.c +4 -0
index 1e59072d478c9..0ce59eb093df6 100644
@@ -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)
+{
+	WRITE_ONCE(subflow->avoid, avoid);

[Severity: Medium]
This version drops the avoid checks from mptcp_subflow_get_send() and mptcp_subflow_get_retrans(). Does anything in the MPTCP core still read subflow->avoid?

As far as I can see, the only reader left is subflow_get_info() in diag.c. The only writer is mptcp_subflow_set_avoid(), and bpf_mptcp_common_kfunc_filter() limits that kfunc to bpf_mptcp_sched_ops struct_ops programs. So the field ends up as one byte of per-subflow scratch storage owned by the BPF scheduler. The core never acts on it in the send, retransmission, stale or mptcp_subflow_active() paths.

The selftest in patch 2 shows the same thing. bpf_avoid_get_send() sets the flag with mptcp_subflow_set_avoid() and then reads it back in its own get_send callback to decide whether to call mptcp_subflow_set_scheduled(). A BPF scheduler can already keep this kind of per-subflow state in a BPF map without any kernel change.

This matters because the patch also adds MPTCP_SUBFLOW_FLAG_AVOID to include/uapi/linux/mptcp.h. Once released, that bit is uAPI, but its meaning depends entirely on whichever BPF scheduler is loaded. The kernel itself attaches no semantics to it.

Earlier review of this series asked for a working scenario that the scheduled bit cannot already cover, with the core actually making use of the new state. Is a follow-up planned where the core honours avoid in code that runs regardless of which scheduler is attached? If not, would it be better to drop the field, the kfunc and the uAPI bit, and keep this state inside the BPF scheduler?

[Severity: Low]
Can a BPF scheduler store a non-canonical bool here?

The verifier classifies a bool kfunc parameter as a plain ARG_SCALAR in get_kfunc_arg_type(), and the ARG_SCALAR case applies no range check. A struct_ops scheduler could therefore pass a value such as 2 in R2, using raw BPF instructions or an extern declared with an int parameter. That byte would then be written into the _Bool field unchanged.

Any user can later reach the read side through the MPTCP inet_diag dump:

net/mptcp/diag.c:subflow_get_info() {
	...
	if (READ_ONCE(sf->avoid))
		flags |= MPTCP_SUBFLOW_FLAG_AVOID;
	...
}

Loading a _Bool that holds a value other than 0 or 1 is undefined behaviour. CONFIG_UBSAN_BOOL would report it, and depending on codegen it could put unexpected bits into MPTCP_SUBFLOW_ATTR_FLAGS.

Would storing !!avoid here avoid this? mptcp_subflow_set_scheduled() has the same pattern, but this patch adds a new instance and exposes the value to userspace.

Quoted 5 lines
net/mptcp/sched.c +2 -0
+}
+
 int mptcp_sched_get_send(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123123730.3265284-1-kalpan.jani%40mpiricsoftware.com
#4 lore raw

PATCH v7 2/2 selftests: mptcp: bpf: exercise the subflow avoid flag across rounds

In reply to Kalpan Jani

Add 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, once a second subflow is available, and never calls set_avoid() again after that. Every later round skips the marked subflow purely by reading back state set earlier, and the harness's own byte-count checks confirm the avoided path carried no data across the whole transfer.

Per-msk state (whether avoid has been asserted yet) is kept in BPF_MAP_TYPE_SK_STORAGE keyed on msk, the same pattern mptcp_bpf_rr.c already uses, rather than in BPF global variables:
globals are process-wide, not per-socket, so they would be shared and reset across any concurrent connections attached to this scheduler.

---
v6: https://lore.kernel.org/all/[email protected]/

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 15 ++++
 .../selftests/bpf/progs/mptcp_bpf_avoid.c     | 87 +++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c
tools/testing/selftests/bpf/prog_tests/mptcp.c +15 -0
index d77c9f8c53c75..3bff30d0d5300 100644
@@ -18,6 +18,7 @@
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
 #include "mptcp_bpf_burst.skel.h"
+#include "mptcp_bpf_avoid.skel.h"
 
 #define NS_TEST "mptcp_ns"
 #define ADDR_1	"10.0.1.1"
@@ -820,6 +821,18 @@ 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);
+	mptcp_bpf_avoid__destroy(skel);
+}
+
 void test_mptcp(void)
 {
 	if (test__start_subtest("base"))
@@ -842,4 +855,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 +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH mptcp-next v7 2/2] selftests: mptcp: bpf: exercise the subflow avoid flag across rounds

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests: mptcp: bpf: bpf_avoid_get_send() returns 0 with no subflow scheduled --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests: mptcp: bpf: bpf_avoid_get_send() returns 0 with no subflow scheduled
--

commit e0591a67aaa7c65d7522308b6dae0bf53d4fc54f
Author: Kalpan Jani <[email protected]>

selftests: mptcp: bpf: exercise the subflow avoid flag across rounds

This commit adds a BPF struct_ops scheduler selftest that exercises mptcp_subflow_set_avoid() across send rounds using per-msk socket storage.

Quoted 6 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +0 -0
new file mode 100644
index 0000000000000..8276ceb0e5397
@@ -0,0 +1,87 @@

[ ... ]

Quoted 33 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +33 -0
+SEC("struct_ops")
+int BPF_PROG(bpf_avoid_get_send, struct mptcp_sock *msk)
+{
+	struct mptcp_subflow_context *subflow;
+	struct mptcp_subflow_context *first = NULL;
+	struct mptcp_avoid_storage *ptr;
+
+	ptr = bpf_sk_storage_get(&mptcp_avoid_map, msk, 0,
+				 BPF_LOCAL_STORAGE_GET_F_CREATE);
+	if (!ptr)
+		return -1;
+
+	/*
+	 * Wait until a second subflow exists before marking it avoided.
+	 * This keeps the state unset until there is actually a subflow
+	 * to exercise.
+	 */
+	bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) {
+		if (!first) {
+			first = subflow;
+			continue;
+		}
+
+		if (!ptr->avoid_marked) {
+			mptcp_subflow_set_avoid(subflow, true);
+			ptr->avoid_marked = true;
+			continue;
+		}
+
+		if (subflow->avoid)
+			continue;
+
+		if (mptcp_subflow_active(subflow)) {

tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c line 79

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +10 -0
+			mptcp_subflow_set_scheduled(subflow, true);
+			return 0;
+		}
+	}
+
+	if (first && mptcp_subflow_active(first) && !first->avoid)
+		mptcp_subflow_set_scheduled(first, true);
+
+	return 0;
+}

[Severity: Medium]
Can bpf_avoid_get_send() return 0 without scheduling any subflow when first is NULL, avoided, or temporarily inactive?

In __mptcp_subflow_push_pending(), a 0 return from mptcp_sched_get_send() when no subflow has subflow->scheduled set leaves keep_pushing true, so the while (mptcp_send_head(sk) && keep_pushing) loop spins indefinitely under mptcp_data_lock(sk):

net/mptcp/protocol.c:__mptcp_subflow_push_pending() {
    ...
		if (mptcp_sched_get_send(msk))
			goto out;

		if (READ_ONCE(subflow->scheduled)) {
			mptcp_subflow_set_scheduled(subflow, false);
			ret = __subflow_push_pending(sk, ssk, &info);
			if (ret <= 0)
				keep_pushing = false;
			else
				copied += ret;
		}

		mptcp_for_each_subflow(msk, subflow) {
			if (READ_ONCE(subflow->scheduled)) {
				xmit_ssk = mptcp_subflow_tcp_sock(subflow);
				if (xmit_ssk != ssk) {
					mptcp_subflow_delegate(subflow,
							       MPTCP_DELEGATE_SEND);
					keep_pushing = false;
				}
			}
		}
    ...
}

Returning 0 inside the if (first && ...) branch and -1 when no subflow is scheduled would match the other BPF schedulers.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH mptcp-next v7 2/2] selftests: mptcp: bpf: exercise the subflow avoid flag across rounds

In reply to Kalpan Jani
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c, bpf_avoid_get_send() always returns 0, including when it scheduled no…
- [Low] bpf_avoid_get_send() in tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c treats avoid as…
- [Low] The commit message misdescribes the extern declarations.

--

selftests: mptcp: bpf: exercise the subflow avoid flag across rounds

This adds a BPF struct_ops MPTCP scheduler selftest. The scheduler calls mptcp_subflow_set_avoid() once, on the second subflow, and in later rounds relies on reading the avoid flag back. Per-msk state lives in SK_STORAGE, and the harness checks that the avoided path carried no data.

Quoted 6 lines

Add 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).

[Severity: Low]
Is this description accurate? mptcp_bpf_avoid.c is a new file, so the extern can't have been missing from it before.

Among the existing scheduler progs, only mptcp_bpf_burst.c declares mptcp_subflow_active(). mptcp_bpf_rr.c, mptcp_bpf_red.c, mptcp_bpf_first.c and mptcp_bpf_bkup.c don't declare it, and mptcp_bpf.h doesn't either.

The message also doesn't say why both externs stay local. The extern for the sibling kfunc mptcp_subflow_set_scheduled() is in mptcp_bpf.h. The preceding patch, "mptcp: sched: add subflow avoid flag for BPF schedulers", registers mptcp_subflow_set_avoid() in the same kfunc set in net/mptcp/bpf.c.

Could this wording be left over from an earlier revision?

Quoted 6 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +0 -0
new file mode 100644
index 0000000000000..8276ceb0e5397
@@ -0,0 +1,87 @@

[ ... ]

Quoted 12 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +12 -0
+SEC("struct_ops")
+int BPF_PROG(bpf_avoid_get_send, struct mptcp_sock *msk)
+{
+	struct mptcp_subflow_context *subflow;
+	struct mptcp_subflow_context *first = NULL;
+	struct mptcp_avoid_storage *ptr;
+
+	ptr = bpf_sk_storage_get(&mptcp_avoid_map, msk, 0,
+				 BPF_LOCAL_STORAGE_GET_F_CREATE);
+	if (!ptr)
+		return -1;
+

[ ... ]

Quoted 4 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +4 -0
+	bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) {
+		if (!first) {
+			first = subflow;
+			continue;

tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c line 67

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +10 -0
+		}
+
+		if (!ptr->avoid_marked) {
+			mptcp_subflow_set_avoid(subflow, true);
+			ptr->avoid_marked = true;
+			continue;
+		}
+
+		if (subflow->avoid)
+			continue;

[Severity: Low]
Should avoid be a hard exclusion here? struct mptcp_subflow_context documents the field as:

bool avoid; /* pkt scheduler: skip subflow if possible */

Once avoid_marked is set, this loop always skips the avoided subflow. The fallback after the loop only schedules first, and only when first is active and not avoided.

That leaves nothing scheduled in at least two cases:

- The head subflow goes stale. mptcp_pm_subflow_chk_stale() only marks it stale when another active subflow exists, and here that is the avoided one.

- The head subflow is closed or reset. The avoided subflow then becomes

    first and is rejected by !first->avoid.

No get_retrans op is set, so retransmissions also go through get_send and stall the same way. On the __mptcp_push_pending() path, nothing is sent on any retry.

Could the scheduler fall back to the avoided subflow when no other subflow is usable?

tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c line 78

Quoted 11 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c new file +11 -0
+
+		if (mptcp_subflow_active(subflow)) {
+			mptcp_subflow_set_scheduled(subflow, true);
+			return 0;
+		}
+	}
+
+	if (first && mptcp_subflow_active(first) && !first->avoid)
+		mptcp_subflow_set_scheduled(first, true);
+
+	return 0;

[Severity: Medium]
Can this return 0 even when no subflow was scheduled? The core reads a 0 return from get_send as "a subflow has been scheduled".

The in-tree implementations return an error when they find nothing. mptcp_sched_default_get_send() returns -EINVAL, and the get_send ops in mptcp_bpf_first.c and mptcp_bpf_burst.c return -1.

In __mptcp_subflow_push_pending(), the scheduler exit is only taken on a nonzero return:

net/mptcp/protocol.c:__mptcp_subflow_push_pending() {
    ...
	while (mptcp_send_head(sk) && keep_pushing) {
		...
		if (mptcp_sched_get_send(msk))
			goto out;

		if (READ_ONCE(subflow->scheduled)) {
			...
		}

		mptcp_for_each_subflow(msk, subflow) {
			if (READ_ONCE(subflow->scheduled)) {
				...
					keep_pushing = false;
		...
	}
    ...
}

If the return is 0 and nothing is scheduled, keep_pushing stays true. The BPF prog then sees the same state on every iteration.

Doesn't this loop then spin forever in softirq with the msk data lock held?

One way to get there, starting from the stale case above:

mptcp_pm_subflow_chk_stale()

    subflow->stale = 1;   /* head subflow; the avoided one is active */
    __mptcp_retransmit_pending_data(sk);

and then a DATA_ACK arrives on the avoided subflow:

ack_update_msk()
__mptcp_check_push()
__mptcp_subflow_push_pending()
mptcp_sched_get_send()
bpf_avoid_get_send() /* returns 0, nothing scheduled */

Closing or resetting the initial subflow leads to the same state. mptcp_subflow_process_delegated() is another entry into this loop.

The core's missing guard here is pre-existing, and mptcp_bpf_bkup.c uses the same return 0 pattern. Because this scheduler excludes a subflow on purpose, the empty case is more likely here.

Would returning -1 when nothing was scheduled avoid this? The function already does that for the !ptr case.

Quoted 1 line

+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123123730.3265284-1-kalpan.jani%40mpiricsoftware.com