kernel-ark/arch/mips/kernel
James Hogan 162b270c66 MIPS: KGDB: Use kernel context for sleeping threads
KGDB is a kernel debug stub and it can't be used to debug userland as it
can only safely access kernel memory.

On MIPS however KGDB has always got the register state of sleeping
processes from the userland register context at the beginning of the
kernel stack. This is meaningless for kernel threads (which never enter
userland), and for user threads it prevents the user seeing what it is
doing while in the kernel:

(gdb) info threads
  Id   Target Id         Frame
  ...
  3    Thread 2 (kthreadd) 0x0000000000000000 in ?? ()
  2    Thread 1 (init)   0x000000007705c4b4 in ?? ()
  1    Thread -2 (shadowCPU0) 0xffffffff8012524c in arch_kgdb_breakpoint () at arch/mips/kernel/kgdb.c:201

Get the register state instead from the (partial) kernel register
context stored in the task's thread_struct for resume() to restore. All
threads now correctly appear to be in context_switch():

(gdb) info threads
  Id   Target Id         Frame
  ...
  3    Thread 2 (kthreadd) context_switch (rq=<optimized out>, cookie=..., next=<optimized out>, prev=0x0) at kernel/sched/core.c:2903
  2    Thread 1 (init)   context_switch (rq=<optimized out>, cookie=..., next=<optimized out>, prev=0x0) at kernel/sched/core.c:2903
  1    Thread -2 (shadowCPU0) 0xffffffff8012524c in arch_kgdb_breakpoint () at arch/mips/kernel/kgdb.c:201

Call clobbered registers which aren't saved and exception registers
(BadVAddr & Cause) which can't be easily determined without stack
unwinding are reported as 0. The PC is taken from the return address,
such that the state presented matches that found immediately after
returning from resume().

Fixes: 8854700115 ("[MIPS] kgdb: add arch support for the kernel's kgdb core")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/15829/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-04-12 22:29:22 +02:00
..
.gitignore
8250-platform.c
asm-offsets.c MIPS: IRQ Stack: Unwind IRQ stack onto task stack 2017-03-22 11:53:57 +01:00
binfmt_elfn32.c fs/binfmt: Convert obsolete cputime type to nsecs 2017-02-01 09:13:51 +01:00
binfmt_elfo32.c fs/binfmt: Convert obsolete cputime type to nsecs 2017-02-01 09:13:51 +01:00
bmips_5xxx_init.S MIPS: BMIPS: Make whitespacely correct. 2016-05-09 12:00:01 +02:00
bmips_vec.S MIPS: BMIPS: Add Whirlwind (BMIPS5200) initialization code 2016-05-09 12:00:01 +02:00
branch.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
cacheinfo.c MIPS: Fix cacheinfo overflow 2017-02-13 18:57:34 +00:00
cevt-bcm1480.c
cevt-ds1287.c
cevt-gt641xx.c
cevt-r4k.c MIPS: cevt-r4k: Fix out-of-bounds array access 2017-04-10 13:31:12 +02:00
cevt-sb1250.c
cevt-txx9.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
cps-vec-ns16550.S
cps-vec.S MIPS: smp-cps: Fix retrieval of VPE mask on big endian CPUs 2017-03-21 20:39:40 +01:00
cpu-bugs64.c MIPS: Fix printk continuations in cpu-bugs64.c 2017-01-24 18:30:34 +01:00
cpu-probe.c MIPS: Add MIPS_CPU_FTLB for Loongson-3A R2 2017-03-21 21:51:26 +01:00
crash_dump.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
crash.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
csrc-bcm1480.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-ioasic.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-r4k.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-sb1250.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
early_printk_8250.c
early_printk.c
elf.c MIPS: Avoid BUG warning in arch_check_elf 2017-04-12 15:22:13 +02:00
entry.S MIPS: Remove r2_emul_return from struct thread_info 2017-01-03 16:34:41 +01:00
ftrace.c ftrace: Add return address pointer to ftrace_ret_stack 2016-08-24 12:15:14 +02:00
genex.S MIPS: IRQ Stack: Unwind IRQ stack onto task stack 2017-03-22 11:53:57 +01:00
gpio_txx9.c
head.S MIPS: store the appended dtb address in a variable 2016-08-02 14:00:16 +02:00
i8253.c
idle.c MIPS: Loongson: Add Loongson-3A R2 basic support 2016-05-13 14:02:14 +02:00
irq_txx9.c
irq-gt641xx.c
irq-msc01.c
irq-rm7000.c
irq.c MIPS: Introduce irq_stack 2017-01-03 16:34:34 +01:00
jump_label.c
kgdb.c MIPS: KGDB: Use kernel context for sleeping threads 2017-04-12 22:29:22 +02:00
kprobes.c MIPS: tracing: disable uprobe/kprobe on compact branch instructions 2016-10-06 17:37:40 +02:00
linux32.c MIPS: Return directly in 32_mmap2() 2017-01-25 02:51:11 +01:00
machine_kexec.c MIPS: kexec: add debug info about the new kexec'ed image 2017-01-03 16:34:46 +01:00
Makefile MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
mcount.S MIPS: Export _mcount alongside its definition 2017-01-03 16:34:49 +01:00
mips_machine.c
mips-cm.c tree-wide: replace config_enabled() with IS_ENABLED() 2016-08-04 08:50:07 -04:00
mips-cpc.c MIPS: CPC: Provide default mips_cpc_default_phys_base to ignore CPC 2016-11-04 00:17:46 +01:00
mips-mt-fpaff.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task.h> 2017-03-02 08:42:35 +01:00
mips-mt.c
mips-r2-to-r6-emul.c MIPS: R2-on-R6 MULTU/MADDU/MSUBU emulation bugfix 2017-01-03 16:34:41 +01:00
module-rela.c MIPS: module: fix incorrect IS_ERR_VALUE macro usages 2016-05-13 14:02:11 +02:00
module.c MIPS: Migrate exception table users off module.h and onto extable.h 2016-10-04 16:13:57 +02:00
octeon_switch.S
perf_event_mipsxx.c MIPS: perf: fix deadlock 2017-04-10 12:25:07 +02:00
perf_event.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
pm-cps.c cpu/hotplug: Cleanup state names 2016-12-25 10:47:44 +01:00
pm.c MIPS: Fix watchpoint restoration 2016-05-09 12:00:02 +02:00
probes-common.h MIPS: tracing: disable uprobe/kprobe on compact branch instructions 2016-10-06 17:37:40 +02:00
proc.c MIPS: Move identification of VP(E) into proc.c from smp-mt.c 2016-10-04 16:13:57 +02:00
process.c MIPS: IRQ Stack: Unwind IRQ stack onto task stack 2017-03-22 11:53:57 +01:00
prom.c MIPS: Use early_init_fdt_reserve_self to protect DTB location 2017-01-03 16:34:45 +01:00
ptrace32.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
ptrace.c Merge branch 'regset' (PTRACE_SETREGSET data leakage) 2017-03-29 08:55:25 -07:00
r4k_fpu.S MIPS: Use copy_s.fmt rather than copy_u.fmt 2016-05-09 12:00:04 +02:00
r4k_switch.S MIPS: Export _save_fp & _save_msa alongside their definitions 2017-01-03 16:34:49 +01:00
r2300_fpu.S MIPS: Correct MIPS I FP sigcontext layout 2016-11-04 01:39:23 +01:00
r2300_switch.S MIPS: Export _save_fp & _save_msa alongside their definitions 2017-01-03 16:34:49 +01:00
r6000_fpu.S MIPS: Fix ISA I/II FP signal context offsets 2016-11-04 01:38:52 +01:00
relocate_kernel.S
relocate.c MIPS: KASLR: Add missing header files 2017-04-12 17:02:04 +02:00
reset.c
rtlx-cmp.c
rtlx-mt.c
rtlx.c sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
scall32-o32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-64.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-n32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-o32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
segment.c MIPS: Print segment physical address when EU=1 2016-07-28 11:44:30 +02:00
setup.c MIPS: kexec: Do not reserve invalid crashkernel memory on boot 2017-01-03 16:34:46 +01:00
signal32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal_n32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal_o32.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
signal-common.h
signal.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-08-06 09:13:11 -04:00
smp-bmips.c MIPS: Add missing include files 2017-03-08 10:38:06 +01:00
smp-cmp.c
smp-cps.c MIPS: smp-cps: Fix potentially uninitialised value of core 2017-04-12 21:34:30 +02:00
smp-mt.c MIPS: Add missing include files 2017-03-08 10:38:06 +01:00
smp-up.c
smp.c sched/headers: Prepare to remove the <linux/mm_types.h> dependency from <linux/sched.h> 2017-03-02 08:42:37 +01:00
spinlock_test.c
spram.c MIPS: Add P6600 cases to CPU switch statements 2016-05-13 14:01:52 +02:00
stacktrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
sync-r4k.c MIPS: sync-r4k: Fix KERN_CONT fallout 2017-02-13 18:58:39 +00:00
syscall.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
sysrq.c
time.c MIPS: Return -ENODEV from weak implementation of rtc_mips_set_time 2016-12-11 11:19:04 +01:00
topology.c
traps.c MIPS: Check TLB before handle_ri_rdhwr() for Loongson-3 2017-03-21 21:52:54 +01:00
unaligned.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
uprobes.c MIPS: uprobes: Remove __weak attribute from arch_uprobe_copy_ixol. 2017-01-03 16:34:48 +01:00
vdso.c userfaultfd: non-cooperative: add event for memory unmaps 2017-02-24 17:46:55 -08:00
vmlinux.lds.S MIPS: Ensure bss section ends on a long-aligned address 2017-01-03 16:34:36 +01:00
vpe-cmp.c
vpe-mt.c
vpe.c
watch.c MIPS: Add and use watch register field definitions 2016-05-13 14:02:13 +02:00