File Index
Files and directories
Sign in
FILE

pro_epilogue_with_kfunc.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/progs/pro_epilogue_with_kfunc.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
 3
 4#include <vmlinux.h>
 5#include <bpf/bpf_tracing.h>
 6#include "bpf_misc.h"
 7#include "../test_kmods/bpf_testmod.h"
 8#include "../test_kmods/bpf_testmod_kfunc.h"
 9
10char _license[] SEC("license") = "GPL";
11
12void __kfunc_btf_root(void)
13{
14	bpf_kfunc_st_ops_inc10(NULL);
15}
16
17static __noinline __used int subprog(struct st_ops_args *args)
18{
19	args->a += 1;
20	return args->a;
21}
22
23__success
24/* prologue */
25__xlated("0: r8 = r1")
26__xlated("1: r1 = 0")
27__xlated("2: call kernel-function")
28__xlated("3: if r0 != 0x0 goto pc+5")
29__xlated("4: r6 = *(u64 *)(r8 +0)")
30__xlated("5: r7 = *(u64 *)(r6 +0)")
31__xlated("6: r7 += 1000")
32__xlated("7: *(u64 *)(r6 +0) = r7")
33__xlated("8: goto pc+2")
34__xlated("9: r1 = r0")
35__xlated("10: call kernel-function")
36__xlated("11: r1 = r8")
37/* save __u64 *ctx to stack */
38__xlated("12: *(u64 *)(r10 -8) = r1")
39/* main prog */
40__xlated("13: r1 = *(u64 *)(r1 +0)")
41__xlated("14: r6 = r1")
42__xlated("15: call kernel-function")
43__xlated("16: r1 = r6")
44__xlated("17: call pc+")
45/* epilogue */
46__xlated("18: r1 = 0")
47__xlated("19: r6 = 0")
48__xlated("20: call kernel-function")
49__xlated("21: if r0 != 0x0 goto pc+6")
50__xlated("22: r1 = *(u64 *)(r10 -8)")
51__xlated("23: r1 = *(u64 *)(r1 +0)")
52__xlated("24: r6 = *(u64 *)(r1 +0)")
53__xlated("25: r6 += 10000")
54__xlated("26: *(u64 *)(r1 +0) = r6")
55__xlated("27: goto pc+2")
56__xlated("28: r1 = r0")
57__xlated("29: call kernel-function")
58__xlated("30: r0 = r6")
59__xlated("31: r0 *= 2")
60__xlated("32: exit")
61SEC("struct_ops/test_pro_epilogue")
62__naked int test_kfunc_pro_epilogue(void)
63{
64	asm volatile (
65	"r1 = *(u64 *)(r1 +0);"
66	"r6 = r1;"
67	"call %[bpf_kfunc_st_ops_inc10];"
68	"r1 = r6;"
69	"call subprog;"
70	"exit;"
71	:
72	: __imm(bpf_kfunc_st_ops_inc10)
73	: __clobber_all);
74}
75
76SEC("syscall")
77__retval(22022) /* (PROLOGUE_A [1000] + KFUNC_INC10 + SUBPROG_A [1] + EPILOGUE_A [10000]) * 2 */
78int syscall_pro_epilogue(void *ctx)
79{
80	struct st_ops_args args = {};
81
82	return bpf_kfunc_st_ops_test_pro_epilogue(&args);
83}
84
85SEC(".struct_ops.link")
86struct bpf_testmod_st_ops pro_epilogue_with_kfunc = {
87	.test_pro_epilogue = (void *)test_kfunc_pro_epilogue,
88};
~/ Read-only file preview.