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

bigjr-mkkong michaelkongboming at gmail.com
Sun Mar 5 03:50:49 UTC 2023


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

---
I plan to apply for Gsoc2023 and this is my micro project.

 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.34.1


>From fe5dc7e1c1235547fff0d50edf7ba5cc1ef88d07 Mon Sep 17 00:00:00 2001
From: bigjr-mkkong <michaelkongboming at gmail.com>
Date: Sat, 4 Mar 2023 14:06:13 -0800
Subject: [PATCH 2/2] add test case for BPF_ENABLE_STATS in linux 6.2

---
 tests/bpf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/bpf.c b/tests/bpf.c
index 76a7698c5..7fcbadd02 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -88,6 +88,7 @@ union bpf_attr_data {
	BPF_ATTR_DATA_FIELD(BPF_LINK_CREATE);
	BPF_ATTR_DATA_FIELD(BPF_LINK_UPDATE);
	BPF_ATTR_DATA_FIELD(BPF_LINK_GET_FD_BY_ID);
+	BPF_ATTR_DATA_FIELD(BPF_ENABLE_STATS);
	char char_data[256];
 };

--
2.34.1


More information about the Strace-devel mailing list