ARM: KDB FIQ debugger
Subsystems (4)
cover ARM: KDB FIQ debugger
Hey all,
Just wanted to try to revive Anton's KDB FIQ patches
which have been sent out a number of times since last October and have gotten almost no response at all.
I've simply updated them to apply to Linus' current HEAD, and figured I'd send them out again to try to spur some interest.
Any feedback would be appreciated!
thanks
-john
Short description of the KDB/FIQ debugger:
The FIQ debugger is a facility that can be used to debug situations when the kernel stuck in uninterruptable sections, e.g. the kernel infinitely loops or deadlocked in an interrupt or with interrupts disabled. On some development boards there is even a special NMI button, which is very useful for debugging weird kernel hangs.
And FIQ is basically an NMI, it has a higher priority than IRQs, and upon IRQ exception FIQs are not disabled. It is still possible to disable FIQs (as well as some "NMIs" on other architectures), but via special means.
Old changelogs and a full rationale for these patches can be found here:
v1-v5, rationale: http://lkml.org/lkml/2012/9/10/2 v6: http://lkml.org/lkml/2012/9/10/2 v7: http://lkml.org/lkml/2012/9/13/367 v8: http://lkml.org/lkml/2012/9/19/525 v9: http://lkml.org/lkml/2012/9/24/538
Anton Vorontsov (3):
ARM: Move some macros from entry-armv to entry-header
ARM: Add KGDB/KDB FIQ debugger generic code
ARM: versatile: Make able to use UART ports for KGDB FIQ debugger
arch/arm/Kconfig | 19 +++++ arch/arm/include/asm/kgdb.h | 7 ++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/entry-armv.S | 169 +----------------------------------- arch/arm/kernel/entry-header.S | 171 +++++++++++++++++++++++++++++++++++++ arch/arm/kernel/kgdb_fiq.c | 118 +++++++++++++++++++++++++ arch/arm/kernel/kgdb_fiq_entry.S | 87 +++++++++++++++++++ arch/arm/mach-versatile/Makefile | 1 + arch/arm/mach-versatile/kgdb_fiq.c | 55 ++++++++++++ 9 files changed, 460 insertions(+), 168 deletions(-) create mode 100644 arch/arm/kernel/kgdb_fiq.c create mode 100644 arch/arm/kernel/kgdb_fiq_entry.S create mode 100644 arch/arm/mach-versatile/kgdb_fiq.c
Signature · 1 line
1.8.1.2
PATCH 1/3 ARM: Move some macros from entry-armv to entry-header
From: Anton Vorontsov <[email protected]>
Just move the macros into header file as we would want to use them for KGDB FIQ entry code.
The following macros were moved:
- svc_entry
- usr_entry
- kuser_cmpxchg_check
- vector_stub
To make kuser_cmpxchg_check actually work across different files, we also have to make kuser_cmpxchg64_fixup global.
--- arch/arm/kernel/entry-armv.S | 169 +--------------------------------------- arch/arm/kernel/entry-header.S | 171 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 168 deletions(-)
arch/arm/kernel/entry-armv.S +1 -168
@@ -136,57 +136,6 @@ common_invalid: b bad_mode ENDPROC(__und_invalid) -/* - * SVC mode handlers - */ - -#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) -#define SPFIX(code...) code -#else -#define SPFIX(code...) -#endif - - .macro svc_entry, stack_hole=0 - UNWIND(.fnstart ) - UNWIND(.save {r0 - pc} ) - sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4) -#ifdef CONFIG_THUMB2_KERNEL - SPFIX( str r0, [sp] ) @ temporarily saved - SPFIX( mov r0, sp ) - SPFIX( tst r0, #4 ) @ test original stack alignment - SPFIX( ldr r0, [sp] ) @ restored -#else - SPFIX( tst sp, #4 ) -#endif - SPFIX( subeq sp, sp, #4 ) - stmia sp, {r1 - r12} - - ldmia r0, {r3 - r5} - add r7, sp, #S_SP - 4 @ here for interlock avoidance - mov r6, #-1 @ "" "" "" "" - add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4) - SPFIX( addeq r2, r2, #4 ) - str r3, [sp, #-4]! @ save the "real" r0 copied - @ from the exception stack - - mov r3, lr - - @ - @ We are now ready to fill in the remaining blanks on the stack: - @ - @ r2 - sp_svc - @ r3 - lr_svc - @ r4 - lr_<exception>, already fixed up for correct return/restart - @ r5 - spsr_<exception> - @ r6 - orig_r0 (see pt_regs definition in ptrace.h) - @ - stmia r7, {r2 - r6} - -#ifdef CONFIG_TRACE_IRQFLAGS - bl trace_hardirqs_off -#endif - .endm - .align 5 __dabt_svc: svc_entry
@@ -305,72 +254,7 @@ ENDPROC(__pabt_svc) /* * User mode handlers - * - * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE */ - -#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7) -#error "sizeof(struct pt_regs) must be a multiple of 8" -#endif - - .macro usr_entry - UNWIND(.fnstart ) - UNWIND(.cantunwind ) @ don't unwind the user space - sub sp, sp, #S_FRAME_SIZE - ARM( stmib sp, {r1 - r12} ) - THUMB( stmia sp, {r0 - r12} ) - - ldmia r0, {r3 - r5} - add r0, sp, #S_PC @ here for interlock avoidance - mov r6, #-1 @ "" "" "" "" - - str r3, [sp] @ save the "real" r0 copied - @ from the exception stack - - @ - @ We are now ready to fill in the remaining blanks on the stack: - @ - @ r4 - lr_<exception>, already fixed up for correct return/restart - @ r5 - spsr_<exception> - @ r6 - orig_r0 (see pt_regs definition in ptrace.h) - @ - @ Also, separately save sp_usr and lr_usr - @ - stmia r0, {r4 - r6} - ARM( stmdb r0, {sp, lr}^ ) - THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) - - @ - @ Enable the alignment trap while in kernel mode - @ - alignment_trap r0 - - @ - @ Clear FP to mark the first stack frame - @ - zero_fp - -#ifdef CONFIG_IRQSOFF_TRACER - bl trace_hardirqs_off -#endif - ct_user_exit save = 0 - .endm - - .macro kuser_cmpxchg_check -#if !defined(CONFIG_CPU_32v6K) && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) -#ifndef CONFIG_MMU -#warning "NPTL on non MMU needs fixing" -#else - @ Make sure our user space atomic helper is restarted - @ if it was interrupted in a critical region. Here we - @ perform a quick test inline since it should be false - @ 99.9999% of the time. The rest is done out of line. - cmp r4, #TASK_SIZE - blhs kuser_cmpxchg64_fixup -#endif -#endif - .endm - .align 5 __dabt_usr: usr_entry
@@ -803,6 +687,7 @@ __kuser_cmpxchg64: @ 0xffff0f60 ldmfd sp!, {r4, r5, r6, pc} .text + .global kuser_cmpxchg64_fixup kuser_cmpxchg64_fixup: @ Called from kuser_cmpxchg_fixup. @ r4 = address of interrupted insn (must be preserved).
@@ -933,58 +818,6 @@ __kuser_helper_end: THUMB( .thumb ) -/* - * Vector stubs. - * - * This code is copied to 0xffff0200 so we can use branches in the - * vectors, rather than ldr's. Note that this code must not - * exceed 0x300 bytes. - * - * Common stub entry macro: - * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC - * - * SP points to a minimal amount of processor-private memory, the address - * of which is copied into r0 for the mode specific abort handler. - */ - .macro vector_stub, name, mode, correction=0 - .align 5 - -vector_\name: - .if \correction - sub lr, lr, #\correction - .endif - - @ - @ Save r0, lr_<exception> (parent PC) and spsr_<exception> - @ (parent CPSR) - @ - stmia sp, {r0, lr} @ save r0, lr - mrs lr, spsr - str lr, [sp, #8] @ save spsr - - @ - @ Prepare for SVC32 mode. IRQs remain disabled. - @ - mrs r0, cpsr - eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) - msr spsr_cxsf, r0 - - @ - @ the branch table must immediately follow this code - @ - and lr, lr, #0x0f - THUMB( adr r0, 1f ) - THUMB( ldr lr, [r0, lr, lsl #2] ) - mov r0, sp - ARM( ldr lr, [pc, lr, lsl #2] ) - movs pc, lr @ branch to handler in SVC mode -ENDPROC(vector_\name) - - .align 2 - @ handler addresses follow this label -1: - .endm - .globl __stubs_start __stubs_start: /*
arch/arm/kernel/entry-header.S +171 -0
183 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 2/3 ARM: Add KGDB/KDB FIQ debugger generic code
In reply to John StultzFrom: Anton Vorontsov <[email protected]>
The FIQ debugger may be used to debug situations when the kernel stuck in uninterruptable sections, e.g. the kernel infinitely loops or deadlocked in an interrupt or with interrupts disabled.
By default KGDB FIQ is disabled in runtime, but can be enabled with kgdb_fiq.enable=1 kernel command line option.
--- arch/arm/Kconfig | 18 ++++++ arch/arm/include/asm/kgdb.h | 7 +++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/kgdb_fiq.c | 118 +++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/kgdb_fiq_entry.S | 87 +++++++++++++++++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 arch/arm/kernel/kgdb_fiq.c create mode 100644 arch/arm/kernel/kgdb_fiq_entry.S
arch/arm/Kconfig +18 -0
@@ -203,6 +203,24 @@ config GENERIC_ISA_DMA config FIQ bool +config ARCH_MIGHT_HAVE_KGDB_FIQ + bool + +config KGDB_FIQ + bool "KGDB/KDB FIQ debugger" + depends on KGDB_KDB && ARCH_MIGHT_HAVE_KGDB_FIQ && !THUMB2_KERNEL + select FIQ + help + The FIQ debugger may be used to debug situations when the + kernel stuck in uninterruptable sections, e.g. the kernel + infinitely loops or deadlocked in an interrupt or with + interrupts disabled. + + By default KGDB FIQ is disabled in runtime, but can be + enabled with kgdb_fiq.enable=1 kernel command line option. + + If unsure, say N. + config NEED_RET_TO_USER bool
arch/arm/include/asm/kgdb.h +7 -0
@@ -11,6 +11,8 @@#define __ARM_KGDB_H__#include <linux/ptrace.h> +#include <linux/linkage.h> +#include <asm/exception.h> /* * GDB assumes that we're a user process being debugged, so
@@ -47,6 +49,11 @@ static inline void arch_kgdb_breakpoint(void)extern void kgdb_handle_bus_error (void );extern int kgdb_fault_expected; +extern char kgdb_fiq_handler; +extern char kgdb_fiq_handler_end; +asmlinkage void __exception_irq_entry kgdb_fiq_do_handle(struct pt_regs *regs); +extern int __init kgdb_register_fiq (void (*mach_kgdb_enable_fiq)(bool on), +bool (*mach_is_kgdb_fiq)(void ));#endif /* !__ASSEMBLY__ */ /*
arch/arm/kernel/Makefile +1 -0
@@ -56,6 +56,7 @@ endif obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_KGDB) += kgdb.o +obj-$(CONFIG_KGDB_FIQ) += kgdb_fiq_entry.o kgdb_fiq.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o obj-$(CONFIG_OF) += devtree.o
arch/arm/kernel/kgdb_fiq.c new file +118 -0
118 lines not on this page · raw message
arch/arm/kernel/kgdb_fiq_entry.S new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 3/3 ARM: versatile: Make able to use UART ports for KGDB FIQ debugger
In reply to John StultzFrom: Anton Vorontsov <[email protected]>
If enabled, kernel will able to enter KGDB upon serial line activity on UART ports.
Note that even with this patch and CONFIG_KGDB_FIQ is enabled, you still need to pass kgdb_fiq.enable=1 kernel command line option, otherwise UART will behave in a normal way.
By default UART0 is used, but this can be changed via kgdb_fiq.uart_num kernel command line option.
--- arch/arm/Kconfig | 1 + arch/arm/mach-versatile/Makefile | 1 + arch/arm/mach-versatile/kgdb_fiq.c | 55 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 arch/arm/mach-versatile/kgdb_fiq.c
arch/arm/Kconfig +1 -0
@@ -364,6 +364,7 @@ config ARCH_VERSATILE select PLAT_VERSATILE_CLCD select PLAT_VERSATILE_CLOCK select VERSATILE_FPGA_IRQ + select ARCH_MIGHT_HAVE_KGDB_FIQ help This enables support for ARM Ltd Versatile board.
arch/arm/mach-versatile/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_ARCH_VERSATILE_PB) += versatile_pb.o obj-$(CONFIG_MACH_VERSATILE_AB) += versatile_ab.o obj-$(CONFIG_MACH_VERSATILE_DT) += versatile_dt.o obj-$(CONFIG_PCI) += pci.o +obj-$(CONFIG_KGDB_FIQ) += kgdb_fiq.o
arch/arm/mach-versatile/kgdb_fiq.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Re: [PATCH 3/3] ARM: versatile: Make able to use UART ports for KGDB FIQ debugger
Dear John Stultz,
Quoted 7 lines · John Stultz
arch/arm/mach-versatile/kgdb_fiq.c new file +7
-0+static void kgdb_fiq_select (bool on) +{ +void __iomem *sel = kgdb_irq_base +VIC_INT_SELECT ; +u32 msk =1 << kgdb_irq; +u32 val; + + pr_debug("rerouting VIC vector %d to %s\n", kgdb_irq,
arch/arm/mach-versatile/kgdb_fiq.c line 42
Quoted 10 lines
arch/arm/mach-versatile/kgdb_fiq.c new file +10
-0+ on ? "FIQ" : "IRQ"); + + val =readl (sel); + val &= ~msk; +if (on) + val |= msk; +writel (val, sel); +} + +static bool kgdb_is_fiq_rised (void )
Shouldn't this function be kgdb_is_fiq_raised() ?
arch/arm/mach-versatile/kgdb_fiq.c line 55
Quoted 13 lines
arch/arm/mach-versatile/kgdb_fiq.c new file +13
-0+{ +return readl (kgdb_irq_base +VIC_FIQ_STATUS ) & (1 << kgdb_irq); +} + +static int __init kgdb_fiq_init (void ) +{ + kgdb_irq_base =__io_address (VERSATILE_VIC_BASE ); + kgdb_irq +=INT_UARTINT0 ; +WARN_ON (kgdb_irq >INT_UARTINT2 ); + +return kgdb_register_fiq (kgdb_fiq_select, kgdb_is_fiq_rised); +} +console_initcall (kgdb_fiq_init);
Also, this code that uses hardcoded addresses and IRQ numbers doesn't seem to play really well with the DT. I was considering toying around with this thing on the mach-mvebu platform, but don't have those hardcoded addresses and IRQs, and the register offsets of the IRQ controller driver are not exposed in an header file. Shouldn't IRQ controller driver be exposing a the fiq_select() functionality instead? Like a new flag for irq_chip->irq_set_type(), or a completely new hook irq_chip->irq_set_mode() or something like that?
Best regards,
Thomas
Signature · 4 lines
Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com
Re: [PATCH 3/3] ARM: versatile: Make able to use UART ports for KGDB FIQ debugger
Thanks a lot for the review, Thomas!
On Fri, May 10, 2013 at 04:17:10PM +0200, Thomas Petazzoni wrote:
[...]
Quoted 14 lines
arch/arm/mach-versatile/kgdb_fiq.c line 55
Quoted 13 lines
arch/arm/mach-versatile/kgdb_fiq.c new file +13
-0+{ +return readl (kgdb_irq_base +VIC_FIQ_STATUS ) & (1 << kgdb_irq); +} + +static int __init kgdb_fiq_init (void ) +{ + kgdb_irq_base =__io_address (VERSATILE_VIC_BASE ); + kgdb_irq +=INT_UARTINT0 ; +WARN_ON (kgdb_irq >INT_UARTINT2 ); + +return kgdb_register_fiq (kgdb_fiq_select, kgdb_is_fiq_rised); +} +console_initcall (kgdb_fiq_init);
Quoted 8 lines
Also, this code that uses hardcoded addresses and IRQ numbers doesn't seem to play really well with the DT. I was considering toying around with this thing on the mach-mvebu platform, but don't have those hardcoded addresses and IRQs, and the register offsets of the IRQ controller driver are not exposed in an header file. Shouldn't IRQ controller driver be exposing a the
fiq_select()functionality instead? Like a new flag forirq_chip->irq_set_type(), or a completely new hookirq_chip->irq_set_mode()or something like that?
FIQs are very specific to the platform, and I doubt that anyone will be happy in exposing this kind of knowledge to the generic subsystem.
Moreover, Russell King once said that we should better detach IRQ stuff from FIQs altogether. Thing is, FIQs are not going through the generic IRQ code flow, so there is actually very little point in managing them thru the generic IRQ subsystem.
What seems more plausible is making a "FIQ subsystem", and register each IRQ controller that can redirect its sources to FIQ with that new subsystem. But the "subsystem" isn't there, and even doing some cleanups in this core stuff takes forever to review/make decision. :) Plus, writing it for this small thing seems like a bit of overhead.
And if you take a closer look at this patch, it actually does not use IRQ numbers with the IRQ subsystem. Instead, it bypasses the whole thing and writes to the VIC registers directly.
So, for your case (if you want to use FIQ debugger on your board), I would suggest doing the same. At least until we figure out how to do these ten lines of board-specific code better (ideas/hints are welcome! :)
Thanks!
Anton