From nobody Sat Sep 5 05:51:21 2026 Received: from sender5-of-o54.zoho.com (sender5-of-o54.zoho.com [165.173.182.54]) (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 C439B3DDAFC for ; Mon, 31 Aug 2026 09:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=165.173.182.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788169644; cv=pass; b=hfI/uucGNdBXq74KbTo91G713WjgtJRvCx//YeZFOs6efV7XIRRDFBZYQYKa/FqpHcCRB5+Ub3SHk9FfuzUtcefzxeD58Yrg6oBRGwjm95JwEAs5QUwtyg8SNozIb90R3DDWIxeFCWMvg7DYa1YEn76W6qC33Q4Xd00qrTeYFaI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788169644; c=relaxed/simple; bh=SahcI1dgCTQoyB2o1bOZCZdp8W7i+h8ihUPiQ177tZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CPeSwGqbnYkFqpkxEZk+kQwJ18cjOOu1w620ijegkexWtMDtNzRFbU3GLUC6wEpqJ5V1pqLM17+QUmqeuuFTkBz7z9lWhUF22icMkysxfzcmTm3N4YFLFGGD9KhiPSH7zPg5yw+pEiqNtNhZ56IfLM1KWgDwEGxkALbRD1Pb9p4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; dkim=fail (0-bit key) header.d=mpiricsoftware.com header.i=kalpan.jani@mpiricsoftware.com header.b=YRHeQJnA reason="key not found in DNS"; arc=pass smtp.client-ip=165.173.182.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mpiricsoftware.com header.i=kalpan.jani@mpiricsoftware.com header.b="YRHeQJnA" ARC-Seal: i=1; a=rsa-sha256; t=1788169625; cv=none; d=zohomail.com; s=zohoarc; b=A98RMJZ+KkKZilxG4S0IU/x0ixnjPXcOPVg19UjC2/9UqxNvpl5NKOR978LTa3Q1nUIYk8vWDU1Pmd036/8NfkgR3HAltcLv0wGlQZWElFJpxd4uueEr2T4HpnlmOgrYsH2p6Z4LAKtG/c/mchwuqHbXXuZOmjnxqCHy4m6lYu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788169625; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=Vifmif0AaxcInq/o1T9GtnJPlZ4FhMADK3Ak1KiHIgc=; b=gsR498btegSUoCp2PBRMINzkWaUdvSXf4qS5NiXQ0oDRB5+ndvETg1d43+ESWWQVF0aTVqtgvhEWSwHVxmPt8ZjTJNjwfjGTBTRUYst51N4P/0bErTiWIE549teaLnwbLSn1aHx+EKlGR1pIgrMKszK20j3eSF3orx8C5OGYeV4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=kalpan.jani@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1788169625; s=mpiric; d=mpiricsoftware.com; i=kalpan.jani@mpiricsoftware.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=Vifmif0AaxcInq/o1T9GtnJPlZ4FhMADK3Ak1KiHIgc=; b=YRHeQJnAv97aQT2t5Zgj2dlXNPPL2x9jh3S8RiXI4/NMVAc4yb6/Jejz6uGbR7TI ASR1VsefjJWXfiSIQ8rVZzrh97ctfYVj1bCVDyjsE/qeXHlU41yDLXg5ePypQb1b1cS 9KfQ9QnpZcrMMhEWQGjPfhLRuWiJQT6Cbq5y5MF0= Received: by mx.zohomail.com with SMTPS id 178816962400691.11884456098892; Mon, 31 Aug 2026 02:47:04 -0700 (PDT) From: Kalpan Jani To: mptcp@lists.linux.dev Cc: matttbe@kernel.org, martineau@kernel.org, pabeni@redhat.com, shardul.b@mpiricsoftware.com, janak@mpiric.us, kalpanjani009@gmail.com Subject: [PATCH mptcp-next v3 1/2] mptcp: sched: add subflow avoid flag and enforce it in core Date: Mon, 31 Aug 2026 15:16:50 +0530 Message-ID: <20260831094651.2682660-2-kalpan.jani@mpiricsoftware.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260831094651.2682660-1-kalpan.jani@mpiricsoftware.com> References: <20260831094651.2682660-1-kalpan.jani@mpiricsoftware.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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:9 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. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/349 Suggested-by: Paolo Abeni Signed-off-by: Kalpan Jani Changes since v2: - rebased onto the current export tree. v2 was generated against a stale local snapshot that predated several unrelated commits touching the same bitfield region in mptcp_subflow_context; applying v2 there produced a merge conflict in protocol.h. No functional change from v2 -- only line offsets and the __unused padding count differ (was 8 unused bits available in the stale snapshot, is 9 in current export, so avoid now leaves __unused:8 instead of __unused:7). Changes since v1: - moved avoid from a standalone bool into the existing __unused 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. v2: https://lore.kernel.org/all/20260824102741.347492-2-kalpan.jani@mpirics= oftware.com/ v1: https://lore.kernel.org/all/20260715101148.2601045-2-kalpan.jani@mpiric= software.com/ --- 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(-) diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h index 72a5d030154e..b4ca97e07445 100644 --- a/include/uapi/linux/mptcp.h +++ b/include/uapi/linux/mptcp.h @@ -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) =20 #define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds" #define MPTCP_PM_EV_GRP_NAME "mptcp_pm_events" diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 82b0ad25f700..3a229e28960d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -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) diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c index 70cf9ebce833..3e98125a9c0c 100644 --- a/net/mptcp/diag.c +++ b/net/mptcp/diag.c @@ -49,6 +49,8 @@ static int subflow_get_info(struct sock *sk, struct sk_bu= ff *skb, bool net_admin flags |=3D MPTCP_SUBFLOW_FLAG_BKUP_LOC; if (READ_ONCE(sf->fully_established)) flags |=3D MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED; + if (sf->avoid) + flags |=3D MPTCP_SUBFLOW_FLAG_AVOID; if (sf->conn_finished) flags |=3D MPTCP_SUBFLOW_FLAG_CONNECTED; if (sf->map_valid) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index f22d64ab1c53..69ab6583f1df 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1645,7 +1645,7 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock= *msk) =20 trace_mptcp_subflow_get_send(subflow); ssk =3D mptcp_subflow_tcp_sock(subflow); - if (!mptcp_subflow_active(subflow)) + if (!mptcp_subflow_active(subflow) || subflow->avoid) continue; =20 tout =3D max(tout, mptcp_timeout_from_subflow(subflow)); @@ -2563,7 +2563,7 @@ struct sock *mptcp_subflow_get_retrans(struct mptcp_s= ock *msk) mptcp_for_each_subflow(msk, subflow) { struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); =20 - if (!__mptcp_subflow_active(subflow)) + if (!__mptcp_subflow_active(subflow) || subflow->avoid) continue; =20 /* still data outstanding at TCP level? skip this */ diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3d250e8204d5..7768a464ff4e 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -586,7 +586,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 : 9; + avoid : 1, /* pkt scheduler: skip subflow if possible */ + __unused : 8; bool data_avail; bool scheduled; bool pm_listener; /* a listener managed by the kernel PM? */ @@ -902,6 +903,8 @@ static inline bool __mptcp_subflow_active(struct mptcp_= subflow_context *subflow) =20 void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow); =20 +void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow, bool a= void); + bool mptcp_subflow_active(struct mptcp_subflow_context *subflow); =20 void mptcp_subflow_drop_ctx(struct sock *ssk); diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c index 1e59072d478c..8a448814a11d 100644 --- a/net/mptcp/sched.c +++ b/net/mptcp/sched.c @@ -165,6 +165,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_= context *subflow, WRITE_ONCE(subflow->scheduled, scheduled); } =20 +__bpf_kfunc void mptcp_subflow_set_avoid(struct mptcp_subflow_context *sub= flow, + bool avoid) +{ + subflow->avoid =3D avoid; +} + int mptcp_sched_get_send(struct mptcp_sock *msk) { struct mptcp_subflow_context *subflow; --=20 2.43.0 From nobody Sat Sep 5 05:51:21 2026 Received: from sender6-of-o54.zoho.com (sender6-of-o54.zoho.com [165.173.180.54]) (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 CA4FF3DD862 for ; Mon, 31 Aug 2026 09:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=165.173.180.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788169655; cv=pass; b=kzCMZ94hocrr7wdqQSL58071vG74xlnBs5Hcp+oL640aq9LjKWskI75X3pc7GMAFaBU1vKSq9iAyx+YuNSxlrLNSYBocEh+dLxLzQNaIUZ1b5aaxhMdlKo7iY3hSPhDqcehKQPjtxKRFfmpG3Ev5H551aslICd4znQsV/rkVxds= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788169655; c=relaxed/simple; bh=BG1ap2562eOCU4CNgiDmlIOjhOidDfxnpMYgk3LqFsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UWswf5At73LCNjZ7khrnJQ86Vu/J6MvvUkpuQf2aPrWh/0WBfVRu6QrSmerZpJPFWv88zNzhdU4ZdTsiOlX0Jpuri2H+U1WG6T0ljOwrkLxTuSZczF8OLNFhcDfs0O4aO1MqfSCx0/R2nBNORzvL7Xzj4Ds7l5wLsPBwZgPgFlE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; dkim=fail (0-bit key) header.d=mpiricsoftware.com header.i=kalpan.jani@mpiricsoftware.com header.b=cN/t1inb reason="key not found in DNS"; arc=pass smtp.client-ip=165.173.180.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=mpiricsoftware.com header.i=kalpan.jani@mpiricsoftware.com header.b="cN/t1inb" ARC-Seal: i=1; a=rsa-sha256; t=1788169629; cv=none; d=zohomail.com; s=zohoarc; b=PDAm87uwpflbdNwNs+IQRlGFxxB+m/eE1H1gz8bXRHuRoQiJ6FIrBxXZPCskK9dSdCdBcFI29LtcvVUuhixJYNVRzfVyyKdmXVWLH2NSaWdoG4NHAzaKOlIaSP5QH1KWbSt8RTEVVxdPNM6b2sDU3GP86e7nX4HYciz0A5MtV+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788169629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=K7oLv/eWS0qOKHT1vmD9bDaYBenXMq62MaGhoH6h7QU=; b=JEg8WZ4T+CFnx9MPNWlp4bhqOYeuyVA/aIxJBE7NbYAXsfdwoU6D4cZvUeSWW3hV2e+aY0sZ7Z9/VFbtD3FB7IQcrMROBbji6WtG1Dvw9kZ39K4KtHPmP+KVVAeyT8zEXqtzmAOWhmokHmwKA/M038blBhZrLqygTwt+j3GcAOQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=kalpan.jani@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1788169629; s=mpiric; d=mpiricsoftware.com; i=kalpan.jani@mpiricsoftware.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=K7oLv/eWS0qOKHT1vmD9bDaYBenXMq62MaGhoH6h7QU=; b=cN/t1inbChLCuLYWwTzo24jZNhFGmlP5OXeB/DdfCwzcE+6FvUDSlHGwfKJianKG KQc285dFYK/nERusbdgbXArUKaqX8zlyS3t1RosSLcskAJdWXoMybMeKE7klWK7aBg8 RL0vE2CI0LB/E/shCzb2LppqpiF0mVFNYRSCCWqc= Received: by mx.zohomail.com with SMTPS id 1788169628205242.00736633108545; Mon, 31 Aug 2026 02:47:08 -0700 (PDT) From: Kalpan Jani To: mptcp@lists.linux.dev Cc: matttbe@kernel.org, martineau@kernel.org, pabeni@redhat.com, shardul.b@mpiricsoftware.com, janak@mpiric.us, kalpanjani009@gmail.com Subject: [PATCH mptcp-next v3 2/2] selftests: mptcp: bpf: exercise the subflow avoid flag across rounds Date: Mon, 31 Aug 2026 15:16:51 +0530 Message-ID: <20260831094651.2682660-3-kalpan.jani@mpiricsoftware.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260831094651.2682660-1-kalpan.jani@mpiricsoftware.com> References: <20260831094651.2682660-1-kalpan.jani@mpiricsoftware.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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, 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. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/349 Suggested-by: Paolo Abeni Signed-off-by: Kalpan Jani Changes since v2: - rebased onto the current export tree, no functional change from v2. 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. v2: https://lore.kernel.org/all/20260824102741.347492-3-kalpan.jani@mpirics= oftware.com/ v1: https://lore.kernel.org/all/20260715101148.2601045-3-kalpan.jani@mpiric= software.com/ --- .../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 diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index d77c9f8c53c7..1c903c121b21 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -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" =20 #define NS_TEST "mptcp_ns" #define ADDR_1 "10.0.1.1" @@ -820,6 +821,19 @@ static void test_burst(void) mptcp_bpf_burst__destroy(skel); } =20 +static void test_avoid(void) +{ + struct mptcp_bpf_avoid *skel; + + skel =3D 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")) @@ -842,4 +856,6 @@ void test_mptcp(void) test_red(); if (test__start_subtest("burst")) test_burst(); + if (test__start_subtest("avoid")) + test_avoid(); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c b/tools/te= sting/selftests/bpf/progs/mptcp_bpf_avoid.c new file mode 100644 index 000000000000..8b22c5967a7a --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026, MPTCP. */ + +#include "mptcp_bpf.h" +#include + +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __= ksym; +extern void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow, + bool avoid) __ksym; + +char _license[] SEC("license") =3D "GPL"; + +/* set once, on the first scheduling round, never touched again -- this + * is what makes "avoid" different from "scheduled": nothing here + * re-asserts the decision, and the core doesn't clear it either. + */ +bool avoid_marked; +__u32 get_send_calls; + +SEC("struct_ops") +void BPF_PROG(mptcp_sched_avoid_init, struct mptcp_sock *msk) +{ + avoid_marked =3D false; + get_send_calls =3D 0; +} + +SEC("struct_ops") +void BPF_PROG(mptcp_sched_avoid_release, struct mptcp_sock *msk) +{ +} + +SEC("struct_ops") +int BPF_PROG(bpf_avoid_get_send, struct mptcp_sock *msk) +{ + struct mptcp_subflow_context *subflow; + + get_send_calls++; + + if (!avoid_marked) { + int i =3D 0; + + /* bench every subflow but the first, once */ + bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) { + if (i++ > 0) + mptcp_subflow_set_avoid(subflow, true); + } + avoid_marked =3D true; + } + + /* every round -- including this one -- just reads back state set + * at most once above. no re-assertion, ever. + */ + bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) { + if (subflow->avoid) + continue; + if (mptcp_subflow_active(subflow)) { + mptcp_subflow_set_scheduled(subflow, true); + break; + } + } + return 0; +} + +SEC(".struct_ops.link") +struct mptcp_sched_ops avoid =3D { + .init =3D (void *)mptcp_sched_avoid_init, + .release =3D (void *)mptcp_sched_avoid_release, + .get_send =3D (void *)bpf_avoid_get_send, + .name =3D "bpf_avoid", +}; --=20 2.43.0