Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/bpf: check precise {func, line, jited_line}_info_rec_size in test_btf

Current btf func_info, line_info and jited_line are designed to be
extensible. The record sizes for {func,line}_info are passed to kernel,
and the record sizes for {func,line,jited_line}_info are returned to
userspace during bpf_prog_info query.

In bpf selftests test_btf.c, when testing whether kernel returns
a legitimate {func,line, jited_line)_info rec_size, the test only
compares to the minimum allowed size. If the returned rec_size is smaller
than the minimum allowed size, it is considered incorrect.
The minimum allowed size for these three info sizes are equal to
current value of sizeof(struct bpf_func_info), sizeof(struct bpf_line_info)
and sizeof(__u64).

The original thinking was that in the future when rec_size is increased
in kernel, the same test should run correctly. But this sacrificed
the precision of testing under the very kernel the test is shipped with,
and bpf selftest is typically run with the same repo kernel.

So this patch changed the testing of rec_size such that the
kernel returned value should be equal to the size defined by
tools uapi header bpf.h which syncs with kernel uapi header.

Martin discovered a bug in one of rec_size comparisons.
Instead of comparing to minimum func_info rec_size 8, it compares to 4.
This patch fixed that issue as well.

Fixes: 999d82cbc044 ("tools/bpf: enhance test_btf file testing to test func info")
Fixes: 05687352c600 ("bpf: Refactor and bug fix in test_func_type in test_btf.c")
Fixes: 4d6304c76355 ("bpf: Add unit tests for bpf_line_info")
Suggested-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Yonghong Song and committed by
Daniel Borkmann
0d7410ea 07a09d1b

+5 -5
+5 -5
tools/testing/selftests/bpf/test_btf.c
··· 3408 3408 goto done; 3409 3409 } 3410 3410 rec_size = info.func_info_rec_size; 3411 - if (CHECK(rec_size < 4, 3411 + if (CHECK(rec_size != sizeof(struct bpf_func_info), 3412 3412 "incorrect info.func_info_rec_size (1st) %d\n", rec_size)) { 3413 3413 err = -1; 3414 3414 goto done; ··· 4544 4544 } 4545 4545 4546 4546 rec_size = info.func_info_rec_size; 4547 - if (CHECK(rec_size < 8, 4547 + if (CHECK(rec_size != sizeof(struct bpf_func_info), 4548 4548 "incorrect info.func_info_rec_size (1st) %d", rec_size)) { 4549 4549 return -1; 4550 4550 } ··· 4573 4573 err = -1; 4574 4574 goto done; 4575 4575 } 4576 - if (CHECK(info.func_info_rec_size < 8, 4576 + if (CHECK(info.func_info_rec_size != rec_size, 4577 4577 "incorrect info.func_info_rec_size (2nd) %d", 4578 4578 info.func_info_rec_size)) { 4579 4579 err = -1; ··· 4649 4649 goto done; 4650 4650 } 4651 4651 4652 - if (CHECK(info.line_info_rec_size < 16 || 4653 - info.jited_line_info_rec_size < 8, 4652 + if (CHECK(info.line_info_rec_size != sizeof(struct bpf_line_info) || 4653 + info.jited_line_info_rec_size != sizeof(__u64), 4654 4654 "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)", 4655 4655 info.line_info_rec_size, rec_size, 4656 4656 info.jited_line_info_rec_size, jited_rec_size)) {