1. 30 7月, 2019 5 次提交
  2. 09 7月, 2019 1 次提交
    • L
      perf top: Fix potential NULL pointer dereference detected by the smatch tool · 111442cf
      Leo Yan 提交于
      Based on the following report from Smatch, fix the potential NULL
      pointer dereference check.
      
        tools/perf/builtin-top.c:109
        perf_top__parse_source() warn: variable dereferenced before check 'he'
        (see line 103)
      
        tools/perf/builtin-top.c:233
        perf_top__show_details() warn: variable dereferenced before check 'he'
        (see line 228)
      
        tools/perf/builtin-top.c
        101 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
        102 {
        103         struct perf_evsel *evsel = hists_to_evsel(he->hists);
                                                              ^^^^
        104         struct symbol *sym;
        105         struct annotation *notes;
        106         struct map *map;
        107         int err = -1;
        108
        109         if (!he || !he->ms.sym)
        110                 return -1;
      
      This patch moves the values assignment after validating pointer 'he'.
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexios Zavras <alexios.zavras@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Changbin Du <changbin.du@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Eric Saint-Etienne <eric.saint.etienne@oracle.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Link: http://lkml.kernel.org/r/20190702103420.27540-4-leo.yan@linaro.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      111442cf
  3. 26 6月, 2019 2 次提交
  4. 05 6月, 2019 1 次提交
  5. 29 5月, 2019 2 次提交
  6. 16 4月, 2019 1 次提交
  7. 21 3月, 2019 2 次提交
    • S
      perf tools: Save bpf_prog_info and BTF of new BPF programs · d56354dc
      Song Liu 提交于
      To fully annotate BPF programs with source code mapping, 4 different
      information are needed:
      
          1) PERF_RECORD_KSYMBOL
          2) PERF_RECORD_BPF_EVENT
          3) bpf_prog_info
          4) btf
      
      This patch handles 3) and 4) for BPF programs loaded after 'perf
      record|top'.
      
      For timely process of these information, a dedicated event is added to
      the side band evlist.
      
      When PERF_RECORD_BPF_EVENT is received via the side band event, the
      polling thread gathers 3) and 4) vis sys_bpf and store them in perf_env.
      
      This information is saved to perf.data at the end of 'perf record'.
      
      Committer testing:
      
      The 'wakeup_watermark' member in 'struct perf_event_attr' is inside a
      unnamed union, so can't be used in a struct designated initialization
      with older gccs, get it out of that, isolating as 'attr.wakeup_watermark
      = 1;' to work with all gcc versions.
      
      We also need to add '--no-bpf-event' to the 'perf record'
      perf_event_attr tests in 'perf test', as the way that that test goes is
      to intercept the events being setup and looking if they match the fields
      described in the control files, since now it finds first the side band
      event used to catch the PERF_RECORD_BPF_EVENT, they all fail.
      
      With these issues fixed:
      
      Same scenario as for testing BPF programs loaded before 'perf record' or
      'perf top' starts, only start the BPF programs after 'perf record|top',
      so that its information get collected by the sideband threads, the rest
      works as for the programs loaded before start monitoring.
      
      Add missing 'inline' to the bpf_event__add_sb_event() when
      HAVE_LIBBPF_SUPPORT is not defined, fixing the build in systems without
      binutils devel files installed.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: http://lkml.kernel.org/r/20190312053051.2690567-16-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d56354dc
    • S
      perf evlist: Introduce side band thread · 657ee553
      Song Liu 提交于
      This patch introduces side band thread that captures extended
      information for events like PERF_RECORD_BPF_EVENT.
      
      This new thread uses its own evlist that uses ring buffer with very low
      watermark for lower latency.
      
      To use side band thread, we need to:
      
      1. add side band event(s) by calling perf_evlist__add_sb_event();
      2. calls perf_evlist__start_sb_thread();
      3. at the end of perf run, perf_evlist__stop_sb_thread().
      
      In the next patch, we use this thread to handle PERF_RECORD_BPF_EVENT.
      
      Committer notes:
      
      Add fix by Jiri Olsa for when te sb_tread can't get started and then at
      the end the stop_sb_thread() segfaults when joining the (non-existing)
      thread.
      
      That can happen when running 'perf top' or 'perf record' as a normal
      user, for instance.
      
      Further checks need to be done on top of this to more graciously handle
      these possible failure scenarios.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: http://lkml.kernel.org/r/20190312053051.2690567-15-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      657ee553
  8. 20 3月, 2019 4 次提交
    • S
      perf top: Add option --no-bpf-event · ee7a112f
      Song Liu 提交于
      This patch adds option --no-bpf-event to 'perf top', which is the same
      as the option of 'perf record'.
      
      The following patches will use this option.
      
      Committer testing:
      
        # perf top -vv 2> /tmp/perf_event_attr.out
        # cat  /tmp/perf_event_attr.out
        ------------------------------------------------------------
        perf_event_attr:
          size                             112
          { sample_period, sample_freq }   4000
          sample_type                      IP|TID|TIME|CPU|PERIOD
          read_format                      ID
          disabled                         1
          inherit                          1
          mmap                             1
          comm                             1
          freq                             1
          task                             1
          precise_ip                       3
          sample_id_all                    1
          exclude_guest                    1
          mmap2                            1
          comm_exec                        1
          ksymbol                          1
          bpf_event                        1
        ------------------------------------------------------------
        #
      
      After this patch:
      
        # perf top --no-bpf-event -vv 2> /tmp/perf_event_attr.out
        # cat  /tmp/perf_event_attr.out
        ------------------------------------------------------------
        perf_event_attr:
          size                             112
          { sample_period, sample_freq }   4000
          sample_type                      IP|TID|TIME|CPU|PERIOD
          read_format                      ID
          disabled                         1
          inherit                          1
          mmap                             1
          comm                             1
          freq                             1
          task                             1
          precise_ip                       3
          sample_id_all                    1
          exclude_guest                    1
          mmap2                            1
          comm_exec                        1
          ksymbol                          1
        ------------------------------------------------------------
        #
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Cc: kernel-team@fb.com
      Link: http://lkml.kernel.org/r/20190312053051.2690567-11-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ee7a112f
    • S
      perf bpf: Make synthesize_bpf_events() receive perf_session pointer instead of perf_tool · e5416950
      Song Liu 提交于
      This patch changes the arguments of perf_event__synthesize_bpf_events()
      to include perf_session* instead of perf_tool*. perf_session will be
      used in the next patch.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Cc: kernel-team@fb.com
      Link: http://lkml.kernel.org/r/20190312053051.2690567-6-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e5416950
    • C
      perf top: Fix error handling in cmd_top() · 70c819e4
      Changbin Du 提交于
      We should go to the cleanup path, to avoid leaks, detected using gcc's
      ASan.
      Signed-off-by: NChangbin Du <changbin.du@gmail.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Link: http://lkml.kernel.org/r/20190316080556.3075-9-changbin.du@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      70c819e4
    • C
      perf top: Delete the evlist before perf_session, fixing heap-use-after-free issue · 0dba9e4b
      Changbin Du 提交于
      The evlist should be destroyed before the perf session.
      
      Detected with gcc's ASan:
      
        =================================================================
        ==27350==ERROR: AddressSanitizer: heap-use-after-free on address 0x62b000002e38 at pc 0x5611da276999 bp 0x7ffce8f1d1a0 sp 0x7ffce8f1d190
        WRITE of size 8 at 0x62b000002e38 thread T0
            #0 0x5611da276998 in __list_del /home/work/linux/tools/include/linux/list.h:89
            #1 0x5611da276d4a in __list_del_entry /home/work/linux/tools/include/linux/list.h:102
            #2 0x5611da276e77 in list_del_init /home/work/linux/tools/include/linux/list.h:145
            #3 0x5611da2781cd in thread__put util/thread.c:130
            #4 0x5611da2cc0a8 in __thread__zput util/thread.h:68
            #5 0x5611da2d2dcb in hist_entry__delete util/hist.c:1148
            #6 0x5611da2cdf91 in hists__delete_entry util/hist.c:337
            #7 0x5611da2ce19e in hists__delete_entries util/hist.c:365
            #8 0x5611da2db2ab in hists__delete_all_entries util/hist.c:2639
            #9 0x5611da2db325 in hists_evsel__exit util/hist.c:2651
            #10 0x5611da1c5352 in perf_evsel__exit util/evsel.c:1304
            #11 0x5611da1c5390 in perf_evsel__delete util/evsel.c:1309
            #12 0x5611da1b35f0 in perf_evlist__purge util/evlist.c:124
            #13 0x5611da1b38e2 in perf_evlist__delete util/evlist.c:148
            #14 0x5611da069781 in cmd_top /home/changbin/work/linux/tools/perf/builtin-top.c:1645
            #15 0x5611da17d038 in run_builtin /home/changbin/work/linux/tools/perf/perf.c:302
            #16 0x5611da17d577 in handle_internal_command /home/changbin/work/linux/tools/perf/perf.c:354
            #17 0x5611da17d97b in run_argv /home/changbin/work/linux/tools/perf/perf.c:398
            #18 0x5611da17e0e9 in main /home/changbin/work/linux/tools/perf/perf.c:520
            #19 0x7fdcc970f09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
            #20 0x5611d9ff35c9 in _start (/home/work/linux/tools/perf/perf+0x3e95c9)
      
        0x62b000002e38 is located 11320 bytes inside of 27448-byte region [0x62b000000200,0x62b000006d38)
        freed by thread T0 here:
            #0 0x7fdccb04ab70 in free (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xedb70)
            #1 0x5611da260df4 in perf_session__delete util/session.c:201
            #2 0x5611da063de5 in __cmd_top /home/changbin/work/linux/tools/perf/builtin-top.c:1300
            #3 0x5611da06973c in cmd_top /home/changbin/work/linux/tools/perf/builtin-top.c:1642
            #4 0x5611da17d038 in run_builtin /home/changbin/work/linux/tools/perf/perf.c:302
            #5 0x5611da17d577 in handle_internal_command /home/changbin/work/linux/tools/perf/perf.c:354
            #6 0x5611da17d97b in run_argv /home/changbin/work/linux/tools/perf/perf.c:398
            #7 0x5611da17e0e9 in main /home/changbin/work/linux/tools/perf/perf.c:520
            #8 0x7fdcc970f09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
      
        previously allocated by thread T0 here:
            #0 0x7fdccb04b138 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xee138)
            #1 0x5611da26010c in zalloc util/util.h:23
            #2 0x5611da260824 in perf_session__new util/session.c:118
            #3 0x5611da0633a6 in __cmd_top /home/changbin/work/linux/tools/perf/builtin-top.c:1192
            #4 0x5611da06973c in cmd_top /home/changbin/work/linux/tools/perf/builtin-top.c:1642
            #5 0x5611da17d038 in run_builtin /home/changbin/work/linux/tools/perf/perf.c:302
            #6 0x5611da17d577 in handle_internal_command /home/changbin/work/linux/tools/perf/perf.c:354
            #7 0x5611da17d97b in run_argv /home/changbin/work/linux/tools/perf/perf.c:398
            #8 0x5611da17e0e9 in main /home/changbin/work/linux/tools/perf/perf.c:520
            #9 0x7fdcc970f09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
      
        SUMMARY: AddressSanitizer: heap-use-after-free /home/work/linux/tools/include/linux/list.h:89 in __list_del
        Shadow bytes around the buggy address:
          0x0c567fff8570: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff8580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff8590: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff85a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff85b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        =>0x0c567fff85c0: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd
          0x0c567fff85d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff85e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff85f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff8600: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
          0x0c567fff8610: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        Shadow byte legend (one shadow byte represents 8 application bytes):
          Addressable:           00
          Partially addressable: 01 02 03 04 05 06 07
          Heap left redzone:       fa
          Freed heap region:       fd
          Stack left redzone:      f1
          Stack mid redzone:       f2
          Stack right redzone:     f3
          Stack after return:      f5
          Stack use after scope:   f8
          Global redzone:          f9
          Global init order:       f6
          Poisoned by user:        f7
          Container overflow:      fc
          Array cookie:            ac
          Intra object redzone:    bb
          ASan internal:           fe
          Left alloca redzone:     ca
          Right alloca redzone:    cb
        ==27350==ABORTING
      Signed-off-by: NChangbin Du <changbin.du@gmail.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Link: http://lkml.kernel.org/r/20190316080556.3075-8-changbin.du@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0dba9e4b
  9. 06 2月, 2019 2 次提交
  10. 25 1月, 2019 1 次提交
  11. 22 1月, 2019 1 次提交
  12. 09 1月, 2019 1 次提交
  13. 18 12月, 2018 12 次提交
  14. 06 11月, 2018 1 次提交
    • J
      perf top: Display the LBR stats in callchain entry · 590ac60d
      Jin Yao 提交于
      'perf report' has supported the displaying of LBR stats (such as cycles,
      predicted%) in callchain entry.
      
      For example:
      
        $ perf report --branch-history --stdio
      
        --1.01%--intel_idle mwait.h:29
                  intel_idle cpufeature.h:164 (cycles:5)
                  intel_idle cpufeature.h:164 (predicted:76.4%)
                  intel_idle mwait.h:102 (cycles:41)
                  intel_idle current.h:15
      
      While 'perf top' doesn't support that.
      
      For example:
      
        $ perf top -a -b --call-graph branch
      
        -   13.86%     0.23%  [kernel]		[k] __x86_indirect_thunk_rax
           - 13.65% __x86_indirect_thunk_rax
              + 1.69% do_syscall_64
              + 1.68% do_select
              + 1.41% ktime_get
              + 0.70% __schedule
              + 0.62% do_sys_poll
                0.58% __x86_indirect_thunk_rax
      
      Actually it's very easy to enable this feature in 'perf top'.
      
      With this patch, the result is:
      
        $ perf top -a -b --call-graph branch
      
        $ -   13.58%     0.00%  [kernel]		[k] __x86_indirect_thunk_rax
           $ - 13.57% __x86_indirect_thunk_rax (predicted:93.9%)
              $ + 1.78% do_select (cycles:2)
              $ + 1.68% perf_pmu_disable.part.99 (cycles:1)
              $ + 1.45% ___sys_recvmsg (cycles:25)
              $ + 0.81% unix_stream_sendmsg (cycles:18)
              $ + 0.80% ktime_get (cycles:400)
                $ 0.58% pick_next_task_fair (cycles:47)
              $ + 0.56% i915_request_retire (cycles:2)
              $ + 0.52% do_sys_poll (cycles:4)
      Signed-off-by: NJin Yao <yao.jin@linux.intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/1540983995-20462-1-git-send-email-yao.jin@linux.intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      590ac60d
  15. 31 10月, 2018 2 次提交
  16. 30 10月, 2018 1 次提交
    • A
      perf top: Allow disabling the overwrite mode · 4e303fbe
      Arnaldo Carvalho de Melo 提交于
      In ebebbf08 ("perf top: Switch default mode to overwrite mode") we
      forgot to leave a way to disable that new default, add a --overwrite
      option that can be disabled using --no-overwrite, since the code already
      in such a way that we can readily disable this mode.
      
      This is useful when investigating bugs with this mode like the recent
      report from David Miller where lots of unknown symbols appear due to
      disabling the events while processing them which disables all record
      types, not just PERF_RECORD_SAMPLE, which makes it impossible to resolve
      maps when we lose PERF_RECORD_MMAP records.
      
      This can be easily seen while building a kernel, when there are lots of
      short lived processes.
      Reported-by: NDavid Miller <davem@davemloft.net>
      Acked-by: NKan Liang <kan.liang@intel.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: ebebbf08 ("perf top: Switch default mode to overwrite mode")
      Link: https://lkml.kernel.org/n/tip-oqgsz2bq4kgrnnajrafcdhie@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4e303fbe
  17. 25 7月, 2018 1 次提交