Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf s390: add regs_query_register_offset()

The regs_query_register_offset() helper function converts
register name like "%r0" to an offset of a register in user_pt_regs
It is required by the BPF prologue generator.

The user_pt_regs structure was recently added to "asm/ptrace.h".
Hence, update tools/perf/check-headers.sh to keep the header file
in sync with kernel changes.

Suggested-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Reviewed-and-tested-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Hendrik Brueckner and committed by
Daniel Borkmann
a81c4213 618e165b

+31 -3
+1
tools/perf/arch/s390/Makefile
··· 2 2 PERF_HAVE_DWARF_REGS := 1 3 3 endif 4 4 HAVE_KVM_STAT_SUPPORT := 1 5 + PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
+29 -3
tools/perf/arch/s390/util/dwarf-regs.c
··· 2 2 /* 3 3 * Mapping of DWARF debug register numbers into register names. 4 4 * 5 - * Copyright IBM Corp. 2010 6 - * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, 5 + * Copyright IBM Corp. 2010, 2017 6 + * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, 7 + * Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 7 8 * 8 9 */ 9 10 11 + #include <errno.h> 10 12 #include <stddef.h> 11 - #include <dwarf-regs.h> 13 + #include <stdlib.h> 12 14 #include <linux/kernel.h> 15 + #include <asm/ptrace.h> 16 + #include <string.h> 17 + #include <dwarf-regs.h> 13 18 #include "dwarf-regs-table.h" 14 19 15 20 const char *get_arch_regstr(unsigned int n) 16 21 { 17 22 return (n >= ARRAY_SIZE(s390_dwarf_regs)) ? NULL : s390_dwarf_regs[n]; 23 + } 24 + 25 + /* 26 + * Convert the register name into an offset to struct pt_regs (kernel). 27 + * This is required by the BPF prologue generator. The BPF 28 + * program is called in the BPF overflow handler in the perf 29 + * core. 30 + */ 31 + int regs_query_register_offset(const char *name) 32 + { 33 + unsigned long gpr; 34 + 35 + if (!name || strncmp(name, "%r", 2)) 36 + return -EINVAL; 37 + 38 + errno = 0; 39 + gpr = strtoul(name + 2, NULL, 10); 40 + if (errno || gpr >= 16) 41 + return -EINVAL; 42 + 43 + return offsetof(user_pt_regs, gprs) + 8 * gpr; 18 44 }
+1
tools/perf/check-headers.sh
··· 30 30 arch/powerpc/include/uapi/asm/kvm.h 31 31 arch/s390/include/uapi/asm/kvm.h 32 32 arch/s390/include/uapi/asm/kvm_perf.h 33 + arch/s390/include/uapi/asm/ptrace.h 33 34 arch/s390/include/uapi/asm/sie.h 34 35 arch/arm/include/uapi/asm/kvm.h 35 36 arch/arm64/include/uapi/asm/kvm.h