Skip to content

Commit c30a135

Browse files
committed
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
2 parents 2988dfe + 0e260fc commit c30a135

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23114,6 +23114,8 @@ static void free_states(struct bpf_verifier_env *env)
2311423114

2311523115
for (i = 0; i < env->scc_cnt; ++i) {
2311623116
info = env->scc_info[i];
23117+
if (!info)
23118+
continue;
2311723119
for (j = 0; j < info->num_visits; j++)
2311823120
free_backedges(&info->visits[j]);
2311923121
kvfree(info);
@@ -24554,6 +24556,7 @@ static int compute_scc(struct bpf_verifier_env *env)
2455424556
err = -ENOMEM;
2455524557
goto exit;
2455624558
}
24559+
env->scc_cnt = next_scc_id;
2455724560
exit:
2455824561
kvfree(stack);
2455924562
kvfree(pre);

tools/lib/bpf/libbpf.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10965,11 +10965,14 @@ struct bpf_link *bpf_program__attach_perf_event_opts(const struct bpf_program *p
1096510965
}
1096610966
link->link.fd = pfd;
1096710967
}
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;
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+
}
1097310976
}
1097410977

1097510978
return &link->link;

tools/lib/bpf/libbpf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,11 @@ struct bpf_perf_event_opts {
499499
__u64 bpf_cookie;
500500
/* don't use BPF link when attach BPF program */
501501
bool force_ioctl_attach;
502+
/* don't automatically enable the event */
503+
bool dont_enable;
502504
size_t :0;
503505
};
504-
#define bpf_perf_event_opts__last_field force_ioctl_attach
506+
#define bpf_perf_event_opts__last_field dont_enable
505507

506508
LIBBPF_API struct bpf_link *
507509
bpf_program__attach_perf_event(const struct bpf_program *prog, int pfd);

tools/perf/util/bpf-filter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
451451
struct bpf_link *link;
452452
struct perf_bpf_filter_entry *entry;
453453
bool needs_idx_hash = !target__has_cpu(target);
454+
DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts,
455+
.dont_enable = true);
454456

455457
entry = calloc(MAX_FILTERS, sizeof(*entry));
456458
if (entry == NULL)
@@ -522,7 +524,8 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
522524
prog = skel->progs.perf_sample_filter;
523525
for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
524526
for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
525-
link = bpf_program__attach_perf_event(prog, FD(evsel, x, y));
527+
link = bpf_program__attach_perf_event_opts(prog, FD(evsel, x, y),
528+
&pe_opts);
526529
if (IS_ERR(link)) {
527530
pr_err("Failed to attach perf sample-filter program\n");
528531
ret = PTR_ERR(link);

0 commit comments

Comments
 (0)