Skip to content

Commit b4406e1

Browse files
author
Alexei Starovoitov
committed
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]>
2 parents 7559a7a + 21a56fc commit b4406e1

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

tools/testing/selftests/bpf/jit_disasm_helpers.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
*/
1717
#define MAX_LOCAL_LABELS 32
1818

19+
/* Local labels are encoded as 'L42', this requires 4 bytes of storage:
20+
* 3 characters + zero byte
21+
*/
22+
#define LOCAL_LABEL_LEN 4
23+
1924
static bool llvm_initialized;
2025

2126
struct local_labels {
2227
bool print_phase;
2328
__u32 prog_len;
2429
__u32 cnt;
2530
__u32 pcs[MAX_LOCAL_LABELS];
26-
char names[MAX_LOCAL_LABELS][4];
31+
char names[MAX_LOCAL_LABELS][LOCAL_LABEL_LEN];
2732
};
2833

2934
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)
118123
}
119124
qsort(labels.pcs, labels.cnt, sizeof(*labels.pcs), cmp_u32);
120125
for (i = 0; i < labels.cnt; ++i)
121-
/* use (i % 100) to avoid format truncation warning */
122-
snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % 100);
126+
/* gcc is unable to infer upper bound for labels.cnt and assumes
127+
* it to be U32_MAX. U32_MAX takes 10 decimal digits.
128+
* snprintf below prints into labels.names[*],
129+
* which has space only for two digits and a letter.
130+
* To avoid truncation warning use (i % MAX_LOCAL_LABELS),
131+
* which informs gcc about printed value upper bound.
132+
*/
133+
snprintf(labels.names[i], sizeof(labels.names[i]), "L%d", i % MAX_LOCAL_LABELS);
123134

124135
/* now print with labels */
125136
labels.print_phase = true;

tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ __jited(" movq -0x10(%rbp), %rax")
5959
__jited(" callq 0x{{.*}}") /* call to sub() */
6060
__jited(" xorl %eax, %eax")
6161
__jited(" leave")
62-
__jited(" retq")
62+
__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */
6363
__jited("...")
6464
/* subprogram entry for sub(), regular function prologue */
6565
__jited(" endbr64")
@@ -89,7 +89,7 @@ __jited(" popq %rax")
8989
__jited(" popq %rax")
9090
__jited(" jmp {{.*}}") /* jump to tail call tgt */
9191
__jited("L0: leave")
92-
__jited(" retq")
92+
__jited(" {{(retq|jmp 0x)}}") /* return or jump to rethunk */
9393
SEC("tc")
9494
__naked int main(void)
9595
{

tools/testing/selftests/bpf/test_loader.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ static const char *skip_dynamic_pfx(const char *s, const char *pfx)
336336
}
337337

338338
enum arch {
339-
ARCH_X86_64 = 0x1,
340-
ARCH_ARM64 = 0x2,
341-
ARCH_RISCV64 = 0x4,
339+
ARCH_UNKNOWN = 0x1,
340+
ARCH_X86_64 = 0x2,
341+
ARCH_ARM64 = 0x4,
342+
ARCH_RISCV64 = 0x8,
342343
};
343344

344345
static int get_current_arch(void)
@@ -350,7 +351,7 @@ static int get_current_arch(void)
350351
#elif defined(__riscv) && __riscv_xlen == 64
351352
return ARCH_RISCV64;
352353
#endif
353-
return 0;
354+
return ARCH_UNKNOWN;
354355
}
355356

356357
/* Uses btf_decl_tag attributes to describe the expected test

0 commit comments

Comments
 (0)