Commit 9f0265e9 authored by Jörn-Thorben Hinz's avatar Jörn-Thorben Hinz Committed by Alexei Starovoitov

bpf: Require only one of cong_avoid() and cong_control() from a TCP CC

Remove the check for required and optional functions in a struct
tcp_congestion_ops from bpf_tcp_ca.c. Rely on
tcp_register_congestion_control() to reject a BPF CC that does not
implement all required functions, as it will do for a non-BPF CC.

When a CC implements tcp_congestion_ops.cong_control(), the alternate
cong_avoid() is not in use in the TCP stack. Previously, a BPF CC was
still forced to implement cong_avoid() as a no-op since it was
non-optional in bpf_tcp_ca.c.
Signed-off-by: default avatarJörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>
Reviewed-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/r/20220622191227.898118-3-jthinz@mailbox.tu-berlin.deSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 41c95dd6
...@@ -503,10 +503,9 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, ...@@ -503,10 +503,9 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
goto unlock; goto unlock;
} }
/* Error during st_ops->reg(). It is very unlikely since /* Error during st_ops->reg(). Can happen if this struct_ops needs to be
* the above init_member() should have caught it earlier * verified as a whole, after all init_member() calls. Can also happen if
* before reg(). The only possibility is if there was a race * there was a race in registering the struct_ops (under the same name) to
* in registering the struct_ops (under the same name) to
* a sub-system through different struct_ops's maps. * a sub-system through different struct_ops's maps.
*/ */
set_memory_nx((long)st_map->image, 1); set_memory_nx((long)st_map->image, 1);
......
...@@ -14,18 +14,6 @@ ...@@ -14,18 +14,6 @@
/* "extern" is to avoid sparse warning. It is only used in bpf_struct_ops.c. */ /* "extern" is to avoid sparse warning. It is only used in bpf_struct_ops.c. */
extern struct bpf_struct_ops bpf_tcp_congestion_ops; extern struct bpf_struct_ops bpf_tcp_congestion_ops;
static u32 optional_ops[] = {
offsetof(struct tcp_congestion_ops, init),
offsetof(struct tcp_congestion_ops, release),
offsetof(struct tcp_congestion_ops, set_state),
offsetof(struct tcp_congestion_ops, cwnd_event),
offsetof(struct tcp_congestion_ops, in_ack_event),
offsetof(struct tcp_congestion_ops, pkts_acked),
offsetof(struct tcp_congestion_ops, min_tso_segs),
offsetof(struct tcp_congestion_ops, sndbuf_expand),
offsetof(struct tcp_congestion_ops, cong_control),
};
static u32 unsupported_ops[] = { static u32 unsupported_ops[] = {
offsetof(struct tcp_congestion_ops, get_info), offsetof(struct tcp_congestion_ops, get_info),
}; };
...@@ -51,18 +39,6 @@ static int bpf_tcp_ca_init(struct btf *btf) ...@@ -51,18 +39,6 @@ static int bpf_tcp_ca_init(struct btf *btf)
return 0; return 0;
} }
static bool is_optional(u32 member_offset)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(optional_ops); i++) {
if (member_offset == optional_ops[i])
return true;
}
return false;
}
static bool is_unsupported(u32 member_offset) static bool is_unsupported(u32 member_offset)
{ {
unsigned int i; unsigned int i;
...@@ -246,7 +222,6 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t, ...@@ -246,7 +222,6 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t,
{ {
const struct tcp_congestion_ops *utcp_ca; const struct tcp_congestion_ops *utcp_ca;
struct tcp_congestion_ops *tcp_ca; struct tcp_congestion_ops *tcp_ca;
int prog_fd;
u32 moff; u32 moff;
utcp_ca = (const struct tcp_congestion_ops *)udata; utcp_ca = (const struct tcp_congestion_ops *)udata;
...@@ -268,14 +243,6 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t, ...@@ -268,14 +243,6 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t,
return 1; return 1;
} }
if (!btf_type_resolve_func_ptr(btf_vmlinux, member->type, NULL))
return 0;
/* Ensure bpf_prog is provided for compulsory func ptr */
prog_fd = (int)(*(unsigned long *)(udata + moff));
if (!prog_fd && !is_optional(moff) && !is_unsupported(moff))
return -EINVAL;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment