tools/testing/selftests/bpf/progs/verifier_kfunc_prog_types.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_kfunc_prog_types.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_kfunc_prog_types.c
Extension
.c
Size
2627 bytes
Lines
171
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */

#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>

#include "bpf_misc.h"
#include "cgrp_kfunc_common.h"
#include "cpumask_common.h"
#include "task_kfunc_common.h"

char _license[] SEC("license") = "GPL";

/***************
 * Task kfuncs *
 ***************/

static void task_kfunc_load_test(void)
{
	struct task_struct *current, *ref_1, *ref_2;

	current = bpf_get_current_task_btf();
	ref_1 = bpf_task_from_pid(current->pid);
	if (!ref_1)
		return;

	ref_2 = bpf_task_acquire(ref_1);
	if (ref_2)
		bpf_task_release(ref_2);
	bpf_task_release(ref_1);
}

SEC("raw_tp")
__success
int BPF_PROG(task_kfunc_raw_tp)
{
	task_kfunc_load_test();
	return 0;
}

SEC("syscall")
__success
int BPF_PROG(task_kfunc_syscall)
{
	task_kfunc_load_test();
	return 0;
}

SEC("tracepoint")
__success
int BPF_PROG(task_kfunc_tracepoint)
{
	task_kfunc_load_test();
	return 0;
}

SEC("perf_event")
__success
int BPF_PROG(task_kfunc_perf_event)
{
	task_kfunc_load_test();
	return 0;
}

/*****************
 * cgroup kfuncs *
 *****************/

static void cgrp_kfunc_load_test(void)
{
	struct cgroup *cgrp, *ref;

	cgrp = bpf_cgroup_from_id(0);
	if (!cgrp)
		return;

	ref = bpf_cgroup_acquire(cgrp);
	if (!ref) {
		bpf_cgroup_release(cgrp);
		return;
	}

	bpf_cgroup_release(ref);
	bpf_cgroup_release(cgrp);
}

SEC("raw_tp")
__success
int BPF_PROG(cgrp_kfunc_raw_tp)

Annotation

Implementation Notes