powerpc: Use set_trap() and avoid open-coding trap masking
authorNicholas Piggin <npiggin@gmail.com>
Thu, 7 May 2020 12:13:30 +0000 (22:13 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 15 May 2020 01:58:54 +0000 (11:58 +1000)
The pt_regs.trap field keeps 4 low bits for some metadata about the
trap or how it was handled, which is masked off in order to test the
architectural trap number.

Add a set_trap() accessor to set this, equivalent to TRAP() for
returning it. This is actually not quite the equivalent of TRAP()
because it always clears the low bits, which may be harmless if
it can only be updated via ptrace syscall, but it seems dangerous.

In fact settting TRAP from ptrace doesn't seem like a great idea
so maybe it's better deleted.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Make it a static inline rather than a shouty macro]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200507121332.2233629-2-mpe@ellerman.id.au
arch/powerpc/include/asm/ptrace.h
arch/powerpc/kernel/ptrace/ptrace-tm.c
arch/powerpc/kernel/ptrace/ptrace-view.c
arch/powerpc/xmon/xmon.c

index 89f31d5..7c585bd 100644 (file)
@@ -182,10 +182,12 @@ extern int ptrace_put_reg(struct task_struct *task, int regno,
 
 #ifdef __powerpc64__
 #ifdef CONFIG_PPC_BOOK3S
+#define TRAP_FLAGS_MASK                0
 #define TRAP(regs)             ((regs)->trap)
 #define FULL_REGS(regs)                true
 #define SET_FULL_REGS(regs)    do { } while (0)
 #else
+#define TRAP_FLAGS_MASK                0x1
 #define TRAP(regs)             ((regs)->trap & ~0x1)
 #define FULL_REGS(regs)                (((regs)->trap & 1) == 0)
 #define SET_FULL_REGS(regs)    ((regs)->trap |= 1)
@@ -200,6 +202,7 @@ extern int ptrace_put_reg(struct task_struct *task, int regno,
  * On 4xx we use the next bit to indicate whether the exception
  * is a critical exception (1 means it is).
  */
+#define TRAP_FLAGS_MASK                0xF
 #define TRAP(regs)             ((regs)->trap & ~0xF)
 #define FULL_REGS(regs)                (((regs)->trap & 1) == 0)
 #define SET_FULL_REGS(regs)    ((regs)->trap |= 1)
@@ -214,6 +217,11 @@ do {                                                                             \
 } while (0)
 #endif /* __powerpc64__ */
 
+static inline void set_trap(struct pt_regs *regs, unsigned long val)
+{
+       regs->trap = (regs->trap & TRAP_FLAGS_MASK) | (val & ~TRAP_FLAGS_MASK);
+}
+
 #define arch_has_single_step() (1)
 #ifndef CONFIG_BOOK3S_601
 #define arch_has_block_step()  (true)
index d75aff3..32d62c6 100644 (file)
@@ -43,7 +43,7 @@ static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr)
 
 static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap)
 {
-       task->thread.ckpt_regs.trap = trap & 0xfff0;
+       set_trap(&task->thread.ckpt_regs, trap);
        return 0;
 }
 
index 15e3b79..caeb582 100644 (file)
@@ -149,7 +149,7 @@ static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  */
 static int set_user_trap(struct task_struct *task, unsigned long trap)
 {
-       task->thread.regs->trap = trap & 0xfff0;
+       set_trap(task->thread.regs, trap);
        return 0;
 }
 
index 7af840c..92761e4 100644 (file)
@@ -1178,7 +1178,7 @@ static int do_step(struct pt_regs *regs)
                                return 0;
                        }
                        if (stepped > 0) {
-                               regs->trap = 0xd00 | (regs->trap & 1);
+                               set_trap(regs, 0xd00);
                                printf("stepped to ");
                                xmon_print_symbol(regs->nip, " ", "\n");
                                ppc_inst_dump(regs->nip, 1, 0);