[PATCH v2 4/6] bpf: support new fields for BPF_PROG_TEST_RUN
Paul Chaignon
paul at isovalent.com
Thu Dec 30 10:59:45 UTC 2021
* src/bpf_attr.h (BPF_PROG_TEST_RUN_struct): Add flags and cpu fields
introduced by Linux kernel commit v5.10-rc1~107^2~96^2~36.
(expected_BPF_PROG_TEST_RUN_struct_size): Update.
* src/xlat/bpf_test_run_flags.in: New file.
* src/bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)): Decode the new
fields.
* NEWS: Mention this.
* tests/bpf.c (BPF_PROG_TEST_RUN_check): Update expected output.
Signed-off-by: Paul Chaignon <paul at isovalent.com>
---
NEWS | 3 ++-
src/bpf.c | 10 ++++++++++
src/bpf_attr.h | 4 +++-
src/xlat/bpf_test_run_flags.in | 1 +
tests/bpf.c | 11 ++++++++---
5 files changed, 24 insertions(+), 5 deletions(-)
create mode 100644 src/xlat/bpf_test_run_flags.in
diff --git a/NEWS b/NEWS
index 9b8c1ec6b..d40e7c8bb 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,8 @@ Noteworthy changes in release ?.?? (????-??-??)
===============================================
* Improvements
- * Enhanced decoding of BPF_MAP_CREATE and BPF_PROG_LOAD bpf syscall commands.
+ * Enhanced decoding of BPF_MAP_CREATE, BPF_PROG_TEST_RUN, and BPF_PROG_LOAD
+ bpf syscall commands.
* Updated lists of BPF_* constants.
* Updated lists of ioctl commands from Linux 5.16.
diff --git a/src/bpf.c b/src/bpf.c
index c909d93cf..44f0191a3 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -28,6 +28,7 @@
#include "xlat/bpf_attach_flags.h"
#include "xlat/bpf_query_flags.h"
#include "xlat/bpf_task_fd_type.h"
+#include "xlat/bpf_test_run_flags.h"
#include "xlat/ebpf_regs.h"
#include "xlat/numa_node.h"
@@ -508,6 +509,15 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)
tprint_struct_next();
PRINT_FIELD_ADDR64(attr, ctx_out);
}
+ /* The following two fields were introduced in Linux commit
+ * v5.10-rc1~107^2~96^2~36.
+ */
+ if (len > offsetof(struct BPF_PROG_TEST_RUN_struct, flags)) {
+ tprint_struct_next();
+ PRINT_FIELD_FLAGS(attr, flags, bpf_test_run_flags, "BPF_F_???");
+ tprint_struct_next();
+ PRINT_FIELD_U(attr, cpu);
+ }
tprint_struct_end();
}
END_BPF_CMD_DECODER(RVAL_DECODED)
diff --git a/src/bpf_attr.h b/src/bpf_attr.h
index f21dbb54d..9f1618264 100644
--- a/src/bpf_attr.h
+++ b/src/bpf_attr.h
@@ -184,11 +184,13 @@ struct BPF_PROG_TEST_RUN_struct /* test */ {
uint32_t ctx_size_out;
uint64_t ATTRIBUTE_ALIGNED(8) ctx_in;
uint64_t ATTRIBUTE_ALIGNED(8) ctx_out;
+ uint32_t flags;
+ uint32_t cpu;
};
# define BPF_PROG_TEST_RUN_struct_size \
sizeof(struct BPF_PROG_TEST_RUN_struct)
-# define expected_BPF_PROG_TEST_RUN_struct_size 64
+# define expected_BPF_PROG_TEST_RUN_struct_size 72
struct BPF_PROG_GET_NEXT_ID_struct {
uint32_t start_id;
diff --git a/src/xlat/bpf_test_run_flags.in b/src/xlat/bpf_test_run_flags.in
new file mode 100644
index 000000000..318e6e9a9
--- /dev/null
+++ b/src/xlat/bpf_test_run_flags.in
@@ -0,0 +1 @@
+BPF_F_TEST_RUN_ON_CPU (1U << 0)
diff --git a/tests/bpf.c b/tests/bpf.c
index eeba43821..b61e23bc2 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -29,6 +29,7 @@
#include "xlat/bpf_commands.h"
#include "xlat/bpf_map_types.h"
#include "xlat/bpf_prog_types.h"
+#include "xlat/bpf_test_run_flags.h"
#if defined MPERS_IS_m32 || SIZEOF_KERNEL_LONG_T > 4
# define BIG_ADDR(addr64_, addr32_) addr64_
@@ -947,9 +948,11 @@ static const struct bpf_attr_check BPF_PROG_TEST_RUN_checks[] = {
.ctx_size_in = 0xfacbfedc,
.ctx_size_out = 0xfacdfede,
.ctx_in = (uint64_t) 0xfacef55dbadc6dedULL,
- .ctx_out = (uint64_t) 0xfacef77dbadc8dedULL
+ .ctx_out = (uint64_t) 0xfacef77dbadc8dedULL,
+ .flags = BPF_F_TEST_RUN_ON_CPU,
+ .cpu = 1,
} },
- .size = offsetofend(struct BPF_PROG_TEST_RUN_struct, ctx_out),
+ .size = offsetofend(struct BPF_PROG_TEST_RUN_struct, cpu),
.str = "test={prog_fd=-1, retval=4207017682"
", data_size_in=4207148756, data_size_out=4207279830"
", data_in=0xfacef11dbadc2ded"
@@ -959,7 +962,9 @@ static const struct bpf_attr_check BPF_PROG_TEST_RUN_checks[] = {
", ctx_size_in=4207673052"
", ctx_size_out=4207804126"
", ctx_in=0xfacef55dbadc6ded"
- ", ctx_out=0xfacef77dbadc8ded}"
+ ", ctx_out=0xfacef77dbadc8ded"
+ ", flags=BPF_F_TEST_RUN_ON_CPU"
+ ", cpu=1}"
}
};
--
2.25.1
More information about the Strace-devel
mailing list