Skip to content

Commit

Permalink
selftests/bpf: Fix tests to use arch-dependent syscall entry points
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Naveen N. Rao authored and Andrii Nakryiko committed Feb 7, 2022
1 parent 046b841 commit e91d280
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 23 deletions.
7 changes: 4 additions & 3 deletions tools/testing/selftests/bpf/progs/bloom_filter_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tools/testing/selftests/bpf/progs/bloom_filter_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions tools/testing/selftests/bpf/progs/bpf_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

Expand Down Expand Up @@ -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 = {};
Expand All @@ -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)
Expand All @@ -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 = {};
Expand All @@ -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 = {};
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/bpf_loop_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

Expand All @@ -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++) {
Expand Down
9 changes: 5 additions & 4 deletions tools/testing/selftests/bpf/progs/fexit_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

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

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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/perfbuf_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/bpf.h>
#include <stdint.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

Expand All @@ -18,7 +19,7 @@ const volatile int batch_cnt = 0;
long sample_val = 42;
long dropped __attribute__((aligned(128))) = 0;

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bench_perfbuf(void *ctx)
{
__u64 *sample;
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/ringbuf_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/bpf.h>
#include <stdint.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

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

Expand All @@ -30,7 +31,7 @@ static __always_inline long get_flags()
return sz >= wakeup_data_size ? BPF_RB_FORCE_WAKEUP : BPF_RB_NO_WAKEUP;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bench_ringbuf(void *ctx)
{
long *sample, flags;
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/test_ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

Expand Down Expand Up @@ -35,7 +36,7 @@ long prod_pos = 0;
/* inner state */
long seq = 0;

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int test_ringbuf(void *ctx)
{
int cur_pid = bpf_get_current_pid_tgid() >> 32;
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/trace_printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

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

Expand All @@ -12,7 +13,7 @@ int trace_printk_ran = 0;

const char fmt[] = "Testing,testing %d\n";

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int sys_enter(void *ctx)
{
trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt),
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/bpf/progs/trace_vprintk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

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

int null_data_vprintk_ret = 0;
int trace_vprintk_ret = 0;
int trace_vprintk_ran = 0;

SEC("fentry/__x64_sys_nanosleep")
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int sys_enter(void *ctx)
{
static const char one[] = "1";
Expand Down
9 changes: 5 additions & 4 deletions tools/testing/selftests/bpf/progs/trigger_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <asm/unistd.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

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

Expand All @@ -25,28 +26,28 @@ int BPF_PROG(bench_trigger_raw_tp, struct pt_regs *regs, long id)
return 0;
}

SEC("kprobe/__x64_sys_getpgid")
SEC("kprobe/" SYS_PREFIX "sys_getpgid")
int bench_trigger_kprobe(void *ctx)
{
__sync_add_and_fetch(&hits, 1);
return 0;
}

SEC("fentry/__x64_sys_getpgid")
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int bench_trigger_fentry(void *ctx)
{
__sync_add_and_fetch(&hits, 1);
return 0;
}

SEC("fentry.s/__x64_sys_getpgid")
SEC("fentry.s/" SYS_PREFIX "sys_getpgid")
int bench_trigger_fentry_sleep(void *ctx)
{
__sync_add_and_fetch(&hits, 1);
return 0;
}

SEC("fmod_ret/__x64_sys_getpgid")
SEC("fmod_ret/" SYS_PREFIX "sys_getpgid")
int bench_trigger_fmodret(void *ctx)
{
__sync_add_and_fetch(&hits, 1);
Expand Down

0 comments on commit e91d280

Please sign in to comment.