Pull perf fixes from Ingo Molnar: "This is mostly tooling fixes, plus an instruction pointer filtering fix. It's more fixes than usual - Arnaldo got back from a longer vacation and there was a backlog" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (27 commits) perf symbols: Kill dso__build_id_is_kmod() perf symbols: Keep DSO->symtab_type after decompress perf tests: Decompress kernel module before objdump perf tools: Consolidate error path in __open_dso() perf tools: Decompress kernel module when reading DSO data perf annotate: Use dso__decompress_kmodule_path() perf tools: Introduce dso__decompress_kmodule_{fd,path} perf tools: Fix a memory leak in __open_dso() perf annotate: Fix symbolic link of build-id cache perf/core: Drop kernel samples even though :u is specified perf script python: Remove dups in documentation examples perf script python: Updated trace_unhandled() signature perf script python: Fix wrong code snippets in documentation perf script: Fix documentation errors perf script: Fix outdated comment for perf-trace-python perf probe: Fix examples section of documentation perf report: Ensure the perf DSO mapping matches what libdw sees perf report: Include partial stacks unwound with libdw perf annotate: Add missing powerpc triplet perf test: Disable breakpoint signal tests for powerpc ...
Unified · Split
| @@ -7316,6 +7316,21 @@ int perf_event_account_interrupt(struct perf_event *event) · 7315 unmodified lines | ||
| 7316 | 7316 | return __perf_event_account_interrupt(event, 1); |
| 7317 | 7317 | } |
| 7318 | 7318 | |
| 7319 | +static bool sample_is_allowed(struct perf_event *event, struct pt_regs *regs) | |
| 7320 | +{ | |
| 7321 | + /* | |
| 7322 | + * Due to interrupt latency (AKA "skid"), we may enter the | |
| 7323 | + * kernel before taking an overflow, even if the PMU is only | |
| 7324 | + * counting user events. | |
| 7325 | + * To avoid leaking information to userspace, we must always | |
| 7326 | + * reject kernel samples when exclude_kernel is set. | |
| 7327 | + */ | |
| 7328 | + if (event->attr.exclude_kernel && !user_mode(regs)) | |
| 7329 | + return false; | |
| 7330 | + | |
| 7331 | + return true; | |
| 7332 | +} | |
| 7333 | + | |
| 7319 | 7334 | /* |
| 7320 | 7335 | * Generic event overflow handling, sampling. |
| 7321 | 7336 | */ |
| @@ -7336,6 +7351,12 @@ static int __perf_event_overflow(struct perf_event *event, · 14 unmodified lines | ||
| 7336 | 7351 | |
| 7337 | 7352 | ret = __perf_event_account_interrupt(event, throttle); |
| 7338 | 7353 | |
| 7354 | + /* | |
| 7355 | + * For security, drop the skid kernel samples if necessary. | |
| 7356 | + */ | |
| 7357 | + if (!sample_is_allowed(event, regs)) | |
| 7358 | + return ret; | |
| 7359 | + | |
| 7339 | 7360 | /* |
| 7340 | 7361 | * XXX event_limit might not quite work as expected on inherited |
| 7341 | 7362 | * events |
| @@ -240,9 +240,13 @@ Add a probe on schedule() function 12th line with recording cpu local variable: · 239 unmodified lines | ||
| 240 | 240 | or |
| 241 | 241 | ./perf probe --add='schedule:12 cpu' |
| 242 | 242 | |
| 243 | − this will add one or more probes which has the name start with "schedule". | |
| 243 | +Add one or more probes which has the name start with "schedule". | |
| 244 | 244 | |
| 245 | − Add probes on lines in schedule() function which calls update_rq_clock(). | |
| 245 | + ./perf probe schedule* | |
| 246 | + or | |
| 247 | + ./perf probe --add='schedule*' | |
| 248 | + | |
| 249 | +Add probes on lines in schedule() function which calls update_rq_clock(). | |
| 246 | 250 | |
| 247 | 251 | ./perf probe 'schedule;update_rq_clock*' |
| 248 | 252 | or |
| @@ -39,7 +39,7 @@ EVENT HANDLERS · 38 unmodified lines | ||
| 39 | 39 | When perf script is invoked using a trace script, a user-defined |
| 40 | 40 | 'handler function' is called for each event in the trace. If there's |
| 41 | 41 | no handler function defined for a given event type, the event is |
| 42 | −ignored (or passed to a 'trace_handled' function, see below) and the | |
| 42 | +ignored (or passed to a 'trace_unhandled' function, see below) and the | |
| 43 | 43 | next event is processed. |
| 44 | 44 | |
| 45 | 45 | Most of the event's field values are passed as arguments to the |
| @@ -149,10 +149,8 @@ def raw_syscalls__sys_enter(event_name, context, common_cpu, · 148 unmodified lines | ||
| 149 | 149 | print "id=%d, args=%s\n" % \ |
| 150 | 150 | (id, args), |
| 151 | 151 | |
| 152 | −def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs, | |
| 153 | − common_pid, common_comm): | |
| 154 | − print_header(event_name, common_cpu, common_secs, common_nsecs, | |
| 155 | − common_pid, common_comm) | |
| 152 | +def trace_unhandled(event_name, context, event_fields_dict): | |
| 153 | + print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) | |
| 156 | 154 | |
| 157 | 155 | def print_header(event_name, cpu, secs, nsecs, pid, comm): |
| 158 | 156 | print "%-20s %5u %05u.%09u %8u %-20s " % \ |
| @@ -321,7 +319,7 @@ So those are the essential steps in writing and running a script. The · 162 unmodified lines | ||
| 321 | 319 | process can be generalized to any tracepoint or set of tracepoints |
| 322 | 320 | you're interested in - basically find the tracepoint(s) you're |
| 323 | 321 | interested in by looking at the list of available events shown by |
| 324 | −'perf list' and/or look in /sys/kernel/debug/tracing events for | |
| 322 | +'perf list' and/or look in /sys/kernel/debug/tracing/events/ for | |
| 325 | 323 | detailed event and field info, record the corresponding trace data |
| 326 | 324 | using 'perf record', passing it the list of interesting events, |
| 327 | 325 | generate a skeleton script using 'perf script -g python' and modify the |
| @@ -334,7 +332,7 @@ right place, you can have your script listed alongside the other · 6 unmodified lines | ||
| 334 | 332 | scripts listed by the 'perf script -l' command e.g.: |
| 335 | 333 | |
| 336 | 334 | ---- |
| 337 | −root@tropicana:~# perf script -l | |
| 335 | +# perf script -l | |
| 338 | 336 | List of available trace scripts: |
| 339 | 337 | wakeup-latency system-wide min/max/avg wakeup latency |
| 340 | 338 | rw-by-file <comm> r/w activity for a program, by file |
| @@ -383,8 +381,6 @@ source tree: · 42 unmodified lines | ||
| 383 | 381 | |
| 384 | 382 | ---- |
| 385 | 383 | # ls -al kernel-source/tools/perf/scripts/python |
| 386 | − | |
| 387 | −root@tropicana:/home/trz/src/tip# ls -al tools/perf/scripts/python | |
| 388 | 384 | total 32 |
| 389 | 385 | drwxr-xr-x 4 trz trz 4096 2010-01-26 22:30 . |
| 390 | 386 | drwxr-xr-x 4 trz trz 4096 2010-01-26 22:29 .. |
| @@ -399,7 +395,7 @@ otherwise your script won't show up at run-time), 'perf script -l' · 8 unmodified lines | ||
| 399 | 395 | should show a new entry for your script: |
| 400 | 396 | |
| 401 | 397 | ---- |
| 402 | −root@tropicana:~# perf script -l | |
| 398 | +# perf script -l | |
| 403 | 399 | List of available trace scripts: |
| 404 | 400 | wakeup-latency system-wide min/max/avg wakeup latency |
| 405 | 401 | rw-by-file <comm> r/w activity for a program, by file |
| @@ -437,7 +433,7 @@ EVENT HANDLERS · 31 unmodified lines | ||
| 437 | 433 | When perf script is invoked using a trace script, a user-defined |
| 438 | 434 | 'handler function' is called for each event in the trace. If there's |
| 439 | 435 | no handler function defined for a given event type, the event is |
| 440 | −ignored (or passed to a 'trace_handled' function, see below) and the | |
| 436 | +ignored (or passed to a 'trace_unhandled' function, see below) and the | |
| 441 | 437 | next event is processed. |
| 442 | 438 | |
| 443 | 439 | Most of the event's field values are passed as arguments to the |
| @@ -532,7 +528,7 @@ can implement a set of optional functions: · 88 unmodified lines | ||
| 532 | 528 | gives scripts a chance to do setup tasks: |
| 533 | 529 | |
| 534 | 530 | ---- |
| 535 | −def trace_begin: | |
| 531 | +def trace_begin(): | |
| 536 | 532 | pass |
| 537 | 533 | ---- |
| 538 | 534 | |
| @@ -541,7 +537,7 @@ def trace_begin: · 2 unmodified lines | ||
| 541 | 537 | as display results: |
| 542 | 538 | |
| 543 | 539 | ---- |
| 544 | −def trace_end: | |
| 540 | +def trace_end(): | |
| 545 | 541 | pass |
| 546 | 542 | ---- |
| 547 | 543 | |
| @@ -550,8 +546,7 @@ def trace_end: · 2 unmodified lines | ||
| 550 | 546 | of common arguments are passed into it: |
| 551 | 547 | |
| 552 | 548 | ---- |
| 553 | −def trace_unhandled(event_name, context, common_cpu, common_secs, | |
| 554 | − common_nsecs, common_pid, common_comm): | |
| 549 | +def trace_unhandled(event_name, context, event_fields_dict): | |
| 555 | 550 | pass |
| 556 | 551 | ---- |
| 557 | 552 | |
| @@ -26,6 +26,7 @@ const char *const arm64_triplets[] = { · 25 unmodified lines | ||
| 26 | 26 | |
| 27 | 27 | const char *const powerpc_triplets[] = { |
| 28 | 28 | "powerpc-unknown-linux-gnu-", |
| 29 | + "powerpc-linux-gnu-", | |
| 29 | 30 | "powerpc64-unknown-linux-gnu-", |
| 30 | 31 | "powerpc64-linux-gnu-", |
| 31 | 32 | "powerpc64le-linux-gnu-", |
| @@ -1578,6 +1578,7 @@ static void print_header(int argc, const char **argv) · 1577 unmodified lines | ||
| 1578 | 1578 | static void print_footer(void) |
| 1579 | 1579 | { |
| 1580 | 1580 | FILE *output = stat_config.output; |
| 1581 | + int n; | |
| 1581 | 1582 | |
| 1582 | 1583 | if (!null_run) |
| 1583 | 1584 | fprintf(output, "\n"); |
| @@ -1590,7 +1591,9 @@ static void print_footer(void) · 6 unmodified lines | ||
| 1590 | 1591 | } |
| 1591 | 1592 | fprintf(output, "\n\n"); |
| 1592 | 1593 | |
| 1593 | − if (print_free_counters_hint) | |
| 1594 | + if (print_free_counters_hint && | |
| 1595 | + sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 && | |
| 1596 | + n > 0) | |
| 1594 | 1597 | fprintf(output, |
| 1595 | 1598 | "Some events weren't counted. Try disabling the NMI watchdog:\n" |
| 1596 | 1599 | " echo 0 > /proc/sys/kernel/nmi_watchdog\n" |
| @@ -681,6 +681,10 @@ static struct syscall_fmt { · 680 unmodified lines | ||
| 681 | 681 | { .name = "mlockall", .errmsg = true, |
| 682 | 682 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
| 683 | 683 | { .name = "mmap", .hexret = true, |
| 684 | +/* The standard mmap maps to old_mmap on s390x */ | |
| 685 | +#if defined(__s390x__) | |
| 686 | + .alias = "old_mmap", | |
| 687 | +#endif | |
| 684 | 688 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
| 685 | 689 | [2] = SCA_MMAP_PROT, /* prot */ |
| 686 | 690 | [3] = SCA_MMAP_FLAGS, /* flags */ }, }, |
| @@ -288,3 +288,17 @@ int test__bp_signal(int subtest __maybe_unused) · 287 unmodified lines | ||
| 288 | 288 | return count1 == 1 && overflows == 3 && count2 == 3 && overflows_2 == 3 && count3 == 2 ? |
| 289 | 289 | TEST_OK : TEST_FAIL; |
| 290 | 290 | } |
| 291 | + | |
| 292 | +bool test__bp_signal_is_supported(void) | |
| 293 | +{ | |
| 294 | +/* | |
| 295 | + * The powerpc so far does not have support to even create | |
| 296 | + * instruction breakpoint using the perf event interface. | |
| 297 | + * Once it's there we can release this. | |
| 298 | + */ | |
| 299 | +#ifdef __powerpc__ | |
| 300 | + return false; | |
| 301 | +#else | |
| 302 | + return true; | |
| 303 | +#endif | |
| 304 | +} | |
| @@ -97,10 +97,12 @@ static struct test generic_tests[] = { · 96 unmodified lines | ||
| 97 | 97 | { |
| 98 | 98 | .desc = "Breakpoint overflow signal handler", |
| 99 | 99 | .func = test__bp_signal, |
| 100 | + .is_supported = test__bp_signal_is_supported, | |
| 100 | 101 | }, |
| 101 | 102 | { |
| 102 | 103 | .desc = "Breakpoint overflow sampling", |
| 103 | 104 | .func = test__bp_signal_overflow, |
| 105 | + .is_supported = test__bp_signal_is_supported, | |
| 104 | 106 | }, |
| 105 | 107 | { |
| 106 | 108 | .desc = "Number of exit events of a simple workload", |
| @@ -401,6 +403,11 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) · 294 unmodified lines | ||
| 401 | 403 | if (!perf_test__matches(t, curr, argc, argv)) |
| 402 | 404 | continue; |
| 403 | 405 | |
| 406 | + if (t->is_supported && !t->is_supported()) { | |
| 407 | + pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc); | |
| 408 | + continue; | |
| 409 | + } | |
| 410 | + | |
| 404 | 411 | pr_info("%2d: %-*s:", i, width, t->desc); |
| 405 | 412 | |
| 406 | 413 | if (intlist__find(skiplist, i)) { |
| @@ -229,6 +229,8 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 228 unmodified lines | ||
| 229 | 229 | unsigned char buf2[BUFSZ]; |
| 230 | 230 | size_t ret_len; |
| 231 | 231 | u64 objdump_addr; |
| 232 | + const char *objdump_name; | |
| 233 | + char decomp_name[KMOD_DECOMP_LEN]; | |
| 232 | 234 | int ret; |
| 233 | 235 | |
| 234 | 236 | pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr); |
| @@ -289,9 +291,25 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 54 unmodified lines | ||
| 289 | 291 | state->done[state->done_cnt++] = al.map->start; |
| 290 | 292 | } |
| 291 | 293 | |
| 294 | + objdump_name = al.map->dso->long_name; | |
| 295 | + if (dso__needs_decompress(al.map->dso)) { | |
| 296 | + if (dso__decompress_kmodule_path(al.map->dso, objdump_name, | |
| 297 | + decomp_name, | |
| 298 | + sizeof(decomp_name)) < 0) { | |
| 299 | + pr_debug("decompression failed\n"); | |
| 300 | + return -1; | |
| 301 | + } | |
| 302 | + | |
| 303 | + objdump_name = decomp_name; | |
| 304 | + } | |
| 305 | + | |
| 292 | 306 | /* Read the object code using objdump */ |
| 293 | 307 | objdump_addr = map__rip_2objdump(al.map, al.addr); |
| 294 | − ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len); | |
| 308 | + ret = read_via_objdump(objdump_name, objdump_addr, buf2, len); | |
| 309 | + | |
| 310 | + if (dso__needs_decompress(al.map->dso)) | |
| 311 | + unlink(objdump_name); | |
| 312 | + | |
| 295 | 313 | if (ret > 0) { |
| 296 | 314 | /* |
| 297 | 315 | * The kernel maps are inaccurate - assume objdump is right in |
| @@ -34,6 +34,7 @@ struct test { · 33 unmodified lines | ||
| 34 | 34 | int (*get_nr)(void); |
| 35 | 35 | const char *(*get_desc)(int subtest); |
| 36 | 36 | } subtest; |
| 37 | + bool (*is_supported)(void); | |
| 37 | 38 | }; |
| 38 | 39 | |
| 39 | 40 | /* Tests */ |
| @@ -99,6 +100,8 @@ const char *test__clang_subtest_get_desc(int subtest); · 59 unmodified lines | ||
| 99 | 100 | int test__clang_subtest_get_nr(void); |
| 100 | 101 | int test__unit_number__scnprint(int subtest); |
| 101 | 102 | |
| 103 | +bool test__bp_signal_is_supported(void); | |
| 104 | + | |
| 102 | 105 | #if defined(__arm__) || defined(__aarch64__) |
| 103 | 106 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
| 104 | 107 | struct thread; |
| @@ -239,10 +239,20 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 238 unmodified lines | ||
| 239 | 239 | const char *s = strchr(ops->raw, '+'); |
| 240 | 240 | const char *c = strchr(ops->raw, ','); |
| 241 | 241 | |
| 242 | − if (c++ != NULL) | |
| 242 | + /* | |
| 243 | + * skip over possible up to 2 operands to get to address, e.g.: | |
| 244 | + * tbnz w0, #26, ffff0000083cd190 <security_file_permission+0xd0> | |
| 245 | + */ | |
| 246 | + if (c++ != NULL) { | |
| 243 | 247 | ops->target.addr = strtoull(c, NULL, 16); |
| 244 | − else | |
| 248 | + if (!ops->target.addr) { | |
| 249 | + c = strchr(c, ','); | |
| 250 | + if (c++ != NULL) | |
| 251 | + ops->target.addr = strtoull(c, NULL, 16); | |
| 252 | + } | |
| 253 | + } else { | |
| 245 | 254 | ops->target.addr = strtoull(ops->raw, NULL, 16); |
| 255 | + } | |
| 246 | 256 | |
| 247 | 257 | if (s++ != NULL) { |
| 248 | 258 | ops->target.offset = strtoull(s, NULL, 16); |
| @@ -257,10 +267,27 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 8 unmodified lines | ||
| 257 | 267 | static int jump__scnprintf(struct ins *ins, char *bf, size_t size, |
| 258 | 268 | struct ins_operands *ops) |
| 259 | 269 | { |
| 270 | + const char *c = strchr(ops->raw, ','); | |
| 271 | + | |
| 260 | 272 | if (!ops->target.addr || ops->target.offset < 0) |
| 261 | 273 | return ins__raw_scnprintf(ins, bf, size, ops); |
| 262 | 274 | |
| 263 | − return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset); | |
| 275 | + if (c != NULL) { | |
| 276 | + const char *c2 = strchr(c + 1, ','); | |
| 277 | + | |
| 278 | + /* check for 3-op insn */ | |
| 279 | + if (c2 != NULL) | |
| 280 | + c = c2; | |
| 281 | + c++; | |
| 282 | + | |
| 283 | + /* mirror arch objdump's space-after-comma style */ | |
| 284 | + if (*c == ' ') | |
| 285 | + c++; | |
| 286 | + } | |
| 287 | + | |
| 288 | + return scnprintf(bf, size, "%-6.6s %.*s%" PRIx64, | |
| 289 | + ins->name, c ? c - ops->raw : 0, ops->raw, | |
| 290 | + ops->target.offset); | |
| 264 | 291 | } |
| 265 | 292 | |
| 266 | 293 | static struct ins_ops jump_ops = { |
| @@ -1294,6 +1321,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 1027 unmodified lines | ||
| 1294 | 1321 | char linkname[PATH_MAX]; |
| 1295 | 1322 | char *build_id_filename; |
| 1296 | 1323 | char *build_id_path = NULL; |
| 1324 | + char *pos; | |
| 1297 | 1325 | |
| 1298 | 1326 | if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && |
| 1299 | 1327 | !dso__is_kcore(dso)) |
| @@ -1313,7 +1341,14 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 13 unmodified lines | ||
| 1313 | 1341 | if (!build_id_path) |
| 1314 | 1342 | return -1; |
| 1315 | 1343 | |
| 1316 | − dirname(build_id_path); | |
| 1344 | + /* | |
| 1345 | + * old style build-id cache has name of XX/XXXXXXX.. while | |
| 1346 | + * new style has XX/XXXXXXX../{elf,kallsyms,vdso}. | |
| 1347 | + * extract the build-id part of dirname in the new style only. | |
| 1348 | + */ | |
| 1349 | + pos = strrchr(build_id_path, '/'); | |
| 1350 | + if (pos && strlen(pos) < SBUILD_ID_SIZE - 2) | |
| 1351 | + dirname(build_id_path); | |
| 1317 | 1352 | |
| 1318 | 1353 | if (dso__is_kcore(dso) || |
| 1319 | 1354 | readlink(build_id_path, linkname, sizeof(linkname)) < 0 || |
| @@ -1396,31 +1431,10 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na · 76 unmodified lines | ||
| 1396 | 1431 | sizeof(symfs_filename)); |
| 1397 | 1432 | } |
| 1398 | 1433 | } else if (dso__needs_decompress(dso)) { |
| 1399 | − char tmp[PATH_MAX]; | |
| 1400 | − struct kmod_path m; | |
| 1401 | − int fd; | |
| 1402 | − bool ret; | |
| 1403 | − | |
| 1404 | − if (kmod_path__parse_ext(&m, symfs_filename)) | |
| 1405 | − goto out; | |
| 1406 | − | |
| 1407 | − snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX"); | |
| 1408 | − | |
| 1409 | − fd = mkstemp(tmp); | |
| 1410 | − if (fd < 0) { | |
| 1411 | − free(m.ext); | |
| 1412 | − goto out; | |
| 1413 | − } | |
| 1414 | − | |
| 1415 | − ret = decompress_to_file(m.ext, symfs_filename, fd); | |
| 1416 | − | |
| 1417 | − if (ret) | |
| 1418 | − pr_err("Cannot decompress %s %s\n", m.ext, symfs_filename); | |
| 1419 | − | |
| 1420 | − free(m.ext); | |
| 1421 | − close(fd); | |
| 1434 | + char tmp[KMOD_DECOMP_LEN]; | |
| 1422 | 1435 | |
| 1423 | − if (!ret) | |
| 1436 | + if (dso__decompress_kmodule_path(dso, symfs_filename, | |
| 1437 | + tmp, sizeof(tmp)) < 0) | |
| 1424 | 1438 | goto out; |
| 1425 | 1439 | |
| 1426 | 1440 | strcpy(symfs_filename, tmp); |
| @@ -1429,7 +1443,7 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na · 2 unmodified lines | ||
| 1429 | 1443 | snprintf(command, sizeof(command), |
| 1430 | 1444 | "%s %s%s --start-address=0x%016" PRIx64 |
| 1431 | 1445 | " --stop-address=0x%016" PRIx64 |
| 1432 | − " -l -d %s %s -C %s 2>/dev/null|grep -v %s:|expand", | |
| 1446 | + " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand", | |
| 1433 | 1447 | objdump_path ? objdump_path : "objdump", |
| 1434 | 1448 | disassembler_style ? "-M " : "", |
| 1435 | 1449 | disassembler_style ? disassembler_style : "", |
| @@ -278,51 +278,6 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size) · 277 unmodified lines | ||
| 278 | 278 | return bf; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | −bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size) | |
| 282 | −{ | |
| 283 | − char *id_name = NULL, *ch; | |
| 284 | − struct stat sb; | |
| 285 | − char sbuild_id[SBUILD_ID_SIZE]; | |
| 286 | − | |
| 287 | − if (!dso->has_build_id) | |
| 288 | − goto err; | |
| 289 | − | |
| 290 | − build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); | |
| 291 | − id_name = build_id_cache__linkname(sbuild_id, NULL, 0); | |
| 292 | − if (!id_name) | |
| 293 | − goto err; | |
| 294 | − if (access(id_name, F_OK)) | |
| 295 | − goto err; | |
| 296 | − if (lstat(id_name, &sb) == -1) | |
| 297 | − goto err; | |
| 298 | − if ((size_t)sb.st_size > size - 1) | |
| 299 | − goto err; | |
| 300 | − if (readlink(id_name, bf, size - 1) < 0) | |
| 301 | − goto err; | |
| 302 | − | |
| 303 | − bf[sb.st_size] = '\0'; | |
| 304 | − | |
| 305 | − /* | |
| 306 | − * link should be: | |
| 307 | − * ../../lib/modules/4.4.0-rc4/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko/a09fe3eb3147dafa4e3b31dbd6257e4d696bdc92 | |
| 308 | − */ | |
| 309 | − ch = strrchr(bf, '/'); | |
| 310 | − if (!ch) | |
| 311 | − goto err; | |
| 312 | − if (ch - 3 < bf) | |
| 313 | − goto err; | |
| 314 | − | |
| 315 | − free(id_name); | |
| 316 | − return strncmp(".ko", ch - 3, 3) == 0; | |
| 317 | −err: | |
| 318 | − pr_err("Invalid build id: %s\n", id_name ? : | |
| 319 | − dso->long_name ? : | |
| 320 | − dso->short_name ? : | |
| 321 | − "[unknown]"); | |
| 322 | − free(id_name); | |
| 323 | − return false; | |
| 324 | −} | |
| 325 | − | |
| 326 | 281 | #define dsos__for_each_with_build_id(pos, head) \ |
| 327 | 282 | list_for_each_entry(pos, head, node) \ |
| 328 | 283 | if (!pos->has_build_id) \ |
| @@ -17,7 +17,6 @@ char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf, · 16 unmodified lines | ||
| 17 | 17 | size_t size); |
| 18 | 18 | |
| 19 | 19 | char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size); |
| 20 | −bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size); | |
| 21 | 20 | |
| 22 | 21 | int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, |
| 23 | 22 | struct perf_sample *sample, struct perf_evsel *evsel, |
| @@ -248,6 +248,64 @@ bool dso__needs_decompress(struct dso *dso) · 247 unmodified lines | ||
| 248 | 248 | dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | +static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf) | |
| 252 | +{ | |
| 253 | + int fd = -1; | |
| 254 | + struct kmod_path m; | |
| 255 | + | |
| 256 | + if (!dso__needs_decompress(dso)) | |
| 257 | + return -1; | |
| 258 | + | |
| 259 | + if (kmod_path__parse_ext(&m, dso->long_name)) | |
| 260 | + return -1; | |
| 261 | + | |
| 262 | + if (!m.comp) | |
| 263 | + goto out; | |
| 264 | + | |
| 265 | + fd = mkstemp(tmpbuf); | |
| 266 | + if (fd < 0) { | |
| 267 | + dso->load_errno = errno; | |
| 268 | + goto out; | |
| 269 | + } | |
| 270 | + | |
| 271 | + if (!decompress_to_file(m.ext, name, fd)) { | |
| 272 | + dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE; | |
| 273 | + close(fd); | |
| 274 | + fd = -1; | |
| 275 | + } | |
| 276 | + | |
| 277 | +out: | |
| 278 | + free(m.ext); | |
| 279 | + return fd; | |
| 280 | +} | |
| 281 | + | |
| 282 | +int dso__decompress_kmodule_fd(struct dso *dso, const char *name) | |
| 283 | +{ | |
| 284 | + char tmpbuf[] = KMOD_DECOMP_NAME; | |
| 285 | + int fd; | |
| 286 | + | |
| 287 | + fd = decompress_kmodule(dso, name, tmpbuf); | |
| 288 | + unlink(tmpbuf); | |
| 289 | + return fd; | |
| 290 | +} | |
| 291 | + | |
| 292 | +int dso__decompress_kmodule_path(struct dso *dso, const char *name, | |
| 293 | + char *pathname, size_t len) | |
| 294 | +{ | |
| 295 | + char tmpbuf[] = KMOD_DECOMP_NAME; | |
| 296 | + int fd; | |
| 297 | + | |
| 298 | + fd = decompress_kmodule(dso, name, tmpbuf); | |
| 299 | + if (fd < 0) { | |
| 300 | + unlink(tmpbuf); | |
| 301 | + return -1; | |
| 302 | + } | |
| 303 | + | |
| 304 | + strncpy(pathname, tmpbuf, len); | |
| 305 | + close(fd); | |
| 306 | + return 0; | |
| 307 | +} | |
| 308 | + | |
| 251 | 309 | /* |
| 252 | 310 | * Parses kernel module specified in @path and updates |
| 253 | 311 | * @m argument like: |
| @@ -335,6 +393,21 @@ int __kmod_path__parse(struct kmod_path *m, const char *path, · 81 unmodified lines | ||
| 335 | 393 | return 0; |
| 336 | 394 | } |
| 337 | 395 | |
| 396 | +void dso__set_module_info(struct dso *dso, struct kmod_path *m, | |
| 397 | + struct machine *machine) | |
| 398 | +{ | |
| 399 | + if (machine__is_host(machine)) | |
| 400 | + dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE; | |
| 401 | + else | |
| 402 | + dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE; | |
| 403 | + | |
| 404 | + /* _KMODULE_COMP should be next to _KMODULE */ | |
| 405 | + if (m->kmod && m->comp) | |
| 406 | + dso->symtab_type++; | |
| 407 | + | |
| 408 | + dso__set_short_name(dso, strdup(m->name), true); | |
| 409 | +} | |
| 410 | + | |
| 338 | 411 | /* |
| 339 | 412 | * Global list of open DSOs and the counter. |
| 340 | 413 | */ |
| @@ -381,7 +454,7 @@ static int do_open(char *name) · 40 unmodified lines | ||
| 381 | 454 | |
| 382 | 455 | static int __open_dso(struct dso *dso, struct machine *machine) |
| 383 | 456 | { |
| 384 | − int fd; | |
| 457 | + int fd = -EINVAL; | |
| 385 | 458 | char *root_dir = (char *)""; |
| 386 | 459 | char *name = malloc(PATH_MAX); |
| 387 | 460 | |
| @@ -392,15 +465,30 @@ static int __open_dso(struct dso *dso, struct machine *machine) · 4 unmodified lines | ||
| 392 | 465 | root_dir = machine->root_dir; |
| 393 | 466 | |
| 394 | 467 | if (dso__read_binary_type_filename(dso, dso->binary_type, |
| 395 | − root_dir, name, PATH_MAX)) { | |
| 396 | − free(name); | |
| 397 | − return -EINVAL; | |
| 398 | − } | |
| 468 | + root_dir, name, PATH_MAX)) | |
| 469 | + goto out; | |
| 399 | 470 | |
| 400 | 471 | if (!is_regular_file(name)) |
| 401 | − return -EINVAL; | |
| 472 | + goto out; | |
| 473 | + | |
| 474 | + if (dso__needs_decompress(dso)) { | |
| 475 | + char newpath[KMOD_DECOMP_LEN]; | |
| 476 | + size_t len = sizeof(newpath); | |
| 477 | + | |
| 478 | + if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) { | |
| 479 | + fd = -dso->load_errno; | |
| 480 | + goto out; | |
| 481 | + } | |
| 482 | + | |
| 483 | + strcpy(name, newpath); | |
| 484 | + } | |
| 402 | 485 | |
| 403 | 486 | fd = do_open(name); |
| 487 | + | |
| 488 | + if (dso__needs_decompress(dso)) | |
| 489 | + unlink(name); | |
| 490 | + | |
| 491 | +out: | |
| 404 | 492 | free(name); |
| 405 | 493 | return fd; |
| 406 | 494 | } |
| @@ -244,6 +244,12 @@ bool is_supported_compression(const char *ext); · 243 unmodified lines | ||
| 244 | 244 | bool is_kernel_module(const char *pathname, int cpumode); |
| 245 | 245 | bool decompress_to_file(const char *ext, const char *filename, int output_fd); |
| 246 | 246 | bool dso__needs_decompress(struct dso *dso); |
| 247 | +int dso__decompress_kmodule_fd(struct dso *dso, const char *name); | |
| 248 | +int dso__decompress_kmodule_path(struct dso *dso, const char *name, | |
| 249 | + char *pathname, size_t len); | |
| 250 | + | |
| 251 | +#define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX" | |
| 252 | +#define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME) | |
| 247 | 253 | |
| 248 | 254 | struct kmod_path { |
| 249 | 255 | char *name; |
| @@ -259,6 +265,9 @@ int __kmod_path__parse(struct kmod_path *m, const char *path, · 9 unmodified lines | ||
| 259 | 265 | #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true , false) |
| 260 | 266 | #define kmod_path__parse_ext(__m, __p) __kmod_path__parse(__m, __p, false, true) |
| 261 | 267 | |
| 268 | +void dso__set_module_info(struct dso *dso, struct kmod_path *m, | |
| 269 | + struct machine *machine); | |
| 270 | + | |
| 262 | 271 | /* |
| 263 | 272 | * The dso__data_* external interface provides following functions: |
| 264 | 273 | * dso__data_get_fd |
| @@ -1469,8 +1469,16 @@ static int __event_process_build_id(struct build_id_event *bev, · 1468 unmodified lines | ||
| 1469 | 1469 | |
| 1470 | 1470 | dso__set_build_id(dso, &bev->build_id); |
| 1471 | 1471 | |
| 1472 | − if (!is_kernel_module(filename, cpumode)) | |
| 1473 | − dso->kernel = dso_type; | |
| 1472 | + if (dso_type != DSO_TYPE_USER) { | |
| 1473 | + struct kmod_path m = { .name = NULL, }; | |
| 1474 | + | |
| 1475 | + if (!kmod_path__parse_name(&m, filename) && m.kmod) | |
| 1476 | + dso__set_module_info(dso, &m, machine); | |
| 1477 | + else | |
| 1478 | + dso->kernel = dso_type; | |
| 1479 | + | |
| 1480 | + free(m.name); | |
| 1481 | + } | |
| 1474 | 1482 | |
| 1475 | 1483 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), |
| 1476 | 1484 | sbuild_id); |
| @@ -572,16 +572,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine, · 571 unmodified lines | ||
| 572 | 572 | if (dso == NULL) |
| 573 | 573 | goto out_unlock; |
| 574 | 574 | |
| 575 | − if (machine__is_host(machine)) | |
| 576 | − dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE; | |
| 577 | − else | |
| 578 | − dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE; | |
| 579 | − | |
| 580 | − /* _KMODULE_COMP should be next to _KMODULE */ | |
| 581 | − if (m->kmod && m->comp) | |
| 582 | − dso->symtab_type++; | |
| 583 | − | |
| 584 | − dso__set_short_name(dso, strdup(m->name), true); | |
| 575 | + dso__set_module_info(dso, m, machine); | |
| 585 | 576 | dso__set_long_name(dso, strdup(filename), true); |
| 586 | 577 | } |
| 587 | 578 | |
| @@ -1219,7 +1219,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) · 1218 unmodified lines | ||
| 1219 | 1219 | fprintf(ofp, "# be retrieved using Python functions of the form " |
| 1220 | 1220 | "common_*(context).\n"); |
| 1221 | 1221 | |
| 1222 | − fprintf(ofp, "# See the perf-trace-python Documentation for the list " | |
| 1222 | + fprintf(ofp, "# See the perf-script-python Documentation for the list " | |
| 1223 | 1223 | "of available functions.\n\n"); |
| 1224 | 1224 | |
| 1225 | 1225 | fprintf(ofp, "import os\n"); |
| @@ -637,43 +637,6 @@ static int dso__swap_init(struct dso *dso, unsigned char eidata) · 636 unmodified lines | ||
| 637 | 637 | return 0; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | −static int decompress_kmodule(struct dso *dso, const char *name, | |
| 641 | − enum dso_binary_type type) | |
| 642 | −{ | |
| 643 | − int fd = -1; | |
| 644 | − char tmpbuf[] = "/tmp/perf-kmod-XXXXXX"; | |
| 645 | − struct kmod_path m; | |
| 646 | − | |
| 647 | − if (type != DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP && | |
| 648 | − type != DSO_BINARY_TYPE__GUEST_KMODULE_COMP && | |
| 649 | − type != DSO_BINARY_TYPE__BUILD_ID_CACHE) | |
| 650 | − return -1; | |
| 651 | − | |
| 652 | − if (type == DSO_BINARY_TYPE__BUILD_ID_CACHE) | |
| 653 | − name = dso->long_name; | |
| 654 | − | |
| 655 | − if (kmod_path__parse_ext(&m, name) || !m.comp) | |
| 656 | − return -1; | |
| 657 | − | |
| 658 | − fd = mkstemp(tmpbuf); | |
| 659 | − if (fd < 0) { | |
| 660 | − dso->load_errno = errno; | |
| 661 | − goto out; | |
| 662 | − } | |
| 663 | − | |
| 664 | − if (!decompress_to_file(m.ext, name, fd)) { | |
| 665 | − dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE; | |
| 666 | − close(fd); | |
| 667 | − fd = -1; | |
| 668 | − } | |
| 669 | − | |
| 670 | − unlink(tmpbuf); | |
| 671 | − | |
| 672 | −out: | |
| 673 | − free(m.ext); | |
| 674 | − return fd; | |
| 675 | −} | |
| 676 | − | |
| 677 | 640 | bool symsrc__possibly_runtime(struct symsrc *ss) |
| 678 | 641 | { |
| 679 | 642 | return ss->dynsym || ss->opdsec; |
| @@ -705,9 +668,11 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, · 25 unmodified lines | ||
| 705 | 668 | int fd; |
| 706 | 669 | |
| 707 | 670 | if (dso__needs_decompress(dso)) { |
| 708 | − fd = decompress_kmodule(dso, name, type); | |
| 671 | + fd = dso__decompress_kmodule_fd(dso, name); | |
| 709 | 672 | if (fd < 0) |
| 710 | 673 | return -1; |
| 674 | + | |
| 675 | + type = dso->symtab_type; | |
| 711 | 676 | } else { |
| 712 | 677 | fd = open(name, O_RDONLY); |
| 713 | 678 | if (fd < 0) { |
| @@ -1562,10 +1562,6 @@ int dso__load(struct dso *dso, struct map *map) · 1561 unmodified lines | ||
| 1562 | 1562 | if (!runtime_ss && syms_ss) |
| 1563 | 1563 | runtime_ss = syms_ss; |
| 1564 | 1564 | |
| 1565 | − if (syms_ss && syms_ss->type == DSO_BINARY_TYPE__BUILD_ID_CACHE) | |
| 1566 | − if (dso__build_id_is_kmod(dso, name, PATH_MAX)) | |
| 1567 | − kmod = true; | |
| 1568 | − | |
| 1569 | 1565 | if (syms_ss) |
| 1570 | 1566 | ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod); |
| 1571 | 1567 | else |
| @@ -39,6 +39,14 @@ static int __report_module(struct addr_location *al, u64 ip, · 38 unmodified lines | ||
| 39 | 39 | return 0; |
| 40 | 40 | |
| 41 | 41 | mod = dwfl_addrmodule(ui->dwfl, ip); |
| 42 | + if (mod) { | |
| 43 | + Dwarf_Addr s; | |
| 44 | + | |
| 45 | + dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL); | |
| 46 | + if (s != al->map->start) | |
| 47 | + mod = 0; | |
| 48 | + } | |
| 49 | + | |
| 42 | 50 | if (!mod) |
| 43 | 51 | mod = dwfl_report_elf(ui->dwfl, dso->short_name, |
| 44 | 52 | dso->long_name, -1, al->map->start, |
| @@ -224,7 +232,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, · 179 unmodified lines | ||
| 224 | 232 | |
| 225 | 233 | err = dwfl_getthread_frames(ui->dwfl, thread->tid, frame_callback, ui); |
| 226 | 234 | |
| 227 | − if (err && !ui->max_stack) | |
| 235 | + if (err && ui->max_stack != max_stack) | |
| 228 | 236 | err = 0; |
| 229 | 237 | |
| 230 | 238 | /* |