1. 12 Jun, 2023 30 commits
    • Ian Rogers's avatar
      perf srcline: Change free_srcline to zfree_srcline · 625db36e
      Ian Rogers authored
      Make use after free more unlikely.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-26-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      625db36e
    • Ian Rogers's avatar
      perf callchain: Use pthread keys for tls callchain_cursor · 8ab12a20
      Ian Rogers authored
      Pthread keys are more portable than __thread and allow the association
      of a destructor with the key. Use the destructor to clean up TLS
      callchain cursors to aid understanding memory leaks.
      
      Committer notes:
      
      Had to fixup a series of unconverted places and also check for the
      return of get_tls_callchain_cursor() as it may fail and return NULL.
      
      In that unlikely case we now either print something to a file, if the
      caller was expecting to print a callchain, or return an error code to
      state that resolving the callchain isn't possible.
      
      In some cases this was made easier because thread__resolve_callchain()
      already can fail for other reasons, so this new one (cursor == NULL) can
      be added and the callers don't have to explicitely check for this new
      condition.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-25-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8ab12a20
    • Ian Rogers's avatar
      perf header: Avoid out-of-bounds read · d7ba60a4
      Ian Rogers authored
      intel-pt tests were failing:
      
        -- Test virtual LBR ---
        Linux
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.126 MB /tmp/perf-test-intel-pt-sh.FW57CXnCqQ/test-perf.data ]
        Failed with virtual lbr
        ...
        ```
      
        The root cause is an out-of-bounds read in header (where maxbrstack.py
        is from test_intel_pt.sh):
        ```
        $ perf --no-pager script --itrace=L -s maxbrstack.py
        =================================================================
        ==3907930==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000095a8 at pc 0x563c26c840bb bp 0x7fff43582710 sp 0x7fff43582708
        READ of size 4 at 0x6020000095a8 thread T0
            #0 0x563c26c840ba in process_group_desc util/header.c:2847
            #1 0x563c26c8bc78 in perf_file_section__process util/header.c:4037
            #2 0x563c26c8aa9b in perf_header__process_sections util/header.c:3813
            #3 0x563c26c8d028 in perf_session__read_header util/header.c:4286
            #4 0x563c26cbab29 in perf_session__open util/session.c:113
            #5 0x563c26cbb3d0 in __perf_session__new util/session.c:221
            #6 0x563c26aacb14 in perf_session__new util/session.h:73
            #7 0x563c26acf7f1 in cmd_script tools/perf/builtin-script.c:4212
            #8 0x563c26bb58ff in run_builtin tools/perf/perf.c:323
            #9 0x563c26bb5e70 in handle_internal_command tools/perf/perf.c:377
            #10 0x563c26bb6238 in run_argv tools/perf/perf.c:421
            #11 0x563c26bb67a0 in main tools/perf/perf.c:537
            #12 0x7f34bde46189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
            #13 0x7f34bde46244 in __libc_start_main_impl ../csu/libc-start.c:381
            #14 0x563c26a33390 in _start (/tmp/perf/perf+0x1eb390)
      
        0x6020000095a8 is located 8 bytes to the right of 16-byte region [0x602000009590,0x6020000095a0)
        allocated by thread T0 here:
            #0 0x7f34beeb83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
            #1 0x563c26c83df8 in process_group_desc util/header.c:2824
            #2 0x563c26c8bc78 in perf_file_section__process util/header.c:4037
            #3 0x563c26c8aa9b in perf_header__process_sections util/header.c:3813
            #4 0x563c26c8d028 in perf_session__read_header util/header.c:4286
            #5 0x563c26cbab29 in perf_session__open util/session.c:113
            #6 0x563c26cbb3d0 in __perf_session__new util/session.c:221
            #7 0x563c26aacb14 in perf_session__new util/session.h:73
            #8 0x563c26acf7f1 in cmd_script tools/perf/builtin-script.c:4212
            #9 0x563c26bb58ff in run_builtin tools/perf/perf.c:323
            #10 0x563c26bb5e70 in handle_internal_command tools/perf/perf.c:377
            #11 0x563c26bb6238 in run_argv tools/perf/perf.c:421
            #12 0x563c26bb67a0 in main tools/perf/perf.c:537
            #13 0x7f34bde46189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
        ```
      
      Avoid the out-of-bounds read checking for the leader. Leave the 'nr'
      check intact as nr will be 0 or the counting down and evsel be a group
      member.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/lkml/20230608232823.4027869-24-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d7ba60a4
    • Ian Rogers's avatar
      perf top: Add exit routine for main thread · cddeeeda
      Ian Rogers authored
      Add exit_process_thread that reverses init_process_thread. This avoids
      leak sanitizer reporting memory leaks.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-23-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cddeeeda
    • Ian Rogers's avatar
      perf annotate: Fix parse_objdump_line memory leak · d3d53b2e
      Ian Rogers authored
      fileloc is used to hold a previous line, before overwriting it ensure
      the previous contents is freed. Free the storage once done in
      symbol__disassemble.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-22-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d3d53b2e
    • Ian Rogers's avatar
      perf map/maps/thread: Changes to reference counting · bffb5b0c
      Ian Rogers authored
      Fix missed reference count gets and puts as detected with leak
      sanitizer and reference count checking.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-21-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      bffb5b0c
    • Ian Rogers's avatar
      perf machine: Don't leak module maps · 1981da1f
      Ian Rogers authored
      machine__addnew_module_map requires a put on its result. Add this and
      narrow the scope of map to make the correctness more obvious. This
      leak was caught with leak sanitizer and the reference count checker.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-20-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1981da1f
    • Ian Rogers's avatar
      perf machine: Fix leak of kernel dso · 34b29bd6
      Ian Rogers authored
      The kernel dso may be found by searching dsos or allocating if not
      found. The allocation returns with a reference count of 2, once for
      the dsos list and once for the returned value. The list search has a
      reference count of 1, once for the dsos list. To make the reference
      counts consistent, increase the dsos list search reference count to 2
      with a dso__get, and do a put when the scope ends for either the
      allocated or found dso.
      
      This issue was found with leak sanitizer and reference count checking.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-19-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      34b29bd6
    • Ian Rogers's avatar
      perf maps: Fix overlapping memory leak · 814a6568
      Ian Rogers authored
      Add a missed free detected by leak sanitizer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-18-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      814a6568
    • Ian Rogers's avatar
      perf symbol-elf: Correct holding a reference · fe8fec10
      Ian Rogers authored
      If a reference is held, don't put it as this will confuse reference
      count checking.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-17-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      fe8fec10
    • Ian Rogers's avatar
      perf jit: Fix two thread leaks · 5cedd1e2
      Ian Rogers authored
      As reported by leak sanitizer with reference count checking.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-16-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5cedd1e2
    • Ian Rogers's avatar
      perf python: Avoid 2 leak sanitizer issues · 51cfe7a3
      Ian Rogers authored
      Leak sanitizer complains about the variable size bf allocation and
      store to bf if sized 0.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-15-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      51cfe7a3
    • Ian Rogers's avatar
      perf evlist: Free stats in all evlist destruction · ac873ac3
      Ian Rogers authored
      There is no evsel free stats, freeing in the evlist__delete ensures
      memory leaks are avoided. Issues detected with "perf stat report" and
      leak sanitizer, perf stat uses perf_session__delete to free the
      evlist. Add dummy symbol for python build.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-14-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ac873ac3
    • Ian Rogers's avatar
      perf intel-pt: Fix missed put and leak · 084770f5
      Ian Rogers authored
      Add missing put and free, detected with leak sanitizer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-13-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      084770f5
    • Ian Rogers's avatar
      perf stat: Avoid evlist leak · 2b87be18
      Ian Rogers authored
      Free evlist before overwriting in "perf stat report" mode. Detected
      using leak sanitizer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-12-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2b87be18
    • Ian Rogers's avatar
      perf header: Ensure bitmaps are freed · f8e502b9
      Ian Rogers authored
      memory_node bitmaps need a bitmap_free to avoid memory leaks. Caught
      by leak sanitizer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-11-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f8e502b9
    • Ian Rogers's avatar
      perf report: Avoid 'parent_thread' thread leak on '--tasks' processing · 2c9f7bd7
      Ian Rogers authored
      Caught with address sanitizer and reference count checking.
      
      Committer notes:
      
      The command leading to this leak:
      
        # perf record -a sleep 2
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 2.516 MB perf.data (6422 samples) ]
        # perf report --tasks
        #      pid      tid     ppid  comm
                 0        0       -1 |swapper
                 1        1        0 | systemd
              1474     1474        1 |  systemd
              2816     2816     1474 |   gjs
              2816     2825     2816 |    gmain
              2816     2831     2816 |    gdbus
              2816     2861     2816 |    JS Helper
              2816     2862     2816 |    JS Helper
              2816     2863     2816 |    JS Helper
              2816     2864     2816 |    JS Helper
              2816     2865     2816 |    JS Helper
              2816     2866     2816 |    JS Helper
              2816     2867     2816 |    JS Helper
              2816     2868     2816 |    JS Helper
              3072     3072     1474 |   gsd-printer
              3072     3082     3072 |    gmain
              3072     3083     3072 |    gdbus
              2600     2600     1474 |   gnome-shell
             15621    15621     2600 |    firefox
             15771    15771    15621 |     WebExtensions
             15771    15872    15771 |      TaskCon~ller #6
             15771    15873    15771 |      TaskCon~ller #7
             15771    15778    15771 |      IPC I/O Child
             15771    15779    15771 |      Socket Thread
             15771    15780    15771 |      HTML5 Parser
             15771    15781    15771 |      JS Watchdog
        # <SNIP>
      
      When it is going to exit a thread__put(parent_thread) was missed, add it
      to have ASAN clean.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-10-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2c9f7bd7
    • Ian Rogers's avatar
      perf machine: Make delete_threads part of machine__exit · cf078c83
      Ian Rogers authored
      The code required threads to be deleted before machine__exit was
      called or the threads would be leaked. This was error prone so move
      the delete_threads into machine__exit.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cf078c83
    • Ian Rogers's avatar
      perf thread: Add reference count checking · f6005caf
      Ian Rogers authored
      Modify struct declaration and accessor functions for the reference
      count checkers additional layer of indirection. Make sure pid_cmp in
      builtin-sched.c uses the underlying/original struct in pointer
      arithmetic, and not the temporary get/put indirection.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f6005caf
    • Ian Rogers's avatar
      perf addr_location: Add init/exit/copy functions · 0dd5041c
      Ian Rogers authored
      struct addr_location holds references to multiple reference counted
      objects. Add init/exit functions to make maintenance of those more
      consistent with the rest of the code and to try to avoid
      leaks. Modification of thread reference counts isn't included in this
      change.
      
      Committer notes:
      
      I needed to initialize result to sample->ip to make sure is set to
      something, fixing a compile time error, mostly keeping the previous
      logic as build_alloc_func_list() already does debugging/error prints
      about what went wrong if it takes the 'goto out'.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0dd5041c
    • Ian Rogers's avatar
      perf addr_location: Move to its own header · 620be847
      Ian Rogers authored
      addr_location is a common abstraction, move it into its own header and
      source file in preparation for wider clean up.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-6-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      620be847
    • Ian Rogers's avatar
      perf maps: Make delete static, always use put · 46125590
      Ian Rogers authored
      Address/leak sanitizer with reference count checking can identify the
      location of leaks, so use put rather than delete to avoid free-ing
      memory when the reference count is >1. Add maps__zput to ensure the
      variable is cleared.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      46125590
    • Ian Rogers's avatar
      perf thread: Add accessor functions for thread · ee84a303
      Ian Rogers authored
      Using accessors will make it easier to add reference count checking in
      later patches.
      
      Committer notes:
      
      thread->nsinfo wasn't wrapped as it is used together with
      nsinfo__zput(), where does a trick to set the field with a refcount
      being dropped to NULL, and that doesn't work well with using
      thread__nsinfo(thread), that loses the &thread->nsinfo pointer.
      
      When refcount checking is added to 'struct thread', later in this
      series, nsinfo__zput(RC_CHK_ACCESS(thread)->nsinfo) will be used to
      check the thread pointer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ee84a303
    • Ian Rogers's avatar
      perf thread: Make threads rbtree non-invasive · 7ee227f6
      Ian Rogers authored
      Separate the rbtree out of thread and into a new struct
      thread_rb_node. The refcnt is in thread and the rbtree is responsible
      for a single count.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7ee227f6
    • Ian Rogers's avatar
      perf thread: Remove notion of dead threads · 40826c45
      Ian Rogers authored
      The dead thread list is best effort. Threads live on it until the
      reference count hits zero and they are removed. With correct reference
      counting this should never happen. It is, however, part of the 'perf
      sched' output that is now removed. If this is an issue we should
      implement tracking of dead threads in a robust not best-effort way.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      40826c45
    • Ian Rogers's avatar
      perf test: Add test of libpfm4 events · dcf7a177
      Ian Rogers authored
        $ ./perf test -v 102
        102: perf all libpfm4 events test                                    :
        --- start ---
        test child forked, pid 3030994
        Testing ix86arch::UNHALTED_CORE_CYCLES
        Testing ix86arch::INSTRUCTION_RETIRED
        Testing ix86arch::UNHALTED_REFERENCE_CYCLES
        Testing ix86arch::LLC_REFERENCES
        Testing ix86arch::LLC_MISSES
        Testing ix86arch::BRANCH_INSTRUCTIONS_RETIRED
        Testing ix86arch::MISPREDICTED_BRANCH_RETIRED
        Testing perf_raw::r0000
        Testing icl::UNHALTED_CORE_CYCLES
        Testing icl::UNHALTED_REFERENCE_CYCLES
        ...
        test child finished with 0
        ---- end ----
        perf all libpfm4 events test: Ok
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lore.kernel.org/r/20230608232400.3056312-4-namhyung@kernel.orgSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      dcf7a177
    • Ian Rogers's avatar
      perf list: Check arguments to show libpfm4 events · cc3d139b
      Ian Rogers authored
      This is particularly useful for tests.
      
        $ perf list pfm
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lore.kernel.org/r/20230608232400.3056312-3-namhyung@kernel.orgSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cc3d139b
    • Namhyung Kim's avatar
      perf list: Check if libpfm4 event is supported · d1f1cecc
      Namhyung Kim authored
      Some of its event info cannot be used directly due to missing default
      attributes.  Let's check if the event is supported before printing like
      we do for hw and cache events.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Acked-by: default avatarIan Rogers <irogers&gt;@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lore.kernel.org/r/20230608232400.3056312-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d1f1cecc
    • Adrian Hunter's avatar
      perf parse: Allow config terms with breakpoints · f0617f52
      Adrian Hunter authored
      Add config terms to the parsing of breakpoint events. Extend "Test event
      parsing" to also cover using a confg term.
      
      This makes breakpoint events consistent with other events which already
      support config terms.
      
      Example:
      
        $ cat dr_test.c
        #include <unistd.h>
        #include <stdio.h>
      
        void func0(void)
        {
        }
      
        int main()
        {
                printf("func0 %p\n", &func0);
                while (1) {
                        func0();
                        usleep(100000);
                }
                return 0;
        }
        $ gcc -g -O0 -o dr_test dr_test.c
        $ ./dr_test &
        [2] 19646
        func0 0x55feb98dd169
        $ perf record -e mem:0x55feb98dd169:x/name=breakpoint/ -p 19646 -- sleep 0.5
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.017 MB perf.data (5 samples) ]
        $ perf script
            dr_test 19646  5632.956628:          1 breakpoint:      55feb98dd169 func0+0x0 (/home/ahunter/git/work/dr_test)
            dr_test 19646  5633.056866:          1 breakpoint:      55feb98dd169 func0+0x0 (/home/ahunter/git/work/dr_test)
            dr_test 19646  5633.157084:          1 breakpoint:      55feb98dd169 func0+0x0 (/home/ahunter/git/work/dr_test)
            dr_test 19646  5633.257309:          1 breakpoint:      55feb98dd169 func0+0x0 (/home/ahunter/git/work/dr_test)
            dr_test 19646  5633.357532:          1 breakpoint:      55feb98dd169 func0+0x0 (/home/ahunter/git/work/dr_test)
        $ sudo perf test "Test event parsing"
          6: Parse event definition strings                                  :
          6.1: Test event parsing                                            : Ok
        $ sudo perf test -v "Test event parsing" |& grep mem
        running test 8 'mem:0'
        running test 9 'mem:0:x'
        running test 10 'mem:0:r'
        running test 11 'mem:0:w'
        running test 19 'mem:0:u'
        running test 20 'mem:0:x:k'
        running test 21 'mem:0:r:hp'
        running test 22 'mem:0:w:up'
        running test 26 'mem:0:rw'
        running test 27 'mem:0:rw:kp'
        running test 42 'mem:0/1'
        running test 43 'mem:0/2:w'
        running test 44 'mem:0/4:rw:u'
        running test 58 'mem:0/name=breakpoint/'
        running test 59 'mem:0:x/name=breakpoint/'
        running test 60 'mem:0:r/name=breakpoint/'
        running test 61 'mem:0:w/name=breakpoint/'
        running test 62 'mem:0/name=breakpoint/u'
        running test 63 'mem:0:x/name=breakpoint/k'
        running test 64 'mem:0:r/name=breakpoint/hp'
        running test 65 'mem:0:w/name=breakpoint/up'
        running test 66 'mem:0:rw/name=breakpoint/'
        running test 67 'mem:0:rw/name=breakpoint/kp'
        running test 68 'mem:0/1/name=breakpoint/'
        running test 69 'mem:0/2:w/name=breakpoint/'
        running test 70 'mem:0/4:rw/name=breakpoint/u'
        running test 71 'mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/'
      
      Committer notes:
      
      Folded follow up patch (see 2nd link below) to address warnings about
      unused tokens:
      
      perf tools: Suppress bison unused value warnings
      
      Patch "perf tools: Allow config terms with breakpoints" introduced parse
      tokens for colons and slashes within breakpoint parsing to prevent mix
      up with colons and slashes related to config terms.
      
      The token values are not needed but introduce bison "unused value"
      warnings.
      
      Suppress those warnings.
      
      Committer testing:
      
        # cat ~acme/c/mem_breakpoint.c
        #include <stdio.h>
        #include <unistd.h>
      
        void func1(void) { }
        void func2(void) { }
        void func3(void) { }
        void func4(void) { }
        void func5(void) { }
      
        int main()
        {
        	printf("func1 %p\n", &func1);
        	printf("func2 %p\n", &func2);
        	printf("func3 %p\n", &func3);
        	printf("func4 %p\n", &func4);
        	printf("func5 %p\n", &func5);
        	while (1) {
        		func1(); func2(); func3(); func4(); func5();
        		usleep(100000);
        	}
        	return 0;
        }
      
        # ~acme/c/mem_breakpoint &
        [1] 3186153
        func1 0x401136
        func2 0x40113d
        func3 0x401144
        func4 0x40114b
        func5 0x401152
        #
      
      Trying to watch the first 4 functions for eXecutable access:
      
        # perf record -e mem:0x401136:x/name=breakpoint1/,mem:0x40113d:x/name=breakpoint2/,mem:0x401144:x/name=breakpoint3/,mem:0x40114b:x/name=breakpoint4/  -p 3186153 -- sleep 0.5
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.026 MB perf.data (20 samples) ]
        [root@five ~]# perf script
          mem_breakpoint 3186153 131612.864793:  1 breakpoint1:  401136 func1+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.864795:  1 breakpoint2:  40113d func2+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.864796:  1 breakpoint3:  401144 func3+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.864797:  1 breakpoint4:  40114b func4+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.964868:  1 breakpoint1:  401136 func1+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.964870:  1 breakpoint2:  40113d func2+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.964871:  1 breakpoint3:  401144 func3+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131612.964872:  1 breakpoint4:  40114b func4+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.064945:  1 breakpoint1:  401136 func1+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.064948:  1 breakpoint2:  40113d func2+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.064948:  1 breakpoint3:  401144 func3+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.064949:  1 breakpoint4:  40114b func4+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.165024:  1 breakpoint1:  401136 func1+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.165026:  1 breakpoint2:  40113d func2+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.165027:  1 breakpoint3:  401144 func3+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.165028:  1 breakpoint4:  40114b func4+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.265103:  1 breakpoint1:  401136 func1+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.265105:  1 breakpoint2:  40113d func2+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.265106:  1 breakpoint3:  401144 func3+0x0 (/var/home/acme/c/mem_breakpoint)
          mem_breakpoint 3186153 131613.265107:  1 breakpoint4:  40114b func4+0x0 (/var/home/acme/c/mem_breakpoint)
        #
      
      Then all the 5 functions:
      
        # perf record -e mem:0x401136:x/name=breakpoint1/,mem:0x40113d:x/name=breakpoint2/,mem:0x401144:x/name=breakpoint3/,mem:0x40114b:x/name=breakpoint4/,mem:0x401152:x/name=breakpoint5/ -p 3186153 -- sleep 0.5
        Error:
        The sys_perf_event_open() syscall returned with 28 (No space left on device) for event (breakpoint5).
        /bin/dmesg | grep -i perf may provide additional information.
      
        # grep -m1 'model name' /proc/cpuinfo
        model name	: AMD Ryzen 9 5950X 16-Core Processor
        #
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/r/20230525082902.25332-2-adrian.hunter@intel.com
      Link: https://lore.kernel.org/r/f7228dc9-fe18-a8e3-7d3f-52922e0e1113@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f0617f52
    • Arnaldo Carvalho de Melo's avatar
      perf script: Fix allocation of evsel->priv related to per-event dump files · 36d3e413
      Arnaldo Carvalho de Melo authored
      When printing output we may want to generate per event files, where the
      --per-event-dump option should be used, creating perf.data.EVENT.dump
      files instead of printing to stdout.
      
      The callback thar processes event thus expects that evsel->priv->fp
      should point to either the per-event FILE descriptor or to stdout.
      
      The a3af66f5 ("perf script: Fix crash because of missing
      evsel->priv") changeset fixed a case where evsel->priv wasn't setup,
      thus set to NULL, causing a segfault when trying to access
      evsel->priv->fp.
      
      But it did it for the non --per-event-dump case by allocating a 'struct
      perf_evsel_script' just to set its ->fp to stdout.
      
      Since evsel->priv is only freed when --per-event-dump is used, we ended
      up with a memory leak, detected using ASAN.
      
      Fix it by using the same method as perf_script__setup_per_event_dump(),
      and reuse that static 'struct perf_evsel_script'.
      
      Also check if evsel_script__new() failed.
      
      Fixes: a3af66f5 ("perf script: Fix crash because of missing evsel->priv")
      Reported-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
      Link: https://lore.kernel.org/lkml/ZH+F0wGAWV14zvMP@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      36d3e413
  2. 09 Jun, 2023 3 commits
  3. 05 Jun, 2023 7 commits