arch/loongarch/kernel/hw_breakpoint.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/hw_breakpoint.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/hw_breakpoint.c- Extension
.c- Size
- 14442 bytes
- Lines
- 576
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hw_breakpoint.hlinux/kprobes.hlinux/perf_event.hasm/hw_breakpoint.h
Detected Declarations
enum hw_breakpoint_opsfunction hw_breakpoint_slotsfunction read_wb_regfunction write_wb_regfunction hw_breakpoint_slot_setupfunction ptrace_hw_copy_threadfunction flush_ptrace_hw_breakpointfunction hw_breakpoint_controlfunction arch_install_hw_breakpointfunction arch_uninstall_hw_breakpointfunction get_hbp_lenfunction arch_check_bp_in_kernelspacefunction arch_bp_generic_fieldsfunction arch_build_bp_infofunction hw_breakpoint_arch_parsefunction update_bp_registersfunction breakpoint_handlerfunction watchpoint_handlerfunction arch_hw_breakpoint_initfunction hw_breakpoint_thread_switchfunction hw_breakpoint_pmu_read
Annotated Snippet
switch (ops) {
case HW_BREAKPOINT_INSTALL:
if (!*slot) {
*slot = bp;
return i;
}
break;
case HW_BREAKPOINT_UNINSTALL:
if (*slot == bp) {
*slot = NULL;
return i;
}
break;
default:
pr_warn_once("Unhandled hw breakpoint ops %d\n", ops);
return -EINVAL;
}
}
return -ENOSPC;
}
void ptrace_hw_copy_thread(struct task_struct *tsk)
{
memset(tsk->thread.hbp_break, 0, sizeof(tsk->thread.hbp_break));
memset(tsk->thread.hbp_watch, 0, sizeof(tsk->thread.hbp_watch));
}
/*
* Unregister breakpoints from this task and reset the pointers in the thread_struct.
*/
void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
{
int i;
struct thread_struct *t = &tsk->thread;
for (i = 0; i < LOONGARCH_MAX_BRP; i++) {
if (t->hbp_break[i]) {
unregister_hw_breakpoint(t->hbp_break[i]);
t->hbp_break[i] = NULL;
}
}
for (i = 0; i < LOONGARCH_MAX_WRP; i++) {
if (t->hbp_watch[i]) {
unregister_hw_breakpoint(t->hbp_watch[i]);
t->hbp_watch[i] = NULL;
}
}
}
static int hw_breakpoint_control(struct perf_event *bp,
enum hw_breakpoint_ops ops)
{
u32 ctrl, privilege;
int i, max_slots, enable;
struct pt_regs *regs;
struct perf_event **slots;
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
if (arch_check_bp_in_kernelspace(info))
privilege = CTRL_PLV0_ENABLE;
else
privilege = CTRL_PLV3_ENABLE;
/* Whether bp belongs to a task. */
if (bp->hw.target)
regs = task_pt_regs(bp->hw.target);
if (info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) {
/* Breakpoint */
slots = this_cpu_ptr(bp_on_reg);
max_slots = boot_cpu_data.watch_ireg_count;
} else {
/* Watchpoint */
slots = this_cpu_ptr(wp_on_reg);
max_slots = boot_cpu_data.watch_dreg_count;
}
i = hw_breakpoint_slot_setup(slots, max_slots, bp, ops);
if (WARN_ONCE(i < 0, "Can't find any breakpoint slot"))
return i;
switch (ops) {
case HW_BREAKPOINT_INSTALL:
/* Set the FWPnCFG/MWPnCFG 1~4 register. */
if (info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) {
write_wb_reg(CSR_CFG_ADDR, i, 0, info->address);
write_wb_reg(CSR_CFG_MASK, i, 0, info->mask);
Annotation
- Immediate include surface: `linux/hw_breakpoint.h`, `linux/kprobes.h`, `linux/perf_event.h`, `asm/hw_breakpoint.h`.
- Detected declarations: `enum hw_breakpoint_ops`, `function hw_breakpoint_slots`, `function read_wb_reg`, `function write_wb_reg`, `function hw_breakpoint_slot_setup`, `function ptrace_hw_copy_thread`, `function flush_ptrace_hw_breakpoint`, `function hw_breakpoint_control`, `function arch_install_hw_breakpoint`, `function arch_uninstall_hw_breakpoint`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.