From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: davem@davemloft.net
Cc: daniel@iogearbox.net, andrii@kernel.org,
john.fastabend@gmail.com, lmb@cloudflare.com,
mcroce@microsoft.com, bpf@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH RFC bpf-next 03/10] bpf: Add proto of bpf_core_apply_relo()
Date: Fri, 17 Sep 2021 14:57:14 -0700 [thread overview]
Message-ID: <20210917215721.43491-4-alexei.starovoitov@gmail.com> (raw)
In-Reply-To: <20210917215721.43491-1-alexei.starovoitov@gmail.com>
From: Alexei Starovoitov <ast@kernel.org>
Prototype of bpf_core_apply_relo() helper.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
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
next prev parent reply other threads:[~2021-09-17 21:57 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-17 21:57 [PATCH RFC bpf-next 00/10] bpf: CO-RE support in the kernel Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 01/10] bpf: Prepare relo_core.c for kernel duty Alexei Starovoitov
2021-09-21 21:25 ` Andrii Nakryiko
2021-09-28 14:45 ` Matteo Croce
2021-09-28 16:37 ` Alexei Starovoitov
2021-09-28 17:11 ` Matteo Croce
2021-09-28 20:34 ` Alexei Starovoitov
2021-09-29 12:32 ` Matteo Croce
2021-09-29 17:38 ` Matteo Croce
2021-09-29 23:00 ` Alexei Starovoitov
2021-09-29 23:49 ` Matteo Croce
2021-10-22 0:48 ` Matteo Croce
2021-10-22 0:51 ` Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 02/10] bpf: Define enum bpf_core_relo_kind as uapi Alexei Starovoitov
2021-09-21 21:27 ` Andrii Nakryiko
2021-09-17 21:57 ` Alexei Starovoitov [this message]
2021-09-23 11:21 ` [PATCH RFC bpf-next 03/10] bpf: Add proto of bpf_core_apply_relo() Lorenz Bauer
2021-09-23 18:48 ` Andrii Nakryiko
2021-09-17 21:57 ` [PATCH RFC bpf-next 04/10] bpf: Add bpf_core_add_cands() and wire it into bpf_core_apply_relo_insn() Alexei Starovoitov
2021-09-21 21:34 ` Andrii Nakryiko
2021-09-27 18:04 ` Matteo Croce
2021-09-17 21:57 ` [PATCH RFC bpf-next 05/10] libbpf: Use CO-RE in the kernel in light skeleton Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 06/10] libbpf: Make gen_loader data aligned Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 07/10] libbpf: Support init of inner maps in light skeleton Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 08/10] selftests/bpf: Convert kfunc test with CO-RE to lskel Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 09/10] selftests/bpf: Improve inner_map test coverage Alexei Starovoitov
2021-09-17 21:57 ` [PATCH RFC bpf-next 10/10] selftests/bpf: Convert map_ptr_kern test to use light skeleton Alexei Starovoitov
2021-09-23 11:33 ` [PATCH RFC bpf-next 00/10] bpf: CO-RE support in the kernel Lorenz Bauer
2021-09-23 18:52 ` Andrii Nakryiko
2021-09-24 23:13 ` Alexei Starovoitov
2021-09-27 16:12 ` Lorenz Bauer
2021-09-27 16:50 ` Alexei Starovoitov
2021-09-28 8:30 ` Lorenz Bauer
2021-09-28 16:35 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210917215721.43491-4-alexei.starovoitov@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@fb.com \
--cc=lmb@cloudflare.com \
--cc=mcroce@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).