diff options
author | Brian Norris <computersforpeace@gmail.com> | 2017-05-15 14:19:19 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2017-05-15 14:19:19 -0400 |
commit | c316cf670491def52a396d3bdc5a63ad01f7fefa (patch) | |
tree | bf22299ce777088d190b532629b1bd647d28fab6 /tools/lib/bpf/bpf.c | |
parent | 6c51a52eeb58befd2e9be2ed7ee2c4c04139b336 (diff) | |
parent | 2ea659a9ef488125eb46da6eb571de5eae5c43f6 (diff) |
Merge 'v4.12-rc1' into MTD
Bring a few queued patches in sync for -next development.
Diffstat (limited to 'tools/lib/bpf/bpf.c')
-rw-r--r-- | tools/lib/bpf/bpf.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 207c2eeddab0..4fe444b8092e 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -37,6 +37,8 @@ | |||
37 | # define __NR_bpf 321 | 37 | # define __NR_bpf 321 |
38 | # elif defined(__aarch64__) | 38 | # elif defined(__aarch64__) |
39 | # define __NR_bpf 280 | 39 | # define __NR_bpf 280 |
40 | # elif defined(__sparc__) | ||
41 | # define __NR_bpf 349 | ||
40 | # else | 42 | # else |
41 | # error __NR_bpf not defined. libbpf does not support your arch. | 43 | # error __NR_bpf not defined. libbpf does not support your arch. |
42 | # endif | 44 | # endif |
@@ -69,6 +71,23 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, | |||
69 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); | 71 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); |
70 | } | 72 | } |
71 | 73 | ||
74 | int bpf_create_map_in_map(enum bpf_map_type map_type, int key_size, | ||
75 | int inner_map_fd, int max_entries, __u32 map_flags) | ||
76 | { | ||
77 | union bpf_attr attr; | ||
78 | |||
79 | memset(&attr, '\0', sizeof(attr)); | ||
80 | |||
81 | attr.map_type = map_type; | ||
82 | attr.key_size = key_size; | ||
83 | attr.value_size = 4; | ||
84 | attr.inner_map_fd = inner_map_fd; | ||
85 | attr.max_entries = max_entries; | ||
86 | attr.map_flags = map_flags; | ||
87 | |||
88 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); | ||
89 | } | ||
90 | |||
72 | int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, | 91 | int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, |
73 | size_t insns_cnt, const char *license, | 92 | size_t insns_cnt, const char *license, |
74 | __u32 kern_version, char *log_buf, size_t log_buf_sz) | 93 | __u32 kern_version, char *log_buf, size_t log_buf_sz) |
@@ -192,3 +211,27 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type) | |||
192 | 211 | ||
193 | return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); | 212 | return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); |
194 | } | 213 | } |
214 | |||
215 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, | ||
216 | void *data_out, __u32 *size_out, __u32 *retval, | ||
217 | __u32 *duration) | ||
218 | { | ||
219 | union bpf_attr attr; | ||
220 | int ret; | ||
221 | |||
222 | bzero(&attr, sizeof(attr)); | ||
223 | attr.test.prog_fd = prog_fd; | ||
224 | attr.test.data_in = ptr_to_u64(data); | ||
225 | attr.test.data_out = ptr_to_u64(data_out); | ||
226 | attr.test.data_size_in = size; | ||
227 | attr.test.repeat = repeat; | ||
228 | |||
229 | ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); | ||
230 | if (size_out) | ||
231 | *size_out = attr.test.data_size_out; | ||
232 | if (retval) | ||
233 | *retval = attr.test.retval; | ||
234 | if (duration) | ||
235 | *duration = attr.test.duration; | ||
236 | return ret; | ||
237 | } | ||