selftests/bpf: Fix field existence CO-RE reloc tests
authorAndrii Nakryiko <andrii@kernel.org>
Mon, 26 Apr 2021 19:29:48 +0000 (12:29 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 27 Apr 2021 01:37:13 +0000 (18:37 -0700)
commit5a30eb23922b52f33222c6729b6b3ff1c37a6c66
tree13617ff8f2845bac4204e495df41148547c8a636
parent0f20615d64ee2ad5e2a133a812382d0c4071589b
selftests/bpf: Fix field existence CO-RE reloc tests

Negative field existence cases for have a broken assumption that FIELD_EXISTS
CO-RE relo will fail for fields that match the name but have incompatible type
signature. That's not how CO-RE relocations generally behave. Types and fields
that match by name but not by expected type are treated as non-matching
candidates and are skipped. Error later is reported if no matching candidate
was found. That's what happens for most relocations, but existence relocations
(FIELD_EXISTS and TYPE_EXISTS) are more permissive and they are designed to
return 0 or 1, depending if a match is found. This allows to handle
name-conflicting but incompatible types in BPF code easily. Combined with
___flavor suffixes, it's possible to handle pretty much any structural type
changes in kernel within the compiled once BPF source code.

So, long story short, negative field existence test cases are invalid in their
assumptions, so this patch reworks them into a single consolidated positive
case that doesn't match any of the fields.

Fixes: c7566a69695c ("selftests/bpf: Add field existence CO-RE relocs tests")
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Lorenz Bauer <lmb@cloudflare.com>
Link: https://lore.kernel.org/bpf/20210426192949.416837-5-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/core_reloc.c
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_value_type.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_kind.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_sz.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_type.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_struct_type.c [deleted file]
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___wrong_field_defs.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/core_reloc_types.h