Reduce ifdef mess in ptrace
Subsystems (2)
cover Reduce ifdef mess in ptrace
The purpose of this series is to reduce the amount of #ifdefs in ptrace.c
This is a first try. Most of it is done, there are still some #ifdefs that could go away.
Please comment and tell whether it is worth continuing in that direction.
Christophe Leroy (13):
powerpc: move ptrace into a subdirectory. powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64 powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET powerpc/ptrace: split out VSX related functions. powerpc/ptrace: split out ALTIVEC related functions. powerpc/ptrace: split out SPE related functions. powerpc/ptrace: split out TRANSACTIONAL_MEM related functions. powerpc/ptrace: move register viewing functions out of ptrace.c powerpc/ptrace: split out ADV_DEBUG_REGS related functions. powerpc/ptrace: create ptrace_get_debugreg() powerpc/ptrace: create ppc_gethwdinfo() powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c powerpc/hw_breakpoint: move instruction stepping out of
hw_breakpoint_handler()
arch/powerpc/include/asm/ptrace.h | 9 +-
arch/powerpc/include/uapi/asm/ptrace.h | 12 +-
arch/powerpc/kernel/Makefile | 7 +-
arch/powerpc/kernel/hw_breakpoint.c | 76 +-
arch/powerpc/kernel/ptrace.c | 3402 ---------------------------
arch/powerpc/kernel/ptrace/Makefile | 20 +
arch/powerpc/kernel/ptrace/ptrace-adv.c | 511 ++++
arch/powerpc/kernel/ptrace/ptrace-altivec.c | 151 ++
arch/powerpc/kernel/ptrace/ptrace-decl.h | 150 ++
arch/powerpc/kernel/ptrace/ptrace-noadv.c | 291 +++
arch/powerpc/kernel/ptrace/ptrace-novsx.c | 83 +
arch/powerpc/kernel/ptrace/ptrace-spe.c | 94 +
arch/powerpc/kernel/ptrace/ptrace-tm.c | 877 +++++++
arch/powerpc/kernel/ptrace/ptrace-view.c | 966 ++++++++
arch/powerpc/kernel/ptrace/ptrace-vsx.c | 177 ++
arch/powerpc/kernel/ptrace/ptrace.c | 430 ++++
arch/powerpc/kernel/{ => ptrace}/ptrace32.c | 0
17 files changed, 3810 insertions(+), 3446 deletions(-)
delete mode 100644 arch/powerpc/kernel/ptrace.c
create mode 100644 arch/powerpc/kernel/ptrace/Makefile
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-adv.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-altivec.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-decl.h
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-noadv.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-novsx.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-spe.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-tm.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-view.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace-vsx.c
create mode 100644 arch/powerpc/kernel/ptrace/ptrace.c
rename arch/powerpc/kernel/{ => ptrace}/ptrace32.c (100%)Signature · 1 line
2.13.3
RFC PATCH 1/13 powerpc: move ptrace into a subdirectory.
In order to allow splitting of ptrace depending on the different CONFIG_ options, create a subdirectory dedicated to ptrace and move ptrace.c and ptrace32.c into it.
---
arch/powerpc/kernel/Makefile | 7 +++----
arch/powerpc/kernel/ptrace/Makefile | 9 +++++++++
arch/powerpc/kernel/{ => ptrace}/ptrace.c | 0
arch/powerpc/kernel/{ => ptrace}/ptrace32.c | 0
4 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 arch/powerpc/kernel/ptrace/Makefile
rename arch/powerpc/kernel/{ => ptrace}/ptrace.c (100%)
rename arch/powerpc/kernel/{ => ptrace}/ptrace32.c (100%)arch/powerpc/kernel/Makefile +3 -4
@@ -3,8 +3,6 @@ # Makefile for the linux kernel. # -CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' - # Disable clang warning for using setjmp without setjmp.h header CFLAGS_crash.o += $(call cc-disable-warning, builtin-requires-header)
@@ -43,15 +41,16 @@ CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING endif -obj-y := cputable.o ptrace.o syscalls.o \ +obj-y := cputable.o syscalls.o \ irq.o align.o signal_32.o pmc.o vdso.o \ process.o systbl.o idle.o \ signal.o sysfs.o cacheinfo.o time.o \ prom.o traps.o setup-common.o \ udbg.o misc.o io.o misc_$(BITS).o \ of_platform.o prom_parse.o +obj-y += ptrace/ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ - signal_64.o ptrace32.o \ + signal_64.o \ paca.o nvram_64.o firmware.o obj-$(CONFIG_VDSO32) += vdso32/ obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o
arch/powerpc/kernel/ptrace/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the linux kernel. +# + +CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' + +obj-y += ptrace.o +obj-$(CONFIG_PPC64) += ptrace32.o
arch/powerpc/kernel/ptrace/ptrace.c renamed from arch/powerpc/kernel/ptrace.c +0 -0
arch/powerpc/kernel/ptrace/ptrace32.c renamed from arch/powerpc/kernel/ptrace32.c +0 -0
Signature · 1 line
2.13.3
RFC PATCH 2/13 powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64
In reply to Christophe LeroyDrop a bunch of #ifdefs CONFIG_PPC64 that are not vital.
--- arch/powerpc/include/asm/ptrace.h | 9 ++++----- arch/powerpc/include/uapi/asm/ptrace.h | 12 ++++-------- arch/powerpc/kernel/ptrace/ptrace.c | 24 +++--------------------- 3 files changed, 11 insertions(+), 34 deletions(-)
arch/powerpc/include/asm/ptrace.h +4 -5
@@ -36,11 +36,10 @@ struct pt_regsunsigned long link;unsigned long xer;unsigned long ccr; -#ifdef CONFIG_PPC64 -unsigned long softe; -#else -unsigned long mq; -#endif +union { +unsigned long softe; +unsigned long mq; + };unsigned long trap;unsigned long dar;unsigned long dsisr;
arch/powerpc/include/uapi/asm/ptrace.h +4 -8
@@ -43,12 +43,11 @@ struct pt_regsunsigned long link;unsigned long xer;unsigned long ccr; -#ifdef __powerpc64__ -unsigned long softe;/* Soft enabled/disabled */ -#else -unsigned long mq;/* 601 only (not used at present) */ +union { +unsigned long softe;/* Soft enabled/disabled */ +unsigned long mq;/* 601 only (not used at present) */ /* Used on APUS to hold IPL value. */ -#endif + };unsigned long trap;/* Reason for being here */ /* N.B. for critical exceptions on 4xx, the dar and dsisr fields are overloaded to hold srr0 and srr1. */
@@ -105,11 +104,8 @@ struct pt_regs#define PT_LNK 36#define PT_XER 37#define PT_CCR 38 -#ifndef __powerpc64__#define PT_MQ 39 -#else #define PT_SOFTE 39 -#endif #define PT_TRAP 40#define PT_DAR 41#define PT_DSISR 42
arch/powerpc/kernel/ptrace/ptrace.c +3 -21
@@ -113,11 +113,8 @@ static const struct pt_regs_offset regoffset_table[] = {REG_OFFSET_NAME (link),REG_OFFSET_NAME (xer),REG_OFFSET_NAME (ccr), -#ifdef CONFIG_PPC64REG_OFFSET_NAME (softe), -#elseREG_OFFSET_NAME (mq), -#endifREG_OFFSET_NAME (trap),REG_OFFSET_NAME (dar), REG_OFFSET_NAME(dsisr),
@@ -289,17 +286,15 @@ int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)if (regno ==PT_DSCR )return get_user_dscr (task, data); -#ifdef CONFIG_PPC64 /* * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask is * no more used as a flag, lets force usr to alway see the softe value as 1 * which means interrupts are not soft disabled. */ -if (regno ==PT_SOFTE ) { +if (IS_ENABLED (CONFIG_PPC64 ) && regno ==PT_SOFTE ) { *data =1 ;return 0 ; } -#endif regs_max =sizeof (struct user_pt_regs ) /sizeof (unsigned long );if (regno < regs_max) {
@@ -2013,7 +2008,6 @@ static const struct user_regset_view user_ppc_native_view = { .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) }; -#ifdef CONFIG_PPC64 #include <linux/compat.h> static int gpr32_get_common(struct task_struct *target,
@@ -2287,14 +2281,11 @@ static const struct user_regset_view user_ppc_compat_view = { .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) }; -#endif /* CONFIG_PPC64 */ const struct user_regset_view *task_user_regset_view (struct task_struct *task) { -#ifdef CONFIG_PPC64 -if (test_tsk_thread_flag (task,TIF_32BIT )) +if (IS_ENABLED (CONFIG_PPC64 ) &&test_tsk_thread_flag (task,TIF_32BIT ))return &user_ppc_compat_view; -#endif return &user_ppc_native_view; }
@@ -3081,11 +3072,7 @@ long arch_ptrace(struct task_struct *child, long request,else dbginfo.num_data_bps =0 ; dbginfo.num_condition_regs =0 ; -#ifdef CONFIG_PPC64 - dbginfo.data_bp_alignment =8 ; -#else - dbginfo.data_bp_alignment =4 ; -#endif + dbginfo.data_bp_alignment =sizeof (long ); dbginfo.sizeof_condition =0 ;#ifdef CONFIG_HAVE_HW_BREAKPOINT dbginfo.features =PPC_DEBUG_FEATURE_DATA_BP_RANGE ;
@@ -3322,12 +3309,10 @@ long do_syscall_trace_enter(struct pt_regs *regs)if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))trace_sys_enter (regs, regs->gpr[0 ]); -#ifdef CONFIG_PPC64 if (!is_32bit_task ())audit_syscall_entry (regs->gpr[0 ], regs->gpr[3 ], regs->gpr[4 ], regs->gpr[5 ], regs->gpr[6 ]);else -#endif audit_syscall_entry(regs->gpr[0], regs->gpr[3] & 0xffffffff, regs->gpr[4] & 0xffffffff,
@@ -3382,13 +3367,10 @@ void __init pt_regs_check(void) offsetof(struct user_pt_regs, xer));BUILD_BUG_ON (offsetof(struct pt_regs , ccr) != offsetof(struct user_pt_regs , ccr)); -#ifdef __powerpc64__BUILD_BUG_ON (offsetof(struct pt_regs , softe) != offsetof(struct user_pt_regs , softe)); -#else BUILD_BUG_ON (offsetof(struct pt_regs , mq) != offsetof(struct user_pt_regs , mq)); -#endif BUILD_BUG_ON (offsetof(struct pt_regs , trap) != offsetof(struct user_pt_regs , trap)); BUILD_BUG_ON(offsetof(struct pt_regs, dar) !=
Signature · 1 line
2.13.3
RFC PATCH 3/13 powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET
In reply to Christophe LeroyPARAMETER_SAVE_AREA_OFFSET is not used, drop it.
--- arch/powerpc/kernel/ptrace/ptrace.c | 10 ---------- 1 file changed, 10 deletions(-)
arch/powerpc/kernel/ptrace/ptrace.c +0 -10
@@ -48,16 +48,6 @@#define CREATE_TRACE_POINTS #include <trace/events/syscalls.h> -/* -* The parameter save area on the stack is used to store arguments being passed -* to callee function and is located at fixed offset from stack pointer. -*/ -#ifdef CONFIG_PPC32 -#define PARAMETER_SAVE_AREA_OFFSET 24/* bytes */ -#else /* CONFIG_PPC32 */ -#define PARAMETER_SAVE_AREA_OFFSET 48/* bytes */ -#endif -struct pt_regs_offset {const char *name;int offset;
Signature · 1 line
2.13.3
RFC PATCH 4/13 powerpc/ptrace: split out VSX related functions.
In reply to Christophe LeroyMove CONFIG_VSX functions out of ptrace.c, intoptrace-vsx.c and ptrace-novsx.c
--- arch/powerpc/kernel/ptrace/Makefile | 4 + arch/powerpc/kernel/ptrace/ptrace-decl.h | 18 +++ arch/powerpc/kernel/ptrace/ptrace-novsx.c | 83 ++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-vsx.c | 177 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 171 +---------------------------- 5 files changed, 284 insertions(+), 169 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-decl.h create mode 100644 arch/powerpc/kernel/ptrace/ptrace-novsx.c create mode 100644 arch/powerpc/kernel/ptrace/ptrace-vsx.c
arch/powerpc/kernel/ptrace/Makefile +4 -0
@@ -7,3 +7,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' obj-y += ptrace.o obj-$(CONFIG_PPC64) += ptrace32.o +obj-$(CONFIG_VSX) += ptrace-vsx.o +ifneq ($(CONFIG_VSX),y) +obj-y += ptrace-novsx.o +endif
arch/powerpc/kernel/ptrace/ptrace-decl.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* ptrace-(no)vsx */ + +int fpr_get (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf); +int fpr_set (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf); + +/* ptrace-vsx */ + +int vsr_active (struct task_struct *target,const struct user_regset *regset); +int vsr_get (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf); +int vsr_set (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf);
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +83 -0
83 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-vsx.c new file +177 -0
177 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +2 -169
189 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 5/13 powerpc/ptrace: split out ALTIVEC related functions.
In reply to Christophe LeroyMove CONFIG_ALTIVEC functions out of ptrace.c, into ptrace-altivec.c
--- arch/powerpc/kernel/ptrace/Makefile | 1 + arch/powerpc/kernel/ptrace/ptrace-altivec.c | 151 ++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-decl.h | 9 ++ arch/powerpc/kernel/ptrace/ptrace.c | 124 ----------------------- 4 files changed, 161 insertions(+), 124 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-altivec.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_VSX) += ptrace-vsx.o ifneq ($(CONFIG_VSX),y) obj-y += ptrace-novsx.o endif +obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o
arch/powerpc/kernel/ptrace/ptrace-altivec.c new file +151 -0
151 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-decl.h +9 -0
@@ -16,3 +16,12 @@ int vsr_get(struct task_struct *target, const struct user_regset *regset,int vsr_set (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,const void *kbuf,const void __user *ubuf); + +/* ptrace-altivec */ + +int vr_active (struct task_struct *target,const struct user_regset *regset); +int vr_get (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf); +int vr_set (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf);
arch/powerpc/kernel/ptrace/ptrace.c +0 -124
130 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 6/13 powerpc/ptrace: split out SPE related functions.
In reply to Christophe LeroyMove CONFIG_SPE functions out of ptrace.c, intoptrace-spe.c
--- arch/powerpc/kernel/ptrace/Makefile | 1 + arch/powerpc/kernel/ptrace/ptrace-decl.h | 9 +++ arch/powerpc/kernel/ptrace/ptrace-spe.c | 94 ++++++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 66 ---------------------- 4 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-spe.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
@@ -12,3 +12,4 @@ ifneq ($(CONFIG_VSX),y) obj-y += ptrace-novsx.o endif obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o +obj-$(CONFIG_SPE) += ptrace-spe.o
arch/powerpc/kernel/ptrace/ptrace-decl.h +9 -0
@@ -25,3 +25,12 @@ int vr_get(struct task_struct *target, const struct user_regset *regset,int vr_set (struct task_struct *target,const struct user_regset *regset,unsigned int pos,unsigned int count,const void *kbuf,const void __user *ubuf); + +/* ptrace-spe */ + +int evr_active (struct task_struct *target,const struct user_regset *regset); +int evr_get (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf); +int evr_set (struct task_struct *target,const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf);
arch/powerpc/kernel/ptrace/ptrace-spe.c new file +94 -0
94 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +0 -66
72 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 7/13 powerpc/ptrace: split out TRANSACTIONAL_MEM related functions.
In reply to Christophe LeroyMove TRANSACTIONAL_MEM functions out of ptrace.c, into ptrace-tm.c
--- arch/powerpc/kernel/ptrace/Makefile | 1 + arch/powerpc/kernel/ptrace/ptrace-decl.h | 63 +++ arch/powerpc/kernel/ptrace/ptrace-tm.c | 877 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 900 ------------------------------- 4 files changed, 941 insertions(+), 900 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-tm.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-y += ptrace-novsx.o endif obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o obj-$(CONFIG_SPE) += ptrace-spe.o +obj-$(CONFIG_PPC_TRANSACTIONAL_MEM) += ptrace-tm.o
arch/powerpc/kernel/ptrace/ptrace-decl.h +63 -0
71 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-tm.c new file +877 -0
877 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +0 -900
930 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 8/13 powerpc/ptrace: move register viewing functions out of ptrace.c
In reply to Christophe LeroyCreate a dedicated ptrace-view.c file.
--- arch/powerpc/kernel/ptrace/Makefile | 4 +- arch/powerpc/kernel/ptrace/ptrace-decl.h | 42 ++ arch/powerpc/kernel/ptrace/ptrace-view.c | 966 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 973 ------------------------------- 4 files changed, 1010 insertions(+), 975 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-view.c
arch/powerpc/kernel/ptrace/Makefile +2 -2
@@ -3,9 +3,9 @@ # Makefile for the linux kernel. # -CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' +CFLAGS_ptrace-view.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' -obj-y += ptrace.o +obj-y += ptrace.o ptrace-view.o obj-$(CONFIG_PPC64) += ptrace32.o obj-$(CONFIG_VSX) += ptrace-vsx.o ifneq ($(CONFIG_VSX),y)
arch/powerpc/kernel/ptrace/ptrace-decl.h +42 -0
51 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-view.c new file +966 -0
966 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +0 -973
979 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 9/13 powerpc/ptrace: split out ADV_DEBUG_REGS related functions.
In reply to Christophe LeroyMove ADV_DEBUG_REGS functions out of ptrace.c, into ptrace-adv.c and ptrace-noadv.c
--- arch/powerpc/kernel/ptrace/Makefile | 4 + arch/powerpc/kernel/ptrace/ptrace-adv.c | 487 ++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-decl.h | 6 + arch/powerpc/kernel/ptrace/ptrace-noadv.c | 258 ++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 652 ------------------------------ 5 files changed, 755 insertions(+), 652 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-adv.c create mode 100644 arch/powerpc/kernel/ptrace/ptrace-noadv.c
arch/powerpc/kernel/ptrace/Makefile +4 -0
@@ -14,3 +14,7 @@ endif obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o obj-$(CONFIG_SPE) += ptrace-spe.o obj-$(CONFIG_PPC_TRANSACTIONAL_MEM) += ptrace-tm.o +obj-$(CONFIG_PPC_ADV_DEBUG_REGS) += ptrace-adv.o +ifneq ($(CONFIG_PPC_ADV_DEBUG_REGS),y) +obj-y += ptrace-noadv.o +endif
arch/powerpc/kernel/ptrace/ptrace-adv.c new file +487 -0
487 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-decl.h +6 -0
@@ -139,3 +139,9 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,/* ptrace-view */ extern const struct user_regset_view user_ppc_native_view; + +/* ptrace-(no)adv */ +int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data); +long ppc_set_hwdebug (struct task_struct *child,struct ppc_hw_breakpoint *bp_info); +long ppc_del_hwdebug (struct task_struct *child,long data); +
arch/powerpc/kernel/ptrace/ptrace-noadv.c new file +258 -0
258 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace.c +0 -652
670 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH 10/13 powerpc/ptrace: create ptrace_get_debugreg()
In reply to Christophe LeroyCreate ptrace_get_debugreg() to handle PTRACE_GET_DEBUGREG and reduce ifdef mess
--- arch/powerpc/kernel/ptrace/ptrace-adv.c | 9 +++++++++ arch/powerpc/kernel/ptrace/ptrace-decl.h | 2 ++ arch/powerpc/kernel/ptrace/ptrace-noadv.c | 13 +++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 18 ++---------------- 4 files changed, 26 insertions(+), 16 deletions(-)
arch/powerpc/kernel/ptrace/ptrace-adv.c +9 -0
@@ -83,6 +83,15 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr, +unsigned long __user *datalp) +{ +/* We only support one DABR and no IABRS at the moment */ +if (addr >0 ) +return -EINVAL ; +return put_user (child->thread.debug.dac1, datalp); +} +int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data) {/* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
arch/powerpc/kernel/ptrace/ptrace-decl.h +2 -0
@@ -141,6 +141,8 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,extern const struct user_regset_view user_ppc_native_view;/* ptrace-(no)adv */ +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr, +unsigned long __user *datalp);int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data);long ppc_set_hwdebug (struct task_struct *child,struct ppc_hw_breakpoint *bp_info);long ppc_del_hwdebug (struct task_struct *child,long data);
arch/powerpc/kernel/ptrace/ptrace-noadv.c +13 -0
@@ -64,6 +64,19 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr, +unsigned long __user *datalp) +{ +unsigned long dabr_fake; + +/* We only support one DABR and no IABRS at the moment */ +if (addr >0 ) +return -EINVAL ; + dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR )) | + (child->thread.hw_brk.type &HW_BRK_TYPE_DABR )); +return put_user (dabr_fake, datalp); +} +int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data) {#ifdef CONFIG_HAVE_HW_BREAKPOINT
arch/powerpc/kernel/ptrace/ptrace.c +2 -16
@@ -211,23 +211,9 @@ long arch_ptrace(struct task_struct *child, long request,break ; } -case PTRACE_GET_DEBUGREG : { -#ifndef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long dabr_fake; -#endif - ret = -EINVAL ; -/* We only support one DABR and no IABRS at the moment */ -if (addr >0 ) -break ; -#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.debug.dac1, datalp); -#else - dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR )) | - (child->thread.hw_brk.type &HW_BRK_TYPE_DABR )); - ret =put_user (dabr_fake, datalp); -#endif +case PTRACE_GET_DEBUGREG : + ret =ptrace_get_debugreg (child, addr, datalp);break ; - }case PTRACE_SET_DEBUGREG : ret =ptrace_set_debugreg (child, addr, data);
Signature · 1 line
2.13.3
RFC PATCH 11/13 powerpc/ptrace: create ppc_gethwdinfo()
In reply to Christophe LeroyCreate ippc_gethwdinfo() to handle PPC_PTRACE_GETHWDBGINFO and reduce ifdef mess
--- arch/powerpc/kernel/ptrace/ptrace-adv.c | 15 +++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-decl.h | 1 + arch/powerpc/kernel/ptrace/ptrace-noadv.c | 20 +++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 32 +------------------------------ 4 files changed, 37 insertions(+), 31 deletions(-)
arch/powerpc/kernel/ptrace/ptrace-adv.c +15 -0
@@ -83,6 +83,21 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo) +{ + dbginfo->version =1 ; + dbginfo->num_instruction_bps =CONFIG_PPC_ADV_DEBUG_IACS ; + dbginfo->num_data_bps =CONFIG_PPC_ADV_DEBUG_DACS ; + dbginfo->num_condition_regs =CONFIG_PPC_ADV_DEBUG_DVCS ; + dbginfo->data_bp_alignment =4 ; + dbginfo->sizeof_condition =4 ; + dbginfo->features =PPC_DEBUG_FEATURE_INSN_BP_RANGE | +PPC_DEBUG_FEATURE_INSN_BP_MASK ; +if (IS_ENABLED (CONFIG_PPC_ADV_DEBUG_DAC_RANGE )) + dbginfo->features |=PPC_DEBUG_FEATURE_DATA_BP_RANGE | +PPC_DEBUG_FEATURE_DATA_BP_MASK ; +} +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp) {
arch/powerpc/kernel/ptrace/ptrace-decl.h +1 -0
@@ -141,6 +141,7 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,extern const struct user_regset_view user_ppc_native_view;/* ptrace-(no)adv */ +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo);int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp);int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data);
arch/powerpc/kernel/ptrace/ptrace-noadv.c +20 -0
@@ -64,6 +64,26 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo) +{ + dbginfo->version =1 ; + dbginfo->num_instruction_bps =0 ; +if (ppc_breakpoint_available ()) + dbginfo->num_data_bps =1 ; +else + dbginfo->num_data_bps =0 ; + dbginfo->num_condition_regs =0 ; + dbginfo->data_bp_alignment =sizeof (long ); + dbginfo->sizeof_condition =0 ; +if (IS_ENABLED (CONFIG_HAVE_HW_BREAKPOINT )) { + dbginfo->features =PPC_DEBUG_FEATURE_DATA_BP_RANGE ; +if (dawr_enabled ()) + dbginfo->features |=PPC_DEBUG_FEATURE_DATA_BP_DAWR ; + }else { + dbginfo->features =0 ; + } +} +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp) {
arch/powerpc/kernel/ptrace/ptrace.c +1 -31
@@ -159,37 +159,7 @@ long arch_ptrace(struct task_struct *child, long request,case PPC_PTRACE_GETHWDBGINFO : {struct ppc_debug_info dbginfo; - dbginfo.version =1 ; -#ifdef CONFIG_PPC_ADV_DEBUG_REGS - dbginfo.num_instruction_bps =CONFIG_PPC_ADV_DEBUG_IACS ; - dbginfo.num_data_bps =CONFIG_PPC_ADV_DEBUG_DACS ; - dbginfo.num_condition_regs =CONFIG_PPC_ADV_DEBUG_DVCS ; - dbginfo.data_bp_alignment =4 ; - dbginfo.sizeof_condition =4 ; - dbginfo.features =PPC_DEBUG_FEATURE_INSN_BP_RANGE | -PPC_DEBUG_FEATURE_INSN_BP_MASK ; -#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - dbginfo.features |= -PPC_DEBUG_FEATURE_DATA_BP_RANGE | -PPC_DEBUG_FEATURE_DATA_BP_MASK ; -#endif -#else /* !CONFIG_PPC_ADV_DEBUG_REGS */ - dbginfo.num_instruction_bps =0 ; -if (ppc_breakpoint_available ()) - dbginfo.num_data_bps =1 ; -else - dbginfo.num_data_bps =0 ; - dbginfo.num_condition_regs =0 ; - dbginfo.data_bp_alignment =sizeof (long ); - dbginfo.sizeof_condition =0 ; -#ifdef CONFIG_HAVE_HW_BREAKPOINT - dbginfo.features =PPC_DEBUG_FEATURE_DATA_BP_RANGE ; -if (dawr_enabled ()) - dbginfo.features |=PPC_DEBUG_FEATURE_DATA_BP_DAWR ; -#else - dbginfo.features =0 ; -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ -#endif /* CONFIG_PPC_ADV_DEBUG_REGS */ +ppc_gethwdinfo (&dbginfo);if (copy_to_user (datavp, &dbginfo,sizeof (struct ppc_debug_info )))
Signature · 1 line
2.13.3
Re: [RFC PATCH v1 11/13] powerpc/ptrace: create ppc_gethwdinfo()
Quoted 2 lines · Christophe Leroy
Create
ippc_gethwdinfo()to handlePPC_PTRACE_GETHWDBGINFOand
s/ippc_gethwdinfo/ppc_gethwdinfo/
Quoted 15 lines
reduce ifdef mess
Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/kernel/ptrace/ptrace-adv.c | 15 +++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-decl.h | 1 + arch/powerpc/kernel/ptrace/ptrace-noadv.c | 20 +++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 32 +------------------------------ 4 files changed, 37 insertions(+), 31 deletions(-)arch/powerpc/kernel/ptrace/ptrace-adv.c +0
-0
arch/powerpc/kernel/ptrace/ptrace-adv.c void user_disable_single_step(struct task_struct *task) · line 86
Quoted 4 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c +1
-0@@ -83,6 +83,21 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo)
Would it be possible to rename it to ppc_gethwdbginfo, I find it easier to read.
Quoted 106 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c +14
-0+{ + dbginfo->version =1 ; + dbginfo->num_instruction_bps =CONFIG_PPC_ADV_DEBUG_IACS ; + dbginfo->num_data_bps =CONFIG_PPC_ADV_DEBUG_DACS ; + dbginfo->num_condition_regs =CONFIG_PPC_ADV_DEBUG_DVCS ; + dbginfo->data_bp_alignment =4 ; + dbginfo->sizeof_condition =4 ; + dbginfo->features =PPC_DEBUG_FEATURE_INSN_BP_RANGE | +PPC_DEBUG_FEATURE_INSN_BP_MASK ; +if (IS_ENABLED (CONFIG_PPC_ADV_DEBUG_DAC_RANGE )) + dbginfo->features |=PPC_DEBUG_FEATURE_DATA_BP_RANGE | +PPC_DEBUG_FEATURE_DATA_BP_MASK ; +} +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp) {arch/powerpc/kernel/ptrace/ptrace-decl.h +1
-0@@ -141,6 +141,7 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,extern const struct user_regset_view user_ppc_native_view;/* ptrace-(no)adv */ +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo);int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp);int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data);arch/powerpc/kernel/ptrace/ptrace-noadv.c +20
-0@@ -64,6 +64,26 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +void ppc_gethwdinfo (struct ppc_debug_info *dbginfo) +{ + dbginfo->version =1 ; + dbginfo->num_instruction_bps =0 ; +if (ppc_breakpoint_available ()) + dbginfo->num_data_bps =1 ; +else + dbginfo->num_data_bps =0 ; + dbginfo->num_condition_regs =0 ; + dbginfo->data_bp_alignment =sizeof (long ); + dbginfo->sizeof_condition =0 ; +if (IS_ENABLED (CONFIG_HAVE_HW_BREAKPOINT )) { + dbginfo->features =PPC_DEBUG_FEATURE_DATA_BP_RANGE ; +if (dawr_enabled ()) + dbginfo->features |=PPC_DEBUG_FEATURE_DATA_BP_DAWR ; + }else { + dbginfo->features =0 ; + } +} +int ptrace_get_debugreg (struct task_struct *child,unsigned long addr,unsigned long __user *datalp) {arch/powerpc/kernel/ptrace/ptrace.c +1
-32@@ -159,37 +159,7 @@ long arch_ptrace(struct task_struct *child, long request,case PPC_PTRACE_GETHWDBGINFO : {struct ppc_debug_info dbginfo; - dbginfo.version =1 ; -#ifdef CONFIG_PPC_ADV_DEBUG_REGS - dbginfo.num_instruction_bps =CONFIG_PPC_ADV_DEBUG_IACS ; - dbginfo.num_data_bps =CONFIG_PPC_ADV_DEBUG_DACS ; - dbginfo.num_condition_regs =CONFIG_PPC_ADV_DEBUG_DVCS ; - dbginfo.data_bp_alignment =4 ; - dbginfo.sizeof_condition =4 ; - dbginfo.features =PPC_DEBUG_FEATURE_INSN_BP_RANGE | -PPC_DEBUG_FEATURE_INSN_BP_MASK ; -#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - dbginfo.features |= -PPC_DEBUG_FEATURE_DATA_BP_RANGE | -PPC_DEBUG_FEATURE_DATA_BP_MASK ; -#endif -#else /* !CONFIG_PPC_ADV_DEBUG_REGS */ - dbginfo.num_instruction_bps =0 ; -if (ppc_breakpoint_available ()) - dbginfo.num_data_bps =1 ; -else - dbginfo.num_data_bps =0 ; - dbginfo.num_condition_regs =0 ; - dbginfo.data_bp_alignment =sizeof (long ); - dbginfo.sizeof_condition =0 ; -#ifdef CONFIG_HAVE_HW_BREAKPOINT - dbginfo.features =PPC_DEBUG_FEATURE_DATA_BP_RANGE ; -if (dawr_enabled ()) - dbginfo.features |=PPC_DEBUG_FEATURE_DATA_BP_DAWR ; -#else - dbginfo.features =0 ; -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ -#endif /* CONFIG_PPC_ADV_DEBUG_REGS */ +ppc_gethwdinfo (&dbginfo);if (copy_to_user (datavp, &dbginfo,sizeof (struct ppc_debug_info ))) --2.13.3
RFC PATCH 12/13 powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c
In reply to Christophe Leroyptrace_triggered() is declared in asm/hw_breakpoint.h and only needed when CONFIG_HW_BREAKPOINT is set, so move it into hw_breakpoint.c
--- arch/powerpc/kernel/hw_breakpoint.c | 16 ++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 18 ------------------ 2 files changed, 16 insertions(+), 18 deletions(-)
arch/powerpc/kernel/hw_breakpoint.c +16 -0
@@ -367,6 +367,22 @@ void hw_breakpoint_pmu_read(struct perf_event *bp)/* TODO */ } +void ptrace_triggered (struct perf_event *bp, +struct perf_sample_data *data,struct pt_regs *regs) +{ +struct perf_event_attr attr; + +/* +* Disable the breakpoint request here since ptrace has defined a +* one-shot behaviour for breakpoint exceptions in PPC64. +* The SIGTRAP signal is generated automatically for us in do_dabr(). +* We don't have to do anything about that here +*/ + attr = bp->attr; + attr.disabled = true; +modify_user_hw_breakpoint (bp, &attr); +} +bool dawr_force_enable;EXPORT_SYMBOL_GPL (dawr_force_enable);
arch/powerpc/kernel/ptrace/ptrace.c +0 -18
@@ -50,24 +50,6 @@#include <kernel/ptrace/ptrace-decl.h> -#ifdef CONFIG_HAVE_HW_BREAKPOINT -void ptrace_triggered (struct perf_event *bp, -struct perf_sample_data *data,struct pt_regs *regs) -{ -struct perf_event_attr attr; - -/* -* Disable the breakpoint request here since ptrace has defined a -* one-shot behaviour for breakpoint exceptions in PPC64. -* The SIGTRAP signal is generated automatically for us in do_dabr(). -* We don't have to do anything about that here -*/ - attr = bp->attr; - attr.disabled = true; -modify_user_hw_breakpoint (bp, &attr); -} -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ -/* * Called by kernel/ptrace.c when detaching.. *
Signature · 1 line
2.13.3
RFC PATCH 13/13 powerpc/hw_breakpoint: move instruction stepping out of hw_breakpoint_handler()
In reply to Christophe LeroyOn 8xx, breakpoints stop after executing the instruction, so stepping/emulation is not needed. Move it into a sub-function and remove the #ifdefs.
--- arch/powerpc/kernel/hw_breakpoint.c | 60 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-)
arch/powerpc/kernel/hw_breakpoint.c +33 -27
@@ -198,15 +198,43 @@ void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs)/* * Handle debug exception notifications. */ +static bool stepping_handler (struct pt_regs *regs,struct perf_event *bp, +unsigned long addr) +{ +int stepped; +unsigned int instr; + +/* Do not emulate user-space instructions, instead single-step them */ +if (user_mode (regs)) { + current->thread.last_hit_ubp = bp; + regs->msr |=MSR_SE ; +return false; + } + + stepped =0 ; + instr =0 ; +if (!__get_user_inatomic (instr, (unsigned int *) regs->nip)) + stepped =emulate_step (regs, instr); + +/* +* emulate_step() could not execute it. We've failed in reliably +* handling the hw-breakpoint. Unregister it and throw a warning +* message to let the user know about it. +*/ +if (!stepped) { +WARN (1 ,"Unable to handle hardware breakpoint. Breakpoint at " +"0x%lx will be disabled." , addr); +perf_event_disable_inatomic (bp); +return false; + } +return true; +} +int hw_breakpoint_handler (struct die_args *args) {int rc =NOTIFY_STOP ;struct perf_event *bp;struct pt_regs *regs = args->regs; -#ifndef CONFIG_PPC_8xx -int stepped =1 ; -unsigned int instr; -#endif struct arch_hw_breakpoint *info;unsigned long dar = regs->dar;
@@ -251,31 +279,9 @@ int hw_breakpoint_handler(struct die_args *args) (dar - bp->attr.bp_addr < bp->attr.bp_len))) info->type |= HW_BRK_TYPE_EXTRANEOUS_IRQ; -#ifndef CONFIG_PPC_8xx -/* Do not emulate user-space instructions, instead single-step them */ -if (user_mode (regs)) { - current->thread.last_hit_ubp = bp; - regs->msr |=MSR_SE ; +if (!IS_ENABLED (CONFIG_PPC_8xx) && !stepping_handler (regs, bp, info->address)) goto out; - } - stepped =0 ; - instr =0 ; -if (!__get_user_inatomic (instr, (unsigned int *) regs->nip)) - stepped =emulate_step (regs, instr); - -/* -* emulate_step() could not execute it. We've failed in reliably -* handling the hw-breakpoint. Unregister it and throw a warning -* message to let the user know about it. -*/ -if (!stepped) { -WARN (1 ,"Unable to handle hardware breakpoint. Breakpoint at " -"0x%lx will be disabled." , info->address); -perf_event_disable_inatomic (bp); - goto out; - } -#endif /* * As a policy, the callback is invoked in a 'trigger-after-execute' * fashion
Signature · 1 line
2.13.3