aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kernel/debug-monitors.c
diff options
context:
space:
mode:
authorSandeepa Prabhu <sandeepa.prabhu@linaro.org>2013-12-04 00:50:20 -0500
committerCatalin Marinas <catalin.marinas@arm.com>2013-12-19 12:43:11 -0500
commitee6214cec7818867f368c35843ea1f3dffcbb57c (patch)
treedc85030cc4fee90004063af8401489f5091af3a6 /arch/arm64/kernel/debug-monitors.c
parent26920dd2da79a3207803da9453c0e6c82ac968ca (diff)
arm64: support single-step and breakpoint handler hooks
AArch64 Single Steping and Breakpoint debug exceptions will be used by multiple debug framworks like kprobes & kgdb. This patch implements the hooks for those frameworks to register their own handlers for handling breakpoint and single step events. Reworked the debug exception handler in entry.S: do_dbg to route software breakpoint (BRK64) exception to do_debug_exception() Signed-off-by: Sandeepa Prabhu <sandeepa.prabhu@linaro.org> Signed-off-by: Deepak Saxena <dsaxena@linaro.org> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64/kernel/debug-monitors.c')
-rw-r--r--arch/arm64/kernel/debug-monitors.c88
1 files changed, 87 insertions, 1 deletions
diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index 4ae68579031d..636ba8b6240b 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -187,6 +187,48 @@ static void clear_regs_spsr_ss(struct pt_regs *regs)
187 regs->pstate = spsr; 187 regs->pstate = spsr;
188} 188}
189 189
190/* EL1 Single Step Handler hooks */
191static LIST_HEAD(step_hook);
192DEFINE_RWLOCK(step_hook_lock);
193
194void register_step_hook(struct step_hook *hook)
195{
196 write_lock(&step_hook_lock);
197 list_add(&hook->node, &step_hook);
198 write_unlock(&step_hook_lock);
199}
200
201void unregister_step_hook(struct step_hook *hook)
202{
203 write_lock(&step_hook_lock);
204 list_del(&hook->node);
205 write_unlock(&step_hook_lock);
206}
207
208/*
209 * Call registered single step handers
210 * There is no Syndrome info to check for determining the handler.
211 * So we call all the registered handlers, until the right handler is
212 * found which returns zero.
213 */
214static int call_step_hook(struct pt_regs *regs, unsigned int esr)
215{
216 struct step_hook *hook;
217 int retval = DBG_HOOK_ERROR;
218
219 read_lock(&step_hook_lock);
220
221 list_for_each_entry(hook, &step_hook, node) {
222 retval = hook->fn(regs, esr);
223 if (retval == DBG_HOOK_HANDLED)
224 break;
225 }
226
227 read_unlock(&step_hook_lock);
228
229 return retval;
230}
231
190static int single_step_handler(unsigned long addr, unsigned int esr, 232static int single_step_handler(unsigned long addr, unsigned int esr,
191 struct pt_regs *regs) 233 struct pt_regs *regs)
192{ 234{
@@ -214,7 +256,9 @@ static int single_step_handler(unsigned long addr, unsigned int esr,
214 */ 256 */
215 user_rewind_single_step(current); 257 user_rewind_single_step(current);
216 } else { 258 } else {
217 /* TODO: route to KGDB */ 259 if (call_step_hook(regs, esr) == DBG_HOOK_HANDLED)
260 return 0;
261
218 pr_warning("Unexpected kernel single-step exception at EL1\n"); 262 pr_warning("Unexpected kernel single-step exception at EL1\n");
219 /* 263 /*
220 * Re-enable stepping since we know that we will be 264 * Re-enable stepping since we know that we will be
@@ -226,11 +270,53 @@ static int single_step_handler(unsigned long addr, unsigned int esr,
226 return 0; 270 return 0;
227} 271}
228 272
273/*
274 * Breakpoint handler is re-entrant as another breakpoint can
275 * hit within breakpoint handler, especically in kprobes.
276 * Use reader/writer locks instead of plain spinlock.
277 */
278static LIST_HEAD(break_hook);
279DEFINE_RWLOCK(break_hook_lock);
280
281void register_break_hook(struct break_hook *hook)
282{
283 write_lock(&break_hook_lock);
284 list_add(&hook->node, &break_hook);
285 write_unlock(&break_hook_lock);
286}
287
288void unregister_break_hook(struct break_hook *hook)
289{
290 write_lock(&break_hook_lock);
291 list_del(&hook->node);
292 write_unlock(&break_hook_lock);
293}
294
295static int call_break_hook(struct pt_regs *regs, unsigned int esr)
296{
297 struct break_hook *hook;
298 int (*fn)(struct pt_regs *regs, unsigned int esr) = NULL;
299
300 read_lock(&break_hook_lock);
301 list_for_each_entry(hook, &break_hook, node)
302 if ((esr & hook->esr_mask) == hook->esr_val)
303 fn = hook->fn;
304 read_unlock(&break_hook_lock);
305
306 return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
307}
308
229static int brk_handler(unsigned long addr, unsigned int esr, 309static int brk_handler(unsigned long addr, unsigned int esr,
230 struct pt_regs *regs) 310 struct pt_regs *regs)
231{ 311{
232 siginfo_t info; 312 siginfo_t info;
233 313
314 if (call_break_hook(regs, esr) == DBG_HOOK_HANDLED)
315 return 0;
316
317 pr_warn("unexpected brk exception at %lx, esr=0x%x\n",
318 (long)instruction_pointer(regs), esr);
319
234 if (!user_mode(regs)) 320 if (!user_mode(regs))
235 return -EFAULT; 321 return -EFAULT;
236 322