Skip to contentSkip to conversation

kgdb-ipipe for 2.6.16

PATCH In review Jan Kiszka 2 participants 11 messages May 22, 2006 – Jun 15, 2006

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 kgdb-ipipe for 2.6.16

Hi,

here comes another round of patches to make kgdb work over Ipipe/Xenomai (still only x86). This series is based on latest kgdb CVS [1], which mostly work over 2.6.16 kernels. As usual, the application series file is attached, and should explain the usage.

It "mostly works" means that you may encounter problems in combination with gcc 4.1 [2]. For now, as a workaround, add "CFLAGS_kgdb.o += -fno-unit-at-a-time" to kernel/Makefile. I will have to post this issue to kgdb-bugreport as well and see if they prefer a cleaner solution.

I also submit a new version of the required Xenomai extension. Hopefully, I managed to integrate it more cleanly this time.

Jan

[1] cvs -d :pserver:[email protected] \
co kgdb-2
(server seems to be down right now...)
[2] http://gcc.gnu.org/ml/gcc-help/2006-05/msg00202.html

arch/i386/kernel/entry.S +3 -3
Index: linux-2.6.16.16/arch/i386/kernel/entry.S
===================================================================
@@ -123,7 +123,7 @@ VM_MASK		= 0x00020000
 .previous
 
 
-KPROBE_ENTRY(ret_from_fork)
+ENTRY(ret_from_fork)
 	pushl %eax
 	call schedule_tail
 	GET_THREAD_INFO(%ebp)
@@ -472,7 +472,7 @@ ENTRY(simd_coprocessor_error)
 	pushl $do_simd_coprocessor_error
 	jmp error_code
 
-KPROBE_ENTRY(device_not_available)
+ENTRY(device_not_available)
 	pushl $-1			# mark this as an int
 	SAVE_ALL
 	movl %cr0, %eax
@@ -654,7 +654,7 @@ ENTRY(machine_check)
 	jmp error_code
 #endif
 
-KPROBE_ENTRY(spurious_interrupt_bug)
+ENTRY(spurious_interrupt_bug)
 	pushl $0
 	pushl $do_spurious_interrupt_bug
 	jmp error_code
drivers/serial/8250_kgdb.c +4 -0
Index: linux-2.6.16.16/drivers/serial/8250_kgdb.c
===================================================================
@@ -301,6 +301,10 @@ static void __init kgdb8250_late_init(vo
 			"GDB-stub", current_port) < 0)
 		printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
 		       current_port->irq);
+#ifdef CONFIG_IPIPE
+	ipipe_control_irq(current_port->irq, 0,
+			IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK|IPIPE_SYSTEM_MASK);
+#endif /* CONFIG_IPIPE */
 }
 
 static __init int kgdb_init_io(void)
include/linux/kgdb.h +3 -0
Index: linux-2.6.16.16/include/linux/kgdb.h
===================================================================
@@ -270,6 +270,9 @@ extern int kgdb_handle_exception(int ex_
 extern void kgdb_nmihook(int cpu, void *regs);
 extern int debugger_step;
 extern atomic_t debugger_active;
+
+struct task_struct *ipipe_default_current(void);
+extern struct task_struct *(*ipipe_safe_current)(void);
 #else
 /* Stubs for when KGDB is not set. */
 static const atomic_t debugger_active = ATOMIC_INIT(0);
kernel/kgdb.c +39 -25

178 lines not on this page · raw message

lib/Kconfig.debug +2 -2
Index: linux-2.6.16.16/lib/Kconfig.debug
===================================================================
@@ -273,7 +273,7 @@ choice
 
 config KGDB_ONLY_MODULES
 	bool "KGDB: Use only kernel modules for I/O"
-	depends on MODULES
+	depends on MODULES && !IPIPE
 	help
 	  Use only kernel modules to configure KGDB I/O after the
 	  kernel is booted.
@@ -318,7 +318,7 @@ config KGDB_SIBYTE
 endchoice
 
 config KGDBOE
-	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
+	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE && !IPIPE
 	depends on m && KGDB
 	select NETPOLL
 	select NETPOLL_TRAP
arch/i386/kernel/entry.S +3 -3
Index: linux-2.6.16.16/arch/i386/kernel/entry.S
===================================================================
@@ -194,7 +194,7 @@ VM_MASK		= 0x00020000
 .previous
 
 
-ENTRY(ret_from_fork)
+KPROBE_ENTRY(ret_from_fork)
 	STI_COND_HW
 	pushl %eax
 	call schedule_tail
@@ -584,7 +584,7 @@ ENTRY(simd_coprocessor_error)
 	PUSH_XCODE(do_simd_coprocessor_error)
 	jmp error_code
 
-ENTRY(device_not_available)
+KPROBE_ENTRY(device_not_available)
 	pushl $-1			# mark this as an int
 	SAVE_ALL
 	DIVERT_EXCEPTION(device_not_available)
@@ -769,7 +769,7 @@ ENTRY(machine_check)
 	jmp error_code
 #endif
 
-ENTRY(spurious_interrupt_bug)
+KPROBE_ENTRY(spurious_interrupt_bug)
 	pushl $0
 	PUSH_XCODE(do_spurious_interrupt_bug)
 	jmp error_code
arch/i386/kernel/ipipe-root.c +52 -0

72 lines not on this page · raw message

arch/i386/kernel/kgdb.c +3 -2
Index: linux-2.6.16.16/arch/i386/kernel/kgdb.c
===================================================================
@@ -276,7 +276,8 @@ int kgdb_arch_handle_exception(int e_vec
 		if (remcom_in_buffer[0] == 's') {
 			linux_regs->eflags |= TF_MASK;
 			debugger_step = 1;
-			atomic_set(&cpu_doing_single_step,smp_processor_id());
+			atomic_set(&cpu_doing_single_step,
+			           ipipe_processor_id());
 		}
 
 		asm volatile ("movl %%db6, %0\n":"=r" (dr6));
@@ -319,7 +320,7 @@ static int kgdb_notify(struct notifier_b
        else if ((cmd == DIE_NMI || cmd == DIE_NMI_IPI ||
                cmd == DIE_NMIWATCHDOG) && atomic_read(&debugger_active)) {
                /* CPU roundup */
-               kgdb_nmihook(smp_processor_id(), regs);
+               kgdb_nmihook(ipipe_processor_id(), regs);
                return NOTIFY_STOP;
        } else if (cmd == DIE_NMI_IPI || cmd == DIE_NMI || user_mode(regs) ||
                        (cmd == DIE_DEBUG && atomic_read(&debugger_active)))

core-lite.patch
8250.patch
netpoll_pass_skb_to_rx_hook.patch
eth.patch
i386-lite.patch
powerpc-lite.patch
mips-lite.patch
ia64-lite.patch
x86_64-no_context_hook.patch
x86_64-lite.patch
sh-lite.patch
arm-lite.patch
cfi_annotations.patch
sysrq_bugfix.patch
module.patch
core.patch
i386.patch
powerpc.patch
ia64.patch
prepare-kgdb-ipipe-x86.patch
adeos-ipipe-2.6.16-i386-1.3-04.patch
kgdb-ipipe.patch
kgdb-ipipe-x86.patch

nucleus/pod.c +10 -0
Index: ksrc/nucleus/pod.c
===================================================================
@@ -234,6 +234,13 @@ static void xnpod_flush_heap(xnheap_t * 
     xnarch_sysfree(extaddr, extsize);
 }
 
+static inline struct task_struct * do_safe_current(void)
+{
+    return xnpod_userspace_p() ? current : &init_task;
+}
+
+RTHAL_DECLARE_SAFE_CURRENT(safe_current);
+
 /*! 
  * \fn int xnpod_init(xnpod_t *pod,int minpri,int maxpri,xnflags_t flags)
  * \brief Initialize a new pod.
@@ -373,6 +380,7 @@ int xnpod_init(xnpod_t *pod, int minpri,
        the remaining operations. */
 
     nkpod = pod;
+    rthal_hook_safe_current(safe_current);
 
     /* No direct handler here since the host timer processing is
        postponed to xnintr_irq_handler(), as part of the interrupt
@@ -477,6 +485,7 @@ int xnpod_init(xnpod_t *pod, int minpri,
 
         if (err) {
           fail:
+            rthal_release_safe_current();
             nkpod = NULL;
             return err;
         }
@@ -607,6 +616,7 @@ void xnpod_shutdown(int xtype)
 
     xnheap_destroy(&kheap, &xnpod_flush_heap, NULL);
 
+    rthal_release_safe_current();
     nkpod = NULL;
 
   unlock_and_exit:
asm-generic/hal.h +19 -0
Index: include/asm-generic/hal.h
===================================================================
@@ -573,6 +573,25 @@ struct proc_dir_entry *__rthal_add_proc_
 					      struct proc_dir_entry *parent);
 #endif /* CONFIG_PROC_FS */
 
+#ifdef CONFIG_KGDB
+#include <linux/kgdb.h>
+
+#define rthal_hook_safe_current(handler) \
+    ipipe_safe_current = handler
+#define rthal_release_safe_current() \
+    ipipe_safe_current = ipipe_default_current
+
+#define RTHAL_DECLARE_SAFE_CURRENT(handler) \
+static struct task_struct *handler(void) \
+{ \
+    return do_##handler(); \
+}
+#else /* !CONFIG_KGDB */
+#define rthal_hook_safe_current(handler)	do { } while (0)
+#define rthal_release_safe_current()		do { } while (0)
+#define RTHAL_DECLARE_SAFE_CURRENT(handler)
+#endif /* CONFIG_KGDB */
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
author
#1 lore raw
Quoted 4 lines · Jan Kiszka

...
I also submit a new version of the required Xenomai extension. Hopefully, I managed to integrate it more cleanly this time.

I did not meet this goal as I found out on my own. So here is revision 3 of the Xenomai kgdb patch, now no longer breaking uvm or the simulator.

Jan

asm-uvm/system.h +5 -0
Index: include/asm-uvm/system.h
===================================================================
@@ -787,4 +787,9 @@ static inline void xnarch_sysfree (void 
 /* Ipipe-tracer */
 #define ipipe_trace_panic_freeze()
 
+/* kgdb hooks */
+#define xnarch_hook_safe_current(handler)       do { } while (0)
+#define xnarch_release_safe_current()           do { } while (0)
+#define XNARCH_DECLARE_SAFE_CURRENT(handler)
+
 #endif /* !_XENO_ASM_UVM_SYSTEM_H */
asm-generic/hal.h +19 -0
Index: include/asm-generic/hal.h
===================================================================
@@ -573,6 +573,25 @@ struct proc_dir_entry *__rthal_add_proc_
 					      struct proc_dir_entry *parent);
 #endif /* CONFIG_PROC_FS */
 
+#ifdef CONFIG_KGDB
+#include <linux/kgdb.h>
+
+#define rthal_hook_safe_current(handler) \
+    ipipe_safe_current = handler
+#define rthal_release_safe_current() \
+    ipipe_safe_current = ipipe_default_current
+
+#define RTHAL_DECLARE_SAFE_CURRENT(handler) \
+static struct task_struct *handler(void) \
+{ \
+    return do_##handler(); \
+}
+#else /* !CONFIG_KGDB */
+#define rthal_hook_safe_current(handler)	do { } while (0)
+#define rthal_release_safe_current()		do { } while (0)
+#define RTHAL_DECLARE_SAFE_CURRENT(handler)
+#endif /* CONFIG_KGDB */
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
asm-generic/system.h +6 -0
Index: include/asm-generic/system.h
===================================================================
@@ -669,4 +669,10 @@ static inline void xnarch_init_heapcb (x
 #define xnarch_post_graph(obj,state)
 #define xnarch_post_graph_if(obj,state,cond)
 
+/* kgdb hooks */
+#define xnarch_hook_safe_current(handler)   rthal_hook_safe_current(handler)
+#define xnarch_release_safe_current         rthal_release_safe_current
+#define XNARCH_DECLARE_SAFE_CURRENT(handler) \
+    RTHAL_DECLARE_SAFE_CURRENT(handler)
+
 #endif /* !_XENO_ASM_GENERIC_SYSTEM_H */
asm-sim/system.h +5 -0
Index: include/asm-sim/system.h
===================================================================
@@ -765,6 +765,11 @@ while(0)
 /* Ipipe-tracer */
 #define ipipe_trace_panic_freeze()
 
+/* kgdb hooks */
+#define xnarch_hook_safe_current(handler)       do { } while (0)
+#define xnarch_release_safe_current()           do { } while (0)
+#define XNARCH_DECLARE_SAFE_CURRENT(handler)
+
 #ifndef PAGE_SIZE
 #define PAGE_SIZE sysconf(_SC_PAGESIZE)
 #endif /* !PAGE_SIZE */
nucleus/pod.c +10 -0
Index: ksrc/nucleus/pod.c
===================================================================
@@ -234,6 +234,13 @@ static void xnpod_flush_heap(xnheap_t * 
     xnarch_sysfree(extaddr, extsize);
 }
 
+#define do_safe_current() \
+({ \
+    xnpod_userspace_p() ? current : &init_task; \
+}}
+
+XNARCH_DECLARE_SAFE_CURRENT(safe_current);
+
 /*! 
  * \fn int xnpod_init(xnpod_t *pod,int minpri,int maxpri,xnflags_t flags)
  * \brief Initialize a new pod.
@@ -373,6 +380,7 @@ int xnpod_init(xnpod_t *pod, int minpri,
        the remaining operations. */
 
     nkpod = pod;
+    xnarch_hook_safe_current(safe_current);
 
     /* No direct handler here since the host timer processing is
        postponed to xnintr_irq_handler(), as part of the interrupt
@@ -477,6 +485,7 @@ int xnpod_init(xnpod_t *pod, int minpri,
 
         if (err) {
           fail:
+            xnarch_release_safe_current();
             nkpod = NULL;
             return err;
         }
@@ -607,6 +616,7 @@ void xnpod_shutdown(int xtype)
 
     xnheap_destroy(&kheap, &xnpod_flush_heap, NULL);
 
+    xnarch_release_safe_current();
     nkpod = NULL;
 
   unlock_and_exit:
#2 lore raw

PATCH 1/1 kgdb/x86 over I-pipe

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and the I-pipe. Basically, I've attempted to shrink the extra patches needed against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

The key difference with the former implementation is that a domain (e.g. Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping smp_processor_id() with ipipe_processor_id() has been addressed the hard way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are debugging after all.

Aside of the small patches attached, you will need the latest I-pipe 1.3-05 patch for x86, adding the foreign stack notifier and the ipipe_safe_current() support:
http://download.gna.org/adeos/patches/v2.6/i386/adeos-ipipe-2.6.16-i386-1.3-05.patch

Patches should be applied in this order on a vanilla 2.6.16 kernel:

- KGDB 2.4 patch series over 2.6.16 (quilt)
- pre-kgdb-ipipe-i386.patch
- adeos-ipipe-2.6.16-i386-1.3-05.patch
- kgdb-ipipe.patch
- post-kgdb-ipipe-i386.patch

Xenomai's trunk/ should be used. Older code won't work and likely crash since the I-pipe would not be notified about foreign stack switches.

Now the surprise: I did not test this stuff, I mean, at all. Eh. :o)

Signature · 1 line
Philippe.
kernel/kgdb.c +29 -21
@@ -740,10 +740,10 @@
 	unsigned long flags;
 	int processor;
 
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 	processor = smp_processor_id();
 	kgdb_info[processor].debuggerinfo = regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 	atomic_set(&procindebug[processor], 1);
 
 	/* Wait till master processor goes completely into the debugger.
@@ -769,7 +769,7 @@
 	/* Signal the master processor that we are done */
 	atomic_set(&procindebug[processor], 0);
 	spin_unlock(&slavecpulocks[processor]);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 }
 #endif
 
@@ -883,8 +883,8 @@
 					kgdb_break[i].saved_instr)))
 			return error;
 
-		if (CACHE_FLUSH_IS_SAFE && current->mm &&
-				addr < TASK_SIZE)
+		if (CACHE_FLUSH_IS_SAFE && ipipe_safe_current() == current &&
+				current->mm && addr < TASK_SIZE)
 			flush_cache_range(current->mm->mmap_cache,
 					addr, addr + BREAK_INSTR_SIZE);
 		else if (CACHE_FLUSH_IS_SAFE)
@@ -1032,7 +1032,7 @@
 	 * Interrupts will be restored by the 'trap return' code, except when
 	 * single stepping.
 	 */
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 
 	/* Hold debugger_active */
 	procid = smp_processor_id();
@@ -1055,7 +1055,7 @@
 	if (atomic_read(&cpu_doing_single_step) != -1 &&
 	    atomic_read(&cpu_doing_single_step) != procid) {
 		atomic_set(&debugger_active, 0);
-		local_irq_restore(flags);
+		local_irq_restore_hw(flags);
 		goto acquirelock;
 	}
 
@@ -1068,7 +1068,7 @@
 		goto kgdb_restore;
 
 	kgdb_info[processor].debuggerinfo = linux_regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 
 	kgdb_disable_hw_debug(linux_regs);
 
@@ -1120,7 +1120,8 @@
 		*ptr++ = hexchars[(signo >> 4) % 16];
 		*ptr++ = hexchars[signo % 16];
 		ptr += strlen(strcpy(ptr, "thread:"));
-		int_to_threadref(&thref, shadow_pid(current->pid));
+		int_to_threadref(&thref,
+		                 shadow_pid(ipipe_safe_current()->pid));
 		ptr = pack_threadid(ptr, &thref);
 		*ptr++ = ';';
 
@@ -1212,7 +1213,8 @@
 			kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs,
 				     NUMREGBYTES);
 
-			if (kgdb_usethread && kgdb_usethread != current)
+			if (kgdb_usethread &&
+			    kgdb_usethread != ipipe_safe_current())
 				error_packet(remcom_out_buffer, -EINVAL);
 			else {
 				gdb_regs_to_regs(gdb_regs, linux_regs);
@@ -1333,7 +1335,8 @@
 				/* Current thread id */
 				strcpy(remcom_out_buffer, "QC");
 
-				threadid = shadow_pid(current->pid);
+				threadid =
+					shadow_pid(ipipe_safe_current()->pid);
 
 				int_to_threadref(&thref, threadid);
 				pack_threadid(remcom_out_buffer + 2, &thref);
@@ -1487,7 +1490,8 @@
 			break;
 		case 'c':
 		case 's':
-			if (kgdb_contthread && kgdb_contthread != current) {
+			if (kgdb_contthread &&
+			    kgdb_contthread != ipipe_safe_current()) {
 				/* Can't switch threads in kgdb */
 				error_packet(remcom_out_buffer, -EINVAL);
 				break;
@@ -1555,7 +1559,7 @@
 kgdb_restore:
 	/* Free debugger_active */
 	atomic_set(&debugger_active, 0);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 
 	return error;
 }
@@ -1924,9 +1928,9 @@
 	if (!kgdb_connected || atomic_read(&debugger_active) != 0)
 		return 0;
 	if ((code == SYS_RESTART) || (code == SYS_HALT) || (code == SYS_POWER_OFF)){
-		local_irq_save(flags);
+		local_irq_save_hw(flags);
 		put_packet("X00");
-		local_irq_restore(flags);
+		local_irq_restore_hw(flags);
 	}
 	return NOTIFY_DONE;
 }		
@@ -1941,10 +1945,10 @@
 	if (!kgdb_connected || atomic_read(&debugger_active) != 0)
 		return;
 
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 	kgdb_msg_write(s, count);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 }
 
 static struct console kgdbcons = {
--- 2.6.16-base/lib/Kconfig.debug	2006-06-07 16:40:21.000000000 +0200
+++ 2.6.16-kgdb/lib/Kconfig.debug	2006-06-06 16:01:26.000000000 +0200
@@ -250,7 +250,7 @@
 
 config KGDB_ONLY_MODULES
 	bool "KGDB: Use only kernel modules for I/O"
-	depends on MODULES
+	depends on MODULES && !IPIPE
 	help
 	  Use only kernel modules to configure KGDB I/O after the
 	  kernel is booted.
@@ -295,8 +295,8 @@
 endchoice
 
 config KGDBOE
-	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
+	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE && !IPIPE
 	depends on m && KGDB
 	select NETPOLL
 	select NETPOLL_TRAP
--- 2.6.16-base/drivers/serial/8250_kgdb.c	2006-06-07 16:40:20.000000000 +0200
+++ 2.6.16-kgdb/drivers/serial/8250_kgdb.c	2006-06-06 16:01:26.000000000 +0200
@@ -301,6 +301,10 @@
 			"GDB-stub", current_port) < 0)
 		printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
 		       current_port->irq);
+#ifdef CONFIG_IPIPE
+	ipipe_control_irq(current_port->irq, 0,
+			IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK|IPIPE_SYSTEM_MASK);
+#endif /* CONFIG_IPIPE */
 }
 
 static __init int kgdb_init_io(void)
include/linux/smp.h +4 -0
@@ -116,12 +116,16 @@
  * which use for some reason is legal). Don't use this to hack around
  * the warning message, as your code might not work under PREEMPT.
  */
+#if defined(CONFIG_KGDB) && defined(CONFIG_IPIPE)
+#define smp_processor_id() ipipe_processor_id()
+#else /* CONFIG_KGDB && CONFIG_IPIPE */
 #ifdef CONFIG_DEBUG_PREEMPT
   extern unsigned int debug_smp_processor_id(void);
 # define smp_processor_id() debug_smp_processor_id()
 #else
 # define smp_processor_id() raw_smp_processor_id()
 #endif
+#endif
 
 #define get_cpu()		({ preempt_disable(); smp_processor_id(); })
 #define put_cpu()		preempt_enable()
arch/i386/kernel/entry.S +3 -3
Index: linux-2.6.16.16/arch/i386/kernel/entry.S
===================================================================
@@ -194,7 +194,7 @@ VM_MASK		= 0x00020000
 .previous
 
 
-ENTRY(ret_from_fork)
+KPROBE_ENTRY(ret_from_fork)
 	STI_COND_HW
 	pushl %eax
 	call schedule_tail
@@ -584,7 +584,7 @@ ENTRY(simd_coprocessor_error)
 	PUSH_XCODE(do_simd_coprocessor_error)
 	jmp error_code
 
-ENTRY(device_not_available)
+KPROBE_ENTRY(device_not_available)
 	pushl $-1			# mark this as an int
 	SAVE_ALL
 	DIVERT_EXCEPTION(device_not_available)
@@ -769,7 +769,7 @@ ENTRY(machine_check)
 	jmp error_code
 #endif
 
-ENTRY(spurious_interrupt_bug)
+KPROBE_ENTRY(spurious_interrupt_bug)
 	pushl $0
 	PUSH_XCODE(do_spurious_interrupt_bug)
 	jmp error_code
arch/i386/kernel/entry.S +3 -3
Index: linux-2.6.16.16/arch/i386/kernel/entry.S
===================================================================
@@ -123,7 +123,7 @@ VM_MASK		= 0x00020000
 .previous
 
 
-KPROBE_ENTRY(ret_from_fork)
+ENTRY(ret_from_fork)
 	pushl %eax
 	call schedule_tail
 	GET_THREAD_INFO(%ebp)
@@ -472,7 +472,7 @@ ENTRY(simd_coprocessor_error)
 	pushl $do_simd_coprocessor_error
 	jmp error_code
 
-KPROBE_ENTRY(device_not_available)
+ENTRY(device_not_available)
 	pushl $-1			# mark this as an int
 	SAVE_ALL
 	movl %cr0, %eax
@@ -654,7 +654,7 @@ ENTRY(machine_check)
 	jmp error_code
 #endif
 
-KPROBE_ENTRY(spurious_interrupt_bug)
+ENTRY(spurious_interrupt_bug)
 	pushl $0
 	pushl $do_spurious_interrupt_bug
 	jmp error_code
author
#3 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 9 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and the I-pipe. Basically, I've attempted to shrink the extra patches needed against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 5 lines

The key difference with the former implementation is that a domain (e.g. Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 7 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are debugging after all.

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Quoted 15 lines

Aside of the small patches attached, you will need the latest I-pipe 1.3-05 patch for x86, adding the foreign stack notifier and the ipipe_safe_current() support:
http://download.gna.org/adeos/patches/v2.6/i386/adeos-ipipe-2.6.16-i386-1.3-05.patch

Patches should be applied in this order on a vanilla 2.6.16 kernel:

- KGDB 2.4 patch series over 2.6.16 (quilt)
- pre-kgdb-ipipe-i386.patch
- adeos-ipipe-2.6.16-i386-1.3-05.patch
- kgdb-ipipe.patch
- post-kgdb-ipipe-i386.patch

Quoted 4 lines

Xenomai's trunk/ should be used. Older code won't work and likely crash since the I-pipe would not be notified about foreign stack switches.

Now the surprise: I did not test this stuff, I mean, at all. Eh. :o)

That's fair: leave the head banging while debugging debuggers (*) up to me. ;)

Will try to let this fly, likely not before the weekend.

BTW, there is one pending issue of gcc-4.1 which popped up under kgdb, see [1] (also for a workaround).

Jan

(*) Actually, that's feasible: kgdb-patched kernel inside qemu - already done this (to find [1]), it's just a bit sloooow.

[1]http://sourceforge.net/mailarchive/forum.php?thread_id=10452132&forum_id=5557

#4 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 29 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and the I-pipe. Basically, I've attempted to shrink the extra patches needed against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 5 lines

The key difference with the former implementation is that a domain (e.g. Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 7 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are debugging after all.

Quoted 3 lines

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Good point. Here is an updated patch.

Quoted 21 lines
Quoted 15 lines

Aside of the small patches attached, you will need the latest I-pipe 1.3-05 patch for x86, adding the foreign stack notifier and the ipipe_safe_current() support:
http://download.gna.org/adeos/patches/v2.6/i386/adeos-ipipe-2.6.16-i386-1.3-05.patch

Patches should be applied in this order on a vanilla 2.6.16 kernel:

- KGDB 2.4 patch series over 2.6.16 (quilt)
- pre-kgdb-ipipe-i386.patch
- adeos-ipipe-2.6.16-i386-1.3-05.patch
- kgdb-ipipe.patch
- post-kgdb-ipipe-i386.patch

Quoted 4 lines

Xenomai's trunk/ should be used. Older code won't work and likely crash since the I-pipe would not be notified about foreign stack switches.

Now the surprise: I did not test this stuff, I mean, at all. Eh. :o)

Quoted 8 lines

That's fair: leave the head banging while debugging debuggers (*) up to me. ;)

Will try to let this fly, likely not before the weekend.

BTW, there is one pending issue of gcc-4.1 which popped up under kgdb, see [1] (also for a workaround).

Mm, I'll keep on working with gcc3.4 and 8k stacks on x86 then.

Quoted 8 lines

Jan

(*) Actually, that's feasible: kgdb-patched kernel inside qemu - already done this (to find [1]), it's just a bit sloooow.

[1]http://sourceforge.net/mailarchive/forum.php?thread_id=10452132&forum_id=5557

Signature · 1 line
Philippe.
kernel/kgdb.c +29 -21
@@ -740,10 +740,10 @@
 	unsigned long flags;
 	int processor;
 
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 	processor = smp_processor_id();
 	kgdb_info[processor].debuggerinfo = regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 	atomic_set(&procindebug[processor], 1);
 
 	/* Wait till master processor goes completely into the debugger.
@@ -769,7 +769,7 @@
 	/* Signal the master processor that we are done */
 	atomic_set(&procindebug[processor], 0);
 	spin_unlock(&slavecpulocks[processor]);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 }
 #endif
 
@@ -883,8 +883,8 @@
 					kgdb_break[i].saved_instr)))
 			return error;
 
-		if (CACHE_FLUSH_IS_SAFE && current->mm &&
-				addr < TASK_SIZE)
+		if (CACHE_FLUSH_IS_SAFE && ipipe_safe_current() == current &&
+				current->mm && addr < TASK_SIZE)
 			flush_cache_range(current->mm->mmap_cache,
 					addr, addr + BREAK_INSTR_SIZE);
 		else if (CACHE_FLUSH_IS_SAFE)
@@ -1032,7 +1032,7 @@
 	 * Interrupts will be restored by the 'trap return' code, except when
 	 * single stepping.
 	 */
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 
 	/* Hold debugger_active */
 	procid = smp_processor_id();
@@ -1055,7 +1055,7 @@
 	if (atomic_read(&cpu_doing_single_step) != -1 &&
 	    atomic_read(&cpu_doing_single_step) != procid) {
 		atomic_set(&debugger_active, 0);
-		local_irq_restore(flags);
+		local_irq_restore_hw(flags);
 		goto acquirelock;
 	}
 
@@ -1068,7 +1068,7 @@
 		goto kgdb_restore;
 
 	kgdb_info[processor].debuggerinfo = linux_regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 
 	kgdb_disable_hw_debug(linux_regs);
 
@@ -1120,7 +1120,8 @@
 		*ptr++ = hexchars[(signo >> 4) % 16];
 		*ptr++ = hexchars[signo % 16];
 		ptr += strlen(strcpy(ptr, "thread:"));
-		int_to_threadref(&thref, shadow_pid(current->pid));
+		int_to_threadref(&thref,
+		                 shadow_pid(ipipe_safe_current()->pid));
 		ptr = pack_threadid(ptr, &thref);
 		*ptr++ = ';';
 
@@ -1212,7 +1213,8 @@
 			kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs,
 				     NUMREGBYTES);
 
-			if (kgdb_usethread && kgdb_usethread != current)
+			if (kgdb_usethread &&
+			    kgdb_usethread != ipipe_safe_current())
 				error_packet(remcom_out_buffer, -EINVAL);
 			else {
 				gdb_regs_to_regs(gdb_regs, linux_regs);
@@ -1333,7 +1335,8 @@
 				/* Current thread id */
 				strcpy(remcom_out_buffer, "QC");
 
-				threadid = shadow_pid(current->pid);
+				threadid =
+					shadow_pid(ipipe_safe_current()->pid);
 
 				int_to_threadref(&thref, threadid);
 				pack_threadid(remcom_out_buffer + 2, &thref);
@@ -1487,7 +1490,8 @@
 			break;
 		case 'c':
 		case 's':
-			if (kgdb_contthread && kgdb_contthread != current) {
+			if (kgdb_contthread &&
+			    kgdb_contthread != ipipe_safe_current()) {
 				/* Can't switch threads in kgdb */
 				error_packet(remcom_out_buffer, -EINVAL);
 				break;
@@ -1555,7 +1559,7 @@
 kgdb_restore:
 	/* Free debugger_active */
 	atomic_set(&debugger_active, 0);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 
 	return error;
 }
@@ -1924,9 +1928,9 @@
 	if (!kgdb_connected || atomic_read(&debugger_active) != 0)
 		return 0;
 	if ((code == SYS_RESTART) || (code == SYS_HALT) || (code == SYS_POWER_OFF)){
-		local_irq_save(flags);
+		local_irq_save_hw(flags);
 		put_packet("X00");
-		local_irq_restore(flags);
+		local_irq_restore_hw(flags);
 	}
 	return NOTIFY_DONE;
 }		
@@ -1941,10 +1945,10 @@
 	if (!kgdb_connected || atomic_read(&debugger_active) != 0)
 		return;
 
-	local_irq_save(flags);
+	local_irq_save_hw(flags);
 	kgdb_msg_write(s, count);
-	local_irq_restore(flags);
+	local_irq_restore_hw(flags);
 }
 
 static struct console kgdbcons = {
--- 2.6.16-base/lib/Kconfig.debug	2006-06-07 16:40:21.000000000 +0200
+++ 2.6.16-kgdb/lib/Kconfig.debug	2006-06-06 16:01:26.000000000 +0200
@@ -250,7 +250,7 @@
 
 config KGDB_ONLY_MODULES
 	bool "KGDB: Use only kernel modules for I/O"
-	depends on MODULES
+	depends on MODULES && !IPIPE
 	help
 	  Use only kernel modules to configure KGDB I/O after the
 	  kernel is booted.
@@ -295,8 +295,8 @@
 endchoice
 
 config KGDBOE
-	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
+	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE && !IPIPE
 	depends on m && KGDB
 	select NETPOLL
 	select NETPOLL_TRAP
--- 2.6.16-base/drivers/serial/8250_kgdb.c	2006-06-07 16:40:20.000000000 +0200
+++ 2.6.16-kgdb/drivers/serial/8250_kgdb.c	2006-06-06 16:01:26.000000000 +0200
@@ -301,6 +301,10 @@
 			"GDB-stub", current_port) < 0)
 		printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
 		       current_port->irq);
+#ifdef CONFIG_IPIPE
+	ipipe_control_irq(current_port->irq, 0,
+			IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK|IPIPE_SYSTEM_MASK);
+#endif /* CONFIG_IPIPE */
 }
 
 static __init int kgdb_init_io(void)
include/asm-i386/smp.h +4 -0
@@ -57,7 +57,11 @@
  * from the initial startup. We map APIC_BASE very early in page_setup(),
  * so this is correct in the x86 case.
  */
+#if defined(CONFIG_KGDB) && defined(CONFIG_IPIPE)
+#define raw_smp_processor_id() ipipe_processor_id()
+#else
 #define raw_smp_processor_id() (current_thread_info()->cpu)
+#endif
 
 extern cpumask_t cpu_callout_map;
 extern cpumask_t cpu_callin_map;
author
#5 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 30 lines · Philippe Gerum
Quoted 29 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and the I-pipe. Basically, I've attempted to shrink the extra patches needed against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 5 lines

The key difference with the former implementation is that a domain (e.g. Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 7 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are debugging after all.

Quoted 6 lines
Quoted 3 lines

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Good point. Here is an updated patch.

Nope that's not the point I meant. I was referring to bugs like the missing smp_processor_id patch in asm-i386/mmu_context.h. Your way makes such problems disappear once you switch on the debugger. Remember that we spotted the mmu_context issue via kgdb.

The attached kgdb-ipipe patch (which also updates to kgdb-CVS head) addresses maintenance and smp-safeness by redefining the involved services only per source file, not kernel-wide. What's do you think about this approach?

I'm also posting two fixes for ipipe itself to 1) make kgdb work over SMP and 2) fix a compiler warning.

This version works fine for me, at least in qemu. I tried to check SMP as well, but qemu obviously lacks support for NMIs raised via IPI, and this is used by kgdb to sync all CPUs on debugging events (vanilla kgdb suffers too).

Jan

kernel/kgdb.c +21 -8
Index: linux/kernel/kgdb.c
===================================================================
@@ -49,6 +49,15 @@
 #include <linux/console.h>
 #include <asm/byteorder.h>
 
+#if defined(CONFIG_KGDB) && defined(CONFIG_IPIPE)
+#undef smp_processor_id
+#undef local_irq_save
+#undef local_irq_restore
+#define smp_processor_id    ipipe_processor_id
+#define local_irq_save      local_irq_save_hw
+#define local_irq_restore   local_irq_restore_hw
+#endif
+
 extern int pid_max;
 extern int pidhash_init_done;
 
@@ -743,7 +752,7 @@ static void kgdb_wait(struct pt_regs *re
 	local_irq_save(flags);
 	processor = smp_processor_id();
 	kgdb_info[processor].debuggerinfo = regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 	atomic_set(&procindebug[processor], 1);
 	atomic_set(&kgdb_sync_softlockup[smp_processor_id()], 1);
 
@@ -884,8 +893,8 @@ int kgdb_deactivate_sw_breakpoints(void)
 					kgdb_break[i].saved_instr)))
 			return error;
 
-		if (CACHE_FLUSH_IS_SAFE && current->mm &&
-				addr < TASK_SIZE)
+		if (CACHE_FLUSH_IS_SAFE && ipipe_safe_current() == current &&
+				current->mm && addr < TASK_SIZE)
 			flush_cache_range(current->mm->mmap_cache,
 					addr, addr + BREAK_INSTR_SIZE);
 		else if (CACHE_FLUSH_IS_SAFE)
@@ -1069,7 +1078,7 @@ int kgdb_handle_exception(int ex_vector,
 		goto kgdb_restore;
 
 	kgdb_info[processor].debuggerinfo = linux_regs;
-	kgdb_info[processor].task = current;
+	kgdb_info[processor].task = ipipe_safe_current();
 
 	kgdb_disable_hw_debug(linux_regs);
 
@@ -1121,7 +1130,8 @@ int kgdb_handle_exception(int ex_vector,
 		*ptr++ = hexchars[(signo >> 4) % 16];
 		*ptr++ = hexchars[signo % 16];
 		ptr += strlen(strcpy(ptr, "thread:"));
-		int_to_threadref(&thref, shadow_pid(current->pid));
+		int_to_threadref(&thref,
+		                 shadow_pid(ipipe_safe_current()->pid));
 		ptr = pack_threadid(ptr, &thref);
 		*ptr++ = ';';
 
@@ -1213,7 +1223,8 @@ int kgdb_handle_exception(int ex_vector,
 			kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs,
 				     NUMREGBYTES);
 
-			if (kgdb_usethread && kgdb_usethread != current)
+			if (kgdb_usethread &&
+			    kgdb_usethread != ipipe_safe_current())
 				error_packet(remcom_out_buffer, -EINVAL);
 			else {
 				gdb_regs_to_regs(gdb_regs, linux_regs);
@@ -1334,7 +1345,8 @@ int kgdb_handle_exception(int ex_vector,
 				/* Current thread id */
 				strcpy(remcom_out_buffer, "QC");
 
-				threadid = shadow_pid(current->pid);
+				threadid =
+					shadow_pid(ipipe_safe_current()->pid);
 
 				int_to_threadref(&thref, threadid);
 				pack_threadid(remcom_out_buffer + 2, &thref);
@@ -1488,7 +1500,8 @@ int kgdb_handle_exception(int ex_vector,
 			break;
 		case 'c':
 		case 's':
-			if (kgdb_contthread && kgdb_contthread != current) {
+			if (kgdb_contthread &&
+			    kgdb_contthread != ipipe_safe_current()) {
 				/* Can't switch threads in kgdb */
 				error_packet(remcom_out_buffer, -EINVAL);
 				break;
lib/Kconfig.debug +2 -2
Index: linux/lib/Kconfig.debug
===================================================================
@@ -273,7 +273,7 @@ choice
 
 config KGDB_ONLY_MODULES
 	bool "KGDB: Use only kernel modules for I/O"
-	depends on MODULES
+	depends on MODULES && !IPIPE
 	help
 	  Use only kernel modules to configure KGDB I/O after the
 	  kernel is booted.
@@ -318,7 +318,7 @@ config KGDB_SIBYTE
 endchoice
 
 config KGDBOE
-	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
+	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE && !IPIPE
 	depends on m && KGDB
 	select NETPOLL
 	select NETPOLL_TRAP
drivers/serial/8250_kgdb.c +4 -0
Index: linux/drivers/serial/8250_kgdb.c
===================================================================
@@ -301,6 +301,10 @@ static void __init kgdb8250_late_init(vo
 			"GDB-stub", current_port) < 0)
 		printk(KERN_ERR "KGDB failed to request the serial IRQ (%d)\n",
 		       current_port->irq);
+#ifdef CONFIG_IPIPE
+	ipipe_control_irq(current_port->irq, 0,
+			IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK|IPIPE_SYSTEM_MASK);
+#endif /* CONFIG_IPIPE */
 }
 
 static __init int kgdb_init_io(void)
arch/i386/kernel/kgdb.c +5 -0
Index: linux/arch/i386/kernel/kgdb.c
===================================================================
@@ -43,6 +43,11 @@
 
 #include "mach_ipi.h"
 
+#if defined(CONFIG_KGDB) && defined(CONFIG_IPIPE)
+#undef smp_processor_id
+#define smp_processor_id    ipipe_processor_id
+#endif
+
 /* Put the error code here just in case the user cares.  */
 int gdb_i386errcode;
 /* Likewise, the vector number here (since GDB only gets the signal
include/linux/ipipe.h +2 -0
Index: linux-2.6.16.16/include/linux/ipipe.h
===================================================================
@@ -617,6 +617,7 @@ static inline void ipipe_set_foreign_sta
 {
 	/* Must be called hw interrupts off. */
 	ipipe_declare_cpuid;
+	ipipe_load_cpuid();
 	__set_bit(IPIPE_NOSTACK_FLAG, &ipd->cpudata[cpuid].status);
 }
 
@@ -624,6 +625,7 @@ static inline void ipipe_clear_foreign_s
 {
 	/* Must be called hw interrupts off. */
 	ipipe_declare_cpuid;
+	ipipe_load_cpuid();
 	__clear_bit(IPIPE_NOSTACK_FLAG, &ipd->cpudata[cpuid].status);
 }
 
arch/i386/kernel/ipipe-root.c +2 -0
Index: linux-2.6.16.16/arch/i386/kernel/ipipe-root.c
===================================================================
@@ -423,6 +423,8 @@ static __ipipe_exptr __ipipe_std_extable
 };
 
 #ifdef CONFIG_KGDB
+#include <linux/kgdb.h>
+
 static int __ipipe_xlate_signo[] = {
 
 	[ex_do_divide_error] = SIGFPE,
#6 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Philippe Gerum
Quoted 34 lines · Jan Kiszka
Quoted 8 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and the I-pipe. Basically, I've attempted to shrink the extra patches needed against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 5 lines

The key difference with the former implementation is that a domain (e.g. Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 7 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are debugging after all.

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Quoted 9 lines
Quoted 2 lines

Good point. Here is an updated patch.

Nope that's not the point I meant. I was referring to bugs like the missing smp_processor_id patch in asm-i386/mmu_context.h. Your way makes such problems disappear once you switch on the debugger. Remember that we spotted the mmu_context issue via kgdb.

Got it now. Indeed, making such kind of bugs disappear would be a very undesirable side-effect of enabling KGDB.

Quoted 5 lines

The attached kgdb-ipipe patch (which also updates to kgdb-CVS head) addresses maintenance and smp-safeness by redefining the involved services only per source file, not kernel-wide. What's do you think about this approach?

Mixed feelings. On one hand, it locally fixes the issue without masking any bugs and that's good. On the other hand, I've been bitten using this kind of tricks in earlier Adeos releases for patching printk() the same way, substituting it with spin_lock_irqsave_hw. At some point, spin_lock_irqsave became local_irq_save + spin_lock in the vanilla code, making the substitution of the former pointless, and opening a preemption hole in the code. This said, no spinlock macros are involved in the substitution you are suggesting, so there is no such risk, and in any case, the risk is confined to one file and not spread all over the place like with the raw_smp_processor_id() substitution. IOW, let's go your way.

While we are at it,
#define current ipipe_safe_current() /* ? */

Quoted 8 lines

I'm also posting two fixes for ipipe itself to 1) make kgdb work over SMP and 2) fix a compiler warning.

This version works fine for me, at least in qemu. I tried to check SMP as well, but qemu obviously lacks support for NMIs raised via IPI, and this is used by kgdb to sync all CPUs on debugging events (vanilla kgdb suffers too).

Signature · 1 line
Philippe.
author
#7 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 65 lines · Philippe Gerum
Quoted 45 lines · Jan Kiszka
Quoted 43 lines · Philippe Gerum
Quoted 40 lines · Jan Kiszka
Quoted 10 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and
the I-pipe. Basically, I've attempted to shrink the extra patches needed
against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 6 lines

The key difference with the former implementation is that a domain (e.g.
Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 10 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline
domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are
debugging after all.

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Quoted 9 lines
Quoted 2 lines

Good point. Here is an updated patch.

Nope that's not the point I meant. I was referring to bugs like the missing smp_processor_id patch in asm-i386/mmu_context.h. Your way makes such problems disappear once you switch on the debugger. Remember that we spotted the mmu_context issue via kgdb.

Got it now. Indeed, making such kind of bugs disappear would be a very undesirable side-effect of enabling KGDB.

Quoted 5 lines

The attached kgdb-ipipe patch (which also updates to kgdb-CVS head) addresses maintenance and smp-safeness by redefining the involved services only per source file, not kernel-wide. What's do you think about this approach?

Quoted 11 lines

Mixed feelings. On one hand, it locally fixes the issue without masking any bugs and that's good. On the other hand, I've been bitten using this kind of tricks in earlier Adeos releases for patching printk() the same way, substituting it with spin_lock_irqsave_hw. At some point, spin_lock_irqsave became local_irq_save + spin_lock in the vanilla code, making the substitution of the former pointless, and opening a preemption hole in the code. This said, no spinlock macros are involved in the substitution you are suggesting, so there is no such risk, and in any case, the risk is confined to one file and not spread all over the place like with the raw_smp_processor_id() substitution. IOW, let's go your way.

I agree that it's kind of fragile, but we need to check on kgdb updates anyway. I hope for kgdb becoming mainline one day. Then the code should stabilise (if it hasn't already), and we can track it via ipipe directly
- without tricks. So far, this should help to keep efforts lower for us.

Quoted 3 lines

While we are at it,
#define current ipipe_safe_current() /* ? */

Nope, there is the need for some special changes.

Quoted 10 lines
Quoted 9 lines

I'm also posting two fixes for ipipe itself to 1) make kgdb work over SMP and 2) fix a compiler warning.

This version works fine for me, at least in qemu. I tried to check SMP as well, but qemu obviously lacks support for NMIs raised via IPI, and this is used by kgdb to sync all CPUs on debugging events (vanilla kgdb suffers too).

Jan

#8 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 92 lines · Jan Kiszka
Quoted 71 lines · Philippe Gerum
Quoted 49 lines · Jan Kiszka
Quoted 46 lines · Philippe Gerum
Quoted 42 lines · Jan Kiszka
Quoted 10 lines · Philippe Gerum

Hi Jan,

Based on your previous work, here is a set of patches coupling KGDB and
the I-pipe. Basically, I've attempted to shrink the extra patches needed
against the original KGDB + I-pipe ones to the bare minimum. This has been obtained by having the I-pipe provide ipipe_current_safe(), and drastically reduce the amount of fiddling with smp_processor_id().

Quoted 6 lines

The key difference with the former implementation is that a domain (e.g.
Xenomai) is now expected to tell the I-pipe when it's switching to a non-Linux stack, and the I-pipe makes good use of this information to return the proper "current" value when asked to through ipipe_safe_current() from the KGDB code. The issue of swapping

This looks nice.

Quoted 10 lines

smp_processor_id() with ipipe_processor_id() has been addressed the hard
way: smp_processor_id() is simply defined as ipipe_processor_id() when CONFIG_IPIPE and CONFIG_KGDB are both enabled in include/linux/smp.h. This approach was actually used during the old Adeos times when pipeline
domain had their own separate stack. I take for granted that the CPU penalty taken in doing this is perfectly acceptable, since well, we are
debugging after all.

There is only one drawback: we will not be able to debug smp_processor_id-related bugs in ipipe/Xenomai anymore...

Quoted 9 lines
Quoted 2 lines

Good point. Here is an updated patch.

Nope that's not the point I meant. I was referring to bugs like the missing smp_processor_id patch in asm-i386/mmu_context.h. Your way makes such problems disappear once you switch on the debugger. Remember that we spotted the mmu_context issue via kgdb.

Got it now. Indeed, making such kind of bugs disappear would be a very undesirable side-effect of enabling KGDB.

Quoted 5 lines

The attached kgdb-ipipe patch (which also updates to kgdb-CVS head) addresses maintenance and smp-safeness by redefining the involved services only per source file, not kernel-wide. What's do you think about this approach?

Quoted 11 lines

Mixed feelings. On one hand, it locally fixes the issue without masking any bugs and that's good. On the other hand, I've been bitten using this kind of tricks in earlier Adeos releases for patching printk() the same way, substituting it with spin_lock_irqsave_hw. At some point, spin_lock_irqsave became local_irq_save + spin_lock in the vanilla code, making the substitution of the former pointless, and opening a preemption hole in the code. This said, no spinlock macros are involved in the substitution you are suggesting, so there is no such risk, and in any case, the risk is confined to one file and not spread all over the place like with the raw_smp_processor_id() substitution. IOW, let's go your way.

I agree that it's kind of fragile, but we need to check on kgdb updates anyway. I hope for kgdb becoming mainline one day. Then the code should stabilise (if it hasn't already), and we can track it via ipipe directly
- without tricks. So far, this should help to keep efforts lower for us.

Quoted 6 lines
Quoted 2 lines

While we are at it,
#define current ipipe_safe_current() /* ? */

Nope, there is the need for some special changes.

If you refer to the cache flushing issue, then it would be better to actually check for foreign stacks explicitely, so that you could substitute current globally:

- if (CACHE_FLUSH_IS_SAFE && current->mm &&
- addr < TASK_SIZE)
+ if (CACHE_FLUSH_IS_SAFE && !testbit(IPIPE_NOSTACK_FLAG, + &ipipe_percpu_domain[cpuid]->cpudata[cpuid].status) &&
+ current->mm && addr < TASK_SIZE)

Signature · 1 line
Philippe.
author
#9 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 14 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Quoted 2 lines · Philippe Gerum

While we are at it,
#define current ipipe_safe_current() /* ? */

Nope, there is the need for some special changes.

If you refer to the cache flushing issue, then it would be better to actually check for foreign stacks explicitely, so that you could substitute current globally:

kernel/kgdb.c int kgdb_deactivate_sw_breakpoints(void) · line 897

Quoted 5 lines
kernel/kgdb.c +3 -2
-    if (CACHE_FLUSH_IS_SAFE && current->mm &&
-            addr < TASK_SIZE)
+    if (CACHE_FLUSH_IS_SAFE && !testbit(IPIPE_NOSTACK_FLAG,         
+     &ipipe_percpu_domain[cpuid]->cpudata[cpuid].status) &&
+            current->mm && addr < TASK_SIZE)

Right - on first sight. I tried to redefine current, but the ipipe_safe_current macro requires that symbol itself, ugh. Turning ipipe_safe_current into a static inline doesn't work due to circular dependencies on linux/sched.h.

So I guess it's best to keep it as it is (though kgdb-ipipe.patch would have become really cute).

Jan

#10 lore raw

[Xenomai-core] Re: [PATCH] kgdb/x86 over I-pipe

Quoted 25 lines · Jan Kiszka
Quoted 16 lines · Philippe Gerum
Quoted 8 lines · Jan Kiszka
Quoted 2 lines · Philippe Gerum

While we are at it,
#define current ipipe_safe_current() /* ? */

Nope, there is the need for some special changes.

If you refer to the cache flushing issue, then it would be better to actually check for foreign stacks explicitely, so that you could substitute current globally:

kernel/kgdb.c int kgdb_deactivate_sw_breakpoints(void) · line 897

Quoted 5 lines
kernel/kgdb.c +3 -2
-    if (CACHE_FLUSH_IS_SAFE && current->mm &&
-            addr < TASK_SIZE)
+    if (CACHE_FLUSH_IS_SAFE && !testbit(IPIPE_NOSTACK_FLAG,         
+     &ipipe_percpu_domain[cpuid]->cpudata[cpuid].status) &&
+            current->mm && addr < TASK_SIZE)
Quoted 8 lines

Right - on first sight. I tried to redefine current, but the ipipe_safe_current macro requires that symbol itself, ugh. Turning ipipe_safe_current into a static inline doesn't work due to circular dependencies on linux/sched.h.

So I guess it's best to keep it as it is (though kgdb-ipipe.patch would have become really cute).

Ack.

Signature · 1 line
Philippe.