Re: [PATCH 10/15] powerpc/watchpoint: Use loop for thread_struct->ptrace_bps

From: Ravi Bangoria
Date: Wed Mar 18 2020 - 05:44:15 EST


@@ -1628,6 +1628,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
ÂÂÂÂÂ void (*f)(void);
ÂÂÂÂÂ unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
ÂÂÂÂÂ struct thread_info *ti = task_thread_info(p);
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+ÂÂÂ int i;
+#endif

Could we avoid all those #ifdefs ?

I think if we make p->thread.ptrace_bps[] exist all the time, with a size of 0 when CONFIG_HAVE_HW_BREAKPOINT is not set, then we can drop a lot of #ifdefs.

Hmm.. what you are saying seems possible. But IMO it should be done as
independent series. Will work on it.


ÂÂÂÂÂ klp_init_thread_info(p);
@@ -1687,7 +1690,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
ÂÂÂÂÂ p->thread.ksp_limit = (unsigned long)end_of_stack(p);
 #endif
 #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
ÂÂÂÂÂ p->thread.fp_save_area = NULL;
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index f6d7955fc61e..e2651f86d56f 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c

You'll have to rebase all this on the series https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=161356 which is about to go into powerpc-next

Sure. Thanks for heads up.


@@ -2829,6 +2829,19 @@ static int set_dac_range(struct task_struct *child,
 }
 #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+static int 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

What does this function do exactly ? I seems to do more than what its name suggests.

It finds an empty breakpoint in ptrace_bps[]. But yeah, function name is
misleading. I'll rename it to find_empty_ptrace_bp().

...

@@ -2979,10 +2993,10 @@ static long ppc_del_hwdebug(struct task_struct *child, long data)
ÂÂÂÂÂÂÂÂÂ return -EINVAL;
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
-ÂÂÂ bp = thread->ptrace_bps[0];
+ÂÂÂ bp = thread->ptrace_bps[data - 1];

Is data checked somewhere to ensure it is not out of boundaries ? Or are we sure it is always within ?

Yes. it's checked. See patch #9:

@@ -2955,7 +2975,7 @@ static long ppc_del_hwdebug(struct task_struct *child, long data)
}
return rc;
#else
- if (data != 1)
+ if (data < 1 || data > nr_wp_slots())
return -EINVAL;
#ifdef CONFIG_HAVE_HW_BREAKPOINT

Thanks,
Ravi