83 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/* save __u64 *ctx to stack */14__xlated("0: *(u64 *)(r10 -8) = r1")15/* main prog */16__xlated("1: r1 = *(u64 *)(r1 +0)")17__xlated("2: r2 = *(u64 *)(r1 +0)")18__xlated("3: r3 = 0")19__xlated("4: r4 = 1")20__xlated("5: if r2 == 0x0 goto pc+10")21__xlated("6: r0 = 0")22__xlated("7: *(u64 *)(r1 +0) = r3")23/* epilogue */24__xlated("8: r1 = *(u64 *)(r10 -8)")25__xlated("9: r1 = *(u64 *)(r1 +0)")26__xlated("10: r6 = *(u64 *)(r1 +0)")27__xlated("11: r6 += 10000")28__xlated("12: *(u64 *)(r1 +0) = r6")29__xlated("13: r0 = r6")30__xlated("14: r0 *= 2")31__xlated("15: exit")32/* 2nd part of the main prog after the first exit */33__xlated("16: *(u64 *)(r1 +0) = r4")34__xlated("17: r0 = 1")35/* Clear the r1 to ensure it does not have36 * off-by-1 error and ensure it jumps back to the37 * beginning of epilogue which initializes38 * the r1 with the ctx ptr.39 */40__xlated("18: r1 = 0")41__xlated("19: gotol pc-12")42SEC("struct_ops/test_epilogue_exit")43__naked int test_epilogue_exit(void)44{45 asm volatile (46 "r1 = *(u64 *)(r1 +0);"47 "r2 = *(u64 *)(r1 +0);"48 "r3 = 0;"49 "r4 = 1;"50 "if r2 == 0 goto +3;"51 "r0 = 0;"52 "*(u64 *)(r1 + 0) = r3;"53 "exit;"54 "*(u64 *)(r1 + 0) = r4;"55 "r0 = 1;"56 "r1 = 0;"57 "exit;"58 ::: __clobber_all);59}60 61SEC(".struct_ops.link")62struct bpf_testmod_st_ops epilogue_exit = {63 .test_epilogue = (void *)test_epilogue_exit,64};65 66SEC("syscall")67__retval(20000)68int syscall_epilogue_exit0(void *ctx)69{70 struct st_ops_args args = { .a = 1 };71 72 return bpf_kfunc_st_ops_test_epilogue(&args);73}74 75SEC("syscall")76__retval(20002)77int syscall_epilogue_exit1(void *ctx)78{79 struct st_ops_args args = {};80 81 return bpf_kfunc_st_ops_test_epilogue(&args);82}83