aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorDavid Miller <davem@davemloft.net>2018-12-01 00:08:14 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-12-01 00:38:48 -0500
commite9ee9efc0d176512cdce9d27ff8549d7ffa2bfcd (patch)
tree94b32bfcaa32c3538810330370ed7cd4b07e15e4 /tools/lib/bpf
parent88945f460603ad8909b556c67a9229bb23188d41 (diff)
bpf: Add BPF_F_ANY_ALIGNMENT.
Often we want to write tests cases that check things like bad context offset accesses. And one way to do this is to use an odd offset on, for example, a 32-bit load. This unfortunately triggers the alignment checks first on platforms that do not set CONFIG_EFFICIENT_UNALIGNED_ACCESS. So the test case see the alignment failure rather than what it was testing for. It is often not completely possible to respect the original intention of the test, or even test the same exact thing, while solving the alignment issue. Another option could have been to check the alignment after the context and other validations are performed by the verifier, but that is a non-trivial change to the verifier. Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/bpf.c8
-rw-r--r--tools/lib/bpf/bpf.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index ce1822194590..c19226cccf39 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -279,9 +279,9 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
279} 279}
280 280
281int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, 281int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
282 size_t insns_cnt, int strict_alignment, 282 size_t insns_cnt, __u32 prog_flags, const char *license,
283 const char *license, __u32 kern_version, 283 __u32 kern_version, char *log_buf, size_t log_buf_sz,
284 char *log_buf, size_t log_buf_sz, int log_level) 284 int log_level)
285{ 285{
286 union bpf_attr attr; 286 union bpf_attr attr;
287 287
@@ -295,7 +295,7 @@ int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
295 attr.log_level = log_level; 295 attr.log_level = log_level;
296 log_buf[0] = 0; 296 log_buf[0] = 0;
297 attr.kern_version = kern_version; 297 attr.kern_version = kern_version;
298 attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0; 298 attr.prog_flags = prog_flags;
299 299
300 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 300 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
301} 301}
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 09e8bbe111d4..60392b70587c 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -98,7 +98,7 @@ LIBBPF_API int bpf_load_program(enum bpf_prog_type type,
98 char *log_buf, size_t log_buf_sz); 98 char *log_buf, size_t log_buf_sz);
99LIBBPF_API int bpf_verify_program(enum bpf_prog_type type, 99LIBBPF_API int bpf_verify_program(enum bpf_prog_type type,
100 const struct bpf_insn *insns, 100 const struct bpf_insn *insns,
101 size_t insns_cnt, int strict_alignment, 101 size_t insns_cnt, __u32 prog_flags,
102 const char *license, __u32 kern_version, 102 const char *license, __u32 kern_version,
103 char *log_buf, size_t log_buf_sz, 103 char *log_buf, size_t log_buf_sz,
104 int log_level); 104 int log_level);