Re: [PATCH v2 09/16] powerpc/watchpoint: Convert thread_struct->hw_brk to an array

From: Ravi Bangoria
Date: Wed Apr 01 2020 - 05:06:37 EST



 static void set_debug_reg_defaults(struct thread_struct *thread)
 {
-ÂÂÂ thread->hw_brk.address = 0;
-ÂÂÂ thread->hw_brk.type = 0;
-ÂÂÂ thread->hw_brk.len = 0;
-ÂÂÂ thread->hw_brk.hw_len = 0;
-ÂÂÂ if (ppc_breakpoint_available())
-ÂÂÂÂÂÂÂ set_breakpoint(&thread->hw_brk);
+ÂÂÂ int i;
+
+ÂÂÂ for (i = 0; i < nr_wp_slots(); i++) {

Maybe you could add the following that you added other places:

ÂÂÂÂstruct arch_hw_breakpoint null_brk = {0};

Then do

ÂÂÂÂthread->hw_brk[i] = null_brk;

Yes that's better.

[...]

+static void switch_hw_breakpoint(struct task_struct *new)
+{
+ÂÂÂ int i;
+
+ÂÂÂ for (i = 0; i < nr_wp_slots(); i++) {
+ÂÂÂÂÂÂÂ if (unlikely(!hw_brk_match(this_cpu_ptr(&current_brk[i]),
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &new->thread.hw_brk[i]))) {
+ÂÂÂÂÂÂÂÂÂÂÂ __set_breakpoint(&new->thread.hw_brk[i], i);
+ÂÂÂÂÂÂÂ }

Or could be:

ÂÂÂÂÂÂÂ if (likely(hw_brk_match(this_cpu_ptr(&current_brk[i]),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &new->thread.hw_brk[i])))
ÂÂÂÂÂÂÂÂÂÂÂ continue;
ÂÂÂÂÂÂÂ __set_breakpoint(&new->thread.hw_brk[i], i);


Sure.

[...]

@@ -128,8 +131,10 @@ static void do_signal(struct task_struct *tsk)
ÂÂÂÂÂÂ * user space. The DABR will have been cleared if it
ÂÂÂÂÂÂ * triggered inside the kernel.
ÂÂÂÂÂÂ */
-ÂÂÂ if (tsk->thread.hw_brk.address && tsk->thread.hw_brk.type)
-ÂÂÂÂÂÂÂ __set_breakpoint(&tsk->thread.hw_brk, 0);
+ÂÂÂ for (i = 0; i < nr_wp_slots(); i++) {
+ÂÂÂÂÂÂÂ if (tsk->thread.hw_brk[i].address && tsk->thread.hw_brk[i].type)
+ÂÂÂÂÂÂÂÂÂÂÂ __set_breakpoint(&tsk->thread.hw_brk[i], i);
+ÂÂÂ }

thread.hwbrk also exists when CONFIG_PPC_ADV_DEBUG_REGS is selected.

You could replace the #ifndef CONFIG_PPC_ADV_DEBUG_REGS by an if (!IS_ENABLED(CONFIG_PPC_ADV_DEBUG_REGS)) and then no need of an ifdef when declaring the int i;

Makes sense. Will change it.

Ravi