Skip to content

Commit ec20469

Browse files
chenhengqiKernel Patches Daemon
authored andcommitted
selftests/bpf: Use vmlinux.h for BPF programs
Some of the bpf test progs still use linux/libc headers. Let's use vmlinux.h instead like the rest of test progs. This will also ease cross compiling. Signed-off-by: Hengqi Chen <[email protected]>
1 parent bf66d41 commit ec20469

File tree

5 files changed

+8
-33
lines changed

5 files changed

+8
-33
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Facebook
3-
#include <linux/sched.h>
4-
#include <linux/ptrace.h>
5-
#include <stdint.h>
6-
#include <stddef.h>
7-
#include <stdbool.h>
8-
#include <linux/bpf.h>
3+
#include "vmlinux.h"
94
#include <bpf/bpf_helpers.h>
105
#include <bpf/bpf_tracing.h>
116

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Facebook
3-
#include <linux/sched.h>
4-
#include <linux/ptrace.h>
5-
#include <stdint.h>
6-
#include <stddef.h>
7-
#include <stdbool.h>
8-
#include <linux/bpf.h>
3+
#include "vmlinux.h"
94
#include <bpf/bpf_helpers.h>
105
#include <bpf/bpf_tracing.h>
116

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
// Copyright (c) 2019 Facebook
3-
#include <linux/sched.h>
4-
#include <linux/ptrace.h>
5-
#include <stdint.h>
6-
#include <stddef.h>
7-
#include <stdbool.h>
8-
#include <linux/bpf.h>
3+
#include "vmlinux.h"
94
#include <bpf/bpf_helpers.h>
105
#include <bpf/bpf_tracing.h>
116

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
#include <linux/ptrace.h>
4-
#include <stddef.h>
5-
#include <linux/bpf.h>
3+
#include <vmlinux.h>
4+
#include <bpf/bpf_core_read.h>
65
#include <bpf/bpf_helpers.h>
76
#include <bpf/bpf_tracing.h>
87
#include "bpf_misc.h"
@@ -26,12 +25,6 @@ char _license[] SEC("license") = "GPL";
2625
#define SG_CHAIN 0x01UL
2726
#define SG_END 0x02UL
2827

29-
struct scatterlist {
30-
unsigned long page_link;
31-
unsigned int offset;
32-
unsigned int length;
33-
};
34-
3528
#define sg_is_chain(sg) ((sg)->page_link & SG_CHAIN)
3629
#define sg_is_last(sg) ((sg)->page_link & SG_END)
3730
#define sg_chain_ptr(sg) \
@@ -80,7 +73,7 @@ int BPF_KPROBE(trace_virtqueue_add_sgs, void *unused, struct scatterlist **sgs,
8073
__sink(out_sgs);
8174
for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX);
8275
sgp = __sg_next(sgp)) {
83-
bpf_probe_read_kernel(&len, sizeof(len), &sgp->length);
76+
len = BPF_CORE_READ(sgp, length);
8477
length1 += len;
8578
n++;
8679
}
@@ -90,7 +83,7 @@ int BPF_KPROBE(trace_virtqueue_add_sgs, void *unused, struct scatterlist **sgs,
9083
__sink(in_sgs);
9184
for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX);
9285
sgp = __sg_next(sgp)) {
93-
bpf_probe_read_kernel(&len, sizeof(len), &sgp->length);
86+
len = BPF_CORE_READ(sgp, length);
9487
length2 += len;
9588
n++;
9689
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2019 Facebook */
3-
#include <stdbool.h>
4-
#include <stddef.h>
5-
#include <linux/bpf.h>
6-
#include <linux/ptrace.h>
3+
#include "vmlinux.h"
74
#include <bpf/bpf_helpers.h>
85
#include <bpf/bpf_tracing.h>
96

0 commit comments

Comments
 (0)