From: Alexei Starovoitov <ast@xxxxxxxxxx> Prototype of bpf_core_apply_relo() helper. Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 14 ++++++++++++++ kernel/bpf/btf.c | 22 ++++++++++++++++++++++ kernel/bpf/syscall.c | 2 ++ tools/include/uapi/linux/bpf.h | 14 ++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index b6c45a6cbbba..a3cb8ea272f7 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2102,6 +2102,7 @@ extern const struct bpf_func_proto bpf_for_each_map_elem_proto; extern const struct bpf_func_proto bpf_btf_find_by_name_kind_proto; extern const struct bpf_func_proto bpf_sk_setsockopt_proto; extern const struct bpf_func_proto bpf_sk_getsockopt_proto; +extern const struct bpf_func_proto bpf_core_apply_relo_proto; const struct bpf_func_proto *tracing_prog_func_proto( enum bpf_func_id func_id, const struct bpf_prog *prog); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 8fb61f22b72c..c2b8857b8a1c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -4909,6 +4909,13 @@ union bpf_attr { * Return * The number of bytes written to the buffer, or a negative error * in case of failure. + * + * long bpf_core_apply_relo(int btf_fd, struct bpf_core_relo_desc *relo, int relo_sz, + * struct bpf_insn *insn, int flags) + * Description + * Apply given relo. + * Return + * Returns 0 on success. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5089,6 +5096,7 @@ union bpf_attr { FN(task_pt_regs), \ FN(get_branch_snapshot), \ FN(trace_vprintk), \ + FN(core_apply_relo), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper @@ -6313,4 +6321,10 @@ enum bpf_core_relo_kind { BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */ }; +struct bpf_core_relo_desc { + __u32 type_id; + __u32 access_str_off; + enum bpf_core_relo_kind kind; +}; + #endif /* _UAPI__LINUX_BPF_H__ */ diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index fa2c88f6ac4a..9bb1247346ce 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6369,3 +6369,25 @@ size_t bpf_core_essential_name_len(const char *name) } return n; } + +BPF_CALL_5(bpf_core_apply_relo, int, btf_fd, struct bpf_core_relo_desc *, relo, + int, relo_sz, void *, insn, int, flags) +{ + struct btf *btf; + long ret; + + if (flags) + return -EINVAL; + return -EOPNOTSUPP; +} + +const struct bpf_func_proto bpf_core_apply_relo_proto = { + .func = bpf_core_apply_relo, + .gpl_only = false, + .ret_type = RET_INTEGER, + .arg1_type = ARG_ANYTHING, + .arg2_type = ARG_PTR_TO_MEM, + .arg3_type = ARG_CONST_SIZE, + .arg4_type = ARG_PTR_TO_LONG, + .arg5_type = ARG_ANYTHING, +}; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4e50c0bfdb7d..3c349b244a28 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4763,6 +4763,8 @@ syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_btf_find_by_name_kind_proto; case BPF_FUNC_sys_close: return &bpf_sys_close_proto; + case BPF_FUNC_core_apply_relo: + return &bpf_core_apply_relo_proto; default: return tracing_prog_func_proto(func_id, prog); } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 8fb61f22b72c..c2b8857b8a1c 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -4909,6 +4909,13 @@ union bpf_attr { * Return * The number of bytes written to the buffer, or a negative error * in case of failure. + * + * long bpf_core_apply_relo(int btf_fd, struct bpf_core_relo_desc *relo, int relo_sz, + * struct bpf_insn *insn, int flags) + * Description + * Apply given relo. + * Return + * Returns 0 on success. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5089,6 +5096,7 @@ union bpf_attr { FN(task_pt_regs), \ FN(get_branch_snapshot), \ FN(trace_vprintk), \ + FN(core_apply_relo), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper @@ -6313,4 +6321,10 @@ enum bpf_core_relo_kind { BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */ }; +struct bpf_core_relo_desc { + __u32 type_id; + __u32 access_str_off; + enum bpf_core_relo_kind kind; +}; + #endif /* _UAPI__LINUX_BPF_H__ */ -- 2.30.2