Skip to content

Commit 84ecc1f

Browse files
iamkafaiAlexei Starovoitov
authored andcommitted
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>
1 parent 555249d commit 84ecc1f

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎tools/bpf/bpftool/prog.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,13 @@ static int do_dump(int argc, char **argv)
589589
goto err_free;
590590
}
591591

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+
592599
if ((member_len == &info.jited_prog_len &&
593600
info.jited_prog_insns == 0) ||
594601
(member_len == &info.xlated_prog_len &&

‎tools/bpf/bpftool/xlated_dumper.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void dump_xlated_json(struct dump_data *dd, void *buf, unsigned int len,
261261
jsonw_start_object(json_wtr);
262262

263263
if (btf && record) {
264-
if (record->insn_offset == i) {
264+
if (record->insn_off == i) {
265265
btf_dumper_type_only(btf, record->type_id,
266266
func_sig,
267267
sizeof(func_sig));
@@ -330,7 +330,7 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len,
330330
}
331331

332332
if (btf && record) {
333-
if (record->insn_offset == i) {
333+
if (record->insn_off == i) {
334334
btf_dumper_type_only(btf, record->type_id,
335335
func_sig,
336336
sizeof(func_sig));

‎tools/lib/bpf/btf.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct btf_ext {
4545

4646
/* The minimum bpf_func_info checked by the loader */
4747
struct bpf_func_info_min {
48-
__u32 insn_offset;
48+
__u32 insn_off;
4949
__u32 type_id;
5050
};
5151

@@ -670,7 +670,7 @@ int btf_ext__reloc_init(struct btf *btf, struct btf_ext *btf_ext,
670670

671671
memcpy(data, sinfo->data, records_len);
672672

673-
/* adjust the insn_offset, the data in .BTF.ext is
673+
/* adjust the insn_off, the data in .BTF.ext is
674674
* the actual byte offset, and the kernel expects
675675
* the offset in term of bpf_insn.
676676
*
@@ -681,7 +681,7 @@ int btf_ext__reloc_init(struct btf *btf, struct btf_ext *btf_ext,
681681
struct bpf_func_info_min *record;
682682

683683
record = data + i * record_size;
684-
record->insn_offset /= sizeof(struct bpf_insn);
684+
record->insn_off /= sizeof(struct bpf_insn);
685685
}
686686

687687
*func_info = data;
@@ -722,15 +722,15 @@ int btf_ext__reloc(struct btf *btf, struct btf_ext *btf_ext,
722722
return -ENOMEM;
723723

724724
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
726726
* to the kernel.
727727
*/
728728
for (i = 0; i < sinfo->num_func_info; i++) {
729729
struct bpf_func_info_min *record;
730730

731731
record = data + existing_flen + i * record_size;
732-
record->insn_offset =
733-
record->insn_offset / sizeof(struct bpf_insn) +
732+
record->insn_off =
733+
record->insn_off / sizeof(struct bpf_insn) +
734734
insns_cnt;
735735
}
736736
*func_info = data;

‎tools/testing/selftests/bpf/test_btf.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ static struct btf_func_type_test {
31563156
},
31573157

31583158
{
3159-
.descr = "func_type (Incorrect bpf_func_info.insn_offset)",
3159+
.descr = "func_type (Incorrect bpf_func_info.insn_off)",
31603160
.raw_types = {
31613161
BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
31623162
BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
@@ -3303,6 +3303,12 @@ static int do_test_func_type(int test_num)
33033303
goto done;
33043304
}
33053305

3306+
if (CHECK(!info.func_info,
3307+
"info.func_info == 0. kernel.kptr_restrict is set?")) {
3308+
err = -1;
3309+
goto done;
3310+
}
3311+
33063312
finfo = func_info;
33073313
for (i = 0; i < 2; i++) {
33083314
if (CHECK(finfo->type_id != test->func_info[i][1],

0 commit comments

Comments
 (0)