]> granicus.if.org Git - strace/commitdiff
bpf: add support for *jited_ksyms and *jited_func_lens fields in struct bpf_prog_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_prog_info_struct): Add nr_jited_ksyms,
nr_jited_func_lens, jited_ksyms, and jited_func_lens fields.
* bpf.c (struct obj_get_info_saved): Likewise.
(print_bpf_prog_info): Decode these fields introduced by Linux commits
v4.18-rc1~114^2~148^2~3^2~6 and v4.18-rc1~114^2~148^2~3^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 8144be954b0a6c7f32110637e2ec3e5f5d468d98..83eeee1e146847324f94836c0573ffc05c534351 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -424,6 +424,11 @@ struct obj_get_info_saved {
        uint32_t jited_prog_len;
        uint32_t xlated_prog_len;
        uint32_t nr_map_ids;
+
+       uint32_t nr_jited_ksyms;
+       uint32_t nr_jited_func_lens;
+       uint64_t jited_ksyms;
+       uint64_t jited_func_lens;
 };
 
 static void
@@ -494,6 +499,10 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd,
                saved->jited_prog_len = info.jited_prog_len;
                saved->xlated_prog_len = info.xlated_prog_len;
                saved->nr_map_ids = info.nr_map_ids;
+               saved->nr_jited_ksyms = info.nr_jited_ksyms;
+               saved->nr_jited_func_lens = info.nr_jited_func_lens;
+               saved->jited_ksyms = info.jited_ksyms;
+               saved->jited_func_lens = info.jited_func_lens;
 
                return;
        }
@@ -556,6 +565,37 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd,
        PRINT_FIELD_DEV(", ", info, netns_dev);
        PRINT_FIELD_U(", ", info, netns_ino);
 
+       /*
+        * The next four fields were introduced by Linux commits
+        * v4.18-rc1~114^2~148^2~3^2~6 and v4.18-rc1~114^2~148^2~3^2~2.
+        */
+       if (len <= offsetof(struct bpf_prog_info_struct, nr_jited_ksyms))
+               goto print_bpf_prog_info_end;
+
+       tprints(", nr_jited_ksyms=");
+       if (saved->nr_jited_ksyms != info.nr_jited_ksyms)
+               tprintf("%" PRIu32 " => ", saved->nr_jited_ksyms);
+       tprintf("%" PRIu32, info.nr_jited_ksyms);
+
+       tprints(", nr_jited_func_lens=");
+       if (saved->nr_jited_func_lens != info.nr_jited_func_lens)
+               tprintf("%" PRIu32 " => ", saved->nr_jited_func_lens);
+       tprintf("%" PRIu32, info.nr_jited_func_lens);
+
+       tprints(", jited_ksyms=");
+       if (saved->jited_ksyms != info.jited_ksyms) {
+               printaddr64(saved->jited_ksyms);
+               tprints(" => ");
+       }
+       printaddr64(info.jited_ksyms);
+
+       tprints(", jited_func_lens=");
+       if (saved->jited_func_lens != info.jited_func_lens) {
+               printaddr64(saved->jited_func_lens);
+               tprints(" => ");
+       }
+       printaddr64(info.jited_func_lens);
+
        decode_attr_extra_data(tcp, info_buf, size, bpf_prog_info_struct_size);
 
 print_bpf_prog_info_end:
index 3fdb4280c74c09dc0ec679b81b855cf719152d55..3a8786f7639277b4f148580e32a38ad082b4f7ed 100644 (file)
@@ -272,10 +272,14 @@ struct bpf_prog_info_struct {
         */
        uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
        uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
+       uint32_t nr_jited_ksyms;
+       uint32_t nr_jited_func_lens;
+       uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
+       uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
 };
 
 # define bpf_prog_info_struct_size \
        sizeof(struct bpf_prog_info_struct)
-# define expected_bpf_prog_info_struct_size 104
+# define expected_bpf_prog_info_struct_size 128
 
 #endif /* !STRACE_BPF_ATTR_H */
index 597a820cd6b0e8b9aa72b4a7b0c2a31175bf3dc2..dca680d7c812f6d4893087d366fa92be01a196bc 100644 (file)
@@ -358,6 +358,8 @@ main(void)
        memset(prog_info, 0, PROG_INFO_SZ);
        for (unsigned int i = 0; i < 4; i++) {
                prog_info->jited_prog_len = 0;
+               prog_info->nr_jited_ksyms = 0;
+               prog_info->nr_jited_func_lens = 0;
                memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
                switch (i) {
                case 1:
@@ -485,6 +487,25 @@ main(void)
                    offsetof(struct bpf_prog_info_struct, netns_ino))
                        printf(", netns_ino=%" PRIu64, prog_info->netns_ino);
 
+               if (bpf_prog_get_info_attr.info_len >
+                   offsetof(struct bpf_prog_info_struct, nr_jited_ksyms)) {
+                       printf(", nr_jited_ksyms=0");
+                       if (prog_info->nr_jited_ksyms)
+                               printf(" => %u", prog_info->nr_jited_ksyms);
+               }
+               if (bpf_prog_get_info_attr.info_len >
+                   offsetof(struct bpf_prog_info_struct, nr_jited_func_lens)) {
+                       printf(", nr_jited_func_lens=0");
+                       if (prog_info->nr_jited_func_lens)
+                               printf(" => %u", prog_info->nr_jited_func_lens);
+               }
+               if (bpf_prog_get_info_attr.info_len >
+                   offsetof(struct bpf_prog_info_struct, jited_ksyms))
+                       printf(", jited_ksyms=NULL");
+               if (bpf_prog_get_info_attr.info_len >
+                   offsetof(struct bpf_prog_info_struct, jited_func_lens))
+                       printf(", jited_func_lens=NULL");
+
                printf("}");
 # else /* !VERBOSE */
                printf("%p", prog_info);