MIPS: Fix watchpoint restoration
authorJames Hogan <james.hogan@imgtec.com>
Tue, 1 Mar 2016 22:19:36 +0000 (22:19 +0000)
committerRalf Baechle <ralf@linux-mips.org>
Mon, 9 May 2016 10:00:02 +0000 (12:00 +0200)
Commit f51246efee2b ("MIPS: Get rid of finish_arch_switch().") moved the
__restore_watch() call from finish_arch_switch() (i.e. after resume()
returns) to before the resume() call in switch_to(). This results in
watchpoints only being restored when a task is descheduled, preventing
the watchpoints from being effective most of the time, except due to
chance before the watchpoints are lazily removed.

Fix the call sequence from switch_to() through to
mips_install_watch_registers() to pass the task_struct pointer of the
next task, instead of using current. This allows the watchpoints for the
next (non-current) task to be restored without reintroducing
finish_arch_switch().

Fixes: f51246efee2b ("MIPS: Get rid of finish_arch_switch().")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: <stable@vger.kernel.org> # 4.3.x-
Patchwork: https://patchwork.linux-mips.org/patch/12726/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/include/asm/switch_to.h
arch/mips/include/asm/watch.h
arch/mips/kernel/pm.c
arch/mips/kernel/watch.c

index 28b5d84a5022a13c7b9c782ad446c30bdff06b29..ebb5c0f2f90daef7b2bcca348fb90df2b7530037 100644 (file)
@@ -105,7 +105,7 @@ do {                                                                        \
        __clear_software_ll_bit();                                      \
        if (cpu_has_userlocal)                                          \
                write_c0_userlocal(task_thread_info(next)->tp_value);   \
-       __restore_watch();                                              \
+       __restore_watch(next);                                          \
        (last) = resume(prev, next, task_thread_info(next));            \
 } while (0)
 
index 20126ec793596a6ab2ab2a2e35d6e96e9ac59541..6ffe3eadf105cb226c269511121be7e3ff349507 100644 (file)
 
 #include <asm/mipsregs.h>
 
-void mips_install_watch_registers(void);
+void mips_install_watch_registers(struct task_struct *t);
 void mips_read_watch_registers(void);
 void mips_clear_watch_registers(void);
 void mips_probe_watch_registers(struct cpuinfo_mips *c);
 
 #ifdef CONFIG_HARDWARE_WATCHPOINTS
-#define __restore_watch() do {                                         \
+#define __restore_watch(task) do {                                     \
        if (unlikely(test_bit(TIF_LOAD_WATCH,                           \
-                             &current_thread_info()->flags))) {        \
-               mips_install_watch_registers();                         \
+                             &task_thread_info(task)->flags))) {       \
+               mips_install_watch_registers(task);                     \
        }                                                               \
 } while (0)
 
 #else
-#define __restore_watch() do {} while (0)
+#define __restore_watch(task) do {} while (0)
 #endif
 
 #endif /* _ASM_WATCH_H */
index fefdf39d3df352ebb68e309607398e72f76f3611..dc814892133c0f7f7c71728cf0eeadad19295ae8 100644 (file)
@@ -56,7 +56,7 @@ static void mips_cpu_restore(void)
                write_c0_userlocal(current_thread_info()->tp_value);
 
        /* Restore watch registers */
-       __restore_watch();
+       __restore_watch(current);
 }
 
 /**
index 2a03abb5bd2cc24e9aa7d4dd6c6fcfa29cb253ed..9b78e375118e8f451902664a150fbee0cacdfc2c 100644 (file)
  * Install the watch registers for the current thread. A maximum of
  * four registers are installed although the machine may have more.
  */
-void mips_install_watch_registers(void)
+void mips_install_watch_registers(struct task_struct *t)
 {
-       struct mips3264_watch_reg_state *watches =
-               &current->thread.watch.mips3264;
+       struct mips3264_watch_reg_state *watches = &t->thread.watch.mips3264;
        switch (current_cpu_data.watch_reg_use_cnt) {
        default:
                BUG();