mirror of
https://github.com/torvalds/linux.git
synced 2024-11-14 08:02:07 +00:00
dfee3a7b92
For quite some time there have been problems with memory barriers and various races with NMI on multi processor systems using the kernel debugger. The algorithm for entering the kernel debug core and resuming kernel execution was racy and had several known edge case problems with attempting to debug something on a heavily loaded system using breakpoints that are hit repeatedly and quickly. The prior "locking" design entry worked as follows: * The atomic counter kgdb_active was used with atomic exchange in order to elect a master cpu out of all the cpus that may have taken a debug exception. * The master cpu increments all elements of passive_cpu_wait[]. * The master cpu issues the round up cpus message. * Each "slave cpu" that enters the debug core increments its own element in cpu_in_kgdb[]. * Each "slave cpu" spins on passive_cpu_wait[] until it becomes 0. * The master cpu debugs the system. The new scheme removes the two arrays of atomic counters and replaces them with 2 single counters. One counter is used to count the number of cpus waiting to become a master cpu (because one or more hit an exception). The second counter is use to indicate how many cpus have entered as slave cpus. The new entry logic works as follows: * One or more cpus enters via kgdb_handle_exception() and increments the masters_in_kgdb. Each cpu attempts to get the spin lock called dbg_master_lock. * The master cpu sets kgdb_active to the current cpu. * The master cpu takes the spinlock dbg_slave_lock. * The master cpu asks to round up all the other cpus. * Each slave cpu that is not already in kgdb_handle_exception() will enter and increment slaves_in_kgdb. Each slave will now spin try_locking on dbg_slave_lock. * The master cpu waits for the sum of masters_in_kgdb and slaves_in_kgdb to be equal to the sum of the online cpus. * The master cpu debugs the system. In the new design the kgdb_active can only be changed while holding dbg_master_lock. Stress testing has not turned up any further entry/exit races that existed in the prior locking design. The prior locking design suffered from atomic variables not being truly atomic (in the capacity as used by kgdb) along with memory barrier races. Signed-off-by: Jason Wessel <jason.wessel@windriver.com> Acked-by: Dongdong Deng <dongdong.deng@windriver.com>
83 lines
2.3 KiB
C
83 lines
2.3 KiB
C
/*
|
|
* Created by: Jason Wessel <jason.wessel@windriver.com>
|
|
*
|
|
* Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
|
|
*
|
|
* This file is licensed under the terms of the GNU General Public
|
|
* License version 2. This program is licensed "as is" without any
|
|
* warranty of any kind, whether express or implied.
|
|
*/
|
|
|
|
#ifndef _DEBUG_CORE_H_
|
|
#define _DEBUG_CORE_H_
|
|
/*
|
|
* These are the private implementation headers between the kernel
|
|
* debugger core and the debugger front end code.
|
|
*/
|
|
|
|
/* kernel debug core data structures */
|
|
struct kgdb_state {
|
|
int ex_vector;
|
|
int signo;
|
|
int err_code;
|
|
int cpu;
|
|
int pass_exception;
|
|
unsigned long thr_query;
|
|
unsigned long threadid;
|
|
long kgdb_usethreadid;
|
|
struct pt_regs *linux_regs;
|
|
};
|
|
|
|
/* Exception state values */
|
|
#define DCPU_WANT_MASTER 0x1 /* Waiting to become a master kgdb cpu */
|
|
#define DCPU_NEXT_MASTER 0x2 /* Transition from one master cpu to another */
|
|
#define DCPU_IS_SLAVE 0x4 /* Slave cpu enter exception */
|
|
#define DCPU_SSTEP 0x8 /* CPU is single stepping */
|
|
|
|
struct debuggerinfo_struct {
|
|
void *debuggerinfo;
|
|
struct task_struct *task;
|
|
int exception_state;
|
|
int ret_state;
|
|
int irq_depth;
|
|
int enter_kgdb;
|
|
};
|
|
|
|
extern struct debuggerinfo_struct kgdb_info[];
|
|
|
|
/* kernel debug core break point routines */
|
|
extern int dbg_remove_all_break(void);
|
|
extern int dbg_set_sw_break(unsigned long addr);
|
|
extern int dbg_remove_sw_break(unsigned long addr);
|
|
extern int dbg_activate_sw_breakpoints(void);
|
|
extern int dbg_deactivate_sw_breakpoints(void);
|
|
|
|
/* polled character access to i/o module */
|
|
extern int dbg_io_get_char(void);
|
|
|
|
/* stub return value for switching between the gdbstub and kdb */
|
|
#define DBG_PASS_EVENT -12345
|
|
/* Switch from one cpu to another */
|
|
#define DBG_SWITCH_CPU_EVENT -123456
|
|
extern int dbg_switch_cpu;
|
|
|
|
/* gdbstub interface functions */
|
|
extern int gdb_serial_stub(struct kgdb_state *ks);
|
|
extern void gdbstub_msg_write(const char *s, int len);
|
|
|
|
/* gdbstub functions used for kdb <-> gdbstub transition */
|
|
extern int gdbstub_state(struct kgdb_state *ks, char *cmd);
|
|
extern int dbg_kdb_mode;
|
|
|
|
#ifdef CONFIG_KGDB_KDB
|
|
extern int kdb_stub(struct kgdb_state *ks);
|
|
extern int kdb_parse(const char *cmdstr);
|
|
#else /* ! CONFIG_KGDB_KDB */
|
|
static inline int kdb_stub(struct kgdb_state *ks)
|
|
{
|
|
return DBG_PASS_EVENT;
|
|
}
|
|
#endif /* CONFIG_KGDB_KDB */
|
|
|
|
#endif /* _DEBUG_CORE_H_ */
|