Skip to content

Commit 2532608

Browse files
chleroyborkmann
authored andcommitted
bpf/tests: Add 32 bits only long conditional jump tests
Commit f1517eb ("bpf/tests: Expand branch conversion JIT test") introduced "Long conditional jump tests" but due to those tests making use of 64 bits DIV and MOD, they don't get jited on powerpc/32, leading to the long conditional jump test being skiped for unrelated reason. Add 4 new tests that are restricted to 32 bits ALU so that the jump tests can also be performed on platforms that do no support 64 bits operations. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/609f87a2d84e032c8d9ccb9ba7aebef893698f1e.1736154762.git.christophe.leroy@csgroup.eu
1 parent 8c21f88 commit 2532608

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

Diff for: lib/test_bpf.c

+58-6
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int __bpf_ld_imm64(struct bpf_insn insns[2], u8 reg, s64 imm64)
478478
* to overflow the field size of the native instruction, triggering
479479
* a branch conversion mechanism in some JITs.
480480
*/
481-
static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm)
481+
static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm, bool alu32)
482482
{
483483
struct bpf_insn *insns;
484484
int len = S16_MAX + 5;
@@ -501,7 +501,7 @@ static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm)
501501
};
502502
int op = ops[(i >> 1) % ARRAY_SIZE(ops)];
503503

504-
if (i & 1)
504+
if ((i & 1) || alu32)
505505
insns[i++] = BPF_ALU32_REG(op, R0, R1);
506506
else
507507
insns[i++] = BPF_ALU64_REG(op, R0, R1);
@@ -516,27 +516,47 @@ static int __bpf_fill_max_jmp(struct bpf_test *self, int jmp, int imm)
516516
}
517517

518518
/* Branch taken by runtime decision */
519+
static int bpf_fill_max_jmp_taken_32(struct bpf_test *self)
520+
{
521+
return __bpf_fill_max_jmp(self, BPF_JEQ, 1, true);
522+
}
523+
519524
static int bpf_fill_max_jmp_taken(struct bpf_test *self)
520525
{
521-
return __bpf_fill_max_jmp(self, BPF_JEQ, 1);
526+
return __bpf_fill_max_jmp(self, BPF_JEQ, 1, false);
522527
}
523528

524529
/* Branch not taken by runtime decision */
530+
static int bpf_fill_max_jmp_not_taken_32(struct bpf_test *self)
531+
{
532+
return __bpf_fill_max_jmp(self, BPF_JEQ, 0, true);
533+
}
534+
525535
static int bpf_fill_max_jmp_not_taken(struct bpf_test *self)
526536
{
527-
return __bpf_fill_max_jmp(self, BPF_JEQ, 0);
537+
return __bpf_fill_max_jmp(self, BPF_JEQ, 0, false);
528538
}
529539

530540
/* Branch always taken, known at JIT time */
541+
static int bpf_fill_max_jmp_always_taken_32(struct bpf_test *self)
542+
{
543+
return __bpf_fill_max_jmp(self, BPF_JGE, 0, true);
544+
}
545+
531546
static int bpf_fill_max_jmp_always_taken(struct bpf_test *self)
532547
{
533-
return __bpf_fill_max_jmp(self, BPF_JGE, 0);
548+
return __bpf_fill_max_jmp(self, BPF_JGE, 0, false);
534549
}
535550

536551
/* Branch never taken, known at JIT time */
552+
static int bpf_fill_max_jmp_never_taken_32(struct bpf_test *self)
553+
{
554+
return __bpf_fill_max_jmp(self, BPF_JLT, 0, true);
555+
}
556+
537557
static int bpf_fill_max_jmp_never_taken(struct bpf_test *self)
538558
{
539-
return __bpf_fill_max_jmp(self, BPF_JLT, 0);
559+
return __bpf_fill_max_jmp(self, BPF_JLT, 0, false);
540560
}
541561

542562
/* ALU result computation used in tests */
@@ -14233,6 +14253,38 @@ static struct bpf_test tests[] = {
1423314253
{ { 0, 0 } },
1423414254
},
1423514255
/* Conditional branch conversions */
14256+
{
14257+
"Long conditional jump: taken at runtime (32 bits)",
14258+
{ },
14259+
INTERNAL | FLAG_NO_DATA,
14260+
{ },
14261+
{ { 0, 1 } },
14262+
.fill_helper = bpf_fill_max_jmp_taken_32,
14263+
},
14264+
{
14265+
"Long conditional jump: not taken at runtime (32 bits)",
14266+
{ },
14267+
INTERNAL | FLAG_NO_DATA,
14268+
{ },
14269+
{ { 0, 2 } },
14270+
.fill_helper = bpf_fill_max_jmp_not_taken_32,
14271+
},
14272+
{
14273+
"Long conditional jump: always taken, known at JIT time (32 bits)",
14274+
{ },
14275+
INTERNAL | FLAG_NO_DATA,
14276+
{ },
14277+
{ { 0, 1 } },
14278+
.fill_helper = bpf_fill_max_jmp_always_taken_32,
14279+
},
14280+
{
14281+
"Long conditional jump: never taken, known at JIT time (32 bits)",
14282+
{ },
14283+
INTERNAL | FLAG_NO_DATA,
14284+
{ },
14285+
{ { 0, 2 } },
14286+
.fill_helper = bpf_fill_max_jmp_never_taken_32,
14287+
},
1423614288
{
1423714289
"Long conditional jump: taken at runtime",
1423814290
{ },

0 commit comments

Comments
 (0)