Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752260AbbBSHII (ORCPT ); Thu, 19 Feb 2015 02:08:08 -0500 Received: from mga01.intel.com ([192.55.52.88]:46969 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751649AbbBSHIH (ORCPT ); Thu, 19 Feb 2015 02:08:07 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,607,1418112000"; d="scan'208";a="687767247" Message-ID: <54E58B64.9010902@intel.com> Date: Thu, 19 Feb 2015 09:06:12 +0200 From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: David Ahern , acme@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf: Fix probing for PERF_FLAG_FD_CLOEXEC flag References: <1424304072-91955-1-git-send-email-david.ahern@oracle.com> In-Reply-To: <1424304072-91955-1-git-send-email-david.ahern@oracle.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2494 Lines: 76 On 19/02/15 02:01, David Ahern wrote: > 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 > Cc: Adrian Hunter > --- > 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); I would prefer to avoid pid = 0 unless necessary and so just do the same thing again i.e. while (1) { fd = sys_perf_event_open(&attr, pid, cpu, -1, 0); if (fd < 0 && pid == -1 && errno == EACCES) { pid = 0; continue; } break; } > 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; > } > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/