linux/arch/mips/kernel
Tiezhu Yang 7c86ff9925 MIPS: Add basic support for ptrace single step
In the current code, arch_has_single_step() is not defined on MIPS,
that means MIPS does not support instruction single-step for user mode.

Delve is a debugger for the Go programming language, the ptrace syscall
PtraceSingleStep() failed [1] on MIPS and then the single step function
can not work well, we can see that PtraceSingleStep() definition returns
ptrace(PTRACE_SINGLESTEP) [2].

So it is necessary to support ptrace single step on MIPS.

At the beginning, we try to use the Debug Single Step exception on the
Loongson 3A4000 platform, but it has no effect when set CP0_DEBUG SSt
bit, this is because CP0_DEBUG NoSSt bit is 1 which indicates no
single-step feature available [3], so this way which is dependent on the
hardware is almost impossible.

With further research, we find out there exists a common way used with
break instruction in arch/alpha/kernel/ptrace.c, it is workable.

For the above analysis, define arch_has_single_step(), add the common
function user_enable_single_step() and user_disable_single_step(), set
flag TIF_SINGLESTEP for child process, use break instruction to set
breakpoint.

We can use the following testcase to test it:
tools/testing/selftests/breakpoints/step_after_suspend_test.c

 $ make -C tools/testing/selftests TARGETS=breakpoints
 $ cd tools/testing/selftests/breakpoints

Without this patch:

 $ ./step_after_suspend_test -n
 TAP version 13
 1..4
 # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
 ok 1 # SKIP CPU 0
 # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
 ok 2 # SKIP CPU 1
 # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
 ok 3 # SKIP CPU 2
 # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
 ok 4 # SKIP CPU 3
 # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:4 error:0

With this patch:

 $ ./step_after_suspend_test -n
 TAP version 13
 1..4
 ok 1 CPU 0
 ok 2 CPU 1
 ok 3 CPU 2
 ok 4 CPU 3
 # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0

[1] https://github.com/go-delve/delve/blob/master/pkg/proc/native/threads_linux.go#L50
[2] https://github.com/go-delve/delve/blob/master/vendor/golang.org/x/sys/unix/syscall_linux.go#L1573
[3] http://www.t-es-t.hu/download/mips/md00047f.pdf

Reported-by: Guoqi Chen <chenguoqi@loongson.cn>
Signed-off-by: Xingxing Su <suxingxing@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
2021-02-13 09:49:19 +01:00
..
syscalls MIPS: UAPI: unexport unistd_nr_{n32,n64,o32}.h 2021-01-07 17:14:56 +01:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
asm-offsets.c
binfmt_elfn32.c y2038: elfcore: Use __kernel_old_timeval for process times 2019-11-15 14:38:29 +01:00
binfmt_elfo32.c y2038: elfcore: Use __kernel_old_timeval for process times 2019-11-15 14:38:29 +01:00
bmips_5xxx_init.S
bmips_vec.S
branch.c MIPS: kernel: include probes-common.h header in branch.c 2020-09-21 22:14:24 +02:00
cacheinfo.c mips: cacheinfo: Remove unnecessary increment of level 2021-01-27 21:48:23 +01:00
cevt-bcm1480.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-ds1287.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-gt641xx.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-r4k.c mips: cevt-r4k: Update the r4k-clockevent frequency in sync with CPU 2020-05-22 09:14:32 +02:00
cevt-sb1250.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-txx9.c mips: kernel: convert comma to semicolon 2020-12-28 22:32:28 +01:00
cmpxchg.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
cps-vec-ns16550.S mips: Add CPS_NS16550_WIDTH config 2020-05-22 09:12:52 +02:00
cps-vec.S MIPS: CPS: don't create redundant .text.cps-vec section 2021-01-15 15:27:54 +01:00
cpu-probe.c Revert "MIPS: Remove unused R4300 CPU support" 2021-01-22 11:39:45 +01:00
cpu-r3k-probe.c MIPS: cpu-probe: introduce exclusive R3k CPU probe 2020-10-12 12:05:16 +02:00
crash.c
crash_dump.c MIPS: crash_dump.c: Simplify copy_oldmem_page() 2021-02-09 13:30:12 +01:00
csrc-bcm1480.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
csrc-ioasic.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
csrc-r4k.c mips: csrc-r4k: Mark R4K timer as unstable if CPU freq changes 2020-05-22 09:14:06 +02:00
csrc-sb1250.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
early_printk.c
early_printk_8250.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
elf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
entry.S mips: Add MIPS Release 5 support 2020-05-22 09:09:01 +02:00
fpu-probe.c MIPS: cpu-probe: move fpu probing/handling into its own file 2020-10-12 12:04:50 +02:00
fpu-probe.h MIPS: cpu-probe: move fpu probing/handling into its own file 2020-10-12 12:04:50 +02:00
ftrace.c MIPS: ftrace: Remove redundant #ifdef CONFIG_DYNAMIC_FTRACE 2020-08-17 13:00:24 +02:00
genex.S MIPS: Make check condition for SDBBP consistent with EJTAG spec 2021-02-11 11:04:31 +01:00
gpio_txx9.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
head.S MIPS: of: Introduce helper function to get DTB 2021-02-04 13:34:51 +01:00
i8253.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
idle.c Revert "MIPS: Remove unused R4300 CPU support" 2021-01-22 11:39:45 +01:00
irq-gt641xx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
irq-msc01.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
irq.c
irq_txx9.c
jump_label.c
kgdb.c
kprobes.c mips: kprobes: Use generic kretprobe trampoline handler 2020-09-08 11:52:33 +02:00
linux32.c
machine_kexec.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
Makefile MIPS: kernel: Support extracting off-line stack traces from user-space with perf 2021-02-04 21:55:45 +01:00
mcount.S
mips-cm.c mips: cm: add missing iounmap() on error in mips_cm_probe() 2020-11-06 11:33:11 +01:00
mips-cpc.c remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
mips-mt-fpaff.c MIPS: Use rcu to lookup a task in mipsmt_sys_sched_setaffinity() 2020-09-03 10:13:43 +02:00
mips-mt.c
mips-r2-to-r6-emul.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
module.c MIPS: module: optimize module relocations processing 2021-01-18 15:55:16 +01:00
octeon_switch.S
perf_event.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
perf_event_mipsxx.c MIPS: perf: Add support for OCTEON III perf events. 2021-01-04 11:32:57 +01:00
perf_regs.c MIPS: kernel: Support extracting off-line stack traces from user-space with perf 2021-02-04 21:55:45 +01:00
pm-cps.c MIPS: barrier: Add __SYNC() infrastructure 2019-10-07 09:42:17 -07:00
pm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
probes-common.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
proc.c mips: Add MIPS Release 5 support 2020-05-22 09:09:01 +02:00
process.c Revert "MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op" 2021-02-09 17:12:34 +01:00
prom.c MIPS: replace add_memory_region with memblock 2020-10-12 12:01:36 +02:00
ptrace.c MIPS: Add basic support for ptrace single step 2021-02-13 09:49:19 +01:00
ptrace32.c mm: don't include asm/pgtable.h if linux/mm.h is already included 2020-06-09 09:39:13 -07:00
r4k-bugs64.c MIPS: r4k-bugs64: Drop CONFIG_CPU_MIPSR6 checks 2019-10-07 09:38:54 -07:00
r4k_fpu.S mips: Add MIPS Release 5 support 2020-05-22 09:09:01 +02:00
r4k_switch.S
r2300_fpu.S
r2300_switch.S
relocate.c MIPS: relocatable: Use __kaslr_offset in show_kernel_relocation 2021-02-09 10:56:04 +01:00
relocate_kernel.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
reset.c
rtlx-cmp.c
rtlx-mt.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
rtlx.c
scall32-o32.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-n32.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-n64.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-o32.S MIPS: asm: Rename some macros to avoid build errors 2020-05-07 13:20:05 +02:00
segment.c
setup.c Revert "mips: Manually call fdt_init_reserved_mem() method" 2021-02-09 13:28:13 +01:00
signal-common.h
signal.c MIPS: Add basic support for ptrace single step 2021-02-13 09:49:19 +01:00
signal32.c
signal_n32.c Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
signal_o32.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
smp-bmips.c MIPS: No need to check CPU 0 in {loongson3,bmips,octeon}_cpu_disable() 2020-11-27 10:38:12 +01:00
smp-cmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
smp-cps.c MIPS: No need to check CPU 0 in cps_cpu_disable() 2020-12-28 22:34:09 +01:00
smp-mt.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
smp-up.c
smp.c arch: mips: kernel: Fix two spelling in smp.c 2021-02-03 11:33:48 +01:00
spinlock_test.c
spram.c mips: Add CONFIG/CONFIG6/Cause reg fields macro 2020-05-22 09:12:22 +02:00
stacktrace.c
sync-r4k.c MIPS: sync-r4k: do slave counter synchronization with disabled HW interrupts 2020-01-22 10:16:18 -08:00
syscall.c MIPS: Convert R10000_LLSC_WAR info a config option 2020-09-07 22:24:27 +02:00
sysrq.c MIPS: constify sysrq_key_op 2020-05-15 14:53:19 +02:00
time.c mips: Add udelay lpj numbers adjustment 2020-05-22 09:13:32 +02:00
topology.c MIPS: CPU#0 is not hotpluggable 2020-07-26 10:18:35 +02:00
traps.c MIPS updates for v5.10: 2020-10-16 12:40:55 -07:00
unaligned.c uaccess: add force_uaccess_{begin,end} helpers 2020-08-12 10:57:59 -07:00
uprobes.c MIPS: uprobes: remove set but not used variable 'epc' 2019-05-29 13:20:30 -07:00
vdso.c MIPS: vdso: Use vma page protection for remapping 2020-11-19 13:26:38 +01:00
vmlinux.lds.S MIPS: vmlinux.lds.S: explicitly declare .got table 2021-01-15 15:27:54 +01:00
vpe-cmp.c mips: pci: convert comma to semicolon 2020-12-28 22:33:43 +01:00
vpe-mt.c mips: kernel: convert comma to semicolon 2020-12-28 22:32:28 +01:00
vpe.c MIPS: vpe: Remove vpe_getcwd 2021-01-27 21:49:16 +01:00
watch.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00