Skip to content

Add kprobe and kretprobe support for LoongArch

Tiezhu Yang lkml loongarch 12 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v12 Latest5 patches 20 repliesIn review
  2. v116 patches 2 repliesSuperseded
  3. v104 patches 11 repliesSuperseded
Earlier versions · 9
VersionPostedPatchesRepliesStatus
v94 patches8 repliesSuperseded
v84 patches0 repliesSuperseded
v74 patches4 repliesSuperseded
v65 patches1 replySuperseded
v54 patches1 replySuperseded
v44 patches0 repliesSuperseded
v34 patches1 replySuperseded
v25 patches10 repliesSuperseded
v14 patches4 repliesSuperseded

Changes in v12 from the cover letter

-- Rebase on the latest code
-- Fix -Wmissing-prototypes warning when make W=1 -- Drop patch #6 "Use common function sign_extend64()"
since it has been applied yet

Patches in v12 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5LoongArch: Simulate branch and PC* instructionsarch/loongarch/include/asm/inst.h arch/loongarch/include/asm/ptrace.h arch/loongarch/kernel/inst.c+129 -00 replies
2/5LoongArch: Add kprobe supportarch/loongarch/Kconfig arch/loongarch/include/asm/inst.h arch/loongarch/include/asm/kprobes.h +4 more+463 -50 replies
3/5LoongArch: Add kretprobe supportarch/loongarch/Kconfig arch/loongarch/include/asm/kprobes.h arch/loongarch/kernel/Makefile +2 more+128 -10 replies
4/5LoongArch: Mark some assembler symbols as non-kprobe-ablearch/loongarch/include/asm/asm.h arch/loongarch/kernel/entry.S arch/loongarch/lib/memcpy.S+14 -09 replies
5/5samples/kprobes: Add LoongArch supportsamples/kprobes/kprobe_example.c+8 -00 replies

Reviews trailers per patch

None of the 5 patches has a Reviewed-by or Acked-by.

PatchJeff Xie
SeriesT-b
1/5
2/5
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v12 thread

Cover letter [PATCH v12 0/5] Add kprobe and kretprobe support for LoongArch

v12:
-- Rebase on the latest code
-- Fix -Wmissing-prototypes warning when make W=1 -- Drop patch #6 "Use common function sign_extend64()"
since it has been applied yet

v11:
-- Rebase on the latest code
-- Address all the review comments, thank you all -- Modify arch_prepare_kprobe() and setup_singlestep()
to make the probe logic more clear
-- Mark some assembler symbols as non-kprobe-able -- Use common function sign_extend64()
-- Test 20 times about 36 hours for all the 71 assembler
functions annotated with SYM_CODE_START and SYM_FUNC_START under arch/loongarch, especially test memset alone for 10 hours, no hang problems

v10:
-- Remove sign_extend() based on the latest code
-- Rename insns_are_not_supported() to insns_not_supported() -- Rename insns_are_not_simulated() to insns_not_simulated() -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler()

v9:
-- Rename sign_extended() to sign_extend()
-- Modify kprobe_fault_handler() to handle all of kprobe_status

v8:
-- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line -- Add code comment of preempt_disable()
-- Put kprobe_page_fault() in __do_page_fault()
-- Modify the check condition of break insn in kprobe_breakpoint_handler()

v7:
-- Remove stop_machine_cpuslocked() related code

v6:
-- Add a new patch to redefine larch_insn_patch_text() with
stop_machine_cpuslocked()
-- Modify kprobe_breakpoint_handler() to consider the original
insn is break and return the correct value
-- Modify do_bp() to refresh bcode when original insn is break

v5:
-- Rebase on the latest code
-- Use stop_machine_cpuslocked() to modify insn to avoid CPU race

v4:
-- Remove kprobe_exceptions_notify() in kprobes.c
-- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler()

     in do_bp()

v3:
-- Rebase on the latest code
-- Check the alignment of PC in simu_branch() and simu_pc() -- Add ibar in flush_insn_slot()
-- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler -- Add preempt_disable() and preempt_enable_no_resched() -- Remove r0 save/restore and do some minor changes
in kprobes_trampoline.S
-- Do not enable CONFIG_KPROBES by default

v2:
-- Split simu_branch() and simu_pc() into a single patch -- Call kprobe_page_fault() in do_page_fault() -- Add kprobes_trampoline.S for kretprobe

Tiezhu Yang (5):
LoongArch: Simulate branch and PC* instructions
LoongArch: Add kprobe support
LoongArch: Add kretprobe support
LoongArch: Mark some assembler symbols as non-kprobe-able samples/kprobes: Add LoongArch support

 arch/loongarch/Kconfig                     |   2 +
 arch/loongarch/include/asm/asm.h           |  10 +
 arch/loongarch/include/asm/inst.h          |  20 ++
 arch/loongarch/include/asm/kprobes.h       |  61 +++++
 arch/loongarch/include/asm/ptrace.h        |   1 +
 arch/loongarch/kernel/Makefile             |   2 +
 arch/loongarch/kernel/entry.S              |   1 +
 arch/loongarch/kernel/inst.c               | 123 +++++++++
 arch/loongarch/kernel/kprobes.c            | 405 +++++++++++++++++++++++++++++
 arch/loongarch/kernel/kprobes_trampoline.S |  96 +++++++
 arch/loongarch/kernel/traps.c              |  11 +-
 arch/loongarch/lib/memcpy.S                |   3 +
 arch/loongarch/mm/fault.c                  |   3 +
 samples/kprobes/kprobe_example.c           |   8 +
 14 files changed, 741 insertions(+), 5 deletions(-)
 create mode 100644 arch/loongarch/include/asm/kprobes.h
 create mode 100644 arch/loongarch/kernel/kprobes.c
 create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S
Signature · 1 line
2.1.0