diff options
author | Mickaël Salaün <mic@digikod.net> | 2017-02-09 18:21:38 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-02-10 15:56:06 -0500 |
commit | 2ee89fb9a942e250b5adb5535de4acca14bb7fa2 (patch) | |
tree | a2a05ae382318bb1a863aa8afee37055409e521c | |
parent | d02d8986a7688d3f0ff6ef61aa6beb41427692eb (diff) |
bpf: Use bpf_load_program() from the library
Replace bpf_prog_load() with bpf_load_program() calls.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | tools/lib/bpf/bpf.c | 6 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 4 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/Makefile | 4 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/bpf_sys.h | 21 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_tag.c | 6 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 8 |
6 files changed, 17 insertions, 32 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 3ddb58a36d3c..58ce252073fa 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -42,7 +42,7 @@ | |||
42 | # endif | 42 | # endif |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | static __u64 ptr_to_u64(void *ptr) | 45 | static __u64 ptr_to_u64(const void *ptr) |
46 | { | 46 | { |
47 | return (__u64) (unsigned long) ptr; | 47 | return (__u64) (unsigned long) ptr; |
48 | } | 48 | } |
@@ -69,8 +69,8 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, | |||
69 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); | 69 | return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); |
70 | } | 70 | } |
71 | 71 | ||
72 | int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns, | 72 | int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, |
73 | size_t insns_cnt, char *license, | 73 | size_t insns_cnt, const char *license, |
74 | __u32 kern_version, char *log_buf, size_t log_buf_sz) | 74 | __u32 kern_version, char *log_buf, size_t log_buf_sz) |
75 | { | 75 | { |
76 | int fd; | 76 | int fd; |
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index a2f9853dd882..bc959a2de023 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -28,8 +28,8 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, | |||
28 | 28 | ||
29 | /* Recommend log buffer size */ | 29 | /* Recommend log buffer size */ |
30 | #define BPF_LOG_BUF_SIZE 65536 | 30 | #define BPF_LOG_BUF_SIZE 65536 |
31 | int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns, | 31 | int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, |
32 | size_t insns_cnt, char *license, | 32 | size_t insns_cnt, const char *license, |
33 | __u32 kern_version, char *log_buf, | 33 | __u32 kern_version, char *log_buf, |
34 | size_t log_buf_sz); | 34 | size_t log_buf_sz); |
35 | 35 | ||
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index f3d65ad53494..a35f564f66a1 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | CFLAGS += -Wall -O2 -lcap -I../../../include/uapi | 1 | CFLAGS += -Wall -O2 -lcap -I../../../include/uapi -I../../../lib |
2 | 2 | ||
3 | test_objs = test_verifier test_tag test_maps test_lru_map test_lpm_map | 3 | test_objs = test_verifier test_tag test_maps test_lru_map test_lpm_map |
4 | 4 | ||
@@ -7,6 +7,8 @@ TEST_FILES := $(test_objs) | |||
7 | 7 | ||
8 | all: $(test_objs) | 8 | all: $(test_objs) |
9 | 9 | ||
10 | $(test_objs): ../../../lib/bpf/bpf.o | ||
11 | |||
10 | include ../lib.mk | 12 | include ../lib.mk |
11 | 13 | ||
12 | clean: | 14 | clean: |
diff --git a/tools/testing/selftests/bpf/bpf_sys.h b/tools/testing/selftests/bpf/bpf_sys.h index 6b4565f2a3f2..e7bbe3e5402e 100644 --- a/tools/testing/selftests/bpf/bpf_sys.h +++ b/tools/testing/selftests/bpf/bpf_sys.h | |||
@@ -84,25 +84,4 @@ static inline int bpf_map_create(enum bpf_map_type type, uint32_t size_key, | |||
84 | return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); | 84 | return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); |
85 | } | 85 | } |
86 | 86 | ||
87 | static inline int bpf_prog_load(enum bpf_prog_type type, | ||
88 | const struct bpf_insn *insns, size_t size_insns, | ||
89 | const char *license, char *log, size_t size_log) | ||
90 | { | ||
91 | union bpf_attr attr = {}; | ||
92 | |||
93 | attr.prog_type = type; | ||
94 | attr.insns = bpf_ptr_to_u64(insns); | ||
95 | attr.insn_cnt = size_insns / sizeof(struct bpf_insn); | ||
96 | attr.license = bpf_ptr_to_u64(license); | ||
97 | |||
98 | if (size_log > 0) { | ||
99 | attr.log_buf = bpf_ptr_to_u64(log); | ||
100 | attr.log_size = size_log; | ||
101 | attr.log_level = 1; | ||
102 | log[0] = 0; | ||
103 | } | ||
104 | |||
105 | return bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | ||
106 | } | ||
107 | |||
108 | #endif /* __BPF_SYS__ */ | 87 | #endif /* __BPF_SYS__ */ |
diff --git a/tools/testing/selftests/bpf/test_tag.c b/tools/testing/selftests/bpf/test_tag.c index 5f7c602f47d1..dc209721ffd5 100644 --- a/tools/testing/selftests/bpf/test_tag.c +++ b/tools/testing/selftests/bpf/test_tag.c | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <linux/bpf.h> | 16 | #include <linux/bpf.h> |
17 | #include <linux/if_alg.h> | 17 | #include <linux/if_alg.h> |
18 | 18 | ||
19 | #include <bpf/bpf.h> | ||
20 | |||
19 | #include "../../../include/linux/filter.h" | 21 | #include "../../../include/linux/filter.h" |
20 | 22 | ||
21 | #include "bpf_sys.h" | 23 | #include "bpf_sys.h" |
@@ -55,8 +57,8 @@ static int bpf_try_load_prog(int insns, int fd_map, | |||
55 | int fd_prog; | 57 | int fd_prog; |
56 | 58 | ||
57 | bpf_filler(insns, fd_map); | 59 | bpf_filler(insns, fd_map); |
58 | fd_prog = bpf_prog_load(BPF_PROG_TYPE_SCHED_CLS, prog, insns * | 60 | fd_prog = bpf_load_program(BPF_PROG_TYPE_SCHED_CLS, prog, insns, "", 0, |
59 | sizeof(struct bpf_insn), "", NULL, 0); | 61 | NULL, 0); |
60 | assert(fd_prog > 0); | 62 | assert(fd_prog > 0); |
61 | if (fd_map > 0) | 63 | if (fd_map > 0) |
62 | bpf_filler(insns, 0); | 64 | bpf_filler(insns, 0); |
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 878bd60da376..247830ecf68e 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/bpf_perf_event.h> | 24 | #include <linux/bpf_perf_event.h> |
25 | #include <linux/bpf.h> | 25 | #include <linux/bpf.h> |
26 | 26 | ||
27 | #include <bpf/bpf.h> | ||
28 | |||
27 | #include "../../../include/linux/filter.h" | 29 | #include "../../../include/linux/filter.h" |
28 | 30 | ||
29 | #include "bpf_sys.h" | 31 | #include "bpf_sys.h" |
@@ -4535,9 +4537,9 @@ static void do_test_single(struct bpf_test *test, bool unpriv, | |||
4535 | 4537 | ||
4536 | do_test_fixup(test, prog, &fd_f1, &fd_f2, &fd_f3); | 4538 | do_test_fixup(test, prog, &fd_f1, &fd_f2, &fd_f3); |
4537 | 4539 | ||
4538 | fd_prog = bpf_prog_load(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER, | 4540 | fd_prog = bpf_load_program(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER, |
4539 | prog, prog_len * sizeof(struct bpf_insn), | 4541 | prog, prog_len, "GPL", 0, bpf_vlog, |
4540 | "GPL", bpf_vlog, sizeof(bpf_vlog)); | 4542 | sizeof(bpf_vlog)); |
4541 | 4543 | ||
4542 | expected_ret = unpriv && test->result_unpriv != UNDEF ? | 4544 | expected_ret = unpriv && test->result_unpriv != UNDEF ? |
4543 | test->result_unpriv : test->result; | 4545 | test->result_unpriv : test->result; |