Commit e91d280c authored by Naveen N. Rao's avatar Naveen N. Rao Committed by Andrii Nakryiko
Browse files

selftests/bpf: Fix tests to use arch-dependent syscall entry points



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: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/e35f7051f03e269b623a68b139d8ed131325f7b7.1643973917.git.naveen.n.rao@linux.vnet.ibm.com
parent 046b841e
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include <linux/bpf.h>
#include <stdbool.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

@@ -87,7 +88,7 @@ bloom_callback(struct bpf_map *map, __u32 *key, void *val,
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bloom_lookup(void *ctx)
{
	struct callback_ctx data;
@@ -100,7 +101,7 @@ int bloom_lookup(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bloom_update(void *ctx)
{
	struct callback_ctx data;
@@ -113,7 +114,7 @@ int bloom_update(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bloom_hashmap_lookup(void *ctx)
{
	__u64 *result;
+3 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

@@ -51,7 +52,7 @@ check_elem(struct bpf_map *map, __u32 *key, __u32 *val,
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int inner_map(void *ctx)
{
	struct bpf_map *inner_map;
@@ -70,7 +71,7 @@ int inner_map(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int check_bloom(void *ctx)
{
	struct callback_ctx data;
+5 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

@@ -53,7 +54,7 @@ static int nested_callback1(__u32 index, void *data)
	return 0;
}

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int test_prog(void *ctx)
{
	struct callback_ctx data = {};
@@ -71,7 +72,7 @@ int test_prog(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int prog_null_ctx(void *ctx)
{
	if (bpf_get_current_pid_tgid() >> 32 != pid)
@@ -82,7 +83,7 @@ int prog_null_ctx(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int prog_invalid_flags(void *ctx)
{
	struct callback_ctx data = {};
@@ -95,7 +96,7 @@ int prog_invalid_flags(void *ctx)
	return 0;
}

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int prog_nested_calls(void *ctx)
{
	struct callback_ctx data = {};
+2 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

@@ -14,7 +15,7 @@ static int empty_callback(__u32 index, void *data)
	return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int benchmark(void *ctx)
{
	for (int i = 0; i < 1000; i++) {
+5 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

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

@@ -10,8 +11,8 @@ int pid = 0;
int fentry_cnt = 0;
int fexit_cnt = 0;

SEC("fentry/__x64_sys_nanosleep")
int BPF_PROG(nanosleep_fentry, const struct pt_regs *regs)
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int nanosleep_fentry(void *ctx)
{
	if (bpf_get_current_pid_tgid() >> 32 != pid)
		return 0;
@@ -20,8 +21,8 @@ int BPF_PROG(nanosleep_fentry, const struct pt_regs *regs)
	return 0;
}

SEC("fexit/__x64_sys_nanosleep")
int BPF_PROG(nanosleep_fexit, const struct pt_regs *regs, int ret)
SEC("fexit/" SYS_PREFIX "sys_nanosleep")
int nanosleep_fexit(void *ctx)
{
	if (bpf_get_current_pid_tgid() >> 32 != pid)
		return 0;
Loading