Add private_stack_timed_may_goto() with enough stack usage to select a private stack. Check that the JIT uses the private-stack frame pointer when constructing the pointer passed to the architecture trampoline. Update the translated instruction expectations in may_goto_batch_2(), may_goto_interaction_x86_64(), and may_goto_interaction() for the additional pointer construction instruction and adjusted branch offsets. Signed-off-by: Siddharth Chintamaneni --- .../bpf/progs/verifier_bpf_fastcall.c | 30 ++++++++++--------- .../selftests/bpf/progs/verifier_may_goto_1.c | 17 ++++++----- .../bpf/progs/verifier_private_stack.c | 19 ++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c index 328cf630210a..c5996d9dc8cc 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c +++ b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c @@ -635,15 +635,16 @@ __xlated("4: r0 = &(void __percpu *)(r0)") __xlated("...") /* may_goto expansion starts */ __xlated("6: r12 = *(u64 *)(r10 -24)") -__xlated("7: if r12 == 0x0 goto pc+6") +__xlated("7: if r12 == 0x0 goto pc+7") __xlated("8: r12 -= 1") -__xlated("9: if r12 != 0x0 goto pc+2") -__xlated("10: r12 = -24") -__xlated("11: call unknown") -__xlated("12: *(u64 *)(r10 -24) = r12") +__xlated("9: if r12 != 0x0 goto pc+3") +__xlated("10: r12 = r10") +__xlated("11: r12 += -24") +__xlated("12: call unknown") +__xlated("13: *(u64 *)(r10 -24) = r12") /* may_goto expansion ends */ -__xlated("13: *(u64 *)(r10 -8) = r1") -__xlated("14: exit") +__xlated("14: *(u64 *)(r10 -8) = r1") +__xlated("15: exit") __success __naked void may_goto_interaction_x86_64(void) { @@ -676,15 +677,16 @@ __xlated("2: r1 = 1") __xlated("3: call bpf_get_smp_processor_id") /* may_goto expansion starts */ __xlated("4: r12 = *(u64 *)(r10 -24)") -__xlated("5: if r12 == 0x0 goto pc+6") +__xlated("5: if r12 == 0x0 goto pc+7") __xlated("6: r12 -= 1") -__xlated("7: if r12 != 0x0 goto pc+2") -__xlated("8: r12 = -24") -__xlated("9: call unknown") -__xlated("10: *(u64 *)(r10 -24) = r12") +__xlated("7: if r12 != 0x0 goto pc+3") +__xlated("8: r12 = r10") +__xlated("9: r12 += -24") +__xlated("10: call unknown") +__xlated("11: *(u64 *)(r10 -24) = r12") /* may_goto expansion ends */ -__xlated("11: *(u64 *)(r10 -8) = r1") -__xlated("12: exit") +__xlated("12: *(u64 *)(r10 -8) = r1") +__xlated("13: exit") __success __naked void may_goto_interaction(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c index db7e30da234f..1721897160dc 100644 --- a/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c +++ b/tools/testing/selftests/bpf/progs/verifier_may_goto_1.c @@ -90,15 +90,16 @@ __arch_loongarch __xlated("0: *(u64 *)(r10 -16) = 65535") __xlated("1: *(u64 *)(r10 -8) = 0") __xlated("2: r12 = *(u64 *)(r10 -16)") -__xlated("3: if r12 == 0x0 goto pc+6") +__xlated("3: if r12 == 0x0 goto pc+7") __xlated("4: r12 -= 1") -__xlated("5: if r12 != 0x0 goto pc+2") -__xlated("6: r12 = -16") -__xlated("7: call unknown") -__xlated("8: *(u64 *)(r10 -16) = r12") -__xlated("9: r0 = 1") -__xlated("10: r0 = 2") -__xlated("11: exit") +__xlated("5: if r12 != 0x0 goto pc+3") +__xlated("6: r12 = r10") +__xlated("7: r12 += -16") +__xlated("8: call unknown") +__xlated("9: *(u64 *)(r10 -16) = r12") +__xlated("10: r0 = 1") +__xlated("11: r0 = 2") +__xlated("12: exit") __success __naked void may_goto_batch_2(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_private_stack.c b/tools/testing/selftests/bpf/progs/verifier_private_stack.c index 3d9994a52464..639b53363c9a 100644 --- a/tools/testing/selftests/bpf/progs/verifier_private_stack.c +++ b/tools/testing/selftests/bpf/progs/verifier_private_stack.c @@ -70,6 +70,25 @@ __naked void no_private_stack_nested(void) " ::: __clobber_all); } +SEC("fentry/bpf_fentry_test9") +__description("Private stack, timed may_goto") +__success __retval(0) +__arch_x86_64 +__jited(" movabsq $0x{{.*}}, %r9") +__jited("...") +__jited(" movq %r9, %r10") +__arch_arm64 +__jited(" mov x9, x25") +int private_stack_timed_may_goto(void) +{ + volatile __u64 stack_space[16] = {}; + + while (can_loop) + ; + + return stack_space[0]; +} + __used __naked static void cumulative_stack_depth_subprog(void) { -- 2.43.0