From: Dmitry V. Levin Date: Thu, 14 Mar 2019 01:57:38 +0000 (+0000) Subject: bpf: add support for new seven fields in BPF_PROG_LOAD X-Git-Tag: v5.0~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b9b904ed96469531f4676979d1ecbb4425bd26a;p=strace bpf: add support for new seven fields in BPF_PROG_LOAD * 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. --- diff --git a/bpf.c b/bpf.c index 5f944cf0..bc99a08a 100644 --- 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) diff --git a/bpf_attr.h b/bpf_attr.h index f9ca310e..90ca018e 100644 --- a/bpf_attr.h +++ b/bpf_attr.h @@ -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; diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c index 229608ae..ca8d4cf1 100644 --- a/tests/bpf-obj_get_info_by_fd.c +++ b/tests/bpf-obj_get_info_by_fd.c @@ -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"); + 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\n", rc); diff --git a/tests/bpf.c b/tests/bpf.c index ba562b4a..ec124139 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -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 diff --git a/tests/kernel_version.c b/tests/kernel_version.c index 3f8a5fef..5d88d927 100644 --- a/tests/kernel_version.c +++ b/tests/kernel_version.c @@ -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