diff options
author | Martin KaFai Lau <kafai@fb.com> | 2018-12-05 20:35:47 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-12-05 21:48:40 -0500 |
commit | 84ecc1f98ca7ce28ede9bc5cc70a557fdfa09caa (patch) | |
tree | d1b34c120c66dd799428ca4e61bf8ed710f4ae3e | |
parent | 555249df711b146a2898949ac80503be29fe7340 (diff) |
bpf: Expect !info.func_info and insn_off name changes in test_btf/libbpf/bpftool
Similar to info.jited_*, info.func_info could be 0 if
bpf_dump_raw_ok() == false.
This patch makes changes to test_btf and bpftool to expect info.func_info
could be 0.
This patch also makes the needed changes for s/insn_offset/insn_off/.
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/bpf/bpftool/prog.c | 7 | ||||
-rw-r--r-- | tools/bpf/bpftool/xlated_dumper.c | 4 | ||||
-rw-r--r-- | tools/lib/bpf/btf.c | 12 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_btf.c | 8 |
4 files changed, 22 insertions, 9 deletions
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 54c8dbf05c9c..a9a51123454c 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
@@ -589,6 +589,13 @@ static int do_dump(int argc, char **argv) | |||
589 | goto err_free; | 589 | goto err_free; |
590 | } | 590 | } |
591 | 591 | ||
592 | if (func_info && !info.func_info) { | ||
593 | /* kernel.kptr_restrict is set. No func_info available. */ | ||
594 | free(func_info); | ||
595 | func_info = NULL; | ||
596 | finfo_cnt = 0; | ||
597 | } | ||
598 | |||
592 | if ((member_len == &info.jited_prog_len && | 599 | if ((member_len == &info.jited_prog_len && |
593 | info.jited_prog_insns == 0) || | 600 | info.jited_prog_insns == 0) || |
594 | (member_len == &info.xlated_prog_len && | 601 | (member_len == &info.xlated_prog_len && |
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index e06ac0286a75..131ecd175533 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c | |||
@@ -261,7 +261,7 @@ void dump_xlated_json(struct dump_data *dd, void *buf, unsigned int len, | |||
261 | jsonw_start_object(json_wtr); | 261 | jsonw_start_object(json_wtr); |
262 | 262 | ||
263 | if (btf && record) { | 263 | if (btf && record) { |
264 | if (record->insn_offset == i) { | 264 | if (record->insn_off == i) { |
265 | btf_dumper_type_only(btf, record->type_id, | 265 | btf_dumper_type_only(btf, record->type_id, |
266 | func_sig, | 266 | func_sig, |
267 | sizeof(func_sig)); | 267 | sizeof(func_sig)); |
@@ -330,7 +330,7 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len, | |||
330 | } | 330 | } |
331 | 331 | ||
332 | if (btf && record) { | 332 | if (btf && record) { |
333 | if (record->insn_offset == i) { | 333 | if (record->insn_off == i) { |
334 | btf_dumper_type_only(btf, record->type_id, | 334 | btf_dumper_type_only(btf, record->type_id, |
335 | func_sig, | 335 | func_sig, |
336 | sizeof(func_sig)); | 336 | sizeof(func_sig)); |
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index c2d641f3e16e..85d6446cf832 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -45,7 +45,7 @@ struct btf_ext { | |||
45 | 45 | ||
46 | /* The minimum bpf_func_info checked by the loader */ | 46 | /* The minimum bpf_func_info checked by the loader */ |
47 | struct bpf_func_info_min { | 47 | struct bpf_func_info_min { |
48 | __u32 insn_offset; | 48 | __u32 insn_off; |
49 | __u32 type_id; | 49 | __u32 type_id; |
50 | }; | 50 | }; |
51 | 51 | ||
@@ -670,7 +670,7 @@ int btf_ext__reloc_init(struct btf *btf, struct btf_ext *btf_ext, | |||
670 | 670 | ||
671 | memcpy(data, sinfo->data, records_len); | 671 | memcpy(data, sinfo->data, records_len); |
672 | 672 | ||
673 | /* adjust the insn_offset, the data in .BTF.ext is | 673 | /* adjust the insn_off, the data in .BTF.ext is |
674 | * the actual byte offset, and the kernel expects | 674 | * the actual byte offset, and the kernel expects |
675 | * the offset in term of bpf_insn. | 675 | * the offset in term of bpf_insn. |
676 | * | 676 | * |
@@ -681,7 +681,7 @@ int btf_ext__reloc_init(struct btf *btf, struct btf_ext *btf_ext, | |||
681 | struct bpf_func_info_min *record; | 681 | struct bpf_func_info_min *record; |
682 | 682 | ||
683 | record = data + i * record_size; | 683 | record = data + i * record_size; |
684 | record->insn_offset /= sizeof(struct bpf_insn); | 684 | record->insn_off /= sizeof(struct bpf_insn); |
685 | } | 685 | } |
686 | 686 | ||
687 | *func_info = data; | 687 | *func_info = data; |
@@ -722,15 +722,15 @@ int btf_ext__reloc(struct btf *btf, struct btf_ext *btf_ext, | |||
722 | return -ENOMEM; | 722 | return -ENOMEM; |
723 | 723 | ||
724 | memcpy(data + existing_flen, sinfo->data, records_len); | 724 | memcpy(data + existing_flen, sinfo->data, records_len); |
725 | /* adjust insn_offset only, the rest data will be passed | 725 | /* adjust insn_off only, the rest data will be passed |
726 | * to the kernel. | 726 | * to the kernel. |
727 | */ | 727 | */ |
728 | for (i = 0; i < sinfo->num_func_info; i++) { | 728 | for (i = 0; i < sinfo->num_func_info; i++) { |
729 | struct bpf_func_info_min *record; | 729 | struct bpf_func_info_min *record; |
730 | 730 | ||
731 | record = data + existing_flen + i * record_size; | 731 | record = data + existing_flen + i * record_size; |
732 | record->insn_offset = | 732 | record->insn_off = |
733 | record->insn_offset / sizeof(struct bpf_insn) + | 733 | record->insn_off / sizeof(struct bpf_insn) + |
734 | insns_cnt; | 734 | insns_cnt; |
735 | } | 735 | } |
736 | *func_info = data; | 736 | *func_info = data; |
diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c index bae7308b7ec5..ff0952ea757a 100644 --- a/tools/testing/selftests/bpf/test_btf.c +++ b/tools/testing/selftests/bpf/test_btf.c | |||
@@ -3156,7 +3156,7 @@ static struct btf_func_type_test { | |||
3156 | }, | 3156 | }, |
3157 | 3157 | ||
3158 | { | 3158 | { |
3159 | .descr = "func_type (Incorrect bpf_func_info.insn_offset)", | 3159 | .descr = "func_type (Incorrect bpf_func_info.insn_off)", |
3160 | .raw_types = { | 3160 | .raw_types = { |
3161 | BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ | 3161 | BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ |
3162 | BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */ | 3162 | BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */ |
@@ -3303,6 +3303,12 @@ static int do_test_func_type(int test_num) | |||
3303 | goto done; | 3303 | goto done; |
3304 | } | 3304 | } |
3305 | 3305 | ||
3306 | if (CHECK(!info.func_info, | ||
3307 | "info.func_info == 0. kernel.kptr_restrict is set?")) { | ||
3308 | err = -1; | ||
3309 | goto done; | ||
3310 | } | ||
3311 | |||
3306 | finfo = func_info; | 3312 | finfo = func_info; |
3307 | for (i = 0; i < 2; i++) { | 3313 | for (i = 0; i < 2; i++) { |
3308 | if (CHECK(finfo->type_id != test->func_info[i][1], | 3314 | if (CHECK(finfo->type_id != test->func_info[i][1], |