Commit 6b424efa authored by Ravi Bangoria's avatar Ravi Bangoria Committed by Michael Ellerman

powerpc/watchpoint: Use loop for thread_struct->ptrace_bps

ptrace_bps is already an array of size HBP_NUM_MAX. But we use
hardcoded index 0 while fetching/updating it. Convert such code
to loop over array.

ptrace interface to use multiple watchpoint remains same. eg:
two PPC_PTRACE_SETHWDEBUG calls will create two watchpoint if
underneath hw supports it.
Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Reviewed-by: default avatarMichael Neuling <mikey@neuling.org>
Link: https://lore.kernel.org/r/20200514111741.97993-11-ravi.bangoria@linux.ibm.com
parent 303e6a9d
...@@ -420,10 +420,13 @@ NOKPROBE_SYMBOL(hw_breakpoint_exceptions_notify); ...@@ -420,10 +420,13 @@ NOKPROBE_SYMBOL(hw_breakpoint_exceptions_notify);
*/ */
void flush_ptrace_hw_breakpoint(struct task_struct *tsk) void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
{ {
int i;
struct thread_struct *t = &tsk->thread; struct thread_struct *t = &tsk->thread;
unregister_hw_breakpoint(t->ptrace_bps[0]); for (i = 0; i < nr_wp_slots(); i++) {
t->ptrace_bps[0] = NULL; unregister_hw_breakpoint(t->ptrace_bps[i]);
t->ptrace_bps[i] = NULL;
}
} }
void hw_breakpoint_pmu_read(struct perf_event *bp) void hw_breakpoint_pmu_read(struct perf_event *bp)
......
...@@ -1604,6 +1604,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, ...@@ -1604,6 +1604,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
void (*f)(void); void (*f)(void);
unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE; unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
struct thread_info *ti = task_thread_info(p); struct thread_info *ti = task_thread_info(p);
#ifdef CONFIG_HAVE_HW_BREAKPOINT
int i;
#endif
klp_init_thread_info(p); klp_init_thread_info(p);
...@@ -1663,7 +1666,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, ...@@ -1663,7 +1666,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
p->thread.ksp_limit = (unsigned long)end_of_stack(p); p->thread.ksp_limit = (unsigned long)end_of_stack(p);
#endif #endif
#ifdef CONFIG_HAVE_HW_BREAKPOINT #ifdef CONFIG_HAVE_HW_BREAKPOINT
p->thread.ptrace_bps[0] = NULL; for (i = 0; i < nr_wp_slots(); i++)
p->thread.ptrace_bps[i] = NULL;
#endif #endif
p->thread.fp_save_area = NULL; p->thread.fp_save_area = NULL;
......
...@@ -168,6 +168,19 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned l ...@@ -168,6 +168,19 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned l
return 0; return 0;
} }
#ifdef CONFIG_HAVE_HW_BREAKPOINT
static int find_empty_ptrace_bp(struct thread_struct *thread)
{
int i;
for (i = 0; i < nr_wp_slots(); i++) {
if (!thread->ptrace_bps[i])
return i;
}
return -1;
}
#endif
static int find_empty_hw_brk(struct thread_struct *thread) static int find_empty_hw_brk(struct thread_struct *thread)
{ {
int i; int i;
...@@ -217,8 +230,9 @@ long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_inf ...@@ -217,8 +230,9 @@ long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_inf
len = 1; len = 1;
else else
return -EINVAL; return -EINVAL;
bp = thread->ptrace_bps[0];
if (bp) i = find_empty_ptrace_bp(thread);
if (i < 0)
return -ENOSPC; return -ENOSPC;
/* Create a new breakpoint request if one doesn't exist already */ /* Create a new breakpoint request if one doesn't exist already */
...@@ -228,13 +242,13 @@ long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_inf ...@@ -228,13 +242,13 @@ long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_inf
arch_bp_generic_fields(brk.type, &attr.bp_type); arch_bp_generic_fields(brk.type, &attr.bp_type);
bp = register_user_hw_breakpoint(&attr, ptrace_triggered, NULL, child); bp = register_user_hw_breakpoint(&attr, ptrace_triggered, NULL, child);
thread->ptrace_bps[0] = bp; thread->ptrace_bps[i] = bp;
if (IS_ERR(bp)) { if (IS_ERR(bp)) {
thread->ptrace_bps[0] = NULL; thread->ptrace_bps[i] = NULL;
return PTR_ERR(bp); return PTR_ERR(bp);
} }
return 1; return i + 1;
#endif /* CONFIG_HAVE_HW_BREAKPOINT */ #endif /* CONFIG_HAVE_HW_BREAKPOINT */
if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT)
...@@ -263,10 +277,10 @@ long ppc_del_hwdebug(struct task_struct *child, long data) ...@@ -263,10 +277,10 @@ long ppc_del_hwdebug(struct task_struct *child, long data)
return -EINVAL; return -EINVAL;
#ifdef CONFIG_HAVE_HW_BREAKPOINT #ifdef CONFIG_HAVE_HW_BREAKPOINT
bp = thread->ptrace_bps[0]; bp = thread->ptrace_bps[data - 1];
if (bp) { if (bp) {
unregister_hw_breakpoint(bp); unregister_hw_breakpoint(bp);
thread->ptrace_bps[0] = NULL; thread->ptrace_bps[data - 1] = NULL;
} else { } else {
ret = -ENOENT; ret = -ENOENT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment