Some of the tests are using x86_64 ABI-specific syscall entry points (such as __x64_sys_nanosleep and __x64_sys_getpgid). Update them to use architecture-dependent syscall entry names. Also update fexit_sleep test to not use BPF_PROG() so that it is clear that the syscall parameters aren't being accessed in the bpf prog. Note that none of the bpf progs in these tests are actually accessing any of the syscall parameters. The only exception is perfbuf_bench, which passes on the bpf prog context into bpf_perf_event_output() as a pointer to pt_regs, but that looks to be mostly ignored. Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/e35f7051f03e269b623a68b139d8ed131325f7b7.1643973917.git.naveen.n.rao@linux.vnet.ibm.com
113 lines
2 KiB
C
113 lines
2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2021 Facebook */
|
|
|
|
#include "vmlinux.h"
|
|
#include <bpf/bpf_helpers.h>
|
|
#include "bpf_misc.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
struct callback_ctx {
|
|
int output;
|
|
};
|
|
|
|
/* These should be set by the user program */
|
|
u32 nested_callback_nr_loops;
|
|
u32 stop_index = -1;
|
|
u32 nr_loops;
|
|
int pid;
|
|
|
|
/* Making these global variables so that the userspace program
|
|
* can verify the output through the skeleton
|
|
*/
|
|
int nr_loops_returned;
|
|
int g_output;
|
|
int err;
|
|
|
|
static int callback(__u32 index, void *data)
|
|
{
|
|
struct callback_ctx *ctx = data;
|
|
|
|
if (index >= stop_index)
|
|
return 1;
|
|
|
|
ctx->output += index;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int empty_callback(__u32 index, void *data)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int nested_callback2(__u32 index, void *data)
|
|
{
|
|
nr_loops_returned += bpf_loop(nested_callback_nr_loops, callback, data, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int nested_callback1(__u32 index, void *data)
|
|
{
|
|
bpf_loop(nested_callback_nr_loops, nested_callback2, data, 0);
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
|
|
int test_prog(void *ctx)
|
|
{
|
|
struct callback_ctx data = {};
|
|
|
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
|
return 0;
|
|
|
|
nr_loops_returned = bpf_loop(nr_loops, callback, &data, 0);
|
|
|
|
if (nr_loops_returned < 0)
|
|
err = nr_loops_returned;
|
|
else
|
|
g_output = data.output;
|
|
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
|
|
int prog_null_ctx(void *ctx)
|
|
{
|
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
|
return 0;
|
|
|
|
nr_loops_returned = bpf_loop(nr_loops, empty_callback, NULL, 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
|
|
int prog_invalid_flags(void *ctx)
|
|
{
|
|
struct callback_ctx data = {};
|
|
|
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
|
return 0;
|
|
|
|
err = bpf_loop(nr_loops, callback, &data, 1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
|
|
int prog_nested_calls(void *ctx)
|
|
{
|
|
struct callback_ctx data = {};
|
|
|
|
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
|
return 0;
|
|
|
|
nr_loops_returned = 0;
|
|
bpf_loop(nr_loops, nested_callback1, &data, 0);
|
|
|
|
g_output = data.output;
|
|
|
|
return 0;
|
|
}
|