aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Starovoitov <[email protected]>2024-08-23 07:29:03 -0700
committerAlexei Starovoitov <[email protected]>2024-08-23 07:29:03 -0700
commitb4406e100347884fb4acaa744bbc01949e74c9f3 (patch)
tree0288f89c2540dda329dbd0297e215e6f5dd2af25
parent7559a7a84ef83a2dd86caf623430b8d834843cec (diff)
parent21a56fc503faae7589167fcd2771ab6dce36ab39 (diff)
Merge branch 'follow-up-for-__jited-test-tag'
Eduard Zingerman says: ==================== follow up for __jited test tag This patch-set is a collection of follow-ups for "__jited test tag to check disassembly after jit" series (see [1]). First patch is most important: as it turns out, I broke all test_loader based tests for s390 CI. E.g. see log [2] for s390 execution of test_progs, note all 'verivier_*' tests being skipped. This happens because of incorrect handling of corner case when get_current_arch() does not know which architecture to return. Second patch makes matching of function return sequence in verifier_tailcall_jit more flexible: -__jited(" retq") +__jited(" {{(retq|jmp 0x)}}") The difference could be seen with and w/o mitigations=off boot parameter for test VM (CI runs with mitigations=off, hence it generates retq). Third patch addresses Alexei's request to add #define and a comment in jit_disasm_helpers.c. [1] https://lore.kernel.org/bpf/[email protected]/ [2] https://github.com/kernel-patches/bpf/actions/runs/10518445973/job/29144511595 ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
-rw-r--r--tools/testing/selftests/bpf/jit_disasm_helpers.c17
-rw-r--r--tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c4
-rw-r--r--tools/testing/selftests/bpf/test_loader.c9
3 files changed, 21 insertions, 9 deletions
diff --git a/tools/testing/selftests/bpf/jit_disasm_helpers.c b/tools/testing/selftests/bpf/jit_disasm_helpers.c
index 1b0f1fd267c0..febd6b12e372 100644
--- a/tools/testing/selftests/bpf/jit_disasm_helpers.c
+++ b/tools/testing/selftests/bpf/jit_disasm_helpers.c
@@ -16,6 +16,11 @@
*/
#define MAX_LOCAL_LABELS 32
+/* Local labels are encoded as 'L42', this requires 4 bytes of storage:
+ * 3 characters + zero byte
+ */
+#define LOCAL_LABEL_LEN 4
+
static bool llvm_initialized;
struct local_labels {
@@ -23,7 +28,7 @@ struct local_labels {
__u32 prog_len;
__u32 cnt;
__u32 pcs[MAX_LOCAL_LABELS];
- char names[MAX_LOCAL_LABELS][4];
+ char names[MAX_LOCAL_LABELS][LOCAL_LABEL_LEN];
};
static const char *lookup_symbol(void *data, uint64_t ref_value, uint64_t *ref_type,
@@ -118,8 +123,14 @@ static int disasm_one_func(FILE *text_out, uint8_t *image, __u32 len)
}
qsort(labels.pcs, labels.cnt, sizeof(*labels.pcs), cmp_u32);
for (i = 0; i < labels.cnt; ++i)
- /* use (i % 100) to avoid format truncation warning */
- snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % 100);
+ /* gcc is unable to infer upper bound for labels.cnt and assumes
+ * it to be U32_MAX. U32_MAX takes 10 decimal digits.
+ * snprintf below prints into labels.names[*],
+ * which has space only for two digits and a letter.
+ * To avoid truncation warning use (i % MAX_LOCAL_LABELS),
+ * which informs gcc about printed value upper bound.
+ */
+ snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % MAX_LOCAL_LABELS);
/* now print with labels */
labels.print_phase = true;
diff --git a/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c b/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
index 06d327cf1e1f..8d60c634a114 100644
--- a/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
+++ b/tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
@@ -59,7 +59,7 @@ __jited(" movq -0x10(%rbp), %rax")
__jited(" callq 0x{{.*}}") /* call to sub() */
__jited(" xorl %eax, %eax")
__jited(" leave")
-__jited(" retq")
+__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */
__jited("...")
/* subprogram entry for sub(), regular function prologue */
__jited(" endbr64")
@@ -89,7 +89,7 @@ __jited(" popq %rax")
__jited(" popq %rax")
__jited(" jmp {{.*}}") /* jump to tail call tgt */
__jited("L0: leave")
-__jited(" retq")
+__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */
SEC("tc")
__naked int main(void)
{
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index 2ca9b73e5a6b..4223cffc090e 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -336,9 +336,10 @@ static const char *skip_dynamic_pfx(const char *s, const char *pfx)
}
enum arch {
- ARCH_X86_64 = 0x1,
- ARCH_ARM64 = 0x2,
- ARCH_RISCV64 = 0x4,
+ ARCH_UNKNOWN = 0x1,
+ ARCH_X86_64 = 0x2,
+ ARCH_ARM64 = 0x4,
+ ARCH_RISCV64 = 0x8,
};
static int get_current_arch(void)
@@ -350,7 +351,7 @@ static int get_current_arch(void)
#elif defined(__riscv) && __riscv_xlen == 64
return ARCH_RISCV64;
#endif
- return 0;
+ return ARCH_UNKNOWN;
}
/* Uses btf_decl_tag attributes to describe the expected test