All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: Fix probing for PERF_FLAG_FD_CLOEXEC flag
@ 2015-02-19  0:01 David Ahern
  2015-02-19  7:06 ` Adrian Hunter
  0 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2015-02-19  0:01 UTC (permalink / raw)
  To: acme, linux-kernel; +Cc: David Ahern, Adrian Hunter

Commit f6edb53c4993ffe92ce521fb449d1c146cea6ec2 converted the probe to
a CPU wide event first (pid == -1). For kernels that do not support
the PERF_FLAG_FD_CLOEXEC flag the probe fails with EINVAL. Since this
errno is not handled pid is not reset to 0 and the subsequent use of
pid = -1 as an argument brings in an additional failure path if
perf_event_paranoid > 0:

$ perf record -- sleep 1
perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.007 MB /tmp/perf.data (11 samples) ]

Since this function only needs to get past this check in kernel/events/core.c:

        /* for future expandability... */
        if (flags & ~PERF_FLAG_ALL)
                return -EINVAL;

pid = 0 is sufficient to confirm if the flag is supported or not.

Also, ensure the fd of the confirmation check is closed.

Needs to go to 3.18 stable tree as well.

Signed-off-by: David Ahern <david.ahern@oracle.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/cloexec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 47b78b3f0325..3cc34edf2403 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -47,16 +47,17 @@ static int perf_flag_probe(void)
 		  err, strerror_r(err, sbuf, sizeof(sbuf)));
 
 	/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
-	fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
+	fd = sys_perf_event_open(&attr, 0, cpu, -1, 0);
 	err = errno;
 
+	if (fd >= 0)
+		close(fd);
+
 	if (WARN_ONCE(fd < 0 && err != EBUSY,
 		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
 		      err, strerror_r(err, sbuf, sizeof(sbuf))))
 		return -1;
 
-	close(fd);
-
 	return 0;
 }
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-03-01 16:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19  0:01 [PATCH] perf: Fix probing for PERF_FLAG_FD_CLOEXEC flag David Ahern
2015-02-19  7:06 ` Adrian Hunter
2015-02-19 14:55   ` David Ahern
2015-02-19 16:17     ` Adrian Hunter
2015-02-19 16:22       ` David Ahern
2015-02-19 17:28         ` Adrian Hunter
2015-02-24 11:31           ` Adrian Hunter
2015-02-24 16:31             ` David Ahern
2015-03-01 16:50             ` [tip:perf/urgent] perf tools: " tip-bot for Adrian Hunter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.