Skip to content

Commit a55c195

Browse files
seehearfeelgregkh
authored andcommitted
LoongArch: Check TIF_LOAD_WATCH to enable user space watchpoint
[ Upstream commit 3892b11 ] 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: c8e57ab ("LoongArch: Trigger user-space watchpoints correctly") Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 97a64fd commit a55c195

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

arch/loongarch/kernel/hw_breakpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int hw_breakpoint_control(struct perf_event *bp,
221221
}
222222
enable = csr_read64(LOONGARCH_CSR_CRMD);
223223
csr_write64(CSR_CRMD_WE | enable, LOONGARCH_CSR_CRMD);
224-
if (bp->hw.target)
224+
if (bp->hw.target && test_tsk_thread_flag(bp->hw.target, TIF_LOAD_WATCH))
225225
regs->csr_prmd |= CSR_PRMD_PWE;
226226
break;
227227
case HW_BREAKPOINT_UNINSTALL:

arch/loongarch/kernel/ptrace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ static int ptrace_hbp_set_ctrl(unsigned int note_type,
589589
struct perf_event *bp;
590590
struct perf_event_attr attr;
591591
struct arch_hw_breakpoint_ctrl ctrl;
592+
struct thread_info *ti = task_thread_info(tsk);
592593

593594
bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
594595
if (IS_ERR(bp))
@@ -613,8 +614,10 @@ static int ptrace_hbp_set_ctrl(unsigned int note_type,
613614
if (err)
614615
return err;
615616
attr.disabled = 0;
617+
set_ti_thread_flag(ti, TIF_LOAD_WATCH);
616618
} else {
617619
attr.disabled = 1;
620+
clear_ti_thread_flag(ti, TIF_LOAD_WATCH);
618621
}
619622

620623
return modify_user_hw_breakpoint(bp, &attr);

0 commit comments

Comments
 (0)