Skip to content

Commit 7c7a489

Browse files
anakryikoborkmann
authored andcommitted
selftests/bpf: add btf_dedup test of FWD/STRUCT resolution
This patch adds a btf_dedup test exercising logic of STRUCT<->FWD resolution and validating that STRUCT is not resolved to a FWD. It also forces hash collisions, forcing both FWD and STRUCT to be candidates for each other. Previously this condition caused infinite loop due to FWD pointing to STRUCT and STRUCT pointing to its FWD. Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 91097fb commit 7c7a489

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tools/testing/selftests/bpf/test_btf.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5731,6 +5731,51 @@ const struct btf_dedup_test dedup_tests[] = {
57315731
.dont_resolve_fwds = false,
57325732
},
57335733
},
5734+
{
5735+
.descr = "dedup: struct <-> fwd resolution w/ hash collision",
5736+
/*
5737+
* // CU 1:
5738+
* struct x;
5739+
* struct s {
5740+
* struct x *x;
5741+
* };
5742+
* // CU 2:
5743+
* struct x {};
5744+
* struct s {
5745+
* struct x *x;
5746+
* };
5747+
*/
5748+
.input = {
5749+
.raw_types = {
5750+
/* CU 1 */
5751+
BTF_FWD_ENC(NAME_TBD, 0 /* struct fwd */), /* [1] fwd x */
5752+
BTF_PTR_ENC(1), /* [2] ptr -> [1] */
5753+
BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [3] struct s */
5754+
BTF_MEMBER_ENC(NAME_TBD, 2, 0),
5755+
/* CU 2 */
5756+
BTF_STRUCT_ENC(NAME_TBD, 0, 0), /* [4] struct x */
5757+
BTF_PTR_ENC(4), /* [5] ptr -> [4] */
5758+
BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [6] struct s */
5759+
BTF_MEMBER_ENC(NAME_TBD, 5, 0),
5760+
BTF_END_RAW,
5761+
},
5762+
BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
5763+
},
5764+
.expect = {
5765+
.raw_types = {
5766+
BTF_PTR_ENC(3), /* [1] ptr -> [3] */
5767+
BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [2] struct s */
5768+
BTF_MEMBER_ENC(NAME_TBD, 1, 0),
5769+
BTF_STRUCT_ENC(NAME_NTH(2), 0, 0), /* [3] struct x */
5770+
BTF_END_RAW,
5771+
},
5772+
BTF_STR_SEC("\0s\0x"),
5773+
},
5774+
.opts = {
5775+
.dont_resolve_fwds = false,
5776+
.dedup_table_size = 1, /* force hash collisions */
5777+
},
5778+
},
57345779
{
57355780
.descr = "dedup: all possible kinds (no duplicates)",
57365781
.input = {

0 commit comments

Comments
 (0)