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(-) diff --git a/bpf.c b/bpf.c index bf7cd6ca..8144be95 100644 --- a/bpf.c +++ b/bpf.c @@ -463,6 +463,16 @@ print_bpf_map_info(struct tcb * const tcp, uint32_t bpf_fd, 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: diff --git a/bpf_attr.h b/bpf_attr.h index a789d10a..3fdb4280 100644 --- a/bpf_attr.h +++ b/bpf_attr.h @@ -242,11 +242,14 @@ struct bpf_map_info_struct { */ 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; diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c index 02d14e5e..597a820c 100644 --- a/tests/bpf-obj_get_info_by_fd.c +++ b/tests/bpf-obj_get_info_by_fd.c @@ -324,6 +324,15 @@ main(void) 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); -- 2.40.0