kgdb: Fixes and regression tests
Subsystems (4)
Jason Wessel
maintainercover kgdb: Fixes and regression tests
To aid in the porting of additional archs for kgdb as well as to continue to check that new changes have not broken kgdb, a kgdb test suite has been created. The objective is to test the kgdb core and some features of the arch support such as SW/HW breakpoints, SMP concurrency, single stepping and the NMI watch dog.
By default the kgdb test suite would not be compiled into the kernel. It main purpose is to test kgdb internals.
Running the regression tests against kgdb has found several problems. The first patch in the series addresses the regressions found from running the kgdb test suite. The second patch in the series is the kgdb test suite itself.
Jason.
The following changes since commit 9b747d4ea3c90a5cda4e295bd0c1257eba3091ca:
Jason Wessel (1):
kgdb: support for ARCH=arm
are available in the git repository at:
master.kernel.org:/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb.git for_ingo
Jason Wessel (2):
kgdb: fix several kgdb regressions
kgdb: Add kgdb internal test suite
arch/x86/kernel/kgdb.c | 4 + arch/x86/kernel/traps_64.c | 7 +- drivers/misc/Makefile | 1 + drivers/misc/kgdbts.c | 1083 ++++++++++++++++++++++++++++++++++++++++++++ kernel/kgdb.c | 14 +- lib/Kconfig.kgdb | 13 + 6 files changed, 1115 insertions(+), 7 deletions(-) create mode 100644 drivers/misc/kgdbts.c
Jason Wessel
maintainerPATCH 1/2 kgdb: fix several kgdb regressions
kgdb core fixes:
- Check to see that mm->mmap_cache is not null before calling flush_cache_range(), else on arch=ARM it will cause a fatal fault.
- Breakpoints should only be restored if they are in the BP_ACTIVE state.
- Fix a typo in comments to "kgdb_register_io_module"
x86 kgdb fixes:
- Fix the x86 arch handler such that on a kill or detach that the appropriate cleanup on the single stepping flags gets run.
- Add in the DIE_NMIWATCHDOG call for x86_64
- Touch the nmi watchdog before returning the system to normal operation after performing any kind of kgdb operation, else the possibility exists to trigger the watchdog.
--- arch/x86/kernel/kgdb.c | 4 ++++ arch/x86/kernel/traps_64.c | 7 ++++++- kernel/kgdb.c | 14 ++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-)
arch/x86/kernel/kgdb.c +4 -0
@@ -370,6 +370,8 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code, ptr = &remcomInBuffer[1 ];if (kgdb_hex2long (&ptr, &addr)) linux_regs->ip = addr; +case 'D' : +case 'k' : newPC = linux_regs->ip;/* clear the trace bit */
@@ -480,6 +482,8 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)if (kgdb_handle_exception (args->trapnr, args->signr, args->err, regs))return NOTIFY_DONE ; +/* Must touch watchdog before return to normal operation */ +touch_nmi_watchdog ();return NOTIFY_STOP ; }
arch/x86/kernel/traps_64.c +6 -1
@@ -600,8 +600,13 @@ void die(const char * str, struct pt_regs * regs, long err)void __kprobes die_nmi (char *str,struct pt_regs *regs,int do_panic) { -unsigned long flags =oops_begin (); +unsigned long flags; + +if (notify_die (DIE_NMIWATCHDOG , str, regs,0 ,2 ,SIGINT ) == +NOTIFY_STOP ) +return ; + flags =oops_begin ();/* * We are in trouble anyway, lets at least try * to get a message out.
kernel/kgdb.c +8 -6
@@ -600,7 +600,7 @@ static void kgdb_flush_swbreak_addr(unsigned long addr)if (!CACHE_FLUSH_IS_SAFE )return ; -if (current->mm) { +if (current->mm && current->mm->mmap_cache) {flush_cache_range (current->mm->mmap_cache, addr, addr +BREAK_INSTR_SIZE ); }else {
@@ -729,14 +729,16 @@ int remove_all_break(void)/* Clear memory breakpoints. */ for (i =0 ; i <KGDB_MAX_BREAKPOINTS ; i++) { -if (kgdb_break[i].state !=BP_SET ) -continue ; +if (kgdb_break[i].state !=BP_ACTIVE ) + goto setundefined; addr = kgdb_break[i].bpt_addr; error =kgdb_arch_remove_breakpoint (addr, kgdb_break[i].saved_instr);if (error) -return error; - kgdb_break[i].state =BP_REMOVED ; +printk (KERN_ERR "KGDB: breakpoint remove failed: %lx\n" , + addr); +setundefined: + kgdb_break[i].state =BP_UNDEFINED ; }/* Clear hardware breakpoints. */
@@ -1605,7 +1607,7 @@ static void kgdb_initial_breakpoint(void) }/** -* kkgdb_register_io_module - register KGDB IO module +* kgdb_register_io_module - register KGDB IO module * @new_kgdb_io_ops: the io ops vector * * Register it with the KGDB core.
Signature · 1 line
1.5.4
Jason Wessel
maintainerPATCH 2/2 kgdb: Add kgdb internal test suite
This patch adds regression tests for testing the kgdb core and arch specific implementation.
The kgdb test suite is designed to be built into the kernel and not as a module because it uses a number of low level kernel and kgdb primitives which should not be exported externally.
The kgdb test suite is designed as a KGDB I/O module which simulates the communications that a debugger would have with kgdb. The tests are broken up in to a line by line and referenced here as a "get" which is kgdb requesting input and "put" which is kgdb sending a response.
The kgdb suite can be invoked from the kernel command line arguments system or executed dynamically at run time. The test suite uses the variable "kgdbts" to obtain the information about which tests to run and to configure the verbosity level. The following are the various characters you can use with the kgdbts= line:
When using the "kgdbts=" you only choose one of the following core test types:
A = Run all the core tests silently
V1 = Run all the core tests with minimal output
V2 = Run all the core tests in debug mode
You can also specify optional tests:
N## = Go to sleep with interrupts of for ## seconds
to test the HW NMI watchdog
F## = Break at do_fork for ## iterations S## = Break at sys_open for ## iterations
NOTE: that the do_fork and sys_open tests are mutually exclusive.
To invoke the kgdb test suite from boot you use a kernel start argument as follows:
kgdbts=V1 kgdbwait
Or if you wanted to perform the NMI test for 6 seconds and do_fork test for 100 forks, you could use:
kgdbts=V1N6F100 kgdbwait
The test suite can also be invoked at run time with:
echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts Or as another example:
echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts
When developing a new kgdb arch specific implementation or using these tests for the purpose of regression testing, several invocations are required.
1) Boot with the test suite enabled by using the kernel arguments
"kgdbts=V1F100 kgdbwait"
## If kgdb arch specific implementation has NMI use
"kgdbts=V1N6F1002) After the system boot run the basic test. echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts
3) Run the concurrency tests. It is best to use n+1 while loops where n is the number of cpus you have in your system. The example below uses only two loops.
## This tests break points on sys_open
while [ 1 ] ; do find / > /dev/null 2>&1 ; done & while [ 1 ] ; do find / > /dev/null 2>&1 ; done & echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts fg # and hit control-c
fg # and hit control-c
## This tests break points on do_fork
while [ 1 ] ; do date > /dev/null ; done &
while [ 1 ] ; do date > /dev/null ; done &
echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts fg # and hit control-c
--- drivers/misc/Makefile | 1 + drivers/misc/kgdbts.c | 1083 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig.kgdb | 13 + 3 files changed, 1097 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/kgdbts.c
drivers/misc/Makefile +1 -0
@@ -22,3 +22,4 @@ obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o +obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
drivers/misc/kgdbts.c new file +1083 -0
1,083 lines not on this page · raw message
lib/Kconfig.kgdb +13 -0
@@ -25,3 +25,16 @@ config KGDB_SERIAL_CONSOLE help Share a serial console with kgdb. Sysrq-g must be used to break in initially. + +config KGDB_TESTS + bool "KGDB: internal test suite" + depends on KGDB + default n + help + This is a kgdb I/O module specifically designed to test + kgdb's internal functions. This kgdb I/O module is + intended to for the development of new kgdb stubs + as well as regression testing the kgdb internals. + See the drivers/misc/kgdbts.c for the details about + the tests. The most basic of this I/O module is to boot + a kernel boot arguments "kgdbwait kgdbts=V1F100"
Signature · 1 line
1.5.4
Re: [PATCH 2/2] kgdb: Add kgdb internal test suite
Quoted 2 lines · Jason Wessel
This patch adds regression tests for testing the kgdb core and arch specific implementation.
nice!
Quoted 5 lines
When using the "kgdbts=" you only choose one of the following core test types:
A = Run all the core tests silently
V1 = Run all the core tests with minimal output
V2 = Run all the core tests in debug mode
please also add a Kconfig way to activate them and let them be executed automatically upon bootup. If any test fails it should generate a WARN_ON() type of message (for automated testers to find).
Ingo
Jason Wessel
maintainerRe: [PATCH 2/2] kgdb: Add kgdb internal test suite
Quoted 13 lines · Ingo Molnar
Quoted 2 lines · Jason Wessel
This patch adds regression tests for testing the kgdb core and arch specific implementation.
nice!
Quoted 5 lines
When using the "kgdbts=" you only choose one of the following core test types:
A = Run all the core tests silently
V1 = Run all the core tests with minimal output
V2 = Run all the core tests in debug mode
Quoted 5 lines
please also add a
Kconfigway to activate them and let them be executed automatically upon bootup. If any test fails it should generate aWARN_ON()type of message (for automated testers to find).Ingo
Easy enough. I folded the attached patch into the original kgdbts patch in the for_ingo branch.
Jason.
-----CLIP HERE-----
Quoted 1 line
From
a855efa51466cc6e46ed11355d7cc3e1ac24a5bfMon Sep 17 00:00:00 2001
From: Jason Wessel <[email protected]>
Date: Mon, 10 Mar 2008 08:43:54 -0500
Subject: [PATCH 3/3] kgdb: allow static kgdbts boot configuration
This patch adds in the ability to compile the kgdb internal test string into the kernel so as to run the tests at boot without changing the kernel boot arguments. This patch also changes all the error paths to invoke WARN_ON(1) which will emit the line number of the file and dump the kernel stack when an error occurs.
You can disable the tests in a kernel that is built this way using "kgdbts="
Jason.
--- drivers/misc/kgdbts.c | 41 ++++++++++++++++++++++++----------------- lib/Kconfig.kgdb | 18 ++++++++++++++++++ 2 files changed, 42 insertions(+), 17 deletions(-)
drivers/misc/kgdbts.c +24 -17
@@ -112,6 +112,10 @@ printk(KERN_INFO a); \touch_nmi_watchdog (); \ }while (0 ) +#define eprintk(a...) do { \ + printk(KERN_ERR a); \ +WARN_ON (1 ); \ + } while (0)#define MAX_CONFIG_LEN 40static const char hexchars[] ="0123456789abcdef" ;
@@ -145,7 +149,11 @@ static struct pt_regs kgdbts_regs;/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */ static int configured =-1 ; +#ifdef CONFIG_KGDB_TESTS_BOOT_STRING +static char config[MAX_CONFIG_LEN ] =CONFIG_KGDB_TESTS_BOOT_STRING ; +#else static char config[MAX_CONFIG_LEN ]; +#endif static struct kparam_string kps = { .string = config, .maxlen =MAX_CONFIG_LEN ,
@@ -289,7 +297,7 @@ static int check_and_rewind_pc(char *put_str, char *arg)#endif if (strcmp (arg,"silent" ) &&instruction_pointer (&kgdbts_regs) + offset != addr) { -printk (KERN_ERR "kgdbts: BP mismatch %lx expected %lx\n" , +eprintk ("kgdbts: BP mismatch %lx expected %lx\n" ,instruction_pointer (&kgdbts_regs) + offset, addr);return 1 ; }
@@ -313,7 +321,7 @@ static int check_single_step(char *put_str, char *arg)v2printk ("Singlestep stopped at IP: %lx\n" ,instruction_pointer (&kgdbts_regs));if (instruction_pointer (&kgdbts_regs) == addr) { -printk (KERN_ERR "kgdbts: SingleStep failed at %lx\n" , +eprintk ("kgdbts: SingleStep failed at %lx\n" ,instruction_pointer (&kgdbts_regs));return 1 ; }
@@ -378,7 +386,7 @@ static void emul_sstep_get(char *arg)break_helper ("z0" ,0 , sstep_addr);break ;default : -printk (KERN_ERR "kgdbts: ERROR failed sstep get emulation\n" ); +eprintk ("kgdbts: ERROR failed sstep get emulation\n" ); } sstep_state++; }
@@ -404,26 +412,26 @@ static int emul_sstep_put(char *put_str, char *arg)break ;case 2 :if (strncmp (put_str,"$OK" ,3 )) { -printk (KERN_ERR "kgdbts: failed sstep break set\n" ); +eprintk ("kgdbts: failed sstep break set\n" );return 1 ; }break ;case 3 :if (strncmp (put_str,"$T0" ,3 )) { -printk (KERN_ERR "kgdbts: failed continue sstep\n" ); +eprintk ("kgdbts: failed continue sstep\n" );return 1 ; }break ;case 4 :if (strncmp (put_str,"$OK" ,3 )) { -printk (KERN_ERR "kgdbts: failed sstep break unset\n" ); +eprintk ("kgdbts: failed sstep break unset\n" );return 1 ; }/* Single step is complete so continue on! */ sstep_state =0 ;return 0 ;default : -printk (KERN_ERR "kgdbts: ERROR failed sstep put emulation\n" ); +eprintk ("kgdbts: ERROR failed sstep put emulation\n" ); }/* Continue on the same test line until emulation is complete */
@@ -668,8 +676,7 @@ static int run_simple_test(int is_get_char, int chr) }if (get_buf[get_buf_cnt] =='\0' ) { -printk (KERN_ERR -"kgdbts: ERROR GET: end of buffer on '%s' at %i\n" , +eprintk ("kgdbts: ERROR GET: EOB on '%s' at %i\n" , ts.name, ts.idx); get_buf_cnt =0 ;fill_get_buf ("D" );
@@ -684,13 +691,13 @@ static int run_simple_test(int is_get_char, int chr)*/ if (ts.tst[ts.idx].get[0 ] =='\0' && ts.tst[ts.idx].put[0 ] =='\0' ) { -printk (KERN_ERR "kgdbts: ERROR: beyond end of test on" +eprintk ("kgdbts: ERROR: beyond end of test on" " '%s' line %i\n" , ts.name, ts.idx);return 0 ; }if (put_buf_cnt >=BUFMAX ) { -printk (KERN_ERR "kgdbts: ERROR: put buffer overflow on" +eprintk ("kgdbts: ERROR: put buffer overflow on" " '%s' line %i\n" , ts.name, ts.idx); put_buf_cnt =0 ;return 0 ;
@@ -708,7 +715,7 @@ static int run_simple_test(int is_get_char, int chr)v2printk ("put%i: %s\n" , ts.idx, put_buf);/* Trigger check here */ if (ts.validate_put && ts.validate_put (put_buf)) { -printk (KERN_ERR "kgdbts: ERROR PUT: end of test " +eprintk ("kgdbts: ERROR PUT: end of test " "buffer on '%s' line %i expected %s got %s\n" , ts.name, ts.idx, ts.tst[ts.idx].put, put_buf); }
@@ -772,7 +779,7 @@ static void run_breakpoint_test(int is_hw_breakpoint)if (test_complete)return ; -printk (KERN_ERR "kgdbts: ERROR %s test failed\n" , ts.name); +eprintk ("kgdbts: ERROR %s test failed\n" , ts.name); }static void run_hw_break_test (int is_write_test)
@@ -791,7 +798,7 @@ static void run_hw_break_test(int is_write_test)hw_break_val_access ();if (is_write_test) {if (test_complete ==2 ) -printk (KERN_ERR "kgdbts: ERROR %s broke on access\n" , +eprintk ("kgdbts: ERROR %s broke on access\n" , ts.name);hw_break_val_write (); }
@@ -800,7 +807,7 @@ static void run_hw_break_test(int is_write_test)if (test_complete ==1 )return ; -printk (KERN_ERR "kgdbts: ERROR %s test failed\n" , ts.name); +eprintk ("kgdbts: ERROR %s test failed\n" , ts.name); }static void run_nmi_sleep_test (int nmi_sleep)
@@ -817,12 +824,12 @@ static void run_nmi_sleep_test(int nmi_sleep)touch_nmi_watchdog ();local_irq_restore (flags);if (test_complete !=2 ) -printk (KERN_ERR "kgdbts: ERROR nmi_test did not hit nmi\n" ); +eprintk ("kgdbts: ERROR nmi_test did not hit nmi\n" );kgdb_breakpoint ();if (test_complete ==1 )return ; -printk (KERN_ERR "kgdbts: ERROR %s test failed\n" , ts.name); +eprintk ("kgdbts: ERROR %s test failed\n" , ts.name); }static void run_bad_read_test (void )
lib/Kconfig.kgdb +18 -0
@@ -38,3 +38,21 @@ config KGDB_TESTS See the drivers/misc/kgdbts.c for the details about the tests. The most basic of this I/O module is to boot a kernel boot arguments "kgdbwait kgdbts=V1F100" + +config KGDB_TESTS_ON_BOOT + bool "KGDB: Run tests on boot" + depends on KGDB_TESTS + default n + help + Run the kgdb tests on boot up automatically without the need + to pass in a kernel parameter + +config KGDB_TESTS_BOOT_STRING + string "KGDB: which internal kgdb tests to run" + depends on KGDB_TESTS_ON_BOOT + default "V1F100" + help + This is the command string to send the kgdb test suite on + boot. See the drivers/misc/kgdbts.c for detailed + information about other strings you could use beyond the + default of V1F100.
Signature · 1 line
1.5.4
Re: [PATCH 2/2] kgdb: Add kgdb internal test suite
Quoted 7 lines · Jason Wessel
Quoted 4 lines
please also add a
Kconfigway to activate them and let them be executed automatically upon bootup. If any test fails it should generate aWARN_ON()type of message (for automated testers to find).Easy enough. I folded the attached patch into the original kgdbts patch in the
for_ingobranch.
great, thanks!
Ingo