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:   Sun, 17 Oct 2021 21:53:13 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Jiri Olsa <jolsa@...hat.com>
Cc:     Arnaldo Carvalho de Melo <arnaldo.melo@...il.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Andi Kleen <ak@...ux.intel.com>,
        Ian Rogers <irogers@...gle.com>,
        Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH] perf evsel: Fix missing exclude_{host,guest} setting

On Sun, Oct 17, 2021 at 2:07 PM Jiri Olsa <jolsa@...hat.com> wrote:
>
> On Sun, Oct 17, 2021 at 06:03:21PM -0300, Arnaldo Carvalho de Melo wrote:
> >
> >
> > On October 17, 2021 4:05:46 PM GMT-03:00, Jiri Olsa <jolsa@...hat.com> wrote:
> > >On Fri, Oct 15, 2021 at 10:12:53PM -0700, Namhyung Kim wrote:
> > >> The current logic for the perf missing feature has a bug that it can
> > >> wrongly clear some modifiers like G or H.  Actually some PMUs don't
> > >> support any filtering or exclusion while others do.  But we check it
> > >> as a global feature.
> > >>
> > >> For example, the cycles event can have 'G' modifier to enable it only
> > >> in the guest mode on x86.  When you don't run any VMs it'll return 0.
> > >>
> > >>   # perf stat -a -e cycles:G sleep 1
> > >>
> > >>     Performance counter stats for 'system wide':
> > >>
> > >>                     0      cycles:G
> > >>
> > >>           1.000721670 seconds time elapsed
> > >>
> > >> But when it's used with other pmu events that don't support G modifier,
> > >> it'll be reset and return non-zero values.
> > >>
> > >>   # perf stat -a -e cycles:G,msr/tsc/ sleep 1
> > >>
> > >>     Performance counter stats for 'system wide':
> > >>
> > >>           538,029,960      cycles:G
> > >>        16,924,010,738      msr/tsc/
> > >>
> > >>           1.001815327 seconds time elapsed
> > >>
> > >> This is because of the missing feature detection logic being global.
> > >> Add a hashmap to set pmu-specific exclude_host/guest features.
> > >>
> > >> Reported-by: Stephane Eranian <eranian@...gle.com>
> > >> Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> > >> ---
> > >>  tools/perf/util/evsel.c | 47 +++++++++++++++++++++++++++++++++++------
> > >>  tools/perf/util/evsel.h |  6 ++++++
> > >>  2 files changed, 47 insertions(+), 6 deletions(-)
> > >>
> > >> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> > >> index dbfeceb2546c..437a28e769fe 100644
> > >> --- a/tools/perf/util/evsel.c
> > >> +++ b/tools/perf/util/evsel.c
> > >> @@ -1434,6 +1434,10 @@ void evsel__delete(struct evsel *evsel)
> > >>  {
> > >>    evsel__exit(evsel);
> > >>    free(evsel);
> > >> +
> > >> +  /* just free it for the first evsel */
> > >> +  hashmap__free(perf_missing_features.pmu);
> > >> +  perf_missing_features.pmu = NULL;
> > >>  }
> > >>
> > >>  void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
> > >> @@ -1791,6 +1795,23 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
> > >>    return 0;
> > >>  }
> > >>
> > >> +#define PMU_HASH_BITS  4
> > >> +
> > >> +static size_t pmu_hash(const void *key, void *ctx __maybe_unused)
> > >> +{
> > >> +  const struct evsel *evsel = key;
> > >> +
> > >> +  return hash_bits(evsel->core.attr.type, PMU_HASH_BITS);
> > >> +}
> > >> +
> > >> +static bool pmu_equal(const void *key1, const void *key2, void *ctx __maybe_unused)
> > >> +{
> > >> +  const struct evsel *a = key1;
> > >> +  const struct evsel *b = key2;
> > >> +
> > >> +  return a->core.attr.type == b->core.attr.type;
> > >> +}
> > >> +
> > >>  static void evsel__disable_missing_features(struct evsel *evsel)
> > >>  {
> > >>    if (perf_missing_features.weight_struct) {
> > >> @@ -1807,8 +1828,14 @@ static void evsel__disable_missing_features(struct evsel *evsel)
> > >>            evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
> > >>    if (perf_missing_features.mmap2)
> > >>            evsel->core.attr.mmap2 = 0;
> > >> -  if (perf_missing_features.exclude_guest)
> > >> -          evsel->core.attr.exclude_guest = evsel->core.attr.exclude_host = 0;
> > >> +  if (perf_missing_features.exclude_guest) {
> > >> +          void *pmu;
> > >
> > >could you just pass NULL in here instead of NULL?
> >
> > ENOPARSE
>
> ugh right... 'instead of &pmu' ;-)

Yes, we can pass NULL for the current code.
Passing the pointer is just for future change.
Maybe I thought too much.. :)

Anyway, I think it should pass the struct itself,
not the pointer to the local variable.
I'm not sure if it's possible to cast a struct literal
to a pointer, will check and update in v2.

Thanks,
Namhyung

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ