aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Ahern <david.ahern@oracle.com>2015-02-19 15:00:22 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-02-26 09:59:04 -0500
commit55d43bcafe78b6da33f8a49be68ef168f3cbfec9 (patch)
tree9a6d2552f32c2f073f2bf9fe33a464c529b62a39 /tools
parent0afb1704010f60e7ae85aef0f93fc10f2d99761e (diff)
perf trace: Fix SIGBUS failures due to misaligned accesses
On Sparc64 perf-trace is failing in many spots due to extended load instructions being used on misaligned accesses. (gdb) run trace ls Starting program: /tmp/perf/perf trace ls [Thread debugging using libthread_db enabled] Detaching after fork from child process 169460. <ls output removed> Program received signal SIGBUS, Bus error. 0x000000000014f4dc in tp_field__u64 (field=0x4cc700, sample=0x7feffffa098) at builtin-trace.c:61 warning: Source file is more recent than executable. 61 TP_UINT_FIELD(64); (gdb) bt 0 0x000000000014f4dc in tp_field__u64 (field=0x4cc700, sample=0x7feffffa098) at builtin-trace.c:61 1 0x0000000000156ad4 in trace__sys_exit (trace=0x7feffffc268, evsel=0x4cc580, event=0xfffffc0104912000, sample=0x7feffffa098) at builtin-trace.c:1701 2 0x0000000000158c14 in trace__run (trace=0x7feffffc268, argc=1, argv=0x7fefffff360) at builtin-trace.c:2160 3 0x000000000015b78c in cmd_trace (argc=1, argv=0x7fefffff360, prefix=0x0) at builtin-trace.c:2609 4 0x0000000000107d94 in run_builtin (p=0x4549c8, argc=2, argv=0x7fefffff360) at perf.c:341 5 0x0000000000108140 in handle_internal_command (argc=2, argv=0x7fefffff360) at perf.c:400 6 0x0000000000108308 in run_argv (argcp=0x7feffffef2c, argv=0x7feffffef20) at perf.c:444 7 0x0000000000108728 in main (argc=2, argv=0x7fefffff360) at perf.c:559 (gdb) p *sample $1 = {ip = 4391276, pid = 169472, tid = 169472, time = 6303014583281250, addr = 0, id = 72082, stream_id = 18446744073709551615, period = 1, weight = 0, transaction = 0, cpu = 73, raw_size = 36, data_src = 84410401, flags = 0, insn_len = 0, raw_data = 0xfffffc010491203c, callchain = 0x0, branch_stack = 0x0, user_regs = {abi = 0, mask = 0, regs = 0x0, cache_regs = 0x7feffffa098, cache_mask = 0}, intr_regs = {abi = 0, mask = 0, regs = 0x0, cache_regs = 0x7feffffa098, cache_mask = 0}, user_stack = { offset = 0, size = 0, data = 0x0}, read = {time_enabled = 0, time_running = 0, {group = {nr = 0, values = 0x0}, one = {value = 0, id = 0}}}} (gdb) p *field $2 = {offset = 16, {integer = 0x14f4a8 <tp_field__u64>, pointer = 0x14f4a8 <tp_field__u64>}} sample->raw_data is guaranteed to not be 8-byte aligned because it is preceded by the size as a u3. So accessing raw data with an extended load instruction causes the SIGBUS. Resolve by using memcpy to a temporary variable of appropriate size. Signed-off-by: David Ahern <david.ahern@oracle.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1424376022-140608-1-git-send-email-david.ahern@oracle.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-trace.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 5cd8497445fe..d95a8f4d988c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -52,7 +52,9 @@ struct tp_field {
52#define TP_UINT_FIELD(bits) \ 52#define TP_UINT_FIELD(bits) \
53static u64 tp_field__u##bits(struct tp_field *field, struct perf_sample *sample) \ 53static u64 tp_field__u##bits(struct tp_field *field, struct perf_sample *sample) \
54{ \ 54{ \
55 return *(u##bits *)(sample->raw_data + field->offset); \ 55 u##bits value; \
56 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
57 return value; \
56} 58}
57 59
58TP_UINT_FIELD(8); 60TP_UINT_FIELD(8);
@@ -63,7 +65,8 @@ TP_UINT_FIELD(64);
63#define TP_UINT_FIELD__SWAPPED(bits) \ 65#define TP_UINT_FIELD__SWAPPED(bits) \
64static u64 tp_field__swapped_u##bits(struct tp_field *field, struct perf_sample *sample) \ 66static u64 tp_field__swapped_u##bits(struct tp_field *field, struct perf_sample *sample) \
65{ \ 67{ \
66 u##bits value = *(u##bits *)(sample->raw_data + field->offset); \ 68 u##bits value; \
69 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
67 return bswap_##bits(value);\ 70 return bswap_##bits(value);\
68} 71}
69 72
@@ -1517,11 +1520,22 @@ static int trace__read_syscall_info(struct trace *trace, int id)
1517 return syscall__set_arg_fmts(sc); 1520 return syscall__set_arg_fmts(sc);
1518} 1521}
1519 1522
1523/*
1524 * args is to be interpreted as a series of longs but we need to handle
1525 * 8-byte unaligned accesses. args points to raw_data within the event
1526 * and raw_data is guaranteed to be 8-byte unaligned because it is
1527 * preceded by raw_size which is a u32. So we need to copy args to a temp
1528 * variable to read it. Most notably this avoids extended load instructions
1529 * on unaligned addresses
1530 */
1531
1520static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, 1532static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
1521 unsigned long *args, struct trace *trace, 1533 unsigned char *args, struct trace *trace,
1522 struct thread *thread) 1534 struct thread *thread)
1523{ 1535{
1524 size_t printed = 0; 1536 size_t printed = 0;
1537 unsigned char *p;
1538 unsigned long val;
1525 1539
1526 if (sc->tp_format != NULL) { 1540 if (sc->tp_format != NULL) {
1527 struct format_field *field; 1541 struct format_field *field;
@@ -1537,12 +1551,17 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
1537 field = field->next, ++arg.idx, bit <<= 1) { 1551 field = field->next, ++arg.idx, bit <<= 1) {
1538 if (arg.mask & bit) 1552 if (arg.mask & bit)
1539 continue; 1553 continue;
1554
1555 /* special care for unaligned accesses */
1556 p = args + sizeof(unsigned long) * arg.idx;
1557 memcpy(&val, p, sizeof(val));
1558
1540 /* 1559 /*
1541 * Suppress this argument if its value is zero and 1560 * Suppress this argument if its value is zero and
1542 * and we don't have a string associated in an 1561 * and we don't have a string associated in an
1543 * strarray for it. 1562 * strarray for it.
1544 */ 1563 */
1545 if (args[arg.idx] == 0 && 1564 if (val == 0 &&
1546 !(sc->arg_scnprintf && 1565 !(sc->arg_scnprintf &&
1547 sc->arg_scnprintf[arg.idx] == SCA_STRARRAY && 1566 sc->arg_scnprintf[arg.idx] == SCA_STRARRAY &&
1548 sc->arg_parm[arg.idx])) 1567 sc->arg_parm[arg.idx]))
@@ -1551,23 +1570,26 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
1551 printed += scnprintf(bf + printed, size - printed, 1570 printed += scnprintf(bf + printed, size - printed,
1552 "%s%s: ", printed ? ", " : "", field->name); 1571 "%s%s: ", printed ? ", " : "", field->name);
1553 if (sc->arg_scnprintf && sc->arg_scnprintf[arg.idx]) { 1572 if (sc->arg_scnprintf && sc->arg_scnprintf[arg.idx]) {
1554 arg.val = args[arg.idx]; 1573 arg.val = val;
1555 if (sc->arg_parm) 1574 if (sc->arg_parm)
1556 arg.parm = sc->arg_parm[arg.idx]; 1575 arg.parm = sc->arg_parm[arg.idx];
1557 printed += sc->arg_scnprintf[arg.idx](bf + printed, 1576 printed += sc->arg_scnprintf[arg.idx](bf + printed,
1558 size - printed, &arg); 1577 size - printed, &arg);
1559 } else { 1578 } else {
1560 printed += scnprintf(bf + printed, size - printed, 1579 printed += scnprintf(bf + printed, size - printed,
1561 "%ld", args[arg.idx]); 1580 "%ld", val);
1562 } 1581 }
1563 } 1582 }
1564 } else { 1583 } else {
1565 int i = 0; 1584 int i = 0;
1566 1585
1567 while (i < 6) { 1586 while (i < 6) {
1587 /* special care for unaligned accesses */
1588 p = args + sizeof(unsigned long) * i;
1589 memcpy(&val, p, sizeof(val));
1568 printed += scnprintf(bf + printed, size - printed, 1590 printed += scnprintf(bf + printed, size - printed,
1569 "%sarg%d: %ld", 1591 "%sarg%d: %ld",
1570 printed ? ", " : "", i, args[i]); 1592 printed ? ", " : "", i, val);
1571 ++i; 1593 ++i;
1572 } 1594 }
1573 } 1595 }