Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at master 75 lines 1.4 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2 3#include <vmlinux.h> 4#include <bpf/bpf_tracing.h> 5#include "bpf_misc.h" 6#include "../test_kmods/bpf_testmod.h" 7#include "../test_kmods/bpf_testmod_kfunc.h" 8 9char _license[] SEC("license") = "GPL"; 10 11#define MAP_A_MAGIC 1234 12int test_err_a; 13int recur; 14 15/* 16 * test_1_a is reused. The kfunc should not be able to get the associated 17 * struct_ops and call test_1 recursively as it is ambiguous. 18 */ 19SEC("struct_ops") 20int BPF_PROG(test_1_a, struct st_ops_args *args) 21{ 22 int ret; 23 24 if (!recur) { 25 recur++; 26 ret = bpf_kfunc_multi_st_ops_test_1_assoc(args); 27 if (ret != -1) 28 test_err_a++; 29 recur--; 30 } 31 32 return MAP_A_MAGIC; 33} 34 35/* Programs associated with st_ops_map_a */ 36 37SEC("syscall") 38int syscall_prog_a(void *ctx) 39{ 40 struct st_ops_args args = {}; 41 int ret; 42 43 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args); 44 if (ret != MAP_A_MAGIC) 45 test_err_a++; 46 47 return 0; 48} 49 50SEC(".struct_ops.link") 51struct bpf_testmod_multi_st_ops st_ops_map_a = { 52 .test_1 = (void *)test_1_a, 53}; 54 55/* Programs associated with st_ops_map_b */ 56 57int test_err_b; 58 59SEC("syscall") 60int syscall_prog_b(void *ctx) 61{ 62 struct st_ops_args args = {}; 63 int ret; 64 65 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args); 66 if (ret != MAP_A_MAGIC) 67 test_err_b++; 68 69 return 0; 70} 71 72SEC(".struct_ops.link") 73struct bpf_testmod_multi_st_ops st_ops_map_b = { 74 .test_1 = (void *)test_1_a, 75};