path: root/arch/arm/kernel/kgdb.c
AgeCommit message (Collapse)AuthorLines
2020-06-17maccess: rename probe_kernel_{read,write} to copy_{from,to}_kernel_nofaultChristoph Hellwig-1/+1
Better describe what these functions do. Suggested-by: Linus Torvalds <> Signed-off-by: Christoph Hellwig <> Signed-off-by: Linus Torvalds <>
2018-12-30kgdb/treewide: constify struct kgdb_arch arch_kgdb_opsChristophe Leroy-1/+1 reports the following: WARNING: struct kgdb_arch should normally be const #28: FILE: arch/mips/kernel/kgdb.c:397: +struct kgdb_arch arch_kgdb_ops = { This report makes sense, as all other ops struct, this one should also be const. This patch does the change. Cc: Vineet Gupta <> Cc: Russell King <> Cc: Catalin Marinas <> Cc: Will Deacon <> Cc: Yoshinori Sato <> Cc: Richard Kuo <> Cc: Michal Simek <> Cc: Ralf Baechle <> Cc: Paul Burton <> Cc: James Hogan <> Cc: Ley Foon Tan <> Cc: Benjamin Herrenschmidt <> Cc: Paul Mackerras <> Cc: Michael Ellerman <> Cc: Rich Felker <> Cc: "David S. Miller" <> Cc: Thomas Gleixner <> Cc: Ingo Molnar <> Cc: Borislav Petkov <> Cc: Acked-by: Daniel Thompson <> Acked-by: Paul Burton <> Signed-off-by: Christophe Leroy <> Acked-by: Borislav Petkov <> Acked-by: Michael Ellerman <> (powerpc) Signed-off-by: Daniel Thompson <>
2018-12-30kgdb: Fix kgdb_roundup_cpus() for arches who used smp_call_function()Douglas Anderson-12/+0
When I had lockdep turned on and dropped into kgdb I got a nice splat on my system. Specifically it hit: DEBUG_LOCKS_WARN_ON(current->hardirq_context) Specifically it looked like this: sysrq: SysRq : DEBUG ------------[ cut here ]------------ DEBUG_LOCKS_WARN_ON(current->hardirq_context) WARNING: CPU: 0 PID: 0 at .../kernel/locking/lockdep.c:2875 lockdep_hardirqs_on+0xf0/0x160 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.19.0 #27 pstate: 604003c9 (nZCv DAIF +PAN -UAO) pc : lockdep_hardirqs_on+0xf0/0x160 ... Call trace: lockdep_hardirqs_on+0xf0/0x160 trace_hardirqs_on+0x188/0x1ac kgdb_roundup_cpus+0x14/0x3c kgdb_cpu_enter+0x53c/0x5cc kgdb_handle_exception+0x180/0x1d4 kgdb_compiled_brk_fn+0x30/0x3c brk_handler+0x134/0x178 do_debug_exception+0xfc/0x178 el1_dbg+0x18/0x78 kgdb_breakpoint+0x34/0x58 sysrq_handle_dbg+0x54/0x5c __handle_sysrq+0x114/0x21c handle_sysrq+0x30/0x3c qcom_geni_serial_isr+0x2dc/0x30c ... ... irq event stamp: ...45 hardirqs last enabled at (...44): [...] __do_softirq+0xd8/0x4e4 hardirqs last disabled at (...45): [...] el1_irq+0x74/0x130 softirqs last enabled at (...42): [...] _local_bh_enable+0x2c/0x34 softirqs last disabled at (...43): [...] irq_exit+0xa8/0x100 ---[ end trace adf21f830c46e638 ]--- Looking closely at it, it seems like a really bad idea to be calling local_irq_enable() in kgdb_roundup_cpus(). If nothing else that seems like it could violate spinlock semantics and cause a deadlock. Instead, let's use a private csd alongside smp_call_function_single_async() to round up the other CPUs. Using smp_call_function_single_async() doesn't require interrupts to be enabled so we can remove the offending bit of code. In order to avoid duplicating this across all the architectures that use the default kgdb_roundup_cpus(), we'll add a "weak" implementation to debug_core.c. Looking at all the people who previously had copies of this code, there were a few variants. I've attempted to keep the variants working like they used to. Specifically: * For arch/arc we passed NULL to kgdb_nmicallback() instead of get_irq_regs(). * For arch/mips there was a bit of extra code around kgdb_nmicallback() NOTE: In this patch we will still get into trouble if we try to round up a CPU that failed to round up before. We'll try to round it up again and potentially hang when we try to grab the csd lock. That's not new behavior but we'll still try to do better in a future patch. Suggested-by: Daniel Thompson <> Signed-off-by: Douglas Anderson <> Cc: Vineet Gupta <> Cc: Russell King <> Cc: Catalin Marinas <> Cc: Will Deacon <> Cc: Richard Kuo <> Cc: Ralf Baechle <> Cc: Paul Burton <> Cc: James Hogan <> Cc: Benjamin Herrenschmidt <> Cc: Paul Mackerras <> Cc: Michael Ellerman <> Cc: Yoshinori Sato <> Cc: Rich Felker <> Cc: "David S. Miller" <> Cc: Thomas Gleixner <> Cc: Ingo Molnar <> Cc: Borislav Petkov <> Cc: "H. Peter Anvin" <> Acked-by: Will Deacon <> Signed-off-by: Daniel Thompson <>
2018-12-30kgdb: Remove irq flags from roundupDouglas Anderson-1/+1
The function kgdb_roundup_cpus() was passed a parameter that was documented as: > the flags that will be used when restoring the interrupts. There is > local_irq_save() call before kgdb_roundup_cpus(). Nobody used those flags. Anyone who wanted to temporarily turn on interrupts just did local_irq_enable() and local_irq_disable() without looking at them. So we can definitely remove the flags. Signed-off-by: Douglas Anderson <> Cc: Vineet Gupta <> Cc: Russell King <> Cc: Catalin Marinas <> Cc: Will Deacon <> Cc: Richard Kuo <> Cc: Ralf Baechle <> Cc: Paul Burton <> Cc: James Hogan <> Cc: Benjamin Herrenschmidt <> Cc: Paul Mackerras <> Cc: Michael Ellerman <> Cc: Yoshinori Sato <> Cc: Rich Felker <> Cc: "David S. Miller" <> Cc: Thomas Gleixner <> Cc: Ingo Molnar <> Cc: Borislav Petkov <> Cc: "H. Peter Anvin" <> Acked-by: Will Deacon <> Signed-off-by: Daniel Thompson <>
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman-0/+1
Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <> Reviewed-by: Philippe Ombredanne <> Reviewed-by: Thomas Gleixner <> Signed-off-by: Greg Kroah-Hartman <>
2017-05-08scripts/spelling.txt: add regsiter -> register spelling mistakeStephen Boyd-1/+1
This typo is quite common. Fix it and add it to the spelling file so that checkpatch catches it earlier. Link: Signed-off-by: Stephen Boyd <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
2015-10-03ARM: 8428/1: kgdb: Fix registers on sleeping tasksDoug Anderson-19/+12
Dumping registers from other sleeping tasks in KGDB was totally failing for me. All registers were reported as 0 in many cases. The code was using task_pt_regs(task) to try to get other thread registers. This doesn't appear to be the right place to look. From my tests, I saw non-zero values in this structure when we were looking at a kernel thread that had a userspace task associated with it, but it contained the register values from the userspace task. So even in the cases where registers weren't reported as 0 we were still not showing the right thing. Instead of using task_pt_regs(task) let's use task_thread_info(task). This is the same place that is referred to when doing a dump of all sleeping task stacks (kdb_show_stack() -> show_stack() -> dump_backtrace() -> unwind_backtrace() -> thread_saved_sp()). As further evidence that this is the right thing to do, you can find the following comment in "gdbstub.c" right before it calls sleeping_thread_to_gdb_regs(): Pull stuff saved during switch_to; nothing else is accessible (or even particularly relevant). This should be enough for a stack trace. ...and if you look at switch_to() it only saves r4-r11, sp and lr. Those are the same registers that I'm getting out of the task_thread_info(). With this change you can use "info thread" to see all tasks in the kernel and you can switch to other tasks and examine them in gdb. Signed-off-by: Doug Anderson <> Tested-by: Stephen Boyd <> Signed-off-by: Russell King <>
2015-09-16ARM: 8425/1: kgdb: Don't try to stop the machine when setting breakpointsDoug Anderson-3/+5
In (23a4e40 arm: kgdb: Handle read-only text / modules) we moved to using patch_text() to set breakpoints so that we could handle the case when we had CONFIG_DEBUG_RODATA. That patch used patch_text(). Unfortunately, patch_text() assumes that we're not in atomic context when it runs since it needs to grab a mutex and also wait for other CPUs to stop (which it does with a completion). This would result in a stack crawl if you had CONFIG_DEBUG_ATOMIC_SLEEP and tried to set a breakpoint in kgdb. The crawl looked something like: BUG: scheduling while atomic: swapper/0/0/0x00010007 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.2.0-rc7-00133-geb63b34 #1073 Hardware name: Rockchip (Device Tree) (unwind_backtrace) from [<c00133d4>] (show_stack+0x20/0x24) (show_stack) from [<c05400e8>] (dump_stack+0x84/0xb8) (dump_stack) from [<c004913c>] (__schedule_bug+0x54/0x6c) (__schedule_bug) from [<c054065c>] (__schedule+0x80/0x668) (__schedule) from [<c0540cfc>] (schedule+0xb8/0xd4) (schedule) from [<c0543a3c>] (schedule_timeout+0x2c/0x234) (schedule_timeout) from [<c05417c0>] (wait_for_common+0xf4/0x188) (wait_for_common) from [<c0541874>] (wait_for_completion+0x20/0x24) (wait_for_completion) from [<c00a0104>] (__stop_cpus+0x58/0x70) (__stop_cpus) from [<c00a0580>] (stop_cpus+0x3c/0x54) (stop_cpus) from [<c00a06c4>] (__stop_machine+0xcc/0xe8) (__stop_machine) from [<c00a0714>] (stop_machine+0x34/0x44) (stop_machine) from [<c00173e8>] (patch_text+0x28/0x34) (patch_text) from [<c001733c>] (kgdb_arch_set_breakpoint+0x40/0x4c) (kgdb_arch_set_breakpoint) from [<c00a0d68>] (kgdb_validate_break_address+0x2c/0x60) (kgdb_validate_break_address) from [<c00a0e90>] (dbg_set_sw_break+0x1c/0xdc) (dbg_set_sw_break) from [<c00a2e88>] (gdb_serial_stub+0x9c4/0xba4) (gdb_serial_stub) from [<c00a11cc>] (kgdb_cpu_enter+0x1f8/0x60c) (kgdb_cpu_enter) from [<c00a18cc>] (kgdb_handle_exception+0x19c/0x1d0) (kgdb_handle_exception) from [<c0016f7c>] (kgdb_compiled_brk_fn+0x30/0x3c) (kgdb_compiled_brk_fn) from [<c00091a4>] (do_undefinstr+0x1a4/0x20c) (do_undefinstr) from [<c001400c>] (__und_svc_finish+0x0/0x34) It turns out that when we're in kgdb all the CPUs are stopped anyway so there's no reason we should be calling patch_text(). We can instead directly call __patch_text() which assumes that CPUs have already been stopped. Fixes: 23a4e4050ba9 ("arm: kgdb: Handle read-only text / modules") Reported-by: Aapo Vienamo <> Signed-off-by: Douglas Anderson <> Reviewed-by: Stephen Boyd <> Acked-by: Kees Cook <> Signed-off-by: Russell King <>
2015-01-09ARM: probes: move all probe code to dedicate directoryWang Nan-2/+1
In discussion on LKML (, Russell King suggests to move all probe related code to arch/arm/probes. This patch does the work. Due to dependency on 'arch/arm/kernel/patch.h', this patch also moves patch.h to 'arch/arm/include/asm/patch.h', and related '#include' directives are also midified to '#include <asm/patch.h>'. Following is an overview of this patch: ./arch/arm/kernel/ ./arch/arm/probes/ |-- Makefile |-- Makefile |-- probes-arm.c ==> |-- decode-arm.c |-- probes-arm.h ==> |-- decode-arm.h |-- probes-thumb.c ==> |-- decode-thumb.c |-- probes-thumb.h ==> |-- decode-thumb.h |-- probes.c ==> |-- decode.c |-- probes.h ==> |-- decode.h | |-- kprobes | | |-- Makefile |-- kprobes-arm.c ==> | |-- actions-arm.c |-- kprobes-common.c ==> | |-- actions-common.c |-- kprobes-thumb.c ==> | |-- actions-thumb.c |-- kprobes.c ==> | |-- core.c |-- kprobes.h ==> | |-- core.h |-- kprobes-test-arm.c ==> | |-- test-arm.c |-- kprobes-test.c ==> | |-- test-core.c |-- kprobes-test.h ==> | |-- test-core.h |-- kprobes-test-thumb.c ==> | `-- test-thumb.c | `-- uprobes | |-- Makefile |-- uprobes-arm.c ==> |-- actions-arm.c |-- uprobes.c ==> |-- core.c |-- uprobes.h ==> `-- core.h | `-- patch.h ==> arch/arm/include/asm/patch.h Signed-off-by: Wang Nan <> Acked-by: Masami Hiramatsu <> Signed-off-by: Jon Medhurst <>
2014-10-16arm: kgdb: Handle read-only text / modulesDoug Anderson-0/+29
Handle the case where someone has set the text segment of the kernel as read-only by using the newly introduced "patch" mechanism. Signed-off-by: Doug Anderson <> [kees: switched structure size check to BUILD_BUG_ON (sboyd)] Signed-off-by: Kees Cook <> Acked-by: Nicolas Pitre <>
2014-08-02ARM: 8124/1: don't enter kgdb when userspace executes a kgdb break instructionOmar Sandoval-0/+4
The kgdb breakpoint hooks (kgdb_brk_fn and kgdb_compiled_brk_fn) should only be entered when a kgdb break instruction is executed from the kernel. Otherwise, if kgdb is enabled, a userspace program can cause the kernel to drop into the debugger by executing either KGDB_BREAKINST or KGDB_COMPILED_BREAK. Acked-by: Will Deacon <> Signed-off-by: Omar Sandoval <> Signed-off-by: Russell King <>
2010-10-29kgdb,arm: fix register dumpRabin Vincent-1/+1
DBG_MAX_REG_NUM incorrectly had the number of indices in the GDB regs array rather than the number of registers, leading to an oops when the "rd" command is used in KDB. Cc: Signed-off-by: Rabin Vincent <> Signed-off-by: Jason Wessel <>
2010-08-14ARM: 6326/1: kgdb: fix GDB_MAX_REGS no longer usederic miao-1/+1
According to commit 22eeef4bb2a7fd225089c0044060ed1fbf091958 kgdb,arm: Individual register get/set for arm It's now replaced by DBG_MAX_REG_NUM. Cc: Jason Wessel <> Signed-off-by: Eric Miao <> Signed-off-by: Russell King <>
2010-08-05arm,kgdb: Add ability to trap into debugger on notify_dieJason Wessel-0/+34
Now that ARM implements the notify die handlers, add the ability for the kernel debugger to receive the notifications. Signed-off-by: Jason Wessel <> CC: Russell King <> CC:
2010-08-05kgdb,arm: Individual register get/set for armJason Wessel-43/+47
Implement the ability to individually get and set registers for kdb and kgdb for arm. Signed-off-by: Jason Wessel <> CC: Russell King <> CC:
2010-05-20kgdb: core changes to support kdbJason Wessel-0/+5
These are the minimum changes to the kgdb core in order to enable an API to connect a new front end (kdb) to the debug core. This patch introduces the dbg_kdb_mode variable controls where the user level I/O is routed. It will be routed to the gdbstub (kgdb) or to the kdb front end which is a simple shell available over the kgdboc connection. You can switch back and forth between kdb or the gdb stub mode of operation dynamically. From gdb stub mode you can blindly type "$3#33", or from the kdb mode you can enter "kgdb" to switch to the gdb stub. The logic in the debug core depends on kdb to look for the typical gdb connection sequences and return immediately with KGDB_PASS_EVENT if a gdb serial command sequence is detected. That should allow a reasonably seamless transition between kdb -> gdb without leaving the kernel exception state. The two gdb serial queries that kdb is responsible for detecting are the "?" and "qSupported" packets. CC: Ingo Molnar <> Signed-off-by: Jason Wessel <> Acked-by: Martin Hicks <>
2010-03-15ARM: 5989/1: ARM: KGDB: add support for SMP platformsWill Deacon-0/+13
To support SMP platforms, KGDB requires the architecture backend to implement the kgdb_roundup_cpus function. This patch, taken against 2.6.33, implements the function for ARM based on the MIPS port. Cc: Jason Wessel <> Cc: Jean-Michel Hautbois <> Cc: KGDB Mailing List <> Signed-off-by: Will Deacon <> Signed-off-by: Russell King <>
2008-09-26kgdb, x86, arm, mips, powerpc: ignore user space single steppingJason Wessel-2/+0
On the x86 arch, user space single step exceptions should be ignored if they occur in the kernel space, such as ptrace stepping through a system call. First check if it is kgdb that is executing a single step, then ensure it is not an accidental traversal into the user space, while in kgdb, any other time the TIF_SINGLESTEP is set, kgdb should ignore the exception. On x86, arm, mips and powerpc, the kgdb_contthread usage was inconsistent with the way single stepping is implemented in the kgdb core. The arch specific stub should always set the kgdb_cpu_doing_single_step correctly if it is single stepping. This allows kgdb to correctly process an instruction steps if ptrace happens to be requesting an instruction step over a system call. Signed-off-by: Jason Wessel <>
2008-07-23kgdb: support for ARCH=armJason Wessel-0/+201
This patch adds the ARCH=arm specific a kgdb backend, originally written by Deepak Saxena <> and George Davis <>. Geoff Levand <>, Nicolas Pitre, Manish Lachwani, and Jason Wessel have contributed various fixups here as well. The KGDB patch makes one change to the core ARM architecture such that the traps are initialized early for use with the debugger or other subsystems. [ small cleanups. ] [ fixed early_trap_init ] Signed-off-by: Jason Wessel <> Acked-by: Deepak Saxena <>