Skip to content

Commit

Permalink
Ensure all perf_event_open() calls use the PERF_FLAG_FD_CLOEXEC flag
Browse files Browse the repository at this point in the history
Also set the size of the attribute struct, and only use PERF_SAMPLE_RAW
for the output buffers.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
kvanhees committed Oct 14, 2021
1 parent 7fe6ce9 commit ad37209
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion libdtrace/dt_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ int
perf_event_open(struct perf_event_attr *attr, pid_t pid,
int cpu, int group_fd, unsigned long flags)
{
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd,
flags | PERF_FLAG_FD_CLOEXEC);
}

int
Expand Down
5 changes: 3 additions & 2 deletions libdtrace/dt_peb.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -75,10 +75,11 @@ dt_peb_open(dt_peb_t *peb)
memset(&attr, 0, sizeof(attr));
attr.config = PERF_COUNT_SW_BPF_OUTPUT;
attr.type = PERF_TYPE_SOFTWARE;
attr.size = sizeof(attr);
attr.sample_type = PERF_SAMPLE_RAW;
attr.sample_period = 1;
attr.wakeup_events = 1;
fd = perf_event_open(&attr, -1, peb->cpu, -1, PERF_FLAG_FD_CLOEXEC);
fd = perf_event_open(&attr, -1, peb->cpu, -1, 0);
if (fd < 0)
goto fail;

Expand Down
3 changes: 1 addition & 2 deletions libdtrace/dt_prov_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
memset(&attr, 0, sizeof(attr));
attr.type = PERF_TYPE_SOFTWARE;
attr.config = PERF_COUNT_SW_CPU_CLOCK;
attr.sample_type = PERF_SAMPLE_RAW;
attr.size = sizeof(struct perf_event_attr);
attr.size = sizeof(attr);
attr.wakeup_events = 1;
attr.freq = 0;
attr.sample_period = pp->period;
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_provider_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dt_tp_attach(dtrace_hdl_t *dtp, tp_probe_t *tpp, int bpf_fd)
struct perf_event_attr attr = { 0, };

attr.type = PERF_TYPE_TRACEPOINT;
attr.sample_type = PERF_SAMPLE_RAW;
attr.size = sizeof(attr);
attr.sample_period = 1;
attr.wakeup_events = 1;
attr.config = tpp->event_id;
Expand Down

0 comments on commit ad37209

Please sign in to comment.