150 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */3 4#include <vmlinux.h>5#include <bpf/bpf_tracing.h>6#include "bpf_misc.h"7#include "../bpf_testmod/bpf_testmod.h"8#include "../bpf_testmod/bpf_testmod_kfunc.h"9 10char _license[] SEC("license") = "GPL";11 12__success13/* prologue */14__xlated("0: r6 = *(u64 *)(r1 +0)")15__xlated("1: r7 = *(u64 *)(r6 +0)")16__xlated("2: r7 += 1000")17__xlated("3: *(u64 *)(r6 +0) = r7")18/* main prog */19__xlated("4: if r1 == 0x0 goto pc+5")20__xlated("5: if r1 == 0x1 goto pc+2")21__xlated("6: r1 = 1")22__xlated("7: goto pc-3")23__xlated("8: r1 = 0")24__xlated("9: goto pc-6")25__xlated("10: r0 = 0")26__xlated("11: exit")27SEC("struct_ops/test_prologue_goto_start")28__naked int test_prologue_goto_start(void)29{30 asm volatile (31 "if r1 == 0 goto +5;"32 "if r1 == 1 goto +2;"33 "r1 = 1;"34 "goto -3;"35 "r1 = 0;"36 "goto -6;"37 "r0 = 0;"38 "exit;"39 ::: __clobber_all);40}41 42__success43/* save __u64 *ctx to stack */44__xlated("0: *(u64 *)(r10 -8) = r1")45/* main prog */46__xlated("1: if r1 == 0x0 goto pc+5")47__xlated("2: if r1 == 0x1 goto pc+2")48__xlated("3: r1 = 1")49__xlated("4: goto pc-3")50__xlated("5: r1 = 0")51__xlated("6: goto pc-6")52__xlated("7: r0 = 0")53/* epilogue */54__xlated("8: r1 = *(u64 *)(r10 -8)")55__xlated("9: r1 = *(u64 *)(r1 +0)")56__xlated("10: r6 = *(u64 *)(r1 +0)")57__xlated("11: r6 += 10000")58__xlated("12: *(u64 *)(r1 +0) = r6")59__xlated("13: r0 = r6")60__xlated("14: r0 *= 2")61__xlated("15: exit")62SEC("struct_ops/test_epilogue_goto_start")63__naked int test_epilogue_goto_start(void)64{65 asm volatile (66 "if r1 == 0 goto +5;"67 "if r1 == 1 goto +2;"68 "r1 = 1;"69 "goto -3;"70 "r1 = 0;"71 "goto -6;"72 "r0 = 0;"73 "exit;"74 ::: __clobber_all);75}76 77__success78/* prologue */79__xlated("0: r6 = *(u64 *)(r1 +0)")80__xlated("1: r7 = *(u64 *)(r6 +0)")81__xlated("2: r7 += 1000")82__xlated("3: *(u64 *)(r6 +0) = r7")83/* save __u64 *ctx to stack */84__xlated("4: *(u64 *)(r10 -8) = r1")85/* main prog */86__xlated("5: if r1 == 0x0 goto pc+5")87__xlated("6: if r1 == 0x1 goto pc+2")88__xlated("7: r1 = 1")89__xlated("8: goto pc-3")90__xlated("9: r1 = 0")91__xlated("10: goto pc-6")92__xlated("11: r0 = 0")93/* epilogue */94__xlated("12: r1 = *(u64 *)(r10 -8)")95__xlated("13: r1 = *(u64 *)(r1 +0)")96__xlated("14: r6 = *(u64 *)(r1 +0)")97__xlated("15: r6 += 10000")98__xlated("16: *(u64 *)(r1 +0) = r6")99__xlated("17: r0 = r6")100__xlated("18: r0 *= 2")101__xlated("19: exit")102SEC("struct_ops/test_pro_epilogue_goto_start")103__naked int test_pro_epilogue_goto_start(void)104{105 asm volatile (106 "if r1 == 0 goto +5;"107 "if r1 == 1 goto +2;"108 "r1 = 1;"109 "goto -3;"110 "r1 = 0;"111 "goto -6;"112 "r0 = 0;"113 "exit;"114 ::: __clobber_all);115}116 117SEC(".struct_ops.link")118struct bpf_testmod_st_ops epilogue_goto_start = {119 .test_prologue = (void *)test_prologue_goto_start,120 .test_epilogue = (void *)test_epilogue_goto_start,121 .test_pro_epilogue = (void *)test_pro_epilogue_goto_start,122};123 124SEC("syscall")125__retval(0)126int syscall_prologue_goto_start(void *ctx)127{128 struct st_ops_args args = {};129 130 return bpf_kfunc_st_ops_test_prologue(&args);131}132 133SEC("syscall")134__retval(20000) /* (EPILOGUE_A [10000]) * 2 */135int syscall_epilogue_goto_start(void *ctx)136{137 struct st_ops_args args = {};138 139 return bpf_kfunc_st_ops_test_epilogue(&args);140}141 142SEC("syscall")143__retval(22000) /* (PROLOGUE_A [1000] + EPILOGUE_A [10000]) * 2 */144int syscall_pro_epilogue_goto_start(void *ctx)145{146 struct st_ops_args args = {};147 148 return bpf_kfunc_st_ops_test_pro_epilogue(&args);149}150