Currently, there are some places to set CSR.PRMD.PWE, the first one is
in hw_breakpoint_thread_switch() to enable user space singlestep via
checking TIF_SINGLESTEP, the second one is in hw_breakpoint_control() to
enable user space watchpoint. For the latter case, it should also check
TIF_LOAD_WATCH to make the logic correct and clear.
Fixes: c8e57ab0995c ("LoongArch: Trigger user-space watchpoints correctly")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
                }
                enable = csr_read64(LOONGARCH_CSR_CRMD);
                csr_write64(CSR_CRMD_WE | enable, LOONGARCH_CSR_CRMD);
-               if (bp->hw.target)
+               if (bp->hw.target && test_tsk_thread_flag(bp->hw.target, TIF_LOAD_WATCH))
                        regs->csr_prmd |= CSR_PRMD_PWE;
                break;
        case HW_BREAKPOINT_UNINSTALL:
 
        struct perf_event *bp;
        struct perf_event_attr attr;
        struct arch_hw_breakpoint_ctrl ctrl;
+       struct thread_info *ti = task_thread_info(tsk);
 
        bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
        if (IS_ERR(bp))
                if (err)
                        return err;
                attr.disabled = 0;
+               set_ti_thread_flag(ti, TIF_LOAD_WATCH);
        } else {
                attr.disabled = 1;
+               clear_ti_thread_flag(ti, TIF_LOAD_WATCH);
        }
 
        return modify_user_hw_breakpoint(bp, &attr);