[PATCH 1/2] [GSoC] add support for New bpf command: BPF_ENABLE_STATS

michaelkongboming at gmail.com michaelkongboming at gmail.com
Sun Mar 26 04:28:03 UTC 2023


From: bigjr-mkkong <anybody-else at outlook.com>

---
BPF_ENABLE_STATS command first introduced in kernel v5.8, and these two patches added the support for this command in strace
This is my micro-proj for GSoC 2023
 src/bpf.c                | 8 ++++++++
 src/bpf_attr.h           | 8 ++++++++
 src/xlat/bpf_commands.in | 1 +
 tests/bpf.c              | 8 ++++++++
 4 files changed, 25 insertions(+)

diff --git a/src/bpf.c b/src/bpf.c
index 7bdeb4f65..38af15564 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -1543,6 +1543,13 @@ BEGIN_BPF_CMD_DECODER(BPF_LINK_GET_FD_BY_ID)
 }
 END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)

+BEGIN_BPF_CMD_DECODER(BPF_ENABLE_STATS)
+{
+	tprint_struct_begin();
+	PRINT_FIELD_U(attr, type);
+}
+END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
+
 SYS_FUNC(bpf)
 {
 	static const bpf_cmd_decoder_t bpf_cmd_decoders[] = {
@@ -1578,6 +1585,7 @@ SYS_FUNC(bpf)
 		BPF_CMD_ENTRY(BPF_LINK_UPDATE),
 		BPF_CMD_ENTRY(BPF_LINK_GET_NEXT_ID),
 		BPF_CMD_ENTRY(BPF_LINK_GET_FD_BY_ID),
+		BPF_CMD_ENTRY(BPF_ENABLE_STATS),
 	};

 	const unsigned int cmd = tcp->u_arg[0];
diff --git a/src/bpf_attr.h b/src/bpf_attr.h
index 894c466a5..97496805e 100644
--- a/src/bpf_attr.h
+++ b/src/bpf_attr.h
@@ -446,4 +446,12 @@ struct BPF_LINK_GET_FD_BY_ID_struct {
 	sizeof(struct BPF_LINK_GET_FD_BY_ID_struct)
 # define expected_BPF_LINK_GET_FD_BY_ID_struct_size 4

+struct BPF_ENABLE_STATS_struct{
+	uint32_t type;
+};
+
+#define BPF_ENABLE_STATS_struct_size \
+	sizeof(struct BPF_ENABLE_STATS_struct)
+#define expected_BPF_ENABLE_STATS_struct_size 4
+
 #endif /* !STRACE_BPF_ATTR_H */
diff --git a/src/xlat/bpf_commands.in b/src/xlat/bpf_commands.in
index 07fb7905c..a48675c2e 100644
--- a/src/xlat/bpf_commands.in
+++ b/src/xlat/bpf_commands.in
@@ -35,3 +35,4 @@ BPF_ENABLE_STATS 32
 BPF_ITER_CREATE 33
 BPF_LINK_DETACH 34
 BPF_PROG_BIND_MAP 35
+BPF_ENABLE_STATS 36
\ No newline at end of file
diff --git a/tests/bpf.c b/tests/bpf.c
index 471ed4fc0..76a7698c5 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -1825,6 +1825,13 @@ static const struct bpf_attr_check BPF_LINK_GET_FD_BY_ID_checks[] = {
 	}
 };

+static const struct bpf_attr_check BPF_ENABLE_STATS_checks[] = {
+	{
+		.data = { .BPF_ENABLE_STATS_data = { .type = 0xdeadbeef } },
+		.size = offsetofend(struct BPF_ENABLE_STATS_struct, type),
+		.str = "type=3735928559"
+	}
+};

 #define CHK(cmd_) \
 	{ \
@@ -1868,6 +1875,7 @@ main(void)
 		CHK(BPF_LINK_UPDATE),
 		CHK(BPF_LINK_GET_NEXT_ID),
 		CHK(BPF_LINK_GET_FD_BY_ID),
+		CHK(BPF_ENABLE_STATS),
 	};

 	page_size = get_page_size();
--
2.40.0



More information about the Strace-devel mailing list