All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf test: Skip sigtrap test on old kernels
@ 2022-09-07  5:04 Namhyung Kim
  2022-09-07  5:58 ` Song Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Namhyung Kim @ 2022-09-07  5:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, linux-perf-users,
	bpf, Marco Elver, Song Liu

If it runs on an old kernel, perf_event_open would fail because of the
new fields sigtrap and sig_data.  Just skipping the test could miss an
actual bug in the kernel.

Let's check BTF if it has the perf_event_attr.sigtrap field.

Cc: Marco Elver <elver@google.com>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
index e32ece90e164..32f08ce0f2b0 100644
--- a/tools/perf/tests/sigtrap.c
+++ b/tools/perf/tests/sigtrap.c
@@ -16,6 +16,8 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#include <bpf/btf.h>
+
 #include "cloexec.h"
 #include "debug.h"
 #include "event.h"
@@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
 	return attr;
 }
 
+static bool attr_has_sigtrap(void)
+{
+	bool ret = false;
+
+#ifdef HAVE_BPF_SKEL
+
+	struct btf *btf;
+	const struct btf_type *t;
+	const struct btf_member *m;
+	const char *name;
+	int i, id;
+
+	/* just assume it doesn't have the field */
+	btf = btf__load_vmlinux_btf();
+	if (btf == NULL)
+		return false;
+
+	id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
+	if (id < 0)
+		goto out;
+
+	t = btf__type_by_id(btf, id);
+	for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
+		name = btf__name_by_offset(btf, m->name_off);
+		if (!strcmp(name, "sigtrap")) {
+			ret = true;
+			break;
+		}
+	}
+out:
+	btf__free(btf);
+#endif
+
+	return ret;
+}
+
 static void
 sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
 {
@@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
 
 	fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
 	if (fd < 0) {
-		pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
+		if (attr_has_sigtrap()) {
+			pr_debug("FAILED sys_perf_event_open(): %s\n",
+				 str_error_r(errno, sbuf, sizeof(sbuf)));
+		} else {
+			pr_debug("perf_event_attr doesn't have sigtrap\n");
+			ret = TEST_SKIP;
+		}
 		goto out_restore_sigaction;
 	}
 
-- 
2.37.2.789.g6183377224-goog


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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07  5:04 [PATCH v2] perf test: Skip sigtrap test on old kernels Namhyung Kim
@ 2022-09-07  5:58 ` Song Liu
  2022-09-07  6:58   ` Namhyung Kim
  2022-09-07  8:32 ` Jiri Olsa
  2022-09-08 18:31 ` Arnaldo Carvalho de Melo
  2 siblings, 1 reply; 7+ messages in thread
From: Song Liu @ 2022-09-07  5:58 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Ian Rogers, linux-perf-users, bpf, Marco Elver, Song Liu

On Tue, Sep 6, 2022 at 10:04 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> If it runs on an old kernel, perf_event_open would fail because of the
> new fields sigtrap and sig_data.  Just skipping the test could miss an
> actual bug in the kernel.
>
> Let's check BTF if it has the perf_event_attr.sigtrap field.
>
> Cc: Marco Elver <elver@google.com>
> Cc: Song Liu <songliubraving@fb.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> index e32ece90e164..32f08ce0f2b0 100644
> --- a/tools/perf/tests/sigtrap.c
> +++ b/tools/perf/tests/sigtrap.c
> @@ -16,6 +16,8 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>
> +#include <bpf/btf.h>
> +

Do we need "#ifdef HAVE_BPF_SKEL" for the include part?

Other than this, looks good to me.

Acked-by: Song Liu <song@kernel.org>

>  #include "cloexec.h"
>  #include "debug.h"
>  #include "event.h"
> @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
>         return attr;
>  }
>
> +static bool attr_has_sigtrap(void)
> +{
> +       bool ret = false;
> +
> +#ifdef HAVE_BPF_SKEL
> +
> +       struct btf *btf;
> +       const struct btf_type *t;
> +       const struct btf_member *m;
> +       const char *name;
> +       int i, id;
> +
> +       /* just assume it doesn't have the field */
> +       btf = btf__load_vmlinux_btf();
> +       if (btf == NULL)
> +               return false;
> +
> +       id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> +       if (id < 0)
> +               goto out;
> +
> +       t = btf__type_by_id(btf, id);
> +       for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> +               name = btf__name_by_offset(btf, m->name_off);
> +               if (!strcmp(name, "sigtrap")) {
> +                       ret = true;
> +                       break;
> +               }
> +       }
> +out:
> +       btf__free(btf);
> +#endif
> +
> +       return ret;
> +}
> +
>  static void
>  sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
>  {
> @@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
>
>         fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
>         if (fd < 0) {
> -               pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
> +               if (attr_has_sigtrap()) {
> +                       pr_debug("FAILED sys_perf_event_open(): %s\n",
> +                                str_error_r(errno, sbuf, sizeof(sbuf)));
> +               } else {
> +                       pr_debug("perf_event_attr doesn't have sigtrap\n");
> +                       ret = TEST_SKIP;
> +               }
>                 goto out_restore_sigaction;
>         }
>
> --
> 2.37.2.789.g6183377224-goog
>

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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07  5:58 ` Song Liu
@ 2022-09-07  6:58   ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2022-09-07  6:58 UTC (permalink / raw)
  To: Song Liu
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Ian Rogers, linux-perf-users, bpf, Marco Elver, Song Liu

Hi Song,

On Tue, Sep 6, 2022 at 10:58 PM Song Liu <song@kernel.org> wrote:
>
> On Tue, Sep 6, 2022 at 10:04 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > If it runs on an old kernel, perf_event_open would fail because of the
> > new fields sigtrap and sig_data.  Just skipping the test could miss an
> > actual bug in the kernel.
> >
> > Let's check BTF if it has the perf_event_attr.sigtrap field.
> >
> > Cc: Marco Elver <elver@google.com>
> > Cc: Song Liu <songliubraving@fb.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> >  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 45 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> > index e32ece90e164..32f08ce0f2b0 100644
> > --- a/tools/perf/tests/sigtrap.c
> > +++ b/tools/perf/tests/sigtrap.c
> > @@ -16,6 +16,8 @@
> >  #include <sys/syscall.h>
> >  #include <unistd.h>
> >
> > +#include <bpf/btf.h>
> > +
>
> Do we need "#ifdef HAVE_BPF_SKEL" for the include part?

Right, it'd be better to move it under the #ifdef.  Will change.

>
> Other than this, looks good to me.
>
> Acked-by: Song Liu <song@kernel.org>

Thanks for the review!
Namhyung

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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07  5:04 [PATCH v2] perf test: Skip sigtrap test on old kernels Namhyung Kim
  2022-09-07  5:58 ` Song Liu
@ 2022-09-07  8:32 ` Jiri Olsa
  2022-09-07 17:50   ` Namhyung Kim
  2022-09-08 18:31 ` Arnaldo Carvalho de Melo
  2 siblings, 1 reply; 7+ messages in thread
From: Jiri Olsa @ 2022-09-07  8:32 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra, LKML,
	Ian Rogers, linux-perf-users, bpf, Marco Elver, Song Liu

On Tue, Sep 06, 2022 at 10:04:07PM -0700, Namhyung Kim wrote:
> If it runs on an old kernel, perf_event_open would fail because of the
> new fields sigtrap and sig_data.  Just skipping the test could miss an
> actual bug in the kernel.
> 
> Let's check BTF if it has the perf_event_attr.sigtrap field.
> 
> Cc: Marco Elver <elver@google.com>
> Cc: Song Liu <songliubraving@fb.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> index e32ece90e164..32f08ce0f2b0 100644
> --- a/tools/perf/tests/sigtrap.c
> +++ b/tools/perf/tests/sigtrap.c
> @@ -16,6 +16,8 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <bpf/btf.h>
> +
>  #include "cloexec.h"
>  #include "debug.h"
>  #include "event.h"
> @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
>  	return attr;
>  }
>  
> +static bool attr_has_sigtrap(void)
> +{
> +	bool ret = false;
> +
> +#ifdef HAVE_BPF_SKEL
> +
> +	struct btf *btf;
> +	const struct btf_type *t;
> +	const struct btf_member *m;
> +	const char *name;
> +	int i, id;
> +
> +	/* just assume it doesn't have the field */
> +	btf = btf__load_vmlinux_btf();
> +	if (btf == NULL)
> +		return false;
> +
> +	id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> +	if (id < 0)
> +		goto out;
> +
> +	t = btf__type_by_id(btf, id);
> +	for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> +		name = btf__name_by_offset(btf, m->name_off);
> +		if (!strcmp(name, "sigtrap")) {
> +			ret = true;
> +			break;
> +		}
> +	}
> +out:
> +	btf__free(btf);
> +#endif

would it be easier to call perf_event_open for simple event with
sigtrap set (and perhaps remove_on_exec) ? perf_copy_attr checks
on reserved fields

jirka


> +
> +	return ret;
> +}
> +
>  static void
>  sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
>  {
> @@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
>  
>  	fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
>  	if (fd < 0) {
> -		pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
> +		if (attr_has_sigtrap()) {
> +			pr_debug("FAILED sys_perf_event_open(): %s\n",
> +				 str_error_r(errno, sbuf, sizeof(sbuf)));
> +		} else {
> +			pr_debug("perf_event_attr doesn't have sigtrap\n");
> +			ret = TEST_SKIP;
> +		}
>  		goto out_restore_sigaction;
>  	}
>  
> -- 
> 2.37.2.789.g6183377224-goog
> 

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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07  8:32 ` Jiri Olsa
@ 2022-09-07 17:50   ` Namhyung Kim
  2022-09-07 18:05     ` Namhyung Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Namhyung Kim @ 2022-09-07 17:50 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra, LKML,
	Ian Rogers, linux-perf-users, bpf, Marco Elver, Song Liu

On Wed, Sep 7, 2022 at 1:32 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Sep 06, 2022 at 10:04:07PM -0700, Namhyung Kim wrote:
> > If it runs on an old kernel, perf_event_open would fail because of the
> > new fields sigtrap and sig_data.  Just skipping the test could miss an
> > actual bug in the kernel.
> >
> > Let's check BTF if it has the perf_event_attr.sigtrap field.
> >
> > Cc: Marco Elver <elver@google.com>
> > Cc: Song Liu <songliubraving@fb.com>
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> >  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 45 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> > index e32ece90e164..32f08ce0f2b0 100644
> > --- a/tools/perf/tests/sigtrap.c
> > +++ b/tools/perf/tests/sigtrap.c
> > @@ -16,6 +16,8 @@
> >  #include <sys/syscall.h>
> >  #include <unistd.h>
> >
> > +#include <bpf/btf.h>
> > +
> >  #include "cloexec.h"
> >  #include "debug.h"
> >  #include "event.h"
> > @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
> >       return attr;
> >  }
> >
> > +static bool attr_has_sigtrap(void)
> > +{
> > +     bool ret = false;
> > +
> > +#ifdef HAVE_BPF_SKEL
> > +
> > +     struct btf *btf;
> > +     const struct btf_type *t;
> > +     const struct btf_member *m;
> > +     const char *name;
> > +     int i, id;
> > +
> > +     /* just assume it doesn't have the field */
> > +     btf = btf__load_vmlinux_btf();
> > +     if (btf == NULL)
> > +             return false;
> > +
> > +     id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> > +     if (id < 0)
> > +             goto out;
> > +
> > +     t = btf__type_by_id(btf, id);
> > +     for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> > +             name = btf__name_by_offset(btf, m->name_off);
> > +             if (!strcmp(name, "sigtrap")) {
> > +                     ret = true;
> > +                     break;
> > +             }
> > +     }
> > +out:
> > +     btf__free(btf);
> > +#endif
>
> would it be easier to call perf_event_open for simple event with
> sigtrap set (and perhaps remove_on_exec) ? perf_copy_attr checks
> on reserved fields

Hmm.. right.  we could do that too.  But it might still fail if there's a
bug in the path handling in sigtrap even for the simple case.  I'm not
sure if it's a realistic concern though. :)

Thanks,
Namhyung

>
>
> > +
> > +     return ret;
> > +}
> > +
> >  static void
> >  sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
> >  {
> > @@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
> >
> >       fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
> >       if (fd < 0) {
> > -             pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
> > +             if (attr_has_sigtrap()) {
> > +                     pr_debug("FAILED sys_perf_event_open(): %s\n",
> > +                              str_error_r(errno, sbuf, sizeof(sbuf)));
> > +             } else {
> > +                     pr_debug("perf_event_attr doesn't have sigtrap\n");
> > +                     ret = TEST_SKIP;
> > +             }
> >               goto out_restore_sigaction;
> >       }
> >
> > --
> > 2.37.2.789.g6183377224-goog
> >

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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07 17:50   ` Namhyung Kim
@ 2022-09-07 18:05     ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2022-09-07 18:05 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra, LKML,
	Ian Rogers, linux-perf-users, bpf, Marco Elver, Song Liu

On Wed, Sep 7, 2022 at 10:50 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Wed, Sep 7, 2022 at 1:32 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Tue, Sep 06, 2022 at 10:04:07PM -0700, Namhyung Kim wrote:
> > > If it runs on an old kernel, perf_event_open would fail because of the
> > > new fields sigtrap and sig_data.  Just skipping the test could miss an
> > > actual bug in the kernel.
> > >
> > > Let's check BTF if it has the perf_event_attr.sigtrap field.
> > >
> > > Cc: Marco Elver <elver@google.com>
> > > Cc: Song Liu <songliubraving@fb.com>
> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > > ---
> > >  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
> > >  1 file changed, 45 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> > > index e32ece90e164..32f08ce0f2b0 100644
> > > --- a/tools/perf/tests/sigtrap.c
> > > +++ b/tools/perf/tests/sigtrap.c
> > > @@ -16,6 +16,8 @@
> > >  #include <sys/syscall.h>
> > >  #include <unistd.h>
> > >
> > > +#include <bpf/btf.h>
> > > +
> > >  #include "cloexec.h"
> > >  #include "debug.h"
> > >  #include "event.h"
> > > @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
> > >       return attr;
> > >  }
> > >
> > > +static bool attr_has_sigtrap(void)
> > > +{
> > > +     bool ret = false;
> > > +
> > > +#ifdef HAVE_BPF_SKEL
> > > +
> > > +     struct btf *btf;
> > > +     const struct btf_type *t;
> > > +     const struct btf_member *m;
> > > +     const char *name;
> > > +     int i, id;
> > > +
> > > +     /* just assume it doesn't have the field */
> > > +     btf = btf__load_vmlinux_btf();
> > > +     if (btf == NULL)
> > > +             return false;
> > > +
> > > +     id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> > > +     if (id < 0)
> > > +             goto out;
> > > +
> > > +     t = btf__type_by_id(btf, id);
> > > +     for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> > > +             name = btf__name_by_offset(btf, m->name_off);
> > > +             if (!strcmp(name, "sigtrap")) {
> > > +                     ret = true;
> > > +                     break;
> > > +             }
> > > +     }
> > > +out:
> > > +     btf__free(btf);
> > > +#endif
> >
> > would it be easier to call perf_event_open for simple event with
> > sigtrap set (and perhaps remove_on_exec) ? perf_copy_attr checks
> > on reserved fields
>
> Hmm.. right.  we could do that too.  But it might still fail if there's a
> bug in the path handling in sigtrap even for the simple case.  I'm not
> sure if it's a realistic concern though. :)

I think we can do that when libbpf is not available.

Thanks,
Namhyung

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

* Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
  2022-09-07  5:04 [PATCH v2] perf test: Skip sigtrap test on old kernels Namhyung Kim
  2022-09-07  5:58 ` Song Liu
  2022-09-07  8:32 ` Jiri Olsa
@ 2022-09-08 18:31 ` Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-08 18:31 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers,
	linux-perf-users, bpf, Marco Elver, Song Liu

Em Tue, Sep 06, 2022 at 10:04:07PM -0700, Namhyung Kim escreveu:
> If it runs on an old kernel, perf_event_open would fail because of the
> new fields sigtrap and sig_data.  Just skipping the test could miss an
> actual bug in the kernel.
> 
> Let's check BTF if it has the perf_event_attr.sigtrap field.
> 
> Cc: Marco Elver <elver@google.com>
> Cc: Song Liu <songliubraving@fb.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> index e32ece90e164..32f08ce0f2b0 100644
> --- a/tools/perf/tests/sigtrap.c
> +++ b/tools/perf/tests/sigtrap.c
> @@ -16,6 +16,8 @@
>  #include <sys/syscall.h>
>  #include <unistd.h>
>  
> +#include <bpf/btf.h>
> +
>  #include "cloexec.h"
>  #include "debug.h"
>  #include "event.h"
> @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void)
>  	return attr;
>  }
>  
> +static bool attr_has_sigtrap(void)
> +{
> +	bool ret = false;
> +
> +#ifdef HAVE_BPF_SKEL
> +
> +	struct btf *btf;
> +	const struct btf_type *t;
> +	const struct btf_member *m;
> +	const char *name;
> +	int i, id;
> +
> +	/* just assume it doesn't have the field */
> +	btf = btf__load_vmlinux_btf();

Cool, at some point we'll probably move this to some other global place,
doing the lazy loading and keeping it in place as probably we'll use it
more often :-)

Waiting for v2.

Thanks for working on this.

- Arnaldo

> +	if (btf == NULL)
> +		return false;
> +
> +	id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> +	if (id < 0)
> +		goto out;
> +
> +	t = btf__type_by_id(btf, id);
> +	for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> +		name = btf__name_by_offset(btf, m->name_off);
> +		if (!strcmp(name, "sigtrap")) {
> +			ret = true;
> +			break;
> +		}
> +	}
> +out:
> +	btf__free(btf);
> +#endif
> +
> +	return ret;
> +}
> +
>  static void
>  sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
>  {
> @@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m
>  
>  	fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag());
>  	if (fd < 0) {
> -		pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf)));
> +		if (attr_has_sigtrap()) {
> +			pr_debug("FAILED sys_perf_event_open(): %s\n",
> +				 str_error_r(errno, sbuf, sizeof(sbuf)));
> +		} else {
> +			pr_debug("perf_event_attr doesn't have sigtrap\n");
> +			ret = TEST_SKIP;
> +		}
>  		goto out_restore_sigaction;
>  	}
>  
> -- 
> 2.37.2.789.g6183377224-goog

-- 

- Arnaldo

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

end of thread, other threads:[~2022-09-08 18:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07  5:04 [PATCH v2] perf test: Skip sigtrap test on old kernels Namhyung Kim
2022-09-07  5:58 ` Song Liu
2022-09-07  6:58   ` Namhyung Kim
2022-09-07  8:32 ` Jiri Olsa
2022-09-07 17:50   ` Namhyung Kim
2022-09-07 18:05     ` Namhyung Kim
2022-09-08 18:31 ` Arnaldo Carvalho de Melo

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.