2008-04-18 02:05:37 +08:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Amit S. Kale <amitkale@linsyssoft.com>
|
|
|
|
* Copyright (C) 2000-2001 VERITAS Software Corporation.
|
|
|
|
* Copyright (C) 2002 Andi Kleen, SuSE Labs
|
|
|
|
* Copyright (C) 2004 LinSysSoft Technologies Pvt. Ltd.
|
|
|
|
* Copyright (C) 2007 MontaVista Software, Inc.
|
|
|
|
* Copyright (C) 2007-2008 Jason Wessel, Wind River Systems, Inc.
|
|
|
|
*/
|
|
|
|
/****************************************************************************
|
|
|
|
* Contributor: Lake Stevens Instrument Division$
|
|
|
|
* Written by: Glenn Engel $
|
|
|
|
* Updated by: Amit Kale<akale@veritas.com>
|
|
|
|
* Updated by: Tom Rini <trini@kernel.crashing.org>
|
|
|
|
* Updated by: Jason Wessel <jason.wessel@windriver.com>
|
|
|
|
* Modified for 386 by Jim Kingdon, Cygnus Support.
|
|
|
|
* Origianl kgdb, compatibility with 2.1.xx kernel by
|
|
|
|
* David Grothe <dave@gcom.com>
|
|
|
|
* Integrated into 2.2.5 kernel by Tigran Aivazian <tigran@sco.com>
|
|
|
|
* X86_64 changes from Andi Kleen's patch merged by Jim Houston
|
|
|
|
*/
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/kgdb.h>
|
|
|
|
#include <linux/smp.h>
|
2008-02-16 04:55:53 +08:00
|
|
|
#include <linux/nmi.h>
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
#include <linux/hw_breakpoint.h>
|
2012-03-23 22:35:05 +08:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/memory.h>
|
2008-04-18 02:05:37 +08:00
|
|
|
|
2016-04-27 03:23:24 +08:00
|
|
|
#include <asm/text-patching.h>
|
2009-06-02 02:17:06 +08:00
|
|
|
#include <asm/debugreg.h>
|
2008-04-18 02:05:37 +08:00
|
|
|
#include <asm/apicdef.h>
|
2009-02-17 20:58:15 +08:00
|
|
|
#include <asm/apic.h>
|
2011-01-07 05:18:49 +08:00
|
|
|
#include <asm/nmi.h>
|
2016-08-14 00:38:18 +08:00
|
|
|
#include <asm/switch_to.h>
|
2008-04-18 02:05:37 +08:00
|
|
|
|
2010-08-05 22:22:20 +08:00
|
|
|
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
|
2008-04-18 02:05:37 +08:00
|
|
|
{
|
2010-08-05 22:22:20 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
{ "ax", 4, offsetof(struct pt_regs, ax) },
|
|
|
|
{ "cx", 4, offsetof(struct pt_regs, cx) },
|
|
|
|
{ "dx", 4, offsetof(struct pt_regs, dx) },
|
|
|
|
{ "bx", 4, offsetof(struct pt_regs, bx) },
|
|
|
|
{ "sp", 4, offsetof(struct pt_regs, sp) },
|
|
|
|
{ "bp", 4, offsetof(struct pt_regs, bp) },
|
|
|
|
{ "si", 4, offsetof(struct pt_regs, si) },
|
|
|
|
{ "di", 4, offsetof(struct pt_regs, di) },
|
|
|
|
{ "ip", 4, offsetof(struct pt_regs, ip) },
|
|
|
|
{ "flags", 4, offsetof(struct pt_regs, flags) },
|
|
|
|
{ "cs", 4, offsetof(struct pt_regs, cs) },
|
|
|
|
{ "ss", 4, offsetof(struct pt_regs, ss) },
|
|
|
|
{ "ds", 4, offsetof(struct pt_regs, ds) },
|
|
|
|
{ "es", 4, offsetof(struct pt_regs, es) },
|
|
|
|
#else
|
|
|
|
{ "ax", 8, offsetof(struct pt_regs, ax) },
|
|
|
|
{ "bx", 8, offsetof(struct pt_regs, bx) },
|
|
|
|
{ "cx", 8, offsetof(struct pt_regs, cx) },
|
|
|
|
{ "dx", 8, offsetof(struct pt_regs, dx) },
|
2015-04-02 17:01:59 +08:00
|
|
|
{ "si", 8, offsetof(struct pt_regs, si) },
|
2010-08-05 22:22:20 +08:00
|
|
|
{ "di", 8, offsetof(struct pt_regs, di) },
|
|
|
|
{ "bp", 8, offsetof(struct pt_regs, bp) },
|
|
|
|
{ "sp", 8, offsetof(struct pt_regs, sp) },
|
|
|
|
{ "r8", 8, offsetof(struct pt_regs, r8) },
|
|
|
|
{ "r9", 8, offsetof(struct pt_regs, r9) },
|
|
|
|
{ "r10", 8, offsetof(struct pt_regs, r10) },
|
|
|
|
{ "r11", 8, offsetof(struct pt_regs, r11) },
|
|
|
|
{ "r12", 8, offsetof(struct pt_regs, r12) },
|
|
|
|
{ "r13", 8, offsetof(struct pt_regs, r13) },
|
|
|
|
{ "r14", 8, offsetof(struct pt_regs, r14) },
|
|
|
|
{ "r15", 8, offsetof(struct pt_regs, r15) },
|
|
|
|
{ "ip", 8, offsetof(struct pt_regs, ip) },
|
|
|
|
{ "flags", 4, offsetof(struct pt_regs, flags) },
|
|
|
|
{ "cs", 4, offsetof(struct pt_regs, cs) },
|
|
|
|
{ "ss", 4, offsetof(struct pt_regs, ss) },
|
2012-03-20 04:16:48 +08:00
|
|
|
{ "ds", 4, -1 },
|
|
|
|
{ "es", 4, -1 },
|
2008-09-26 23:36:42 +08:00
|
|
|
#endif
|
2012-03-20 04:16:48 +08:00
|
|
|
{ "fs", 4, -1 },
|
|
|
|
{ "gs", 4, -1 },
|
2010-08-05 22:22:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (
|
2008-04-18 02:05:37 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2010-08-05 22:22:20 +08:00
|
|
|
regno == GDB_SS || regno == GDB_FS || regno == GDB_GS ||
|
|
|
|
#endif
|
|
|
|
regno == GDB_SP || regno == GDB_ORIG_AX)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
|
|
memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
|
|
|
|
dbg_reg_def[regno].size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regno == GDB_ORIG_AX) {
|
|
|
|
memcpy(mem, ®s->orig_ax, sizeof(regs->orig_ax));
|
|
|
|
return "orig_ax";
|
2009-12-11 22:43:16 +08:00
|
|
|
}
|
2010-08-05 22:22:20 +08:00
|
|
|
if (regno >= DBG_MAX_REG_NUM || regno < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
|
|
memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
|
|
|
|
dbg_reg_def[regno].size);
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
2010-03-15 20:28:00 +08:00
|
|
|
switch (regno) {
|
2010-08-05 22:22:20 +08:00
|
|
|
case GDB_SS:
|
2015-03-19 09:33:33 +08:00
|
|
|
if (!user_mode(regs))
|
2010-08-05 22:22:20 +08:00
|
|
|
*(unsigned long *)mem = __KERNEL_DS;
|
|
|
|
break;
|
|
|
|
case GDB_SP:
|
2015-03-19 09:33:33 +08:00
|
|
|
if (!user_mode(regs))
|
2010-08-05 22:22:20 +08:00
|
|
|
*(unsigned long *)mem = kernel_stack_pointer(regs);
|
|
|
|
break;
|
|
|
|
case GDB_GS:
|
|
|
|
case GDB_FS:
|
|
|
|
*(unsigned long *)mem = 0xFFFF;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-15 20:28:00 +08:00
|
|
|
#endif
|
2010-08-05 22:22:20 +08:00
|
|
|
return dbg_reg_def[regno].name;
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
|
|
|
|
* @gdb_regs: A pointer to hold the registers in the order GDB wants.
|
|
|
|
* @p: The &struct task_struct of the desired process.
|
|
|
|
*
|
|
|
|
* Convert the register values of the sleeping process in @p to
|
|
|
|
* the format that GDB expects.
|
|
|
|
* This function is called when kgdb does not have access to the
|
|
|
|
* &struct pt_regs and therefore it should fill the gdb registers
|
|
|
|
* @gdb_regs with what has been saved in &struct thread_struct
|
|
|
|
* thread field during switch_to.
|
|
|
|
*/
|
|
|
|
void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
|
|
|
|
{
|
2008-09-26 23:36:42 +08:00
|
|
|
#ifndef CONFIG_X86_32
|
|
|
|
u32 *gdb_regs32 = (u32 *)gdb_regs;
|
|
|
|
#endif
|
2008-04-18 02:05:37 +08:00
|
|
|
gdb_regs[GDB_AX] = 0;
|
|
|
|
gdb_regs[GDB_BX] = 0;
|
|
|
|
gdb_regs[GDB_CX] = 0;
|
|
|
|
gdb_regs[GDB_DX] = 0;
|
|
|
|
gdb_regs[GDB_SI] = 0;
|
|
|
|
gdb_regs[GDB_DI] = 0;
|
2016-08-14 00:38:18 +08:00
|
|
|
gdb_regs[GDB_BP] = ((struct inactive_task_frame *)p->thread.sp)->bp;
|
2008-04-18 02:05:37 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
gdb_regs[GDB_DS] = __KERNEL_DS;
|
|
|
|
gdb_regs[GDB_ES] = __KERNEL_DS;
|
|
|
|
gdb_regs[GDB_PS] = 0;
|
|
|
|
gdb_regs[GDB_CS] = __KERNEL_CS;
|
|
|
|
gdb_regs[GDB_SS] = __KERNEL_DS;
|
|
|
|
gdb_regs[GDB_FS] = 0xFFFF;
|
|
|
|
gdb_regs[GDB_GS] = 0xFFFF;
|
|
|
|
#else
|
2016-08-14 00:38:17 +08:00
|
|
|
gdb_regs32[GDB_PS] = 0;
|
2008-09-26 23:36:42 +08:00
|
|
|
gdb_regs32[GDB_CS] = __KERNEL_CS;
|
|
|
|
gdb_regs32[GDB_SS] = __KERNEL_DS;
|
2008-04-18 02:05:37 +08:00
|
|
|
gdb_regs[GDB_R8] = 0;
|
|
|
|
gdb_regs[GDB_R9] = 0;
|
|
|
|
gdb_regs[GDB_R10] = 0;
|
|
|
|
gdb_regs[GDB_R11] = 0;
|
|
|
|
gdb_regs[GDB_R12] = 0;
|
|
|
|
gdb_regs[GDB_R13] = 0;
|
|
|
|
gdb_regs[GDB_R14] = 0;
|
|
|
|
gdb_regs[GDB_R15] = 0;
|
|
|
|
#endif
|
2016-08-14 00:38:16 +08:00
|
|
|
gdb_regs[GDB_PC] = 0;
|
2008-04-18 02:05:37 +08:00
|
|
|
gdb_regs[GDB_SP] = p->thread.sp;
|
|
|
|
}
|
|
|
|
|
2008-02-16 04:55:56 +08:00
|
|
|
static struct hw_breakpoint {
|
|
|
|
unsigned enabled;
|
|
|
|
unsigned long addr;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
int len;
|
|
|
|
int type;
|
2010-08-08 02:00:59 +08:00
|
|
|
struct perf_event * __percpu *pev;
|
2010-08-05 22:22:25 +08:00
|
|
|
} breakinfo[HBP_NUM];
|
2008-02-16 04:55:56 +08:00
|
|
|
|
2010-05-21 10:04:30 +08:00
|
|
|
static unsigned long early_dr7;
|
|
|
|
|
2008-02-16 04:55:56 +08:00
|
|
|
static void kgdb_correct_hw_break(void)
|
|
|
|
{
|
|
|
|
int breakno;
|
|
|
|
|
2010-08-05 22:22:25 +08:00
|
|
|
for (breakno = 0; breakno < HBP_NUM; breakno++) {
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
struct perf_event *bp;
|
|
|
|
struct arch_hw_breakpoint *info;
|
|
|
|
int val;
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
if (!breakinfo[breakno].enabled)
|
|
|
|
continue;
|
2010-05-21 10:04:30 +08:00
|
|
|
if (dbg_is_early) {
|
|
|
|
set_debugreg(breakinfo[breakno].addr, breakno);
|
|
|
|
early_dr7 |= encode_dr7(breakno,
|
|
|
|
breakinfo[breakno].len,
|
|
|
|
breakinfo[breakno].type);
|
|
|
|
set_debugreg(early_dr7, 7);
|
|
|
|
continue;
|
|
|
|
}
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
bp = *per_cpu_ptr(breakinfo[breakno].pev, cpu);
|
|
|
|
info = counter_arch_bp(bp);
|
|
|
|
if (bp->attr.disabled != 1)
|
|
|
|
continue;
|
|
|
|
bp->attr.bp_addr = breakinfo[breakno].addr;
|
|
|
|
bp->attr.bp_len = breakinfo[breakno].len;
|
|
|
|
bp->attr.bp_type = breakinfo[breakno].type;
|
|
|
|
info->address = breakinfo[breakno].addr;
|
|
|
|
info->len = breakinfo[breakno].len;
|
|
|
|
info->type = breakinfo[breakno].type;
|
|
|
|
val = arch_install_hw_breakpoint(bp);
|
|
|
|
if (!val)
|
|
|
|
bp->attr.disabled = 0;
|
2008-02-16 04:55:56 +08:00
|
|
|
}
|
2010-05-21 10:04:30 +08:00
|
|
|
if (!dbg_is_early)
|
|
|
|
hw_breakpoint_restore();
|
2008-02-16 04:55:56 +08:00
|
|
|
}
|
|
|
|
|
2010-01-29 07:04:43 +08:00
|
|
|
static int hw_break_reserve_slot(int breakno)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
int cnt = 0;
|
|
|
|
struct perf_event **pevent;
|
|
|
|
|
2010-05-21 10:04:30 +08:00
|
|
|
if (dbg_is_early)
|
|
|
|
return 0;
|
|
|
|
|
2010-01-29 07:04:43 +08:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
cnt++;
|
|
|
|
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
|
|
|
|
if (dbg_reserve_bp_slot(*pevent))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
cnt--;
|
|
|
|
if (!cnt)
|
|
|
|
break;
|
|
|
|
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
|
|
|
|
dbg_release_bp_slot(*pevent);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hw_break_release_slot(int breakno)
|
|
|
|
{
|
|
|
|
struct perf_event **pevent;
|
|
|
|
int cpu;
|
|
|
|
|
2010-05-21 10:04:30 +08:00
|
|
|
if (dbg_is_early)
|
|
|
|
return 0;
|
|
|
|
|
2010-01-29 07:04:43 +08:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
pevent = per_cpu_ptr(breakinfo[breakno].pev, cpu);
|
|
|
|
if (dbg_release_bp_slot(*pevent))
|
|
|
|
/*
|
2011-03-18 03:24:16 +08:00
|
|
|
* The debugger is responsible for handing the retry on
|
2010-01-29 07:04:43 +08:00
|
|
|
* remove failure.
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-16 04:55:56 +08:00
|
|
|
static int
|
|
|
|
kgdb_remove_hw_break(unsigned long addr, int len, enum kgdb_bptype bptype)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-08-05 22:22:25 +08:00
|
|
|
for (i = 0; i < HBP_NUM; i++)
|
2008-02-16 04:55:56 +08:00
|
|
|
if (breakinfo[i].addr == addr && breakinfo[i].enabled)
|
|
|
|
break;
|
2010-08-05 22:22:25 +08:00
|
|
|
if (i == HBP_NUM)
|
2008-02-16 04:55:56 +08:00
|
|
|
return -1;
|
|
|
|
|
2010-01-29 07:04:43 +08:00
|
|
|
if (hw_break_release_slot(i)) {
|
|
|
|
printk(KERN_ERR "Cannot remove hw breakpoint at %lx\n", addr);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-02-16 04:55:56 +08:00
|
|
|
breakinfo[i].enabled = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kgdb_remove_all_hw_break(void)
|
|
|
|
{
|
|
|
|
int i;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
struct perf_event *bp;
|
2008-02-16 04:55:56 +08:00
|
|
|
|
2010-08-05 22:22:25 +08:00
|
|
|
for (i = 0; i < HBP_NUM; i++) {
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
if (!breakinfo[i].enabled)
|
|
|
|
continue;
|
|
|
|
bp = *per_cpu_ptr(breakinfo[i].pev, cpu);
|
2010-11-15 22:07:35 +08:00
|
|
|
if (!bp->attr.disabled) {
|
|
|
|
arch_uninstall_hw_breakpoint(bp);
|
|
|
|
bp->attr.disabled = 1;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
continue;
|
2010-11-15 22:07:35 +08:00
|
|
|
}
|
2010-05-21 10:04:30 +08:00
|
|
|
if (dbg_is_early)
|
|
|
|
early_dr7 &= ~encode_dr7(i, breakinfo[i].len,
|
|
|
|
breakinfo[i].type);
|
2010-11-15 22:07:35 +08:00
|
|
|
else if (hw_break_release_slot(i))
|
|
|
|
printk(KERN_ERR "KGDB: hw bpt remove failed %lx\n",
|
|
|
|
breakinfo[i].addr);
|
|
|
|
breakinfo[i].enabled = 0;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
}
|
2008-02-16 04:55:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kgdb_set_hw_break(unsigned long addr, int len, enum kgdb_bptype bptype)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-08-05 22:22:25 +08:00
|
|
|
for (i = 0; i < HBP_NUM; i++)
|
2008-02-16 04:55:56 +08:00
|
|
|
if (!breakinfo[i].enabled)
|
|
|
|
break;
|
2010-08-05 22:22:25 +08:00
|
|
|
if (i == HBP_NUM)
|
2008-02-16 04:55:56 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
switch (bptype) {
|
|
|
|
case BP_HARDWARE_BREAKPOINT:
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
len = 1;
|
|
|
|
breakinfo[i].type = X86_BREAKPOINT_EXECUTE;
|
2008-02-16 04:55:56 +08:00
|
|
|
break;
|
|
|
|
case BP_WRITE_WATCHPOINT:
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
breakinfo[i].type = X86_BREAKPOINT_WRITE;
|
2008-02-16 04:55:56 +08:00
|
|
|
break;
|
|
|
|
case BP_ACCESS_WATCHPOINT:
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
breakinfo[i].type = X86_BREAKPOINT_RW;
|
2008-02-16 04:55:56 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
switch (len) {
|
|
|
|
case 1:
|
|
|
|
breakinfo[i].len = X86_BREAKPOINT_LEN_1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
breakinfo[i].len = X86_BREAKPOINT_LEN_2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
breakinfo[i].len = X86_BREAKPOINT_LEN_4;
|
|
|
|
break;
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
case 8:
|
|
|
|
breakinfo[i].len = X86_BREAKPOINT_LEN_8;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2008-02-16 04:55:56 +08:00
|
|
|
return -1;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
}
|
2008-02-16 04:55:56 +08:00
|
|
|
breakinfo[i].addr = addr;
|
2010-01-29 07:04:43 +08:00
|
|
|
if (hw_break_reserve_slot(i)) {
|
|
|
|
breakinfo[i].addr = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
breakinfo[i].enabled = 1;
|
2008-02-16 04:55:56 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
|
|
|
|
* @regs: Current &struct pt_regs.
|
|
|
|
*
|
|
|
|
* This function will be called if the particular architecture must
|
|
|
|
* disable hardware debugging while it is processing gdb packets or
|
|
|
|
* handling exception.
|
|
|
|
*/
|
2010-08-18 19:02:00 +08:00
|
|
|
static void kgdb_disable_hw_debug(struct pt_regs *regs)
|
2008-02-16 04:55:56 +08:00
|
|
|
{
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
int i;
|
|
|
|
int cpu = raw_smp_processor_id();
|
|
|
|
struct perf_event *bp;
|
|
|
|
|
2008-02-16 04:55:56 +08:00
|
|
|
/* Disable hardware debugging while we are in kgdb: */
|
|
|
|
set_debugreg(0UL, 7);
|
2010-08-05 22:22:25 +08:00
|
|
|
for (i = 0; i < HBP_NUM; i++) {
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
if (!breakinfo[i].enabled)
|
|
|
|
continue;
|
2010-05-21 10:04:30 +08:00
|
|
|
if (dbg_is_early) {
|
|
|
|
early_dr7 &= ~encode_dr7(i, breakinfo[i].len,
|
|
|
|
breakinfo[i].type);
|
|
|
|
continue;
|
|
|
|
}
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
bp = *per_cpu_ptr(breakinfo[i].pev, cpu);
|
|
|
|
if (bp->attr.disabled == 1)
|
|
|
|
continue;
|
|
|
|
arch_uninstall_hw_breakpoint(bp);
|
|
|
|
bp->attr.disabled = 1;
|
|
|
|
}
|
2008-02-16 04:55:56 +08:00
|
|
|
}
|
|
|
|
|
2008-04-18 02:05:37 +08:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/**
|
|
|
|
* kgdb_roundup_cpus - Get other CPUs into a holding pattern
|
|
|
|
*
|
|
|
|
* On SMP systems, we need to get the attention of the other CPUs
|
|
|
|
* and get them be in a known state. This should do what is needed
|
|
|
|
* to get the other CPUs to call kgdb_wait(). Note that on some arches,
|
|
|
|
* the NMI approach is not used for rounding up all the CPUs. For example,
|
2018-12-05 11:38:25 +08:00
|
|
|
* in case of MIPS, smp_call_function() is used to roundup CPUs.
|
2008-04-18 02:05:37 +08:00
|
|
|
*
|
|
|
|
* On non-SMP systems, this is not called.
|
|
|
|
*/
|
2018-12-05 11:38:25 +08:00
|
|
|
void kgdb_roundup_cpus(void)
|
2008-04-18 02:05:37 +08:00
|
|
|
{
|
2009-01-28 22:42:24 +08:00
|
|
|
apic->send_IPI_allbutself(APIC_DM_NMI);
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kgdb_arch_handle_exception - Handle architecture specific GDB packets.
|
2012-06-12 12:53:21 +08:00
|
|
|
* @e_vector: The error vector of the exception that happened.
|
2008-04-18 02:05:37 +08:00
|
|
|
* @signo: The signal number of the exception that happened.
|
|
|
|
* @err_code: The error code of the exception that happened.
|
2012-06-12 12:53:21 +08:00
|
|
|
* @remcomInBuffer: The buffer of the packet we have read.
|
|
|
|
* @remcomOutBuffer: The buffer of %BUFMAX bytes to write a packet into.
|
|
|
|
* @linux_regs: The &struct pt_regs of the current process.
|
2008-04-18 02:05:37 +08:00
|
|
|
*
|
|
|
|
* This function MUST handle the 'c' and 's' command packets,
|
|
|
|
* as well packets to set / remove a hardware breakpoint, if used.
|
|
|
|
* If there are additional packets which the hardware needs to handle,
|
|
|
|
* they are handled here. The code should return -1 if it wants to
|
|
|
|
* process more packets, and a %0 or %1 if it wants to exit from the
|
|
|
|
* kgdb callback.
|
|
|
|
*/
|
|
|
|
int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
|
|
|
|
char *remcomInBuffer, char *remcomOutBuffer,
|
|
|
|
struct pt_regs *linux_regs)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
switch (remcomInBuffer[0]) {
|
|
|
|
case 'c':
|
|
|
|
case 's':
|
|
|
|
/* try to read optional parameter, pc unchanged if no parm */
|
|
|
|
ptr = &remcomInBuffer[1];
|
|
|
|
if (kgdb_hex2long(&ptr, &addr))
|
|
|
|
linux_regs->ip = addr;
|
2019-01-26 02:39:03 +08:00
|
|
|
/* fall through */
|
2008-03-08 06:34:16 +08:00
|
|
|
case 'D':
|
|
|
|
case 'k':
|
2008-04-18 02:05:37 +08:00
|
|
|
/* clear the trace bit */
|
2008-04-19 00:54:38 +08:00
|
|
|
linux_regs->flags &= ~X86_EFLAGS_TF;
|
2008-04-18 02:05:37 +08:00
|
|
|
atomic_set(&kgdb_cpu_doing_single_step, -1);
|
|
|
|
|
|
|
|
/* set the trace bit if we're stepping */
|
|
|
|
if (remcomInBuffer[0] == 's') {
|
2008-04-19 00:54:38 +08:00
|
|
|
linux_regs->flags |= X86_EFLAGS_TF;
|
kgdb, x86, arm, mips, powerpc: ignore user space single stepping
On the x86 arch, user space single step exceptions should be ignored
if they occur in the kernel space, such as ptrace stepping through a
system call.
First check if it is kgdb that is executing a single step, then ensure
it is not an accidental traversal into the user space, while in kgdb,
any other time the TIF_SINGLESTEP is set, kgdb should ignore the
exception.
On x86, arm, mips and powerpc, the kgdb_contthread usage was
inconsistent with the way single stepping is implemented in the kgdb
core. The arch specific stub should always set the
kgdb_cpu_doing_single_step correctly if it is single stepping. This
allows kgdb to correctly process an instruction steps if ptrace
happens to be requesting an instruction step over a system call.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
2008-09-26 23:36:41 +08:00
|
|
|
atomic_set(&kgdb_cpu_doing_single_step,
|
|
|
|
raw_smp_processor_id());
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this means that we do not want to exit from the handler: */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
single_step_cont(struct pt_regs *regs, struct die_args *args)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Single step exception from kernel space to user space so
|
|
|
|
* eat the exception and continue the process:
|
|
|
|
*/
|
|
|
|
printk(KERN_ERR "KGDB: trap/step from kernel to user space, "
|
|
|
|
"resuming...\n");
|
|
|
|
kgdb_arch_handle_exception(args->trapnr, args->signr,
|
|
|
|
args->err, "c", "", regs);
|
2009-06-02 02:17:06 +08:00
|
|
|
/*
|
|
|
|
* Reset the BS bit in dr6 (pointed by args->err) to
|
|
|
|
* denote completion of processing
|
|
|
|
*/
|
|
|
|
(*(unsigned long *)ERR_PTR(args->err)) &= ~DR_STEP;
|
2008-04-18 02:05:37 +08:00
|
|
|
|
|
|
|
return NOTIFY_STOP;
|
|
|
|
}
|
|
|
|
|
2015-09-26 20:47:17 +08:00
|
|
|
static DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS);
|
2008-02-16 04:55:53 +08:00
|
|
|
|
2011-10-01 03:06:21 +08:00
|
|
|
static int kgdb_nmi_handler(unsigned int cmd, struct pt_regs *regs)
|
2008-04-18 02:05:37 +08:00
|
|
|
{
|
2015-09-26 20:47:17 +08:00
|
|
|
int cpu;
|
|
|
|
|
2008-04-18 02:05:37 +08:00
|
|
|
switch (cmd) {
|
2011-10-01 03:06:21 +08:00
|
|
|
case NMI_LOCAL:
|
2008-04-18 02:05:37 +08:00
|
|
|
if (atomic_read(&kgdb_active) != -1) {
|
|
|
|
/* KGDB CPU roundup */
|
2015-09-26 20:47:17 +08:00
|
|
|
cpu = raw_smp_processor_id();
|
|
|
|
kgdb_nmicallback(cpu, regs);
|
|
|
|
set_bit(cpu, was_in_debug_nmi);
|
2008-02-16 04:55:53 +08:00
|
|
|
touch_nmi_watchdog();
|
2015-09-26 20:47:17 +08:00
|
|
|
|
2011-10-01 03:06:21 +08:00
|
|
|
return NMI_HANDLED;
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
2011-10-01 03:06:21 +08:00
|
|
|
break;
|
2008-04-18 02:05:37 +08:00
|
|
|
|
2011-10-01 03:06:21 +08:00
|
|
|
case NMI_UNKNOWN:
|
2015-09-26 20:47:17 +08:00
|
|
|
cpu = raw_smp_processor_id();
|
|
|
|
|
|
|
|
if (__test_and_clear_bit(cpu, was_in_debug_nmi))
|
2011-10-01 03:06:21 +08:00
|
|
|
return NMI_HANDLED;
|
2015-09-26 20:47:17 +08:00
|
|
|
|
2011-10-01 03:06:21 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NMI_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __kgdb_notify(struct die_args *args, unsigned long cmd)
|
|
|
|
{
|
|
|
|
struct pt_regs *regs = args->regs;
|
2008-04-18 02:05:37 +08:00
|
|
|
|
2011-10-01 03:06:21 +08:00
|
|
|
switch (cmd) {
|
2008-04-18 02:05:37 +08:00
|
|
|
case DIE_DEBUG:
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
|
kgdb, x86, arm, mips, powerpc: ignore user space single stepping
On the x86 arch, user space single step exceptions should be ignored
if they occur in the kernel space, such as ptrace stepping through a
system call.
First check if it is kgdb that is executing a single step, then ensure
it is not an accidental traversal into the user space, while in kgdb,
any other time the TIF_SINGLESTEP is set, kgdb should ignore the
exception.
On x86, arm, mips and powerpc, the kgdb_contthread usage was
inconsistent with the way single stepping is implemented in the kgdb
core. The arch specific stub should always set the
kgdb_cpu_doing_single_step correctly if it is single stepping. This
allows kgdb to correctly process an instruction steps if ptrace
happens to be requesting an instruction step over a system call.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
2008-09-26 23:36:41 +08:00
|
|
|
if (user_mode(regs))
|
|
|
|
return single_step_cont(regs, args);
|
|
|
|
break;
|
|
|
|
} else if (test_thread_flag(TIF_SINGLESTEP))
|
|
|
|
/* This means a user thread is single stepping
|
|
|
|
* a system call which should be ignored
|
|
|
|
*/
|
|
|
|
return NOTIFY_DONE;
|
2008-04-18 02:05:37 +08:00
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
if (user_mode(regs))
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2010-05-21 10:04:25 +08:00
|
|
|
if (kgdb_handle_exception(args->trapnr, args->signr, cmd, regs))
|
2008-04-18 02:05:37 +08:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
2008-03-08 06:34:16 +08:00
|
|
|
/* Must touch watchdog before return to normal operation */
|
|
|
|
touch_nmi_watchdog();
|
2008-04-18 02:05:37 +08:00
|
|
|
return NOTIFY_STOP;
|
|
|
|
}
|
|
|
|
|
2010-05-21 10:04:25 +08:00
|
|
|
int kgdb_ll_trap(int cmd, const char *str,
|
|
|
|
struct pt_regs *regs, long err, int trap, int sig)
|
|
|
|
{
|
|
|
|
struct die_args args = {
|
|
|
|
.regs = regs,
|
|
|
|
.str = str,
|
|
|
|
.err = err,
|
|
|
|
.trapnr = trap,
|
|
|
|
.signr = sig,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!kgdb_io_module_registered)
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
return __kgdb_notify(&args, cmd);
|
|
|
|
}
|
|
|
|
|
2008-04-18 02:05:37 +08:00
|
|
|
static int
|
|
|
|
kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
ret = __kgdb_notify(ptr, cmd);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block kgdb_notifier = {
|
|
|
|
.notifier_call = kgdb_notify,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-24 07:34:30 +08:00
|
|
|
* kgdb_arch_init - Perform any architecture specific initialization.
|
2008-04-18 02:05:37 +08:00
|
|
|
*
|
2016-02-24 07:34:30 +08:00
|
|
|
* This function will handle the initialization of any architecture
|
2008-04-18 02:05:37 +08:00
|
|
|
* specific callbacks.
|
|
|
|
*/
|
|
|
|
int kgdb_arch_init(void)
|
2010-05-21 10:04:29 +08:00
|
|
|
{
|
2011-10-01 03:06:21 +08:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = register_die_notifier(&kgdb_notifier);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retval = register_nmi_handler(NMI_LOCAL, kgdb_nmi_handler,
|
|
|
|
0, "kgdb");
|
|
|
|
if (retval)
|
|
|
|
goto out1;
|
|
|
|
|
|
|
|
retval = register_nmi_handler(NMI_UNKNOWN, kgdb_nmi_handler,
|
|
|
|
0, "kgdb");
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
goto out2;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
out2:
|
|
|
|
unregister_nmi_handler(NMI_LOCAL, "kgdb");
|
|
|
|
out1:
|
|
|
|
unregister_die_notifier(&kgdb_notifier);
|
|
|
|
out:
|
|
|
|
return retval;
|
2010-05-21 10:04:29 +08:00
|
|
|
}
|
|
|
|
|
2011-06-27 20:41:57 +08:00
|
|
|
static void kgdb_hw_overflow_handler(struct perf_event *event,
|
2010-07-29 08:10:30 +08:00
|
|
|
struct perf_sample_data *data, struct pt_regs *regs)
|
|
|
|
{
|
2010-10-20 21:20:00 +08:00
|
|
|
struct task_struct *tsk = current;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (breakinfo[i].enabled)
|
|
|
|
tsk->thread.debugreg6 |= (DR_TRAP0 << i);
|
2010-07-29 08:10:30 +08:00
|
|
|
}
|
|
|
|
|
2010-05-21 10:04:29 +08:00
|
|
|
void kgdb_arch_late(void)
|
2008-04-18 02:05:37 +08:00
|
|
|
{
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
int i, cpu;
|
|
|
|
struct perf_event_attr attr;
|
|
|
|
struct perf_event **pevent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pre-allocate the hw breakpoint structions in the non-atomic
|
|
|
|
* portion of kgdb because this operation requires mutexs to
|
|
|
|
* complete.
|
|
|
|
*/
|
2010-03-31 03:05:07 +08:00
|
|
|
hw_breakpoint_init(&attr);
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
attr.bp_addr = (unsigned long)kgdb_arch_init;
|
|
|
|
attr.bp_len = HW_BREAKPOINT_LEN_1;
|
|
|
|
attr.bp_type = HW_BREAKPOINT_W;
|
|
|
|
attr.disabled = 1;
|
2010-08-05 22:22:25 +08:00
|
|
|
for (i = 0; i < HBP_NUM; i++) {
|
2010-05-21 10:04:29 +08:00
|
|
|
if (breakinfo[i].pev)
|
|
|
|
continue;
|
2011-06-29 23:42:35 +08:00
|
|
|
breakinfo[i].pev = register_wide_hw_breakpoint(&attr, NULL, NULL);
|
2010-08-23 22:20:14 +08:00
|
|
|
if (IS_ERR((void * __force)breakinfo[i].pev)) {
|
2010-05-21 10:04:29 +08:00
|
|
|
printk(KERN_ERR "kgdb: Could not allocate hw"
|
|
|
|
"breakpoints\nDisabling the kernel debugger\n");
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
breakinfo[i].pev = NULL;
|
|
|
|
kgdb_arch_exit();
|
2010-05-21 10:04:29 +08:00
|
|
|
return;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
}
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
pevent = per_cpu_ptr(breakinfo[i].pev, cpu);
|
|
|
|
pevent[0]->hw.sample_period = 1;
|
2010-07-29 08:10:30 +08:00
|
|
|
pevent[0]->overflow_handler = kgdb_hw_overflow_handler;
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
if (pevent[0]->destroy != NULL) {
|
|
|
|
pevent[0]->destroy = NULL;
|
|
|
|
release_bp_slot(*pevent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-18 02:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kgdb_arch_exit - Perform any architecture specific uninitalization.
|
|
|
|
*
|
|
|
|
* This function will handle the uninitalization of any architecture
|
|
|
|
* specific callbacks, for dynamic registration and unregistration.
|
|
|
|
*/
|
|
|
|
void kgdb_arch_exit(void)
|
|
|
|
{
|
x86, hw_breakpoints, kgdb: Fix kgdb to use hw_breakpoint API
In the 2.6.33 kernel, the hw_breakpoint API is now used for the
performance event counters. The hw_breakpoint_handler() now
consumes the hw breakpoints that were previously set by kgdb
arch specific code. In order for kgdb to work in conjunction
with this core API change, kgdb must use some of the low level
functions of the hw_breakpoint API to install, uninstall, and
deal with hw breakpoint reservations.
The kgdb core required a change to call kgdb_disable_hw_debug
anytime a slave cpu enters kgdb_wait() in order to keep all the
hw breakpoints in sync as well as to prevent hitting a hw
breakpoint while kgdb is active.
During the architecture specific initialization of kgdb, it will
pre-allocate 4 disabled (struct perf event **) structures. Kgdb
will use these to manage the capabilities for the 4 hw
breakpoint registers, per cpu. Right now the hw_breakpoint API
does not have a way to ask how many breakpoints are available,
on each CPU so it is possible that the install of a breakpoint
might fail when kgdb restores the system to the run state. The
intent of this patch is to first get the basic functionality of
hw breakpoints working and leave it to the person debugging the
kernel to understand what hw breakpoints are in use and what
restrictions have been imposed as a result. Breakpoint
constraints will be dealt with in a future patch.
While atomic, the x86 specific kgdb code will call
arch_uninstall_hw_breakpoint() and arch_install_hw_breakpoint()
to manage the cpu specific hw breakpoints.
The net result of these changes allow kgdb to use the same pool
of hw_breakpoints that are used by the perf event API, but
neither knows about future reservations for the available hw
breakpoint slots.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: kgdb-bugreport@lists.sourceforge.net
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: torvalds@linux-foundation.org
LKML-Reference: <1264719883-7285-2-git-send-email-jason.wessel@windriver.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-29 07:04:42 +08:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (breakinfo[i].pev) {
|
|
|
|
unregister_wide_hw_breakpoint(breakinfo[i].pev);
|
|
|
|
breakinfo[i].pev = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-10-01 03:06:21 +08:00
|
|
|
unregister_nmi_handler(NMI_UNKNOWN, "kgdb");
|
|
|
|
unregister_nmi_handler(NMI_LOCAL, "kgdb");
|
2008-04-18 02:05:37 +08:00
|
|
|
unregister_die_notifier(&kgdb_notifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* kgdb_skipexception - Bail out of KGDB when we've been triggered.
|
|
|
|
* @exception: Exception vector number
|
|
|
|
* @regs: Current &struct pt_regs.
|
|
|
|
*
|
|
|
|
* On some architectures we need to skip a breakpoint exception when
|
|
|
|
* it occurs after a breakpoint has been removed.
|
|
|
|
*
|
|
|
|
* Skip an int3 exception when it occurs after a breakpoint has been
|
|
|
|
* removed. Backtrack eip by 1 since the int3 would have caused it to
|
|
|
|
* increment by 1.
|
|
|
|
*/
|
|
|
|
int kgdb_skipexception(int exception, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (exception == 3 && kgdb_isremovedbreak(regs->ip - 1)) {
|
|
|
|
regs->ip -= 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (exception == 3)
|
|
|
|
return instruction_pointer(regs) - 1;
|
|
|
|
return instruction_pointer(regs);
|
|
|
|
}
|
|
|
|
|
2010-05-21 10:04:21 +08:00
|
|
|
void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
|
|
|
|
{
|
|
|
|
regs->ip = ip;
|
|
|
|
}
|
|
|
|
|
2012-03-23 22:35:05 +08:00
|
|
|
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char opc[BREAK_INSTR_SIZE];
|
|
|
|
|
|
|
|
bpt->type = BP_BREAKPOINT;
|
|
|
|
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
|
|
|
|
BREAK_INSTR_SIZE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = probe_kernel_write((char *)bpt->bpt_addr,
|
|
|
|
arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
|
|
|
|
if (!err)
|
|
|
|
return err;
|
|
|
|
/*
|
2019-04-26 08:11:21 +08:00
|
|
|
* It is safe to call text_poke_kgdb() because normal kernel execution
|
2012-03-23 22:35:05 +08:00
|
|
|
* is stopped on all cores, so long as the text_mutex is not locked.
|
|
|
|
*/
|
|
|
|
if (mutex_is_locked(&text_mutex))
|
|
|
|
return -EBUSY;
|
2019-04-26 08:11:21 +08:00
|
|
|
text_poke_kgdb((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
|
|
|
|
BREAK_INSTR_SIZE);
|
2012-03-23 22:35:05 +08:00
|
|
|
err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
|
|
|
|
return -EINVAL;
|
|
|
|
bpt->type = BP_POKE_BREAKPOINT;
|
2016-02-18 06:41:14 +08:00
|
|
|
|
2012-03-23 22:35:05 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
char opc[BREAK_INSTR_SIZE];
|
|
|
|
|
|
|
|
if (bpt->type != BP_POKE_BREAKPOINT)
|
|
|
|
goto knl_write;
|
|
|
|
/*
|
2019-04-26 08:11:21 +08:00
|
|
|
* It is safe to call text_poke_kgdb() because normal kernel execution
|
2012-03-23 22:35:05 +08:00
|
|
|
* is stopped on all cores, so long as the text_mutex is not locked.
|
|
|
|
*/
|
|
|
|
if (mutex_is_locked(&text_mutex))
|
|
|
|
goto knl_write;
|
2019-04-26 08:11:21 +08:00
|
|
|
text_poke_kgdb((void *)bpt->bpt_addr, bpt->saved_instr,
|
|
|
|
BREAK_INSTR_SIZE);
|
2012-03-23 22:35:05 +08:00
|
|
|
err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
|
|
|
|
if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
|
|
|
|
goto knl_write;
|
|
|
|
return err;
|
2016-02-18 06:41:14 +08:00
|
|
|
|
2012-03-23 22:35:05 +08:00
|
|
|
knl_write:
|
|
|
|
return probe_kernel_write((char *)bpt->bpt_addr,
|
|
|
|
(char *)bpt->saved_instr, BREAK_INSTR_SIZE);
|
|
|
|
}
|
|
|
|
|
2018-12-07 04:07:40 +08:00
|
|
|
const struct kgdb_arch arch_kgdb_ops = {
|
2008-04-18 02:05:37 +08:00
|
|
|
/* Breakpoint instruction: */
|
|
|
|
.gdb_bpt_instr = { 0xcc },
|
2008-02-16 04:55:56 +08:00
|
|
|
.flags = KGDB_HW_BREAKPOINT,
|
|
|
|
.set_hw_breakpoint = kgdb_set_hw_break,
|
|
|
|
.remove_hw_breakpoint = kgdb_remove_hw_break,
|
2010-08-18 19:02:00 +08:00
|
|
|
.disable_hw_break = kgdb_disable_hw_debug,
|
2008-02-16 04:55:56 +08:00
|
|
|
.remove_all_hw_break = kgdb_remove_all_hw_break,
|
|
|
|
.correct_hw_break = kgdb_correct_hw_break,
|
2008-04-18 02:05:37 +08:00
|
|
|
};
|