diff options
| author | Michael Holzheu <holzheu@linux.vnet.ibm.com> | 2015-07-06 10:20:07 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-07-08 18:17:45 -0400 |
| commit | d912557b346099584bbbfa8d3c1e101c46e33b59 (patch) | |
| tree | 2752bc31be26f1c27776a0d52439efdd81f9eed7 /samples | |
| parent | 7baaa9092dedad5f670a7b1716b2ce9e1175ba02 (diff) | |
samples: bpf: enable trace samples for s390x
The trace bpf samples do not compile on s390x because they use x86
specific fields from the "pt_regs" structure.
Fix this and access the fields via new PT_REGS macros.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/bpf/bpf_helpers.h | 25 | ||||
| -rw-r--r-- | samples/bpf/tracex1_kern.c | 2 | ||||
| -rw-r--r-- | samples/bpf/tracex2_kern.c | 6 | ||||
| -rw-r--r-- | samples/bpf/tracex3_kern.c | 4 | ||||
| -rw-r--r-- | samples/bpf/tracex4_kern.c | 6 | ||||
| -rw-r--r-- | samples/bpf/tracex5_kern.c | 6 |
6 files changed, 37 insertions, 12 deletions
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h index bdf1c1607b80..c77c872fe8ee 100644 --- a/samples/bpf/bpf_helpers.h +++ b/samples/bpf/bpf_helpers.h | |||
| @@ -60,4 +60,29 @@ static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flag | |||
| 60 | static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) = | 60 | static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) = |
| 61 | (void *) BPF_FUNC_l4_csum_replace; | 61 | (void *) BPF_FUNC_l4_csum_replace; |
| 62 | 62 | ||
| 63 | #if defined(__x86_64__) | ||
| 64 | |||
| 65 | #define PT_REGS_PARM1(x) ((x)->di) | ||
| 66 | #define PT_REGS_PARM2(x) ((x)->si) | ||
| 67 | #define PT_REGS_PARM3(x) ((x)->dx) | ||
| 68 | #define PT_REGS_PARM4(x) ((x)->cx) | ||
| 69 | #define PT_REGS_PARM5(x) ((x)->r8) | ||
| 70 | #define PT_REGS_RET(x) ((x)->sp) | ||
| 71 | #define PT_REGS_FP(x) ((x)->bp) | ||
| 72 | #define PT_REGS_RC(x) ((x)->ax) | ||
| 73 | #define PT_REGS_SP(x) ((x)->sp) | ||
| 74 | |||
| 75 | #elif defined(__s390x__) | ||
| 76 | |||
| 77 | #define PT_REGS_PARM1(x) ((x)->gprs[2]) | ||
| 78 | #define PT_REGS_PARM2(x) ((x)->gprs[3]) | ||
| 79 | #define PT_REGS_PARM3(x) ((x)->gprs[4]) | ||
| 80 | #define PT_REGS_PARM4(x) ((x)->gprs[5]) | ||
| 81 | #define PT_REGS_PARM5(x) ((x)->gprs[6]) | ||
| 82 | #define PT_REGS_RET(x) ((x)->gprs[14]) | ||
| 83 | #define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */ | ||
| 84 | #define PT_REGS_RC(x) ((x)->gprs[2]) | ||
| 85 | #define PT_REGS_SP(x) ((x)->gprs[15]) | ||
| 86 | |||
| 87 | #endif | ||
| 63 | #endif | 88 | #endif |
diff --git a/samples/bpf/tracex1_kern.c b/samples/bpf/tracex1_kern.c index 31620463701a..3f450a8fa1f3 100644 --- a/samples/bpf/tracex1_kern.c +++ b/samples/bpf/tracex1_kern.c | |||
| @@ -29,7 +29,7 @@ int bpf_prog1(struct pt_regs *ctx) | |||
| 29 | int len; | 29 | int len; |
| 30 | 30 | ||
| 31 | /* non-portable! works for the given kernel only */ | 31 | /* non-portable! works for the given kernel only */ |
| 32 | skb = (struct sk_buff *) ctx->di; | 32 | skb = (struct sk_buff *) PT_REGS_PARM1(ctx); |
| 33 | 33 | ||
| 34 | dev = _(skb->dev); | 34 | dev = _(skb->dev); |
| 35 | 35 | ||
diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c index dc50f4f2943f..b32367cfbff4 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 specific: read ip of kfree_skb caller. | 30 | /* x64/s390x specific: 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 *)ctx->sp); | 33 | bpf_probe_read(&loc, sizeof(loc), (void *)PT_REGS_RET(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) |
| @@ -79,7 +79,7 @@ struct bpf_map_def SEC("maps") my_hist_map = { | |||
| 79 | SEC("kprobe/sys_write") | 79 | SEC("kprobe/sys_write") |
| 80 | int bpf_prog3(struct pt_regs *ctx) | 80 | int bpf_prog3(struct pt_regs *ctx) |
| 81 | { | 81 | { |
| 82 | long write_size = ctx->dx; /* arg3 */ | 82 | long write_size = PT_REGS_PARM3(ctx); |
| 83 | long init_val = 1; | 83 | long init_val = 1; |
| 84 | long *value; | 84 | long *value; |
| 85 | struct hist_key key = {}; | 85 | struct hist_key key = {}; |
diff --git a/samples/bpf/tracex3_kern.c b/samples/bpf/tracex3_kern.c index 255ff2792366..bf337fbb0947 100644 --- a/samples/bpf/tracex3_kern.c +++ b/samples/bpf/tracex3_kern.c | |||
| @@ -23,7 +23,7 @@ struct bpf_map_def SEC("maps") my_map = { | |||
| 23 | SEC("kprobe/blk_mq_start_request") | 23 | SEC("kprobe/blk_mq_start_request") |
| 24 | int bpf_prog1(struct pt_regs *ctx) | 24 | int bpf_prog1(struct pt_regs *ctx) |
| 25 | { | 25 | { |
| 26 | long rq = ctx->di; | 26 | long rq = PT_REGS_PARM1(ctx); |
| 27 | u64 val = bpf_ktime_get_ns(); | 27 | u64 val = bpf_ktime_get_ns(); |
| 28 | 28 | ||
| 29 | bpf_map_update_elem(&my_map, &rq, &val, BPF_ANY); | 29 | bpf_map_update_elem(&my_map, &rq, &val, BPF_ANY); |
| @@ -51,7 +51,7 @@ struct bpf_map_def SEC("maps") lat_map = { | |||
| 51 | SEC("kprobe/blk_update_request") | 51 | SEC("kprobe/blk_update_request") |
| 52 | int bpf_prog2(struct pt_regs *ctx) | 52 | int bpf_prog2(struct pt_regs *ctx) |
| 53 | { | 53 | { |
| 54 | long rq = ctx->di; | 54 | long rq = PT_REGS_PARM1(ctx); |
| 55 | u64 *value, l, base; | 55 | u64 *value, l, base; |
| 56 | u32 index; | 56 | u32 index; |
| 57 | 57 | ||
diff --git a/samples/bpf/tracex4_kern.c b/samples/bpf/tracex4_kern.c index 126b80512228..ac4671420cf1 100644 --- a/samples/bpf/tracex4_kern.c +++ b/samples/bpf/tracex4_kern.c | |||
| @@ -27,7 +27,7 @@ struct bpf_map_def SEC("maps") my_map = { | |||
| 27 | SEC("kprobe/kmem_cache_free") | 27 | SEC("kprobe/kmem_cache_free") |
| 28 | int bpf_prog1(struct pt_regs *ctx) | 28 | int bpf_prog1(struct pt_regs *ctx) |
| 29 | { | 29 | { |
| 30 | long ptr = ctx->si; | 30 | long ptr = PT_REGS_PARM2(ctx); |
| 31 | 31 | ||
| 32 | bpf_map_delete_elem(&my_map, &ptr); | 32 | bpf_map_delete_elem(&my_map, &ptr); |
| 33 | return 0; | 33 | return 0; |
| @@ -36,11 +36,11 @@ int bpf_prog1(struct pt_regs *ctx) | |||
| 36 | SEC("kretprobe/kmem_cache_alloc_node") | 36 | SEC("kretprobe/kmem_cache_alloc_node") |
| 37 | int bpf_prog2(struct pt_regs *ctx) | 37 | int bpf_prog2(struct pt_regs *ctx) |
| 38 | { | 38 | { |
| 39 | long ptr = ctx->ax; | 39 | long ptr = PT_REGS_RC(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 *)(ctx->bp + sizeof(ip))); | 43 | bpf_probe_read(&ip, sizeof(ip), (void *)(PT_REGS_FP(ctx) + sizeof(ip))); |
| 44 | 44 | ||
| 45 | struct pair v = { | 45 | struct pair v = { |
| 46 | .val = bpf_ktime_get_ns(), | 46 | .val = bpf_ktime_get_ns(), |
diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c index b71fe07a7a7a..b3f4295bf288 100644 --- a/samples/bpf/tracex5_kern.c +++ b/samples/bpf/tracex5_kern.c | |||
| @@ -24,7 +24,7 @@ int bpf_prog1(struct pt_regs *ctx) | |||
| 24 | { | 24 | { |
| 25 | struct seccomp_data sd = {}; | 25 | struct seccomp_data sd = {}; |
| 26 | 26 | ||
| 27 | bpf_probe_read(&sd, sizeof(sd), (void *)ctx->di); | 27 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); |
| 28 | 28 | ||
| 29 | /* dispatch into next BPF program depending on syscall number */ | 29 | /* dispatch into next BPF program depending on syscall number */ |
| 30 | bpf_tail_call(ctx, &progs, sd.nr); | 30 | bpf_tail_call(ctx, &progs, sd.nr); |
| @@ -42,7 +42,7 @@ PROG(__NR_write)(struct pt_regs *ctx) | |||
| 42 | { | 42 | { |
| 43 | struct seccomp_data sd = {}; | 43 | struct seccomp_data sd = {}; |
| 44 | 44 | ||
| 45 | bpf_probe_read(&sd, sizeof(sd), (void *)ctx->di); | 45 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); |
| 46 | if (sd.args[2] == 512) { | 46 | if (sd.args[2] == 512) { |
| 47 | char fmt[] = "write(fd=%d, buf=%p, size=%d)\n"; | 47 | char fmt[] = "write(fd=%d, buf=%p, size=%d)\n"; |
| 48 | bpf_trace_printk(fmt, sizeof(fmt), | 48 | bpf_trace_printk(fmt, sizeof(fmt), |
| @@ -55,7 +55,7 @@ PROG(__NR_read)(struct pt_regs *ctx) | |||
| 55 | { | 55 | { |
| 56 | struct seccomp_data sd = {}; | 56 | struct seccomp_data sd = {}; |
| 57 | 57 | ||
| 58 | bpf_probe_read(&sd, sizeof(sd), (void *)ctx->di); | 58 | bpf_probe_read(&sd, sizeof(sd), (void *)PT_REGS_PARM1(ctx)); |
| 59 | if (sd.args[2] > 128 && sd.args[2] <= 1024) { | 59 | if (sd.args[2] > 128 && sd.args[2] <= 1024) { |
| 60 | char fmt[] = "read(fd=%d, buf=%p, size=%d)\n"; | 60 | char fmt[] = "read(fd=%d, buf=%p, size=%d)\n"; |
| 61 | bpf_trace_printk(fmt, sizeof(fmt), | 61 | bpf_trace_printk(fmt, sizeof(fmt), |
