Skip to content

Commit 422ee58

Browse files
rnavanakryiko
authored andcommitted
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: Naveen N. Rao <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/e35f7051f03e269b623a68b139d8ed131325f7b7.1643973917.git.naveen.n.rao@linux.vnet.ibm.com
1 parent 9830f05 commit 422ee58

File tree

11 files changed

+34
-23
lines changed

11 files changed

+34
-23
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/bpf.h>
66
#include <stdbool.h>
77
#include <bpf/bpf_helpers.h>
8+
#include "bpf_misc.h"
89

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

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

90-
SEC("fentry/__x64_sys_getpgid")
91+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
9192
int bloom_lookup(void *ctx)
9293
{
9394
struct callback_ctx data;
@@ -100,7 +101,7 @@ int bloom_lookup(void *ctx)
100101
return 0;
101102
}
102103

103-
SEC("fentry/__x64_sys_getpgid")
104+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
104105
int bloom_update(void *ctx)
105106
{
106107
struct callback_ctx data;
@@ -113,7 +114,7 @@ int bloom_update(void *ctx)
113114
return 0;
114115
}
115116

116-
SEC("fentry/__x64_sys_getpgid")
117+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
117118
int bloom_hashmap_lookup(void *ctx)
118119
{
119120
__u64 *result;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/bpf.h>
55
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
67

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

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

54-
SEC("fentry/__x64_sys_getpgid")
55+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
5556
int inner_map(void *ctx)
5657
{
5758
struct bpf_map *inner_map;
@@ -70,7 +71,7 @@ int inner_map(void *ctx)
7071
return 0;
7172
}
7273

73-
SEC("fentry/__x64_sys_getpgid")
74+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
7475
int check_bloom(void *ctx)
7576
{
7677
struct callback_ctx data;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "vmlinux.h"
55
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
67

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

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

56-
SEC("fentry/__x64_sys_nanosleep")
57+
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
5758
int test_prog(void *ctx)
5859
{
5960
struct callback_ctx data = {};
@@ -71,7 +72,7 @@ int test_prog(void *ctx)
7172
return 0;
7273
}
7374

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

85-
SEC("fentry/__x64_sys_nanosleep")
86+
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
8687
int prog_invalid_flags(void *ctx)
8788
{
8889
struct callback_ctx data = {};
@@ -95,7 +96,7 @@ int prog_invalid_flags(void *ctx)
9596
return 0;
9697
}
9798

98-
SEC("fentry/__x64_sys_nanosleep")
99+
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
99100
int prog_nested_calls(void *ctx)
100101
{
101102
struct callback_ctx data = {};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "vmlinux.h"
55
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
67

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

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

17-
SEC("fentry/__x64_sys_getpgid")
18+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
1819
int benchmark(void *ctx)
1920
{
2021
for (int i = 0; i < 1000; i++) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include "vmlinux.h"
44
#include <bpf/bpf_helpers.h>
55
#include <bpf/bpf_tracing.h>
6+
#include "bpf_misc.h"
67

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

910
int pid = 0;
1011
int fentry_cnt = 0;
1112
int fexit_cnt = 0;
1213

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

23-
SEC("fexit/__x64_sys_nanosleep")
24-
int BPF_PROG(nanosleep_fexit, const struct pt_regs *regs, int ret)
24+
SEC("fexit/" SYS_PREFIX "sys_nanosleep")
25+
int nanosleep_fexit(void *ctx)
2526
{
2627
if (bpf_get_current_pid_tgid() >> 32 != pid)
2728
return 0;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/bpf.h>
55
#include <stdint.h>
66
#include <bpf/bpf_helpers.h>
7+
#include "bpf_misc.h"
78

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

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

21-
SEC("fentry/__x64_sys_getpgid")
22+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
2223
int bench_perfbuf(void *ctx)
2324
{
2425
__u64 *sample;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/bpf.h>
55
#include <stdint.h>
66
#include <bpf/bpf_helpers.h>
7+
#include "bpf_misc.h"
78

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

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

33-
SEC("fentry/__x64_sys_getpgid")
34+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
3435
int bench_ringbuf(void *ctx)
3536
{
3637
long *sample, flags;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/bpf.h>
55
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
67

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

@@ -35,7 +36,7 @@ long prod_pos = 0;
3536
/* inner state */
3637
long seq = 0;
3738

38-
SEC("fentry/__x64_sys_getpgid")
39+
SEC("fentry/" SYS_PREFIX "sys_getpgid")
3940
int test_ringbuf(void *ctx)
4041
{
4142
int cur_pid = bpf_get_current_pid_tgid() >> 32;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "vmlinux.h"
55
#include <bpf/bpf_helpers.h>
66
#include <bpf/bpf_tracing.h>
7+
#include "bpf_misc.h"
78

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

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

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

15-
SEC("fentry/__x64_sys_nanosleep")
16+
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
1617
int sys_enter(void *ctx)
1718
{
1819
trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
#include "vmlinux.h"
55
#include <bpf/bpf_helpers.h>
66
#include <bpf/bpf_tracing.h>
7+
#include "bpf_misc.h"
78

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

1011
int null_data_vprintk_ret = 0;
1112
int trace_vprintk_ret = 0;
1213
int trace_vprintk_ran = 0;
1314

14-
SEC("fentry/__x64_sys_nanosleep")
15+
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
1516
int sys_enter(void *ctx)
1617
{
1718
static const char one[] = "1";

0 commit comments

Comments
 (0)