aboutsummaryrefslogtreecommitdiffstats
path: root/samples/bpf
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2016-05-05 03:57:27 -0400
committerIngo Molnar <mingo@kernel.org>2016-05-05 03:57:27 -0400
commite8c8ce54807b19e90ac84e609b13f7d4e337eab1 (patch)
treeae7d65ae17d55aee197b605ce1a193fe594af614 /samples/bpf
parent5db4298133d99b3dfc60d6899ac9df169769c899 (diff)
parent04974df8049fc4240d22759a91e035082ccd18b4 (diff)
Merge tag 'v4.6-rc6' into locking/core, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'samples/bpf')
-rw-r--r--samples/bpf/Makefile12
-rw-r--r--samples/bpf/bpf_helpers.h26
-rw-r--r--samples/bpf/map_perf_test_user.c1
-rw-r--r--samples/bpf/spintest_kern.c2
-rw-r--r--samples/bpf/tracex2_kern.c4
-rw-r--r--samples/bpf/tracex4_kern.c2
6 files changed, 34 insertions, 13 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 502c9fc8db85..b820cc96a3bc 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -76,16 +76,10 @@ HOSTLOADLIBES_offwaketime += -lelf
76HOSTLOADLIBES_spintest += -lelf 76HOSTLOADLIBES_spintest += -lelf
77HOSTLOADLIBES_map_perf_test += -lelf -lrt 77HOSTLOADLIBES_map_perf_test += -lelf -lrt
78 78
79# point this to your LLVM backend with bpf support 79# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
80LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc 80# But, there is no easy way to fix it, so just exclude it since it is
81
82# asm/sysreg.h inline assmbly used by it is incompatible with llvm.
83# But, ehere is not easy way to fix it, so just exclude it since it is
84# useless for BPF samples. 81# useless for BPF samples.
85$(obj)/%.o: $(src)/%.c 82$(obj)/%.o: $(src)/%.c
86 clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \ 83 clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
87 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ 84 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
88 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ 85 -O2 -emit-llvm -c $< -o -| llc -march=bpf -filetype=obj -o $@
89 clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
90 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
91 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=asm -o $@.s
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index 9363500131a7..7904a2a493de 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -82,6 +82,7 @@ static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flag
82#define PT_REGS_FP(x) ((x)->bp) 82#define PT_REGS_FP(x) ((x)->bp)
83#define PT_REGS_RC(x) ((x)->ax) 83#define PT_REGS_RC(x) ((x)->ax)
84#define PT_REGS_SP(x) ((x)->sp) 84#define PT_REGS_SP(x) ((x)->sp)
85#define PT_REGS_IP(x) ((x)->ip)
85 86
86#elif defined(__s390x__) 87#elif defined(__s390x__)
87 88
@@ -94,6 +95,7 @@ static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flag
94#define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */ 95#define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */
95#define PT_REGS_RC(x) ((x)->gprs[2]) 96#define PT_REGS_RC(x) ((x)->gprs[2])
96#define PT_REGS_SP(x) ((x)->gprs[15]) 97#define PT_REGS_SP(x) ((x)->gprs[15])
98#define PT_REGS_IP(x) ((x)->ip)
97 99
98#elif defined(__aarch64__) 100#elif defined(__aarch64__)
99 101
@@ -106,6 +108,30 @@ static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flag
106#define PT_REGS_FP(x) ((x)->regs[29]) /* Works only with CONFIG_FRAME_POINTER */ 108#define PT_REGS_FP(x) ((x)->regs[29]) /* Works only with CONFIG_FRAME_POINTER */
107#define PT_REGS_RC(x) ((x)->regs[0]) 109#define PT_REGS_RC(x) ((x)->regs[0])
108#define PT_REGS_SP(x) ((x)->sp) 110#define PT_REGS_SP(x) ((x)->sp)
111#define PT_REGS_IP(x) ((x)->pc)
112
113#elif defined(__powerpc__)
114
115#define PT_REGS_PARM1(x) ((x)->gpr[3])
116#define PT_REGS_PARM2(x) ((x)->gpr[4])
117#define PT_REGS_PARM3(x) ((x)->gpr[5])
118#define PT_REGS_PARM4(x) ((x)->gpr[6])
119#define PT_REGS_PARM5(x) ((x)->gpr[7])
120#define PT_REGS_RC(x) ((x)->gpr[3])
121#define PT_REGS_SP(x) ((x)->sp)
122#define PT_REGS_IP(x) ((x)->nip)
109 123
110#endif 124#endif
125
126#ifdef __powerpc__
127#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ (ip) = (ctx)->link; })
128#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
129#else
130#define BPF_KPROBE_READ_RET_IP(ip, ctx) ({ \
131 bpf_probe_read(&(ip), sizeof(ip), (void *)PT_REGS_RET(ctx)); })
132#define BPF_KRETPROBE_READ_RET_IP(ip, ctx) ({ \
133 bpf_probe_read(&(ip), sizeof(ip), \
134 (void *)(PT_REGS_FP(ctx) + sizeof(ip))); })
135#endif
136
111#endif 137#endif
diff --git a/samples/bpf/map_perf_test_user.c b/samples/bpf/map_perf_test_user.c
index 95af56ec5739..3147377e8fd3 100644
--- a/samples/bpf/map_perf_test_user.c
+++ b/samples/bpf/map_perf_test_user.c
@@ -17,6 +17,7 @@
17#include <linux/bpf.h> 17#include <linux/bpf.h>
18#include <string.h> 18#include <string.h>
19#include <time.h> 19#include <time.h>
20#include <sys/resource.h>
20#include "libbpf.h" 21#include "libbpf.h"
21#include "bpf_load.h" 22#include "bpf_load.h"
22 23
diff --git a/samples/bpf/spintest_kern.c b/samples/bpf/spintest_kern.c
index 4b27619d91a4..ce0167d09cdc 100644
--- a/samples/bpf/spintest_kern.c
+++ b/samples/bpf/spintest_kern.c
@@ -34,7 +34,7 @@ struct bpf_map_def SEC("maps") stackmap = {
34#define PROG(foo) \ 34#define PROG(foo) \
35int foo(struct pt_regs *ctx) \ 35int foo(struct pt_regs *ctx) \
36{ \ 36{ \
37 long v = ctx->ip, *val; \ 37 long v = PT_REGS_IP(ctx), *val; \
38\ 38\
39 val = bpf_map_lookup_elem(&my_map, &v); \ 39 val = bpf_map_lookup_elem(&my_map, &v); \
40 bpf_map_update_elem(&my_map, &v, &v, BPF_ANY); \ 40 bpf_map_update_elem(&my_map, &v, &v, BPF_ANY); \
diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c
index 09c1adc27d42..6d6eefd0d465 100644
--- a/samples/bpf/tracex2_kern.c
+++ b/samples/bpf/tracex2_kern.c
@@ -27,10 +27,10 @@ int bpf_prog2(struct pt_regs *ctx)
27 long init_val = 1; 27 long init_val = 1;
28 long *value; 28 long *value;
29 29
30 /* x64/s390x specific: read ip of kfree_skb caller. 30 /* read ip of kfree_skb caller.
31 * non-portable version of __builtin_return_address(0) 31 * non-portable version of __builtin_return_address(0)
32 */ 32 */
33 bpf_probe_read(&loc, sizeof(loc), (void *)PT_REGS_RET(ctx)); 33 BPF_KPROBE_READ_RET_IP(loc, ctx);
34 34
35 value = bpf_map_lookup_elem(&my_map, &loc); 35 value = bpf_map_lookup_elem(&my_map, &loc);
36 if (value) 36 if (value)
diff --git a/samples/bpf/tracex4_kern.c b/samples/bpf/tracex4_kern.c
index ac4671420cf1..6dd8e384de96 100644
--- a/samples/bpf/tracex4_kern.c
+++ b/samples/bpf/tracex4_kern.c
@@ -40,7 +40,7 @@ int bpf_prog2(struct pt_regs *ctx)
40 long ip = 0; 40 long ip = 0;
41 41
42 /* get ip address of kmem_cache_alloc_node() caller */ 42 /* get ip address of kmem_cache_alloc_node() caller */
43 bpf_probe_read(&ip, sizeof(ip), (void *)(PT_REGS_FP(ctx) + sizeof(ip))); 43 BPF_KRETPROBE_READ_RET_IP(ip, ctx);
44 44
45 struct pair v = { 45 struct pair v = {
46 .val = bpf_ktime_get_ns(), 46 .val = bpf_ktime_get_ns(),