diff options
author | Stanislav Fomichev <sdf@google.com> | 2019-04-09 14:49:10 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-04-11 04:21:41 -0400 |
commit | 5e903c656b98614698a891c6e098186272cbba14 (patch) | |
tree | 3be59bca2d7c6bc7e1b19dbce746fe5a19fde349 | |
parent | b0b9395d865e3060d97658fbc9ba3f77fecc8da1 (diff) |
libbpf: add support for ctx_{size, }_{in, out} in BPF_PROG_TEST_RUN
Support recently introduced input/output context for test runs.
We extend only bpf_prog_test_run_xattr. bpf_prog_test_run is
unextendable and left as is.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | tools/include/uapi/linux/bpf.h | 7 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.c | 5 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 5 |
3 files changed, 17 insertions, 0 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index af1cbd951f26..31a27dd337dc 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h | |||
@@ -412,6 +412,13 @@ union bpf_attr { | |||
412 | __aligned_u64 data_out; | 412 | __aligned_u64 data_out; |
413 | __u32 repeat; | 413 | __u32 repeat; |
414 | __u32 duration; | 414 | __u32 duration; |
415 | __u32 ctx_size_in; /* input: len of ctx_in */ | ||
416 | __u32 ctx_size_out; /* input/output: len of ctx_out | ||
417 | * returns ENOSPC if ctx_out | ||
418 | * is too small. | ||
419 | */ | ||
420 | __aligned_u64 ctx_in; | ||
421 | __aligned_u64 ctx_out; | ||
415 | } test; | 422 | } test; |
416 | 423 | ||
417 | struct { /* anonymous struct used by BPF_*_GET_*_ID */ | 424 | struct { /* anonymous struct used by BPF_*_GET_*_ID */ |
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index dababce68f0b..955191c64b64 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -554,10 +554,15 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr) | |||
554 | attr.test.data_out = ptr_to_u64(test_attr->data_out); | 554 | attr.test.data_out = ptr_to_u64(test_attr->data_out); |
555 | attr.test.data_size_in = test_attr->data_size_in; | 555 | attr.test.data_size_in = test_attr->data_size_in; |
556 | attr.test.data_size_out = test_attr->data_size_out; | 556 | attr.test.data_size_out = test_attr->data_size_out; |
557 | attr.test.ctx_in = ptr_to_u64(test_attr->ctx_in); | ||
558 | attr.test.ctx_out = ptr_to_u64(test_attr->ctx_out); | ||
559 | attr.test.ctx_size_in = test_attr->ctx_size_in; | ||
560 | attr.test.ctx_size_out = test_attr->ctx_size_out; | ||
557 | attr.test.repeat = test_attr->repeat; | 561 | attr.test.repeat = test_attr->repeat; |
558 | 562 | ||
559 | ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); | 563 | ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); |
560 | test_attr->data_size_out = attr.test.data_size_out; | 564 | test_attr->data_size_out = attr.test.data_size_out; |
565 | test_attr->ctx_size_out = attr.test.ctx_size_out; | ||
561 | test_attr->retval = attr.test.retval; | 566 | test_attr->retval = attr.test.retval; |
562 | test_attr->duration = attr.test.duration; | 567 | test_attr->duration = attr.test.duration; |
563 | return ret; | 568 | return ret; |
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index c9d218d21453..bc30783d1403 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -136,6 +136,11 @@ struct bpf_prog_test_run_attr { | |||
136 | * out: length of data_out */ | 136 | * out: length of data_out */ |
137 | __u32 retval; /* out: return code of the BPF program */ | 137 | __u32 retval; /* out: return code of the BPF program */ |
138 | __u32 duration; /* out: average per repetition in ns */ | 138 | __u32 duration; /* out: average per repetition in ns */ |
139 | const void *ctx_in; /* optional */ | ||
140 | __u32 ctx_size_in; | ||
141 | void *ctx_out; /* optional */ | ||
142 | __u32 ctx_size_out; /* in: max length of ctx_out | ||
143 | * out: length of cxt_out */ | ||
139 | }; | 144 | }; |
140 | 145 | ||
141 | LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); | 146 | LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); |