diff options
author | Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> | 2016-04-04 13:01:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-04-06 16:01:29 -0400 |
commit | 138d6153a139c318739f20e61309e5778427a73c (patch) | |
tree | 0faa155a8266a068779ecc3c02e8c8098ead3275 | |
parent | 128d1514be3583c3cfd56d66d7cdfba413b867ae (diff) |
samples/bpf: Enable powerpc support
Add the necessary definitions for building bpf samples on ppc.
Since ppc doesn't store function return address on the stack, modify how
PT_REGS_RET() and PT_REGS_FP() work.
Also, introduce PT_REGS_IP() to access the instruction pointer.
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David S. Miller <davem@davemloft.net>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | samples/bpf/bpf_helpers.h | 26 | ||||
-rw-r--r-- | samples/bpf/spintest_kern.c | 2 | ||||
-rw-r--r-- | samples/bpf/tracex2_kern.c | 4 | ||||
-rw-r--r-- | samples/bpf/tracex4_kern.c | 2 |
4 files changed, 30 insertions, 4 deletions
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/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) \ |
35 | int foo(struct pt_regs *ctx) \ | 35 | int 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(), |