Skip to content

Commit 0e260fc

Browse files
author
Alexei Starovoitov
committed
Merge branch 'perf-s390-regression-move-uid-filtering-to-bpf-filters'
Ilya Leoshkevich says: ==================== perf/s390: Regression: Move uid filtering to BPF filters v4: https://lore.kernel.org/bpf/[email protected]/ v4 -> v5: Fix a typo in the commit message (Yonghong). v3: https://lore.kernel.org/bpf/[email protected]/ v3 -> v4: Rename the new field to dont_enable (Alexei, Eduard). Switch the Fixes: tag in patch 2 (Alexander, Thomas). Fix typos in the cover letter (Thomas). v2: https://lore.kernel.org/bpf/[email protected]/ v2 -> v3: Use no_ioctl_enable in perf. v1: https://lore.kernel.org/bpf/[email protected]/ v1 -> v2: Introduce no_ioctl_enable (Jiri). Hi, This series fixes a regression caused by moving UID filtering to BPF. The regression affects all events that support auxiliary data, most notably, "cycles" events on s390, but also PT events on Intel. The symptom is missing events when UID filtering is enabled. Patch 1 introduces a new option for the bpf_program__attach_perf_event_opts() function. Patch 2 makes use of it in perf, and also contains a lot of technical details of why exactly the problem is occurring. Thanks to Thomas Richter for the investigation and the initial version of this fix, and to Jiri Olsa for suggestions. Best regards, Ilya ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 1b30d44 + 5e2ac8e commit 0e260fc

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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)