1. 05 Oct, 2023 5 commits
    • Athira Rajeev's avatar
      tools/perf/tests: Fix object code reading to skip address that falls out of text section · 8f5b62a1
      Athira Rajeev authored
      The testcase "Object code reading" fails in somecases
      for "fs_something" sub test as below:
      
          Reading object code for memory address: 0xc008000007f0142c
          File is: /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
          On file address is: 0x1114cc
          Objdump command is: objdump -z -d --start-address=0x11142c --stop-address=0x1114ac /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
          objdump read too few bytes: 128
          test child finished with -1
      
      This can alo be reproduced when running perf record with
      workload that exercises fs_something() code. In the test
      setup, this is exercising xfs code since root is xfs.
      
          # perf record ./a.out
          # perf report -v |grep "xfs.ko"
            0.76% a.out /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko  0xc008000007de5efc B [k] xlog_cil_commit
            0.74% a.out  /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko  0xc008000007d5ae18 B [k] xfs_btree_key_offset
            0.74% a.out  /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko  0xc008000007e11fd4 B [k] 0x0000000000112074
      
      Here addr "0xc008000007e11fd4" is not resolved. since this is a
      kernel module, its offset is from the DSO. Xfs module is loaded
      at 0xc008000007d00000
      
         # cat /proc/modules | grep xfs
          xfs 2228224 3 - Live 0xc008000007d00000
      
      And size is 0x220000. So its loaded between  0xc008000007d00000
      and 0xc008000007f20000. From objdump, text section is:
          text 0010f7bc  0000000000000000 0000000000000000 000000a0 2**4
      
      Hence perf captured ip maps to 0x112074 which is:
      ( ip - start of module ) + a0
      
      This offset 0x112074 falls out .text section which is up to 0x10f7bc
      In this case for module, the address 0xc008000007e11fd4 is pointing
      to stub instructions. This address range represents the module stubs
      which is allocated on module load and hence is not part of DSO offset.
      
      To address this issue in "object code reading", skip the sample if
      address falls out of text section and is within the module end.
      Use the "text_end" member of "struct dso" to do this check.
      
      To address this issue in "perf report", exploring an option of
      having stubs range as part of the /proc/kallsyms, so that perf
      report can resolve addresses in stubs range
      
      However this patch uses text_end to skip the stub range for
      Object code reading testcase.
      Reported-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: Disha Goel<disgoel@linux.ibm.com>
      Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: maddy@linux.ibm.com
      Cc: disgoel@linux.vnet.ibm.com
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230928075213.84392-3-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      8f5b62a1
    • Athira Rajeev's avatar
      tools/perf: Add "is_kmod" to struct dso to check if it is kernel module · 6be5d828
      Athira Rajeev authored
      Update "struct dso" to include new member "is_kmod".
      This new field will determine if the file is a kernel
      module or not.
      
      To resolve the address from a sample, perf looks at the
      DSO maps. In case of address from a kernel module, there
      were some address found to be not resolved. This was
      observed while running perf test for "Object code reading".
      Though the ip falls beteen the start address of the loaded
      module (perf map->start ) and end address ( perf map->end),
      it was unresolved.
      
      This was happening because in some cases for kernel
      modules, address from sample points to stub instructions.
      To identify if the DSO is a kernel module, the new field
      "is_kmod" is added to "struct dso".
      Reported-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: kjain@linux.ibm.com
      Cc: maddy@linux.ibm.com
      Cc: disgoel@linux.vnet.ibm.com
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230928075213.84392-2-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      6be5d828
    • Athira Rajeev's avatar
      tools/perf: Add text_end to "struct dso" to save .text section size · 26a5262d
      Athira Rajeev authored
      Update "struct dso" to include new member "text_end".
      This new field will represent the offset for end of text
      section for a dso. For elf, this value is derived as:
      sh_size (Size of section in byes) + sh_offset (Section file
      offst) of the elf header for text.
      
      For bfd, this value is derived as:
      1. For PE file,
      section->size + ( section->vma - dso->text_offset)
      2. Other cases:
      section->filepos (file position) + section->size (size of
      section)
      
      To resolve the address from a sample, perf looks at the
      DSO maps. In case of address from a kernel module, there
      were some address found to be not resolved. This was
      observed while running perf test for "Object code reading".
      Though the ip falls beteen the start address of the loaded
      module (perf map->start ) and end address ( perf map->end),
      it was unresolved.
      
      Example:
      
          Reading object code for memory address: 0xc008000007f0142c
          File is: /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
          On file address is: 0x1114cc
          Objdump command is: objdump -z -d --start-address=0x11142c --stop-address=0x1114ac /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
          objdump read too few bytes: 128
          test child finished with -1
      
      Here, module is loaded at:
          # cat /proc/modules | grep xfs
          xfs 2228224 3 - Live 0xc008000007d00000
      
      From objdump for xfs module, text section is:
          text 0010f7bc  0000000000000000 0000000000000000 000000a0 2**4
      
      Here the offset for 0xc008000007f0142c ie  0x112074 falls out
      .text section which is up to 0x10f7bc.
      
      In this case for module, the address 0xc008000007e11fd4 is pointing
      to stub instructions. This address range represents the module stubs
      which is allocated on module load and hence is not part of DSO offset.
      
      To identify such  address, which falls out of text
      section and within module end, added the new field "text_end" to
      "struct dso".
      Reported-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: maddy@linux.ibm.com
      Cc: disgoel@linux.vnet.ibm.com
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230928075213.84392-1-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      26a5262d
    • Ian Rogers's avatar
      perf test: Avoid system wide when not privileged · 0ddce121
      Ian Rogers authored
      Switch the test program to sleep that makes more sense for system wide
      events. Only enable system wide when root or not paranoid. This avoids
      failures under some testing conditions like ARM cloud.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/r/20230930060206.2353141-1-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      0ddce121
    • Kuan-Wei Chiu's avatar
      perf hisi-ptt: Fix memory leak in lseek failure handling · be7a4caa
      Kuan-Wei Chiu authored
      In the previous code, there was a memory leak issue where the previously
      allocated memory was not freed upon a failed lseek operation. This patch
      addresses the problem by releasing the old memory before returning -errno
      in case of a lseek failure. This ensures that memory is properly managed
      and avoids potential memory leaks.
      Signed-off-by: default avatarKuan-Wei Chiu <visitorckw@gmail.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: yangyicong@hisilicon.com
      Cc: jonathan.cameron@huawei.com
      Link: https://lore.kernel.org/r/20230930072719.1267784-1-visitorckw@gmail.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      be7a4caa
  2. 30 Sep, 2023 2 commits
  3. 28 Sep, 2023 9 commits
  4. 27 Sep, 2023 11 commits
  5. 21 Sep, 2023 2 commits
  6. 20 Sep, 2023 1 commit
  7. 18 Sep, 2023 7 commits
    • Ian Rogers's avatar
      perf parse-events: Fix tracepoint name memory leak · ede72dca
      Ian Rogers authored
      Fuzzing found that an invalid tracepoint name would create a memory
      leak with an address sanitizer build:
      ```
      $ perf stat -e '*:o/' true
      event syntax error: '*:o/'
                             \___ parser error
      Run 'perf list' for a list of valid events
      
       Usage: perf stat [<options>] [<command>]
      
          -e, --event <event>   event selector. use 'perf list' to list available events
      
      =================================================================
      ==59380==ERROR: LeakSanitizer: detected memory leaks
      
      Direct leak of 4 byte(s) in 2 object(s) allocated from:
          #0 0x7f38ac07077b in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:439
          #1 0x55f2f41be73b in str util/parse-events.l:49
          #2 0x55f2f41d08e8 in parse_events_lex util/parse-events.l:338
          #3 0x55f2f41dc3b1 in parse_events_parse util/parse-events-bison.c:1464
          #4 0x55f2f410b8b3 in parse_events__scanner util/parse-events.c:1822
          #5 0x55f2f410d1b9 in __parse_events util/parse-events.c:2094
          #6 0x55f2f410e57f in parse_events_option util/parse-events.c:2279
          #7 0x55f2f4427b56 in get_value tools/lib/subcmd/parse-options.c:251
          #8 0x55f2f4428d98 in parse_short_opt tools/lib/subcmd/parse-options.c:351
          #9 0x55f2f4429d80 in parse_options_step tools/lib/subcmd/parse-options.c:539
          #10 0x55f2f442acb9 in parse_options_subcommand tools/lib/subcmd/parse-options.c:654
          #11 0x55f2f3ec99fc in cmd_stat tools/perf/builtin-stat.c:2501
          #12 0x55f2f4093289 in run_builtin tools/perf/perf.c:322
          #13 0x55f2f40937f5 in handle_internal_command tools/perf/perf.c:375
          #14 0x55f2f4093bbd in run_argv tools/perf/perf.c:419
          #15 0x55f2f409412b in main tools/perf/perf.c:535
      
      SUMMARY: AddressSanitizer: 4 byte(s) leaked in 2 allocation(s).
      ```
      Fix by adding the missing destructor.
      
      Fixes: 865582c3 ("perf tools: Adds the tracepoint name parsing support")
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: He Kuang <hekuang@huawei.com>
      Link: https://lore.kernel.org/r/20230914164028.363220-1-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      ede72dca
    • Ian Rogers's avatar
      perf test: Detect off-cpu support from build options · b4f48f34
      Ian Rogers authored
      Use perf version to detect whether BPF skeletons were enabled in a
      build rather than a failing perf record.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: James Clark <james.clark@arm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Patrice Duroux <patrice.duroux@gmail.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230914211948.814999-6-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      b4f48f34
    • Ian Rogers's avatar
      perf test: Ensure EXTRA_TESTS is covered in build test · c2ac838e
      Ian Rogers authored
      Add to run variable.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: James Clark <james.clark@arm.com>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Patrice Duroux <patrice.duroux@gmail.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230914211948.814999-5-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      c2ac838e
    • Ian Rogers's avatar
      perf test: Update build test for changed BPF skeleton defaults · c67c631d
      Ian Rogers authored
      Fix a target name and set BUILD_BPF_SKEL to 0 rather than 1.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: James Clark <james.clark@arm.com>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Patrice Duroux <patrice.duroux@gmail.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230914211948.814999-4-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      c67c631d
    • Ian Rogers's avatar
      perf build: Default BUILD_BPF_SKEL, warn/disable for missing deps · 9925495d
      Ian Rogers authored
      LIBBPF is dependent on zlib so move the NO_ZLIB and feature check
      early to avoid statically building when zlib is disabled. This avoids
      a linkage failure with perf and static libbpf when zlib isn't
      specified.
      
      Move BUILD_BPF_SKEL logic to one place and if not defined set
      BUILD_BPF_SKEL to 1. Detect dependencies of building with BPF
      skeletons and warn/disable if the dependencies aren't present.
      
      Change Makefile.perf to contain BPF skeleton logic dependent on the
      Makefile.config result and refresh the comment about BUILD_BPF_SKEL.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: James Clark <james.clark@arm.com>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Patrice Duroux <patrice.duroux@gmail.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230914211948.814999-3-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      9925495d
    • Ian Rogers's avatar
      perf version: Add status of bpf skeletons · 727e4314
      Ian Rogers authored
      Add status for BPF skeletons, to see if a build has them enabled:
      ```
      $ perf version --build-options
      perf version 6.6.rc1.g0381ae36d1a6
                       dwarf: [ OFF ]  # HAVE_DWARF_SUPPORT
          dwarf_getlocations: [ OFF ]  # HAVE_DWARF_GETLOCATIONS_SUPPORT
               syscall_table: [ on  ]  # HAVE_SYSCALL_TABLE_SUPPORT
                      libbfd: [ OFF ]  # HAVE_LIBBFD_SUPPORT
                  debuginfod: [ OFF ]  # HAVE_DEBUGINFOD_SUPPORT
                      libelf: [ OFF ]  # HAVE_LIBELF_SUPPORT
                     libnuma: [ OFF ]  # HAVE_LIBNUMA_SUPPORT
      numa_num_possible_cpus: [ OFF ]  # HAVE_LIBNUMA_SUPPORT
                     libperl: [ on  ]  # HAVE_LIBPERL_SUPPORT
                   libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
                    libslang: [ on  ]  # HAVE_SLANG_SUPPORT
                   libcrypto: [ on  ]  # HAVE_LIBCRYPTO_SUPPORT
                   libunwind: [ OFF ]  # HAVE_LIBUNWIND_SUPPORT
          libdw-dwarf-unwind: [ OFF ]  # HAVE_DWARF_SUPPORT
                        zlib: [ on  ]  # HAVE_ZLIB_SUPPORT
                        lzma: [ on  ]  # HAVE_LZMA_SUPPORT
                   get_cpuid: [ on  ]  # HAVE_AUXTRACE_SUPPORT
                         bpf: [ OFF ]  # HAVE_LIBBPF_SUPPORT
                         aio: [ on  ]  # HAVE_AIO_SUPPORT
                        zstd: [ on  ]  # HAVE_ZSTD_SUPPORT
                     libpfm4: [ on  ]  # HAVE_LIBPFM
               libtraceevent: [ on  ]  # HAVE_LIBTRACEEVENT
               bpf_skeletons: [ OFF ]  # HAVE_BPF_SKEL
      ```
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: James Clark <james.clark@arm.com>
      Cc: Nick Terrell <terrelln@fb.com>
      Cc: Patrice Duroux <patrice.duroux@gmail.com>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230914211948.814999-2-irogers@google.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      727e4314
    • Yang Li's avatar
      perf kwork top: Simplify bool conversion · 3ecf87b2
      Yang Li authored
      ./tools/perf/util/bpf_kwork_top.c:120:53-58: WARNING: conversion to bool not needed here
      Signed-off-by: default avatarYang Li <yang.lee@linux.alibaba.com>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230915063832.120274-1-yang.lee@linux.alibaba.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      3ecf87b2
  8. 17 Sep, 2023 1 commit
    • Yang Jihong's avatar
      perf test: Fix test-record-dummy-C0 failure for supported PERF_FORMAT_LOST feature kernel · a132b784
      Yang Jihong authored
      For kernel that supports PERF_FORMAT_LOST, attr->read_format has
      PERF_FORMAT_LOST bit. Update expected value of
      attr->read_format of test-record-dummy-C0 for this scenario.
      
      Before:
      
        # ./perf test 17 -vv
         17: Setup struct perf_event_attr                                    :
        --- start ---
        test child forked, pid 1609441
        <SNIP>
        running './tests/attr/test-record-dummy-C0'
          'PERF_TEST_ATTR=/tmp/tmpm3s60aji ./perf record -o /tmp/tmpm3s60aji/perf.data --no-bpf-event -e dummy -C 0 kill >/dev/null 2>&1' ret '1', expected '1'
        expected read_format=4, got 20
        FAILED './tests/attr/test-record-dummy-C0' - match failure
        test child finished with -1
        ---- end ----
        Setup struct perf_event_attr: FAILED!
      
      After:
      
        # ./perf test 17 -vv
         17: Setup struct perf_event_attr                                    :
        --- start ---
        test child forked, pid 1609441
        <SNIP>
        running './tests/attr/test-record-dummy-C0'
          'PERF_TEST_ATTR=/tmp/tmppa9vxcb7 ./perf record -o /tmp/tmppa9vxcb7/perf.data --no-bpf-event -e dummy -C 0 kill >/dev/null 2>&1' ret '1', expected '1'
        <SNIP>
        test child finished with 0
        ---- end ----
        Setup struct perf_event_attr: Ok
      Reported-and-Tested-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarYang Jihong <yangjihong1@huawei.com>
      Link: https://lore.kernel.org/r/20230916091641.776031-1-yangjihong1@huawei.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      a132b784
  9. 15 Sep, 2023 2 commits