diff mbox series

[mptcp-next,RFC,3/4] mptcp: bpf: allow to write to mptcp_sched_chunk

Message ID 20240527-sched_per_packet-v1-3-09a41d405f7c@gmail.com (mailing list archive)
State RFC
Headers show
Series mptcp: update scheduler API | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 43 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf__only_bpftest_all_ success Success! ✅

Commit Message

Gregory Detal May 27, 2024, 1:17 p.m. UTC
This patch allows to write to either limit or flags, allowing a bpf
program to change the packet scheduling behavior.

The fields will be used in next commit.

Signed-off-by: Gregory Detal <gregory.detal@gmail.com>
---
 net/mptcp/bpf.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
index 57c47bb430b1..2fb706342064 100644
--- a/net/mptcp/bpf.c
+++ b/net/mptcp/bpf.c
@@ -18,8 +18,9 @@ 
 
 #ifdef CONFIG_BPF_JIT
 static struct bpf_struct_ops bpf_mptcp_sched_ops;
-static const struct btf_type *mptcp_sock_type, *mptcp_subflow_type __read_mostly;
-static u32 mptcp_sock_id, mptcp_subflow_id;
+static const struct btf_type *mptcp_sock_type, *mptcp_subflow_type __read_mostly,
+	*mptcp_sched_chunk_type;
+static u32 mptcp_sock_id, mptcp_subflow_id, mptcp_sched_chunk_id;
 
 static const struct bpf_func_proto *
 bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
@@ -71,6 +72,19 @@  static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log,
 				off);
 			return -EACCES;
 		}
+	} else if (t == mptcp_sched_chunk_type) {
+		switch (off) {
+		case offsetof(struct mptcp_sched_chunk, limit):
+			end = offsetofend(struct mptcp_sched_chunk, limit);
+			break;
+		case offsetof(struct mptcp_sched_chunk, flags):
+			end = offsetofend(struct mptcp_sched_chunk, flags);
+			break;
+		default:
+			bpf_log(log, "no write support to mptcp_sched_chunk at off %d\n",
+				off);
+			return -EACCES;
+		}
 	} else {
 		bpf_log(log, "only access to mptcp sock or subflow is supported\n");
 		return -EACCES;
@@ -152,6 +166,13 @@  static int bpf_mptcp_sched_init(struct btf *btf)
 	mptcp_subflow_id = type_id;
 	mptcp_subflow_type = btf_type_by_id(btf, mptcp_subflow_id);
 
+	type_id = btf_find_by_name_kind(btf, "mptcp_sched_chunk",
+					BTF_KIND_STRUCT);
+	if (type_id < 0)
+		return -EINVAL;
+	mptcp_sched_chunk_id = type_id;
+	mptcp_sched_chunk_type = btf_type_by_id(btf, mptcp_sched_chunk_id);
+
 	return 0;
 }