aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kernel/perf_event.c
diff options
context:
space:
mode:
authorJean Pihet <jean.pihet@linaro.org>2014-02-03 13:18:28 -0500
committerCatalin Marinas <catalin.marinas@arm.com>2014-03-13 07:22:38 -0400
commit23c7d70d55c6d963f225744cd1b996dee68c88d1 (patch)
treedc570dd03bd458ffa5ae6c22c1b585dac9c05d19 /arch/arm64/kernel/perf_event.c
parent2ee0d7fd36a3f87bc5b29b1ec54ad6728deedb41 (diff)
ARM64: perf: add support for frame pointer unwinding in compat mode
When profiling a 32-bit application, user space callchain unwinding using the frame pointer is performed in compat mode. The code is taken over from the AARCH32 code and adapted to work on AARCH64. Signed-off-by: Jean Pihet <jean.pihet@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/perf_event.c')
-rw-r--r--arch/arm64/kernel/perf_event.c75
1 files changed, 67 insertions, 8 deletions
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 5b1cd792274a..e868c72a7938 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -1348,8 +1348,8 @@ early_initcall(init_hw_perf_events);
1348 * Callchain handling code. 1348 * Callchain handling code.
1349 */ 1349 */
1350struct frame_tail { 1350struct frame_tail {
1351 struct frame_tail __user *fp; 1351 struct frame_tail __user *fp;
1352 unsigned long lr; 1352 unsigned long lr;
1353} __attribute__((packed)); 1353} __attribute__((packed));
1354 1354
1355/* 1355/*
@@ -1386,22 +1386,80 @@ user_backtrace(struct frame_tail __user *tail,
1386 return buftail.fp; 1386 return buftail.fp;
1387} 1387}
1388 1388
1389/*
1390 * The registers we're interested in are at the end of the variable
1391 * length saved register structure. The fp points at the end of this
1392 * structure so the address of this struct is:
1393 * (struct compat_frame_tail *)(xxx->fp)-1
1394 *
1395 * This code has been adapted from the ARM OProfile support.
1396 */
1397struct compat_frame_tail {
1398 compat_uptr_t fp; /* a (struct compat_frame_tail *) in compat mode */
1399 u32 sp;
1400 u32 lr;
1401} __attribute__((packed));
1402
1403static struct compat_frame_tail __user *
1404compat_user_backtrace(struct compat_frame_tail __user *tail,
1405 struct perf_callchain_entry *entry)
1406{
1407 struct compat_frame_tail buftail;
1408 unsigned long err;
1409
1410 /* Also check accessibility of one struct frame_tail beyond */
1411 if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
1412 return NULL;
1413
1414 pagefault_disable();
1415 err = __copy_from_user_inatomic(&buftail, tail, sizeof(buftail));
1416 pagefault_enable();
1417
1418 if (err)
1419 return NULL;
1420
1421 perf_callchain_store(entry, buftail.lr);
1422
1423 /*
1424 * Frame pointers should strictly progress back up the stack
1425 * (towards higher addresses).
1426 */
1427 if (tail + 1 >= (struct compat_frame_tail __user *)
1428 compat_ptr(buftail.fp))
1429 return NULL;
1430
1431 return (struct compat_frame_tail __user *)compat_ptr(buftail.fp) - 1;
1432}
1433
1389void perf_callchain_user(struct perf_callchain_entry *entry, 1434void perf_callchain_user(struct perf_callchain_entry *entry,
1390 struct pt_regs *regs) 1435 struct pt_regs *regs)
1391{ 1436{
1392 struct frame_tail __user *tail;
1393
1394 if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { 1437 if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
1395 /* We don't support guest os callchain now */ 1438 /* We don't support guest os callchain now */
1396 return; 1439 return;
1397 } 1440 }
1398 1441
1399 perf_callchain_store(entry, regs->pc); 1442 perf_callchain_store(entry, regs->pc);
1400 tail = (struct frame_tail __user *)regs->regs[29];
1401 1443
1402 while (entry->nr < PERF_MAX_STACK_DEPTH && 1444 if (!compat_user_mode(regs)) {
1403 tail && !((unsigned long)tail & 0xf)) 1445 /* AARCH64 mode */
1404 tail = user_backtrace(tail, entry); 1446 struct frame_tail __user *tail;
1447
1448 tail = (struct frame_tail __user *)regs->regs[29];
1449
1450 while (entry->nr < PERF_MAX_STACK_DEPTH &&
1451 tail && !((unsigned long)tail & 0xf))
1452 tail = user_backtrace(tail, entry);
1453 } else {
1454 /* AARCH32 compat mode */
1455 struct compat_frame_tail __user *tail;
1456
1457 tail = (struct compat_frame_tail __user *)regs->compat_fp - 1;
1458
1459 while ((entry->nr < PERF_MAX_STACK_DEPTH) &&
1460 tail && !((unsigned long)tail & 0x3))
1461 tail = compat_user_backtrace(tail, entry);
1462 }
1405} 1463}
1406 1464
1407/* 1465/*
@@ -1429,6 +1487,7 @@ void perf_callchain_kernel(struct perf_callchain_entry *entry,
1429 frame.fp = regs->regs[29]; 1487 frame.fp = regs->regs[29];
1430 frame.sp = regs->sp; 1488 frame.sp = regs->sp;
1431 frame.pc = regs->pc; 1489 frame.pc = regs->pc;
1490
1432 walk_stackframe(&frame, callchain_trace, entry); 1491 walk_stackframe(&frame, callchain_trace, entry);
1433} 1492}
1434 1493