1. 25 Sep, 2019 31 commits
  2. 23 Sep, 2019 2 commits
    • Arnaldo Carvalho de Melo's avatar
      perf record: Move restricted maps check to after a possible fallback to not collect kernel samples · c8b567c8
      Arnaldo Carvalho de Melo authored
      Before:
      
        [acme@quaco ~]$ perf record -b -e cycles date
        WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
        check /proc/sys/kernel/kptr_restrict and /proc/sys/kernel/perf_event_paranoid.
      
        Samples in kernel functions may not be resolved if a suitable vmlinux
        file is not found in the buildid cache or in the vmlinux path.
      
        Samples in kernel modules won't be resolved at all.
      
        If some relocation was applied (e.g. kexec) symbols may be misresolved
        even with a suitable vmlinux or kallsyms file.
      
        Mon 23 Sep 2019 11:00:59 AM -03
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.005 MB perf.data (14 samples) ]
        [acme@quaco ~]$
      
      But we did a fallback and exclude_kernel was set, so no need for
      resolving kernel symbols:
      
        $ perf evlist -v
        cycles:u: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: ANY
        $
      
      After:
      
        [acme@quaco ~]$ perf record -b -e cycles date
        Mon 23 Sep 2019 11:07:18 AM -03
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.007 MB perf.data (16 samples) ]
        [acme@quaco ~]$ perf evlist -v
        cycles:u: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: ANY
        [acme@quaco ~]$
      
      No needless warning is emitted.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lkml.kernel.org/n/tip-5yqnr8xcqwhr15xktj2097ac@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c8b567c8
    • Stephane Eranian's avatar
      perf record: Fix priv level with branch sampling for paranoid=2 · 4ec8d984
      Stephane Eranian authored
      Now that the default perf_events paranoid level is set to 2, a regular
      user cannot monitor kernel level activity anymore. As such, with the
      following cmdline:
      
        $ perf record -e cycles date
      
      The perf tool first tries cycles:uk but then falls back to cycles:u as
      can be seen in the perf report --header-only output:
      
        cmdline : /export/hda3/tmp/perf.tip record -e cycles ls
        event : name = cycles:u, , id = { 436186, ... }
      
      This is okay as long as there is way to learn the priv level was changed
      internally by the tool.
      
      But consider a similar example:
      
        $ perf record -b -e cycles date
        Error:
        You may not have permission to collect stats.
      
      Consider tweaking /proc/sys/kernel/perf_event_paranoid,
      which controls use of the performance events system by
      unprivileged users (without CAP_SYS_ADMIN).
      ...
      
      Why is that treated differently given that the branch sampling inherits the
      priv level of the first event in this case, i.e., cycles:u? It turns out
      that the branch sampling code is more picky and also checks exclude_hv.
      
      In the fallback path, perf record is setting exclude_kernel = 1, but it
      does not change exclude_hv. This does not seem to match the restriction
      imposed by paranoid = 2.
      
      This patch fixes the problem by forcing exclude_hv = 1 in the fallback
      for paranoid=2. With this in place:
      
        $ perf record -b -e cycles date
          cmdline : /export/hda3/tmp/perf.tip record -b -e cycles ls
          event : name = cycles:u, , id = { 436847, ... }
      
      And the command succeeds as expected.
      
      V2 fix a white space.
      
      Committer testing:
      
      After aplying the patch we get:
      
        [acme@quaco ~]$ perf record -b -e cycles date
        WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
        check /proc/sys/kernel/kptr_restrict and /proc/sys/kernel/perf_event_paranoid.
      
        Samples in kernel functions may not be resolved if a suitable vmlinux
        file is not found in the buildid cache or in the vmlinux path.
      
        Samples in kernel modules won't be resolved at all.
      
        If some relocation was applied (e.g. kexec) symbols may be misresolved
        even with a suitable vmlinux or kallsyms file.
      
        Mon 23 Sep 2019 11:00:59 AM -03
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.005 MB perf.data (14 samples) ]
        [acme@quaco ~]$ perf evlist -v
        cycles:u: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: ANY
        [acme@quaco ~]$
      
      That warning about restricted kernel maps will be suppressed in a follow
      up patch, as perf_event_attr.exclude_kernel is set, i.e. no samples for
      the kernel will be taken and thus no need for those maps.
      Signed-off-by: default avatarStephane Eranian <eranian@google.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20190920230356.41420-1-eranian@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      4ec8d984
  3. 22 Sep, 2019 1 commit
    • Ingo Molnar's avatar
      Merge tag 'perf-urgent-for-mingo-5.4-20190921' of... · 2b327697
      Ingo Molnar authored
      Merge tag 'perf-urgent-for-mingo-5.4-20190921' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
      
      Pull perf/urgent fixes from Arnaldo Carvalho de Melo:
      
      perf tests:
      
        Jiri Olsa:
      
        - Fix 'make -C tools/perf build-test' static build entry.
      
      perf record:
      
        Jiri Olsa:
      
        - Fix segfault in cpu_cache_level__read() when reading CPU topology.
      
      session:
      
        Mamatha Inamdar:
      
        - Properly propagate error when reading a perf.data file, it may
          not exist or the user may not have permissions, etc.
      
      perf probe:
      
        Masami Hiramatsu:
      
        - Skip same probe address for a given line.
      
        - Clear tev->nargs in clear_probe_trace_event(), fixing segfault.
      
      tools headers UAPI:
      
        Arnaldo Carvalho de Melo:
      
        - Sync headers, among them prctl.h, that introduces two new options
          that are now supported in the 'perf trace' prctl syscall args
          beautifiers.
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      2b327697
  4. 20 Sep, 2019 6 commits
    • Roy Ben Shlomo's avatar
      perf/core: Fix several typos in comments · 9f014e3a
      Roy Ben Shlomo authored
      Fix typos in a few functions' documentation comments.
      Signed-off-by: default avatarRoy Ben Shlomo <royb@sentinelone.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: royb@sentinelone.com
      Link: http://lore.kernel.org/lkml/20190920171254.31373-1-royb@sentinelone.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9f014e3a
    • Mamatha Inamdar's avatar
      perf session: Return error code for perf_session__new() function on failure · 6ef81c55
      Mamatha Inamdar authored
      This patch is to return error code of perf_new_session function on
      failure instead of NULL.
      
      Test Results:
      
      Before Fix:
      
        $ perf c2c report -input
        failed to open nput: No such file or directory
      
        $ echo $?
        0
        $
      
      After Fix:
      
        $ perf c2c report -input
        failed to open nput: No such file or directory
      
        $ echo $?
        254
        $
      
      Committer notes:
      
      Fix 'perf tests topology' case, where we use that TEST_ASSERT_VAL(...,
      session), i.e. we need to pass zero in case of failure, which was the
      case before when NULL was returned by perf_session__new() for failure,
      but now we need to negate the result of IS_ERR(session) to respect that
      TEST_ASSERT_VAL) expectation of zero meaning failure.
      Reported-by: default avatarNageswara R Sastry <rnsastry@linux.vnet.ibm.com>
      Signed-off-by: default avatarMamatha Inamdar <mamatha4@linux.vnet.ibm.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarNageswara R Sastry <rnsastry@linux.vnet.ibm.com>
      Acked-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
      Reviewed-by: default avatarJiri Olsa <jolsa@redhat.com>
      Reviewed-by: default avatarMukesh Ojha <mojha@codeaurora.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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Shawn Landden <shawn@git.icu>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
      Link: http://lore.kernel.org/lkml/20190822071223.17892.45782.stgit@localhost.localdomainSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6ef81c55
    • Masami Hiramatsu's avatar
      perf probe: Fix to clear tev->nargs in clear_probe_trace_event() · 9e6124d9
      Masami Hiramatsu authored
      Since add_probe_trace_event() can reuse tf->tevs[i] after calling
      clear_probe_trace_event(), this can make perf-probe crash if the 1st
      attempt of probe event finding fails to find an event argument, and the
      2nd attempt fails to find probe point.
      
      E.g.
        $ perf probe -D "task_pid_nr tsk"
        Failed to find 'tsk' in this function.
        Failed to get entry address of warn_bad_vsyscall
        Segmentation fault (core dumped)
      
      Committer testing:
      
      After the patch:
      
        $ perf probe -D "task_pid_nr tsk"
        Failed to find 'tsk' in this function.
        Failed to get entry address of warn_bad_vsyscall
        Failed to get entry address of signal_fault
        Failed to get entry address of show_signal
        Failed to get entry address of umip_printk
        Failed to get entry address of __bad_area_nosemaphore
        <SNIP>
        Failed to get entry address of sock_set_timeout
        Failed to get entry address of tcp_recvmsg
        Probe point 'task_pid_nr' not found.
          Error: Failed to add events.
        $
      
      Fixes: 092b1f0b ("perf probe: Clear probe_trace_event when add_probe_trace_event() fails")
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/156856587999.25775.5145779959474477595.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9e6124d9
    • Masami Hiramatsu's avatar
      perf probe: Skip same probe address for a given line · 1a375ae7
      Masami Hiramatsu authored
      Fix to skip making a same probe address on given line.
      
      Since a DWARF line info contains several entries for one line with
      different column, perf probe will make a different probe on same address
      if user specifies a probe point by "function:line" or "file:line".
      
      e.g.
       $ perf probe -D kernel_read:8
       p:probe/kernel_read_L8 kernel_read+39
       p:probe/kernel_read_L8_1 kernel_read+39
      
      This skips such duplicated probe addresses.
      
      Committer testing:
      
        # uname -a
        Linux quaco 5.3.0+ #2 SMP Thu Sep 19 16:13:22 -03 2019 x86_64 x86_64 x86_64 GNU/Linux
        #
      
      Before:
      
        # perf probe -D kernel_read:8
        p:probe/kernel_read _text+3115191
        p:probe/kernel_read_1 _text+3115191
        #
      
      After:
      
        # perf probe -D kernel_read:8
        p:probe/kernel_read _text+3115191
        #
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/156886447061.10772.4261569305869149178.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1a375ae7
    • Jiri Olsa's avatar
      perf tools: Fix segfault in cpu_cache_level__read() · 0216234c
      Jiri Olsa authored
      We release wrong pointer on error path in cpu_cache_level__read
      function, leading to segfault:
      
        (gdb) r record ls
        Starting program: /root/perf/tools/perf/perf record ls
        ...
        [ perf record: Woken up 1 times to write data ]
        double free or corruption (out)
      
        Thread 1 "perf" received signal SIGABRT, Aborted.
        0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
        (gdb) bt
        #0  0x00007ffff7463798 in raise () from /lib64/power9/libc.so.6
        #1  0x00007ffff7443bac in abort () from /lib64/power9/libc.so.6
        #2  0x00007ffff74af8bc in __libc_message () from /lib64/power9/libc.so.6
        #3  0x00007ffff74b92b8 in malloc_printerr () from /lib64/power9/libc.so.6
        #4  0x00007ffff74bb874 in _int_free () from /lib64/power9/libc.so.6
        #5  0x0000000010271260 in __zfree (ptr=0x7fffffffa0b0) at ../../lib/zalloc..
        #6  0x0000000010139340 in cpu_cache_level__read (cache=0x7fffffffa090, cac..
        #7  0x0000000010143c90 in build_caches (cntp=0x7fffffffa118, size=<optimiz..
        ...
      
      Releasing the proper pointer.
      
      Fixes: 720e98b5 ("perf tools: Add perf data cache feature")
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org: # v4.6+
      Link: http://lore.kernel.org/lkml/20190912105235.10689-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0216234c
    • Arnaldo Carvalho de Melo's avatar
      tools arch x86: Sync asm/cpufeatures.h with the kernel sources · 40f1c039
      Arnaldo Carvalho de Melo authored
      To pick up the changes from:
      
        b4dd4f6e ("x86/vmware: Add a header file for hypercall definitions")
        f36cf386 ("x86/speculation/swapgs: Exclude ATOMs from speculation through SWAPGS")
        be261ffc ("x86: Remove X86_FEATURE_MFENCE_RDTSC")
        018ebca8 ("x86/cpufeatures: Enable a new AVX512 CPU feature")
      
      These don't cause any changes in tooling, just silences this perf build
      warning:
      
        Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
        diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h
      
      To clarify, updating those files cause these bits of tools/perf to rebuild:
      
        CC       /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
        CC       /tmp/build/perf/bench/mem-memset-x86-64-asm.o
        INSTALL  GTK UI
        LD       /tmp/build/perf/bench/perf-in.o
      
      Those use just:
      
        $ grep FEATURE tools/arch/x86/lib/mem*.S
        tools/arch/x86/lib/memcpy_64.S:	ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
        tools/arch/x86/lib/memcpy_64.S:		      "jmp memcpy_erms", X86_FEATURE_ERMS
        tools/arch/x86/lib/memset_64.S:	ALTERNATIVE_2 "jmp memset_orig", "", X86_FEATURE_REP_GOOD, \
        tools/arch/x86/lib/memset_64.S:		      "jmp memset_erms", X86_FEATURE_ERMS
        $
      
      I.e. none of the feature defines added/removed by the patches above.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Gayatri Kammela <gayatri.kammela@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Hellstrom <thellstrom@vmware.com>
      Link: https://lkml.kernel.org/n/tip-pq63abgknsaeov23p80d8gjv@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      40f1c039