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:
"Mostly tooling fixes, but also start/stop filter related fixes, a perf
event read() fix, a fix uncovered by fuzzing, and an uprobes leak fix"

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/core: Check return value of the perf_event_read() IPI
perf/core: Enable mapping of the stop filters
perf/core: Update filters only on executable mmap
perf/core: Fix file name handling for start/stop filters
perf/core: Fix event_function_local()
uprobes: Fix the memcg accounting
perf intel-pt: Fix occasional decoding errors when tracing system-wide
tools: Sync kvm related header files for arm64 and s390
perf probe: Release resources on error when handling exit paths
perf probe: Check for dup and fdopen failures
perf symbols: Fix annotation of objects with debuginfo files
perf script: Don't disable use_callchain if input is pipe
perf script: Show proper message when failed list scripts
perf jitdump: Add the right header to get the major()/minor() definitions
perf ppc64le: Fix build failure when libelf is not present
perf tools mem: Fix -t store option for record command
perf intel-pt: Fix ip compression

+207 -69
+68 -27
kernel/events/core.c
··· 242 242 return ret; 243 243 } 244 244 245 - static void event_function_local(struct perf_event *event, event_f func, void *data) 246 - { 247 - struct event_function_struct efs = { 248 - .event = event, 249 - .func = func, 250 - .data = data, 251 - }; 252 - 253 - int ret = event_function(&efs); 254 - WARN_ON_ONCE(ret); 255 - } 256 - 257 245 static void event_function_call(struct perf_event *event, event_f func, void *data) 258 246 { 259 247 struct perf_event_context *ctx = event->ctx; ··· 289 301 } 290 302 func(event, NULL, ctx, data); 291 303 raw_spin_unlock_irq(&ctx->lock); 304 + } 305 + 306 + /* 307 + * Similar to event_function_call() + event_function(), but hard assumes IRQs 308 + * are already disabled and we're on the right CPU. 309 + */ 310 + static void event_function_local(struct perf_event *event, event_f func, void *data) 311 + { 312 + struct perf_event_context *ctx = event->ctx; 313 + struct perf_cpu_context *cpuctx = __get_cpu_context(ctx); 314 + struct task_struct *task = READ_ONCE(ctx->task); 315 + struct perf_event_context *task_ctx = NULL; 316 + 317 + WARN_ON_ONCE(!irqs_disabled()); 318 + 319 + if (task) { 320 + if (task == TASK_TOMBSTONE) 321 + return; 322 + 323 + task_ctx = ctx; 324 + } 325 + 326 + perf_ctx_lock(cpuctx, task_ctx); 327 + 328 + task = ctx->task; 329 + if (task == TASK_TOMBSTONE) 330 + goto unlock; 331 + 332 + if (task) { 333 + /* 334 + * We must be either inactive or active and the right task, 335 + * otherwise we're screwed, since we cannot IPI to somewhere 336 + * else. 337 + */ 338 + if (ctx->is_active) { 339 + if (WARN_ON_ONCE(task != current)) 340 + goto unlock; 341 + 342 + if (WARN_ON_ONCE(cpuctx->task_ctx != ctx)) 343 + goto unlock; 344 + } 345 + } else { 346 + WARN_ON_ONCE(&cpuctx->ctx != ctx); 347 + } 348 + 349 + func(event, cpuctx, ctx, data); 350 + unlock: 351 + perf_ctx_unlock(cpuctx, task_ctx); 292 352 } 293 353 294 354 #define PERF_FLAG_ALL (PERF_FLAG_FD_NO_GROUP |\ ··· 3549 3513 .group = group, 3550 3514 .ret = 0, 3551 3515 }; 3552 - smp_call_function_single(event->oncpu, 3553 - __perf_event_read, &data, 1); 3554 - ret = data.ret; 3516 + ret = smp_call_function_single(event->oncpu, __perf_event_read, &data, 1); 3517 + /* The event must have been read from an online CPU: */ 3518 + WARN_ON_ONCE(ret); 3519 + ret = ret ? : data.ret; 3555 3520 } else if (event->state == PERF_EVENT_STATE_INACTIVE) { 3556 3521 struct perf_event_context *ctx = event->ctx; 3557 3522 unsigned long flags; ··· 6621 6584 } 6622 6585 6623 6586 /* 6624 - * Whether this @filter depends on a dynamic object which is not loaded 6625 - * yet or its load addresses are not known. 6626 - */ 6627 - static bool perf_addr_filter_needs_mmap(struct perf_addr_filter *filter) 6628 - { 6629 - return filter->filter && filter->inode; 6630 - } 6631 - 6632 - /* 6633 6587 * Check whether inode and address range match filter criteria. 6634 6588 */ 6635 6589 static bool perf_addr_filter_match(struct perf_addr_filter *filter, ··· 6680 6652 { 6681 6653 struct perf_event_context *ctx; 6682 6654 int ctxn; 6655 + 6656 + /* 6657 + * Data tracing isn't supported yet and as such there is no need 6658 + * to keep track of anything that isn't related to executable code: 6659 + */ 6660 + if (!(vma->vm_flags & VM_EXEC)) 6661 + return; 6683 6662 6684 6663 rcu_read_lock(); 6685 6664 for_each_task_context_nr(ctxn) { ··· 7840 7805 list_for_each_entry(filter, &ifh->list, entry) { 7841 7806 event->addr_filters_offs[count] = 0; 7842 7807 7843 - if (perf_addr_filter_needs_mmap(filter)) 7808 + /* 7809 + * Adjust base offset if the filter is associated to a binary 7810 + * that needs to be mapped: 7811 + */ 7812 + if (filter->inode) 7844 7813 event->addr_filters_offs[count] = 7845 7814 perf_addr_filter_apply(filter, mm); 7846 7815 ··· 7975 7936 goto fail; 7976 7937 } 7977 7938 7978 - if (token == IF_SRC_FILE) { 7979 - filename = match_strdup(&args[2]); 7939 + if (token == IF_SRC_FILE || token == IF_SRC_FILEADDR) { 7940 + int fpos = filter->range ? 2 : 1; 7941 + 7942 + filename = match_strdup(&args[fpos]); 7980 7943 if (!filename) { 7981 7944 ret = -ENOMEM; 7982 7945 goto fail;
+3 -2
kernel/events/uprobes.c
··· 172 172 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end); 173 173 err = -EAGAIN; 174 174 ptep = page_check_address(page, mm, addr, &ptl, 0); 175 - if (!ptep) 175 + if (!ptep) { 176 + mem_cgroup_cancel_charge(kpage, memcg, false); 176 177 goto unlock; 178 + } 177 179 178 180 get_page(kpage); 179 181 page_add_new_anon_rmap(kpage, vma, addr, false); ··· 202 200 203 201 err = 0; 204 202 unlock: 205 - mem_cgroup_cancel_charge(kpage, memcg, false); 206 203 mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end); 207 204 unlock_page(page); 208 205 return err;
+2
tools/arch/arm64/include/uapi/asm/kvm.h
··· 87 87 /* Supported VGICv3 address types */ 88 88 #define KVM_VGIC_V3_ADDR_TYPE_DIST 2 89 89 #define KVM_VGIC_V3_ADDR_TYPE_REDIST 3 90 + #define KVM_VGIC_ITS_ADDR_TYPE 4 90 91 91 92 #define KVM_VGIC_V3_DIST_SIZE SZ_64K 92 93 #define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K) 94 + #define KVM_VGIC_V3_ITS_SIZE (2 * SZ_64K) 93 95 94 96 #define KVM_ARM_VCPU_POWER_OFF 0 /* CPU is started in OFF state */ 95 97 #define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */
+41
tools/arch/s390/include/uapi/asm/kvm.h
··· 93 93 __u64 fac_list[256]; 94 94 }; 95 95 96 + #define KVM_S390_VM_CPU_PROCESSOR_FEAT 2 97 + #define KVM_S390_VM_CPU_MACHINE_FEAT 3 98 + 99 + #define KVM_S390_VM_CPU_FEAT_NR_BITS 1024 100 + #define KVM_S390_VM_CPU_FEAT_ESOP 0 101 + #define KVM_S390_VM_CPU_FEAT_SIEF2 1 102 + #define KVM_S390_VM_CPU_FEAT_64BSCAO 2 103 + #define KVM_S390_VM_CPU_FEAT_SIIF 3 104 + #define KVM_S390_VM_CPU_FEAT_GPERE 4 105 + #define KVM_S390_VM_CPU_FEAT_GSLS 5 106 + #define KVM_S390_VM_CPU_FEAT_IB 6 107 + #define KVM_S390_VM_CPU_FEAT_CEI 7 108 + #define KVM_S390_VM_CPU_FEAT_IBS 8 109 + #define KVM_S390_VM_CPU_FEAT_SKEY 9 110 + #define KVM_S390_VM_CPU_FEAT_CMMA 10 111 + #define KVM_S390_VM_CPU_FEAT_PFMFI 11 112 + #define KVM_S390_VM_CPU_FEAT_SIGPIF 12 113 + struct kvm_s390_vm_cpu_feat { 114 + __u64 feat[16]; 115 + }; 116 + 117 + #define KVM_S390_VM_CPU_PROCESSOR_SUBFUNC 4 118 + #define KVM_S390_VM_CPU_MACHINE_SUBFUNC 5 119 + /* for "test bit" instructions MSB 0 bit ordering, for "query" raw blocks */ 120 + struct kvm_s390_vm_cpu_subfunc { 121 + __u8 plo[32]; /* always */ 122 + __u8 ptff[16]; /* with TOD-clock steering */ 123 + __u8 kmac[16]; /* with MSA */ 124 + __u8 kmc[16]; /* with MSA */ 125 + __u8 km[16]; /* with MSA */ 126 + __u8 kimd[16]; /* with MSA */ 127 + __u8 klmd[16]; /* with MSA */ 128 + __u8 pckmo[16]; /* with MSA3 */ 129 + __u8 kmctr[16]; /* with MSA4 */ 130 + __u8 kmf[16]; /* with MSA4 */ 131 + __u8 kmo[16]; /* with MSA4 */ 132 + __u8 pcc[16]; /* with MSA4 */ 133 + __u8 ppno[16]; /* with MSA5 */ 134 + __u8 reserved[1824]; 135 + }; 136 + 96 137 /* kvm attributes for crypto */ 97 138 #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0 98 139 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1
+1
tools/arch/s390/include/uapi/asm/sie.h
··· 140 140 exit_code_ipa0(0xB2, 0x4c, "TAR"), \ 141 141 exit_code_ipa0(0xB2, 0x50, "CSP"), \ 142 142 exit_code_ipa0(0xB2, 0x54, "MVPG"), \ 143 + exit_code_ipa0(0xB2, 0x56, "STHYI"), \ 143 144 exit_code_ipa0(0xB2, 0x58, "BSG"), \ 144 145 exit_code_ipa0(0xB2, 0x5a, "BSA"), \ 145 146 exit_code_ipa0(0xB2, 0x5f, "CHSC"), \
+2
tools/perf/arch/powerpc/util/sym-handling.c
··· 97 97 } 98 98 } 99 99 100 + #ifdef HAVE_LIBELF_SUPPORT 100 101 void arch__post_process_probe_trace_events(struct perf_probe_event *pev, 101 102 int ntevs) 102 103 { ··· 119 118 } 120 119 } 121 120 } 121 + #endif /* HAVE_LIBELF_SUPPORT */ 122 122 123 123 #endif
+5 -1
tools/perf/arch/x86/util/intel-pt.c
··· 501 501 struct intel_pt_recording *ptr = 502 502 container_of(itr, struct intel_pt_recording, itr); 503 503 struct perf_pmu *intel_pt_pmu = ptr->intel_pt_pmu; 504 - bool have_timing_info; 504 + bool have_timing_info, need_immediate = false; 505 505 struct perf_evsel *evsel, *intel_pt_evsel = NULL; 506 506 const struct cpu_map *cpus = evlist->cpus; 507 507 bool privileged = geteuid() == 0 || perf_event_paranoid() < 0; ··· 655 655 ptr->have_sched_switch = 3; 656 656 } else { 657 657 opts->record_switch_events = true; 658 + need_immediate = true; 658 659 if (cpu_wide) 659 660 ptr->have_sched_switch = 3; 660 661 else ··· 700 699 701 700 tracking_evsel->attr.freq = 0; 702 701 tracking_evsel->attr.sample_period = 1; 702 + 703 + if (need_immediate) 704 + tracking_evsel->immediate = true; 703 705 704 706 /* In per-cpu case, always need the time of mmap events etc */ 705 707 if (!cpu_map__empty(cpus)) {
+3
tools/perf/builtin-mem.c
··· 88 88 if (mem->operation & MEM_OPERATION_LOAD) 89 89 perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true; 90 90 91 + if (mem->operation & MEM_OPERATION_STORE) 92 + perf_mem_events[PERF_MEM_EVENTS__STORE].record = true; 93 + 91 94 if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record) 92 95 rec_argv[i++] = "-W"; 93 96
+10 -3
tools/perf/builtin-script.c
··· 371 371 372 372 if (!no_callchain) { 373 373 bool use_callchain = false; 374 + bool not_pipe = false; 374 375 375 376 evlist__for_each_entry(session->evlist, evsel) { 377 + not_pipe = true; 376 378 if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) { 377 379 use_callchain = true; 378 380 break; 379 381 } 380 382 } 381 - if (!use_callchain) 383 + if (not_pipe && !use_callchain) 382 384 symbol_conf.use_callchain = false; 383 385 } 384 386 ··· 1692 1690 snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); 1693 1691 1694 1692 scripts_dir = opendir(scripts_path); 1695 - if (!scripts_dir) 1696 - return -1; 1693 + if (!scripts_dir) { 1694 + fprintf(stdout, 1695 + "open(%s) failed.\n" 1696 + "Check \"PERF_EXEC_PATH\" env to set scripts dir.\n", 1697 + scripts_path); 1698 + exit(-1); 1699 + } 1697 1700 1698 1701 for_each_lang(scripts_path, scripts_dir, lang_dirent) { 1699 1702 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+23 -21
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
··· 123 123 bool have_calc_cyc_to_tsc; 124 124 int exec_mode; 125 125 unsigned int insn_bytes; 126 - uint64_t sign_bit; 127 - uint64_t sign_bits; 128 126 uint64_t period; 129 127 enum intel_pt_period_type period_type; 130 128 uint64_t tot_insn_cnt; ··· 188 190 decoder->walk_insn = params->walk_insn; 189 191 decoder->data = params->data; 190 192 decoder->return_compression = params->return_compression; 191 - 192 - decoder->sign_bit = (uint64_t)1 << 47; 193 - decoder->sign_bits = ~(((uint64_t)1 << 48) - 1); 194 193 195 194 decoder->period = params->period; 196 195 decoder->period_type = params->period_type; ··· 357 362 return 0; 358 363 } 359 364 360 - static uint64_t intel_pt_calc_ip(struct intel_pt_decoder *decoder, 361 - const struct intel_pt_pkt *packet, 365 + static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet, 362 366 uint64_t last_ip) 363 367 { 364 368 uint64_t ip; 365 369 366 370 switch (packet->count) { 367 - case 2: 371 + case 1: 368 372 ip = (last_ip & (uint64_t)0xffffffffffff0000ULL) | 369 373 packet->payload; 370 374 break; 371 - case 4: 375 + case 2: 372 376 ip = (last_ip & (uint64_t)0xffffffff00000000ULL) | 377 + packet->payload; 378 + break; 379 + case 3: 380 + ip = packet->payload; 381 + /* Sign-extend 6-byte ip */ 382 + if (ip & (uint64_t)0x800000000000ULL) 383 + ip |= (uint64_t)0xffff000000000000ULL; 384 + break; 385 + case 4: 386 + ip = (last_ip & (uint64_t)0xffff000000000000ULL) | 373 387 packet->payload; 374 388 break; 375 389 case 6: ··· 388 384 return 0; 389 385 } 390 386 391 - if (ip & decoder->sign_bit) 392 - return ip | decoder->sign_bits; 393 - 394 387 return ip; 395 388 } 396 389 397 390 static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder) 398 391 { 399 - decoder->last_ip = intel_pt_calc_ip(decoder, &decoder->packet, 400 - decoder->last_ip); 392 + decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip); 401 393 } 402 394 403 395 static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder) ··· 1657 1657 } 1658 1658 } 1659 1659 1660 + static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder) 1661 + { 1662 + return decoder->last_ip || decoder->packet.count == 0 || 1663 + decoder->packet.count == 3 || decoder->packet.count == 6; 1664 + } 1665 + 1660 1666 /* Walk PSB+ packets to get in sync. */ 1661 1667 static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) 1662 1668 { ··· 1683 1677 1684 1678 case INTEL_PT_FUP: 1685 1679 decoder->pge = true; 1686 - if (decoder->last_ip || decoder->packet.count == 6 || 1687 - decoder->packet.count == 0) { 1680 + if (intel_pt_have_ip(decoder)) { 1688 1681 uint64_t current_ip = decoder->ip; 1689 1682 1690 1683 intel_pt_set_ip(decoder); ··· 1772 1767 case INTEL_PT_TIP_PGE: 1773 1768 case INTEL_PT_TIP: 1774 1769 decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD; 1775 - if (decoder->last_ip || decoder->packet.count == 6 || 1776 - decoder->packet.count == 0) 1770 + if (intel_pt_have_ip(decoder)) 1777 1771 intel_pt_set_ip(decoder); 1778 1772 if (decoder->ip) 1779 1773 return 0; ··· 1780 1776 1781 1777 case INTEL_PT_FUP: 1782 1778 if (decoder->overflow) { 1783 - if (decoder->last_ip || 1784 - decoder->packet.count == 6 || 1785 - decoder->packet.count == 0) 1779 + if (intel_pt_have_ip(decoder)) 1786 1780 intel_pt_set_ip(decoder); 1787 1781 if (decoder->ip) 1788 1782 return 0;
+17 -7
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
··· 292 292 const unsigned char *buf, size_t len, 293 293 struct intel_pt_pkt *packet) 294 294 { 295 - switch (byte >> 5) { 295 + int ip_len; 296 + 297 + packet->count = byte >> 5; 298 + 299 + switch (packet->count) { 296 300 case 0: 297 - packet->count = 0; 301 + ip_len = 0; 298 302 break; 299 303 case 1: 300 304 if (len < 3) 301 305 return INTEL_PT_NEED_MORE_BYTES; 302 - packet->count = 2; 306 + ip_len = 2; 303 307 packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); 304 308 break; 305 309 case 2: 306 310 if (len < 5) 307 311 return INTEL_PT_NEED_MORE_BYTES; 308 - packet->count = 4; 312 + ip_len = 4; 309 313 packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); 310 314 break; 311 315 case 3: 312 - case 6: 316 + case 4: 313 317 if (len < 7) 314 318 return INTEL_PT_NEED_MORE_BYTES; 315 - packet->count = 6; 319 + ip_len = 6; 316 320 memcpy_le64(&packet->payload, buf + 1, 6); 321 + break; 322 + case 6: 323 + if (len < 9) 324 + return INTEL_PT_NEED_MORE_BYTES; 325 + ip_len = 8; 326 + packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1)); 317 327 break; 318 328 default: 319 329 return INTEL_PT_BAD_PACKET; ··· 331 321 332 322 packet->type = type; 333 323 334 - return packet->count + 1; 324 + return ip_len + 1; 335 325 } 336 326 337 327 static int intel_pt_get_mode(const unsigned char *buf, size_t len,
+1
tools/perf/util/jitdump.c
··· 1 + #include <sys/sysmacros.h> 1 2 #include <sys/types.h> 2 3 #include <stdio.h> 3 4 #include <stdlib.h>
+29 -7
tools/perf/util/probe-file.c
··· 133 133 /* Get raw string list of current kprobe_events or uprobe_events */ 134 134 struct strlist *probe_file__get_rawlist(int fd) 135 135 { 136 - int ret, idx; 136 + int ret, idx, fddup; 137 137 FILE *fp; 138 138 char buf[MAX_CMDLEN]; 139 139 char *p; ··· 143 143 return NULL; 144 144 145 145 sl = strlist__new(NULL, NULL); 146 + if (sl == NULL) 147 + return NULL; 146 148 147 - fp = fdopen(dup(fd), "r"); 149 + fddup = dup(fd); 150 + if (fddup < 0) 151 + goto out_free_sl; 152 + 153 + fp = fdopen(fddup, "r"); 154 + if (!fp) 155 + goto out_close_fddup; 156 + 148 157 while (!feof(fp)) { 149 158 p = fgets(buf, MAX_CMDLEN, fp); 150 159 if (!p) ··· 165 156 ret = strlist__add(sl, buf); 166 157 if (ret < 0) { 167 158 pr_debug("strlist__add failed (%d)\n", ret); 168 - strlist__delete(sl); 169 - return NULL; 159 + goto out_close_fp; 170 160 } 171 161 } 172 162 fclose(fp); 173 163 174 164 return sl; 165 + 166 + out_close_fp: 167 + fclose(fp); 168 + goto out_free_sl; 169 + out_close_fddup: 170 + close(fddup); 171 + out_free_sl: 172 + strlist__delete(sl); 173 + return NULL; 175 174 } 176 175 177 176 static struct strlist *__probe_file__get_namelist(int fd, bool include_group) ··· 464 447 { 465 448 struct probe_cache_entry *entry = NULL; 466 449 char buf[MAX_CMDLEN], *p; 467 - int ret = 0; 450 + int ret = 0, fddup; 468 451 FILE *fp; 469 452 470 - fp = fdopen(dup(pcache->fd), "r"); 471 - if (!fp) 453 + fddup = dup(pcache->fd); 454 + if (fddup < 0) 455 + return -errno; 456 + fp = fdopen(fddup, "r"); 457 + if (!fp) { 458 + close(fddup); 472 459 return -EINVAL; 460 + } 473 461 474 462 while (!feof(fp)) { 475 463 if (!fgets(buf, MAX_CMDLEN, fp))
+2 -1
tools/perf/util/symbol-elf.c
··· 837 837 sec = syms_ss->symtab; 838 838 shdr = syms_ss->symshdr; 839 839 840 - if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL)) 840 + if (elf_section_by_name(runtime_ss->elf, &runtime_ss->ehdr, &tshdr, 841 + ".text", NULL)) 841 842 dso->text_offset = tshdr.sh_addr - tshdr.sh_offset; 842 843 843 844 if (runtime_ss->opdsec)