linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] LoongArch: Add hardware breakpoints/watchpoints support
@ 2023-02-17  2:37 Qing Zhang
  2023-02-17  2:37 ` [PATCH v4 1/3] " Qing Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Qing Zhang @ 2023-02-17  2:37 UTC (permalink / raw)
  To: Huacai Chen, Oleg Nesterov, WANG Xuerui
  Cc: Jiaxun Yang, loongarch, linux-kernel

Use perf framework to manage hardware instruction and data breakpoints.
LoongArch defines hardware watchpoint functions for instruction fetch
and load/store operations, after the software configures hardware watchpoints
for instruction fetch and load/store operations. The processor hardware will
monitor the access address of the instruction fetch and load/store operation,
and will trigger the exception of the watchpoint when it meets the conditions
set by the watchpoint.

The hardware monitoring points for instruction fetching and load/store operations
each have a register for the overall configuration of all monitoring points,
a register for recording the status of all monitoring points, and four registers
required for configuration of each watchpoint individually.

Watchpoint related control status register chapters:
https://github.com/loongson/LoongArch-Documentation/releases/download/2022.08.12/
LoongArch-Vol1-v1.02-CN.pdf

Initial version has the following limitations:
- no support for virtualization

Can be tested: e.g.
1. see samples/hw_breakpoint and register_wide_hw_breakpoint.
2. ptrace(PTRACE_SINGLESTEP/..., pid, NULL, NULL)
3. ptrace (PTRACE_SETREGSET, tid, ... , ...)

TODO:
- Add hardware breakpoints/watchpoints for gdb, kgdb

Changes v1 -> v2:
Suggested by Huacai:
- Use irqentry_enter()/irqentry_exit() instead of
  exception_enter()/exception_exit().
- Add ptrace interface to expose hw-breakpoints to debuggers.
- Use 2022-2023.
- Some other changes.

Changes v2 -> v3:
Suggested by Jinyang:
- get_num_brps/wrps, decode/encode_ctrl_reg which the function
  returns directly.
- Remove irrelevant content from the first patch.
- Use macros to avoid using magic values directly.
- Add new arg to indicate it is breakpoint or watchpoint
  to avoid function coupling.
- Remove redundant tab.
- Modify the breakpoint/watchpoint_handler function type to void.
- Some other changes.

Changes v3 -> v4:
Suggested by Jinyang:
- Add judgment prevent rd == pc from causing single step to fail to stop.
- Add code comments to improve readability.
- Use macros in csr_write32.

Qing Zhang (3):
  LoongArch: Add hardware breakpoints/watchpoints support
  LoongArch: Add ptrace single step support
  LoongArch: ptrace: expose hardware breakpoints to debuggers

 arch/loongarch/Kconfig                     |   1 +
 arch/loongarch/include/asm/hw_breakpoint.h | 145 ++++++
 arch/loongarch/include/asm/inst.h          |  39 ++
 arch/loongarch/include/asm/loongarch.h     |  35 +-
 arch/loongarch/include/asm/processor.h     |  14 +-
 arch/loongarch/include/asm/ptrace.h        |   2 +
 arch/loongarch/include/asm/switch_to.h     |   1 +
 arch/loongarch/include/uapi/asm/ptrace.h   |   9 +
 arch/loongarch/kernel/Makefile             |   1 +
 arch/loongarch/kernel/hw_breakpoint.c      | 544 +++++++++++++++++++++
 arch/loongarch/kernel/process.c            |   7 +
 arch/loongarch/kernel/ptrace.c             | 484 ++++++++++++++++++
 arch/loongarch/kernel/traps.c              |  38 +-
 include/uapi/linux/elf.h                   |   2 +
 14 files changed, 1301 insertions(+), 21 deletions(-)
 create mode 100644 arch/loongarch/include/asm/hw_breakpoint.h
 create mode 100644 arch/loongarch/kernel/hw_breakpoint.c

-- 
2.36.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-02-18  6:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17  2:37 [PATCH v4 0/3] LoongArch: Add hardware breakpoints/watchpoints support Qing Zhang
2023-02-17  2:37 ` [PATCH v4 1/3] " Qing Zhang
2023-02-17  2:37 ` [PATCH v4 2/3] LoongArch: Add ptrace single step support Qing Zhang
2023-02-17  9:50   ` Youling Tang
2023-02-17 10:00     ` Qing Zhang
2023-02-18  1:21       ` Jinyang He
2023-02-18  6:38         ` Qing Zhang
2023-02-17 10:16   ` WANG Xuerui
2023-02-18  6:31     ` Qing Zhang
2023-02-17  2:37 ` [PATCH v4 3/3] LoongArch: ptrace: expose hardware breakpoints to debuggers Qing Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).