public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf record: Fix perf_can_aux_sample_size()
@ 2019-11-22  9:48 Adrian Hunter
  2019-11-22 13:42 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Adrian Hunter @ 2019-11-22  9:48 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel

perf_can_aux_sample_size() always returned true because it did not pass
the attribute size to sys_perf_event_open, nor correctly check the
return value and errno.

Before:

  # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
  Error:
  The sys_perf_event_open() syscall returned with 7 (Argument list too long) for event (branch-misses:u).
  /bin/dmesg | grep -i perf may provide additional information.

After:

  # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
  AUX area sampling is not supported by kernel

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/record.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index e2321edcdd8f..7def66168503 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -143,6 +143,7 @@ bool perf_can_record_cpu_wide(void)
 bool perf_can_aux_sample(void)
 {
 	struct perf_event_attr attr = {
+		.size = sizeof(struct perf_event_attr),
 		.exclude_kernel = 1,
 		/*
 		 * Non-zero value causes the kernel to calculate the effective
@@ -158,7 +159,7 @@ bool perf_can_aux_sample(void)
 	 * then we assume that it is supported. We are relying on the kernel to
 	 * validate the attribute size before anything else that could be wrong.
 	 */
-	if (fd == -E2BIG)
+	if (fd < 0 && errno == E2BIG)
 		return false;
 	if (fd >= 0)
 		close(fd);
-- 
2.17.1


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

* Re: [PATCH] perf record: Fix perf_can_aux_sample_size()
  2019-11-22  9:48 [PATCH] perf record: Fix perf_can_aux_sample_size() Adrian Hunter
@ 2019-11-22 13:42 ` Arnaldo Carvalho de Melo
  2019-11-22 13:49   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-22 13:42 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel

Em Fri, Nov 22, 2019 at 11:48:56AM +0200, Adrian Hunter escreveu:
> perf_can_aux_sample_size() always returned true because it did not pass
> the attribute size to sys_perf_event_open, nor correctly check the
> return value and errno.
> 
> Before:
> 
>   # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
>   Error:
>   The sys_perf_event_open() syscall returned with 7 (Argument list too long) for event (branch-misses:u).
>   /bin/dmesg | grep -i perf may provide additional information.
> 
> After:
> 
>   # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
>   AUX area sampling is not supported by kernel

Since this hasn't been sent to Ingo, I combined it with the patch that
introduced the problem, this one:

c31d79e7a052 perf record: Add a function to test for kernel support for AUX area sampling

Thanks for the quick fix,

- Arnaldo

 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/util/record.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
> index e2321edcdd8f..7def66168503 100644
> --- a/tools/perf/util/record.c
> +++ b/tools/perf/util/record.c
> @@ -143,6 +143,7 @@ bool perf_can_record_cpu_wide(void)
>  bool perf_can_aux_sample(void)
>  {
>  	struct perf_event_attr attr = {
> +		.size = sizeof(struct perf_event_attr),
>  		.exclude_kernel = 1,
>  		/*
>  		 * Non-zero value causes the kernel to calculate the effective
> @@ -158,7 +159,7 @@ bool perf_can_aux_sample(void)
>  	 * then we assume that it is supported. We are relying on the kernel to
>  	 * validate the attribute size before anything else that could be wrong.
>  	 */
> -	if (fd == -E2BIG)
> +	if (fd < 0 && errno == E2BIG)
>  		return false;
>  	if (fd >= 0)
>  		close(fd);
> -- 
> 2.17.1

-- 

- Arnaldo

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

* Re: [PATCH] perf record: Fix perf_can_aux_sample_size()
  2019-11-22 13:42 ` Arnaldo Carvalho de Melo
@ 2019-11-22 13:49   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-22 13:49 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel

Em Fri, Nov 22, 2019 at 10:42:57AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Nov 22, 2019 at 11:48:56AM +0200, Adrian Hunter escreveu:
> > perf_can_aux_sample_size() always returned true because it did not pass
> > the attribute size to sys_perf_event_open, nor correctly check the
> > return value and errno.
> > 
> > Before:
> > 
> >   # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
> >   Error:
> >   The sys_perf_event_open() syscall returned with 7 (Argument list too long) for event (branch-misses:u).
> >   /bin/dmesg | grep -i perf may provide additional information.
> > 
> > After:
> > 
> >   # perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
> >   AUX area sampling is not supported by kernel
> 
> Since this hasn't been sent to Ingo, I combined it with the patch that
> introduced the problem, this one:
> 
> c31d79e7a052 perf record: Add a function to test for kernel support for AUX area sampling
> 
> Thanks for the quick fix,

Wrapping up, at the end of the series I now get:

  [root@quaco ~]# perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
  AUX area sampling is not supported by kernel
  [root@quaco ~]#
  [root@quaco ~]# uname -a
  Linux quaco 5.4.0-rc8 #1 SMP Mon Nov 18 06:15:31 -03 2019 x86_64 x86_64 x86_64 GNU/Linux
  [root@quaco ~]#

Thanks,

- Arnaldo

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

end of thread, other threads:[~2019-11-22 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-22  9:48 [PATCH] perf record: Fix perf_can_aux_sample_size() Adrian Hunter
2019-11-22 13:42 ` Arnaldo Carvalho de Melo
2019-11-22 13:49   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox