* [PATCH bpf-next 0/3] migrate from bpf_prog_test_run{,_xattr}
@ 2022-01-27 23:58 Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 3/3] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run Delyan Kratunov
0 siblings, 2 replies; 3+ messages in thread
From: Delyan Kratunov @ 2022-01-27 23:58 UTC (permalink / raw)
To: bpf, ast, andrii, daniel; +Cc: Delyan Kratunov, lmb
Fairly straight-forward mechanical transformation from bpf_prog_test_run
and bpf_prog_test_run_xattr to the bpf_prog_test_run_opts goodness.
Most of the changes are in tests, though bpftool and libbpf (xsk.c) have one
call site each as well.
The only aspect that's still a bit RFC is that prog_run_xattr is testing
behavior specific to bpf_prog_test_run_xattr, which does not exist in prog_run_opts.
Namely, -EINVAL return on data_out == NULL && data_size_out > 0.
Adding this behavior to prog_test_run_opts is one option, keeping the test as-is
and cloning it to use bpf_prog_test_run_opts is another possibility.
The current version just suppresses the deprecation warning.
As an aside, checkpatch really doesn't like that LIBBPF_OPTS looks like
a function call but is formatted like a struct declaration. If anyone
cares about formatting, now would be a good time to mention it.
Delyan Kratunov (3):
selftests: bpf: migrate from bpf_prog_test_run{,_xattr}
bpftool: migrate from bpf_prog_test_run_xattr
libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run
tools/bpf/bpftool/prog.c | 55 ++--
tools/lib/bpf/bpf.h | 8 +-
tools/lib/bpf/xsk.c | 11 +-
.../selftests/bpf/prog_tests/atomics.c | 86 +++---
.../testing/selftests/bpf/prog_tests/bpf_nf.c | 10 +-
.../selftests/bpf/prog_tests/check_mtu.c | 47 ++--
.../selftests/bpf/prog_tests/cls_redirect.c | 30 +--
.../selftests/bpf/prog_tests/dummy_st_ops.c | 31 +--
.../selftests/bpf/prog_tests/fentry_fexit.c | 33 ++-
.../selftests/bpf/prog_tests/fentry_test.c | 9 +-
.../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 33 ++-
.../selftests/bpf/prog_tests/fexit_stress.c | 26 +-
.../selftests/bpf/prog_tests/fexit_test.c | 9 +-
.../selftests/bpf/prog_tests/flow_dissector.c | 75 +++---
.../prog_tests/flow_dissector_load_bytes.c | 27 +-
.../selftests/bpf/prog_tests/for_each.c | 32 ++-
.../bpf/prog_tests/get_func_args_test.c | 14 +-
.../bpf/prog_tests/get_func_ip_test.c | 12 +-
.../selftests/bpf/prog_tests/global_data.c | 25 +-
.../bpf/prog_tests/global_func_args.c | 13 +-
.../selftests/bpf/prog_tests/kfree_skb.c | 16 +-
.../selftests/bpf/prog_tests/kfunc_call.c | 46 ++--
.../selftests/bpf/prog_tests/ksyms_module.c | 23 +-
.../selftests/bpf/prog_tests/l4lb_all.c | 35 ++-
.../selftests/bpf/prog_tests/map_lock.c | 15 +-
.../selftests/bpf/prog_tests/map_ptr.c | 18 +-
.../selftests/bpf/prog_tests/modify_return.c | 38 +--
.../selftests/bpf/prog_tests/pkt_access.c | 27 +-
.../selftests/bpf/prog_tests/pkt_md_access.c | 15 +-
.../selftests/bpf/prog_tests/prog_run_xattr.c | 5 +
.../bpf/prog_tests/queue_stack_map.c | 43 +--
.../bpf/prog_tests/raw_tp_test_run.c | 85 +++---
.../bpf/prog_tests/raw_tp_writable_test_run.c | 16 +-
.../selftests/bpf/prog_tests/signal_pending.c | 24 +-
.../selftests/bpf/prog_tests/skb_ctx.c | 93 +++----
.../selftests/bpf/prog_tests/skb_helpers.c | 16 +-
.../selftests/bpf/prog_tests/sockmap_basic.c | 19 +-
.../selftests/bpf/prog_tests/spinlock.c | 15 +-
.../selftests/bpf/prog_tests/syscall.c | 12 +-
.../selftests/bpf/prog_tests/tailcalls.c | 245 ++++++++++--------
.../selftests/bpf/prog_tests/test_profiler.c | 16 +-
.../bpf/prog_tests/test_skb_pkt_end.c | 15 +-
.../testing/selftests/bpf/prog_tests/timer.c | 9 +-
.../selftests/bpf/prog_tests/timer_mim.c | 9 +-
.../selftests/bpf/prog_tests/trace_ext.c | 28 +-
tools/testing/selftests/bpf/prog_tests/xdp.c | 35 ++-
.../bpf/prog_tests/xdp_adjust_frags.c | 34 ++-
.../bpf/prog_tests/xdp_adjust_tail.c | 148 ++++++-----
.../selftests/bpf/prog_tests/xdp_bpf2bpf.c | 16 +-
.../selftests/bpf/prog_tests/xdp_noinline.c | 45 ++--
.../selftests/bpf/prog_tests/xdp_perf.c | 19 +-
tools/testing/selftests/bpf/test_lru_map.c | 11 +-
tools/testing/selftests/bpf/test_progs.h | 2 +
tools/testing/selftests/bpf/test_verifier.c | 16 +-
54 files changed, 993 insertions(+), 802 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr
2022-01-27 23:58 [PATCH bpf-next 0/3] migrate from bpf_prog_test_run{,_xattr} Delyan Kratunov
@ 2022-01-27 23:58 ` Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 3/3] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run Delyan Kratunov
1 sibling, 0 replies; 3+ messages in thread
From: Delyan Kratunov @ 2022-01-27 23:58 UTC (permalink / raw)
To: bpf, ast, andrii, daniel; +Cc: Delyan Kratunov
bpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts.
Signed-off-by: Delyan Kratunov <delyank@fb.com>
---
tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 87593f98d2d1..4f96c229ba77 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -1272,12 +1272,12 @@ static int do_run(int argc, char **argv)
{
char *data_fname_in = NULL, *data_fname_out = NULL;
char *ctx_fname_in = NULL, *ctx_fname_out = NULL;
- struct bpf_prog_test_run_attr test_attr = {0};
const unsigned int default_size = SZ_32K;
void *data_in = NULL, *data_out = NULL;
void *ctx_in = NULL, *ctx_out = NULL;
unsigned int repeat = 1;
int fd, err;
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
if (!REQ_ARGS(4))
return -1;
@@ -1315,7 +1315,7 @@ static int do_run(int argc, char **argv)
if (!REQ_ARGS(1))
return -1;
- test_attr.data_size_out = strtoul(*argv, &endptr, 0);
+ topts.data_size_out = strtoul(*argv, &endptr, 0);
if (*endptr) {
p_err("can't parse %s as output data size",
*argv);
@@ -1343,7 +1343,7 @@ static int do_run(int argc, char **argv)
if (!REQ_ARGS(1))
return -1;
- test_attr.ctx_size_out = strtoul(*argv, &endptr, 0);
+ topts.ctx_size_out = strtoul(*argv, &endptr, 0);
if (*endptr) {
p_err("can't parse %s as output context size",
*argv);
@@ -1371,38 +1371,37 @@ static int do_run(int argc, char **argv)
}
}
- err = get_run_data(data_fname_in, &data_in, &test_attr.data_size_in);
+ err = get_run_data(data_fname_in, &data_in, &topts.data_size_in);
if (err)
return -1;
if (data_in) {
- if (!test_attr.data_size_out)
- test_attr.data_size_out = default_size;
- err = alloc_run_data(&data_out, test_attr.data_size_out);
+ if (!topts.data_size_out)
+ topts.data_size_out = default_size;
+ err = alloc_run_data(&data_out, topts.data_size_out);
if (err)
goto free_data_in;
}
- err = get_run_data(ctx_fname_in, &ctx_in, &test_attr.ctx_size_in);
+ err = get_run_data(ctx_fname_in, &ctx_in, &topts.ctx_size_in);
if (err)
goto free_data_out;
if (ctx_in) {
- if (!test_attr.ctx_size_out)
- test_attr.ctx_size_out = default_size;
- err = alloc_run_data(&ctx_out, test_attr.ctx_size_out);
+ if (!topts.ctx_size_out)
+ topts.ctx_size_out = default_size;
+ err = alloc_run_data(&ctx_out, topts.ctx_size_out);
if (err)
goto free_ctx_in;
}
- test_attr.prog_fd = fd;
- test_attr.repeat = repeat;
- test_attr.data_in = data_in;
- test_attr.data_out = data_out;
- test_attr.ctx_in = ctx_in;
- test_attr.ctx_out = ctx_out;
+ topts.repeat = repeat;
+ topts.data_in = data_in;
+ topts.data_out = data_out;
+ topts.ctx_in = ctx_in;
+ topts.ctx_out = ctx_out;
- err = bpf_prog_test_run_xattr(&test_attr);
+ err = bpf_prog_test_run_opts(fd, &topts);
if (err) {
p_err("failed to run program: %s", strerror(errno));
goto free_ctx_out;
@@ -1416,23 +1415,23 @@ static int do_run(int argc, char **argv)
/* Do not exit on errors occurring when printing output data/context,
* we still want to print return value and duration for program run.
*/
- if (test_attr.data_size_out)
- err += print_run_output(test_attr.data_out,
- test_attr.data_size_out,
+ if (topts.data_size_out)
+ err += print_run_output(topts.data_out,
+ topts.data_size_out,
data_fname_out, "data_out");
- if (test_attr.ctx_size_out)
- err += print_run_output(test_attr.ctx_out,
- test_attr.ctx_size_out,
+ if (topts.ctx_size_out)
+ err += print_run_output(topts.ctx_out,
+ topts.ctx_size_out,
ctx_fname_out, "ctx_out");
if (json_output) {
- jsonw_uint_field(json_wtr, "retval", test_attr.retval);
- jsonw_uint_field(json_wtr, "duration", test_attr.duration);
+ jsonw_uint_field(json_wtr, "retval", topts.retval);
+ jsonw_uint_field(json_wtr, "duration", topts.duration);
jsonw_end_object(json_wtr); /* root */
} else {
fprintf(stdout, "Return value: %u, duration%s: %uns\n",
- test_attr.retval,
- repeat > 1 ? " (average)" : "", test_attr.duration);
+ topts.retval,
+ repeat > 1 ? " (average)" : "", topts.duration);
}
free_ctx_out:
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH bpf-next 3/3] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run
2022-01-27 23:58 [PATCH bpf-next 0/3] migrate from bpf_prog_test_run{,_xattr} Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr Delyan Kratunov
@ 2022-01-27 23:58 ` Delyan Kratunov
1 sibling, 0 replies; 3+ messages in thread
From: Delyan Kratunov @ 2022-01-27 23:58 UTC (permalink / raw)
To: bpf, ast, andrii, daniel; +Cc: Delyan Kratunov
Closes: https://github.com/libbpf/libbpf/issues/286
Signed-off-by: Delyan Kratunov <delyank@fb.com>
---
tools/lib/bpf/bpf.h | 8 +++++---
tools/lib/bpf/xsk.c | 11 +++++++----
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index c2e8327010f9..e3d87b35435d 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -453,13 +453,15 @@ struct bpf_prog_test_run_attr {
* out: length of cxt_out */
};
-LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr);
+LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead")
+int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr);
/*
* bpf_prog_test_run does not check that data_out is large enough. Consider
- * using bpf_prog_test_run_xattr instead.
+ * using bpf_prog_test_run_opts instead.
*/
-LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data,
+LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead")
+int bpf_prog_test_run(int prog_fd, int repeat, void *data,
__u32 size, void *data_out, __u32 *size_out,
__u32 *retval, __u32 *duration);
LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index edafe56664f3..843d03b8f58c 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -369,8 +369,7 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,
static enum xsk_prog get_xsk_prog(void)
{
enum xsk_prog detected = XSK_PROG_FALLBACK;
- __u32 size_out, retval, duration;
- char data_in = 0, data_out;
+ char data_in = 0;
struct bpf_insn insns[] = {
BPF_LD_MAP_FD(BPF_REG_1, 0),
BPF_MOV64_IMM(BPF_REG_2, 0),
@@ -378,6 +377,10 @@ static enum xsk_prog get_xsk_prog(void)
BPF_EMIT_CALL(BPF_FUNC_redirect_map),
BPF_EXIT_INSN(),
};
+ LIBBPF_OPTS(bpf_test_run_opts, test_opts,
+ .data_in = &data_in,
+ .data_size_in = 1,
+ );
int prog_fd, map_fd, ret, insn_cnt = ARRAY_SIZE(insns);
map_fd = bpf_map_create(BPF_MAP_TYPE_XSKMAP, NULL, sizeof(int), sizeof(int), 1, NULL);
@@ -392,8 +395,8 @@ static enum xsk_prog get_xsk_prog(void)
return detected;
}
- ret = bpf_prog_test_run(prog_fd, 0, &data_in, 1, &data_out, &size_out, &retval, &duration);
- if (!ret && retval == XDP_PASS)
+ ret = bpf_prog_test_run_opts(prog_fd, &test_opts);
+ if (!ret && test_opts.retval == XDP_PASS)
detected = XSK_PROG_REDIRECT_FLAGS;
close(prog_fd);
close(map_fd);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-27 23:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-27 23:58 [PATCH bpf-next 0/3] migrate from bpf_prog_test_run{,_xattr} Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr Delyan Kratunov
2022-01-27 23:58 ` [PATCH bpf-next 3/3] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run Delyan Kratunov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).