]> granicus.if.org Git - strace/commitdiff
bpf: add support for btf_* fields in struct bpf_map_info
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 12 Mar 2019 11:17:20 +0000 (11:17 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 12 Mar 2019 11:17:20 +0000 (11:17 +0000)
* 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
bpf_attr.h
tests/bpf-obj_get_info_by_fd.c

diff --git a/bpf.c b/bpf.c
index bf7cd6ca881e3c296cdec90c65966057ce7bdb16..8144be954b0a6c7f32110637e2ec3e5f5d468d98 100644 (file)
--- 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:
index a789d10a08ae9520e7f542e0dd10add093e82fde..3fdb4280c74c09dc0ec679b81b855cf719152d55 100644 (file)
@@ -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;
index 02d14e5e81bae9d795da080b75f79447c0a4edf4..597a820cd6b0e8b9aa72b4a7b0c2a31175bf3dc2 100644 (file)
@@ -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);