xref: /linux/tools/testing/selftests/bpf/progs/struct_ops_multi_args.c (revision 0fc8f6200d2313278fbf4539bbab74677c685531)
1*b43d574cSVarun R Mallya // SPDX-License-Identifier: GPL-2.0
2*b43d574cSVarun R Mallya /* Copyright (c) 2026 Varun R Mallya */
3*b43d574cSVarun R Mallya 
4*b43d574cSVarun R Mallya #include <vmlinux.h>
5*b43d574cSVarun R Mallya #include <bpf/bpf_helpers.h>
6*b43d574cSVarun R Mallya #include <bpf/bpf_tracing.h>
7*b43d574cSVarun R Mallya #include "../test_kmods/bpf_testmod.h"
8*b43d574cSVarun R Mallya #include "bpf_misc.h"
9*b43d574cSVarun R Mallya 
10*b43d574cSVarun R Mallya char _license[] SEC("license") = "GPL";
11*b43d574cSVarun R Mallya 
12*b43d574cSVarun R Mallya struct {
13*b43d574cSVarun R Mallya 	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
14*b43d574cSVarun R Mallya 	__uint(max_entries, 1);
15*b43d574cSVarun R Mallya 	__uint(key_size, sizeof(__u32));
16*b43d574cSVarun R Mallya 	__uint(value_size, sizeof(__u32));
17*b43d574cSVarun R Mallya } prog_array SEC(".maps");
18*b43d574cSVarun R Mallya 
19*b43d574cSVarun R Mallya SEC("struct_ops/test_refcounted_multi")
20*b43d574cSVarun R Mallya __failure __msg("program with __ref argument cannot tail call")
21*b43d574cSVarun R Mallya int test_refcounted_multi(unsigned long long *ctx)
22*b43d574cSVarun R Mallya {
23*b43d574cSVarun R Mallya 	/* ctx[2] is used because the refcounted variable is the third argument */
24*b43d574cSVarun R Mallya 	struct task_struct *refcounted_task = (struct task_struct *)ctx[2];
25*b43d574cSVarun R Mallya 
26*b43d574cSVarun R Mallya 	bpf_task_release(refcounted_task);
27*b43d574cSVarun R Mallya 	bpf_tail_call(ctx, &prog_array, 0);
28*b43d574cSVarun R Mallya 
29*b43d574cSVarun R Mallya 	return 0;
30*b43d574cSVarun R Mallya }
31*b43d574cSVarun R Mallya 
32*b43d574cSVarun R Mallya SEC(".struct_ops.link")
33*b43d574cSVarun R Mallya struct bpf_testmod_ops testmod_ref_acquire = {
34*b43d574cSVarun R Mallya 	.test_refcounted_multi = (void *)test_refcounted_multi,
35*b43d574cSVarun R Mallya };
36