[PATCH 1/4] bpf: support new field for BPF_MAP_CREATE

Paul Chaignon paul.chaignon at gmail.com
Sun Feb 23 10:13:02 UTC 2020


* bpf_attr.h (BPF_MAP_CREATE_struct): New field introduced in Linux
v5.6-rc1~151^2~46^2~37^2~5.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Decode the new field.
* NEWS: Mention this.
* tests/bpf-obj_get_info_by_fd.c (print_map_create): Update expected
output.
* tests/bpf.c (BPF_MAP_CREATE_checks): Likewise.

Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
---
 NEWS                           | 1 +
 bpf.c                          | 8 ++++++++
 bpf_attr.h                     | 3 ++-
 tests/bpf-obj_get_info_by_fd.c | 4 ++++
 tests/bpf.c                    | 6 ++++--
 5 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index e27221df..1a4dbdda 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Noteworthy changes in release ?.? (????-??-??)
 ==============================================
 
 * Improvements
+  * Enhanced decoding of BPF_MAP_CREATE bpf syscall command.
 
 * Bug fixes
   * Fixed build on csky abiv1 architecture.
diff --git a/bpf.c b/bpf.c
index b42cf29d..74d46f1b 100644
--- a/bpf.c
+++ b/bpf.c
@@ -224,6 +224,14 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)
 	PRINT_FIELD_FD(", ", attr, btf_fd, tcp);
 	PRINT_FIELD_U(", ", attr, btf_key_type_id);
 	PRINT_FIELD_U(", ", attr, btf_value_type_id);
+
+	/*
+	 * The following field was introduced by Linux commit
+	 * v5.6-rc1~151^2~46^2~37^2~5.
+	 */
+	if (len <= offsetof(struct BPF_MAP_CREATE_struct, btf_vmlinux_value_type_id))
+		break;
+	PRINT_FIELD_U(", ", attr, btf_vmlinux_value_type_id);
 }
 END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
 
diff --git a/bpf_attr.h b/bpf_attr.h
index 33dd54af..b569096b 100644
--- a/bpf_attr.h
+++ b/bpf_attr.h
@@ -49,11 +49,12 @@ struct BPF_MAP_CREATE_struct {
 	uint32_t btf_fd;
 	uint32_t btf_key_type_id;
 	uint32_t btf_value_type_id;
+	uint32_t btf_vmlinux_value_type_id;
 };
 
 # define BPF_MAP_CREATE_struct_size \
 	sizeof(struct BPF_MAP_CREATE_struct)
-# define expected_BPF_MAP_CREATE_struct_size 60
+# define expected_BPF_MAP_CREATE_struct_size 64
 
 struct BPF_MAP_LOOKUP_ELEM_struct {
 	uint32_t map_fd;
diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c
index 36ab80e0..80196df3 100644
--- a/tests/bpf-obj_get_info_by_fd.c
+++ b/tests/bpf-obj_get_info_by_fd.c
@@ -87,6 +87,10 @@ print_map_create(void *attr_void, size_t size, long rc)
 		printf(", btf_fd=0</dev/null>"
 		       ", btf_key_type_id=0, btf_value_type_id=0");
 	}
+	if (size > offsetof(struct BPF_MAP_CREATE_struct,
+			    btf_vmlinux_value_type_id)) {
+		printf(", btf_vmlinux_value_type_id=0");
+	}
 	printf("}, %zu) = ", size);
 	if (rc >= 0)
 		printf("%ld<anon_inode:bpf-map>\n", rc);
diff --git a/tests/bpf.c b/tests/bpf.c
index d21c0f10..a462d008 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -417,10 +417,11 @@ static struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
 		.data = { .BPF_MAP_CREATE_data = {
 			.btf_fd = 0xbadc0ded,
 			.btf_key_type_id = 0xfacefeed,
-			.btf_value_type_id = 0xcafef00d
+			.btf_value_type_id = 0xcafef00d,
+			.btf_vmlinux_value_type_id = 0xdeadbeef,
 		} },
 		.size = offsetofend(struct BPF_MAP_CREATE_struct,
-				    btf_value_type_id),
+				    btf_vmlinux_value_type_id),
 		.str = "map_type=BPF_MAP_TYPE_UNSPEC"
 		       ", key_size=0"
 		       ", value_size=0"
@@ -432,6 +433,7 @@ static struct bpf_attr_check BPF_MAP_CREATE_checks[] = {
 		       ", btf_fd=-1159983635"
 		       ", btf_key_type_id=4207869677"
 		       ", btf_value_type_id=3405705229"
+		       ", btf_vmlinux_value_type_id=3735928559"
 	},
 };
 
-- 
2.20.1



More information about the Strace-devel mailing list