From 27bd13d3664a6047e9431e01bd13fc04cc5e373b Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 12 Mar 2019 11:17:20 +0000 Subject: [PATCH] bpf: add support for btf_* fields in struct bpf_map_info * bpf_attr.h (struct bpf_map_info_struct): Add btf_fd, btf_key_type_id, and btf_value_type_id fields. * bpf.c (print_bpf_map_info): Decode btf_fd, btf_key_type_id, and btf_value_type_id fields introduced by Linux commits v4.18-rc1~114^2~223^2~21^2~4 and v4.18-rc1~114^2~148^2~7^2~2. * tests/bpf-obj_get_info_by_fd.c (main): Update expected output. --- bpf.c | 10 ++++++++++ bpf_attr.h | 7 +++++-- tests/bpf-obj_get_info_by_fd.c | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) Index: strace-4.24/bpf.c =================================================================== --- strace-4.24.orig/bpf.c 2020-01-28 00:15:26.973756792 +0100 +++ strace-4.24/bpf.c 2020-01-28 00:15:59.919446522 +0100 @@ -466,6 +466,16 @@ PRINT_FIELD_DEV(", ", info, netns_dev); PRINT_FIELD_U(", ", info, netns_ino); + /* + * The next three fields were introduced by Linux commits + * v4.18-rc1~114^2~223^2~21^2~4 and v4.18-rc1~114^2~148^2~7^2~2. + */ + if (len <= offsetof(struct bpf_map_info_struct, btf_id)) + goto print_bpf_map_info_end; + PRINT_FIELD_U(", ", info, btf_id); + PRINT_FIELD_U(", ", info, btf_key_type_id); + PRINT_FIELD_U(", ", info, btf_value_type_id); + decode_attr_extra_data(tcp, info_buf, size, bpf_map_info_struct_size); print_bpf_map_info_end: Index: strace-4.24/bpf_attr.h =================================================================== --- strace-4.24.orig/bpf_attr.h 2020-01-28 00:15:26.974756783 +0100 +++ strace-4.24/bpf_attr.h 2020-01-28 00:15:59.919446522 +0100 @@ -242,11 +242,14 @@ */ uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */ uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */ + uint32_t btf_id; + uint32_t btf_key_type_id; + uint32_t btf_value_type_id; }; # define bpf_map_info_struct_size \ - sizeof(struct bpf_map_info_struct) -# define expected_bpf_map_info_struct_size 64 + offsetofend(struct bpf_map_info_struct, btf_value_type_id) +# define expected_bpf_map_info_struct_size 76 struct bpf_prog_info_struct { uint32_t type; Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c =================================================================== --- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c 2020-01-28 00:15:26.974756783 +0100 +++ strace-4.24/tests/bpf-obj_get_info_by_fd.c 2020-01-28 00:15:59.920446513 +0100 @@ -324,6 +324,15 @@ if (bpf_map_get_info_attr.info_len > offsetof(struct bpf_map_info_struct, netns_ino)) printf(", netns_ino=%" PRIu64, map_info->netns_ino); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_id)) + PRINT_FIELD_U(", ", *map_info, btf_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_key_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_key_type_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_value_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_value_type_id); printf("}"); #else /* !VERBOSE */ printf("%p", map_info); Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c =================================================================== --- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c 2020-01-28 00:15:51.739523557 +0100 +++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:14.855305862 +0100 @@ -324,6 +324,15 @@ if (bpf_map_get_info_attr.info_len > offsetof(struct bpf_map_info_struct, netns_ino)) printf(", netns_ino=%" PRIu64, map_info->netns_ino); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_id)) + PRINT_FIELD_U(", ", *map_info, btf_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_key_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_key_type_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_value_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_value_type_id); printf("}"); #else /* !VERBOSE */ printf("%p", map_info); Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c =================================================================== --- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c 2020-01-28 00:15:55.110491811 +0100 +++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c 2020-01-28 00:16:23.096228252 +0100 @@ -324,6 +324,15 @@ if (bpf_map_get_info_attr.info_len > offsetof(struct bpf_map_info_struct, netns_ino)) printf(", netns_ino=%" PRIu64, map_info->netns_ino); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_id)) + PRINT_FIELD_U(", ", *map_info, btf_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_key_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_key_type_id); + if (bpf_map_get_info_attr.info_len > + offsetof(struct bpf_map_info_struct, btf_value_type_id)) + PRINT_FIELD_U(", ", *map_info, btf_value_type_id); printf("}"); #else /* !VERBOSE */ printf("%p", map_info);