Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf fixes from Ingo Molnar:
"Misc kernel side fixes:

- fix event leak
- fix AMD PMU driver bug
- fix core event handling bug
- fix build bug on certain randconfigs

Plus misc tooling fixes"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/x86/amd/ibs: Fix pmu::stop() nesting
perf/core: Don't leak event in the syscall error path
perf/core: Fix time tracking bug with multiplexing
perf jit: genelf makes assumptions about endian
perf hists: Fix determination of a callchain node's childlessness
perf tools: Add missing initialization of perf_sample.cpumode in synthesized samples
perf tools: Fix build break on powerpc
perf/x86: Move events_sysfs_show() outside CPU_SUP_INTEL
perf bench: Fix detached tarball building due to missing 'perf bench memcpy' headers
perf tests: Fix tarpkg build test error output redirection

+98 -35
+45 -7
arch/x86/events/amd/ibs.c
··· 28 28 #define IBS_FETCH_CONFIG_MASK (IBS_FETCH_RAND_EN | IBS_FETCH_MAX_CNT) 29 29 #define IBS_OP_CONFIG_MASK IBS_OP_MAX_CNT 30 30 31 + 32 + /* 33 + * IBS states: 34 + * 35 + * ENABLED; tracks the pmu::add(), pmu::del() state, when set the counter is taken 36 + * and any further add()s must fail. 37 + * 38 + * STARTED/STOPPING/STOPPED; deal with pmu::start(), pmu::stop() state but are 39 + * complicated by the fact that the IBS hardware can send late NMIs (ie. after 40 + * we've cleared the EN bit). 41 + * 42 + * In order to consume these late NMIs we have the STOPPED state, any NMI that 43 + * happens after we've cleared the EN state will clear this bit and report the 44 + * NMI handled (this is fundamentally racy in the face or multiple NMI sources, 45 + * someone else can consume our BIT and our NMI will go unhandled). 46 + * 47 + * And since we cannot set/clear this separate bit together with the EN bit, 48 + * there are races; if we cleared STARTED early, an NMI could land in 49 + * between clearing STARTED and clearing the EN bit (in fact multiple NMIs 50 + * could happen if the period is small enough), and consume our STOPPED bit 51 + * and trigger streams of unhandled NMIs. 52 + * 53 + * If, however, we clear STARTED late, an NMI can hit between clearing the 54 + * EN bit and clearing STARTED, still see STARTED set and process the event. 55 + * If this event will have the VALID bit clear, we bail properly, but this 56 + * is not a given. With VALID set we can end up calling pmu::stop() again 57 + * (the throttle logic) and trigger the WARNs in there. 58 + * 59 + * So what we do is set STOPPING before clearing EN to avoid the pmu::stop() 60 + * nesting, and clear STARTED late, so that we have a well defined state over 61 + * the clearing of the EN bit. 62 + * 63 + * XXX: we could probably be using !atomic bitops for all this. 64 + */ 65 + 31 66 enum ibs_states { 32 67 IBS_ENABLED = 0, 33 68 IBS_STARTED = 1, 34 69 IBS_STOPPING = 2, 70 + IBS_STOPPED = 3, 35 71 36 72 IBS_MAX_STATES, 37 73 }; ··· 413 377 414 378 perf_ibs_set_period(perf_ibs, hwc, &period); 415 379 /* 416 - * Set STARTED before enabling the hardware, such that 417 - * a subsequent NMI must observe it. Then clear STOPPING 418 - * such that we don't consume NMIs by accident. 380 + * Set STARTED before enabling the hardware, such that a subsequent NMI 381 + * must observe it. 419 382 */ 420 - set_bit(IBS_STARTED, pcpu->state); 383 + set_bit(IBS_STARTED, pcpu->state); 421 384 clear_bit(IBS_STOPPING, pcpu->state); 422 385 perf_ibs_enable_event(perf_ibs, hwc, period >> 4); 423 386 ··· 431 396 u64 config; 432 397 int stopping; 433 398 399 + if (test_and_set_bit(IBS_STOPPING, pcpu->state)) 400 + return; 401 + 434 402 stopping = test_bit(IBS_STARTED, pcpu->state); 435 403 436 404 if (!stopping && (hwc->state & PERF_HES_UPTODATE)) ··· 443 405 444 406 if (stopping) { 445 407 /* 446 - * Set STOPPING before disabling the hardware, such that it 408 + * Set STOPPED before disabling the hardware, such that it 447 409 * must be visible to NMIs the moment we clear the EN bit, 448 410 * at which point we can generate an !VALID sample which 449 411 * we need to consume. 450 412 */ 451 - set_bit(IBS_STOPPING, pcpu->state); 413 + set_bit(IBS_STOPPED, pcpu->state); 452 414 perf_ibs_disable_event(perf_ibs, hwc, config); 453 415 /* 454 416 * Clear STARTED after disabling the hardware; if it were ··· 594 556 * with samples that even have the valid bit cleared. 595 557 * Mark all this NMIs as handled. 596 558 */ 597 - if (test_and_clear_bit(IBS_STOPPING, pcpu->state)) 559 + if (test_and_clear_bit(IBS_STOPPED, pcpu->state)) 598 560 return 1; 599 561 600 562 return 0;
+3 -3
arch/x86/events/perf_event.h
··· 800 800 801 801 struct attribute **merge_attr(struct attribute **a, struct attribute **b); 802 802 803 + ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, 804 + char *page); 805 + 803 806 #ifdef CONFIG_CPU_SUP_AMD 804 807 805 808 int amd_pmu_init(void); ··· 932 929 int p6_pmu_init(void); 933 930 934 931 int knc_pmu_init(void); 935 - 936 - ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, 937 - char *page); 938 932 939 933 static inline int is_ht_workaround_enabled(void) 940 934 {
+13 -2
kernel/events/core.c
··· 2417 2417 cpuctx->task_ctx = NULL; 2418 2418 } 2419 2419 2420 - is_active ^= ctx->is_active; /* changed bits */ 2421 - 2420 + /* 2421 + * Always update time if it was set; not only when it changes. 2422 + * Otherwise we can 'forget' to update time for any but the last 2423 + * context we sched out. For example: 2424 + * 2425 + * ctx_sched_out(.event_type = EVENT_FLEXIBLE) 2426 + * ctx_sched_out(.event_type = EVENT_PINNED) 2427 + * 2428 + * would only update time for the pinned events. 2429 + */ 2422 2430 if (is_active & EVENT_TIME) { 2423 2431 /* update (and stop) ctx time */ 2424 2432 update_context_time(ctx); 2425 2433 update_cgrp_time_from_cpuctx(cpuctx); 2426 2434 } 2435 + 2436 + is_active ^= ctx->is_active; /* changed bits */ 2427 2437 2428 2438 if (!ctx->nr_active || !(is_active & EVENT_ALL)) 2429 2439 return; ··· 8542 8532 f_flags); 8543 8533 if (IS_ERR(event_file)) { 8544 8534 err = PTR_ERR(event_file); 8535 + event_file = NULL; 8545 8536 goto err_context; 8546 8537 } 8547 8538
+1
tools/perf/MANIFEST
··· 74 74 arch/*/include/uapi/asm/perf_regs.h 75 75 arch/*/lib/memcpy*.S 76 76 arch/*/lib/memset*.S 77 + arch/*/include/asm/*features.h 77 78 include/linux/poison.h 78 79 include/linux/hw_breakpoint.h 79 80 include/uapi/linux/perf_event.h
+2
tools/perf/arch/powerpc/util/header.c
··· 4 4 #include <stdlib.h> 5 5 #include <string.h> 6 6 #include <linux/stringify.h> 7 + #include "header.h" 8 + #include "util.h" 7 9 8 10 #define mfspr(rn) ({unsigned long rval; \ 9 11 asm volatile("mfspr %0," __stringify(rn) \
+1 -1
tools/perf/tests/perf-targz-src-pkg
··· 15 15 tar xf ${TARBALL} -C $TMP_DEST 16 16 rm -f ${TARBALL} 17 17 cd - > /dev/null 18 - make -C $TMP_DEST/perf*/tools/perf > /dev/null 2>&1 18 + make -C $TMP_DEST/perf*/tools/perf > /dev/null 19 19 RC=$? 20 20 rm -rf ${TMP_DEST} 21 21 exit $RC
+1 -1
tools/perf/ui/browsers/hists.c
··· 337 337 chain = list_entry(node->val.next, struct callchain_list, list); 338 338 chain->has_children = has_sibling; 339 339 340 - if (node->val.next != node->val.prev) { 340 + if (!list_empty(&node->val)) { 341 341 chain = list_entry(node->val.prev, struct callchain_list, list); 342 342 chain->has_children = !RB_EMPTY_ROOT(&node->rb_root); 343 343 }
+16 -7
tools/perf/util/event.c
··· 56 56 return perf_event__names[id]; 57 57 } 58 58 59 - static struct perf_sample synth_sample = { 59 + static int perf_tool__process_synth_event(struct perf_tool *tool, 60 + union perf_event *event, 61 + struct machine *machine, 62 + perf_event__handler_t process) 63 + { 64 + struct perf_sample synth_sample = { 60 65 .pid = -1, 61 66 .tid = -1, 62 67 .time = -1, 63 68 .stream_id = -1, 64 69 .cpu = -1, 65 70 .period = 1, 71 + .cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK, 72 + }; 73 + 74 + return process(tool, event, &synth_sample, machine); 66 75 }; 67 76 68 77 /* ··· 195 186 if (perf_event__prepare_comm(event, pid, machine, &tgid, &ppid) != 0) 196 187 return -1; 197 188 198 - if (process(tool, event, &synth_sample, machine) != 0) 189 + if (perf_tool__process_synth_event(tool, event, machine, process) != 0) 199 190 return -1; 200 191 201 192 return tgid; ··· 227 218 228 219 event->fork.header.size = (sizeof(event->fork) + machine->id_hdr_size); 229 220 230 - if (process(tool, event, &synth_sample, machine) != 0) 221 + if (perf_tool__process_synth_event(tool, event, machine, process) != 0) 231 222 return -1; 232 223 233 224 return 0; ··· 353 344 event->mmap2.pid = tgid; 354 345 event->mmap2.tid = pid; 355 346 356 - if (process(tool, event, &synth_sample, machine) != 0) { 347 + if (perf_tool__process_synth_event(tool, event, machine, process) != 0) { 357 348 rc = -1; 358 349 break; 359 350 } ··· 411 402 412 403 memcpy(event->mmap.filename, pos->dso->long_name, 413 404 pos->dso->long_name_len + 1); 414 - if (process(tool, event, &synth_sample, machine) != 0) { 405 + if (perf_tool__process_synth_event(tool, event, machine, process) != 0) { 415 406 rc = -1; 416 407 break; 417 408 } ··· 481 472 /* 482 473 * Send the prepared comm event 483 474 */ 484 - if (process(tool, comm_event, &synth_sample, machine) != 0) 475 + if (perf_tool__process_synth_event(tool, comm_event, machine, process) != 0) 485 476 break; 486 477 487 478 rc = 0; ··· 710 701 event->mmap.len = map->end - event->mmap.start; 711 702 event->mmap.pid = machine->pid; 712 703 713 - err = process(tool, event, &synth_sample, machine); 704 + err = perf_tool__process_synth_event(tool, event, machine, process); 714 705 free(event); 715 706 716 707 return err;
+10 -14
tools/perf/util/genelf.h
··· 9 9 10 10 #if defined(__arm__) 11 11 #define GEN_ELF_ARCH EM_ARM 12 - #define GEN_ELF_ENDIAN ELFDATA2LSB 13 12 #define GEN_ELF_CLASS ELFCLASS32 14 13 #elif defined(__aarch64__) 15 14 #define GEN_ELF_ARCH EM_AARCH64 16 - #define GEN_ELF_ENDIAN ELFDATA2LSB 17 15 #define GEN_ELF_CLASS ELFCLASS64 18 16 #elif defined(__x86_64__) 19 17 #define GEN_ELF_ARCH EM_X86_64 20 - #define GEN_ELF_ENDIAN ELFDATA2LSB 21 18 #define GEN_ELF_CLASS ELFCLASS64 22 19 #elif defined(__i386__) 23 20 #define GEN_ELF_ARCH EM_386 24 - #define GEN_ELF_ENDIAN ELFDATA2LSB 25 21 #define GEN_ELF_CLASS ELFCLASS32 26 - #elif defined(__ppcle__) 27 - #define GEN_ELF_ARCH EM_PPC 28 - #define GEN_ELF_ENDIAN ELFDATA2LSB 22 + #elif defined(__powerpc64__) 23 + #define GEN_ELF_ARCH EM_PPC64 29 24 #define GEN_ELF_CLASS ELFCLASS64 30 25 #elif defined(__powerpc__) 31 - #define GEN_ELF_ARCH EM_PPC64 32 - #define GEN_ELF_ENDIAN ELFDATA2MSB 33 - #define GEN_ELF_CLASS ELFCLASS64 34 - #elif defined(__powerpcle__) 35 - #define GEN_ELF_ARCH EM_PPC64 36 - #define GEN_ELF_ENDIAN ELFDATA2LSB 37 - #define GEN_ELF_CLASS ELFCLASS64 26 + #define GEN_ELF_ARCH EM_PPC 27 + #define GEN_ELF_CLASS ELFCLASS32 38 28 #else 39 29 #error "unsupported architecture" 30 + #endif 31 + 32 + #if __BYTE_ORDER == __BIG_ENDIAN 33 + #define GEN_ELF_ENDIAN ELFDATA2MSB 34 + #else 35 + #define GEN_ELF_ENDIAN ELFDATA2LSB 40 36 #endif 41 37 42 38 #if GEN_ELF_CLASS == ELFCLASS64
+1
tools/perf/util/intel-bts.c
··· 279 279 event.sample.header.misc = PERF_RECORD_MISC_USER; 280 280 event.sample.header.size = sizeof(struct perf_event_header); 281 281 282 + sample.cpumode = PERF_RECORD_MISC_USER; 282 283 sample.ip = le64_to_cpu(branch->from); 283 284 sample.pid = btsq->pid; 284 285 sample.tid = btsq->tid;
+3
tools/perf/util/intel-pt.c
··· 979 979 if (!pt->timeless_decoding) 980 980 sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc); 981 981 982 + sample.cpumode = PERF_RECORD_MISC_USER; 982 983 sample.ip = ptq->state->from_ip; 983 984 sample.pid = ptq->pid; 984 985 sample.tid = ptq->tid; ··· 1036 1035 if (!pt->timeless_decoding) 1037 1036 sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc); 1038 1037 1038 + sample.cpumode = PERF_RECORD_MISC_USER; 1039 1039 sample.ip = ptq->state->from_ip; 1040 1040 sample.pid = ptq->pid; 1041 1041 sample.tid = ptq->tid; ··· 1094 1092 if (!pt->timeless_decoding) 1095 1093 sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc); 1096 1094 1095 + sample.cpumode = PERF_RECORD_MISC_USER; 1097 1096 sample.ip = ptq->state->from_ip; 1098 1097 sample.pid = ptq->pid; 1099 1098 sample.tid = ptq->tid;
+2
tools/perf/util/jitdump.c
··· 417 417 * use first address as sample address 418 418 */ 419 419 memset(&sample, 0, sizeof(sample)); 420 + sample.cpumode = PERF_RECORD_MISC_USER; 420 421 sample.pid = pid; 421 422 sample.tid = tid; 422 423 sample.time = id->time; ··· 506 505 * use first address as sample address 507 506 */ 508 507 memset(&sample, 0, sizeof(sample)); 508 + sample.cpumode = PERF_RECORD_MISC_USER; 509 509 sample.pid = pid; 510 510 sample.tid = tid; 511 511 sample.time = id->time;