]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
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)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 24 May 2021 23:46:43 +0000 (17:46 -0600)
BugLink: https://bugs.launchpad.net/bugs/1929455
[ Upstream commit 5a30eb23922b52f33222c6729b6b3ff1c37a6c66 ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
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

index 06eb956ff7bbd154c28fe3d883ca877efb107afd..cd3ba54a1f68c646a967827d65ed5e0d05d2ea74 100644 (file)
@@ -210,11 +210,6 @@ static int duration = 0;
        .bpf_obj_file = "test_core_reloc_existence.o",                  \
        .btf_src_file = "btf__core_reloc_" #name ".o"                   \
 
-#define FIELD_EXISTS_ERR_CASE(name) {                                  \
-       FIELD_EXISTS_CASE_COMMON(name),                                 \
-       .fails = true,                                                  \
-}
-
 #define BITFIELDS_CASE_COMMON(objfile, test_name_prefix,  name)                \
        .case_name = test_name_prefix#name,                             \
        .bpf_obj_file = objfile,                                        \
@@ -642,13 +637,25 @@ static struct core_reloc_test_case test_cases[] = {
                },
                .output_len = sizeof(struct core_reloc_existence_output),
        },
-
-       FIELD_EXISTS_ERR_CASE(existence__err_int_sz),
-       FIELD_EXISTS_ERR_CASE(existence__err_int_type),
-       FIELD_EXISTS_ERR_CASE(existence__err_int_kind),
-       FIELD_EXISTS_ERR_CASE(existence__err_arr_kind),
-       FIELD_EXISTS_ERR_CASE(existence__err_arr_value_type),
-       FIELD_EXISTS_ERR_CASE(existence__err_struct_type),
+       {
+               FIELD_EXISTS_CASE_COMMON(existence___wrong_field_defs),
+               .input = STRUCT_TO_CHAR_PTR(core_reloc_existence___wrong_field_defs) {
+               },
+               .input_len = sizeof(struct core_reloc_existence___wrong_field_defs),
+               .output = STRUCT_TO_CHAR_PTR(core_reloc_existence_output) {
+                       .a_exists = 0,
+                       .b_exists = 0,
+                       .c_exists = 0,
+                       .arr_exists = 0,
+                       .s_exists = 0,
+                       .a_value = 0xff000001u,
+                       .b_value = 0xff000002u,
+                       .c_value = 0xff000003u,
+                       .arr_value = 0xff000004u,
+                       .s_value = 0xff000005u,
+               },
+               .output_len = sizeof(struct core_reloc_existence_output),
+       },
 
        /* bitfield relocation checks */
        BITFIELDS_CASE(bitfields, {
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.c
deleted file mode 100644 (file)
index dd0ffa5..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_arr_kind x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_value_type.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_value_type.c
deleted file mode 100644 (file)
index bc83372..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_arr_value_type x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_kind.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_kind.c
deleted file mode 100644 (file)
index 917bec4..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_int_kind x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_sz.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_sz.c
deleted file mode 100644 (file)
index 6ec7e6e..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_int_sz x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_type.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_type.c
deleted file mode 100644 (file)
index 7bbcacf..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_int_type x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_struct_type.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_struct_type.c
deleted file mode 100644 (file)
index f384dd3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "core_reloc_types.h"
-
-void f(struct core_reloc_existence___err_wrong_struct_type x) {}
diff --git a/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___wrong_field_defs.c b/tools/testing/selftests/bpf/progs/btf__core_reloc_existence___wrong_field_defs.c
new file mode 100644 (file)
index 0000000..d14b496
--- /dev/null
@@ -0,0 +1,3 @@
+#include "core_reloc_types.h"
+
+void f(struct core_reloc_existence___wrong_field_defs x) {}
index 9a2850850121316480347cb40044e69093250783..664eea1013aabb8f1479709ebc14cf4b39190f3a 100644 (file)
@@ -700,27 +700,11 @@ struct core_reloc_existence___minimal {
        int a;
 };
 
-struct core_reloc_existence___err_wrong_int_sz {
-       short a;
-};
-
-struct core_reloc_existence___err_wrong_int_type {
+struct core_reloc_existence___wrong_field_defs {
+       void *a;
        int b[1];
-};
-
-struct core_reloc_existence___err_wrong_int_kind {
        struct{ int x; } c;
-};
-
-struct core_reloc_existence___err_wrong_arr_kind {
        int arr;
-};
-
-struct core_reloc_existence___err_wrong_arr_value_type {
-       short arr[1];
-};
-
-struct core_reloc_existence___err_wrong_struct_type {
        int s;
 };