Blame SOURCES/0048-bpf-add-support-for-btf_-fields-in-BPF_MAP_CREATE.patch

8e169c
From 14a9b6ca66109fc1231eb16e98a9ce4262fb610c Mon Sep 17 00:00:00 2001
8e169c
From: "Dmitry V. Levin" <ldv@altlinux.org>
8e169c
Date: Tue, 12 Mar 2019 11:17:20 +0000
8e169c
Subject: [PATCH] bpf: add support for btf_* fields in BPF_MAP_CREATE
8e169c
8e169c
* bpf_attr.h (struct BPF_MAP_CREATE_struct): Add btf_fd,
8e169c
btf_key_type_id, and btf_value_type_id fields.
8e169c
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Decode btf_fd,
8e169c
btf_key_type_id, and btf_value_type_id fields introduced by Linux
8e169c
commits v4.18-rc1~114^2~417^2~1^2~3 and v4.18-rc1~114^2~148^2~7^2~2.
8e169c
* tests/bpf.c (BPF_MAP_CREATE_checks): Check it.
8e169c
* tests/bpf-obj_get_info_by_fd.c (print_map_create): Update expected
8e169c
output.
8e169c
---
8e169c
 bpf.c                          | 10 ++++++++++
8e169c
 bpf_attr.h                     |  5 ++++-
8e169c
 tests/bpf-obj_get_info_by_fd.c |  4 ++++
8e169c
 tests/bpf.c                    | 20 ++++++++++++++++++++
8e169c
 4 files changed, 38 insertions(+), 1 deletion(-)
8e169c
8e169c
Index: strace-4.24/bpf.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/bpf.c	2020-01-28 00:14:36.905228319 +0100
8e169c
+++ strace-4.24/bpf.c	2020-01-28 00:15:26.973756792 +0100
8e169c
@@ -212,6 +212,16 @@
8e169c
 	if (len <= offsetof(struct BPF_MAP_CREATE_struct, map_ifindex))
8e169c
 		break;
8e169c
 	PRINT_FIELD_IFINDEX(", ", attr, map_ifindex);
8e169c
+
8e169c
+	/*
8e169c
+	 * The following three fields were introduced by Linux commits
8e169c
+	 * v4.18-rc1~114^2~417^2~1^2~3 and v4.18-rc1~114^2~148^2~7^2~2.
8e169c
+	 */
8e169c
+	if (len <= offsetof(struct BPF_MAP_CREATE_struct, btf_fd))
8e169c
+		break;
8e169c
+	PRINT_FIELD_FD(", ", attr, btf_fd, tcp);
8e169c
+	PRINT_FIELD_U(", ", attr, btf_key_type_id);
8e169c
+	PRINT_FIELD_U(", ", attr, btf_value_type_id);
8e169c
 }
8e169c
 END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
8e169c
 
8e169c
Index: strace-4.24/bpf_attr.h
8e169c
===================================================================
8e169c
--- strace-4.24.orig/bpf_attr.h	2020-01-28 00:14:36.905228319 +0100
8e169c
+++ strace-4.24/bpf_attr.h	2020-01-28 00:15:26.974756783 +0100
8e169c
@@ -45,11 +45,14 @@
8e169c
 	uint32_t numa_node;
8e169c
 	char     map_name[BPF_OBJ_NAME_LEN];
8e169c
 	uint32_t map_ifindex;
8e169c
+	uint32_t btf_fd;
8e169c
+	uint32_t btf_key_type_id;
8e169c
+	uint32_t btf_value_type_id;
8e169c
 };
8e169c
 
8e169c
 # define BPF_MAP_CREATE_struct_size \
8e169c
 	sizeof(struct BPF_MAP_CREATE_struct)
8e169c
-# define expected_BPF_MAP_CREATE_struct_size 48
8e169c
+# define expected_BPF_MAP_CREATE_struct_size 60
8e169c
 
8e169c
 struct BPF_MAP_LOOKUP_ELEM_struct {
8e169c
 	uint32_t map_fd;
8e169c
Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c	2020-01-28 00:14:36.905228319 +0100
8e169c
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c	2020-01-28 00:15:26.974756783 +0100
8e169c
@@ -84,6 +84,10 @@
8e169c
 		printf(", map_name=\"test_map\"");
8e169c
 	if (size > offsetof(struct BPF_MAP_CREATE_struct, map_ifindex))
8e169c
 		printf(", map_ifindex=0");
8e169c
+	if (size > offsetof(struct BPF_MAP_CREATE_struct, btf_fd)) {
8e169c
+		printf(", btf_fd=0</dev/null>"
8e169c
+		       ", btf_key_type_id=0, btf_value_type_id=0");
8e169c
+	}
8e169c
 	printf("}, %zu) = ", size);
8e169c
 	if (rc >= 0)
8e169c
 		printf("%ld<anon_inode:bpf-map>\n", rc);
8e169c
Index: strace-4.24/tests/bpf.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests/bpf.c	2020-01-28 00:14:36.905228319 +0100
8e169c
+++ strace-4.24/tests/bpf.c	2020-01-28 00:15:26.975756773 +0100
8e169c
@@ -400,6 +400,26 @@
8e169c
 		       ", map_ifindex=" IFINDEX_LO_STR,
8e169c
 		.init_fn = init_BPF_MAP_CREATE_attr7,
8e169c
 	},
8e169c
+	{ /* 8 */
8e169c
+		.data = { .BPF_MAP_CREATE_data = {
8e169c
+			.btf_fd = 0xbadc0ded,
8e169c
+			.btf_key_type_id = 0xfacefeed,
8e169c
+			.btf_value_type_id = 0xcafef00d
8e169c
+		} },
8e169c
+		.size = offsetofend(struct BPF_MAP_CREATE_struct,
8e169c
+				    btf_value_type_id),
8e169c
+		.str = "map_type=BPF_MAP_TYPE_UNSPEC"
8e169c
+		       ", key_size=0"
8e169c
+		       ", value_size=0"
8e169c
+		       ", max_entries=0"
8e169c
+		       ", map_flags=0"
8e169c
+		       ", inner_map_fd=0"
8e169c
+		       ", map_name=\"\""
8e169c
+		       ", map_ifindex=0"
8e169c
+		       ", btf_fd=-1159983635"
8e169c
+		       ", btf_key_type_id=4207869677"
8e169c
+		       ", btf_value_type_id=3405705229"
8e169c
+	},
8e169c
 };
8e169c
 
8e169c
 static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = {
8e169c
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c	2020-01-28 00:15:16.441855977 +0100
8e169c
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c	2020-01-28 00:15:51.739523557 +0100
8e169c
@@ -84,6 +84,10 @@
8e169c
 		printf(", map_name=\"test_map\"");
8e169c
 	if (size > offsetof(struct BPF_MAP_CREATE_struct, map_ifindex))
8e169c
 		printf(", map_ifindex=0");
8e169c
+	if (size > offsetof(struct BPF_MAP_CREATE_struct, btf_fd)) {
8e169c
+		printf(", btf_fd=0</dev/null>"
8e169c
+		       ", btf_key_type_id=0, btf_value_type_id=0");
8e169c
+	}
8e169c
 	printf("}, %zu) = ", size);
8e169c
 	if (rc >= 0)
8e169c
 		printf("%ld<anon_inode:bpf-map>\n", rc);
8e169c
Index: strace-4.24/tests-m32/bpf.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests-m32/bpf.c	2020-01-28 00:15:08.917926835 +0100
8e169c
+++ strace-4.24/tests-m32/bpf.c	2020-01-28 00:15:45.840579111 +0100
8e169c
@@ -400,6 +400,26 @@
8e169c
 		       ", map_ifindex=" IFINDEX_LO_STR,
8e169c
 		.init_fn = init_BPF_MAP_CREATE_attr7,
8e169c
 	},
8e169c
+	{ /* 8 */
8e169c
+		.data = { .BPF_MAP_CREATE_data = {
8e169c
+			.btf_fd = 0xbadc0ded,
8e169c
+			.btf_key_type_id = 0xfacefeed,
8e169c
+			.btf_value_type_id = 0xcafef00d
8e169c
+		} },
8e169c
+		.size = offsetofend(struct BPF_MAP_CREATE_struct,
8e169c
+				    btf_value_type_id),
8e169c
+		.str = "map_type=BPF_MAP_TYPE_UNSPEC"
8e169c
+		       ", key_size=0"
8e169c
+		       ", value_size=0"
8e169c
+		       ", max_entries=0"
8e169c
+		       ", map_flags=0"
8e169c
+		       ", inner_map_fd=0"
8e169c
+		       ", map_name=\"\""
8e169c
+		       ", map_ifindex=0"
8e169c
+		       ", btf_fd=-1159983635"
8e169c
+		       ", btf_key_type_id=4207869677"
8e169c
+		       ", btf_value_type_id=3405705229"
8e169c
+	},
8e169c
 };
8e169c
 
8e169c
 static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = {
8e169c
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c	2020-01-28 00:15:18.824833536 +0100
8e169c
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c	2020-01-28 00:15:55.110491811 +0100
8e169c
@@ -84,6 +84,10 @@
8e169c
 		printf(", map_name=\"test_map\"");
8e169c
 	if (size > offsetof(struct BPF_MAP_CREATE_struct, map_ifindex))
8e169c
 		printf(", map_ifindex=0");
8e169c
+	if (size > offsetof(struct BPF_MAP_CREATE_struct, btf_fd)) {
8e169c
+		printf(", btf_fd=0</dev/null>"
8e169c
+		       ", btf_key_type_id=0, btf_value_type_id=0");
8e169c
+	}
8e169c
 	printf("}, %zu) = ", size);
8e169c
 	if (rc >= 0)
8e169c
 		printf("%ld<anon_inode:bpf-map>\n", rc);
8e169c
Index: strace-4.24/tests-mx32/bpf.c
8e169c
===================================================================
8e169c
--- strace-4.24.orig/tests-mx32/bpf.c	2020-01-28 00:15:10.852908612 +0100
8e169c
+++ strace-4.24/tests-mx32/bpf.c	2020-01-28 00:15:48.667552488 +0100
8e169c
@@ -400,6 +400,26 @@
8e169c
 		       ", map_ifindex=" IFINDEX_LO_STR,
8e169c
 		.init_fn = init_BPF_MAP_CREATE_attr7,
8e169c
 	},
8e169c
+	{ /* 8 */
8e169c
+		.data = { .BPF_MAP_CREATE_data = {
8e169c
+			.btf_fd = 0xbadc0ded,
8e169c
+			.btf_key_type_id = 0xfacefeed,
8e169c
+			.btf_value_type_id = 0xcafef00d
8e169c
+		} },
8e169c
+		.size = offsetofend(struct BPF_MAP_CREATE_struct,
8e169c
+				    btf_value_type_id),
8e169c
+		.str = "map_type=BPF_MAP_TYPE_UNSPEC"
8e169c
+		       ", key_size=0"
8e169c
+		       ", value_size=0"
8e169c
+		       ", max_entries=0"
8e169c
+		       ", map_flags=0"
8e169c
+		       ", inner_map_fd=0"
8e169c
+		       ", map_name=\"\""
8e169c
+		       ", map_ifindex=0"
8e169c
+		       ", btf_fd=-1159983635"
8e169c
+		       ", btf_key_type_id=4207869677"
8e169c
+		       ", btf_value_type_id=3405705229"
8e169c
+	},
8e169c
 };
8e169c
 
8e169c
 static const struct bpf_attr_check BPF_MAP_LOOKUP_ELEM_checks[] = {