Merge tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Pull bpf fixes from Alexei Starovoitov:

- Fix memory leak of bpf_scc_info objects (Eduard Zingerman)

- Fix a regression in the 'perf' tool caused by moving UID filtering to
BPF (Ilya Leoshkevich)

* tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf:
perf bpf-filter: Enable events manually
libbpf: Add the ability to suppress perf event enablement
bpf: Fix memory leak of bpf_scc_info objects

+18 -7
+3
kernel/bpf/verifier.c
··· 23114 23115 for (i = 0; i < env->scc_cnt; ++i) { 23116 info = env->scc_info[i]; 23117 for (j = 0; j < info->num_visits; j++) 23118 free_backedges(&info->visits[j]); 23119 kvfree(info); ··· 24556 err = -ENOMEM; 24557 goto exit; 24558 } 24559 exit: 24560 kvfree(stack); 24561 kvfree(pre);
··· 23114 23115 for (i = 0; i < env->scc_cnt; ++i) { 23116 info = env->scc_info[i]; 23117 + if (!info) 23118 + continue; 23119 for (j = 0; j < info->num_visits; j++) 23120 free_backedges(&info->visits[j]); 23121 kvfree(info); ··· 24554 err = -ENOMEM; 24555 goto exit; 24556 } 24557 + env->scc_cnt = next_scc_id; 24558 exit: 24559 kvfree(stack); 24560 kvfree(pre);
+8 -5
tools/lib/bpf/libbpf.c
··· 10965 } 10966 link->link.fd = pfd; 10967 } 10968 - if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { 10969 - err = -errno; 10970 - pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", 10971 - prog->name, pfd, errstr(err)); 10972 - goto err_out; 10973 } 10974 10975 return &link->link;
··· 10965 } 10966 link->link.fd = pfd; 10967 } 10968 + 10969 + if (!OPTS_GET(opts, dont_enable, false)) { 10970 + if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { 10971 + err = -errno; 10972 + pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", 10973 + prog->name, pfd, errstr(err)); 10974 + goto err_out; 10975 + } 10976 } 10977 10978 return &link->link;
+3 -1
tools/lib/bpf/libbpf.h
··· 499 __u64 bpf_cookie; 500 /* don't use BPF link when attach BPF program */ 501 bool force_ioctl_attach; 502 size_t :0; 503 }; 504 - #define bpf_perf_event_opts__last_field force_ioctl_attach 505 506 LIBBPF_API struct bpf_link * 507 bpf_program__attach_perf_event(const struct bpf_program *prog, int pfd);
··· 499 __u64 bpf_cookie; 500 /* don't use BPF link when attach BPF program */ 501 bool force_ioctl_attach; 502 + /* don't automatically enable the event */ 503 + bool dont_enable; 504 size_t :0; 505 }; 506 + #define bpf_perf_event_opts__last_field dont_enable 507 508 LIBBPF_API struct bpf_link * 509 bpf_program__attach_perf_event(const struct bpf_program *prog, int pfd);
+4 -1
tools/perf/util/bpf-filter.c
··· 451 struct bpf_link *link; 452 struct perf_bpf_filter_entry *entry; 453 bool needs_idx_hash = !target__has_cpu(target); 454 455 entry = calloc(MAX_FILTERS, sizeof(*entry)); 456 if (entry == NULL) ··· 524 prog = skel->progs.perf_sample_filter; 525 for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) { 526 for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) { 527 - link = bpf_program__attach_perf_event(prog, FD(evsel, x, y)); 528 if (IS_ERR(link)) { 529 pr_err("Failed to attach perf sample-filter program\n"); 530 ret = PTR_ERR(link);
··· 451 struct bpf_link *link; 452 struct perf_bpf_filter_entry *entry; 453 bool needs_idx_hash = !target__has_cpu(target); 454 + DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts, 455 + .dont_enable = true); 456 457 entry = calloc(MAX_FILTERS, sizeof(*entry)); 458 if (entry == NULL) ··· 522 prog = skel->progs.perf_sample_filter; 523 for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) { 524 for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) { 525 + link = bpf_program__attach_perf_event_opts(prog, FD(evsel, x, y), 526 + &pe_opts); 527 if (IS_ERR(link)) { 528 pr_err("Failed to attach perf sample-filter program\n"); 529 ret = PTR_ERR(link);