]> granicus.if.org Git - strace/commitdiff
bpf: add support for new seven fields in BPF_PROG_LOAD
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 14 Mar 2019 01:57:38 +0000 (01:57 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 14 Mar 2019 01:57:38 +0000 (01:57 +0000)
* bpf_attr.h (struct BPF_PROG_LOAD_struct): Add prog_btf_fd,
func_info_rec_size, func_info, func_info_cnt, line_info_rec_size,
line_info, and line_info_cnt fields.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Decode these fields
introduced by Linux commits v5.0-rc1~129^2~209^2~16^2~8 and
v5.0-rc1~129^2~114^2~5^2~6.
* tests/bpf.c (BPF_PROG_LOAD_checks): Check it.
* tests/kernel_version.c (print_bpf_attr): Update expected output.
* tests/bpf-obj_get_info_by_fd.c (print_prog_load): Likewise.

bpf.c
bpf_attr.h
tests/bpf-obj_get_info_by_fd.c
tests/bpf.c
tests/kernel_version.c

diff --git a/bpf.c b/bpf.c
index 5f944cf05b56db579c21f4f4c2fd121ec17eebad..bc99a08a6dfefb61c70970c603d355d7ec66e17d 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -317,6 +317,20 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)
                break;
        PRINT_FIELD_XVAL(", ", attr, expected_attach_type, bpf_attach_type,
                         "BPF_???");
+
+       /*
+        * The following seven fields were introduced by Linux commits
+        * v5.0-rc1~129^2~209^2~16^2~8 and v5.0-rc1~129^2~114^2~5^2~6.
+        */
+       if (len <= offsetof(struct BPF_PROG_LOAD_struct, prog_btf_fd))
+               break;
+       PRINT_FIELD_FD(", ", attr, prog_btf_fd, tcp);
+       PRINT_FIELD_U(", ", attr, func_info_rec_size);
+       PRINT_FIELD_ADDR64(", ", attr, func_info);
+       PRINT_FIELD_U(", ", attr, func_info_cnt);
+       PRINT_FIELD_U(", ", attr, line_info_rec_size);
+       PRINT_FIELD_ADDR64(", ", attr, line_info);
+       PRINT_FIELD_U(", ", attr, line_info_cnt);
 }
 END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
 
index f9ca310e362de4cd9c1273a3b9b08df19fa2ca14..90ca018e252bdc4e8b8330616bfd846740c4f31e 100644 (file)
@@ -107,11 +107,18 @@ struct BPF_PROG_LOAD_struct {
        char     prog_name[BPF_OBJ_NAME_LEN];
        uint32_t prog_ifindex;
        uint32_t expected_attach_type;
+       uint32_t prog_btf_fd;
+       uint32_t func_info_rec_size;
+       uint64_t ATTRIBUTE_ALIGNED(8) func_info;
+       uint32_t func_info_cnt;
+       uint32_t line_info_rec_size;
+       uint64_t ATTRIBUTE_ALIGNED(8) line_info;
+       uint32_t line_info_cnt;
 };
 
 # define BPF_PROG_LOAD_struct_size \
-       offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
-# define expected_BPF_PROG_LOAD_struct_size 72
+       offsetofend(struct BPF_PROG_LOAD_struct, line_info_cnt)
+# define expected_BPF_PROG_LOAD_struct_size 108
 
 struct BPF_OBJ_PIN_struct {
        uint64_t ATTRIBUTE_ALIGNED(8) pathname;
index 229608ae9e9f527407f24ab0e4ef8e0d0120410d..ca8d4cf1cd83bd701f79d395b37f14d54264217f 100644 (file)
@@ -192,6 +192,20 @@ print_prog_load(void *attr_void, size_t size, long rc)
                printf(", prog_ifindex=0");
        if (size > offsetof(struct BPF_PROG_LOAD_struct, expected_attach_type))
                printf(", expected_attach_type=BPF_CGROUP_INET_INGRESS");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, prog_btf_fd))
+               printf(", prog_btf_fd=0</dev/null>");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, func_info_rec_size))
+               printf(", func_info_rec_size=0");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, func_info))
+               printf(", func_info=NULL");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, func_info_cnt))
+               printf(", func_info_cnt=0");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, line_info_rec_size))
+               printf(", line_info_rec_size=0");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, line_info))
+               printf(", line_info=NULL");
+       if (size > offsetof(struct BPF_PROG_LOAD_struct, line_info_cnt))
+               printf(", line_info_cnt=0");
        printf("}, %zu) = ", size);
        if (rc >= 0)
                printf("%ld<anon_inode:bpf-prog>\n", rc);
index ba562b4afcc2d67350a7fe7b01e8e6296633f8eb..ec1241398f3204573a02feb755ac1d380b616786 100644 (file)
@@ -670,6 +670,40 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
                .init_fn = init_BPF_PROG_LOAD_attr4,
                .print_fn = print_BPF_PROG_LOAD_attr4
        },
+       { /* 5 */
+               .data = { .BPF_PROG_LOAD_data = {
+                       .prog_flags = 2,
+                       .expected_attach_type = 17,
+                       .prog_btf_fd = 0xbadc0ded,
+                       .func_info_rec_size = 0xdad1bef2,
+                       .func_info = 0xfac1fed2fac3fed4,
+                       .func_info_cnt = 0xdad3bef4,
+                       .line_info_rec_size = 0xdad5bef6,
+                       .line_info = 0xfac5fed5fac7fed8,
+                       .line_info_cnt = 0xdad7bef8
+               } },
+               .size = offsetofend(struct BPF_PROG_LOAD_struct,
+                                   line_info_cnt),
+               .str = "prog_type=BPF_PROG_TYPE_UNSPEC"
+                      ", insn_cnt=0"
+                      ", insns=NULL"
+                      ", license=NULL"
+                      ", log_level=0"
+                      ", log_size=0"
+                      ", log_buf=NULL"
+                      ", kern_version=KERNEL_VERSION(0, 0, 0)"
+                      ", prog_flags=BPF_F_ANY_ALIGNMENT"
+                      ", prog_name=\"\""
+                      ", prog_ifindex=0"
+                      ", expected_attach_type=BPF_FLOW_DISSECTOR"
+                      ", prog_btf_fd=-1159983635"
+                      ", func_info_rec_size=3671178994"
+                      ", func_info=0xfac1fed2fac3fed4"
+                      ", func_info_cnt=3671310068"
+                      ", line_info_rec_size=3671441142"
+                      ", line_info=0xfac5fed5fac7fed8"
+                      ", line_info_cnt=3671572216"
+       },
 };
 
 static void
index 3f8a5fef9d407af502a9f387c10ec68c8e6a6dea..5d88d92798822f1d0922002aa9cc7b2e15a0a2a2 100644 (file)
@@ -58,13 +58,19 @@ print_bpf_attr(void)
                ", prog_ifindex=0"
                ", expected_attach_type="
 #if XLAT_RAW
-               "0}"
+               "0"
 #elif XLAT_VERBOSE
-               "0 /* BPF_CGROUP_INET_INGRESS */}"
+               "0 /* BPF_CGROUP_INET_INGRESS */"
 #else /* XLAT_ABBREV */
-               "BPF_CGROUP_INET_INGRESS}"
+               "BPF_CGROUP_INET_INGRESS"
 #endif
-               );
+               ", prog_btf_fd=0"
+               ", func_info_rec_size=0"
+               ", func_info=NULL"
+               ", func_info_cnt=0"
+               ", line_info_rec_size=0"
+               ", line_info=NULL"
+               ", line_info_cnt=0}");
 }
 
 int