diff options
author | Jan Stancek <jstancek@redhat.com> | 2017-02-17 06:10:25 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-17 10:37:04 -0500 |
commit | 43db2843a4a41cc8cdb6ab696639aeee1f4d5062 (patch) | |
tree | e6b24505f0a6c455fa2e6026e77b2f7d3f84864c | |
parent | 92a7e1278005b6bb3459affc50b2b6e2464e7e7c (diff) |
perf header: Make build_cpu_topology skip offline/absent CPUs
When build_cpu_topo() encounters offline/absent CPUs, it fails to find any
sysfs entries and returns failure.
This leads to build_cpu_topology() and write_cpu_topology() failing as
well.
Because HEADER_CPU_TOPOLOGY has not been written, read leaves cpu_topology_map
NULL and we get NULL ptr deref at:
...
cmd_test
__cmd_test
test_and_print
run_test
test_session_topology
check_cpu_topology
36: Session topology :
--- start ---
test child forked, pid 14902
templ file: /tmp/perf-test-4CKocW
failed to write feature HEADER_CPU_TOPOLOGY
perf: Segmentation fault
Obtained 9 stack frames.
./perf(sighandler_dump_stack+0x41) [0x5095f1]
/lib64/libc.so.6(+0x35250) [0x7f4b7c3c9250]
./perf(test_session_topology+0x1db) [0x490ceb]
./perf() [0x475b68]
./perf(cmd_test+0x5b9) [0x4763c9]
./perf() [0x4945a3]
./perf(main+0x69f) [0x427e8f]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f4b7c3b5b35]
./perf() [0x427fb9]
test child interrupted
---- end ----
Session topology: FAILED!
This patch makes build_cpu_topology() skip offline/absent CPUs, by checking
their presence against cpu_map built from online CPUs.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/a271b770175524f4961d4903af33798358a4a518.1487146877.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/header.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 3d12c16e5103..1222f6c5e7b3 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -505,24 +505,31 @@ static void free_cpu_topo(struct cpu_topo *tp) | |||
505 | 505 | ||
506 | static struct cpu_topo *build_cpu_topology(void) | 506 | static struct cpu_topo *build_cpu_topology(void) |
507 | { | 507 | { |
508 | struct cpu_topo *tp; | 508 | struct cpu_topo *tp = NULL; |
509 | void *addr; | 509 | void *addr; |
510 | u32 nr, i; | 510 | u32 nr, i; |
511 | size_t sz; | 511 | size_t sz; |
512 | long ncpus; | 512 | long ncpus; |
513 | int ret = -1; | 513 | int ret = -1; |
514 | struct cpu_map *map; | ||
514 | 515 | ||
515 | ncpus = sysconf(_SC_NPROCESSORS_CONF); | 516 | ncpus = sysconf(_SC_NPROCESSORS_CONF); |
516 | if (ncpus < 0) | 517 | if (ncpus < 0) |
517 | return NULL; | 518 | return NULL; |
518 | 519 | ||
520 | /* build online CPU map */ | ||
521 | map = cpu_map__new(NULL); | ||
522 | if (map == NULL) { | ||
523 | pr_debug("failed to get system cpumap\n"); | ||
524 | return NULL; | ||
525 | } | ||
526 | |||
519 | nr = (u32)(ncpus & UINT_MAX); | 527 | nr = (u32)(ncpus & UINT_MAX); |
520 | 528 | ||
521 | sz = nr * sizeof(char *); | 529 | sz = nr * sizeof(char *); |
522 | |||
523 | addr = calloc(1, sizeof(*tp) + 2 * sz); | 530 | addr = calloc(1, sizeof(*tp) + 2 * sz); |
524 | if (!addr) | 531 | if (!addr) |
525 | return NULL; | 532 | goto out_free; |
526 | 533 | ||
527 | tp = addr; | 534 | tp = addr; |
528 | tp->cpu_nr = nr; | 535 | tp->cpu_nr = nr; |
@@ -532,10 +539,16 @@ static struct cpu_topo *build_cpu_topology(void) | |||
532 | tp->thread_siblings = addr; | 539 | tp->thread_siblings = addr; |
533 | 540 | ||
534 | for (i = 0; i < nr; i++) { | 541 | for (i = 0; i < nr; i++) { |
542 | if (!cpu_map__has(map, i)) | ||
543 | continue; | ||
544 | |||
535 | ret = build_cpu_topo(tp, i); | 545 | ret = build_cpu_topo(tp, i); |
536 | if (ret < 0) | 546 | if (ret < 0) |
537 | break; | 547 | break; |
538 | } | 548 | } |
549 | |||
550 | out_free: | ||
551 | cpu_map__put(map); | ||
539 | if (ret) { | 552 | if (ret) { |
540 | free_cpu_topo(tp); | 553 | free_cpu_topo(tp); |
541 | tp = NULL; | 554 | tp = NULL; |