diff options
author | Quentin Monnet <quentin.monnet@netronome.com> | 2019-08-20 05:31:50 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-08-20 12:51:06 -0400 |
commit | 1b9ed84ecf268904d89edf2908426a8eb3b5a4ba (patch) | |
tree | 66b002286c9a5a1ff26dcb800c4230f7c5213f63 | |
parent | 098454362a06029c1abc175b74409bf7d6e6604b (diff) |
bpf: add new BPF_BTF_GET_NEXT_ID syscall command
Add a new command for the bpf() system call: BPF_BTF_GET_NEXT_ID is used
to cycle through all BTF objects loaded on the system.
The motivation is to be able to inspect (list) all BTF objects presents
on the system.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | include/linux/bpf.h | 3 | ||||
-rw-r--r-- | include/uapi/linux/bpf.h | 1 | ||||
-rw-r--r-- | kernel/bpf/btf.c | 4 | ||||
-rw-r--r-- | kernel/bpf/syscall.c | 4 |
4 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 15ae49862b82..5b9d22338606 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h | |||
@@ -24,6 +24,9 @@ struct seq_file; | |||
24 | struct btf; | 24 | struct btf; |
25 | struct btf_type; | 25 | struct btf_type; |
26 | 26 | ||
27 | extern struct idr btf_idr; | ||
28 | extern spinlock_t btf_idr_lock; | ||
29 | |||
27 | /* map is generic key/value storage optionally accesible by eBPF programs */ | 30 | /* map is generic key/value storage optionally accesible by eBPF programs */ |
28 | struct bpf_map_ops { | 31 | struct bpf_map_ops { |
29 | /* funcs callable from userspace (via syscall) */ | 32 | /* funcs callable from userspace (via syscall) */ |
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 0ef594ac3899..8aa6126f0b6e 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h | |||
@@ -106,6 +106,7 @@ enum bpf_cmd { | |||
106 | BPF_TASK_FD_QUERY, | 106 | BPF_TASK_FD_QUERY, |
107 | BPF_MAP_LOOKUP_AND_DELETE_ELEM, | 107 | BPF_MAP_LOOKUP_AND_DELETE_ELEM, |
108 | BPF_MAP_FREEZE, | 108 | BPF_MAP_FREEZE, |
109 | BPF_BTF_GET_NEXT_ID, | ||
109 | }; | 110 | }; |
110 | 111 | ||
111 | enum bpf_map_type { | 112 | enum bpf_map_type { |
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 6b403dc18486..adb3adcebe3c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c | |||
@@ -195,8 +195,8 @@ | |||
195 | i < btf_type_vlen(struct_type); \ | 195 | i < btf_type_vlen(struct_type); \ |
196 | i++, member++) | 196 | i++, member++) |
197 | 197 | ||
198 | static DEFINE_IDR(btf_idr); | 198 | DEFINE_IDR(btf_idr); |
199 | static DEFINE_SPINLOCK(btf_idr_lock); | 199 | DEFINE_SPINLOCK(btf_idr_lock); |
200 | 200 | ||
201 | struct btf { | 201 | struct btf { |
202 | void *data; | 202 | void *data; |
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index cf8052b016e7..c0f62fd67c6b 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -2884,6 +2884,10 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz | |||
2884 | err = bpf_obj_get_next_id(&attr, uattr, | 2884 | err = bpf_obj_get_next_id(&attr, uattr, |
2885 | &map_idr, &map_idr_lock); | 2885 | &map_idr, &map_idr_lock); |
2886 | break; | 2886 | break; |
2887 | case BPF_BTF_GET_NEXT_ID: | ||
2888 | err = bpf_obj_get_next_id(&attr, uattr, | ||
2889 | &btf_idr, &btf_idr_lock); | ||
2890 | break; | ||
2887 | case BPF_PROG_GET_FD_BY_ID: | 2891 | case BPF_PROG_GET_FD_BY_ID: |
2888 | err = bpf_prog_get_fd_by_id(&attr); | 2892 | err = bpf_prog_get_fd_by_id(&attr); |
2889 | break; | 2893 | break; |