FAILED: patch "[PATCH] bpf: tcp: Support tcp_congestion_ops in bpf" failed to apply to 5.10-stable tree
Subsystems (6)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 0baf26b0fcd74bbfcef53c5d5e8bad2b99c8d0d2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026102107-augmented-cupbearer-7f31@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 0baf26b0fcd74bbfcef53c5d5e8bad2b99c8d0d2 Mon Sep 17 00:00:00 2001
From: Martin KaFai Lau <[email protected]>
Date: Wed, 8 Jan 2020 16:35:08 -0800
Subject: [PATCH] bpf: tcp: Support tcp_congestion_ops in bpf
This patch makes "struct tcp_congestion_ops" to be the first user of BPF STRUCT_OPS. It allows implementing a tcp_congestion_ops in bpf.
The BPF implemented tcp_congestion_ops can be used like regular kernel tcp-cc through sysctl and setsockopt. e.g. [root@arch-fb-vm1 bpf]# sysctl -a | egrep congestion net.ipv4.tcp_allowed_congestion_control = reno cubic bpf_cubic net.ipv4.tcp_available_congestion_control = reno bic cubic bpf_cubic net.ipv4.tcp_congestion_control = bpf_cubic
There has been attempt to move the TCP CC to the user space
(e.g. CCP in TCP). The common arguments are faster turn around,
get away from long-tail kernel versions in production...etc, which are legit points.
BPF has been the continuous effort to join both kernel and userspace upsides together (e.g. XDP to gain the performance advantage without bypassing the kernel). The recent BPF advancements (in particular BTF-aware verifier, BPF trampoline, BPF CO-RE...) made implementing kernel struct ops (e.g. tcp cc) possible in BPF. It allows a faster turnaround for testing algorithm in the production while leveraging the existing (and continue growing) BPF feature/framework instead of building one specifically for userspace TCP CC.
This patch allows write access to a few fields in tcp-sock (in bpf_tcp_ca_btf_struct_access()).
The optional "get_info" is unsupported now. It can be added later. One possible way is to output the info with a btf-id to describe the content.
include/linux/filter.h +2 -0
@@ -843,6 +843,8 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);int bpf_prog_create_from_user (struct bpf_prog **pfp,struct sock_fprog *fprog,bpf_aux_classic_check_t trans,bool save_orig);void bpf_prog_destroy (struct bpf_prog *fp); +const struct bpf_func_proto * +bpf_base_func_proto (enum bpf_func_id func_id);int sk_attach_filter (struct sock_fprog *fprog,struct sock *sk);int sk_attach_bpf (u32 ufd,struct sock *sk);
include/net/tcp.h +2 -0
@@ -1007,6 +1007,7 @@ enum tcp_ca_ack_event_flags {#define TCP_CONG_NON_RESTRICTED 0x1/* Requires ECN/ECT set on all packets */ #define TCP_CONG_NEEDS_ECN 0x2 +#define TCP_CONG_MASK (TCP_CONG_NON_RESTRICTED | TCP_CONG_NEEDS_ECN)union tcp_cc_info ;
@@ -1101,6 +1102,7 @@ u32 tcp_reno_undo_cwnd(struct sock *sk);void tcp_reno_cong_avoid (struct sock *sk,u32 ack,u32 acked);extern struct tcp_congestion_ops tcp_reno; +struct tcp_congestion_ops *tcp_ca_find (const char *name);struct tcp_congestion_ops *tcp_ca_find_key (u32 key);u32 tcp_ca_get_key_by_name (struct net *net,const char *name,bool *ecn_ca);#ifdef CONFIG_INET
kernel/bpf/bpf_struct_ops_types.h +6 -1
@@ -1,4 +1,9 @@/* SPDX-License-Identifier: GPL-2.0 */ /* internal file - do not include directly */ -/* To be filled in a later patch */ +#ifdef CONFIG_BPF_JIT +#ifdef CONFIG_INET +#include <net/tcp.h> +BPF_STRUCT_OPS_TYPE(tcp_congestion_ops) +#endif +#endif
net/core/filter.c +1 -1
@@ -5935,7 +5935,7 @@ bool bpf_helper_changes_pkt_data(void *func)return false; } -static const struct bpf_func_proto * +const struct bpf_func_proto *bpf_base_func_proto (enum bpf_func_id func_id) {switch (func_id) {
net/ipv4/Makefile +4 -0
@@ -65,3 +65,7 @@ obj-$(CONFIG_NETLABEL) += cipso_ipv4.o obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \ xfrm4_output.o xfrm4_protocol.o + +ifeq ($(CONFIG_BPF_JIT),y) +obj-$(CONFIG_BPF_SYSCALL) += bpf_tcp_ca.o +endif
net/ipv4/bpf_tcp_ca.c new file +230 -0
230 lines not on this page · raw message
net/ipv4/tcp_cong.c +8 -8
@@ -21,7 +21,7 @@ static DEFINE_SPINLOCK(tcp_cong_list_lock);static LIST_HEAD (tcp_cong_list);/* Simple linear search, don't expect many entries! */ -static struct tcp_congestion_ops *tcp_ca_find (const char *name) +struct tcp_congestion_ops *tcp_ca_find (const char *name) {struct tcp_congestion_ops *e;
@@ -162,7 +162,7 @@ void tcp_assign_congestion_control(struct sock *sk)rcu_read_lock (); ca =rcu_dereference (net->ipv4.tcp_congestion_control); -if (unlikely (!try_module_get (ca->owner))) +if (unlikely (!bpf_try_module_get (ca, ca->owner))) ca = &tcp_reno; icsk->icsk_ca_ops = ca;rcu_read_unlock ();
@@ -208,7 +208,7 @@ void tcp_cleanup_congestion_control(struct sock *sk)if (icsk->icsk_ca_ops->release) icsk->icsk_ca_ops->release (sk); -module_put (icsk->icsk_ca_ops->owner); +bpf_module_put (icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner); }/* Used by sysctl to change default congestion control */
@@ -222,12 +222,12 @@ int tcp_set_default_congestion_control(struct net *net, const char *name) ca =tcp_ca_find_autoload (net, name);if (!ca) { ret = -ENOENT ; - }else if (!try_module_get (ca->owner)) { + }else if (!bpf_try_module_get (ca, ca->owner)) { ret = -EBUSY ; }else { prev =xchg (&net->ipv4.tcp_congestion_control, ca);if (prev) -module_put (prev->owner); +bpf_module_put (prev, prev->owner); ca->flags |=TCP_CONG_NON_RESTRICTED ; ret =0 ;
@@ -366,19 +366,19 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, }else if (!load) {const struct tcp_congestion_ops *old_ca = icsk->icsk_ca_ops; -if (try_module_get (ca->owner)) { +if (bpf_try_module_get (ca, ca->owner)) {if (reinit) {tcp_reinit_congestion_control (sk, ca); }else { icsk->icsk_ca_ops = ca; -module_put (old_ca->owner); +bpf_module_put (old_ca, old_ca->owner); } }else { err = -EBUSY ; } }else if (!((ca->flags &TCP_CONG_NON_RESTRICTED ) || cap_net_admin)) { err = -EPERM ; - }else if (!try_module_get (ca->owner)) { + }else if (!bpf_try_module_get (ca, ca->owner)) { err = -EBUSY ; }else {tcp_reinit_congestion_control (sk, ca);
net/ipv4/tcp_ipv4.c +4 -2
@@ -2678,7 +2678,8 @@ static void __net_exit tcp_sk_exit(struct net *net)int cpu;if (net->ipv4.tcp_congestion_control) -module_put (net->ipv4.tcp_congestion_control->owner); +bpf_module_put (net->ipv4.tcp_congestion_control, + net->ipv4.tcp_congestion_control->owner);for_each_possible_cpu (cpu)inet_ctl_sock_destroy (*per_cpu_ptr (net->ipv4.tcp_sk, cpu));
@@ -2785,7 +2786,8 @@ static int __net_init tcp_sk_init(struct net *net)/* Reno is always built in */ if (!net_eq (net, &init_net) && -try_module_get (init_net.ipv4.tcp_congestion_control->owner)) +bpf_try_module_get (init_net.ipv4.tcp_congestion_control, + init_net.ipv4.tcp_congestion_control->owner)) net->ipv4.tcp_congestion_control = init_net.ipv4.tcp_congestion_control;else net->ipv4.tcp_congestion_control = &tcp_reno;
net/ipv4/tcp_minisocks.c +2 -2
@@ -414,7 +414,7 @@ void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst)rcu_read_lock (); ca =tcp_ca_find_key (ca_key); -if (likely (ca &&try_module_get (ca->owner))) { +if (likely (ca &&bpf_try_module_get (ca, ca->owner))) { icsk->icsk_ca_dst_locked =tcp_ca_dst_locked (dst); icsk->icsk_ca_ops = ca; ca_got_dst = true;
@@ -425,7 +425,7 @@ void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst)/* If no valid choice made yet, assign current system default ca. */ if (!ca_got_dst && (!icsk->icsk_ca_setsockopt || - !try_module_get (icsk->icsk_ca_ops->owner))) + !bpf_try_module_get (icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner)))tcp_assign_congestion_control (sk);tcp_set_ca_state (sk, TCP_CA_Open);
net/ipv4/tcp_output.c +2 -2
@@ -3368,8 +3368,8 @@ static void tcp_ca_dst_init(struct sock *sk, const struct dst_entry *dst)rcu_read_lock (); ca =tcp_ca_find_key (ca_key); -if (likely (ca &&try_module_get (ca->owner))) { -module_put (icsk->icsk_ca_ops->owner); +if (likely (ca &&bpf_try_module_get (ca, ca->owner))) { +bpf_module_put (icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner); icsk->icsk_ca_dst_locked =tcp_ca_dst_locked (dst); icsk->icsk_ca_ops = ca; }