mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
bpf: remove struct bpf_prog_type_list
There's no need to have struct bpf_prog_type_list since it just contains a list_head, the type, and the ops pointer. Since the types are densely packed and not actually dynamically registered, it's much easier and smaller to have an array of type->ops pointer. Also initialize this array statically to remove code needed to initialize it. In order to save duplicating the list, move it to a new header file and include it in the places needing it. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
98601e8bc6
commit
be9370a7d8
5 changed files with 44 additions and 122 deletions
|
@ -573,26 +573,21 @@ err_put:
|
|||
return err;
|
||||
}
|
||||
|
||||
static LIST_HEAD(bpf_prog_types);
|
||||
static const struct bpf_verifier_ops * const bpf_prog_types[] = {
|
||||
#define BPF_PROG_TYPE(_id, _ops) \
|
||||
[_id] = &_ops,
|
||||
#include <linux/bpf_types.h>
|
||||
#undef BPF_PROG_TYPE
|
||||
};
|
||||
|
||||
static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
|
||||
{
|
||||
struct bpf_prog_type_list *tl;
|
||||
if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type])
|
||||
return -EINVAL;
|
||||
|
||||
list_for_each_entry(tl, &bpf_prog_types, list_node) {
|
||||
if (tl->type == type) {
|
||||
prog->aux->ops = tl->ops;
|
||||
prog->type = type;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
void bpf_register_prog_type(struct bpf_prog_type_list *tl)
|
||||
{
|
||||
list_add(&tl->list_node, &bpf_prog_types);
|
||||
prog->aux->ops = bpf_prog_types[type];
|
||||
prog->type = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drop refcnt on maps used by eBPF program and free auxilary data */
|
||||
|
|
|
@ -501,16 +501,11 @@ static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type
|
|||
return true;
|
||||
}
|
||||
|
||||
static const struct bpf_verifier_ops kprobe_prog_ops = {
|
||||
const struct bpf_verifier_ops kprobe_prog_ops = {
|
||||
.get_func_proto = kprobe_prog_func_proto,
|
||||
.is_valid_access = kprobe_prog_is_valid_access,
|
||||
};
|
||||
|
||||
static struct bpf_prog_type_list kprobe_tl __ro_after_init = {
|
||||
.ops = &kprobe_prog_ops,
|
||||
.type = BPF_PROG_TYPE_KPROBE,
|
||||
};
|
||||
|
||||
BPF_CALL_5(bpf_perf_event_output_tp, void *, tp_buff, struct bpf_map *, map,
|
||||
u64, flags, void *, data, u64, size)
|
||||
{
|
||||
|
@ -584,16 +579,11 @@ static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type
|
|||
return true;
|
||||
}
|
||||
|
||||
static const struct bpf_verifier_ops tracepoint_prog_ops = {
|
||||
const struct bpf_verifier_ops tracepoint_prog_ops = {
|
||||
.get_func_proto = tp_prog_func_proto,
|
||||
.is_valid_access = tp_prog_is_valid_access,
|
||||
};
|
||||
|
||||
static struct bpf_prog_type_list tracepoint_tl __ro_after_init = {
|
||||
.ops = &tracepoint_prog_ops,
|
||||
.type = BPF_PROG_TYPE_TRACEPOINT,
|
||||
};
|
||||
|
||||
static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
|
||||
enum bpf_reg_type *reg_type)
|
||||
{
|
||||
|
@ -642,22 +632,8 @@ static u32 pe_prog_convert_ctx_access(enum bpf_access_type type,
|
|||
return insn - insn_buf;
|
||||
}
|
||||
|
||||
static const struct bpf_verifier_ops perf_event_prog_ops = {
|
||||
const struct bpf_verifier_ops perf_event_prog_ops = {
|
||||
.get_func_proto = tp_prog_func_proto,
|
||||
.is_valid_access = pe_prog_is_valid_access,
|
||||
.convert_ctx_access = pe_prog_convert_ctx_access,
|
||||
};
|
||||
|
||||
static struct bpf_prog_type_list perf_event_tl __ro_after_init = {
|
||||
.ops = &perf_event_prog_ops,
|
||||
.type = BPF_PROG_TYPE_PERF_EVENT,
|
||||
};
|
||||
|
||||
static int __init register_kprobe_prog_ops(void)
|
||||
{
|
||||
bpf_register_prog_type(&kprobe_tl);
|
||||
bpf_register_prog_type(&tracepoint_tl);
|
||||
bpf_register_prog_type(&perf_event_tl);
|
||||
return 0;
|
||||
}
|
||||
late_initcall(register_kprobe_prog_ops);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue