Skip to content

Commit c33eff6

Browse files
heicarstMartin Schwidefsky
authored andcommitted
s390/perf: add perf_regs support and user stack dump
Add s390 support to dump user stack to user space for DWARF stack unwinding. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Reviewed-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com> Reviewed-and-tested-by: Thomas Richter <tmricht@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 9232c3c commit c33eff6

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

arch/s390/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ config S390
159159
select HAVE_KRETPROBES
160160
select HAVE_KVM
161161
select HAVE_LIVEPATCH
162+
select HAVE_PERF_REGS
163+
select HAVE_PERF_USER_STACK_DUMP
162164
select HAVE_MEMBLOCK
163165
select HAVE_MEMBLOCK_NODE_MAP
164166
select HAVE_MEMBLOCK_PHYS_MAP
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef _ASM_S390_PERF_REGS_H
2+
#define _ASM_S390_PERF_REGS_H
3+
4+
enum perf_event_s390_regs {
5+
PERF_REG_S390_R0,
6+
PERF_REG_S390_R1,
7+
PERF_REG_S390_R2,
8+
PERF_REG_S390_R3,
9+
PERF_REG_S390_R4,
10+
PERF_REG_S390_R5,
11+
PERF_REG_S390_R6,
12+
PERF_REG_S390_R7,
13+
PERF_REG_S390_R8,
14+
PERF_REG_S390_R9,
15+
PERF_REG_S390_R10,
16+
PERF_REG_S390_R11,
17+
PERF_REG_S390_R12,
18+
PERF_REG_S390_R13,
19+
PERF_REG_S390_R14,
20+
PERF_REG_S390_R15,
21+
PERF_REG_S390_MASK,
22+
PERF_REG_S390_PC,
23+
24+
PERF_REG_S390_MAX
25+
};
26+
27+
#endif /* _ASM_S390_PERF_REGS_H */

arch/s390/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
7979
obj-$(CONFIG_UPROBES) += uprobes.o
8080

8181
obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_cpum_cf.o perf_cpum_sf.o
82-
obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o
82+
obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o
8383

8484
obj-$(CONFIG_TRACEPOINTS) += trace.o
8585

arch/s390/kernel/perf_regs.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <linux/perf_event.h>
2+
#include <linux/perf_regs.h>
3+
#include <linux/kernel.h>
4+
#include <linux/errno.h>
5+
#include <linux/bug.h>
6+
#include <asm/ptrace.h>
7+
8+
u64 perf_reg_value(struct pt_regs *regs, int idx)
9+
{
10+
if (WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX))
11+
return 0;
12+
13+
if (idx == PERF_REG_S390_MASK)
14+
return regs->psw.mask;
15+
if (idx == PERF_REG_S390_PC)
16+
return regs->psw.addr;
17+
18+
return regs->gprs[idx];
19+
}
20+
21+
#define REG_RESERVED (~((1UL << PERF_REG_S390_MAX) - 1))
22+
23+
int perf_reg_validate(u64 mask)
24+
{
25+
if (!mask || mask & REG_RESERVED)
26+
return -EINVAL;
27+
28+
return 0;
29+
}
30+
31+
u64 perf_reg_abi(struct task_struct *task)
32+
{
33+
if (test_tsk_thread_flag(task, TIF_31BIT))
34+
return PERF_SAMPLE_REGS_ABI_32;
35+
36+
return PERF_SAMPLE_REGS_ABI_64;
37+
}
38+
39+
void perf_get_regs_user(struct perf_regs *regs_user,
40+
struct pt_regs *regs,
41+
struct pt_regs *regs_user_copy)
42+
{
43+
/*
44+
* Use the regs from the first interruption and let
45+
* perf_sample_regs_intr() handle interrupts (regs == get_irq_regs()).
46+
*/
47+
regs_user->regs = task_pt_regs(current);
48+
regs_user->abi = perf_reg_abi(current);
49+
}

0 commit comments

Comments
 (0)