Skip to content

Commit 2dbb4c0

Browse files
Michael Holzheudavem330
authored andcommitted
bpf/samples: Fix PT_REGS_IP on s390x and use it
The files "sampleip_kern.c" and "trace_event_kern.c" directly access "ctx->regs.ip" which is not available on s390x. Fix this and use the PT_REGS_IP() macro instead. Also fix the macro for s390x and use "psw.addr" from "pt_regs". Reported-by: Zvonko Kosic <zvonko.kosic@de.ibm.com> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7a99cd6 commit 2dbb4c0

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

samples/bpf/bpf_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) =
113113
#define PT_REGS_FP(x) ((x)->gprs[11]) /* Works only with CONFIG_FRAME_POINTER */
114114
#define PT_REGS_RC(x) ((x)->gprs[2])
115115
#define PT_REGS_SP(x) ((x)->gprs[15])
116-
#define PT_REGS_IP(x) ((x)->ip)
116+
#define PT_REGS_IP(x) ((x)->psw.addr)
117117

118118
#elif defined(__aarch64__)
119119

samples/bpf/sampleip_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int do_sample(struct bpf_perf_event_data *ctx)
2525
u64 ip;
2626
u32 *value, init_val = 1;
2727

28-
ip = ctx->regs.ip;
28+
ip = PT_REGS_IP(&ctx->regs);
2929
value = bpf_map_lookup_elem(&ip_map, &ip);
3030
if (value)
3131
*value += 1;

samples/bpf/trace_event_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
5050
key.userstack = bpf_get_stackid(ctx, &stackmap, USER_STACKID_FLAGS);
5151
if ((int)key.kernstack < 0 && (int)key.userstack < 0) {
5252
bpf_trace_printk(fmt, sizeof(fmt), cpu, ctx->sample_period,
53-
ctx->regs.ip);
53+
PT_REGS_IP(&ctx->regs));
5454
return 0;
5555
}
5656

0 commit comments

Comments
 (0)