Skip to contentSkip to conversation

Reduce ifdef mess in ptrace

RFC PATCH Superseded Christophe Leroy 5 participants 30 messages Jun 28, 2019 – Feb 26, 2020

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#2 lore raw

RFC PATCH v2 2/12 powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

In reply to Christophe Leroy

Drop 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
index faa5a338ac5a..1506a9c61d50 100644
@@ -36,11 +36,10 @@ struct pt_regs
 			unsigned 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
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
 	unsigned 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
index 684b0b315c32..0afb223c4d57 100644
@@ -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_PPC64
 	REG_OFFSET_NAME(softe),
-#else
 	REG_OFFSET_NAME(mq),
-#endif
 	REG_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
#13 lore raw

RFC PATCH v2 6/12 powerpc/ptrace: split out SPE related functions.

In reply to Christophe Leroy

Move CONFIG_SPE functions out of ptrace.c, into
ptrace-spe.c

---
 arch/powerpc/kernel/ptrace/Makefile      |  1 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  9 ++++
 arch/powerpc/kernel/ptrace/ptrace-spe.c  | 92 ++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace/ptrace.c      | 66 -----------------------
 4 files changed, 102 insertions(+), 66 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-spe.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
index 522e6fd0b5b8..f87eadf6e072 100644
@@ -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
index 0f9282cb52fc..8a362f97f1d6 100644
@@ -26,6 +26,15 @@ 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);
+
 /* ptrace */
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
arch/powerpc/kernel/ptrace/ptrace-spe.c new file +92 -0

92 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
#14 lore raw

RFC PATCH v2 7/12 powerpc/ptrace: split out TRANSACTIONAL_MEM related functions.

In reply to Christophe Leroy

Move TRANSACTIONAL_MEM functions out of ptrace.c, into ptrace-tm.c

---
 arch/powerpc/kernel/ptrace/Makefile      |   1 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  89 +++
 arch/powerpc/kernel/ptrace/ptrace-tm.c   | 879 +++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace/ptrace.c      | 915 +------------------------------
 4 files changed, 971 insertions(+), 913 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-tm.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
index f87eadf6e072..2d7f5f301536 100644
@@ -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 +89 -0

102 lines not on this page · raw message

arch/powerpc/kernel/ptrace/ptrace-tm.c new file +879 -0

879 lines not on this page · raw message

arch/powerpc/kernel/ptrace/ptrace.c +2 -913

963 lines not on this page · raw message

Signature · 1 line
2.13.3
#20 lore raw

RFC PATCH v2 11/12 powerpc/ptrace: create ppc_gethwdinfo()

In reply to Christophe Leroy

Create 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
index dcc765940344..f5f334484ebc 100644
@@ -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
index 4b4b6a1d508a..3c8a81999292 100644
@@ -176,6 +176,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
index 985cca136f85..426fedd7ab6c 100644
@@ -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
index e789afae6f56..31e8c5a9171e 100644
@@ -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
#22 lore raw

RFC PATCH v2 12/12 powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c

In reply to Christophe Leroy

ptrace_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
index a293a53b4365..b71d3837d673 100644
@@ -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
index 31e8c5a9171e..b85998b159d7 100644
@@ -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
#16 lore raw

RFC PATCH v2 9/12 powerpc/ptrace: split out ADV_DEBUG_REGS related functions.

In reply to Christophe Leroy

Move 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  |   5 +
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 258 ++++++++++++
 arch/powerpc/kernel/ptrace/ptrace.c       | 652 ------------------------------
 5 files changed, 754 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
index 7addc5994bb9..e9d97c2d063e 100644
@@ -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 +5 -0
index e12f6615fc1d..bdba09a87aea 100644
@@ -174,3 +174,8 @@ 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
#18 lore raw

RFC PATCH v2 10/12 powerpc/ptrace: create ptrace_get_debugreg()

In reply to Christophe Leroy

Create 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
index 86e71fa6c5c8..dcc765940344 100644
@@ -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
index bdba09a87aea..4b4b6a1d508a 100644
@@ -176,6 +176,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
index 7db330c94538..985cca136f85 100644
@@ -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
index 377e0e541d5f..e789afae6f56 100644
@@ -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
#15 lore raw

RFC PATCH v2 8/12 powerpc/ptrace: move register viewing functions out of ptrace.c

In reply to Christophe Leroy

Create a dedicated ptrace-view.c file.

---
 arch/powerpc/kernel/ptrace/Makefile      |   4 +-
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  43 ++
 arch/powerpc/kernel/ptrace/ptrace-view.c | 953 ++++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace/ptrace.c      | 960 -------------------------------
 4 files changed, 998 insertions(+), 962 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-view.c
arch/powerpc/kernel/ptrace/Makefile +2 -2
index 2d7f5f301536..7addc5994bb9 100644
@@ -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 +43 -0

52 lines not on this page · raw message

arch/powerpc/kernel/ptrace/ptrace-view.c new file +953 -0

953 lines not on this page · raw message

arch/powerpc/kernel/ptrace/ptrace.c +0 -960

966 lines not on this page · raw message

Signature · 1 line
2.13.3
#12 lore raw

RFC PATCH v2 5/12 powerpc/ptrace: split out ALTIVEC related functions.

In reply to Christophe Leroy

Move 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
index 238c27189078..522e6fd0b5b8 100644
@@ -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
index 764df4ee9362..0f9282cb52fc 100644
@@ -17,6 +17,15 @@ 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);
+
 /* ptrace */
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
arch/powerpc/kernel/ptrace/ptrace.c +0 -124

130 lines not on this page · raw message

Signature · 1 line
2.13.3
#9 lore raw

RFC PATCH v2 4/12 powerpc/ptrace: split out VSX related functions.

In reply to Christophe Leroy

Move CONFIG_VSX functions out of ptrace.c, into
ptrace-vsx.c and ptrace-novsx.c

---
 arch/powerpc/kernel/ptrace/Makefile       |   4 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h  |  26 +++++
 arch/powerpc/kernel/ptrace/ptrace-novsx.c |  83 ++++++++++++++
 arch/powerpc/kernel/ptrace/ptrace-vsx.c   | 177 ++++++++++++++++++++++++++++++
 arch/powerpc/kernel/ptrace/ptrace.c       | 175 +----------------------------
 5 files changed, 293 insertions(+), 172 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
index 02fb28eb3b55..238c27189078 100644
@@ -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 +26 -0
new file mode 100644
index 000000000000..764df4ee9362
@@ -0,0 +1,26 @@
+/* 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);
+
+/* ptrace */
+
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+void flush_tmregs_to_thread(struct task_struct *tsk);
+#else
+static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
+#endif
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 +3 -172

205 lines not on this page · raw message

Signature · 1 line
2.13.3
#8 lore raw

RFC PATCH v2 3/12 powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET

In reply to Christophe Leroy

PARAMETER_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
index 0afb223c4d57..cc8efcb404d6 100644
@@ -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
#0 lore raw

v2 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.

v2:
- Fixed several build failures. Now builts cleanly on kisskb, see http://kisskb.ellerman.id.au/kisskb/head/840e53cf913d6096dd60181a085f102c85d6e526/
- Droped last patch which is not related to ptrace and can be applies independently.

Christophe Leroy (12):
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

 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         |   16 +
 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    |  184 ++
 arch/powerpc/kernel/ptrace/ptrace-noadv.c   |  291 +++
 arch/powerpc/kernel/ptrace/ptrace-novsx.c   |   83 +
 arch/powerpc/kernel/ptrace/ptrace-spe.c     |   92 +
 arch/powerpc/kernel/ptrace/ptrace-tm.c      |  879 +++++++
 arch/powerpc/kernel/ptrace/ptrace-view.c    |  953 ++++++++
 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, 3798 insertions(+), 3419 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
#1 lore raw

RFC PATCH v2 1/12 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
index 0ea6c4aa3a20..c522464fa56a 100644
@@ -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
new file mode 100644
index 000000000000..02fb28eb3b55
@@ -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
similarity index 100%
rename from arch/powerpc/kernel/ptrace.c
rename to arch/powerpc/kernel/ptrace/ptrace.c
arch/powerpc/kernel/ptrace/ptrace32.c renamed from arch/powerpc/kernel/ptrace32.c +0 -0
similarity index 100%
rename from arch/powerpc/kernel/ptrace32.c
rename to arch/powerpc/kernel/ptrace/ptrace32.c
Signature · 1 line
2.13.3
#3 lore raw

Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

In reply to Christophe Leroy
Quoted 8 lines · Christophe Leroy
arch/powerpc/include/uapi/asm/ptrace.h +0 -0
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
 	unsigned long link;
 	unsigned long xer;
 	unsigned long ccr;

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 50

Quoted 10 lines
arch/powerpc/include/uapi/asm/ptrace.h +4 -5
-#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
+	};

Anonymous unions are a C11 feature.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
#4 lore raw

Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

Le 28/06/2019 à 18:36, Andreas Schwab a écrit :

Quoted 14 lines · Christophe Leroy
Quoted 13 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -4
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
  	unsigned 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) */
Quoted 9 lines

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 50

Quoted 6 lines
arch/powerpc/include/uapi/asm/ptrace.h +4 -1
+	union {
+		unsigned long softe;	/* Soft enabled/disabled */
+		unsigned long mq;	/* 601 only (not used at present) */
  					/* Used on APUS to hold IPL value. */
-#endif
+	};

Anonymous unions are a C11 feature.

Is that a problem ?

Kernel has a minimum GCC requirement of version 4.6, doesn't 4.6 support C11 ?

Christophe

#5 lore raw

Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

Quoted 25 lines · Christophe Leroy

Le 28/06/2019 à 18:36, Andreas Schwab a écrit :

Quoted 14 lines · Christophe Leroy
Quoted 13 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -4
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
  	unsigned 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) */
Quoted 9 lines

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 50

Quoted 6 lines
arch/powerpc/include/uapi/asm/ptrace.h +4 -1
+	union {
+		unsigned long softe;	/* Soft enabled/disabled */
+		unsigned long mq;	/* 601 only (not used at present) */
  					/* Used on APUS to hold IPL value. */
-#endif
+	};

Anonymous unions are a C11 feature.

Quoted 1 line

Is that a problem ?

Yes, this is a UAPI header.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
#17 lore raw

Re: [RFC PATCH v2 09/12] powerpc/ptrace: split out ADV_DEBUG_REGS related functions.

In reply to Christophe Leroy
Quoted 87 lines · Christophe Leroy
arch/powerpc/kernel/ptrace/ptrace-adv.c new file +81 -0
new file mode 100644
index 000000000000..86e71fa6c5c8
@@ -0,0 +1,487 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/regset.h>
+#include <linux/tracehook.h>
+#include <linux/elf.h>
+#include <linux/user.h>
+#include <linux/security.h>
+#include <linux/signal.h>
+#include <linux/seccomp.h>
+#include <linux/audit.h>
+#include <trace/syscall.h>
+#include <linux/hw_breakpoint.h>
+#include <linux/perf_event.h>
+#include <linux/context_tracking.h>
+#include <linux/nospec.h>
+
+#include <linux/uaccess.h>
+#include <linux/pkeys.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/switch_to.h>
+#include <asm/tm.h>
+#include <asm/asm-prototypes.h>
+#include <asm/debug.h>
+#include <asm/hw_breakpoint.h>
+
+#include <kernel/ptrace/ptrace-decl.h>
+
+void user_enable_single_step(struct task_struct *task)
+{
+	struct pt_regs *regs = task->thread.regs;
+
+	if (regs != NULL) {
+		task->thread.debug.dbcr0 &= ~DBCR0_BT;
+		task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC;
+		regs->msr |= MSR_DE;
+	}
+	set_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+void user_enable_block_step(struct task_struct *task)
+{
+	struct pt_regs *regs = task->thread.regs;
+
+	if (regs != NULL) {
+		task->thread.debug.dbcr0 &= ~DBCR0_IC;
+		task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT;
+		regs->msr |= MSR_DE;
+	}
+	set_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+void user_disable_single_step(struct task_struct *task)
+{
+	struct pt_regs *regs = task->thread.regs;
+
+	if (regs != NULL) {
+		/*
+		 * The logic to disable single stepping should be as
+		 * simple as turning off the Instruction Complete flag.
+		 * And, after doing so, if all debug flags are off, turn
+		 * off DBCR0(IDM) and MSR(DE) .... Torez
+		 */
+		task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT);
+		/*
+		 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
+		 */
+		if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
+					task->thread.debug.dbcr1)) {
+			/*
+			 * All debug events were off.....
+			 */
+			task->thread.debug.dbcr0 &= ~DBCR0_IDM;
+			regs->msr &= ~MSR_DE;
+		}

arch/powerpc/kernel/ptrace/ptrace-adv.c line 91

Quoted 10 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c new file +10 -0
+	}
+	clear_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+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).
+	 *  For embedded processors we support one DAC and no IAC's at the
+	 *  moment.
+	 */

I guess mentioning DABR and IABR doesn't make sense in ptrace-adv.c?

arch/powerpc/kernel/ptrace/ptrace-adv.c line 95

Quoted 4 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c new file +4 -0
+	if (addr > 0)
+		return -EINVAL;
+
+	/* The bottom 3 bits in dabr are flags */

Same here.

arch/powerpc/kernel/ptrace/ptrace-noadv.c

Quoted 410 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c new file +392 -0
+	if ((data & ~0x7UL) >= TASK_SIZE)
+		return -EIO;
+
+	/* As described above, it was assumed 3 bits were passed with the data
+	 *  address, but we will assume only the mode bits will be passed
+	 *  as to not cause alignment restrictions for DAC-based processors.
+	 */
+
+	/* DAC's hold the whole address without any mode flags */
+	task->thread.debug.dac1 = data & ~0x3UL;
+
+	if (task->thread.debug.dac1 == 0) {
+		dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
+		if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
+					task->thread.debug.dbcr1)) {
+			task->thread.regs->msr &= ~MSR_DE;
+			task->thread.debug.dbcr0 &= ~DBCR0_IDM;
+		}
+		return 0;
+	}
+
+	/* Read or Write bits must be set */
+
+	if (!(data & 0x3UL))
+		return -EINVAL;
+
+	/* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
+	   register */
+	task->thread.debug.dbcr0 |= DBCR0_IDM;
+
+	/* Check for write and read flags and set DBCR0
+	   accordingly */
+	dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
+	if (data & 0x1UL)
+		dbcr_dac(task) |= DBCR_DAC1R;
+	if (data & 0x2UL)
+		dbcr_dac(task) |= DBCR_DAC1W;
+	task->thread.regs->msr |= MSR_DE;
+	return 0;
+}
+
+static long set_instruction_bp(struct task_struct *child,
+			      struct ppc_hw_breakpoint *bp_info)
+{
+	int slot;
+	int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0);
+	int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0);
+	int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0);
+	int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0);
+
+	if (dbcr_iac_range(child) & DBCR_IAC12MODE)
+		slot2_in_use = 1;
+	if (dbcr_iac_range(child) & DBCR_IAC34MODE)
+		slot4_in_use = 1;
+
+	if (bp_info->addr >= TASK_SIZE)
+		return -EIO;
+
+	if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
+
+		/* Make sure range is valid. */
+		if (bp_info->addr2 >= TASK_SIZE)
+			return -EIO;
+
+		/* We need a pair of IAC regsisters */
+		if ((!slot1_in_use) && (!slot2_in_use)) {
+			slot = 1;
+			child->thread.debug.iac1 = bp_info->addr;
+			child->thread.debug.iac2 = bp_info->addr2;
+			child->thread.debug.dbcr0 |= DBCR0_IAC1;
+			if (bp_info->addr_mode ==
+					PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
+				dbcr_iac_range(child) |= DBCR_IAC12X;
+			else
+				dbcr_iac_range(child) |= DBCR_IAC12I;
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+		} else if ((!slot3_in_use) && (!slot4_in_use)) {
+			slot = 3;
+			child->thread.debug.iac3 = bp_info->addr;
+			child->thread.debug.iac4 = bp_info->addr2;
+			child->thread.debug.dbcr0 |= DBCR0_IAC3;
+			if (bp_info->addr_mode ==
+					PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
+				dbcr_iac_range(child) |= DBCR_IAC34X;
+			else
+				dbcr_iac_range(child) |= DBCR_IAC34I;
+#endif
+		} else
+			return -ENOSPC;
+	} else {
+		/* We only need one.  If possible leave a pair free in
+		 * case a range is needed later
+		 */
+		if (!slot1_in_use) {
+			/*
+			 * Don't use iac1 if iac1-iac2 are free and either
+			 * iac3 or iac4 (but not both) are free
+			 */
+			if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
+				slot = 1;
+				child->thread.debug.iac1 = bp_info->addr;
+				child->thread.debug.dbcr0 |= DBCR0_IAC1;
+				goto out;
+			}
+		}
+		if (!slot2_in_use) {
+			slot = 2;
+			child->thread.debug.iac2 = bp_info->addr;
+			child->thread.debug.dbcr0 |= DBCR0_IAC2;
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+		} else if (!slot3_in_use) {
+			slot = 3;
+			child->thread.debug.iac3 = bp_info->addr;
+			child->thread.debug.dbcr0 |= DBCR0_IAC3;
+		} else if (!slot4_in_use) {
+			slot = 4;
+			child->thread.debug.iac4 = bp_info->addr;
+			child->thread.debug.dbcr0 |= DBCR0_IAC4;
+#endif
+		} else
+			return -ENOSPC;
+	}
+out:
+	child->thread.debug.dbcr0 |= DBCR0_IDM;
+	child->thread.regs->msr |= MSR_DE;
+
+	return slot;
+}
+
+static int del_instruction_bp(struct task_struct *child, int slot)
+{
+	switch (slot) {
+	case 1:
+		if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0)
+			return -ENOENT;
+
+		if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
+			/* address range - clear slots 1 & 2 */
+			child->thread.debug.iac2 = 0;
+			dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
+		}
+		child->thread.debug.iac1 = 0;
+		child->thread.debug.dbcr0 &= ~DBCR0_IAC1;
+		break;
+	case 2:
+		if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0)
+			return -ENOENT;
+
+		if (dbcr_iac_range(child) & DBCR_IAC12MODE)
+			/* used in a range */
+			return -EINVAL;
+		child->thread.debug.iac2 = 0;
+		child->thread.debug.dbcr0 &= ~DBCR0_IAC2;
+		break;
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	case 3:
+		if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0)
+			return -ENOENT;
+
+		if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
+			/* address range - clear slots 3 & 4 */
+			child->thread.debug.iac4 = 0;
+			dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
+		}
+		child->thread.debug.iac3 = 0;
+		child->thread.debug.dbcr0 &= ~DBCR0_IAC3;
+		break;
+	case 4:
+		if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0)
+			return -ENOENT;
+
+		if (dbcr_iac_range(child) & DBCR_IAC34MODE)
+			/* Used in a range */
+			return -EINVAL;
+		child->thread.debug.iac4 = 0;
+		child->thread.debug.dbcr0 &= ~DBCR0_IAC4;
+		break;
+#endif
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
+{
+	int byte_enable =
+		(bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT)
+		& 0xf;
+	int condition_mode =
+		bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE;
+	int slot;
+
+	if (byte_enable && (condition_mode == 0))
+		return -EINVAL;
+
+	if (bp_info->addr >= TASK_SIZE)
+		return -EIO;
+
+	if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
+		slot = 1;
+		if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
+			dbcr_dac(child) |= DBCR_DAC1R;
+		if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
+			dbcr_dac(child) |= DBCR_DAC1W;
+		child->thread.debug.dac1 = (unsigned long)bp_info->addr;
+#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
+		if (byte_enable) {
+			child->thread.debug.dvc1 =
+				(unsigned long)bp_info->condition_value;
+			child->thread.debug.dbcr2 |=
+				((byte_enable << DBCR2_DVC1BE_SHIFT) |
+				 (condition_mode << DBCR2_DVC1M_SHIFT));
+		}
+#endif
+#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
+	} else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
+		/* Both dac1 and dac2 are part of a range */
+		return -ENOSPC;
+#endif
+	} else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
+		slot = 2;
+		if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
+			dbcr_dac(child) |= DBCR_DAC2R;
+		if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
+			dbcr_dac(child) |= DBCR_DAC2W;
+		child->thread.debug.dac2 = (unsigned long)bp_info->addr;
+#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
+		if (byte_enable) {
+			child->thread.debug.dvc2 =
+				(unsigned long)bp_info->condition_value;
+			child->thread.debug.dbcr2 |=
+				((byte_enable << DBCR2_DVC2BE_SHIFT) |
+				 (condition_mode << DBCR2_DVC2M_SHIFT));
+		}
+#endif
+	} else
+		return -ENOSPC;
+	child->thread.debug.dbcr0 |= DBCR0_IDM;
+	child->thread.regs->msr |= MSR_DE;
+
+	return slot + 4;
+}
+
+static int del_dac(struct task_struct *child, int slot)
+{
+	if (slot == 1) {
+		if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
+			return -ENOENT;
+
+		child->thread.debug.dac1 = 0;
+		dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
+#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
+		if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
+			child->thread.debug.dac2 = 0;
+			child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE;
+		}
+		child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
+#endif
+#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
+		child->thread.debug.dvc1 = 0;
+#endif
+	} else if (slot == 2) {
+		if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
+			return -ENOENT;
+
+#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
+		if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE)
+			/* Part of a range */
+			return -EINVAL;
+		child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
+#endif
+#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
+		child->thread.debug.dvc2 = 0;
+#endif
+		child->thread.debug.dac2 = 0;
+		dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
+	} else
+		return -EINVAL;
+
+	return 0;
+}
+
+#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
+static int set_dac_range(struct task_struct *child,
+			 struct ppc_hw_breakpoint *bp_info)
+{
+	int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK;
+
+	/* We don't allow range watchpoints to be used with DVC */
+	if (bp_info->condition_mode)
+		return -EINVAL;
+
+	/*
+	 * Best effort to verify the address range.  The user/supervisor bits
+	 * prevent trapping in kernel space, but let's fail on an obvious bad
+	 * range.  The simple test on the mask is not fool-proof, and any
+	 * exclusive range will spill over into kernel space.
+	 */
+	if (bp_info->addr >= TASK_SIZE)
+		return -EIO;
+	if (mode == PPC_BREAKPOINT_MODE_MASK) {
+		/*
+		 * dac2 is a bitmask.  Don't allow a mask that makes a
+		 * kernel space address from a valid dac1 value
+		 */
+		if (~((unsigned long)bp_info->addr2) >= TASK_SIZE)
+			return -EIO;
+	} else {
+		/*
+		 * For range breakpoints, addr2 must also be a valid address
+		 */
+		if (bp_info->addr2 >= TASK_SIZE)
+			return -EIO;
+	}
+
+	if (child->thread.debug.dbcr0 &
+	    (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
+		return -ENOSPC;
+
+	if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
+		child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
+	if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
+		child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
+	child->thread.debug.dac1 = bp_info->addr;
+	child->thread.debug.dac2 = bp_info->addr2;
+	if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
+		child->thread.debug.dbcr2  |= DBCR2_DAC12M;
+	else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
+		child->thread.debug.dbcr2  |= DBCR2_DAC12MX;
+	else	/* PPC_BREAKPOINT_MODE_MASK */
+		child->thread.debug.dbcr2  |= DBCR2_DAC12MM;
+	child->thread.regs->msr |= MSR_DE;
+
+	return 5;
+}
+#endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
+
+long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
+{
+	if (bp_info->version != 1)
+		return -ENOTSUPP;
+	/*
+	 * Check for invalid flags and combinations
+	 */
+	if ((bp_info->trigger_type == 0) ||
+	    (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE |
+				       PPC_BREAKPOINT_TRIGGER_RW)) ||
+	    (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) ||
+	    (bp_info->condition_mode &
+	     ~(PPC_BREAKPOINT_CONDITION_MODE |
+	       PPC_BREAKPOINT_CONDITION_BE_ALL)))
+		return -EINVAL;
+#if CONFIG_PPC_ADV_DEBUG_DVCS == 0
+	if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
+		return -EINVAL;
+#endif
+
+	if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) {
+		if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
+		    (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
+			return -EINVAL;
+		return set_instruction_bp(child, bp_info);
+	}
+	if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
+		return set_dac(child, bp_info);
+
+#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
+	return set_dac_range(child, bp_info);
+#else
+	return -EINVAL;
+#endif
+}
+
+long ppc_del_hwdebug(struct task_struct *child, long data)
+{
+	int rc;
+
+	if (data <= 4)
+		rc = del_instruction_bp(child, (int)data);
+	else
+		rc = del_dac(child, (int)data - 4);
+
+	if (!rc) {
+		if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0,
+					child->thread.debug.dbcr1)) {
+			child->thread.debug.dbcr0 &= ~DBCR0_IDM;
+			child->thread.regs->msr &= ~MSR_DE;
+		}
+	}
+	return rc;
+}
arch/powerpc/kernel/ptrace/ptrace-decl.h +5 -0
index e12f6615fc1d..bdba09a87aea 100644
@@ -174,3 +174,8 @@ 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 +0 -0
new file mode 100644
index 000000000000..7db330c94538

ptrace-noadv.c looks good to me.

Reviewed-by on v2 10/12
#19 lore raw

Re: [RFC PATCH v2 10/12] powerpc/ptrace: create ptrace_get_debugreg()

In reply to Christophe Leroy
Quoted 16 lines · Christophe Leroy

Create 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 +0 -0
index 86e71fa6c5c8..dcc765940344 100644

arch/powerpc/kernel/ptrace/ptrace-adv.c void user_disable_single_step(struct task_struct *task) · line 89

Quoted 7 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c +4 -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 */

No DABR / IABR in ptrace-adv.c

Quoted 66 lines
arch/powerpc/kernel/ptrace/ptrace-adv.c +5 -0
+	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
index bdba09a87aea..4b4b6a1d508a 100644
@@ -176,6 +176,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
index 7db330c94538..985cca136f85 100644
@@ -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 +0 -12
index 377e0e541d5f..e789afae6f56 100644
@@ -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)) |

arch/powerpc/kernel/ptrace/ptrace.c long arch_ptrace(struct task_struct *child, long request, · line 219

Quoted 10 lines
arch/powerpc/kernel/ptrace/ptrace.c +2 -4
-			     (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);

Otherwise,

#24 lore raw
In reply to Christophe Leroy
Quoted 7 lines · Christophe Leroy

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.

Hi Christopher,

I'm seeing this warning with all the patches.

WARNING: Improper SPDX comment style for 'arch/powerpc/kernel/ptrace/ptrace-view.c', please use '//' instead #100: FILE: arch/powerpc/kernel/ptrace/ptrace-view.c:1:
+/* SPDX-License-Identifier: GPL-2.0-or-later */

#25 lore raw
In reply to Christophe Leroy

Hi Mikey,

Le 28/06/2019 à 17:47, Christophe Leroy a écrit :

Quoted 3 lines

The purpose of this series is to reduce the amount of #ifdefs in ptrace.c

Any feedback on this series which aims at fixing the issue you opened at https://github.com/linuxppc/issues/issues/128 ?

Thanks
Christophe

Quoted 55 lines

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.

v2:
- Fixed several build failures. Now builts cleanly on kisskb, see http://kisskb.ellerman.id.au/kisskb/head/840e53cf913d6096dd60181a085f102c85d6e526/
- Droped last patch which is not related to ptrace and can be applies independently.

Christophe Leroy (12):
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

  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         |   16 +
  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    |  184 ++
  arch/powerpc/kernel/ptrace/ptrace-noadv.c   |  291 +++
  arch/powerpc/kernel/ptrace/ptrace-novsx.c   |   83 +
  arch/powerpc/kernel/ptrace/ptrace-spe.c     |   92 +
  arch/powerpc/kernel/ptrace/ptrace-tm.c      |  879 +++++++
  arch/powerpc/kernel/ptrace/ptrace-view.c    |  953 ++++++++
  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, 3798 insertions(+), 3419 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%)

#26 lore raw

Christophe,

Quoted 7 lines · Christophe Leroy
Quoted 3 lines

The purpose of this series is to reduce the amount of #ifdefs in ptrace.c

Any feedback on this series which aims at fixing the issue you opened at
https://github.com/linuxppc/issues/issues/128 ?

Yeah, sorry my bad. You did all the hard work and I ignored it.

I like the approach and is a long the lines I was thinking. Putting it in a ptrace subdir, splitting out adv_debug_regs, TM, SPE, Alitivec, VSX. ppc_gethwdinfo() looks a lot nicer now too (that was some of the worst of it).

I've not gone through it with a fine tooth comb though. There is (rightly) a lot of code moved around which could have introduced some issues.

It applies on v5.2 but are you planning on updating it to a newer base?

Mikey

#27 lore raw

Le 24/02/2020 à 03:15, Michael Neuling a écrit :

Quoted 12 lines

Christophe,

Quoted 7 lines · Christophe Leroy
Quoted 3 lines

The purpose of this series is to reduce the amount of #ifdefs in ptrace.c

Any feedback on this series which aims at fixing the issue you opened at
https://github.com/linuxppc/issues/issues/128 ?

Yeah, sorry my bad. You did all the hard work and I ignored it.

Quoted 9 lines

I like the approach and is a long the lines I was thinking. Putting it in a ptrace subdir, splitting out adv_debug_regs, TM, SPE, Alitivec, VSX. ppc_gethwdinfo() looks a lot nicer now too (that was some of the worst of it).

I've not gone through it with a fine tooth comb though. There is (rightly) a lot of code moved around which could have introduced some issues.

It applies on v5.2 but are you planning on updating it to a newer base?

As you noticed there is a lot of code moved around, and rebasing produces a lot of conflicts. So I didn't want to spend hours to rebase and rebase without being sure it was the right approach.

Now that I got a positive feedback I'll consider rebasing it, hopping that Michael will pick it up.

Christophe

#6 lore raw

Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

In reply to Christophe Leroy
Quoted 37 lines · Christophe Leroy

Drop 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
index faa5a338ac5a..1506a9c61d50 100644
@@ -36,11 +36,10 @@ struct pt_regs
 			unsigned 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 +0 -0
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
 	unsigned long link;
 	unsigned long xer;
 	unsigned long ccr;

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 50

Quoted 10 lines
arch/powerpc/include/uapi/asm/ptrace.h +4 -5
-#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
+	};

As Andreas pointed out this is not safe as this is a uapi header.

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 112

Quoted 12 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -3
 	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

I'd also rather leave that as it is.

There's a slim chance it could break some code that already has either of those defined.

If you need them both defined to make other code work in the kernel that's fine, in the kernel header we can do:

// Ensure these are always defined inside the kernel to avoid #ifdefs #ifdef CONFIG_PPC64
#define PT_MQ 39
#else
#define PT_SOFTE 39
#endif

Quoted 8 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -0
 #define PT_TRAP	40
 #define PT_DAR	41
 #define PT_DSISR 42
arch/powerpc/kernel/ptrace/ptrace.c +0 -0
index 684b0b315c32..0afb223c4d57 100644

arch/powerpc/kernel/ptrace/ptrace.c static const struct pt_regs_offset regoffset_table[] = { · line 120

Quoted 8 lines
arch/powerpc/kernel/ptrace/ptrace.c +0 -3
@@ -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_PPC64
 	REG_OFFSET_NAME(softe),
-#else
 	REG_OFFSET_NAME(mq),
-#endif

Pretty sure that will cause breakage. The offset is ABI.

cheers

#10 lore raw

Re: [RFC PATCH v2 04/12] powerpc/ptrace: split out VSX related functions.

In reply to Christophe Leroy
Quoted 27 lines · Christophe Leroy
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +21 -0
new file mode 100644
index 000000000000..55fbbb4aa9d7
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/regset.h>
+#include <linux/tracehook.h>
+#include <linux/elf.h>
+#include <linux/user.h>
+#include <linux/security.h>
+#include <linux/signal.h>
+#include <linux/seccomp.h>
+#include <linux/audit.h>
+#include <trace/syscall.h>
+#include <linux/hw_breakpoint.h>
+#include <linux/perf_event.h>
+#include <linux/context_tracking.h>
+#include <linux/nospec.h>

arch/powerpc/kernel/ptrace/ptrace-novsx.c line 31

Quoted 10 lines
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +10 -0
+
+#include <linux/uaccess.h>
+#include <linux/pkeys.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/switch_to.h>
+#include <asm/tm.h>
+#include <asm/asm-prototypes.h>
+#include <asm/debug.h>
+#include <asm/hw_breakpoint.h>

I suspect we probably don't need all those headers anymore. But I guess we'll clean them up in future, as it's very tedious work to trim the list.

arch/powerpc/kernel/ptrace/ptrace-novsx.c line 33

Quoted 2 lines
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +2 -0
+
+#include <kernel/ptrace/ptrace-decl.h>

It's preferable to use:

#include "ptrace-decl.h"

cheers

#28 lore raw
In reply to Christophe Leroy
Quoted 21 lines · Christophe Leroy

Le 24/02/2020 à 03:15, Michael Neuling a écrit :

Quoted 10 lines

Christophe,

Quoted 6 lines · Christophe Leroy
Quoted 2 lines

The purpose of this series is to reduce the amount of #ifdefs in ptrace.c

Any feedback on this series which aims at fixing the issue you opened at
https://github.com/linuxppc/issues/issues/128 ?

Yeah, sorry my bad. You did all the hard work and I ignored it.

Quoted 9 lines

I like the approach and is a long the lines I was thinking. Putting it in a ptrace subdir, splitting out adv_debug_regs, TM, SPE, Alitivec, VSX. ppc_gethwdinfo() looks a lot nicer now too (that was some of the worst of it).

I've not gone through it with a fine tooth comb though. There is (rightly) a lot of code moved around which could have introduced some issues.

It applies on v5.2 but are you planning on updating it to a newer base?

Quoted 6 lines

As you noticed there is a lot of code moved around, and rebasing produces a lot of conflicts. So I didn't want to spend hours to rebase and rebase without being sure it was the right approach.

Now that I got a positive feedback I'll consider rebasing it, hopping that Michael will pick it up.

I would love to.

cheers

#29 lore raw

Le 24/02/2020 à 11:54, Michael Ellerman a écrit :

Quoted 22 lines
Quoted 21 lines · Christophe Leroy

Le 24/02/2020 à 03:15, Michael Neuling a écrit :

Quoted 19 lines

Christophe,

Quoted 6 lines · Christophe Leroy
Quoted 2 lines

The purpose of this series is to reduce the amount of #ifdefs in ptrace.c

Any feedback on this series which aims at fixing the issue you opened at
https://github.com/linuxppc/issues/issues/128 ?

Yeah, sorry my bad. You did all the hard work and I ignored it.

I like the approach and is a long the lines I was thinking. Putting it in a ptrace subdir, splitting out adv_debug_regs, TM, SPE, Alitivec, VSX. ppc_gethwdinfo() looks a lot nicer now too (that was some of the worst of it).

I've not gone through it with a fine tooth comb though. There is (rightly) a lot of code moved around which could have introduced some issues.

It applies on v5.2 but are you planning on updating it to a newer base?

Quoted 9 lines
Quoted 6 lines

As you noticed there is a lot of code moved around, and rebasing produces a lot of conflicts. So I didn't want to spend hours to rebase and rebase without being sure it was the right approach.

Now that I got a positive feedback I'll consider rebasing it, hopping that Michael will pick it up.

I would love to.

Great.

Just sent v3 out.

Christophe

#11 lore raw

Re: [RFC PATCH v2 04/12] powerpc/ptrace: split out VSX related functions.

In reply to Michael Ellerman

Le 24/02/2020 à 11:51, Michael Ellerman a écrit :

Quoted 33 lines
Quoted 32 lines · Christophe Leroy
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +26 -0
new file mode 100644
index 000000000000..55fbbb4aa9d7
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/regset.h>
+#include <linux/tracehook.h>
+#include <linux/elf.h>
+#include <linux/user.h>
+#include <linux/security.h>
+#include <linux/signal.h>
+#include <linux/seccomp.h>
+#include <linux/audit.h>
+#include <trace/syscall.h>
+#include <linux/hw_breakpoint.h>
+#include <linux/perf_event.h>
+#include <linux/context_tracking.h>
+#include <linux/nospec.h>
+
+#include <linux/uaccess.h>
+#include <linux/pkeys.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
Quoted 8 lines

arch/powerpc/kernel/ptrace/ptrace-novsx.c line 31

Quoted 5 lines
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +5 -0
+#include <asm/switch_to.h>
+#include <asm/tm.h>
+#include <asm/asm-prototypes.h>
+#include <asm/debug.h>
+#include <asm/hw_breakpoint.h>

I suspect we probably don't need all those headers anymore. But I guess we'll clean them up in future, as it's very tedious work to trim the list.

Ok, I did it.

Quoted 8 lines

arch/powerpc/kernel/ptrace/ptrace-novsx.c line 33

Quoted 3 lines
arch/powerpc/kernel/ptrace/ptrace-novsx.c new file +2 -0
+
+#include <kernel/ptrace/ptrace-decl.h>

It's preferable to use:

#include "ptrace-decl.h"

Ok, done.

Christophe

#7 lore raw

Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

In reply to Michael Ellerman

Le 24/02/2020 à 11:48, Michael Ellerman a écrit :

Quoted 42 lines
Quoted 41 lines · Christophe Leroy

Drop 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
index faa5a338ac5a..1506a9c61d50 100644
@@ -36,11 +36,10 @@ struct pt_regs
  			unsigned 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 +0 -4
index f5f1ccc740fc..37d7befbb8dc 100644
@@ -43,12 +43,11 @@ struct pt_regs
  	unsigned 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) */
Quoted 8 lines

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 50

Quoted 6 lines
arch/powerpc/include/uapi/asm/ptrace.h +4 -1
+	union {
+		unsigned long softe;	/* Soft enabled/disabled */
+		unsigned long mq;	/* 601 only (not used at present) */
  					/* Used on APUS to hold IPL value. */
-#endif
+	};

As Andreas pointed out this is not safe as this is a uapi header.

Ok, dropped

Quoted 22 lines

arch/powerpc/include/uapi/asm/ptrace.h struct pt_regs · line 112

Quoted 13 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -3
  	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

I'd also rather leave that as it is.

There's a slim chance it could break some code that already has either of those defined.

If you need them both defined to make other code work in the kernel that's fine, in the kernel header we can do:

Quoted 6 lines

// Ensure these are always defined inside the kernel to avoid #ifdefs #ifdef CONFIG_PPC64
#define PT_MQ 39
#else
#define PT_SOFTE 39
#endif

Ok.

Only the PT_SOFTE is missing, I added the following in the relevant case:

#define PT_SOFTE PT_MQ

Quoted 12 lines
Quoted 12 lines
arch/powerpc/include/uapi/asm/ptrace.h +0 -0
  #define PT_TRAP	40
  #define PT_DAR	41
  #define PT_DSISR 42
arch/powerpc/kernel/ptrace/ptrace.c +0 -0
index 684b0b315c32..0afb223c4d57 100644
@@ -113,11 +113,8 @@ static const struct pt_regs_offset regoffset_table[] = {
  	REG_OFFSET_NAME(link),
  	REG_OFFSET_NAME(xer),
Quoted 8 lines

arch/powerpc/kernel/ptrace/ptrace.c static const struct pt_regs_offset regoffset_table[] = { · line 120

Quoted 6 lines
arch/powerpc/kernel/ptrace/ptrace.c +0 -3
  	REG_OFFSET_NAME(ccr),
-#ifdef CONFIG_PPC64
  	REG_OFFSET_NAME(softe),
-#else
  	REG_OFFSET_NAME(mq),
-#endif

Pretty sure that will cause breakage. The offset is ABI.

Ok, dropped

Christophe