lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 28 Jun 2023 13:05:17 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Yang Jihong <yangjihong1@...wei.com>
Cc:     Ian Rogers <irogers@...gle.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Kan Liang <kan.liang@...ux.intel.com>,
        James Clark <james.clark@....com>,
        Suzuki Poulouse <suzuki.poulose@....com>,
        Rob Herring <robh@...nel.org>,
        Ravi Bangoria <ravi.bangoria@....com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1] perf pmus: Add placeholder core PMU

On Tue, Jun 27, 2023 at 8:01 PM Yang Jihong <yangjihong1@...wei.com> wrote:
>
> Hello,
>
> On 2023/6/28 2:28, Ian Rogers wrote:
> > If loading a core PMU fails, legacy hardware/cache events may segv due
> > to there being no PMU. Create a placeholder empty PMU for this
> > case. This was discussed in:
> > https://lore.kernel.org/lkml/20230614151625.2077-1-yangjihong1@huawei.com/
> >
> > Reported-by: Yang Jihong <yangjihong1@...wei.com>
> > Signed-off-by: Ian Rogers <irogers@...gle.com>
> > ---
> >   tools/perf/util/pmu.c  | 25 +++++++++++++++++++++++++
> >   tools/perf/util/pmu.h  |  1 +
> >   tools/perf/util/pmus.c |  7 ++++++-
> >   3 files changed, 32 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> > index 8d5ecd4ff1a9..7f984a7f16ca 100644
> > --- a/tools/perf/util/pmu.c
> > +++ b/tools/perf/util/pmu.c
> > @@ -928,6 +928,31 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
> >       return NULL;
> >   }
> >
> > +/* Creates the PMU when sysfs scanning fails. */
> > +struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus)
> > +{
> > +     struct perf_pmu *pmu = zalloc(sizeof(*pmu));
> > +
> > +     if (!pmu)
> > +             return NULL;
> > +
> > +     pmu->name = strdup("cpu");
> > +     if (!pmu->name) {
> > +             free(pmu);
> > +             return NULL;
> > +     }
> > +
> > +     pmu->is_core = true;
> > +     pmu->type = PERF_TYPE_RAW;
> > +     pmu->cpus = cpu_map__online();
> > +
> > +     INIT_LIST_HEAD(&pmu->format);
> > +     INIT_LIST_HEAD(&pmu->aliases);
> > +     INIT_LIST_HEAD(&pmu->caps);
> > +     list_add_tail(&pmu->list, core_pmus);
> > +     return pmu;
> > +}
> > +
> >   void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu)
> >   {
> >       struct perf_pmu_format *format;
> > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
> > index 8807a624e918..203b92860e3c 100644
> > --- a/tools/perf/util/pmu.h
> > +++ b/tools/perf/util/pmu.h
> > @@ -286,6 +286,7 @@ int perf_pmu__event_source_devices_fd(void);
> >   int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags);
> >
> >   struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
> > +struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus);
> >   void perf_pmu__delete(struct perf_pmu *pmu);
> >
> >   #endif /* __PMU_H */
> > diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> > index 0866dee3fc62..3cd9de42139e 100644
> > --- a/tools/perf/util/pmus.c
> > +++ b/tools/perf/util/pmus.c
> > @@ -153,7 +153,12 @@ static void pmu_read_sysfs(bool core_only)
> >
> >       closedir(dir);
> >       if (core_only) {
> > -             read_sysfs_core_pmus = true;
> > +             if (!list_empty(&core_pmus))
> > +                     read_sysfs_core_pmus = true;
> > +             else {
> > +                     if (perf_pmu__create_placeholder_core_pmu(&core_pmus))
> > +                             read_sysfs_core_pmus = true;
> > +             }
> >       } else {
> >               read_sysfs_core_pmus = true;
> >               read_sysfs_all_pmus = true;
> >
> Great. This patch solves the problem, the test results are shown in [1].
>
> Tested-by: Yang Jihong <yangjihong1@...wei.com>

Applied to perf-tools-next, thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ