[PATCH v2 6/6] bpf: add support for new fields in struct bpf_prog_info

Paul Chaignon paul at isovalent.com
Thu Dec 30 11:00:00 UTC 2021


* src/bpf_attr.h (struct bpf_prog_info_struct): Add recursion_misses and
verified_insns fields.
(expected_bpf_prog_info_struct_size): Update.
* src/bpf.c (print_bpf_prog_info): Decode recursion_misses and
verified_insns fields introduced by Linux kernel commits
v5.12-rc1~200^2~28^2~28 and v5.16-rc1~159^2~2^2~43^2~1.
* tests/bpf-obj_get_info_by_fd.c (main): Update expected output.

Signed-off-by: Paul Chaignon <paul at isovalent.com>
---
 src/bpf.c                      | 20 ++++++++++++++++++++
 src/bpf_attr.h                 |  6 ++++--
 tests/bpf-obj_get_info_by_fd.c |  7 +++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/bpf.c b/src/bpf.c
index d1ac17f0a..801968048 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -923,6 +923,26 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd,
 	tprint_struct_next();
 	PRINT_FIELD_U(info, run_cnt);
 
+	/*
+	 * The following field was introduced by Linux commit
+	 * v5.12-rc1~200^2~28^2~28.
+	 */
+	if (len <= offsetof(struct bpf_prog_info_struct, recursion_misses))
+		goto print_bpf_prog_info_end;
+
+	tprint_struct_next();
+	PRINT_FIELD_U64(info, recursion_misses);
+
+	/*
+	 * The following field was introduced by Linux commit
+	 * v5.16-rc1~159^2~2^2~43^2~1.
+	 */
+	if (len <= offsetof(struct bpf_prog_info_struct, verified_insns))
+		goto print_bpf_prog_info_end;
+
+	tprint_struct_next();
+	PRINT_FIELD_U(info, verified_insns);
+
 	decode_attr_extra_data(tcp, info_buf, size, bpf_prog_info_struct_size);
 
 print_bpf_prog_info_end:
diff --git a/src/bpf_attr.h b/src/bpf_attr.h
index ca686c6cc..80b5cb457 100644
--- a/src/bpf_attr.h
+++ b/src/bpf_attr.h
@@ -362,11 +362,13 @@ struct bpf_prog_info_struct {
 	uint64_t ATTRIBUTE_ALIGNED(8) prog_tags;
 	uint64_t ATTRIBUTE_ALIGNED(8) run_time_ns;
 	uint64_t ATTRIBUTE_ALIGNED(8) run_cnt;
+	uint64_t ATTRIBUTE_ALIGNED(8) recursion_misses;
+	uint32_t verified_insns;
 };
 
 # define bpf_prog_info_struct_size \
-	sizeof(struct bpf_prog_info_struct)
-# define expected_bpf_prog_info_struct_size 208
+	offsetofend(struct bpf_prog_info_struct, verified_insns)
+# define expected_bpf_prog_info_struct_size 220
 
 struct BPF_MAP_LOOKUP_BATCH_struct /* batch */ {
 	uint64_t ATTRIBUTE_ALIGNED(8) in_batch;
diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c
index 95392cd53..71b13b91f 100644
--- a/tests/bpf-obj_get_info_by_fd.c
+++ b/tests/bpf-obj_get_info_by_fd.c
@@ -705,6 +705,13 @@ main(int ac, char **av)
 		    offsetof(struct bpf_prog_info_struct, run_cnt))
 			printf(", run_cnt=%llu",
 			       (unsigned long long) prog_info->run_cnt);
+		if (bpf_prog_get_info_attr.info_len >
+		    offsetof(struct bpf_prog_info_struct, recursion_misses))
+			printf(", recursion_misses=%llu",
+			       (unsigned long long) prog_info->recursion_misses);
+		if (bpf_prog_get_info_attr.info_len >
+		    offsetof(struct bpf_prog_info_struct, verified_insns))
+			printf(", verified_insns=%u", prog_info->verified_insns);
 
 		printf("}");
 # else /* !VERBOSE */
-- 
2.25.1



More information about the Strace-devel mailing list