[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7cgG_Jwb1Z98svrk0Q1X9RmeodOyHBvbqxGijP3eyBU_uw@mail.gmail.com>
Date: Wed, 7 Sep 2022 11:05:58 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Jiri Olsa <olsajiri@...il.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
LKML <linux-kernel@...r.kernel.org>,
Ian Rogers <irogers@...gle.com>,
linux-perf-users <linux-perf-users@...r.kernel.org>,
bpf <bpf@...r.kernel.org>, Marco Elver <elver@...gle.com>,
Song Liu <songliubraving@...com>
Subject: Re: [PATCH v2] perf test: Skip sigtrap test on old kernels
On Wed, Sep 7, 2022 at 10:50 AM Namhyung Kim <namhyung@...nel.org> wrote:
>
> On Wed, Sep 7, 2022 at 1:32 AM Jiri Olsa <olsajiri@...il.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@...gle.com>
> > > Cc: Song Liu <songliubraving@...com>
> > > Signed-off-by: Namhyung Kim <namhyung@...nel.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
Powered by blists - more mailing lists