From kbaidarov@ru.mvista.com Thu Mar 1 11:03:24 2007 Received: with ECARTIS (v1.0.0; list kdb); Thu, 01 Mar 2007 11:03:29 -0800 (PST) X-Spam-oss-Status: No, score=0.2 required=5.0 tests=BAYES_50,J_CHICKENPOX_32, J_CHICKENPOX_35 autolearn=no version=3.2.0-pre1-r499012 Received: from mail.dev.rtsoft.ru (rtsoft2.corbina.net [85.21.88.2] (may be forged)) by oss.sgi.com (8.12.10/8.12.10/SuSE Linux 0.7) with SMTP id l21J3J6p020148 for ; Thu, 1 Mar 2007 11:03:22 -0800 Received: (qmail 30161 invoked from network); 1 Mar 2007 18:04:19 -0000 Received: from windmill.dev.rtsoft.ru (192.168.1.188) by mail.dev.rtsoft.ru with SMTP; 1 Mar 2007 18:04:19 -0000 Date: Thu, 1 Mar 2007 21:06:25 +0300 From: Konstantin Baydarov To: kdb@oss.sgi.com Subject: kdb early doesn't work for i386 kernel Message-ID: <20070301210625.4a9ccf4d@windmill.dev.rtsoft.ru> X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.19; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-archive-position: 1196 X-ecartis-version: Ecartis v1.0.0 Sender: kdb-bounce@oss.sgi.com Errors-to: kdb-bounce@oss.sgi.com X-original-sender: kbaidarov@ru.mvista.com Precedence: bulk X-list: kdb Hi, I'm Montavista software engineer. Currently I'm working with kdb, and I've found issue: I386 Kernel 2.6.18 with kdb patch doesn't enter KDB during boot with kernel parameter kdb=early and kdb=on. After investigations I found out that i386 kernel enter KDB during boot using macros KDB_ENTER() (in init/main.c) #define KDB_ENTER() do {if (kdb_on && !KDB_IS_RUNNING()) { asm("\tint $129\n"); }} while(0) So, before execution of instruction "int $129", corresponding handler(kdb_call) should be registered. But in kernel 2.6.18 we register handler later KDB_ENTER() - in late init call: static int __init kdba_late_init(void) { #ifdef CONFIG_SMP set_intr_gate(KDB_VECTOR, kdb_interrupt); #endif set_trap_gate(KDBENTER_VECTOR, kdb_call); return 0; } __initcall(kdba_late_init); In earlier kernels(2.6.10) registration of kdb_call() occur more earlier - in trap_init() and kdb early works fine. So I suggest to move registration of kdb_call from kdba_late_init to trap_init as it used to be. Then, I had browsed kdb patches and found out that kdb early doesn't wing from 2.6.17. In 2.6.16 we register kdb_call in trap_init - and early kdb works fine and In 2.6.17 registration was moved to late init call kdba_late_init(). So here is patch, that fix kdb early for 2.6.17, thanks. Index: linux-2.6.17/arch/i386/kernel/traps.c =================================================================== --- linux-2.6.17.orig/arch/i386/kernel/traps.c +++ linux-2.6.17/arch/i386/kernel/traps.c @@ -57,6 +57,7 @@ #include #include +#include #include "mach_traps.h" @@ -1175,6 +1176,9 @@ static void __init set_task_gate(unsigne _set_gate(idt_table+n,5,0,0,(gdt_entry<<3)); } +#ifdef CONFIG_KDB +asmlinkage int kdb_call(void); +#endif /* CONFIG_KDB */ void __init trap_init(void) { @@ -1237,6 +1241,17 @@ void __init trap_init(void) set_system_gate(SYSCALL_VECTOR,&system_call); +#ifdef CONFIG_KDB + /* + * A trap gate, used by the kernel to enter the + * debugger, preserving all registers. + */ +#ifdef CONFIG_SMP + set_intr_gate(KDB_VECTOR, kdb_interrupt); +#endif + set_trap_gate(KDBENTER_VECTOR, kdb_call); +#endif /* CONFIG_KDB */ + /* * Should be a barrier for any external CPU state. */ Index: linux-2.6.17/arch/i386/kdb/kdbasupport.c =================================================================== --- linux-2.6.17.orig/arch/i386/kdb/kdbasupport.c +++ linux-2.6.17/arch/i386/kdb/kdbasupport.c @@ -1334,11 +1334,6 @@ do { \ "3" ((char *) (addr)),"2" ((seg) << 16)); \ } while (0) -static void __init set_trap_gate(unsigned int n, void *addr) -{ - _set_gate(idt_table+n,15,0,addr,__KERNEL_CS); -} - /* End of copy from arch/i386/kernel/traps.c */ asmlinkage int kdb_call(void); @@ -1479,18 +1474,6 @@ kdba_verify_rw(unsigned long addr, size_ return(kdba_getarea_size(data, addr, size) || kdba_putarea_size(addr, data, size)); } -static int __init -kdba_late_init(void) -{ -#ifdef CONFIG_SMP - set_intr_gate(KDB_VECTOR, kdb_interrupt); -#endif - set_trap_gate(KDBENTER_VECTOR, kdb_call); - return 0; -} - -__initcall(kdba_late_init); - #ifdef CONFIG_SMP #include --------------------------- Use http://oss.sgi.com/ecartis to modify your settings or to unsubscribe. From kbaidarov@ru.mvista.com Thu Mar 1 11:31:23 2007 Received: with ECARTIS (v1.0.0; list kdb); Thu, 01 Mar 2007 11:31:31 -0800 (PST) X-Spam-oss-Status: No, score=0.2 required=5.0 tests=BAYES_50,J_CHICKENPOX_32, J_CHICKENPOX_35 autolearn=no version=3.2.0-pre1-r499012 Received: from mail.dev.rtsoft.ru (rtsoft2.corbina.net [85.21.88.2] (may be forged)) by oss.sgi.com (8.12.10/8.12.10/SuSE Linux 0.7) with SMTP id l21JVK6p025935 for ; Thu, 1 Mar 2007 11:31:22 -0800 Received: (qmail 31605 invoked from network); 1 Mar 2007 19:32:21 -0000 Received: from windmill.dev.rtsoft.ru (192.168.1.188) by mail.dev.rtsoft.ru with SMTP; 1 Mar 2007 19:32:21 -0000 Date: Thu, 1 Mar 2007 22:34:27 +0300 From: Konstantin Baydarov To: kdb@oss.sgi.com Subject: kdb early doesn't work for i386 kernel Message-ID: <20070301223427.3d06333c@windmill.dev.rtsoft.ru> X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.19; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-archive-position: 1197 X-ecartis-version: Ecartis v1.0.0 Sender: kdb-bounce@oss.sgi.com Errors-to: kdb-bounce@oss.sgi.com X-original-sender: kbaidarov@ru.mvista.com Precedence: bulk X-list: kdb Hi, I'm Montavista software engineer. Currently I'm working with kdb, and I've found issue: I386 Kernel 2.6.18 with kdb patch doesn't enter KDB during boot with kernel parameter kdb=early and kdb=on. After investigations I found out that i386 kernel enter KDB during boot using macros KDB_ENTER() (in init/main.c) #define KDB_ENTER() do {if (kdb_on && !KDB_IS_RUNNING()) { asm("\tint $129\n"); }} while(0) So, before execution of instruction "int $129", corresponding handler(kdb_call) should be registered. But in kernel 2.6.18 we register handler later KDB_ENTER() - in late init call: static int __init kdba_late_init(void) { #ifdef CONFIG_SMP set_intr_gate(KDB_VECTOR, kdb_interrupt); #endif set_trap_gate(KDBENTER_VECTOR, kdb_call); return 0; } __initcall(kdba_late_init); In earlier kernels(2.6.10) registration of kdb_call() occur more earlier - in trap_init() and kdb early works fine. So I suggest to move registration of kdb_call from kdba_late_init to trap_init as it used to be. Then, I had browsed kdb patches and found out that kdb early doesn't wing from 2.6.17. In 2.6.16 we register kdb_call in trap_init - and early kdb works fine and In 2.6.17 registration was moved to late init call kdba_late_init(). So here is patch, that fix kdb early for 2.6.17, thanks. Index: linux-2.6.17/arch/i386/kernel/traps.c =================================================================== --- linux-2.6.17.orig/arch/i386/kernel/traps.c +++ linux-2.6.17/arch/i386/kernel/traps.c @@ -57,6 +57,7 @@ #include #include +#include #include "mach_traps.h" @@ -1175,6 +1176,9 @@ static void __init set_task_gate(unsigne _set_gate(idt_table+n,5,0,0,(gdt_entry<<3)); } +#ifdef CONFIG_KDB +asmlinkage int kdb_call(void); +#endif /* CONFIG_KDB */ void __init trap_init(void) { @@ -1237,6 +1241,17 @@ void __init trap_init(void) set_system_gate(SYSCALL_VECTOR,&system_call); +#ifdef CONFIG_KDB + /* + * A trap gate, used by the kernel to enter the + * debugger, preserving all registers. + */ +#ifdef CONFIG_SMP + set_intr_gate(KDB_VECTOR, kdb_interrupt); +#endif + set_trap_gate(KDBENTER_VECTOR, kdb_call); +#endif /* CONFIG_KDB */ + /* * Should be a barrier for any external CPU state. */ Index: linux-2.6.17/arch/i386/kdb/kdbasupport.c =================================================================== --- linux-2.6.17.orig/arch/i386/kdb/kdbasupport.c +++ linux-2.6.17/arch/i386/kdb/kdbasupport.c @@ -1334,11 +1334,6 @@ do { \ "3" ((char *) (addr)),"2" ((seg) << 16)); \ } while (0) -static void __init set_trap_gate(unsigned int n, void *addr) -{ - _set_gate(idt_table+n,15,0,addr,__KERNEL_CS); -} - /* End of copy from arch/i386/kernel/traps.c */ asmlinkage int kdb_call(void); @@ -1479,18 +1474,6 @@ kdba_verify_rw(unsigned long addr, size_ return(kdba_getarea_size(data, addr, size) || kdba_putarea_size(addr, data, size)); } -static int __init -kdba_late_init(void) -{ -#ifdef CONFIG_SMP - set_intr_gate(KDB_VECTOR, kdb_interrupt); -#endif - set_trap_gate(KDBENTER_VECTOR, kdb_call); - return 0; -} - -__initcall(kdba_late_init); - #ifdef CONFIG_SMP #include --------------------------- Use http://oss.sgi.com/ecartis to modify your settings or to unsubscribe.